Added boundTo as a property to QuantitySpinBox to enable binding from Python.
This commit is contained in:
@@ -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;};
|
||||
|
||||
@@ -43,6 +43,9 @@
|
||||
#include "Command.h"
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/Expression.h>
|
||||
#include <sstream>
|
||||
#include <boost/math/special_functions/round.hpp>
|
||||
@@ -284,6 +287,47 @@ void Gui::QuantitySpinBox::setExpression(boost::shared_ptr<Expression> 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());
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user