diff options
Diffstat (limited to 'tests/auto/quick/qquickrepeater')
-rw-r--r-- | tests/auto/quick/qquickrepeater/data/clearremovalorder.qml | 31 | ||||
-rw-r--r-- | tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp | 38 |
2 files changed, 69 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickrepeater/data/clearremovalorder.qml b/tests/auto/quick/qquickrepeater/data/clearremovalorder.qml new file mode 100644 index 0000000000..a341246163 --- /dev/null +++ b/tests/auto/quick/qquickrepeater/data/clearremovalorder.qml @@ -0,0 +1,31 @@ +import QtQuick 2.0 + +Item { + ListModel { + id: firstModel + objectName: "firstModel" + + ListElement { + name: "Captain" + } + ListElement { + name: "Jack" + } + ListElement { + name: "Sparrow" + } + } + ListModel { + id: secondModel + objectName: "secondModel" + } + Repeater { + objectName: "repeater" + model: firstModel + delegate: Rectangle { + width: 5 + height: 5 + color: "green" + } + } +} diff --git a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp index 258eaee981..62ace2ac7e 100644 --- a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp +++ b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp @@ -40,6 +40,7 @@ #include <QtQml/qqmlincubator.h> #include <private/qquickrepeater_p.h> #include <QtQuick/private/qquicktext_p.h> +#include <QtQml/private/qqmllistmodel_p.h> #include "../../shared/util.h" #include "../shared/viewtestutil.h" @@ -73,6 +74,7 @@ private slots: void visualItemModelCrash(); void invalidContextCrash(); void jsArrayChange(); + void clearRemovalOrder(); }; class TestObject : public QObject @@ -807,6 +809,42 @@ void tst_QQuickRepeater::jsArrayChange() QCOMPARE(spy.count(), 1); } +void tst_QQuickRepeater::clearRemovalOrder() +{ + // Here, we're going to test that when the model is cleared, item removal + // signals are sent in a sensible order that gives us correct indices. + // (QTBUG-42243) + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("clearremovalorder.qml")); + + QQuickItem *rootObject = qobject_cast<QQuickItem*>(component.create()); + QVERIFY(rootObject); + + QQuickRepeater *repeater = findItem<QQuickRepeater>(rootObject, "repeater"); + QVERIFY(repeater); + QCOMPARE(repeater->count(), 3); + + QQmlListModel *model = rootObject->findChild<QQmlListModel*>("secondModel"); + QVERIFY(model); + QCOMPARE(model->count(), 0); + + // Now change the model + QSignalSpy removedSpy(repeater, &QQuickRepeater::itemRemoved); + repeater->setModel(QVariant::fromValue(model)); + + // we should have 0 items, and 3 removal signals. + QCOMPARE(repeater->count(), 0); + QCOMPARE(removedSpy.count(), 3); + + // column 1 is for the items, we won't bother verifying these. just look at + // the indices and make sure they're sane. + QCOMPARE(removedSpy.at(0).at(0).toInt(), 2); + QCOMPARE(removedSpy.at(1).at(0).toInt(), 1); + QCOMPARE(removedSpy.at(2).at(0).toInt(), 0); + + delete rootObject; +} + QTEST_MAIN(tst_QQuickRepeater) #include "tst_qquickrepeater.moc" |