aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/data
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-08-14 16:03:05 +0200
committerUlf Hermann <ulf.hermann@qt.io>2023-08-24 12:39:43 +0200
commit72e9f475268dac1543c8cd17510dbf9a57783a76 (patch)
tree68e3284fbb0bda5f85c194e9612ed941d1b9ecd9 /tests/auto/qml/qmlcppcodegen/data
parentc86c13d491ec80cbdecba513959ca481a508cb72 (diff)
QmlCompiler: Allow write-back to members of objects
This covers recursive write-back, but not write-back to members of singletons or attached types, write-back of lists. Task-number: QTBUG-116011 Change-Id: I6d33fae3bf9fdaed8d696a708124e0a707ecb07e Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/data')
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt1
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/failures.qml5
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/person.cpp7
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/person.h32
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/writeback.qml34
5 files changed, 72 insertions, 7 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
index 99cbf9dcd5..865b0ffa64 100644
--- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
+++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
@@ -247,6 +247,7 @@ set(qml_files
versionmismatch.qml
voidConversion.qml
voidfunction.qml
+ writeback.qml
dummy_imports.qml
)
diff --git a/tests/auto/qml/qmlcppcodegen/data/failures.qml b/tests/auto/qml/qmlcppcodegen/data/failures.qml
index f255274206..2dfa751780 100644
--- a/tests/auto/qml/qmlcppcodegen/data/failures.qml
+++ b/tests/auto/qml/qmlcppcodegen/data/failures.qml
@@ -83,11 +83,6 @@ QtObject {
return a;
}
- property Person shadowable
- function setLookupOnShadowable() {
- shadowable.area.width = 16
- }
-
// TODO: Drop these once we can manipulate QVariant-wrapped lists.
property list<withLength> withLengths
property int l: withLengths.length
diff --git a/tests/auto/qml/qmlcppcodegen/data/person.cpp b/tests/auto/qml/qmlcppcodegen/data/person.cpp
index f6353d9b67..9b3710b22f 100644
--- a/tests/auto/qml/qmlcppcodegen/data/person.cpp
+++ b/tests/auto/qml/qmlcppcodegen/data/person.cpp
@@ -106,8 +106,13 @@ QRectF Person::area() const
void Person::setArea(const QRectF &newArea)
{
- if (m_area == newArea)
+ if (m_area.valueBypassingBindings() == newArea)
return;
m_area = newArea;
emit areaChanged();
}
+
+QBindable<QRectF> Person::areaBindable()
+{
+ return QBindable<QRectF>(&m_area);
+}
diff --git a/tests/auto/qml/qmlcppcodegen/data/person.h b/tests/auto/qml/qmlcppcodegen/data/person.h
index 85306b2eae..f722ed3046 100644
--- a/tests/auto/qml/qmlcppcodegen/data/person.h
+++ b/tests/auto/qml/qmlcppcodegen/data/person.h
@@ -10,6 +10,34 @@
#include <QtCore/qproperty.h>
#include <QtCore/qrect.h>
+struct Inner
+{
+ Q_GADGET
+ QML_VALUE_TYPE(inner)
+ QML_STRUCTURED_VALUE
+ Q_PROPERTY(int i MEMBER i)
+
+private:
+ friend bool operator==(const Inner &lhs, const Inner &rhs) { return lhs.i == rhs.i; }
+ friend bool operator!=(const Inner &lhs, const Inner &rhs) { return !(lhs == rhs); }
+
+ int i = 11;
+};
+
+struct Outer
+{
+ Q_GADGET
+ QML_VALUE_TYPE(outer)
+ QML_STRUCTURED_VALUE
+ Q_PROPERTY(Inner inner MEMBER inner)
+
+private:
+ friend bool operator==(const Outer &lhs, const Outer &rhs) { return lhs.inner == rhs.inner; }
+ friend bool operator!=(const Outer &lhs, const Outer &rhs) { return !(lhs == rhs); }
+
+ Inner inner;
+};
+
// Intentionally opaque type
class Barzle : public QObject {};
@@ -24,6 +52,7 @@ class Person : public QObject
Q_PROPERTY(QList<Person *> cousins READ cousins WRITE setCousins NOTIFY cousinsChanged FINAL)
Q_PROPERTY(QByteArray data READ data WRITE setData NOTIFY dataChanged FINAL)
Q_PROPERTY(QRectF area READ area WRITE setArea NOTIFY areaChanged) // not FINAL
+ Q_PROPERTY(QRectF area2 READ area WRITE setArea NOTIFY areaChanged BINDABLE areaBindable FINAL)
QML_ELEMENT
public:
Person(QObject *parent = nullptr);
@@ -56,6 +85,7 @@ public:
QRectF area() const;
void setArea(const QRectF &newArea);
+ QBindable<QRectF> areaBindable();
Q_INVOKABLE QString getName() const { return m_name; }
@@ -81,7 +111,7 @@ private:
QList<Barzle *> m_barzles;
QList<Person *> m_cousins;
QProperty<QByteArray> m_data;
- QRectF m_area;
+ QProperty<QRectF> m_area;
};
class BarzleListRegistration
diff --git a/tests/auto/qml/qmlcppcodegen/data/writeback.qml b/tests/auto/qml/qmlcppcodegen/data/writeback.qml
new file mode 100644
index 0000000000..17ddf7fd3e
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/writeback.qml
@@ -0,0 +1,34 @@
+pragma Strict
+
+import TestTypes
+import QtQml
+
+Person {
+ id: self
+
+ area {
+ width: 19
+ height: 199
+ }
+
+ property outer recursive
+ property Person shadowable: Person {
+ area.width: self.area.width
+ area2.height: self.area2.height
+ }
+
+ Component.onCompleted: {
+ area.width = 16
+ area2.height = 17
+
+ self.area.x = 4
+ self.area2.y = 5
+
+ shadowable.area.x = 40
+ shadowable.area2.y = 50
+
+ self.recursive.inner.i = 99;
+ }
+
+ property int inner: recursive.inner.i
+}