diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-08-22 11:20:03 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-08-22 15:44:49 +0000 |
commit | 8ee5dff21c3701a5a0dd1de9bed563da0aa12ef6 (patch) | |
tree | 3de793f50b4544f5209a6b5664e2d6ffe0ef7d03 /tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | |
parent | cd5937273ee14c3941574a2db7cc0f8c3682def0 (diff) |
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 <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/quick/qquicktableview/tst_qquicktableview.cpp')
-rw-r--r-- | tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
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" |