diff --git a/src/Gui/ExpressionBinding.h b/src/Gui/ExpressionBinding.h
index b794447aa1..8280dec18d 100644
--- a/src/Gui/ExpressionBinding.h
+++ b/src/Gui/ExpressionBinding.h
@@ -50,7 +50,7 @@ public:
QPixmap getIcon(const char *name, const QSize &size) const;
- //auto apply means that the python code is issues not only on aplly() but
+ //auto apply means that the python code is issued not only on apply() but
//also on setExpression
bool autoApply() const {return m_autoApply;};
void setAutoApply(bool value) {m_autoApply = value;};
diff --git a/src/Gui/QuantitySpinBox.cpp b/src/Gui/QuantitySpinBox.cpp
index 32a0bbd4ca..ce9a81eea8 100644
--- a/src/Gui/QuantitySpinBox.cpp
+++ b/src/Gui/QuantitySpinBox.cpp
@@ -43,6 +43,9 @@
#include "Command.h"
#include
#include
+#include
+#include
+#include
#include
#include
#include
@@ -284,6 +287,47 @@ void Gui::QuantitySpinBox::setExpression(boost::shared_ptr expr)
}
}
+QString QuantitySpinBox::boundToName() const
+{
+ Q_D(const QuantitySpinBox);
+ if (isBound()) {
+ std::string path = getPath().toString();
+ return QString::fromStdString(path);
+ }
+ return QString();
+}
+
+void QuantitySpinBox::setBoundToByName(const QString &qstr)
+{
+ Q_D(QuantitySpinBox);
+ std::string name = qstr.toStdString();
+ size_t pos = name.rfind('.');
+ if (std::string::npos != pos && 0 != pos) {
+ std::string objName = name.substr(0, pos);
+ std::string prpName = name.substr(pos+1);
+ App::Document *doc = App::GetApplication().getActiveDocument();
+ if (doc) {
+ App::DocumentObject *obj = doc->getObject(objName.c_str());
+ if (obj) {
+ App::Property *prop = obj->getPropertyByName(prpName.c_str());
+ if (prop) {
+ App::ObjectIdentifier path(*prop);
+ path.setDocumentObjectName(objName, true);
+ bind(path);
+ } else {
+ printf("%s.%s('%s', '%s'): no prop\n", __FILE__, __FUNCTION__, objName.c_str(), prpName.c_str());
+ }
+ } else {
+ printf("%s.%s('%s', '%s'): no obj\n", __FILE__, __FUNCTION__, objName.c_str(), prpName.c_str());
+ }
+ } else {
+ printf("%s.%s('%s', '%s'): no doc\n", __FILE__, __FUNCTION__, objName.c_str(), prpName.c_str());
+ }
+ } else {
+ printf("%s.%s(%s'): invalid name\n", __FILE__, __FUNCTION__, name.c_str());
+ }
+}
+
void Gui::QuantitySpinBox::onChange() {
Q_ASSERT(isBound());
diff --git a/src/Gui/QuantitySpinBox.h b/src/Gui/QuantitySpinBox.h
index a7fdbf0b8e..4041d29492 100644
--- a/src/Gui/QuantitySpinBox.h
+++ b/src/Gui/QuantitySpinBox.h
@@ -45,6 +45,7 @@ class GuiExport QuantitySpinBox : public QAbstractSpinBox, public ExpressionBind
Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
Q_PROPERTY(double rawValue READ rawValue WRITE setValue NOTIFY valueChanged)
Q_PROPERTY(Base::Quantity value READ value WRITE setValue NOTIFY valueChanged USER true)
+ Q_PROPERTY(QString boundTo READ boundToName WRITE setBoundToByName)
public:
using ExpressionBinding::apply;
@@ -89,6 +90,11 @@ public:
/// Sets the value of the maximum property
void setMaximum(double max);
+ /// Gets the path of the bound property
+ QString boundToName() const;
+ /// Sets the path of the bound property
+ void setBoundToByName(const QString &path);
+
/// Set the number portion selected
void selectNumber();