From f573157ca0421b9754128585b4d54c0254f1a60a Mon Sep 17 00:00:00 2001
From: Caroline Chao <caroline.chao@digia.com>
Date: Mon, 22 Apr 2013 12:43:45 +0200
Subject: [PATCH] ComboBox: Arrays of strings don't have textRole.

Don't return a get function when the model is an array and
the return value is a string. So resolveTextValue() won't try
to retrieve a textRole in that case.

Change-Id: Ifc85eacc67accd34d63805487e20ae5829523c14
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
---
 src/controls/ComboBox.qml                 |  3 ++-
 tests/auto/controls/data/tst_combobox.qml | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/controls/ComboBox.qml b/src/controls/ComboBox.qml
index e09e276b4..110e3db1a 100644
--- a/src/controls/ComboBox.qml
+++ b/src/controls/ComboBox.qml
@@ -164,7 +164,8 @@ Control {
 
             var get = model['get'];
             if (!get && popup.__modelIsArray) {
-                get = function(i) { return model[i]; }
+                if (model[0].constructor !== String) // arrays of strings don't have textRole
+                    get = function(i) { return model[i]; }
             }
 
             var modelMayHaveRoles = get !== undefined
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index fc1353544..d3bd27916 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -133,6 +133,16 @@ TestCase {
         comboBox.destroy()
     }
 
+    function test_arrayModelWithoutTextRole() {
+        var arrayModel = ['Banana', 'Coconut', 'Apple']
+
+        var comboBox = Qt.createQmlObject('import QtQuick.Controls 1.0 ; ComboBox {}', testCase, '');
+        comboBox.model = arrayModel
+        compare(comboBox.currentIndex, 0)
+        compare(comboBox.currentText, "Banana")
+        comboBox.destroy()
+    }
+
     function test_activeFocusOnTab() {
         var test_control = 'import QtQuick 2.1; \
         import QtQuick.Controls 1.0;            \
-- 
GitLab