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);
|
||||
|
||||
// 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;
|
||||
|
||||
if (expr) {
|
||||
|
|
|
@ -180,7 +180,7 @@ bool ExpressionBinding::apply()
|
|||
|
||||
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) {
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
|
||||
//auto apply means that the python code is issues not only on aplly() but
|
||||
//also on setExpression
|
||||
bool autoApply() {return m_autoApply;};
|
||||
bool autoApply() const {return m_autoApply;};
|
||||
void setAutoApply(bool value) {m_autoApply = value;};
|
||||
|
||||
protected:
|
||||
|
|
|
@ -317,10 +317,7 @@ void Gui::QuantitySpinBox::onChange() {
|
|||
QPalette p(lineEdit()->palette());
|
||||
p.setColor(QPalette::Active, QPalette::Text, defaultPalette.color(QPalette::Text));
|
||||
lineEdit()->setPalette(p);
|
||||
<<<<<<< 175351b02ea3a586e1dbe0dc5e993966714ea236
|
||||
=======
|
||||
iconLabel->setToolTip(QString());
|
||||
>>>>>>> further expression integration for property editor
|
||||
}
|
||||
iconLabel->setToolTip(QString());
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ TYPESYSTEM_SOURCE(Gui::PropertyEditor::PropertyItem, Base::BaseClass);
|
|||
PropertyItem::PropertyItem() : parentItem(0), readonly(false), cleared(false)
|
||||
{
|
||||
precision = Base::UnitsApi::getDecimals();
|
||||
setAutoApply(true);
|
||||
}
|
||||
|
||||
PropertyItem::~PropertyItem()
|
||||
|
@ -86,7 +87,8 @@ void PropertyItem::setPropertyData(const std::vector<App::Property*>& items)
|
|||
|
||||
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;
|
||||
|
@ -97,8 +99,9 @@ void PropertyItem::setPropertyData(const std::vector<App::Property*>& items)
|
|||
bind(id);
|
||||
|
||||
}
|
||||
else
|
||||
setReadOnly(true);
|
||||
}
|
||||
//it may happen that setting properties is not possible
|
||||
catch(...) {};
|
||||
}
|
||||
|
||||
propertyItems = items;
|
||||
|
@ -367,11 +370,6 @@ QVariant PropertyItem::data(int column, int role) const
|
|||
|
||||
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;
|
||||
|
||||
// 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)
|
||||
{
|
||||
//if the item has an expression it issues the python code
|
||||
if(!hasExpression()) {
|
||||
if (!value.canConvert(QVariant::Int))
|
||||
return;
|
||||
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
|
||||
|
@ -561,9 +562,10 @@ QWidget* PropertyIntegerItem::createEditor(QWidget* parent, const QObject* recei
|
|||
|
||||
if(isBound()) {
|
||||
sb->bind(getPath());
|
||||
sb->setAutoApply(true);
|
||||
sb->setAutoApply(autoApply());
|
||||
}
|
||||
|
||||
|
||||
return sb;
|
||||
}
|
||||
|
||||
|
@ -608,11 +610,14 @@ QVariant PropertyIntegerConstraintItem::value(const App::Property* prop) const
|
|||
|
||||
void PropertyIntegerConstraintItem::setValue(const QVariant& value)
|
||||
{
|
||||
//if the item has an expression it issues the python code
|
||||
if(!hasExpression()) {
|
||||
if (!value.canConvert(QVariant::Int))
|
||||
return;
|
||||
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
|
||||
|
@ -624,7 +629,7 @@ QWidget* PropertyIntegerConstraintItem::createEditor(QWidget* parent, const QObj
|
|||
|
||||
if(isBound()) {
|
||||
sb->bind(getPath());
|
||||
sb->setAutoApply(true);
|
||||
sb->setAutoApply(autoApply());
|
||||
}
|
||||
|
||||
return sb;
|
||||
|
@ -695,11 +700,14 @@ QVariant PropertyFloatItem::value(const App::Property* prop) const
|
|||
|
||||
void PropertyFloatItem::setValue(const QVariant& value)
|
||||
{
|
||||
//if the item has an expression it issues the python code
|
||||
if(!hasExpression()) {
|
||||
if (!value.canConvert(QVariant::Double))
|
||||
return;
|
||||
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
|
||||
|
@ -712,7 +720,7 @@ QWidget* PropertyFloatItem::createEditor(QWidget* parent, const QObject* receive
|
|||
|
||||
if(isBound()) {
|
||||
sb->bind(getPath());
|
||||
sb->setAutoApply(true);
|
||||
sb->setAutoApply(autoApply());
|
||||
}
|
||||
|
||||
return sb;
|
||||
|
@ -760,12 +768,15 @@ QVariant PropertyUnitItem::value(const App::Property* prop) const
|
|||
|
||||
void PropertyUnitItem::setValue(const QVariant& value)
|
||||
{
|
||||
//if the item has an expression it handles the python code
|
||||
if(!hasExpression()) {
|
||||
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());
|
||||
setPropertyValue(unit);
|
||||
}
|
||||
}
|
||||
|
||||
QWidget* PropertyUnitItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const
|
||||
|
@ -778,9 +789,10 @@ 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(isBound()) {
|
||||
infield->bind(getPath());
|
||||
infield->setAutoApply(true);
|
||||
infield->setAutoApply(autoApply());
|
||||
}
|
||||
|
||||
|
||||
QObject::connect(infield, SIGNAL(valueChanged(double)), receiver, method);
|
||||
return infield;
|
||||
}
|
||||
|
@ -860,11 +872,14 @@ QVariant PropertyFloatConstraintItem::value(const App::Property* prop) const
|
|||
|
||||
void PropertyFloatConstraintItem::setValue(const QVariant& value)
|
||||
{
|
||||
//if the item has an expression it issues the python code
|
||||
if(!hasExpression()) {
|
||||
if (!value.canConvert(QVariant::Double))
|
||||
return;
|
||||
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
|
||||
|
@ -877,9 +892,10 @@ QWidget* PropertyFloatConstraintItem::createEditor(QWidget* parent, const QObjec
|
|||
|
||||
if(isBound()) {
|
||||
sb->bind(getPath());
|
||||
sb->setAutoApply(true);
|
||||
sb->setAutoApply(autoApply());
|
||||
}
|
||||
|
||||
|
||||
return sb;
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ void PropertyConstraintListItem::initialize()
|
|||
}
|
||||
|
||||
item->bind(list->createPath(id-1));
|
||||
item->setAutoApply(true);
|
||||
item->setAutoApply(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user