OSDN Git Service

QmlDesigner.rewriter: string fix
authorThomas Hartmann <Thomas.Hartmann@nokia.com>
Mon, 1 Aug 2011 13:06:50 +0000 (15:06 +0200)
committerThomas Hartmann <Thomas.Hartmann@nokia.com>
Mon, 1 Aug 2011 14:37:57 +0000 (16:37 +0200)
Change-Id: I9a46704c24bdd9ddfd24ba2cf76eb2573f1cf5ef
Reviewed-on: http://codereview.qt.nokia.com/2441
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
src/plugins/qmldesigner/designercore/model/qmltextgenerator.cpp

index 0a29977..2c3d115 100644 (file)
@@ -54,6 +54,14 @@ inline static QString properColorName(const QColor &color)
     return s;
 }
 
+inline static QString doubleToString(double d)
+{
+    QString string = QString::number(d, 'f', 3);
+    if (string.endsWith(".000"))
+        string.chop(4);
+    return string;
+}
+
 QmlTextGenerator::QmlTextGenerator(const QStringList &propertyOrder, int indentDepth):
         m_propertyOrder(propertyOrder),
         m_indentDepth(indentDepth)
@@ -116,7 +124,7 @@ QString QmlTextGenerator::toQml(const AbstractProperty &property, int indentDept
                 return QString(QLatin1String("\"%1\"")).arg(properColorName(value.value<QColor>()));
 
             case QVariant::Double:
-                return QString::number(value.toDouble(), 'f', 3);
+                return doubleToString(value.toDouble());
             case QVariant::Int:
             case QVariant::LongLong:
             case QVariant::UInt: