From 8ee5dff21c3701a5a0dd1de9bed563da0aa12ef6 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 22 Aug 2018 11:20:03 +0200 Subject: QQmlDelegateModelItem: ensure that we emit changes to row and column As it stood, we would only emit changes to row and column if index changed as well. But when removing rows and columns from the model, it can happen that we reuse an item that by accident has the same index as the one we change it to, but belonging to a different row and column. So we need to check for changes to the index the same way we do for row and column. Change-Id: I9d507a74aa5dcb0fe7630e7af1e949bd2db7fb47 Reviewed-by: Mitch Curtis --- .../quick/qquicktableview/tst_qquicktableview.cpp | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests/auto/quick/qquicktableview/tst_qquicktableview.cpp') diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index b49164a78c..ea3531ba13 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -127,6 +127,7 @@ private slots: void checkContextProperties(); void checkContextPropertiesQQmlListProperyModel_data(); void checkContextPropertiesQQmlListProperyModel(); + void checkRowAndColumnChangedButNotIndex(); }; tst_QQuickTableView::tst_QQuickTableView() @@ -1593,6 +1594,34 @@ void tst_QQuickTableView::checkContextPropertiesQQmlListProperyModel() } } +void tst_QQuickTableView::checkRowAndColumnChangedButNotIndex() +{ + // Check that context row and column changes even if the index stays the + // same when the item is reused. This can happen in rare cases if the item + // is first used at e.g (row 1, col 0), but then reused at (row 0, col 1) + // while the model has changed row count in-between. + LOAD_TABLEVIEW("checkrowandcolumnnotchanged.qml"); + + TestModel model(2, 1); + tableView->setModel(QVariant::fromValue(&model)); + + WAIT_UNTIL_POLISHED; + + model.removeRow(1); + model.insertColumn(1); + tableView->forceLayout(); + + const auto item = tableViewPrivate->loadedTableItem(QPoint(1, 0))->item; + const auto context = qmlContext(item.data()); + const int contextIndex = context->contextProperty("index").toInt(); + const int contextRow = context->contextProperty("row").toInt(); + const int contextColumn = context->contextProperty("column").toInt(); + + QCOMPARE(contextIndex, 1); + QCOMPARE(contextRow, 0); + QCOMPARE(contextColumn, 1); +} + QTEST_MAIN(tst_QQuickTableView) #include "tst_qquicktableview.moc" -- cgit v1.2.3