From f26ff87192cd75a9fe1c92f8078c7263680caaf8 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Thu, 29 Apr 2021 09:19:23 +0200 Subject: ListView: support QList models For now this patch just tacks on another list type, but there may be a better way to account for all types in the future. This change also adds tst_qquicklistview2 to speed up development. tst_QQuickListView is 10000 lines long, and compiling it is slow (36 seconds on a 2016 i7 MacBook Pro). In addition, a similar approach (creating a second test to avoid the slowness of a massive one) already exists for QQuickItem tests. Task-number: QTBUG-72906 Change-Id: I05455a2f20978b07eb38591ab63e7d0fb7dac1ab Reviewed-by: Fabian Kosmale Reviewed-by: Volker Hilsheimer (cherry picked from commit 0e3902b83dc3c59567a81a90c3f3c0365bdf68da) Reviewed-by: Qt CI Bot --- tests/auto/quick/CMakeLists.txt | 1 + .../quick/qquicklistview/tst_qquicklistview.cpp | 6 ++ tests/auto/quick/qquicklistview2/CMakeLists.txt | 37 +++++++++++ .../quick/qquicklistview2/data/urlListModel.qml | 69 ++++++++++++++++++++ .../quick/qquicklistview2/tst_qquicklistview2.cpp | 76 ++++++++++++++++++++++ 5 files changed, 189 insertions(+) create mode 100644 tests/auto/quick/qquicklistview2/CMakeLists.txt create mode 100644 tests/auto/quick/qquicklistview2/data/urlListModel.qml create mode 100644 tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp (limited to 'tests') diff --git a/tests/auto/quick/CMakeLists.txt b/tests/auto/quick/CMakeLists.txt index 70574110ed..f75201515d 100644 --- a/tests/auto/quick/CMakeLists.txt +++ b/tests/auto/quick/CMakeLists.txt @@ -42,6 +42,7 @@ if(QT_FEATURE_private_tests) add_subdirectory(qquickitem2) add_subdirectory(qquickitemlayer) add_subdirectory(qquicklistview) + add_subdirectory(qquicklistview2) add_subdirectory(qquicktableview) add_subdirectory(qquickloader) add_subdirectory(qquickmousearea) diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index fbc4b92762..fdd82b3bdd 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -74,6 +74,8 @@ public: tst_QQuickListView(); private slots: + // WARNING: please add new tests to tst_qquicklistview2; this file is too slow to work with. + void init(); void cleanupTestCase(); // Test QAbstractItemModel model types @@ -300,6 +302,8 @@ private slots: void requiredObjectListModel(); void clickHeaderAndFooterWhenClip(); + // WARNING: please add new tests to tst_qquicklistview2; this file is too slow to work with. + private: template void items(const QUrl &source); template void changed(const QUrl &source); @@ -10102,6 +10106,8 @@ void tst_QQuickListView::clickHeaderAndFooterWhenClip() // QTBUG-85302 QVERIFY(root->property("footerPressed").toBool()); } +// WARNING: please add new tests to tst_qquicklistview2; this file is too slow to work with. + QTEST_MAIN(tst_QQuickListView) #include "tst_qquicklistview.moc" diff --git a/tests/auto/quick/qquicklistview2/CMakeLists.txt b/tests/auto/quick/qquicklistview2/CMakeLists.txt new file mode 100644 index 0000000000..8cad53c0d2 --- /dev/null +++ b/tests/auto/quick/qquicklistview2/CMakeLists.txt @@ -0,0 +1,37 @@ +# Collect test data +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + data/*) +list(APPEND test_data ${test_data_glob}) + +qt_internal_add_test(tst_qquicklistview2 + SOURCES + ../../shared/util.cpp ../../shared/util.h + ../shared/geometrytestutil.cpp ../shared/geometrytestutil.h + ../shared/viewtestutil.cpp ../shared/viewtestutil.h + ../shared/visualtestutil.cpp ../shared/visualtestutil.h + tst_qquicklistview2.cpp + DEFINES + QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\" + INCLUDE_DIRECTORIES + ../../shared + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + Qt::QmlModelsPrivate + Qt::QmlPrivate + Qt::QuickPrivate + Qt::QuickTest + TESTDATA ${test_data} +) + +qt_internal_extend_target(tst_qquicklistview2 CONDITION ANDROID OR IOS + DEFINES + QT_QMLTEST_DATADIR=\\\":/data\\\" +) + +qt_internal_extend_target(tst_qquicklistview2 CONDITION NOT ANDROID AND NOT IOS + DEFINES + QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\" +) diff --git a/tests/auto/quick/qquicklistview2/data/urlListModel.qml b/tests/auto/quick/qquicklistview2/data/urlListModel.qml new file mode 100644 index 0000000000..91e599338d --- /dev/null +++ b/tests/auto/quick/qquicklistview2/data/urlListModel.qml @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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:BSD$ +** 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick + +Rectangle { + id: root + + property var model + property alias view: view + + ListView { + id: view + anchors.fill: parent + objectName: "view" + model: root.model + delegate: Text { + height: view.width + text: modelData + } + } +} diff --git a/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp b/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp new file mode 100644 index 0000000000..c9c7769182 --- /dev/null +++ b/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include "../shared/viewtestutil.h" +#include "../shared/visualtestutil.h" +#include "../../shared/util.h" + +using namespace QQuickViewTestUtil; +using namespace QQuickVisualTestUtil; + +class tst_QQuickListView2 : public QQmlDataTest +{ + Q_OBJECT +public: + tst_QQuickListView2(); + +private slots: + void urlListModel(); +}; + +tst_QQuickListView2::tst_QQuickListView2() +{ +} + +void tst_QQuickListView2::urlListModel() +{ + QScopedPointer window(createView()); + QVERIFY(window); + + QList model = { QUrl::fromLocalFile("abc"), QUrl::fromLocalFile("123") }; + window->setInitialProperties({{ "model", QVariant::fromValue(model) }}); + + window->setSource(testFileUrl("urlListModel.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + QQuickListView *view = window->rootObject()->property("view").value(); + QVERIFY(view); + if (QQuickTest::qIsPolishScheduled(view)) + QVERIFY(QQuickTest::qWaitForItemPolished(view)); + QCOMPARE(view->count(), model.size()); +} + +QTEST_MAIN(tst_QQuickListView2) + +#include "tst_qquicklistview2.moc" -- cgit v1.2.3