From 081bc6b10708c244577dd1baf73070be47eb3109 Mon Sep 17 00:00:00 2001 From: Eivind Kvedalen Date: Tue, 10 Nov 2015 01:09:27 +0100 Subject: [PATCH] QuantitySpinBox: Make sure Python code is emitted also when expressions are not used. In that case, the property should be set directly. --- src/Gui/ExpressionBinding.cpp | 11 ++++++----- src/Gui/ExpressionBinding.h | 1 + src/Gui/QuantitySpinBox.cpp | 5 ----- src/Gui/QuantitySpinBox.h | 3 ++- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Gui/ExpressionBinding.cpp b/src/Gui/ExpressionBinding.cpp index fef3b14d5..3af8053be 100644 --- a/src/Gui/ExpressionBinding.cpp +++ b/src/Gui/ExpressionBinding.cpp @@ -64,6 +64,7 @@ void Gui::ExpressionBinding::setExpression(boost::shared_ptr expr) } + lastExpression = getExpression(); docObj->ExpressionEngine.setValue(path, expr); } @@ -146,11 +147,11 @@ bool ExpressionBinding::apply(const std::string & propName) if (!docObj) throw Base::Exception("Document object not found."); - Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument('%s').%s.setExpression('%s', None)", - docObj->getDocument()->getName(), - docObj->getNameInDocument(), - path.toEscapedString().c_str()); - return true; + if (lastExpression) + Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument('%s').%s.setExpression('%s', None)", + docObj->getDocument()->getName(), + docObj->getNameInDocument(), + path.toEscapedString().c_str()); } return false; diff --git a/src/Gui/ExpressionBinding.h b/src/Gui/ExpressionBinding.h index 7e66e403b..83dc478cb 100644 --- a/src/Gui/ExpressionBinding.h +++ b/src/Gui/ExpressionBinding.h @@ -58,6 +58,7 @@ protected: private: App::ObjectIdentifier path; + boost::shared_ptr lastExpression; protected: QLabel* iconLabel; QPalette defaultPalette; diff --git a/src/Gui/QuantitySpinBox.cpp b/src/Gui/QuantitySpinBox.cpp index 0eac61008..95546ee80 100644 --- a/src/Gui/QuantitySpinBox.cpp +++ b/src/Gui/QuantitySpinBox.cpp @@ -321,11 +321,6 @@ bool QuantitySpinBox::apply(const std::string & propName) return false; } -bool QuantitySpinBox::apply() -{ - return ExpressionBinding::apply(); -} - void QuantitySpinBox::resizeEvent(QResizeEvent * event) { QAbstractSpinBox::resizeEvent(event); diff --git a/src/Gui/QuantitySpinBox.h b/src/Gui/QuantitySpinBox.h index 2a6d7d411..71e2dbffb 100644 --- a/src/Gui/QuantitySpinBox.h +++ b/src/Gui/QuantitySpinBox.h @@ -46,6 +46,8 @@ class GuiExport QuantitySpinBox : public QAbstractSpinBox, public ExpressionBind Q_PROPERTY(Base::Quantity value READ value WRITE setValue NOTIFY valueChanged USER true) public: + using ExpressionBinding::apply; + explicit QuantitySpinBox(QWidget *parent = 0); virtual ~QuantitySpinBox(); @@ -101,7 +103,6 @@ public: void setExpression(boost::shared_ptr expr); void bind(const App::ObjectIdentifier &_path); bool apply(const std::string &propName); - bool apply(); public Q_SLOTS: /// Sets the field with a quantity