summaryrefslogtreecommitdiffstats
path: root/tests/auto/qitemselectionmodel
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2010-12-12 22:11:23 +0100
committerOlivier Goffart <olivier.goffart@nokia.com>2011-05-10 12:54:43 +0200
commit3880eee2d0e9f116c0ee4bde1dc8c1c8acaaae1e (patch)
tree2d67b514af5bf40031f4e074977658e9299585bf /tests/auto/qitemselectionmodel
parentfde6021547b634dd7ee561af39668f39748befaf (diff)
Use the virtual API to clear a selection.
Reviewed-by: Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> Merge-request: 980 (cherry picked from commit e3cd651d92a9e550fe52360d1be6ae41d0f2ab85)
Diffstat (limited to 'tests/auto/qitemselectionmodel')
-rw-r--r--tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp
index 6e20fb23c4..d91b068c5f 100644
--- a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp
+++ b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp
@@ -101,6 +101,7 @@ private slots:
void testDifferentModels();
void testValidRangesInSelectionsAfterReset();
+ void testChainedSelectionClear();
private:
QAbstractItemModel *model;
@@ -2655,5 +2656,58 @@ void tst_QItemSelectionModel::testValidRangesInSelectionsAfterReset()
model.setStringList(strings);
}
+class DuplicateItemSelectionModel : public QItemSelectionModel
+{
+ Q_OBJECT
+public:
+ DuplicateItemSelectionModel(QItemSelectionModel *target, QAbstractItemModel *model, QObject *parent = 0)
+ : QItemSelectionModel(model, parent), m_target(target)
+ {
+
+ }
+
+ void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
+ {
+ QItemSelectionModel::select(selection, command);
+ m_target->select(selection, command);
+ }
+
+ using QItemSelectionModel::select;
+
+private:
+ QItemSelectionModel *m_target;
+
+};
+
+void tst_QItemSelectionModel::testChainedSelectionClear()
+{
+ QStringListModel model(QStringList() << "Apples" << "Pears");
+
+ QItemSelectionModel selectionModel(&model, 0);
+ DuplicateItemSelectionModel duplicate(&selectionModel, &model, 0);
+
+ duplicate.select(model.index(0, 0), QItemSelectionModel::Select);
+
+ {
+ QModelIndexList selectedIndexes = selectionModel.selection().indexes();
+ QModelIndexList duplicatedIndexes = duplicate.selection().indexes();
+
+ QVERIFY(selectedIndexes.size() == duplicatedIndexes.size());
+ QVERIFY(selectedIndexes.size() == 1);
+ QVERIFY(selectedIndexes.first() == model.index(0, 0));
+ }
+
+ duplicate.clearSelection();
+
+ {
+ QModelIndexList selectedIndexes = selectionModel.selection().indexes();
+ QModelIndexList duplicatedIndexes = duplicate.selection().indexes();
+
+ QVERIFY(selectedIndexes.size() == duplicatedIndexes.size());
+ QVERIFY(selectedIndexes.size() == 0);
+ }
+
+}
+
QTEST_MAIN(tst_QItemSelectionModel)
#include "tst_qitemselectionmodel.moc"