App/Gui: Fix auto checking 'Sync sub object' if property link editor

Related FreeCAD/FreeCAD#6672 case C
This commit is contained in:
Zheng, Lei
2022-04-03 21:17:20 +08:00
committed by wwmayer
parent 9242355c8c
commit 15c59d6007
3 changed files with 42 additions and 8 deletions

View File

@@ -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<std::string> &SubList, std::vector<ShadowSub> &&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<int>(_Links.size());

View File

@@ -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<App::DocumentObject *> &inList) override;
void setSyncSubObject(bool enable);
protected:
App::DocumentObject* _pcLinkSub;
std::vector<std::string> _cSubList;
@@ -1003,6 +1005,8 @@ public:
virtual bool adjustLink(const std::set<App::DocumentObject *> &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<PropertyXLinkSub> _Links;
};

View File

@@ -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);