From 16ede646c96861a07108499d895c5fc56263f312 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Fri, 28 Oct 2022 18:44:07 +0200 Subject: QQuickTableView: emit changes to leftColumn() _after_ it has been updated An application might listen for e.g the leftColumnChanged signal and query the position to the delegate items in the new left column. But for this to work, be sure to layout the items (and basically finish loading the column) before emitting the signals, so that leftColumn(), rightColumn(), topRow() and bottomRow() return the correct values. Change-Id: I0e64bd2b240b0dac03120a944815ee2e5e43a6a0 Reviewed-by: Mitch Curtis --- .../quick/qquicktableview/tst_qquicktableview.cpp | 28 ++++++++++++++++++++++ 1 file changed, 28 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 099895e296..783fa4a265 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -186,6 +186,7 @@ private slots: void itemAtCell(); void leftRightTopBottomProperties_data(); void leftRightTopBottomProperties(); + void leftRightTopBottomUpdatedBeforeSignalEmission(); void checkContentSize_data(); void checkContentSize(); void checkSelectionModelWithRequiredSelectedProperty_data(); @@ -3987,6 +3988,33 @@ void tst_QQuickTableView::leftRightTopBottomProperties() QCOMPARE(bottomSpy.size(), expectedSignalCount.bottom()); } +void tst_QQuickTableView::leftRightTopBottomUpdatedBeforeSignalEmission() +{ + // Check that leftColumn, rightColumn, topRow and bottomRow are + // actually updated before the changed signals are emitted. + LOAD_TABLEVIEW("plaintableview.qml"); + auto model = TestModelAsVariant(100, 100); + tableView->setModel(model); + + WAIT_UNTIL_POLISHED; + + connect(tableView, &QQuickTableView::leftColumnChanged, [=]{ + QCOMPARE(tableView->leftColumn(), 1); + }); + connect(tableView, &QQuickTableView::rightColumnChanged, [=]{ + QCOMPARE(tableView->rightColumn(), 6); + }); + connect(tableView, &QQuickTableView::topRowChanged, [=]{ + QCOMPARE(tableView->topRow(), 1); + }); + connect(tableView, &QQuickTableView::bottomRowChanged, [=]{ + QCOMPARE(tableView->bottomRow(), 8); + }); + + tableView->setContentX(100); + tableView->setContentY(50); +} + void tst_QQuickTableView::checkContentSize_data() { QTest::addColumn("rowCount"); -- cgit v1.2.3