diff options
author | Nicolas Ettlin <nicolas.ettlin@me.com> | 2018-07-13 15:48:57 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-07-18 18:22:23 +0000 |
commit | ab1df24c8283cafd76f05c86004963c4c2d0673f (patch) | |
tree | 17c7764e393ca21f66293addcc831e745bc56d20 /tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | |
parent | 790e2f37d451933c4fe24c64e655e65e9e9c0a05 (diff) |
Qt Quick Table View: set the default row and column spacing to 0
Currently, in the TableView QML component, the initial row and column
spacing is set to (-1, -1), as in the default QSizeF constructor. As
the negative spacing was ignored when positioning the items, but taken
in account when computing the total content size, it caused an issue
where the user wouldn’t be able to scroll to the bottom right corner of
the TableView. This commit fixes this issue by setting a default
spacing to (0, 0). It also prevents the developer from using invalid
spacing values (such as negative numbers, NaN or Infinite).
Task-number: QTBUG-69454
Change-Id: I343475790c384954372afad0a778f8da7dff0b0d
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 | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index 8e02703826..dc2176f839 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -104,6 +104,7 @@ private slots: void fillTableViewButNothingMore(); void checkInitialAttachedProperties_data(); void checkInitialAttachedProperties(); + void checkSpacingValues(); void flick_data(); void flick(); void flickOvershoot_data(); @@ -687,6 +688,50 @@ void tst_QQuickTableView::checkInitialAttachedProperties() } } +void tst_QQuickTableView::checkSpacingValues() +{ + LOAD_TABLEVIEW("tableviewdefaultspacing.qml"); + + int rowCount = 9; + int columnCount = 9; + int delegateWidth = 15; + int delegateHeight = 10; + auto model = TestModelAsVariant(rowCount, columnCount); + tableView->setModel(model); + + WAIT_UNTIL_POLISHED; + + // Default spacing : 0 + QCOMPARE(tableView->rowSpacing(), 0); + QCOMPARE(tableView->columnSpacing(), 0); + + tableView->polish(); + WAIT_UNTIL_POLISHED; + QCOMPARE(tableView->contentWidth(), columnCount * (delegateWidth + tableView->columnSpacing()) - tableView->columnSpacing()); + QCOMPARE(tableView->contentHeight(), rowCount * (delegateHeight + tableView->rowSpacing()) - tableView->rowSpacing()); + + // Valid spacing assignment + tableView->setRowSpacing(42); + tableView->setColumnSpacing(12); + QCOMPARE(tableView->rowSpacing(), 42); + QCOMPARE(tableView->columnSpacing(), 12); + + tableView->polish(); + WAIT_UNTIL_POLISHED; + QCOMPARE(tableView->contentWidth(), columnCount * (delegateWidth + tableView->columnSpacing()) - tableView->columnSpacing()); + QCOMPARE(tableView->contentHeight(), rowCount * (delegateHeight + tableView->rowSpacing()) - tableView->rowSpacing()); + + // Invalid assignments (should ignore) + tableView->setRowSpacing(-1); + tableView->setColumnSpacing(-5); + tableView->setRowSpacing(INFINITY); + tableView->setColumnSpacing(INFINITY); + tableView->setRowSpacing(NAN); + tableView->setColumnSpacing(NAN); + QCOMPARE(tableView->rowSpacing(), 42); + QCOMPARE(tableView->columnSpacing(), 12); +} + void tst_QQuickTableView::flick_data() { QTest::addColumn<QSizeF>("spacing"); |