diff options
author | Stephen Kelly <stephen.kelly@kdab.com> | 2012-04-15 23:03:40 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-17 00:47:49 +0200 |
commit | da7880b0f032e67e3a2b24ec9bb47259ffd671da (patch) | |
tree | 9c2f353c0fe50a26c9b4f551b8df9e5f82499a6e /tests/auto/other/modeltest/dynamictreemodel.cpp | |
parent | 76d61af1e272628aa38f088ea10ec7076fae8b06 (diff) |
Update parent indexes first with changePersistentIndex.
Otherwise, the order of updating of the indexes will cause
inconsistent results because it will rely on ordering within a
QHash (which is indeterminate).
Task-number: QTBUG-25325
Change-Id: I7d99578c8ee2954b8562dc5aff7dc32e74d41fb5
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'tests/auto/other/modeltest/dynamictreemodel.cpp')
-rw-r--r-- | tests/auto/other/modeltest/dynamictreemodel.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/tests/auto/other/modeltest/dynamictreemodel.cpp b/tests/auto/other/modeltest/dynamictreemodel.cpp index 325fc19db2..ab783d0ba2 100644 --- a/tests/auto/other/modeltest/dynamictreemodel.cpp +++ b/tests/auto/other/modeltest/dynamictreemodel.cpp @@ -372,7 +372,17 @@ void ModelChangeChildrenLayoutsCommand::doCommand() } } - foreach (const QModelIndex &idx, m_model->persistentIndexList()) { + // If we're changing one of the parent indexes, we need to ensure that we do that before + // changing any children of that parent. The reason is that we're keeping parent1 and parent2 + // around as QPersistentModelIndex instances, and we query idx.parent() in the loop. + QModelIndexList persistent = m_model->persistentIndexList(); + foreach (const QModelIndex &parent, parents) { + int idx = persistent.indexOf(parent); + if (idx != -1) + persistent.move(idx, 0); + } + + foreach (const QModelIndex &idx, persistent) { if (idx.parent() == parent1) { if (idx.row() == rowSize1 - 1) { m_model->changePersistentIndex(idx, m_model->createIndex(0, idx.column(), idx.internalPointer())); |