diff options
author | Jens Bache-Wiig <jens.bache-wiig@digia.com> | 2013-12-11 18:51:14 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-12-13 12:02:36 +0100 |
commit | 49a7f0b8e544fed6bf7811198d7696af8d7baba9 (patch) | |
tree | f01c68e820ac899bf111f2cf2b2a95b6eab90438 | |
parent | 29a362c1915f82e8eb89cf9788d2379acb67d24d (diff) | |
download | qtquickcontrols-49a7f0b8e544fed6bf7811198d7696af8d7baba9.tar.gz |
Make editable Combobox accept substrings
This fixes the issue that onAccepted would not update the currentText or
current index if the string was a substring/partial match.
Note that the new internal MatchFixedString case matches the complete
string in a case insensitive way.
[ChangeLog][Qt Quick Controls][Editable Combobox would not update
currentText when accepting a substring of an existing value.]
Task-number: QTBUG-35521
Change-Id: Ied850208425ae71b2414f1abf9389e9a8ed50cfb
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
-rw-r--r-- | src/controls/ComboBox.qml | 13 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_combobox.qml | 18 |
2 files changed, 25 insertions, 6 deletions
diff --git a/src/controls/ComboBox.qml b/src/controls/ComboBox.qml index 81c8588d..419bc117 100644 --- a/src/controls/ComboBox.qml +++ b/src/controls/ComboBox.qml @@ -356,13 +356,10 @@ Control { selectionColor: __style.__syspal.highlight selectedTextColor: __style.__syspal.highlightedText onAccepted: { - var idx = input.find(editText) + var idx = input.find(editText, Qt.MatchFixedString) if (idx > -1) { - var string = textAt(idx); - if (string.length === editText.length) { - currentIndex = idx; - editText = string; - } + currentIndex = idx; + editText = textAt(idx); } else { currentIndex = -1; popup.currentText = editText; @@ -382,6 +379,10 @@ Control { } else if (searchType === Qt.CaseSensitive) { if (currentString.indexOf(text) === 0) return i; + } else if (searchType === Qt.MatchFixedString) { + if (currentString.toLowerCase().indexOf(text.toLowerCase()) === 0 + && currentString.length === text.length) + return i; } else if (currentString.toLowerCase().indexOf(text.toLowerCase()) === 0) { return i } diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml index 256e213e..f63a6ee7 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -307,6 +307,24 @@ TestCase { compare(comboBox.editText, "Coco") compare(comboBox.currentIndex, 1) + comboBox.editText = "" + keyPress(Qt.Key_C) + keyPress(Qt.Key_O) + keyPress(Qt.Key_C) // autocompletes "coco" + keyPress(Qt.Key_Backspace) + keyPress(Qt.Key_Return) // Accept "coc" + compare(comboBox.editText, "coc") + compare(comboBox.currentText, "coc") + + comboBox.editText = "" + keyPress(Qt.Key_C) + keyPress(Qt.Key_O) + keyPress(Qt.Key_C) // autocompletes "coc" + keyPress(Qt.Key_Space) + keyPress(Qt.Key_Return) // Accept "coc " + compare(comboBox.editText, "coc ") + compare(comboBox.currentText, "coc ") + comboBox.destroy() } |