diff options
Diffstat (limited to 'tests/auto/quick/qquicktableview')
-rw-r--r-- | tests/auto/quick/qquicktableview/data/sizefromdelegate.qml | 74 | ||||
-rw-r--r-- | tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | 58 |
2 files changed, 132 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/data/sizefromdelegate.qml b/tests/auto/quick/qquicktableview/data/sizefromdelegate.qml new file mode 100644 index 0000000000..b4a04c89cb --- /dev/null +++ b/tests/auto/quick/qquicktableview/data/sizefromdelegate.qml @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Window 2.3 + +Item { + width: 640 + height: 450 + + property alias tableView: tableView + + TableView { + id: tableView + width: 600 + height: 400 + anchors.margins: 1 + delegate: tableViewDelegate + columnSpacing: 1 + rowSpacing: 1 + } + + Component { + id: tableViewDelegate + Rectangle { + color: "lightgray" + implicitWidth: text.width + implicitHeight: text.height + + Text { + id: 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 d489a873e4..d14c37d8e3 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -121,7 +121,9 @@ private slots: void checkForceLayoutFunction(); void checkForceLayoutEndUpDoingALayout(); void checkForceLayoutDuringModelChange(); + void checkForceLayoutWhenAllItemsAreHidden(); void checkContentWidthAndHeight(); + void checkContentWidthAndHeightForSmallTables(); void checkPageFlicking(); void checkExplicitContentWidthAndHeight(); void checkExtents_origin(); @@ -625,6 +627,38 @@ void tst_QQuickTableView::checkForceLayoutDuringModelChange() QCOMPARE(tableView->rows(), initialRowCount + 1); } +void tst_QQuickTableView::checkForceLayoutWhenAllItemsAreHidden() +{ + // Check that you can have a TableView where all columns are + // initially hidden, and then show some columns and call + // forceLayout(). This should make the columns become visible. + LOAD_TABLEVIEW("forcelayout.qml"); + + // Tell all columns to be hidden + const char *propertyName = "columnWidths"; + view->rootObject()->setProperty(propertyName, 0); + + const int rows = 3; + const int columns = 3; + auto model = TestModelAsVariant(rows, columns); + tableView->setModel(model); + + WAIT_UNTIL_POLISHED; + + // Check that the we have no items loaded + QCOMPARE(tableViewPrivate->loadedColumns.count(), 0); + QCOMPARE(tableViewPrivate->loadedRows.count(), 0); + QCOMPARE(tableViewPrivate->loadedItems.count(), 0); + + // Tell all columns to be visible + view->rootObject()->setProperty(propertyName, 10); + tableView->forceLayout(); + + QCOMPARE(tableViewPrivate->loadedRows.count(), rows); + QCOMPARE(tableViewPrivate->loadedColumns.count(), columns); + QCOMPARE(tableViewPrivate->loadedItems.count(), rows * columns); +} + void tst_QQuickTableView::checkContentWidthAndHeight() { // Check that contentWidth/Height reports the correct size of the @@ -673,6 +707,30 @@ void tst_QQuickTableView::checkContentWidthAndHeight() QCOMPARE(tableView->contentHeight(), expectedSizeInit); } +void tst_QQuickTableView::checkContentWidthAndHeightForSmallTables() +{ + // For tables where all the columns in the model are loaded, we know + // the exact table width, and can therefore update the content width + // if e.g new rows are added or removed. The same is true for rows. + // This test will check that we do so. + LOAD_TABLEVIEW("sizefromdelegate.qml"); + + TestModel model(3, 3); + tableView->setModel(QVariant::fromValue(&model)); + WAIT_UNTIL_POLISHED; + + const qreal initialContentWidth = tableView->contentWidth(); + const qreal initialContentHeight = tableView->contentHeight(); + const QString longText = QStringLiteral("Adding a row with a very long text"); + model.insertRow(0); + model.setModelData(QPoint(0, 0), QSize(1, 1), longText); + + WAIT_UNTIL_POLISHED; + + QVERIFY(tableView->contentWidth() > initialContentWidth); + QVERIFY(tableView->contentHeight() > initialContentHeight); +} + void tst_QQuickTableView::checkPageFlicking() { // Check that we rebuild the table instead of refilling edges, if the viewport moves |