diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2021-03-25 13:52:37 +0100 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2021-04-13 19:19:56 +0200 |
commit | b15d300fd1d5151a8540d47a20b002a8fefb907b (patch) | |
tree | 432da1b1721e60b7f4cb65fe185d3c9ed788c686 /tests/auto/quick/qquicktableview | |
parent | bd1e0844aef407924863f8368b4f475937290ee5 (diff) |
QQuickTableView: add isColumnLoaded() and isRowLoaded()
TableView needs an API that lets you check if the
delegate items inside a row or column is available
for iteration from within the columnWidth/rowHeightProvider.
This is especially needed since we call the providers
several times when loading a new row or column - once
to figure out if it's visible, and another time later,
to get the width to use for layout when the items
are loaded.
[ChangeLog][QtQuick][TableView] Added API to query if a
row or column is loaded and available for iteration:
isRowLoaded(row) and isColumnLoaded(column).
Fixes: QTBUG-92151
Change-Id: Iad0c9953a794bb6464b973f79e18826b4727fb47
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/quick/qquicktableview')
-rw-r--r-- | tests/auto/quick/qquicktableview/data/iscolumnloaded.qml | 103 | ||||
-rw-r--r-- | tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | 21 |
2 files changed, 124 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/data/iscolumnloaded.qml b/tests/auto/quick/qquicktableview/data/iscolumnloaded.qml new file mode 100644 index 0000000000..1cae7aad75 --- /dev/null +++ b/tests/auto/quick/qquicktableview/data/iscolumnloaded.qml @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** 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 +import QtQuick.Window + +Item { + width: 640 + height: 450 + + property alias tableView: tableView + property int itemsInColumnAfterLoaded: 0 + property int itemsInRowAfterLoaded: 0 + + TableView { + id: tableView + width: 600 + height: 400 + anchors.margins: 1 + clip: true + delegate: tableViewDelegate + columnSpacing: 1 + rowSpacing: 1 + columnWidthProvider: function(column) { + if (isColumnLoaded(column)) { + var count = 0; + for (var row = topRow; row <= bottomRow; ++row) { + var item = itemAtCell(Qt.point(column, row)) + if (item) + count++; + } + itemsInColumnAfterLoaded = count; + } + + return -1 + } + rowHeightProvider: function(row) { + if (isRowLoaded(row)) { + var count = 0; + for (var column = leftColumn; column <= rightColumn; ++column) { + var item = itemAtCell(Qt.point(column, row)) + if (item) + count++; + } + itemsInRowAfterLoaded = count; + } + + return -1 + } + } + + Component { + id: tableViewDelegate + Rectangle { + objectName: "tableViewDelegate" + implicitWidth: 20 + implicitHeight: 20 + color: "lightgray" + border.width: 1 + 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 005aae0639..069e424d44 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -118,6 +118,7 @@ private slots: void checkRowHeightProviderInvalidReturnValues(); void checkRowHeightProviderNegativeReturnValue(); void checkRowHeightProviderNotCallable(); + void isColumnLoadedAndIsRowLoaded(); void checkForceLayoutFunction(); void checkForceLayoutEndUpDoingALayout(); void checkForceLayoutDuringModelChange(); @@ -553,6 +554,26 @@ void tst_QQuickTableView::checkRowHeightProviderNotCallable() QCOMPARE(fxItem->item->height(), kDefaultRowHeight); } +void tst_QQuickTableView::isColumnLoadedAndIsRowLoaded() +{ + // Check that all the delegate items are loaded and available from + // the columnWidthProvider/rowHeightProvider when 'isColumnLoaded()' + // and 'isRowLoaded()' returns true. + LOAD_TABLEVIEW("iscolumnloaded.qml"); + + auto model = TestModelAsVariant(4, 5); + + tableView->setModel(model); + + WAIT_UNTIL_POLISHED; + + const int itemsInColumnAfterLoaded = view->rootObject()->property("itemsInColumnAfterLoaded").toInt(); + const int itemsInRowAfterLoaded = view->rootObject()->property("itemsInRowAfterLoaded").toInt(); + + QCOMPARE(itemsInColumnAfterLoaded, tableView->rows()); + QCOMPARE(itemsInRowAfterLoaded, tableView->columns()); +} + void tst_QQuickTableView::checkForceLayoutFunction() { // When we set the 'columnWidths' property in the test file, the |