summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2021-04-29 09:19:23 +0200
committerMitch Curtis <mitch.curtis@qt.io>2021-04-30 16:14:45 +0200
commitf26ff87192cd75a9fe1c92f8078c7263680caaf8 (patch)
treef94f9e4fc845e7de61f9d9baf15de5cde7dd4664
parentdc68df916df2cf8576ebf2a03d35fefec30fa00d (diff)
ListView: support QList<QUrl> 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 <fabian.kosmale@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 0e3902b83dc3c59567a81a90c3f3c0365bdf68da) Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r--src/qmlmodels/qqmllistaccessor.cpp9
-rw-r--r--src/qmlmodels/qqmllistaccessor_p.h2
-rw-r--r--tests/auto/quick/CMakeLists.txt1
-rw-r--r--tests/auto/quick/qquicklistview/tst_qquicklistview.cpp6
-rw-r--r--tests/auto/quick/qquicklistview2/CMakeLists.txt37
-rw-r--r--tests/auto/quick/qquicklistview2/data/urlListModel.qml69
-rw-r--r--tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp76
7 files changed, 198 insertions, 2 deletions
diff --git a/src/qmlmodels/qqmllistaccessor.cpp b/src/qmlmodels/qqmllistaccessor.cpp
index 5e3fb86510..7412dd0146 100644
--- a/src/qmlmodels/qqmllistaccessor.cpp
+++ b/src/qmlmodels/qqmllistaccessor.cpp
@@ -43,6 +43,7 @@
#include <QtCore/qstringlist.h>
#include <QtCore/qdebug.h>
+#include <QtCore/qurl.h>
// ### Remove me
#include <private/qqmlengine_p.h>
@@ -78,7 +79,9 @@ void QQmlListAccessor::setList(const QVariant &v, QQmlEngine *engine)
m_type = Invalid;
} else if (d.userType() == QMetaType::QStringList) {
m_type = StringList;
- } else if (d.userType() == QMetaType::QVariantList) {
+ } else if (d.userType() == qMetaTypeId<QList<QUrl>>()) {
+ m_type = UrlList;
+ } else if (d.userType() == qMetaTypeId<QVariantList>()) {
m_type = VariantList;
} else if (d.userType() == qMetaTypeId<QList<QObject *>>()) {
m_type = ObjectList;
@@ -120,6 +123,8 @@ qsizetype QQmlListAccessor::count() const
switch(m_type) {
case StringList:
return qvariant_cast<QStringList>(d).count();
+ case UrlList:
+ return qvariant_cast<QList<QUrl>>(d).count();
case VariantList:
return qvariant_cast<QVariantList>(d).count();
case ObjectList:
@@ -142,6 +147,8 @@ QVariant QQmlListAccessor::at(qsizetype idx) const
switch(m_type) {
case StringList:
return QVariant::fromValue(qvariant_cast<QStringList>(d).at(idx));
+ case UrlList:
+ return QVariant::fromValue(qvariant_cast<QList<QUrl>>(d).at(idx));
case VariantList:
return qvariant_cast<QVariantList>(d).at(idx);
case ObjectList:
diff --git a/src/qmlmodels/qqmllistaccessor_p.h b/src/qmlmodels/qqmllistaccessor_p.h
index 3306396b00..dba3c6d402 100644
--- a/src/qmlmodels/qqmllistaccessor_p.h
+++ b/src/qmlmodels/qqmllistaccessor_p.h
@@ -70,7 +70,7 @@ public:
qsizetype count() const;
QVariant at(qsizetype) const;
- enum Type { Invalid, StringList, VariantList, ObjectList, ListProperty, Instance, Integer };
+ enum Type { Invalid, StringList, UrlList, VariantList, ObjectList, ListProperty, Instance, Integer };
Type type() const { return m_type; }
private:
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 <class T> void items(const QUrl &source);
template <class T> 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 <QtTest/QtTest>
+#include <QtQuick/qquickview.h>
+#include <QtQuick/private/qquickitemview_p_p.h>
+#include <QtQuick/private/qquicklistview_p.h>
+#include <QtQuickTest/QtQuickTest>
+#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<QQuickView> window(createView());
+ QVERIFY(window);
+
+ QList<QUrl> 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<QQuickListView*>();
+ QVERIFY(view);
+ if (QQuickTest::qIsPolishScheduled(view))
+ QVERIFY(QQuickTest::qWaitForItemPolished(view));
+ QCOMPARE(view->count(), model.size());
+}
+
+QTEST_MAIN(tst_QQuickListView2)
+
+#include "tst_qquicklistview2.moc"