diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-06-19 14:56:24 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-07-18 15:36:59 +0000 |
commit | 7661a4197ca7967db0913f888295bb332519fbcc (patch) | |
tree | d872ff4eb3166fd4418c998409455bf746aca1ee /tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | |
parent | fc0e40f413808dd1a7b5631e5f087c3970db2869 (diff) |
QQuickTableView: change how tableview resolves column width and row height
The current solution of storing column widths as the user flicks around
turns out to not scale so well for huge data models. We basically don't
want to take on the responsibility of storing column widths and row
heights for e.g 100 000 rows/columns. Instead, we now choose to ask the
application for the sizes, whenever we need them. This way, the application
developer can optimize how to store/calculate/determine/persist row and
column sizes locally.
To implement this functionality, we add two new properties:
rowHeightProvider and columnWidthProvider. They both accept a javascript
function that takes one argument (row or column), and returns the
corresponing row height or column width.
If no function is assigned to the properties, TableView will calculate
the row height / column width based on the currently visible items, as
before.
Change-Id: I6e5552599f63c896531cf3963e8745658ba4d45a
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 | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index 2a6179847d..db73d916af 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -85,6 +85,14 @@ private slots: void emptyModel(); void checkZeroSizedDelegate(); void checkImplicitSizeDelegate(); + void checkColumnWidthWithoutProvider(); + void checkColumnWidthProvider(); + void checkColumnWidthProviderInvalidReturnValues(); + void checkColumnWidthProviderNotCallable(); + void checkRowHeightWithoutProvider(); + void checkRowHeightProvider(); + void checkRowHeightProviderInvalidReturnValues(); + void checkRowHeightProviderNotCallable(); void noDelegate(); void countDelegateItems_data(); void countDelegateItems(); @@ -181,6 +189,8 @@ void tst_QQuickTableView::checkZeroSizedDelegate() view->rootObject()->setProperty("delegateWidth", 0); view->rootObject()->setProperty("delegateHeight", 0); + QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*implicit")); + WAIT_UNTIL_POLISHED; auto items = tableViewPrivate->loadedItems; @@ -215,6 +225,163 @@ void tst_QQuickTableView::checkImplicitSizeDelegate() } } +void tst_QQuickTableView::checkColumnWidthWithoutProvider() +{ + // Checks that a function isn't assigned to the columnWidthProvider property + // and that the column width is equal to the implicitWidth of the delegate. + LOAD_TABLEVIEW("alternatingrowheightcolumnwidth.qml"); + + auto model = TestModelAsVariant(10, 10); + + tableView->setModel(model); + QVERIFY(tableView->columnWidthProvider().isUndefined()); + + WAIT_UNTIL_POLISHED; + + for (auto fxItem : tableViewPrivate->loadedItems) { + // expectedWidth mirrors the implicit width of the delegate + qreal expectedWidth = fxItem->cell.x() % 2 ? 30 : 40; + QCOMPARE(fxItem->item->width(), expectedWidth); + } +} + +void tst_QQuickTableView::checkColumnWidthProvider() +{ + // Check that you can assign a function to the columnWidthProvider property, and + // that it's used to control (and override) the width of the columns. + LOAD_TABLEVIEW("userowcolumnprovider.qml"); + + auto model = TestModelAsVariant(10, 10); + + tableView->setModel(model); + QVERIFY(tableView->columnWidthProvider().isCallable()); + + WAIT_UNTIL_POLISHED; + + for (auto fxItem : tableViewPrivate->loadedItems) { + // expectedWidth mirrors the expected return value of the assigned javascript function + qreal expectedWidth = fxItem->cell.x() + 10; + QCOMPARE(fxItem->item->width(), expectedWidth); + } +} + +void tst_QQuickTableView::checkColumnWidthProviderInvalidReturnValues() +{ + // Check that we fall back to use default columns widths, if you + // assign a function to columnWidthProvider that returns invalid values. + LOAD_TABLEVIEW("usefaultyrowcolumnprovider.qml"); + + auto model = TestModelAsVariant(10, 10); + + tableView->setModel(model); + + QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*Provider.*valid")); + + WAIT_UNTIL_POLISHED; + + for (auto fxItem : tableViewPrivate->loadedItems) + QCOMPARE(fxItem->item->width(), kDefaultColumnWidth); +} + +void tst_QQuickTableView::checkColumnWidthProviderNotCallable() +{ + // Check that we fall back to use default columns widths, if you + // assign something to columnWidthProvider that is not callable. + LOAD_TABLEVIEW("usefaultyrowcolumnprovider.qml"); + + auto model = TestModelAsVariant(10, 10); + + tableView->setModel(model); + tableView->setRowHeightProvider(QJSValue()); + tableView->setColumnWidthProvider(QJSValue(10)); + + QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".Provider.*function")); + + WAIT_UNTIL_POLISHED; + + for (auto fxItem : tableViewPrivate->loadedItems) + QCOMPARE(fxItem->item->width(), kDefaultColumnWidth); +} + +void tst_QQuickTableView::checkRowHeightWithoutProvider() +{ + // Checks that a function isn't assigned to the rowHeightProvider property + // and that the row height is equal to the implicitHeight of the delegate. + LOAD_TABLEVIEW("alternatingrowheightcolumnwidth.qml"); + + auto model = TestModelAsVariant(10, 10); + QVERIFY(tableView->rowHeightProvider().isUndefined()); + + tableView->setModel(model); + + WAIT_UNTIL_POLISHED; + + for (auto fxItem : tableViewPrivate->loadedItems) { + // expectedHeight mirrors the implicit height of the delegate + qreal expectedHeight = fxItem->cell.y() % 2 ? 30 : 40; + QCOMPARE(fxItem->item->height(), expectedHeight); + } +} + +void tst_QQuickTableView::checkRowHeightProvider() +{ + // Check that you can assign a function to the columnWidthProvider property, and + // that it's used to control (and override) the width of the columns. + LOAD_TABLEVIEW("userowcolumnprovider.qml"); + + auto model = TestModelAsVariant(10, 10); + + tableView->setModel(model); + QVERIFY(tableView->rowHeightProvider().isCallable()); + + WAIT_UNTIL_POLISHED; + + for (auto fxItem : tableViewPrivate->loadedItems) { + // expectedWidth mirrors the expected return value of the assigned javascript function + qreal expectedHeight = fxItem->cell.y() + 10; + QCOMPARE(fxItem->item->height(), expectedHeight); + } +} + +void tst_QQuickTableView::checkRowHeightProviderInvalidReturnValues() +{ + // Check that we fall back to use default row heights, if you + // assign a function to rowHeightProvider that returns invalid values. + LOAD_TABLEVIEW("usefaultyrowcolumnprovider.qml"); + + auto model = TestModelAsVariant(10, 10); + + tableView->setModel(model); + + QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*Provider.*valid")); + + WAIT_UNTIL_POLISHED; + + for (auto fxItem : tableViewPrivate->loadedItems) + QCOMPARE(fxItem->item->height(), kDefaultRowHeight); +} + +void tst_QQuickTableView::checkRowHeightProviderNotCallable() +{ + // Check that we fall back to use default row heights, if you + // assign something to rowHeightProvider that is not callable. + LOAD_TABLEVIEW("usefaultyrowcolumnprovider.qml"); + + auto model = TestModelAsVariant(10, 10); + + tableView->setModel(model); + + tableView->setColumnWidthProvider(QJSValue()); + tableView->setRowHeightProvider(QJSValue(10)); + + QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*Provider.*function")); + + WAIT_UNTIL_POLISHED; + + for (auto fxItem : tableViewPrivate->loadedItems) + QCOMPARE(fxItem->item->height(), kDefaultRowHeight); +} + void tst_QQuickTableView::noDelegate() { // Check that you can skip setting a delegate without |