diff options
author | Andreas Buhr <andreas.buhr@qt.io> | 2020-12-14 19:27:10 +0100 |
---|---|---|
committer | Andreas Buhr <andreas.buhr@qt.io> | 2021-04-27 20:12:50 +0200 |
commit | 62f5a6ca4274d72bab78db4bc374c481717871b0 (patch) | |
tree | a157cee0c4ed9afd11e78102a7ec070b147f6f13 /tests/auto/corelib/itemmodels/qitemselectionmodel | |
parent | 001e9c6a1995662b53405f37cb3538ff80154886 (diff) |
Port of QItemSelectionModel::model to new property system
The property 'model' is ported to a bindable property.
The properties hasSelection, selection, selectedIndexes,
and currentIndex are left for later patches.
Task-number: QTBUG-85520
Change-Id: Ia424ce99fc80c3d807c634c21d161a3ad94b27d2
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'tests/auto/corelib/itemmodels/qitemselectionmodel')
-rw-r--r-- | tests/auto/corelib/itemmodels/qitemselectionmodel/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp | 26 |
2 files changed, 28 insertions, 1 deletions
diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/CMakeLists.txt b/tests/auto/corelib/itemmodels/qitemselectionmodel/CMakeLists.txt index 2dfa6f98f8..8eadf67b66 100644 --- a/tests/auto/corelib/itemmodels/qitemselectionmodel/CMakeLists.txt +++ b/tests/auto/corelib/itemmodels/qitemselectionmodel/CMakeLists.txt @@ -7,6 +7,7 @@ qt_internal_add_test(tst_qitemselectionmodel SOURCES tst_qitemselectionmodel.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui + Qt::TestPrivate ) diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp index 052abe0700..ceca96f791 100644 --- a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp +++ b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp @@ -27,6 +27,7 @@ ****************************************************************************/ #include <QTest> +#include <QtTest/private/qpropertytesthelper_p.h> #include <QSignalSpy> #include <QtGui/QtGui> @@ -85,6 +86,8 @@ private slots: void deselectRemovedMiddleRange(); void setModel(); + void bindableModel(); + void testDifferentModels(); void testValidRangesInSelectionsAfterReset(); @@ -2435,6 +2438,29 @@ void tst_QItemSelectionModel::setModel() QVERIFY(sel.selection().isEmpty()); } +void tst_QItemSelectionModel::bindableModel() +{ + QItemSelectionModel sel; + QVERIFY(!sel.model()); + + std::unique_ptr<QStringListModel> firstModel( + new QStringListModel(QStringList { "Some", "random", "content" })); + std::unique_ptr<QStringListModel> changedModel( + new QStringListModel(QStringList { "Other", "random", "content" })); + + QTestPrivate::testReadWritePropertyBasics<QItemSelectionModel, QAbstractItemModel *>( + sel, firstModel.get(), changedModel.get(), "model"); + if (QTest::currentTestFailed()) { + qDebug("Failed property test for QItemSelectionModel::model"); + return; + } + + // check that model is set to nullptr when the object pointed to is deleted: + sel.setModel(firstModel.get()); + firstModel.reset(); + QCOMPARE(sel.model(), nullptr); +} + void tst_QItemSelectionModel::testDifferentModels() { QStandardItemModel model1; |