summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorStephen Kelly <stephen@kdab.com>2010-06-03 14:55:38 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2010-06-03 15:16:20 (GMT)
commita64791bdf663fb1d7595f11fbe7e44a62acd4126 (patch)
treeba0c507bd64f64a72ca7de4c409932180972cab5 /tests/auto
parentcba9c55a97c0a04859658d4c7a67d5853a3d3a55 (diff)
downloadQt-a64791bdf663fb1d7595f11fbe7e44a62acd4126.zip
Qt-a64791bdf663fb1d7595f11fbe7e44a62acd4126.tar.gz
Qt-a64791bdf663fb1d7595f11fbe7e44a62acd4126.tar.bz2
QItemSelectionModel: When rows are removed from the middle of the range, remove them from the selection.
Merge-request: 2403 Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp
index 3b2a716..bfe306d 100644
--- a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp
+++ b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp
@@ -94,6 +94,7 @@ private slots:
void task260134_layoutChangedWithAllSelected();
void QTBUG5671_layoutChangedWithAllSelected();
void QTBUG2804_layoutChangedTreeSelection();
+ void deselectRemovedMiddleRange();
private:
QAbstractItemModel *model;
@@ -2353,6 +2354,53 @@ void tst_QItemSelectionModel::QTBUG2804_layoutChangedTreeSelection()
QCOMPARE(selModel.selectedIndexes().count(), 4);
}
+class RemovalObserver : public QObject
+{
+ Q_OBJECT
+ QItemSelectionModel *m_itemSelectionModel;
+public:
+ RemovalObserver(QItemSelectionModel *selectionModel)
+ : m_itemSelectionModel(selectionModel)
+ {
+ connect(m_itemSelectionModel, SIGNAL(selectionChanged(QItemSelection, QItemSelection)), SLOT(selectionChanged(QItemSelection, QItemSelection)));
+ }
+
+public slots:
+ void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
+ {
+ foreach(const QModelIndex &index, deselected.indexes()) {
+ QVERIFY(!m_itemSelectionModel->selection().contains(index));
+ }
+ QVERIFY(m_itemSelectionModel->selection().size() == 2);
+ }
+
+};
+
+void tst_QItemSelectionModel::deselectRemovedMiddleRange()
+{
+ QStandardItemModel model(8, 0);
+
+ for (int row = 0; row < 8; ++row) {
+ static const int column = 0;
+ QStandardItem *item = new QStandardItem(QString::number(row));
+ model.setItem(row, column, item);
+ }
+
+ QItemSelectionModel selModel(&model);
+
+ selModel.select(QItemSelection(model.index(3, 0), model.index(6, 0)), QItemSelectionModel::Select);
+
+ QVERIFY(selModel.selection().size() == 1);
+
+ RemovalObserver ro(&selModel);
+
+ QSignalSpy spy(&selModel, SIGNAL(selectionChanged(QItemSelection, QItemSelection)));
+ bool ok = model.removeRows(4, 2);
+
+ QVERIFY(ok);
+ QVERIFY(spy.size() == 1);
+}
+
QTEST_MAIN(tst_QItemSelectionModel)
#include "tst_qitemselectionmodel.moc"