diff options
author | Stephen Kelly <stephen.kelly@kdab.com> | 2010-09-15 09:33:43 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2010-09-15 09:33:43 (GMT) |
commit | b96c55b0edf888b919ac365465529a7b5e4d0ae6 (patch) | |
tree | 72ad66b073a44c66f3fd631ccfd4e4ded06e1afa /tests | |
parent | e3801c20bd3626c3c9c9fac110ee2f9e4269e3c8 (diff) | |
download | Qt-b96c55b0edf888b919ac365465529a7b5e4d0ae6.zip Qt-b96c55b0edf888b919ac365465529a7b5e4d0ae6.tar.gz Qt-b96c55b0edf888b919ac365465529a7b5e4d0ae6.tar.bz2 |
Make sure mapSelectionFromSource does not return a selection with invalid ranges.
Similar for mapSelectionToSource, but that one could possibly be an assert instead.
Merge-request: 2474
Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 53fefee..66caf4a 100644 --- a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -143,6 +143,7 @@ private slots: void taskQTBUG_10287_unnecessaryMapCreation(); void testMultipleProxiesWithSelection(); + void mapSelectionFromSource(); protected: void buildHierarchy(const QStringList &data, QAbstractItemModel *model); @@ -3075,6 +3076,44 @@ void tst_QSortFilterProxyModel::testMultipleProxiesWithSelection() } +static bool isValid(const QItemSelection &selection) { + foreach(const QItemSelectionRange &range, selection) + if (!range.isValid()) + return false; + return true; +} + +void tst_QSortFilterProxyModel::mapSelectionFromSource() +{ + QStringListModel model; + const QStringList initial = QString("bravo charlie delta echo").split(" "); + model.setStringList(initial); + + QSortFilterProxyModel proxy; + proxy.setDynamicSortFilter(true); + proxy.setFilterRegExp("d.*"); + proxy.setSourceModel(&model); + + // Only "delta" remains. + QVERIFY(proxy.rowCount() == 1); + + QItemSelection selection; + QModelIndex charlie = model.index(1, 0); + selection.append(QItemSelectionRange(charlie, charlie)); + QModelIndex delta = model.index(2, 0); + selection.append(QItemSelectionRange(delta, delta)); + QModelIndex echo = model.index(3, 0); + selection.append(QItemSelectionRange(echo, echo)); + + QVERIFY(isValid(selection)); + + QItemSelection proxiedSelection = proxy.mapSelectionFromSource(selection); + + // Only "delta" is in the mapped result. + QVERIFY(proxiedSelection.size() == 1); + QVERIFY(isValid(proxiedSelection)); +} + class Model10287 : public QStandardItemModel { Q_OBJECT |