aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick
diff options
context:
space:
mode:
authorNicolas Ettlin <nicolas.ettlin@me.com>2018-07-13 15:48:57 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-07-18 18:22:23 +0000
commitab1df24c8283cafd76f05c86004963c4c2d0673f (patch)
tree17c7764e393ca21f66293addcc831e745bc56d20 /tests/auto/quick
parent790e2f37d451933c4fe24c64e655e65e9e9c0a05 (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')
-rw-r--r--tests/auto/quick/qquicktableview/data/tableviewdefaultspacing.qml62
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp45
2 files changed, 107 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/data/tableviewdefaultspacing.qml b/tests/auto/quick/qquicktableview/data/tableviewdefaultspacing.qml
new file mode 100644
index 0000000000..0212d5b9a4
--- /dev/null
+++ b/tests/auto/quick/qquicktableview/data/tableviewdefaultspacing.qml
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.12
+import QtQuick.Window 2.3
+import Qt.labs.tableview 1.0
+
+Item {
+ width: 640
+ height: 450
+
+ property alias tableView: tableView
+
+ TableView {
+ id: tableView
+ width: 600
+ height: 400
+ anchors.margins: 1
+ delegate: tableViewDelegate
+ }
+
+ Component {
+ id: tableViewDelegate
+ Rectangle {
+ objectName: "tableViewDelegate"
+ color: "lightgray"
+ border.width: 1
+ implicitWidth: 15
+ implicitHeight: 10
+ Text {
+ anchors.centerIn: parent
+ text: modelData
+ }
+ }
+ }
+
+}
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");