From 15c59d6007e5bf3749dfdf4f6679b8b0bc787acc Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sun, 3 Apr 2022 21:17:20 +0800 Subject: [PATCH] App/Gui: Fix auto checking 'Sync sub object' if property link editor Related FreeCAD/FreeCAD#6672 case C --- src/App/PropertyLinks.cpp | 22 ++++++++++++++++++++++ src/App/PropertyLinks.h | 8 ++++++++ src/Gui/DlgPropertyLink.cpp | 20 ++++++++++++-------- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/App/PropertyLinks.cpp b/src/App/PropertyLinks.cpp index 9ce90c6cc6..755dd626fb 100644 --- a/src/App/PropertyLinks.cpp +++ b/src/App/PropertyLinks.cpp @@ -939,6 +939,11 @@ PropertyLinkSub::~PropertyLinkSub() #endif } +void PropertyLinkSub::setSyncSubObject(bool enable) +{ + _Flags.set((std::size_t)LinkSyncSubObject, enable); +} + void PropertyLinkSub::setValue(App::DocumentObject * lValue, const std::vector &SubList, std::vector &&shadows) { @@ -1614,6 +1619,11 @@ PropertyLinkSubList::~PropertyLinkSubList() #endif } +void PropertyLinkSubList::setSyncSubObject(bool enable) +{ + _Flags.set((std::size_t)LinkSyncSubObject, enable); +} + void PropertyLinkSubList::verifyObject(App::DocumentObject* obj, App::DocumentObject* parent) { if (obj) { @@ -2968,6 +2978,7 @@ PropertyXLink::PropertyXLink(bool _allowPartial, PropertyLinkBase *parent) { setAllowPartial(_allowPartial); setAllowExternal(true); + setSyncSubObject(true); if(parent) setContainer(parent->getContainer()); } @@ -2976,6 +2987,11 @@ PropertyXLink::~PropertyXLink() { unlink(); } +void PropertyXLink::setSyncSubObject(bool enable) +{ + _Flags.set((std::size_t)LinkSyncSubObject, enable); +} + void PropertyXLink::unlink() { if(docInfo) { docInfo->remove(this); @@ -3835,12 +3851,18 @@ TYPESYSTEM_SOURCE(App::PropertyXLinkSubList , App::PropertyLinkBase) PropertyXLinkSubList::PropertyXLinkSubList() { _pcScope = LinkScope::Global; + setSyncSubObject(true); } PropertyXLinkSubList::~PropertyXLinkSubList() { } +void PropertyXLinkSubList::setSyncSubObject(bool enable) +{ + _Flags.set((std::size_t)LinkSyncSubObject, enable); +} + int PropertyXLinkSubList::getSize(void) const { return static_cast(_Links.size()); diff --git a/src/App/PropertyLinks.h b/src/App/PropertyLinks.h index 34de1fa14a..08f508036c 100644 --- a/src/App/PropertyLinks.h +++ b/src/App/PropertyLinks.h @@ -537,6 +537,7 @@ public: LinkRestoring, LinkAllowPartial, LinkRestoreLabel, + LinkSyncSubObject, // used by DlgPropertyLink }; inline bool testFlag(int flag) const { return _Flags.test((std::size_t)flag); @@ -857,6 +858,7 @@ public: virtual bool adjustLink(const std::set &inList) override; + void setSyncSubObject(bool enable); protected: App::DocumentObject* _pcLinkSub; std::vector _cSubList; @@ -1003,6 +1005,8 @@ public: virtual bool adjustLink(const std::set &inList) override; + void setSyncSubObject(bool enable); + private: void verifyObject(App::DocumentObject *, App::DocumentObject *); @@ -1139,6 +1143,8 @@ public: virtual bool upgrade(Base::XMLReader &reader, const char *typeName); + void setSyncSubObject(bool enable); + protected: void unlink(); void detach(); @@ -1292,6 +1298,8 @@ public: virtual void hasSetChildValue(Property &) override; virtual void aboutToSetChildValue(Property &) override; + void setSyncSubObject(bool enable); + protected: std::list _Links; }; diff --git a/src/Gui/DlgPropertyLink.cpp b/src/Gui/DlgPropertyLink.cpp index 5632a03c43..63bd12a3f4 100644 --- a/src/Gui/DlgPropertyLink.cpp +++ b/src/Gui/DlgPropertyLink.cpp @@ -322,19 +322,23 @@ void DlgPropertyLink::init(const App::DocumentObjectT &prop, bool tryFilter) { docItems[d] = item; } - if(oldLinks.isEmpty()) - return; - if(allowSubObject) { - for(auto &link : oldLinks) { - auto sobj = link.getSubObject(); - if(sobj && sobj!=link.getObject()) { - ui->checkSubObject->setChecked(true); - break; + if (propLink->testFlag(App::PropertyLinkBase::LinkSyncSubObject)) + ui->checkSubObject->setChecked(true); + else { + for(auto &link : oldLinks) { + auto sobj = link.getSubObject(); + if(sobj && sobj!=link.getObject()) { + ui->checkSubObject->setChecked(true); + break; + } } } } + if(oldLinks.isEmpty()) + return; + // Try to select items corresponding to the current links inside the // property ui->treeWidget->blockSignals(true);