summaryrefslogtreecommitdiffstats
path: root/tests/auto/qitemselectionmodel
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2010-10-21 08:37:46 (GMT)
committerGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2010-10-21 08:38:29 (GMT)
commitdefe418c16e5e79033812752416efa874c70e622 (patch)
treeddfcaf84417e0b027d0b68053b01a4198142d00b /tests/auto/qitemselectionmodel
parent8331e9700b830594d3c015308bf0aa351997862c (diff)
downloadQt-defe418c16e5e79033812752416efa874c70e622.zip
Qt-defe418c16e5e79033812752416efa874c70e622.tar.gz
Qt-defe418c16e5e79033812752416efa874c70e622.tar.bz2
Make sure d->ranges does not have invalid ranges before processing it.
Reviewed-by: gabi Merge-request: 831
Diffstat (limited to 'tests/auto/qitemselectionmodel')
-rw-r--r--tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp
index 3b2a716..8058294 100644
--- a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp
+++ b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp
@@ -95,6 +95,8 @@ private slots:
void QTBUG5671_layoutChangedWithAllSelected();
void QTBUG2804_layoutChangedTreeSelection();
+ void testValidRangesInSelectionsAfterReset();
+
private:
QAbstractItemModel *model;
QItemSelectionModel *selection;
@@ -2353,6 +2355,70 @@ void tst_QItemSelectionModel::QTBUG2804_layoutChangedTreeSelection()
QCOMPARE(selModel.selectedIndexes().count(), 4);
}
+class SelectionObserver : public QObject
+{
+ Q_OBJECT
+public:
+ SelectionObserver(QAbstractItemModel *model, QObject *parent = 0)
+ : QObject(parent), m_model(model), m_selectionModel(0)
+ {
+ connect(model, SIGNAL(modelReset()), SLOT(modelReset()));
+ }
+
+ void setSelectionModel(QItemSelectionModel *selectionModel)
+ {
+ m_selectionModel = selectionModel;
+ connect(m_selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(selectionChanged(QItemSelection,QItemSelection)));
+ }
+
+ private slots:
+ void modelReset()
+ {
+ const QModelIndex idx = m_model->index(2, 0);
+ QVERIFY(idx.isValid());
+ m_selectionModel->select(QItemSelection(idx, idx), QItemSelectionModel::Clear);
+ }
+
+ void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
+ {
+ foreach(const QItemSelectionRange &range, selected)
+ QVERIFY(range.isValid());
+ foreach(const QItemSelectionRange &range, deselected)
+ QVERIFY(range.isValid());
+ }
+
+private:
+ QAbstractItemModel *m_model;
+ QItemSelectionModel *m_selectionModel;
+};
+
+void tst_QItemSelectionModel::testValidRangesInSelectionsAfterReset()
+{
+ QStringListModel model;
+
+ QStringList strings;
+ strings << "one"
+ << "two"
+ << "three"
+ << "four"
+ << "five";
+
+ model.setStringList(strings);
+
+ SelectionObserver observer(&model);
+
+ QItemSelectionModel selectionModel(&model);
+
+ selectionModel.select(QItemSelection(model.index(1, 0), model.index(3, 0)), QItemSelectionModel::Select);
+
+ // Cause d->ranges to contain something.
+ model.insertRows(2, 1);
+
+ observer.setSelectionModel(&selectionModel);
+
+ model.setStringList(strings);
+
+}
QTEST_MAIN(tst_QItemSelectionModel)
#include "tst_qitemselectionmodel.moc"