aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicklistview2
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-04-27 10:20:36 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-04-28 14:16:58 +0200
commit67c5a38fec3bdf42587d3ba446a0bbb1d7f35e38 (patch)
tree805b207c198c7b0afb070b4e3663f8f2a52c8fdf /tests/auto/quick/qquicklistview2
parent536d0c8babb2f37a43f8bef6841f18e04df2d52b (diff)
QQmlListAccessor: Support registered sequence types
Since we can pass any registered sequence types through QML as-is now, they are not wrapped into JS arrays anymore. We have to accept them as models because we also accept JS arrays. Fixes: QTBUG-102857 Change-Id: Ib294fff3681dce7f754efe877b19d17e698b4911 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 01f6ba9949a2f4ef2ac38d14f9d6f3ccff5852c9)
Diffstat (limited to 'tests/auto/quick/qquicklistview2')
-rw-r--r--tests/auto/quick/qquicklistview2/CMakeLists.txt1
-rw-r--r--tests/auto/quick/qquicklistview2/data/metaSequenceAsModel.qml12
-rw-r--r--tests/auto/quick/qquicklistview2/listviewwithsequences.h80
-rw-r--r--tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp13
4 files changed, 106 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicklistview2/CMakeLists.txt b/tests/auto/quick/qquicklistview2/CMakeLists.txt
index 0c4179dc31..a89a7737cf 100644
--- a/tests/auto/quick/qquicklistview2/CMakeLists.txt
+++ b/tests/auto/quick/qquicklistview2/CMakeLists.txt
@@ -6,6 +6,7 @@ list(APPEND test_data ${test_data_glob})
qt_internal_add_test(tst_qquicklistview2
SOURCES
+ listviewwithsequences.h
typerolemodel.h typerolemodel.cpp
tst_qquicklistview2.cpp
DEFINES
diff --git a/tests/auto/quick/qquicklistview2/data/metaSequenceAsModel.qml b/tests/auto/quick/qquicklistview2/data/metaSequenceAsModel.qml
new file mode 100644
index 0000000000..527cab9e0c
--- /dev/null
+++ b/tests/auto/quick/qquicklistview2/data/metaSequenceAsModel.qml
@@ -0,0 +1,12 @@
+import QtQuick
+import Test
+
+ListViewWithSequences {
+ id: view
+ rects: [ Qt.rect(1, 2, 3, 4), Qt.rect(5, 6, 7, 8) ]
+
+ model: rects
+ delegate: Item {
+ Component.onCompleted: view.texts.push(modelData.x + "/" + modelData.y)
+ }
+}
diff --git a/tests/auto/quick/qquicklistview2/listviewwithsequences.h b/tests/auto/quick/qquicklistview2/listviewwithsequences.h
new file mode 100644
index 0000000000..8a2c6e4db4
--- /dev/null
+++ b/tests/auto/quick/qquicklistview2/listviewwithsequences.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 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$
+**
+****************************************************************************/
+
+
+#ifndef LISTVIEWWITHSEQUENCES_H
+#define LISTVIEWWITHSEQUENCES_H
+
+#include <private/qquicklistview_p.h>
+#include <QtQml/qqml.h>
+#include <QtCore/qrect.h>
+
+class ListViewWithSequences : public QQuickListView {
+ Q_OBJECT
+ QML_ELEMENT
+ Q_PROPERTY(QList<QRectF> rects READ rects WRITE setRects NOTIFY rectsChanged)
+ Q_PROPERTY(QList<QString> texts READ texts WRITE setTexts NOTIFY textsChanged)
+public:
+ ListViewWithSequences(QQuickItem *parent = nullptr) : QQuickListView(parent) {}
+
+ const QList<QRectF> &rects() const { return m_rects; }
+ void setRects(const QList<QRectF> &rects)
+ {
+ if (rects != m_rects) {
+ m_rects = rects;
+ emit rectsChanged();
+ }
+ }
+
+ const QList<QString> &texts() const { return m_texts; }
+ void setTexts(const QList<QString> &texts)
+ {
+ if (texts != m_texts) {
+ m_texts = texts;
+ emit textsChanged();
+ }
+ }
+
+signals:
+ void rectsChanged();
+ void textsChanged();
+
+private:
+ QList<QRectF> m_rects;
+ QList<QString> m_texts;
+};
+
+struct RectListForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QList<QRectF>)
+ QML_SEQUENTIAL_CONTAINER(QRectF)
+ QML_ANONYMOUS
+};
+
+#endif // LISTVIEWWITHSEQUENCES_H
diff --git a/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp b/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp
index 6cc7abef39..f7bbbb22e8 100644
--- a/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp
+++ b/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp
@@ -57,6 +57,7 @@ private slots:
void singletonModelLifetime();
void sectionsNoOverlap();
+ void metaSequenceAsModel();
};
tst_QQuickListView2::tst_QQuickListView2()
@@ -275,6 +276,18 @@ void tst_QQuickListView2::sectionsNoOverlap()
}
}
+void tst_QQuickListView2::metaSequenceAsModel()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, testFileUrl("metaSequenceAsModel.qml"));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(!o.isNull());
+ QStringList strings = qvariant_cast<QStringList>(o->property("texts"));
+ QCOMPARE(strings.length(), 2);
+ QCOMPARE(strings[0], QStringLiteral("1/2"));
+ QCOMPARE(strings[1], QStringLiteral("5/6"));
+}
class SingletonModel : public QStringListModel
{