diff --git a/src/Gui/ExpressionBinding.cpp b/src/Gui/ExpressionBinding.cpp index f6ad623b4c..d90e0dedfb 100644 --- a/src/Gui/ExpressionBinding.cpp +++ b/src/Gui/ExpressionBinding.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include @@ -167,6 +168,28 @@ std::string ExpressionBinding::getEscapedExpressionString() const return Base::Tools::escapedUnicodeFromUtf8(getExpressionString(false).c_str()); } +bool ExpressionBinding::assignToProperty(const std::string & propName, double value) +{ + if (isBound()) { + const App::ObjectIdentifier & path = getPath(); + const Property * prop = path.getProperty(); + + /* Skip update if property is bound and we know it is read-only */ + if (prop && prop->isReadOnly()) + return true; + + if (prop && prop->getTypeId().isDerivedFrom(App::PropertyPlacement::getClassTypeId())) { + std::string p = path.getSubPathStr(); + if (p == ".Rotation.Angle") { + value = Base::toRadians(value); + } + } + } + + Gui::Command::doCommand(Gui::Command::Doc, "%s = %f", propName.c_str(), value); + return true; +} + QPixmap ExpressionBinding::getIcon(const char* name, const QSize& size) const { QString key = QString::fromLatin1("%1_%2x%3") diff --git a/src/Gui/ExpressionBinding.h b/src/Gui/ExpressionBinding.h index d7454fb577..bf59eec898 100644 --- a/src/Gui/ExpressionBinding.h +++ b/src/Gui/ExpressionBinding.h @@ -65,6 +65,7 @@ protected: std::shared_ptr getExpression() const; std::string getExpressionString(bool no_throw=true) const; std::string getEscapedExpressionString() const; + bool assignToProperty(const std::string & propName, double); virtual void setExpression(std::shared_ptr expr); //gets called when the bound expression is changed, either by this binding or any external action diff --git a/src/Gui/QuantitySpinBox.cpp b/src/Gui/QuantitySpinBox.cpp index 845508eb58..22039421b8 100644 --- a/src/Gui/QuantitySpinBox.cpp +++ b/src/Gui/QuantitySpinBox.cpp @@ -39,7 +39,6 @@ #include #include #include -#include #include #include #include @@ -370,24 +369,7 @@ bool QuantitySpinBox::apply(const std::string & propName) { if (!ExpressionBinding::apply(propName)) { double dValue = value().getValue(); - if (isBound()) { - const App::ObjectIdentifier & path = getPath(); - const Property * prop = path.getProperty(); - - /* Skip update if property is bound and we know it is read-only */ - if (prop && prop->isReadOnly()) - return true; - - if (prop && prop->getTypeId().isDerivedFrom(App::PropertyPlacement::getClassTypeId())) { - std::string p = path.getSubPathStr(); - if (p == ".Rotation.Angle") { - dValue = Base::toRadians(dValue); - } - } - } - - Gui::Command::doCommand(Gui::Command::Doc, "%s = %f", propName.c_str(), dValue); - return true; + return assignToProperty(propName, dValue); } return false;