diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-02-09 10:25:05 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-05-04 22:07:06 +0200 |
commit | a0d74b122a06f97fde95c1cc6974c83c3d6996b8 (patch) | |
tree | b85e39e40ad5e26247913cf91d34e24badb42ed0 /tests | |
parent | c04cec25c31917b4373db833cca079e39c7d036c (diff) |
QQmlPropertyValueInterceptor: Add binding interception support
With the new property system, it is not enough to only intercept writes;
we also need the ability to intercept calls to the bindable interface.
This is done by adding a new bindable virtual method
QQmlPropertyValueInterceptor. The default implementation does not do any
interception at all for now. This allows us to keep the existing
interceptors for now, and to port them step by step. Once all
interceptors in Qt are ported, we can make the method in the interface
pure virtual.
Task-number: QTBUG-90999
Change-Id: I697658a1cd9a5204805a444e0d949213ba71b91c
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmlmetatype/data/interceptorApi.qml | 13 | ||||
-rw-r--r-- | tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp | 42 |
2 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlmetatype/data/interceptorApi.qml b/tests/auto/qml/qqmlmetatype/data/interceptorApi.qml new file mode 100644 index 0000000000..229dd2e6a9 --- /dev/null +++ b/tests/auto/qml/qqmlmetatype/data/interceptorApi.qml @@ -0,0 +1,13 @@ +import QtQml +import test + +QtObject { + id: root + default property list<QtObject> children + Interceptor on objectName { id: interceptor } + property string s: "foo" + objectName: s + + property Interceptor i: interceptor + Component.onCompleted: () => root.objectName = "bar" +} diff --git a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp index 57adb79097..c23c0fb73f 100644 --- a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp +++ b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp @@ -57,6 +57,8 @@ private slots: void compositeType(); void externalEnums(); + void interceptorAPI(); + void isList(); void defaultObject(); @@ -337,6 +339,46 @@ void tst_qqmlmetatype::externalEnums() } +class ForwardAndLogInterceptor : public QObject, public QQmlPropertyValueInterceptor { + Q_OBJECT + Q_INTERFACES(QQmlPropertyValueInterceptor) +public: + + // QQmlPropertyValueInterceptor interface + void setTarget(const QQmlProperty &property) override + { + m_property = property; + } + void write(const QVariant &value) override + { + interceptedWrite = true; + QQmlPropertyPrivate::write(m_property, value, QQmlPropertyData::BypassInterceptor); + } + bool bindable(QUntypedBindable *bindable, QUntypedBindable target) override + { + interceptedBindable = true; + *bindable = target; + return true; + } + + QQmlProperty m_property; + bool interceptedBindable = false; + bool interceptedWrite = false; +}; + +void tst_qqmlmetatype::interceptorAPI() +{ + qmlRegisterType<ForwardAndLogInterceptor>("test", 1, 0, "Interceptor"); + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("interceptorApi.qml")); + QScopedPointer<QObject> obj(component.create()); + QVERIFY2(obj, qPrintable(component.errorString())); + + auto interceptor = obj->property("i").value<ForwardAndLogInterceptor *>(); + QVERIFY(interceptor->interceptedBindable); + QVERIFY(interceptor->interceptedWrite); +} + class Controller1 : public QObject { Q_OBJECT |