aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-09-12 09:33:47 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2018-09-13 04:57:01 +0000
commit00afb51baaf0b0398ba7780dec491cf144dad0d9 (patch)
tree231bc76a2c1726aaa1edd184274cdce48fea625a /tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
parent22a5630d3c97709b09412dc1037d7dae959bdae5 (diff)
QQuickTableView: sync model and delegate when ready to do so
Doing (silly) things in the delegate, like: Component.onCompleted: TableView.view.delegate = null will lead to a crash. The same if you change the model. The reason is that you end up changing the model while e.g a row is half-way loaded. Information needed for building the row, like model size, will then be invalid. To protect against this, we insert a "sync" phase to the code that takes any such changes into effect at a time when we know it's safe to do so. Change-Id: I85a992dfc0e04ec6635b10c9768a8ddc140e09da Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/quick/qquicktableview/tst_qquicktableview.cpp')
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index 9eb942fc93..a1951bdf90 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -106,6 +106,8 @@ private slots:
void checkExplicitContentWidthAndHeight();
void checkContentXY();
void noDelegate();
+ void changeDelegateDuringUpdate();
+ void changeModelDuringUpdate();
void countDelegateItems_data();
void countDelegateItems();
void checkLayoutOfEqualSizedDelegateItems_data();
@@ -664,6 +666,51 @@ void tst_QQuickTableView::noDelegate()
QVERIFY(items.isEmpty());
}
+void tst_QQuickTableView::changeDelegateDuringUpdate()
+{
+ // Check that you can change the delegate (set it to null)
+ // while the TableView is busy loading the table.
+ LOAD_TABLEVIEW("changemodelordelegateduringupdate.qml");
+
+ auto model = TestModelAsVariant(1, 1);
+ tableView->setModel(model);
+ view->rootObject()->setProperty("changeDelegate", true);
+
+ WAIT_UNTIL_POLISHED;
+
+ // We should no longer have a delegate, and no
+ // items should therefore be loaded.
+ QCOMPARE(tableView->delegate(), nullptr);
+ QCOMPARE(tableViewPrivate->loadedItems.size(), 0);
+
+ // Even if the delegate is missing, we still report
+ // the correct size of the model
+ QCOMPARE(tableView->rows(), 1);
+ QCOMPARE(tableView->columns(), 1);
+};
+
+void tst_QQuickTableView::changeModelDuringUpdate()
+{
+ // Check that you can change the model (set it to null)
+ // while the TableView is buzy loading the table.
+ LOAD_TABLEVIEW("changemodelordelegateduringupdate.qml");
+
+ auto model = TestModelAsVariant(1, 1);
+ tableView->setModel(model);
+ view->rootObject()->setProperty("changeModel", true);
+
+ WAIT_UNTIL_POLISHED;
+
+ // We should no longer have a model, and the no
+ // items should therefore be loaded.
+ QVERIFY(tableView->model().isNull());
+ QCOMPARE(tableViewPrivate->loadedItems.size(), 0);
+
+ // The empty model has no rows or columns
+ QCOMPARE(tableView->rows(), 0);
+ QCOMPARE(tableView->columns(), 0);
+};
+
void tst_QQuickTableView::countDelegateItems_data()
{
QTest::addColumn<QVariant>("model");