Added boundTo as a property to QuantitySpinBox to enable binding from Python.

This commit is contained in:
Markus Lampert
2017-10-06 17:16:03 -07:00
committed by wmayer
parent fb49c5a078
commit bec9268ba3
3 changed files with 51 additions and 1 deletions

View File

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