diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-08-09 14:03:14 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-08-10 14:58:51 +0000 |
commit | 481ea25bc8aa64e7131edd85a6c871b2a3193f58 (patch) | |
tree | 3c52abef78a2321e8baf47c339a53bb2c740f648 /tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | |
parent | 886d463061ba34802bf844133396e3706d6912a4 (diff) |
QQuickTableView: add a 'forceLayout()' function to the public API
This function needs to be called from the application whenever it
needs to change column widths (or row heights) for the currently
visible columns.
Changing column widths is done by changing what values the
columnWidthProvider returns. But TableView doesn't know that the
assigned function has new values to return for the current columns.
Calling 'forceLayout()' will inform about this, and trigger
a re-layout.
Change-Id: I3cf15bbfb522baf93c7e01a34841e54455a098b9
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: J-P Nurmi <jpnurmi@gmail.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/quick/qquicktableview/tst_qquicktableview.cpp')
-rw-r--r-- | tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index b2f4e412f1..982eed7fe2 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -95,6 +95,7 @@ private slots: void checkRowHeightProvider(); void checkRowHeightProviderInvalidReturnValues(); void checkRowHeightProviderNotCallable(); + void checkForceLayoutFunction(); void checkContentWidthAndHeight(); void checkExplicitContentWidthAndHeight(); void noDelegate(); @@ -402,6 +403,35 @@ void tst_QQuickTableView::checkRowHeightProviderNotCallable() QCOMPARE(fxItem->item->height(), kDefaultRowHeight); } +void tst_QQuickTableView::checkForceLayoutFunction() +{ + // When we set the 'columnWidths' property in the test file, the + // columnWidthProvider should return other values than it did during + // start-up. Check that this takes effect after a call to the 'forceLayout()' function. + LOAD_TABLEVIEW("forcelayout.qml"); + + const char *propertyName = "columnWidths"; + auto model = TestModelAsVariant(10, 10); + + tableView->setModel(model); + + WAIT_UNTIL_POLISHED; + + // Check that the initial column widths are as specified in the QML file + const qreal initialColumnWidth = view->rootObject()->property(propertyName).toReal(); + for (auto fxItem : tableViewPrivate->loadedItems) + QCOMPARE(fxItem->item->width(), initialColumnWidth); + + // Change the return value from the columnWidthProvider to something else + const qreal newColumnWidth = 100; + view->rootObject()->setProperty(propertyName, newColumnWidth); + tableView->forceLayout(); + // We don't have to polish; The re-layout happens immediately + + for (auto fxItem : tableViewPrivate->loadedItems) + QCOMPARE(fxItem->item->width(), newColumnWidth); +} + void tst_QQuickTableView::checkContentWidthAndHeight() { // Check that contentWidth/Height reports the correct size of the the |