diff options
author | Pierre-Yves Siret <gr3cko@gmail.com> | 2020-01-28 23:46:56 +0100 |
---|---|---|
committer | Pierre-Yves Siret <gr3cko@gmail.com> | 2020-01-31 08:43:33 +0100 |
commit | 276d00cff956cb54612ec425b7c40eb50a20d78a (patch) | |
tree | f4b2855b4e1779d36b7d3e3338f1cb196b880c2d /tests/auto/quick/qquickbehaviors | |
parent | f7647d5adaaed4c651cb2e65c7ce66d7ef6639f1 (diff) |
Add Behavior.targetProperty property
[ChangeLog][Behavior] Behavior now have a targetProperty property to
allow custom logic based on the target property's object or name.
Fixes: QTBUG-70964
Change-Id: I866c10d36c7de181fff48da94c8e16cd73ce49b1
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/quick/qquickbehaviors')
-rw-r--r-- | tests/auto/quick/qquickbehaviors/data/targetProperty.qml | 16 | ||||
-rw-r--r-- | tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp | 22 |
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickbehaviors/data/targetProperty.qml b/tests/auto/quick/qquickbehaviors/data/targetProperty.qml new file mode 100644 index 0000000000..18abd46010 --- /dev/null +++ b/tests/auto/quick/qquickbehaviors/data/targetProperty.qml @@ -0,0 +1,16 @@ +import QtQuick 2.15 + +Item { + readonly property QtObject xBehaviorObject: xBehavior.targetProperty.object + readonly property string xBehaviorName: xBehavior.targetProperty.name + readonly property QtObject emptyBehaviorObject: emptyBehavior.targetProperty.object + readonly property string emptyBehaviorName: emptyBehavior.targetProperty.name + Behavior on x { + id: xBehavior + objectName: "xBehavior" + } + Behavior { + id: emptyBehavior + objectName: "emptyBehavior" + } +} diff --git a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp index 64e32dcdfd..3b46019f64 100644 --- a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp +++ b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp @@ -75,6 +75,7 @@ private slots: void innerBehaviorOverwritten(); void oneWay(); void safeToDelete(); + void targetProperty(); }; void tst_qquickbehaviors::simpleBehavior() @@ -656,6 +657,27 @@ void tst_qquickbehaviors::safeToDelete() QVERIFY(c.create()); } +Q_DECLARE_METATYPE(QQmlProperty) +void tst_qquickbehaviors::targetProperty() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("targetProperty.qml")); + QScopedPointer<QQuickItem> item(qobject_cast<QQuickItem*>(c.create())); + QVERIFY2(!item.isNull(), qPrintable(c.errorString())); + + QQuickBehavior* xBehavior = + qobject_cast<QQuickBehavior*>(item->findChild<QQuickBehavior*>("xBehavior")); + QCOMPARE(xBehavior->property("targetProperty").value<QQmlProperty>(), QQmlProperty(item.data(), "x")); + QCOMPARE(item->property("xBehaviorObject").value<QObject*>(), item.data()); + QCOMPARE(item->property("xBehaviorName").toString(), "x"); + + QQuickBehavior* emptyBehavior = + qobject_cast<QQuickBehavior*>(item->findChild<QQuickBehavior*>("emptyBehavior")); + QCOMPARE(emptyBehavior->property("targetProperty").value<QQmlProperty>().isValid(), false); + QCOMPARE(item->property("emptyBehaviorObject").value<QObject*>(), nullptr); + QCOMPARE(item->property("emptyBehaviorName").toString(), ""); +} + QTEST_MAIN(tst_qquickbehaviors) |