diff options
author | Stephen Kelly <steveire@gmail.com> | 2016-12-19 21:13:57 +0000 |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2016-12-21 01:37:40 +0000 |
commit | 0874861bcc70313c343aba5e5566ed30b69eed1c (patch) | |
tree | 46cfeb3f6b3a4a7ac74b12239e82a56675b132fe /tests | |
parent | 3bd0fd8f97e7a33a874929a383a42e6c710bfff3 (diff) |
QSFPM: Remove data manipulation from move handlers
Similar to the fix in the parent commit, incorrect updating of the
internal data structures during layout changes can lead to dangling
pointers being dereferenced later. Moves are treated as layoutChanges
by this proxy by forwarding to the appropriate method. However, data is
incorrectly cleared prior to that forwarding. Remove that, and let the
layoutChange handling take appropriate action.
Change-Id: Iee951e37152328a4e6a5fb8e5385c32a2fe4c0bd
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 6b98d9f4a3..7b6c470dc4 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -146,6 +146,7 @@ private slots: void filterHint(); void sourceLayoutChangeLeavesValidPersistentIndexes(); + void rowMoveLeavesValidPersistentIndexes(); protected: void buildHierarchy(const QStringList &data, QAbstractItemModel *model); @@ -4307,5 +4308,50 @@ void tst_QSortFilterProxyModel::sourceLayoutChangeLeavesValidPersistentIndexes() QVERIFY(persistentIndex.parent().isValid()); } +void tst_QSortFilterProxyModel::rowMoveLeavesValidPersistentIndexes() +{ + DynamicTreeModel model; + Q_SET_OBJECT_NAME(model); + + QList<int> ancestors; + for (auto i = 0; i < 5; ++i) + { + Q_UNUSED(i); + ModelInsertCommand insertCommand(&model); + insertCommand.setAncestorRowNumbers(ancestors); + insertCommand.setStartRow(0); + insertCommand.setEndRow(0); + insertCommand.doCommand(); + ancestors.push_back(0); + } + + QSortFilterProxyModel proxy1; + proxy1.setSourceModel(&model); + Q_SET_OBJECT_NAME(proxy1); + + proxy1.setFilterRegExp("1|2"); + + auto item5 = model.match(model.index(0, 0), Qt::DisplayRole, "5", 1, Qt::MatchRecursive).first(); + auto item3 = model.match(model.index(0, 0), Qt::DisplayRole, "3", 1, Qt::MatchRecursive).first(); + + Q_ASSERT(item5.isValid()); + Q_ASSERT(item3.isValid()); + + QPersistentModelIndex persistentIndex = proxy1.match(proxy1.index(0, 0), Qt::DisplayRole, "2", 1, Qt::MatchRecursive).first(); + + ModelMoveCommand moveCommand(&model, 0); + moveCommand.setAncestorRowNumbers(QList<int>{0, 0, 0, 0}); + moveCommand.setStartRow(0); + moveCommand.setEndRow(0); + moveCommand.setDestRow(0); + moveCommand.setDestAncestors(QList<int>{0, 0, 0}); + moveCommand.doCommand(); + + // Calling parent() causes the internalPointer to be used. + // Before fixing QTBUG-47711 (moveRows case), that could be + // a dangling pointer. + QVERIFY(persistentIndex.parent().isValid()); +} + QTEST_MAIN(tst_QSortFilterProxyModel) #include "tst_qsortfilterproxymodel.moc" |