From 001b93d9cbd2ba56b99ff03e15681605d7b6734f Mon Sep 17 00:00:00 2001
From: Thomas Hartmann <Thomas.Hartmann@digia.com>
Date: Mon, 19 May 2014 18:52:06 +0200
Subject: [PATCH] QmlDesigner.PropertyEditor: Fix ComboBox

We have to wait until the model is properly set until we react
to currentTextChanged. We also have to guard against binding loops.

Task-number: QTCREATORBUG-12257
Change-Id: Id602f6f192962e83a6166bf24a0711b22baa7868
Reviewed-by: Marco Bubke <marco.bubke@digia.com>
---
 .../HelperWidgets/ComboBox.qml                | 30 +++++++++++++++----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/ComboBox.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/ComboBox.qml
index dfc408f5e2f..2c90e1b73e3 100644
--- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/ComboBox.qml
+++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/ComboBox.qml
@@ -41,33 +41,53 @@ Controls.ComboBox {
 
     property bool useInteger: false
 
+    property bool __isCompleted: false
+
     ColorLogic {
         id: colorLogic
         backendValue: comboBox.backendValue
         onValueFromBackendChanged: {
-            if (!comboBox.useInt) {
+            invalidate();
+        }
+
+        function invalidate() {
+            if (!comboBox.useInteger) {
                 var enumString = comboBox.backendValue.enumeration;
+
                 if (enumString === "")
                     enumString = comboBox.backendValue.value
-                comboBox.currentIndex = comboBox.find(enumString);
+
+                var index = comboBox.find(enumString)
+
+                if (index !== comboBox.currentIndex)
+                    comboBox.currentIndex = comboBox.find(enumString)
+
             } else {
-                comboBox.currentIndex = backendValue.value
+                if (comboBox.currentIndex !== backendValue.value)
+                    comboBox.currentIndex = backendValue.value
             }
         }
     }
 
     onCurrentTextChanged: {
+        if (!__isCompleted)
+            return;
+
         if (backendValue === undefined)
             return;
 
-        if (!comboBox.useInt) {
+        if (!comboBox.useInteger) {
             backendValue.setEnumeration(comboBox.scope, comboBox.currentText);
         } else {
-            print("useint" + comboBox.currentIndex)
             backendValue.value = comboBox.currentIndex;
         }
     }
 
+    Component.onCompleted: {
+        colorLogic.invalidate()
+        __isCompleted = true;
+    }
+
     style: CustomComboBoxStyle {
         textColor: comboBox.textColor
     }
-- 
GitLab