Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
realthunder authored and wwmayer committed Oct 7, 2019
1 parent be951cc commit 29f5ac7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/Gui/propertyeditor/PropertyItem.cpp
Expand Up @@ -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<App::Expression>());
}
for(auto item=parentItem;item;item=item->parentItem) {
if(item->hasExpression())
item->setExpression(boost::shared_ptr<App::Expression>());
}
}
}

bool PropertyItem::hasAnyExpression() const
{
if(ExpressionBinding::hasExpression())
return true;
if(parentItem)
return parentItem->hasExpression();
return false;
}

void PropertyItem::setPropertyData(const std::vector<App::Property*>& items)
{
//if we have a single property we can bind it for expression handling
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/Gui/propertyeditor/PropertyItem.h
Expand Up @@ -164,6 +164,8 @@ class GuiExport PropertyItem : public QObject, public ExpressionBinding
int row() const;
void reset();

bool hasAnyExpression() const;

protected:
PropertyItem();

Expand All @@ -176,6 +178,9 @@ class GuiExport PropertyItem : public QObject, public ExpressionBinding
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;
Expand Down

0 comments on commit 29f5ac7

Please sign in to comment.