diff options
author | Stephen Kelly <stephen@kdab.com> | 2010-05-20 11:07:41 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2010-05-20 11:07:41 (GMT) |
commit | 2c1d1c136102a17eef9ae3c4e9f0cf01338306ae (patch) | |
tree | 646ad769de11c8d4d3fe42b7c4cb0436149ec490 /tests | |
parent | 76fcf30c0f275a7c9f9752b1be5cb1d5ba98d9b6 (diff) | |
download | Qt-2c1d1c136102a17eef9ae3c4e9f0cf01338306ae.zip Qt-2c1d1c136102a17eef9ae3c4e9f0cf01338306ae.tar.gz Qt-2c1d1c136102a17eef9ae3c4e9f0cf01338306ae.tar.bz2 |
Deselect the current selection when the QItemSelectionModel::model is reset.
Merge-request: 639
Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp index 3b2a716..9858829 100644 --- a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp +++ b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp @@ -1536,6 +1536,43 @@ public: inline void reset() { QStandardItemModel::reset(); } }; +class ResetObserver : public QObject +{ + QItemSelectionModel * const m_selectionModel; + QItemSelection m_selection; + Q_OBJECT +public: + ResetObserver(QItemSelectionModel *selectionModel) + : m_selectionModel(selectionModel) + { + connect(selectionModel->model(), SIGNAL(modelAboutToBeReset()),SLOT(modelAboutToBeReset())); + connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(selectionChanged(QItemSelection,QItemSelection))); + connect(selectionModel->model(), SIGNAL(modelReset()),SLOT(modelReset())); + } + +private slots: + void modelAboutToBeReset() + { + m_selection = m_selectionModel->selection(); + foreach(const QItemSelectionRange &range, m_selection) + { + QVERIFY(range.isValid()); + } + } + + void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) + { + qDebug() << deselected << selected; + QCOMPARE(m_selection, deselected); + m_selection.clear(); + } + + void modelReset() + { + QVERIFY(m_selectionModel->selection().isEmpty()); + } +}; + void tst_QItemSelectionModel::resetModel() { MyStandardItemModel model(20, 20); @@ -1555,11 +1592,13 @@ void tst_QItemSelectionModel::resetModel() view.selectionModel()->select(QItemSelection(model.index(0, 0), model.index(5, 5)), QItemSelectionModel::Select); - QCOMPARE(spy.count(), 2); - QCOMPARE(spy.at(1).count(), 2); + // We get this signal three times. Twice in this test method and once because the source reset causes the current selection to + // be deselected. + QCOMPARE(spy.count(), 3); + QCOMPARE(spy.at(2).count(), 2); // make sure we don't get an "old selection" - QCOMPARE(spy.at(1).at(1).userType(), qMetaTypeId<QItemSelection>()); - QVERIFY(qvariant_cast<QItemSelection>(spy.at(1).at(1)).isEmpty()); + QCOMPARE(spy.at(2).at(1).userType(), qMetaTypeId<QItemSelection>()); + QVERIFY(qvariant_cast<QItemSelection>(spy.at(2).at(1)).isEmpty()); } void tst_QItemSelectionModel::removeRows_data() |