aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2016-04-17 19:28:17 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-04-18 09:48:40 +0000
commit392d520ade77e6fb941e54fdaa8b23d34c745a8b (patch)
tree46991b006ef4da4227a79b18f5b72799ec3efcee
parent34c43df77dbd29eeb7e9ea34b23cad7fb80c735c (diff)
ComboBox: respect currentIndex:-1
Don't override explicitly set current index in Component.onCompleted. Task-number: QTBUG-52615 Change-Id: If5ce4ec1db29f8ac94d457d297910d61fb0b8a18 Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
-rw-r--r--src/quicktemplates2/qquickcombobox.cpp6
-rw-r--r--tests/auto/controls/data/tst_combobox.qml10
2 files changed, 14 insertions, 2 deletions
diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp
index e10a8b48..766cabe8 100644
--- a/src/quicktemplates2/qquickcombobox.cpp
+++ b/src/quicktemplates2/qquickcombobox.cpp
@@ -154,7 +154,7 @@ class QQuickComboBoxPrivate : public QQuickControlPrivate
Q_DECLARE_PUBLIC(QQuickComboBox)
public:
- QQuickComboBoxPrivate() : pressed(false), ownModel(false), hasDisplayText(false),
+ QQuickComboBoxPrivate() : pressed(false), ownModel(false), hasDisplayText(false), hasCurrentIndex(false),
highlightedIndex(-1), currentIndex(-1), delegateModel(nullptr),
delegate(nullptr), popup(nullptr) { }
@@ -177,6 +177,7 @@ public:
bool pressed;
bool ownModel;
bool hasDisplayText;
+ bool hasCurrentIndex;
int highlightedIndex;
int currentIndex;
QVariant model;
@@ -479,6 +480,7 @@ int QQuickComboBox::currentIndex() const
void QQuickComboBox::setCurrentIndex(int index)
{
Q_D(QQuickComboBox);
+ d->hasCurrentIndex = true;
if (d->currentIndex == index)
return;
@@ -857,7 +859,7 @@ void QQuickComboBox::componentComplete()
static_cast<QQmlDelegateModel *>(d->delegateModel)->componentComplete();
if (count() > 0) {
- if (d->currentIndex == -1)
+ if (!d->hasCurrentIndex && d->currentIndex == -1)
setCurrentIndex(0);
else
d->updateCurrentText();
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index ef46172f..c400d912 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -792,4 +792,14 @@ TestCase {
loader.destroy()
}
+
+ // QTBUG-52615
+ function test_currentIndex() {
+ var control = comboBox.createObject(testCase, {currentIndex: -1, model: 3})
+ verify(control)
+
+ compare(control.currentIndex, -1)
+
+ control.destroy()
+ }
}