summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2016-03-22 15:53:36 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2016-03-23 22:10:07 +0000
commit4ca77851612a1b89f3e403db356641f3919304fd (patch)
tree20d58f0e2b32b99c01132d395b13ebdf688d7acf
parent060e0f6628fd185994911307c59f5355acaaf18f (diff)
QAbstractItemView test: check that the selection model is in sync with the view
Change-Id: Ifca91154b47184a9d9a1979e1fba471517e16698 Reviewed-by: Stephen Kelly <ske@ableton.com>
-rw-r--r--tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
index 2b2f130060..6cbf51efd9 100644
--- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
+++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
@@ -253,6 +253,7 @@ private slots:
void shiftSelectionAfterChangingModelContents();
void QTBUG48968_reentrant_updateEditorGeometries();
void QTBUG50535_update_on_new_selection_model();
+ void testSelectionModelInSyncWithView();
};
class MyAbstractItemDelegate : public QAbstractItemDelegate
@@ -2082,5 +2083,59 @@ void tst_QAbstractItemView::QTBUG50535_update_on_new_selection_model()
QTRY_VERIFY(view.m_paintEventsCount > oldPaintEventsCount);
}
+void tst_QAbstractItemView::testSelectionModelInSyncWithView()
+{
+ QStandardItemModel model;
+ for (int i = 0; i < 10; ++i)
+ model.appendRow(new QStandardItem(QStringLiteral("%1").arg(i)));
+
+ class ListView : public QListView
+ {
+ public:
+ using QListView::selectedIndexes;
+ };
+
+ ListView view;
+ QVERIFY(!view.selectionModel());
+
+ view.setModel(&model);
+ QVERIFY(view.selectionModel());
+ QVERIFY(view.selectedIndexes().isEmpty());
+ QVERIFY(view.selectionModel()->selection().isEmpty());
+
+ view.setCurrentIndex(model.index(0, 0));
+ QCOMPARE(view.currentIndex(), model.index(0, 0));
+ QCOMPARE(view.selectionModel()->currentIndex(), model.index(0, 0));
+
+ view.selectionModel()->setCurrentIndex(model.index(1, 0), QItemSelectionModel::SelectCurrent);
+ QCOMPARE(view.currentIndex(), model.index(1, 0));
+ QCOMPARE(view.selectedIndexes(), QModelIndexList() << model.index(1, 0));
+ QCOMPARE(view.selectionModel()->currentIndex(), model.index(1, 0));
+ QCOMPARE(view.selectionModel()->selection().indexes(), QModelIndexList() << model.index(1, 0));
+
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+
+ QItemSelectionModel selectionModel(&model);
+ selectionModel.setCurrentIndex(model.index(2, 0), QItemSelectionModel::Current);
+
+ view.setSelectionModel(&selectionModel);
+ QCOMPARE(view.currentIndex(), model.index(2, 0));
+ QCOMPARE(view.selectedIndexes(), QModelIndexList());
+ QCOMPARE(view.selectionModel()->currentIndex(), model.index(2, 0));
+ QCOMPARE(view.selectionModel()->selection().indexes(), QModelIndexList());
+
+
+ QItemSelectionModel selectionModel2(&model);
+ selectionModel2.select(model.index(0, 0), QItemSelectionModel::ClearAndSelect);
+ selectionModel2.setCurrentIndex(model.index(1, 0), QItemSelectionModel::Current);
+
+ view.setSelectionModel(&selectionModel2);
+ QCOMPARE(view.currentIndex(), model.index(1, 0));
+ QCOMPARE(view.selectedIndexes(), QModelIndexList() << model.index(0, 0));
+ QCOMPARE(view.selectionModel()->currentIndex(), model.index(1, 0));
+ QCOMPARE(view.selectionModel()->selection().indexes(), QModelIndexList() << model.index(0, 0));
+}
+
QTEST_MAIN(tst_QAbstractItemView)
#include "tst_qabstractitemview.moc"