diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2021-01-08 11:58:55 +0100 |
---|---|---|
committer | Maximilian Goldstein <max.goldstein@qt.io> | 2021-04-22 10:27:45 +0200 |
commit | 44055ebbe1db7e8f229de6c6936cd326b69dff15 (patch) | |
tree | d9f7289c6c0aec5d1682d549afc7ec79c34d13df /tests | |
parent | 02f0c23d001b433e333ede211227c8021b55277e (diff) |
Fix warning and assert when removing items from groups
When removing items from groups actively shown by a model filter a warning
and assert was triggered in the past. This change fixes this behavior.
Fixes: QTBUG-86017
Change-Id: I49b7498a3d03141b654e453a3c35a43fc7ba804a
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit 8a3ede5ba1daf2d9314d71db972175b2791456c0)
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmldelegatemodel/data/qtbug_86017.qml | 32 | ||||
-rw-r--r-- | tests/auto/qml/qqmldelegatemodel/tst_qqmldelegatemodel.cpp | 15 |
2 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmldelegatemodel/data/qtbug_86017.qml b/tests/auto/qml/qqmldelegatemodel/data/qtbug_86017.qml new file mode 100644 index 0000000000..02d737e37f --- /dev/null +++ b/tests/auto/qml/qqmldelegatemodel/data/qtbug_86017.qml @@ -0,0 +1,32 @@ +import QtQuick 2.8 +import QtQml.Models 2.1 + +DelegateModel { + id: visualModel + model: ListModel { + id: myLM + ListElement { + name: "Apple" + } + ListElement { + name: "Orange" + } + } + + filterOnGroup: "selected" + + groups: [ + DelegateModelGroup { + name: "selected" + includeByDefault: true + } + ] + + delegate: Text { + Component.onCompleted: { + DelegateModel.inPersistedItems = true + DelegateModel.inSelected = false + } + text: "item " + index + } +} diff --git a/tests/auto/qml/qqmldelegatemodel/tst_qqmldelegatemodel.cpp b/tests/auto/qml/qqmldelegatemodel/tst_qqmldelegatemodel.cpp index 71550a50f3..9bc359d243 100644 --- a/tests/auto/qml/qqmldelegatemodel/tst_qqmldelegatemodel.cpp +++ b/tests/auto/qml/qqmldelegatemodel/tst_qqmldelegatemodel.cpp @@ -45,6 +45,7 @@ private slots: void valueWithoutCallingObjectFirst_data(); void valueWithoutCallingObjectFirst(); void filterOnGroup_removeWhenCompleted(); + void qtbug_86017(); }; class AbstractItemModel : public QAbstractItemModel @@ -147,6 +148,20 @@ void tst_QQmlDelegateModel::filterOnGroup_removeWhenCompleted() QQmlDelegateModel *model = root->findChild<QQmlDelegateModel*>(); QVERIFY(model); QTest::qWaitFor([=]{ return model->count() == 2; } ); + +void tst_QQmlDelegateModel::qtbug_86017() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("qtbug_86017.qml")); + QScopedPointer<QObject> root(component.create()); + QVERIFY2(root, qPrintable(component.errorString())); + QTRY_VERIFY(component.isReady()); + QQmlDelegateModel *model = qobject_cast<QQmlDelegateModel*>(root.data()); + + QVERIFY(model); + QCOMPARE(model->count(), 2); + QCOMPARE(model->filterGroup(), "selected"); } QTEST_MAIN(tst_QQmlDelegateModel) |