aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-01-23 14:44:32 +0100
committerUlf Hermann <ulf.hermann@qt.io>2023-01-25 18:08:36 +0100
commit518509297fd545892ed4200b7b806f87d19cc57d (patch)
treef24ae9289aa36fa41b5fea9715fb17fc05cf9649 /tests/auto
parent6972cf37228a9808ed225915b1fc4e38ff17b06a (diff)
qmltyperegistrar: Strip '*' from list value types
We do this for function return types, property types, and function argument types already. Formally, we would have to store some "isPointer" somewhere, but considering that we never read it anyway, let's not go there. This allows the compilers to recognize lists of QObject-derived types as proper lists. This way we can generate better code for moving them around or getting their length. Pick-to: 6.5 Task-number: QTBUG-110438 Change-Id: I35e0fc21d574afc18799e9c3cef402f05b60a3ed Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/badSequence.qml2
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/person.cpp13
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/person.h17
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp10
4 files changed, 40 insertions, 2 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/badSequence.qml b/tests/auto/qml/qmlcppcodegen/data/badSequence.qml
index 785765ec74..e2ce707205 100644
--- a/tests/auto/qml/qmlcppcodegen/data/badSequence.qml
+++ b/tests/auto/qml/qmlcppcodegen/data/badSequence.qml
@@ -3,5 +3,7 @@ import TestTypes
Person {
property Person other: Person { id: oo }
barzles: oo.barzles
+ cousins: oo.cousins
property int l: oo.barzles.length
+ property int m: oo.cousins.length
}
diff --git a/tests/auto/qml/qmlcppcodegen/data/person.cpp b/tests/auto/qml/qmlcppcodegen/data/person.cpp
index 348e41ba0b..4dcd6fd56f 100644
--- a/tests/auto/qml/qmlcppcodegen/data/person.cpp
+++ b/tests/auto/qml/qmlcppcodegen/data/person.cpp
@@ -85,3 +85,16 @@ QByteArray Person::data() const
{
return m_data;
}
+
+QList<Person *> Person::cousins() const
+{
+ return m_cousins;
+}
+
+void Person::setCousins(const QList<Person *> &newCousins)
+{
+ if (m_cousins == newCousins)
+ return;
+ m_cousins = newCousins;
+ emit cousinsChanged();
+}
diff --git a/tests/auto/qml/qmlcppcodegen/data/person.h b/tests/auto/qml/qmlcppcodegen/data/person.h
index 6961b01e12..fba4a9e9a5 100644
--- a/tests/auto/qml/qmlcppcodegen/data/person.h
+++ b/tests/auto/qml/qmlcppcodegen/data/person.h
@@ -9,6 +9,7 @@
#include <QtQml/qqmlengine.h>
#include <QtCore/qproperty.h>
+// Intentionally opaque type
class Barzle : public QObject {};
class Person : public QObject
@@ -19,6 +20,7 @@ class Person : public QObject
Q_PROPERTY(int pain READ pain CONSTANT FINAL)
Q_PROPERTY(QVariantList things READ things WRITE setThings NOTIFY thingsChanged FINAL)
Q_PROPERTY(QList<Barzle *> barzles READ barzles WRITE setBarzles NOTIFY barzlesChanged FINAL)
+ Q_PROPERTY(QList<Person *> cousins READ cousins WRITE setCousins NOTIFY cousinsChanged FINAL)
Q_PROPERTY(QByteArray data READ data WRITE setData NOTIFY dataChanged FINAL)
QML_ELEMENT
public:
@@ -47,6 +49,9 @@ public:
void setData(const QByteArray &data);
QByteArray data() const;
+ QList<Person *> cousins() const;
+ void setCousins(const QList<Person *> &newCousins);
+
signals:
void nameChanged();
void shoeSizeChanged();
@@ -56,15 +61,18 @@ signals:
void ambiguous(int a = 9);
+ void cousinsChanged();
+
private:
QString m_name;
int m_shoeSize;
QVariantList m_things;
QList<Barzle *> m_barzles;
+ QList<Person *> m_cousins;
QProperty<QByteArray> m_data;
};
-class FoozleListRegistration
+class BarzleListRegistration
{
Q_GADGET
QML_FOREIGN(QList<Barzle *>)
@@ -72,5 +80,12 @@ class FoozleListRegistration
QML_SEQUENTIAL_CONTAINER(Barzle *)
};
+class PersonListRegistration
+{
+ Q_GADGET
+ QML_FOREIGN(QList<Person *>)
+ QML_ANONYMOUS
+ QML_SEQUENTIAL_CONTAINER(Person *)
+};
#endif // PERSON_H
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index bd11d613e5..b5a146ad12 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -2460,20 +2460,28 @@ void tst_QmlCppCodegen::badSequence()
QScopedPointer<QObject> o(c.create());
Person *self = qobject_cast<Person *>(o.data());
- QVERIFY(self); QVERIFY(self->barzles().isEmpty());
+ QVERIFY(self);
+ QVERIFY(self->barzles().isEmpty());
+ QVERIFY(self->cousins().isEmpty());
Person *other = o->property("other").value<Person *>();
QVERIFY(other);
QVERIFY(other->barzles().isEmpty());
+ QVERIFY(other->cousins().isEmpty());
Barzle f1;
Barzle f2;
const QList<Barzle *> barzles { &f1, &f2 };
+ const QList<Person *> cousins { self, other };
other->setBarzles(barzles);
QCOMPARE(self->barzles(), barzles);
QCOMPARE(self->property("l").toInt(), 2);
+
+ other->setCousins(cousins);
+ QCOMPARE(self->cousins(), cousins);
+ QCOMPARE(self->property("m").toInt(), 2);
}
void tst_QmlCppCodegen::enumLookup()