summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@digia.com>2013-11-26 14:59:10 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-26 15:21:38 +0100
commit6ab374f0fd530c841470f93c8befb92f1f646470 (patch)
tree4811ff4f1d8eb383cf7e0f08f4892bfbb61e4c51
parentefc340f2504bf7faa3591e4b53af0000a963089e (diff)
downloadqtquickcontrols-6ab374f0fd530c841470f93c8befb92f1f646470.tar.gz
ComboBox: Call resolveTextValue() after any model change
Particularly if the nature of the model has changed (e.g., from null to array). Task-number: QTBUG-34936 Change-Id: If07690a8836dcd786ed7a32afda1e344d048d31f Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
-rw-r--r--src/controls/ComboBox.qml8
-rw-r--r--tests/auto/controls/data/tst_combobox.qml16
2 files changed, 14 insertions, 10 deletions
diff --git a/src/controls/ComboBox.qml b/src/controls/ComboBox.qml
index db39f579..ad28efb5 100644
--- a/src/controls/ComboBox.qml
+++ b/src/controls/ComboBox.qml
@@ -432,7 +432,7 @@ Control {
property ExclusiveGroup eg: ExclusiveGroup { id: eg }
- property bool __modelIsArray: popupItems.model ? popupItems.model.constructor === Array : false
+ property bool modelIsArray: false
Instantiator {
id: popupItems
@@ -440,6 +440,7 @@ Control {
property bool updatingModel: false
onModelChanged: {
+ popup.modelIsArray = !!model ? model.constructor === Array : false
if (active) {
if (updatingModel && popup.__selectedIndex === 0) {
// We still want to update the currentText
@@ -449,12 +450,13 @@ Control {
popup.__selectedIndex = 0
}
}
+ popup.resolveTextValue(comboBox.textRole)
}
MenuItem {
text: popup.textRole === '' ?
modelData :
- ((popup.__modelIsArray ? modelData[popup.textRole] : model[popup.textRole]) || '')
+ ((popup.modelIsArray ? modelData[popup.textRole] : model[popup.textRole]) || '')
onTriggered: {
if (index !== currentIndex)
activated(index)
@@ -479,7 +481,7 @@ Control {
}
var get = model['get'];
- if (!get && popup.__modelIsArray) {
+ if (!get && popup.modelIsArray && !!model[0]) {
if (model[0].constructor !== String && model[0].constructor !== Number)
get = function(i) { return model[i]; }
}
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index 802d23e4..256e213e 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -118,13 +118,15 @@ TestCase {
}
function test_arraymodelwithtextrole() {
- // FIXME The use-case before this change should work.
- var comboBox = Qt.createQmlObject('import QtQuick.Controls 1.1 ; \
- ComboBox { \
- model: [ { "text": "Banana", "color": "Yellow"}, \
- { "text": "Apple", "color": "Green"}, \
- { "text": "Coconut", "color": "Brown"} ]; \
- textRole: "text" }', testCase, '');
+ var arrayModel = [
+ {text: 'Banana', color: 'Yellow'},
+ {text: 'Apple', color: 'Green'},
+ {text: 'Coconut', color: 'Brown'}
+ ];
+
+ var comboBox = Qt.createQmlObject('import QtQuick.Controls 1.1 ; ComboBox { }', testCase, '');
+ comboBox.textRole = "text"
+ comboBox.model = arrayModel
compare(comboBox.currentIndex, 0)
compare(comboBox.currentText, "Banana")
comboBox.textRole = "color"