Expressions: Fix property editor behavior
- change responsibility of python code emition - Correct python code handling for expressions - handle constraints expressions handling
This commit is contained in:
parent
580a4e15d1
commit
dcad131357
|
@ -317,7 +317,8 @@ void PropertyExpressionEngine::setValue(const ObjectIdentifier & path, boost::sh
|
||||||
prop->getPathValue(usePath);
|
prop->getPathValue(usePath);
|
||||||
|
|
||||||
// Check if the current expression equals the new one and do nothing if so to reduce unneeded computations
|
// Check if the current expression equals the new one and do nothing if so to reduce unneeded computations
|
||||||
if(expressions.find(usePath) != expressions.end() && expr == expressions[usePath].expression)
|
ExpressionMap::iterator it = expressions.find(usePath);
|
||||||
|
if(it != expressions.end() && expr == it->second.expression)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (expr) {
|
if (expr) {
|
||||||
|
|
|
@ -180,7 +180,7 @@ bool ExpressionBinding::apply()
|
||||||
|
|
||||||
std::string name = docObj->getNameInDocument();
|
std::string name = docObj->getNameInDocument();
|
||||||
|
|
||||||
return apply("App.ActiveDocument." + name + "." + std::string(prop->getName()));
|
return apply("App.ActiveDocument." + name + "." + getPath().toEscapedString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpressionBinding::expressionChange(const ObjectIdentifier& id) {
|
void ExpressionBinding::expressionChange(const ObjectIdentifier& id) {
|
||||||
|
|
|
@ -52,7 +52,7 @@ public:
|
||||||
|
|
||||||
//auto apply means that the python code is issues not only on aplly() but
|
//auto apply means that the python code is issues not only on aplly() but
|
||||||
//also on setExpression
|
//also on setExpression
|
||||||
bool autoApply() {return m_autoApply;};
|
bool autoApply() const {return m_autoApply;};
|
||||||
void setAutoApply(bool value) {m_autoApply = value;};
|
void setAutoApply(bool value) {m_autoApply = value;};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -317,10 +317,7 @@ void Gui::QuantitySpinBox::onChange() {
|
||||||
QPalette p(lineEdit()->palette());
|
QPalette p(lineEdit()->palette());
|
||||||
p.setColor(QPalette::Active, QPalette::Text, defaultPalette.color(QPalette::Text));
|
p.setColor(QPalette::Active, QPalette::Text, defaultPalette.color(QPalette::Text));
|
||||||
lineEdit()->setPalette(p);
|
lineEdit()->setPalette(p);
|
||||||
<<<<<<< 175351b02ea3a586e1dbe0dc5e993966714ea236
|
|
||||||
=======
|
|
||||||
iconLabel->setToolTip(QString());
|
iconLabel->setToolTip(QString());
|
||||||
>>>>>>> further expression integration for property editor
|
|
||||||
}
|
}
|
||||||
iconLabel->setToolTip(QString());
|
iconLabel->setToolTip(QString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ TYPESYSTEM_SOURCE(Gui::PropertyEditor::PropertyItem, Base::BaseClass);
|
||||||
PropertyItem::PropertyItem() : parentItem(0), readonly(false), cleared(false)
|
PropertyItem::PropertyItem() : parentItem(0), readonly(false), cleared(false)
|
||||||
{
|
{
|
||||||
precision = Base::UnitsApi::getDecimals();
|
precision = Base::UnitsApi::getDecimals();
|
||||||
|
setAutoApply(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
PropertyItem::~PropertyItem()
|
PropertyItem::~PropertyItem()
|
||||||
|
@ -86,19 +87,21 @@ void PropertyItem::setPropertyData(const std::vector<App::Property*>& items)
|
||||||
|
|
||||||
const App::Property& p = *items.front();
|
const App::Property& p = *items.front();
|
||||||
|
|
||||||
if(!(p.getContainer()->getPropertyType(&p) & App::Prop_ReadOnly)) {
|
try {
|
||||||
|
if(!(p.getContainer()->isReadOnly(&p))) {
|
||||||
App::ObjectIdentifier id(p);
|
|
||||||
std::vector<App::ObjectIdentifier> paths;
|
App::ObjectIdentifier id(p);
|
||||||
p.getPaths(paths);
|
std::vector<App::ObjectIdentifier> paths;
|
||||||
|
p.getPaths(paths);
|
||||||
//there may be no paths available in this property (for example an empty constraint list)
|
|
||||||
if(id.getProperty() && !paths.empty())
|
//there may be no paths available in this property (for example an empty constraint list)
|
||||||
bind(id);
|
if(id.getProperty() && !paths.empty())
|
||||||
|
bind(id);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
//it may happen that setting properties is not possible
|
||||||
setReadOnly(true);
|
catch(...) {};
|
||||||
}
|
}
|
||||||
|
|
||||||
propertyItems = items;
|
propertyItems = items;
|
||||||
|
@ -247,26 +250,26 @@ QString PropertyItem::pythonIdentifier(const App::Property* prop) const
|
||||||
if (parent->getTypeId() == App::Document::getClassTypeId()) {
|
if (parent->getTypeId() == App::Document::getClassTypeId()) {
|
||||||
App::Document* doc = static_cast<App::Document*>(parent);
|
App::Document* doc = static_cast<App::Document*>(parent);
|
||||||
QString docName = QString::fromAscii(App::GetApplication().getDocumentName(doc));
|
QString docName = QString::fromAscii(App::GetApplication().getDocumentName(doc));
|
||||||
QString propName = QString::fromAscii(parent->getPropertyName(prop));
|
QString propName = QString::fromAscii(parent->getPropertyName(prop));
|
||||||
return QString::fromAscii("FreeCAD.getDocument(\"%1\").%2").arg(docName).arg(propName);
|
return QString::fromAscii("FreeCAD.getDocument(\"%1\").%2").arg(docName).arg(propName);
|
||||||
}
|
}
|
||||||
if (parent->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId())) {
|
if (parent->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId())) {
|
||||||
App::DocumentObject* obj = static_cast<App::DocumentObject*>(parent);
|
App::DocumentObject* obj = static_cast<App::DocumentObject*>(parent);
|
||||||
App::Document* doc = obj->getDocument();
|
App::Document* doc = obj->getDocument();
|
||||||
QString docName = QString::fromAscii(App::GetApplication().getDocumentName(doc));
|
QString docName = QString::fromAscii(App::GetApplication().getDocumentName(doc));
|
||||||
QString objName = QString::fromAscii(obj->getNameInDocument());
|
QString objName = QString::fromAscii(obj->getNameInDocument());
|
||||||
QString propName = QString::fromAscii(parent->getPropertyName(prop));
|
QString propName = QString::fromAscii(parent->getPropertyName(prop));
|
||||||
return QString::fromAscii("FreeCAD.getDocument(\"%1\").getObject(\"%2\").%3")
|
return QString::fromAscii("FreeCAD.getDocument(\"%1\").getObject(\"%2\").%3")
|
||||||
.arg(docName).arg(objName).arg(propName);
|
.arg(docName).arg(objName).arg(propName);
|
||||||
}
|
}
|
||||||
if (parent->getTypeId().isDerivedFrom(Gui::ViewProviderDocumentObject::getClassTypeId())) {
|
if (parent->getTypeId().isDerivedFrom(Gui::ViewProviderDocumentObject::getClassTypeId())) {
|
||||||
App::DocumentObject* obj = static_cast<Gui::ViewProviderDocumentObject*>(parent)->getObject();
|
App::DocumentObject* obj = static_cast<Gui::ViewProviderDocumentObject*>(parent)->getObject();
|
||||||
App::Document* doc = obj->getDocument();
|
App::Document* doc = obj->getDocument();
|
||||||
QString docName = QString::fromAscii(App::GetApplication().getDocumentName(doc));
|
QString docName = QString::fromAscii(App::GetApplication().getDocumentName(doc));
|
||||||
QString objName = QString::fromAscii(obj->getNameInDocument());
|
QString objName = QString::fromAscii(obj->getNameInDocument());
|
||||||
QString propName = QString::fromAscii(parent->getPropertyName(prop));
|
QString propName = QString::fromAscii(parent->getPropertyName(prop));
|
||||||
return QString::fromAscii("FreeCADGui.getDocument(\"%1\").getObject(\"%2\").%3")
|
return QString::fromAscii("FreeCADGui.getDocument(\"%1\").getObject(\"%2\").%3")
|
||||||
.arg(docName).arg(objName).arg(propName);
|
.arg(docName).arg(objName).arg(propName);
|
||||||
}
|
}
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
@ -366,12 +369,7 @@ QVariant PropertyItem::data(int column, int role) const
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PropertyItem::setData (const QVariant& value)
|
bool PropertyItem::setData (const QVariant& value)
|
||||||
{
|
{
|
||||||
//check if we have an expression set. If so we do nothing, as than the editor is responsible
|
|
||||||
//for issuing the relevant python code
|
|
||||||
if(hasExpression())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
cleared = false;
|
cleared = false;
|
||||||
|
|
||||||
// This is the basic mechanism to set the value to
|
// This is the basic mechanism to set the value to
|
||||||
|
@ -545,11 +543,14 @@ QVariant PropertyIntegerItem::value(const App::Property* prop) const
|
||||||
|
|
||||||
void PropertyIntegerItem::setValue(const QVariant& value)
|
void PropertyIntegerItem::setValue(const QVariant& value)
|
||||||
{
|
{
|
||||||
if (!value.canConvert(QVariant::Int))
|
//if the item has an expression it issues the python code
|
||||||
return;
|
if(!hasExpression()) {
|
||||||
int val = value.toInt();
|
if (!value.canConvert(QVariant::Int))
|
||||||
QString data = QString::fromAscii("%1").arg(val);
|
return;
|
||||||
setPropertyValue(data);
|
int val = value.toInt();
|
||||||
|
QString data = QString::fromAscii("%1").arg(val);
|
||||||
|
setPropertyValue(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* PropertyIntegerItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const
|
QWidget* PropertyIntegerItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const
|
||||||
|
@ -561,8 +562,9 @@ QWidget* PropertyIntegerItem::createEditor(QWidget* parent, const QObject* recei
|
||||||
|
|
||||||
if(isBound()) {
|
if(isBound()) {
|
||||||
sb->bind(getPath());
|
sb->bind(getPath());
|
||||||
sb->setAutoApply(true);
|
sb->setAutoApply(autoApply());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return sb;
|
return sb;
|
||||||
}
|
}
|
||||||
|
@ -608,11 +610,14 @@ QVariant PropertyIntegerConstraintItem::value(const App::Property* prop) const
|
||||||
|
|
||||||
void PropertyIntegerConstraintItem::setValue(const QVariant& value)
|
void PropertyIntegerConstraintItem::setValue(const QVariant& value)
|
||||||
{
|
{
|
||||||
if (!value.canConvert(QVariant::Int))
|
//if the item has an expression it issues the python code
|
||||||
return;
|
if(!hasExpression()) {
|
||||||
int val = value.toInt();
|
if (!value.canConvert(QVariant::Int))
|
||||||
QString data = QString::fromAscii("%1").arg(val);
|
return;
|
||||||
setPropertyValue(data);
|
int val = value.toInt();
|
||||||
|
QString data = QString::fromAscii("%1").arg(val);
|
||||||
|
setPropertyValue(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* PropertyIntegerConstraintItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const
|
QWidget* PropertyIntegerConstraintItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const
|
||||||
|
@ -624,8 +629,8 @@ QWidget* PropertyIntegerConstraintItem::createEditor(QWidget* parent, const QObj
|
||||||
|
|
||||||
if(isBound()) {
|
if(isBound()) {
|
||||||
sb->bind(getPath());
|
sb->bind(getPath());
|
||||||
sb->setAutoApply(true);
|
sb->setAutoApply(autoApply());
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb;
|
return sb;
|
||||||
}
|
}
|
||||||
|
@ -695,11 +700,14 @@ QVariant PropertyFloatItem::value(const App::Property* prop) const
|
||||||
|
|
||||||
void PropertyFloatItem::setValue(const QVariant& value)
|
void PropertyFloatItem::setValue(const QVariant& value)
|
||||||
{
|
{
|
||||||
if (!value.canConvert(QVariant::Double))
|
//if the item has an expression it issues the python code
|
||||||
return;
|
if(!hasExpression()) {
|
||||||
double val = value.toDouble();
|
if (!value.canConvert(QVariant::Double))
|
||||||
QString data = QString::fromAscii("%1").arg(val,0,'f',decimals());
|
return;
|
||||||
setPropertyValue(data);
|
double val = value.toDouble();
|
||||||
|
QString data = QString::fromAscii("%1").arg(val,0,'f',decimals());
|
||||||
|
setPropertyValue(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* PropertyFloatItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const
|
QWidget* PropertyFloatItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const
|
||||||
|
@ -712,7 +720,7 @@ QWidget* PropertyFloatItem::createEditor(QWidget* parent, const QObject* receive
|
||||||
|
|
||||||
if(isBound()) {
|
if(isBound()) {
|
||||||
sb->bind(getPath());
|
sb->bind(getPath());
|
||||||
sb->setAutoApply(true);
|
sb->setAutoApply(autoApply());
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb;
|
return sb;
|
||||||
|
@ -760,12 +768,15 @@ QVariant PropertyUnitItem::value(const App::Property* prop) const
|
||||||
|
|
||||||
void PropertyUnitItem::setValue(const QVariant& value)
|
void PropertyUnitItem::setValue(const QVariant& value)
|
||||||
{
|
{
|
||||||
if (!value.canConvert<Base::Quantity>())
|
//if the item has an expression it handles the python code
|
||||||
return;
|
if(!hasExpression()) {
|
||||||
const Base::Quantity& val = value.value<Base::Quantity>();
|
if (!value.canConvert<Base::Quantity>())
|
||||||
|
return;
|
||||||
|
const Base::Quantity& val = value.value<Base::Quantity>();
|
||||||
|
|
||||||
QString unit = QString::fromLatin1("'%1 %2'").arg(val.getValue()).arg(val.getUnit().getString());
|
QString unit = QString::fromLatin1("'%1 %2'").arg(val.getValue()).arg(val.getUnit().getString());
|
||||||
setPropertyValue(unit);
|
setPropertyValue(unit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* PropertyUnitItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const
|
QWidget* PropertyUnitItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const
|
||||||
|
@ -778,8 +789,9 @@ QWidget* PropertyUnitItem::createEditor(QWidget* parent, const QObject* receiver
|
||||||
//if we are bound to an expression we need to bind it to the input field
|
//if we are bound to an expression we need to bind it to the input field
|
||||||
if(isBound()) {
|
if(isBound()) {
|
||||||
infield->bind(getPath());
|
infield->bind(getPath());
|
||||||
infield->setAutoApply(true);
|
infield->setAutoApply(autoApply());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QObject::connect(infield, SIGNAL(valueChanged(double)), receiver, method);
|
QObject::connect(infield, SIGNAL(valueChanged(double)), receiver, method);
|
||||||
return infield;
|
return infield;
|
||||||
|
@ -860,11 +872,14 @@ QVariant PropertyFloatConstraintItem::value(const App::Property* prop) const
|
||||||
|
|
||||||
void PropertyFloatConstraintItem::setValue(const QVariant& value)
|
void PropertyFloatConstraintItem::setValue(const QVariant& value)
|
||||||
{
|
{
|
||||||
if (!value.canConvert(QVariant::Double))
|
//if the item has an expression it issues the python code
|
||||||
return;
|
if(!hasExpression()) {
|
||||||
double val = value.toDouble();
|
if (!value.canConvert(QVariant::Double))
|
||||||
QString data = QString::fromAscii("%1").arg(val,0,'f',decimals());
|
return;
|
||||||
setPropertyValue(data);
|
double val = value.toDouble();
|
||||||
|
QString data = QString::fromAscii("%1").arg(val,0,'f',decimals());
|
||||||
|
setPropertyValue(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* PropertyFloatConstraintItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const
|
QWidget* PropertyFloatConstraintItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const
|
||||||
|
@ -877,8 +892,9 @@ QWidget* PropertyFloatConstraintItem::createEditor(QWidget* parent, const QObjec
|
||||||
|
|
||||||
if(isBound()) {
|
if(isBound()) {
|
||||||
sb->bind(getPath());
|
sb->bind(getPath());
|
||||||
sb->setAutoApply(true);
|
sb->setAutoApply(autoApply());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return sb;
|
return sb;
|
||||||
}
|
}
|
||||||
|
@ -2317,7 +2333,7 @@ QVariant PropertyPathItem::toolTip(const App::Property* prop) const
|
||||||
QWidget* PropertyPathItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const
|
QWidget* PropertyPathItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const
|
||||||
{
|
{
|
||||||
Gui::FileChooser *fc = new Gui::FileChooser(parent);
|
Gui::FileChooser *fc = new Gui::FileChooser(parent);
|
||||||
fc->setMode(FileChooser::Directory);
|
fc->setMode(FileChooser::Directory);
|
||||||
fc->setAutoFillBackground(true);
|
fc->setAutoFillBackground(true);
|
||||||
fc->setDisabled(isReadOnly());
|
fc->setDisabled(isReadOnly());
|
||||||
QObject::connect(fc, SIGNAL(fileNameSelected(const QString&)), receiver, method);
|
QObject::connect(fc, SIGNAL(fileNameSelected(const QString&)), receiver, method);
|
||||||
|
|
|
@ -103,7 +103,7 @@ void PropertyConstraintListItem::initialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
item->bind(list->createPath(id-1));
|
item->bind(list->createPath(id-1));
|
||||||
item->setAutoApply(true);
|
item->setAutoApply(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user