From ab1df24c8283cafd76f05c86004963c4c2d0673f Mon Sep 17 00:00:00 2001 From: Nicolas Ettlin Date: Fri, 13 Jul 2018 15:48:57 +0200 Subject: Qt Quick Table View: set the default row and column spacing to 0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../quick/qquicktableview/tst_qquicktableview.cpp | 45 ++++++++++++++++++++++ 1 file changed, 45 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 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("spacing"); -- cgit v1.2.3