From 62f5a6ca4274d72bab78db4bc374c481717871b0 Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Mon, 14 Dec 2020 19:27:10 +0100 Subject: 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 --- .../itemmodels/qitemselectionmodel/CMakeLists.txt | 3 ++- .../tst_qitemselectionmodel.cpp | 26 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'tests/auto/corelib/itemmodels/qitemselectionmodel') 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 +#include #include #include @@ -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 firstModel( + new QStringListModel(QStringList { "Some", "random", "content" })); + std::unique_ptr changedModel( + new QStringListModel(QStringList { "Other", "random", "content" })); + + QTestPrivate::testReadWritePropertyBasics( + 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; -- cgit v1.2.3