diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2014-12-18 16:18:16 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2015-01-13 22:52:05 +0100 |
commit | 940530ab67a8fd59130b2299fe854707207f041f (patch) | |
tree | e6d627cb2b6ed0ba084b38e8db5ec3ee8484fc03 /tests | |
parent | 14583137ae445fbfdc82922266f5c0736454f6c4 (diff) |
QComboBox: make setModel reset the root model index
When changing models it makes no sense to keep the old root model index,
pointing into a possibly deleted model. Reset it to the root
of the new model is the best line of action.
[ChangeLog][QtWidgets][QComboBox] QComboBox will now reset its root
model index when a new model is set on it.
Task-number: QTBUG-43350
Change-Id: I113d558ce19fcaed31f13abfbedc7a24302e28d7
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index 556602b523..5007983aa6 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -1577,11 +1577,34 @@ void tst_QComboBox::setModel() QCOMPARE(box.currentIndex(), 0); QVERIFY(box.model() != oldModel); + // set a new root index + QModelIndex rootModelIndex; + rootModelIndex = box.model()->index(0, 0); + QVERIFY(rootModelIndex.isValid()); + box.setRootModelIndex(rootModelIndex); + QCOMPARE(box.rootModelIndex(), rootModelIndex); + + // change the model, ensure that the root index gets reset + oldModel = box.model(); + box.setModel(new QStandardItemModel(2, 1, &box)); + QCOMPARE(box.currentIndex(), 0); + QVERIFY(box.model() != oldModel); + QVERIFY(box.rootModelIndex() != rootModelIndex); + QVERIFY(box.rootModelIndex() == QModelIndex()); + // check that setting the very same model doesn't move the current item box.setCurrentIndex(1); QCOMPARE(box.currentIndex(), 1); box.setModel(box.model()); QCOMPARE(box.currentIndex(), 1); + + // check that setting the very same model doesn't move the root index + rootModelIndex = box.model()->index(0, 0); + QVERIFY(rootModelIndex.isValid()); + box.setRootModelIndex(rootModelIndex); + QCOMPARE(box.rootModelIndex(), rootModelIndex); + box.setModel(box.model()); + QCOMPARE(box.rootModelIndex(), rootModelIndex); } void tst_QComboBox::setCustomModelAndView() |