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.
This commit is contained in:
Zheng, Lei
2019-09-30 11:48:06 +08:00
committed by wmayer
parent be951cc0d8
commit 29f5ac736b
2 changed files with 29 additions and 1 deletions

View File

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

View File

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