diff options
author | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2022-04-07 15:22:02 +0300 |
---|---|---|
committer | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2022-04-07 15:22:02 +0300 |
commit | 04ea6df18a2b06efd133a4f1b13c2e38817279ae (patch) | |
tree | 73b84355c755c6e21f3f66816aeb13e6a16012cd /tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | |
parent | 4bb06cfba94bcc9ddf30d968a227d00479d475b7 (diff) | |
parent | 1089f8f226d546aef3b032a2f4391e08a3afa48d (diff) |
Merge remote-tracking branch 'origin/tqtc/lts-5.15.4' into tqtc/lts-5.15-opensourcev5.15.4-lts-lgpl
Change-Id: I39595f8b7ad212c842709b939226d95531819391
Diffstat (limited to 'tests/auto/quick/qquicktableview/tst_qquicktableview.cpp')
-rw-r--r-- | tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index d489a873e4..d14c37d8e3 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -121,7 +121,9 @@ private slots: void checkForceLayoutFunction(); void checkForceLayoutEndUpDoingALayout(); void checkForceLayoutDuringModelChange(); + void checkForceLayoutWhenAllItemsAreHidden(); void checkContentWidthAndHeight(); + void checkContentWidthAndHeightForSmallTables(); void checkPageFlicking(); void checkExplicitContentWidthAndHeight(); void checkExtents_origin(); @@ -625,6 +627,38 @@ void tst_QQuickTableView::checkForceLayoutDuringModelChange() QCOMPARE(tableView->rows(), initialRowCount + 1); } +void tst_QQuickTableView::checkForceLayoutWhenAllItemsAreHidden() +{ + // Check that you can have a TableView where all columns are + // initially hidden, and then show some columns and call + // forceLayout(). This should make the columns become visible. + LOAD_TABLEVIEW("forcelayout.qml"); + + // Tell all columns to be hidden + const char *propertyName = "columnWidths"; + view->rootObject()->setProperty(propertyName, 0); + + const int rows = 3; + const int columns = 3; + auto model = TestModelAsVariant(rows, columns); + tableView->setModel(model); + + WAIT_UNTIL_POLISHED; + + // Check that the we have no items loaded + QCOMPARE(tableViewPrivate->loadedColumns.count(), 0); + QCOMPARE(tableViewPrivate->loadedRows.count(), 0); + QCOMPARE(tableViewPrivate->loadedItems.count(), 0); + + // Tell all columns to be visible + view->rootObject()->setProperty(propertyName, 10); + tableView->forceLayout(); + + QCOMPARE(tableViewPrivate->loadedRows.count(), rows); + QCOMPARE(tableViewPrivate->loadedColumns.count(), columns); + QCOMPARE(tableViewPrivate->loadedItems.count(), rows * columns); +} + void tst_QQuickTableView::checkContentWidthAndHeight() { // Check that contentWidth/Height reports the correct size of the @@ -673,6 +707,30 @@ void tst_QQuickTableView::checkContentWidthAndHeight() QCOMPARE(tableView->contentHeight(), expectedSizeInit); } +void tst_QQuickTableView::checkContentWidthAndHeightForSmallTables() +{ + // For tables where all the columns in the model are loaded, we know + // the exact table width, and can therefore update the content width + // if e.g new rows are added or removed. The same is true for rows. + // This test will check that we do so. + LOAD_TABLEVIEW("sizefromdelegate.qml"); + + TestModel model(3, 3); + tableView->setModel(QVariant::fromValue(&model)); + WAIT_UNTIL_POLISHED; + + const qreal initialContentWidth = tableView->contentWidth(); + const qreal initialContentHeight = tableView->contentHeight(); + const QString longText = QStringLiteral("Adding a row with a very long text"); + model.insertRow(0); + model.setModelData(QPoint(0, 0), QSize(1, 1), longText); + + WAIT_UNTIL_POLISHED; + + QVERIFY(tableView->contentWidth() > initialContentWidth); + QVERIFY(tableView->contentHeight() > initialContentHeight); +} + void tst_QQuickTableView::checkPageFlicking() { // Check that we rebuild the table instead of refilling edges, if the viewport moves |