diff --git a/tests/auto/qml/qqmltreemodel/data/common.qml b/tests/auto/qml/qqmltreemodel/data/common.qml index ef8f98b6f4..2036d160ef 100644 --- a/tests/auto/qml/qqmltreemodel/data/common.qml +++ b/tests/auto/qml/qqmltreemodel/data/common.qml @@ -10,6 +10,7 @@ Item { height: 200 property alias testModel: testModel + property alias treeView: treeView TreeView { id: treeView diff --git a/tests/auto/qml/qqmltreemodel/tst_qqmltreemodel.cpp b/tests/auto/qml/qqmltreemodel/tst_qqmltreemodel.cpp index 39e25444be..2407af2bc8 100644 --- a/tests/auto/qml/qqmltreemodel/tst_qqmltreemodel.cpp +++ b/tests/auto/qml/qqmltreemodel/tst_qqmltreemodel.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -25,9 +26,43 @@ public: tst_QQmlTreeModel() : QQmlDataTest(QT_QMLTEST_DATADIR, FailOnWarningsPolicy::FailOnWarnings) {} private slots: + void clear(); void getRow(); }; +void tst_QQmlTreeModel::clear() +{ + QQuickView view; + QVERIFY(QQuickTest::showView(view, testFileUrl("common.qml"))); + + auto *model = view.rootObject()->property("testModel").value(); + QVERIFY(model); + + QCOMPARE(model->columnCount(), 5); + QCOMPARE(model->treeSize(), 8); + + QSignalSpy columnCountSpy(model, SIGNAL(columnCountChanged())); + QVERIFY(columnCountSpy.isValid()); + + QSignalSpy rowsChangedSpy(model, SIGNAL(rowsChanged())); + QVERIFY(rowsChangedSpy.isValid()); + + QQuickTreeView *treeView = view.rootObject()->property("treeView").value(); + QVERIFY(treeView); + QCOMPARE(treeView->columns(), 5); + QCOMPARE(treeView->rows(), 2); // treeView cannot call our treeSize + + model->clear(); + // the rows should be cleared but the columns should not change + QCOMPARE(model->columnCount(), 5); + QCOMPARE(model->treeSize(), 0); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowsChangedSpy.size(), 1); + // Wait until updatePolish() gets called, which is where the size is recalculated. + QTRY_COMPARE(treeView->rows(), 0); + QCOMPARE(treeView->columns(), 5); +} + void tst_QQmlTreeModel::getRow() { QQuickView view;