From ddeef6318966948710c09f449cd006b55d5a2ba4 Mon Sep 17 00:00:00 2001
From: Thomas Hartmann <Thomas.Hartmann@nokia.com>
Date: Mon, 18 Jul 2011 13:18:40 +0200
Subject: [PATCH] QmlDesigner.propertyEditor: bugfix for assert

Since the linedit in the property editor has an input mask,
propery names like "red" are not handled correctly.

Change-Id: I43ec2f7e42de7f57d78c97b6865ea36c4e11b3fb
Solution: We normalize "red" to "#ff0000" in the property editor.
Task-number: QTCREATORBUG-5479
Reviewed-on: http://codereview.qt.nokia.com/1749
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Marco Bubke <marco.bubke@nokia.com>
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
---
 .../propertyeditor/propertyeditorvalue.cpp     | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp
index a6d7019858f..e55e4c466df 100644
--- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp
+++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorvalue.cpp
@@ -96,6 +96,22 @@ static bool cleverColorCompare(QVariant value1, QVariant value2)
     return false;
 }
 
+
+/* "red" is the same color as "#ff0000"
+  To simplify editing we convert all explicit color names in the hash format */
+static void fixAmbigousColorNames(const QmlDesigner::ModelNode &modelNode, const QString &name, QVariant *value)
+{
+    if (modelNode.isValid() && modelNode.metaInfo().isValid()
+            && (modelNode.metaInfo().propertyTypeName(name) == "QColor"
+                || modelNode.metaInfo().propertyTypeName(name) == "color")) {
+        if ((value->type() == QVariant::Color)) {
+            *value = QColor(value->value<QColor>().name());
+        } else {
+            *value = QColor(value->toString()).name();
+        }
+    }
+}
+
 void PropertyEditorValue::setValueWithEmit(const QVariant &value)
 {
     if (m_value != value || isBound()) {
@@ -125,6 +141,8 @@ void PropertyEditorValue::setValue(const QVariant &value)
 
         m_value = value;
 
+    fixAmbigousColorNames(modelNode(), name(), &m_value);
+
     if (m_value.isValid())
         emit valueChangedQml();
     emit isBoundChanged();
-- 
GitLab