diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-01-13 10:39:15 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-01-13 17:06:40 +0000 |
commit | 0ff25e23c69571983bbf34c41bc5445a1fbf4f66 (patch) | |
tree | d06477d467a2d89fdf64bd0125501eccb5e081d6 /tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp | |
parent | 6f04dffb4ee8b49327a19b1f32246188ddc23267 (diff) |
ListModel: Fix move handling in sync
When a ListModel is modified in a workerscript, we reconciliate the
state in ListModel::sync. However, the logic for moving elements was
wrong, causing crashes in endMoveRows due to invalid moves.
This patch ensures that elements are moved to the correct position.
Notably, whenever an element is moved, we must update the targetIndex of
all elements affected by that move.
Amends 3accc1dae76575120e71cadb547e961ecd50bcb0.
Task-number: QTBUG-85557
Change-Id: I1a1ffa43eab39ed2315f1916527d897b208c2c3b
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
(cherry picked from commit 2996439993c587bc9c7169e4f152169f28247c21)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp')
-rw-r--r-- | tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp b/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp index 85814a54fb..262ac25d6a 100644 --- a/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp +++ b/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp @@ -104,6 +104,7 @@ private slots: void worker_remove_list(); void dynamic_role_data(); void dynamic_role(); + void correctMoves(); }; bool tst_qqmllistmodelworkerscript::compareVariantList(const QVariantList &testList, QVariant object) @@ -842,6 +843,22 @@ void tst_qqmllistmodelworkerscript::dynamic_role() qApp->processEvents(); } +void tst_qqmllistmodelworkerscript::correctMoves() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("listmodel_async_sort/main.qml")); + QScopedPointer<QObject> root {component.create()}; + QVERIFY2(root, qPrintable(component.errorString())); + bool ok =QMetaObject::invokeMethod(root.get(), "doSort"); + QVERIFY(ok); + auto check = [&](){ + bool success = false; + QMetaObject::invokeMethod(root.get(), "verify", Q_RETURN_ARG(bool, success)); + return success; + }; + QTRY_VERIFY(check()); +} + QTEST_MAIN(tst_qqmllistmodelworkerscript) #include "tst_qqmllistmodelworkerscript.moc" |