forked from qt-creator/qt-creator
QmlDesigner: Increase precision for float properties
The precision for float properties in QML was quite low. We keep the reduced precision for a few known 2d related properties, but increase it in general. Task-number: QDS-2190 Change-Id: Ie82ac03485aa52f9b400151153ccaf37a80e39b0 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -49,9 +49,16 @@ inline static QString properColorName(const QColor &color)
|
||||
return QString::asprintf("#%02x%02x%02x%02x", color.alpha(), color.red(), color.green(), color.blue());
|
||||
}
|
||||
|
||||
inline static QString doubleToString(double d)
|
||||
inline static QString doubleToString(const PropertyName &propertyName, double d)
|
||||
{
|
||||
QString string = QString::number(d, 'f', 3);
|
||||
static QVector<PropertyName> lowPrecisionProperties
|
||||
= {"width", "height", "x", "y", "rotation", "scale", "opacity"};
|
||||
int precision = 5;
|
||||
if (propertyName.contains("anchors") || propertyName.contains("font")
|
||||
|| lowPrecisionProperties.contains(propertyName))
|
||||
precision = 3;
|
||||
|
||||
QString string = QString::number(d, 'f', precision);
|
||||
if (string.contains(QLatin1Char('.'))) {
|
||||
while (string.at(string.length()- 1) == QLatin1Char('0'))
|
||||
string.chop(1);
|
||||
@@ -142,7 +149,7 @@ QString QmlTextGenerator::toQml(const AbstractProperty &property, int indentDept
|
||||
|
||||
case QMetaType::Float:
|
||||
case QMetaType::Double:
|
||||
return doubleToString(value.toDouble());
|
||||
return doubleToString(property.name(), value.toDouble());
|
||||
case QMetaType::Int:
|
||||
case QMetaType::LongLong:
|
||||
case QMetaType::UInt:
|
||||
|
Reference in New Issue
Block a user