diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index c6b8bd3044..4c996ff0c5 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -25,6 +25,7 @@ #ifndef _PreComp_ #include +#include #include #include #include @@ -842,14 +843,9 @@ QVariant PropertyStringItem::value(const App::Property* prop) const void PropertyStringItem::setValue(const QVariant& value) { - if (!hasExpression()) { - if (!value.canConvert()) { - return; - } - QString val = value.toString(); - val = QString::fromUtf8(Base::InterpreterSingleton::strToPython(val.toUtf8()).c_str()); - QString data = QString::fromLatin1("\"%1\"").arg(val); - setPropertyValue(data); + if (!hasExpression() && value.canConvert()) { + std::string val = Base::InterpreterSingleton::strToPython(value.toString().toStdString()); + setPropertyValue(Base::Tools::quoted(val)); } } @@ -896,13 +892,9 @@ QVariant PropertyFontItem::value(const App::Property* prop) const void PropertyFontItem::setValue(const QVariant& value) { - if (hasExpression() || !value.canConvert()) { - return; + if (!hasExpression() && value.canConvert()) { + setPropertyValue(Base::Tools::quoted(value.toString().toStdString())); } - - QString val = value.toString(); - QString data = QString::fromLatin1("\"%1\"").arg(val); - setPropertyValue(data); } QWidget* PropertyFontItem::createEditor(QWidget* parent, const std::function& method) const @@ -966,13 +958,9 @@ 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()) { - return; - } + if (!hasExpression() && value.canConvert()) { int val = value.toInt(); - QString data = QString::fromLatin1("%1").arg(val); - setPropertyValue(data); + setPropertyValue(std::to_string(val)); } } @@ -1035,13 +1023,9 @@ 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()) { - return; - } + if (!hasExpression() && value.canConvert()) { int val = value.toInt(); - QString data = QString::fromLatin1("%1").arg(val); - setPropertyValue(data); + setPropertyValue(std::to_string(val)); } } @@ -1133,13 +1117,10 @@ 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()) { - return; - } - double val = value.toDouble(); - QString data = QString::fromLatin1("%1").arg(val, 0, 'g', highPrec); - setPropertyValue(data); + if (!hasExpression() && value.canConvert()) { + std::ostringstream ss; + ss << std::setprecision(highPrec) << value.toDouble(); + setPropertyValue(ss.str()); } } @@ -1202,12 +1183,8 @@ 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()) { - return; - } + if (!hasExpression() && value.canConvert()) { const Base::Quantity& val = value.value(); - Base::QuantityFormat format(Base::QuantityFormat::Default, highPrec); QString unit = Base::UnitsApi::toString(val, format); setPropertyValue(unit); @@ -1305,13 +1282,10 @@ 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()) { - return; - } - double val = value.toDouble(); - QString data = QString::fromLatin1("%1").arg(val, 0, 'g', highPrec); - setPropertyValue(data); + if (!hasExpression() && value.canConvert()) { + std::ostringstream ss; + ss << std::setprecision(highPrec) << value.toDouble(); + setPropertyValue(ss.str()); } } @@ -1403,12 +1377,10 @@ QVariant PropertyBoolItem::value(const App::Property* prop) const void PropertyBoolItem::setValue(const QVariant& value) { - if (hasExpression() || !value.canConvert()) { - return; + if (!hasExpression() && value.canConvert()) { + std::string val = value.toBool() ? "True" : "False"; + setPropertyValue(val); } - bool val = value.toBool(); - QString data = (val ? QLatin1String("True") : QLatin1String("False")); - setPropertyValue(data); } QWidget* PropertyBoolItem::createEditor(QWidget* parent, const std::function& method) const @@ -3012,28 +2984,26 @@ void PropertyEnumItem::setValue(const QVariant& value) return; } - QString data; + std::ostringstream ss; if (value.userType() == QMetaType::QStringList) { QStringList values = value.toStringList(); - QTextStream str(&data); - str << "["; + ss << "["; for (const auto& it : values) { QString text(it); text.replace(QString::fromUtf8("'"), QString::fromUtf8("\\'")); - std::string pystr = Base::Tools::escapedUnicodeFromUtf8(text.toUtf8()); - pystr = Base::InterpreterSingleton::strToPython(pystr.c_str()); - str << "u\"" << pystr.c_str() << "\", "; + std::string str = Base::Tools::escapedUnicodeFromUtf8(text.toUtf8()); + str = Base::InterpreterSingleton::strToPython(str); + ss << "u\"" << str << "\", "; } - str << "]"; - setPropertyValue(data); + ss << "]"; + setPropertyValue(ss.str()); } else if (value.canConvert()) { - QByteArray val = value.toString().toUtf8(); - std::string str = Base::Tools::escapedUnicodeFromUtf8(val); - data = QString::fromLatin1("u\"%1\"").arg(QString::fromStdString(str)); - setPropertyValue(data); + std::string str = Base::Tools::escapedUnicodeFromUtf8(value.toString().toUtf8()); + ss << "u\"" << str << "\""; + setPropertyValue(ss.str()); } } @@ -3282,22 +3252,17 @@ void PropertyStringListItem::setValue(const QVariant& value) if (hasExpression() || !value.canConvert()) { return; } - QStringList values = value.toStringList(); - QString data; - QTextStream str(&data); -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - str.setCodec("UTF-8"); -#endif - str << "["; + QStringList values = value.toStringList(); + std::ostringstream ss; + ss << "["; for (const auto& it : values) { QString text(it); std::string pystr = Base::InterpreterSingleton::strToPython(text.toUtf8().constData()); - str << "\"" << QString::fromUtf8(pystr.c_str()) << "\", "; + ss << "\"" << pystr << "\", "; } - str << "]"; - - setPropertyValue(data); + ss << "]"; + setPropertyValue(ss.str()); } // --------------------------------------------------------------- @@ -3363,17 +3328,18 @@ void PropertyFloatListItem::setValue(const QVariant& value) if (hasExpression() || !value.canConvert()) { return; } + QStringList values = value.toStringList(); QString data; QTextStream str(&data); str << "["; - for (const auto& it : values) { - str << it << ","; + for (auto it = values.begin(); it != values.end(); ++it) { + if (it != values.begin()) { + str << ","; + } + str << *it; } str << "]"; - if (data == QString::fromUtf8("[,]")) { - data = QString::fromUtf8("[]"); - } setPropertyValue(data); } @@ -3441,17 +3407,18 @@ void PropertyIntegerListItem::setValue(const QVariant& value) if (hasExpression() || !value.canConvert()) { return; } + QStringList values = value.toStringList(); QString data; QTextStream str(&data); str << "["; - for (const auto& value : values) { - str << value << ","; + for (auto it = values.begin(); it != values.end(); ++it) { + if (it != values.begin()) { + str << ","; + } + str << *it; } str << "]"; - if (data == QString::fromUtf8("[,]")) { - data = QString::fromUtf8("[]"); - } setPropertyValue(data); } @@ -4426,12 +4393,9 @@ QVariant PropertyFileItem::value(const App::Property* prop) const void PropertyFileItem::setValue(const QVariant& value) { - if (hasExpression() || !value.canConvert()) { - return; + if (!hasExpression() && value.canConvert()) { + setPropertyValue(Base::Tools::quoted(value.toString().toStdString())); } - QString val = value.toString(); - QString data = QString::fromLatin1("\"%1\"").arg(val); - setPropertyValue(data); } QVariant PropertyFileItem::toolTip(const App::Property* prop) const @@ -4483,13 +4447,9 @@ QVariant PropertyPathItem::value(const App::Property* prop) const void PropertyPathItem::setValue(const QVariant& value) { - if (hasExpression() || !value.canConvert()) { - return; + if (!hasExpression() && value.canConvert()) { + setPropertyValue(Base::Tools::quoted(value.toString().toStdString())); } - - QString val = value.toString(); - QString data = QString::fromLatin1("\"%1\"").arg(val); - setPropertyValue(data); } QVariant PropertyPathItem::toolTip(const App::Property* prop) const @@ -4535,13 +4495,9 @@ QVariant PropertyTransientFileItem::value(const App::Property* prop) const void PropertyTransientFileItem::setValue(const QVariant& value) { - if (hasExpression() || !value.canConvert()) { - return; + if (!hasExpression() && value.canConvert()) { + setPropertyValue(Base::Tools::quoted(value.toString().toStdString())); } - - QString val = value.toString(); - QString data = QString::fromLatin1("\"%1\"").arg(val); - setPropertyValue(data); } QVariant PropertyTransientFileItem::toolTip(const App::Property* prop) const