summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2010-12-12 21:11:23 (GMT)
committerGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2011-03-15 17:34:43 (GMT)
commite3cd651d92a9e550fe52360d1be6ae41d0f2ab85 (patch)
tree8054abc8dd4848bfe8a8cf9cca4bdf220aa2f514
parent306d16002220b99ad386fb1255034b94861a8c9f (diff)
downloadQt-e3cd651d92a9e550fe52360d1be6ae41d0f2ab85.zip
Qt-e3cd651d92a9e550fe52360d1be6ae41d0f2ab85.tar.gz
Qt-e3cd651d92a9e550fe52360d1be6ae41d0f2ab85.tar.bz2
Use the virtual API to clear a selection.
Reviewed-by: Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> Merge-request: 980
-rw-r--r--src/gui/itemviews/qitemselectionmodel.cpp7
-rw-r--r--tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp54
2 files changed, 56 insertions, 5 deletions
diff --git a/src/gui/itemviews/qitemselectionmodel.cpp b/src/gui/itemviews/qitemselectionmodel.cpp
index 27a4a40..0b64452 100644
--- a/src/gui/itemviews/qitemselectionmodel.cpp
+++ b/src/gui/itemviews/qitemselectionmodel.cpp
@@ -1145,11 +1145,8 @@ void QItemSelectionModel::clearSelection()
Q_D(QItemSelectionModel);
if (d->ranges.count() == 0 && d->currentSelection.count() == 0)
return;
- QItemSelection selection = d->ranges;
- selection.merge(d->currentSelection, d->currentCommand);
- d->ranges.clear();
- d->currentSelection.clear();
- emit selectionChanged(QItemSelection(), selection);
+
+ select(QItemSelection(), Clear);
}
diff --git a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp
index 6e20fb2..d91b068 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"