From 29f5ac736b77db20604375af769c5cff30ed6eee Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Mon, 30 Sep 2019 11:48:06 +0800 Subject: [PATCH] Gui: sync expression change in property editor This patch fixes two problems, When one property item is assigned an expression, auto remove any parent and child item expressions to avoid expression conflicts. Disable value update when an property item or any of its parents are bound by an expression. --- src/Gui/propertyeditor/PropertyItem.cpp | 25 ++++++++++++++++++++++++- src/Gui/propertyeditor/PropertyItem.h | 5 +++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 7a44222ec9..adc10d1118 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -111,6 +111,29 @@ void PropertyItem::reset() childItems.clear(); } +void PropertyItem::onChange() +{ + if(hasExpression()) { + for(auto child : childItems) { + if(child && child->hasExpression()) + child->setExpression(boost::shared_ptr()); + } + for(auto item=parentItem;item;item=item->parentItem) { + if(item->hasExpression()) + item->setExpression(boost::shared_ptr()); + } + } +} + +bool PropertyItem::hasAnyExpression() const +{ + if(ExpressionBinding::hasExpression()) + return true; + if(parentItem) + return parentItem->hasExpression(); + return false; +} + void PropertyItem::setPropertyData(const std::vector& items) { //if we have a single property we can bind it for expression handling @@ -581,7 +604,7 @@ bool PropertyItem::setData (const QVariant& value) // property or delegates again to its parent... if (propertyItems.empty()) { PropertyItem* parent = this->parent(); - if (!parent || !parent->parent()) + if (!parent || !parent->parent() || hasAnyExpression()) return false; parent->setProperty(qPrintable(objectName()),value); return true; diff --git a/src/Gui/propertyeditor/PropertyItem.h b/src/Gui/propertyeditor/PropertyItem.h index 5bccc400bc..43c7754441 100644 --- a/src/Gui/propertyeditor/PropertyItem.h +++ b/src/Gui/propertyeditor/PropertyItem.h @@ -164,6 +164,8 @@ public: int row() const; void reset(); + bool hasAnyExpression() const; + protected: PropertyItem(); @@ -176,6 +178,9 @@ protected: virtual void initialize(); QString pythonIdentifier(const App::Property*) const; + //gets called when the bound expression is changed + virtual void onChange(); + protected: QString propName; QString displayText;