diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-12-15 08:31:22 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-03-15 11:42:15 +0100 |
commit | d64e7c9c6cd172e426b9bb2c5e45fda5e6a5bfb2 (patch) | |
tree | b26471692f35d02351e33adcb31cd80e8cde3926 /tests/auto/qml/qqmlecmascript/data | |
parent | 3b39f700fb2b4eeab60ad67a020f469e39c48eab (diff) |
QQmlPropertyBinding: handle reset
Bindings are allowed to toggle between a defined state, and undefined
which calls the property's reset function. Calls to the reset function
must not remove the binding, even when they write to the property.
To support this, we put the binding in a special undefined state, in
which it is still active (and installed on the property), but does not
actually provide its evaluated value to the property. Then, when the
binding later becomes defined again, the binding leaves its undefined
state and works normally again.
Notes:
- Calling the reset function during binding evaluation could have all
kinds of unwelcome side-effects. We therefore have to suspend binding
evaluation before the reset call (and restore that state afterwards).
- QObjectCompatProperty expects that we write the current value into the
propertyDataPtr. If we do not do this, it will overwrite the current
value with the default constructed value of its property. Arguably, we
should change the API so that we communicate that nothing has changed;
but for now, we have to live with that limitation and read the
current value and write it back again.
- We currently do not handle the case correctly where a non-resettable
property implemented via QObjectCompatProperty gets assigned undefined
in a binding. Such a binding is likely unintentional (as the undefined
assignment only creates a warning), and thus less of a priority.
Nevertheless, a test marked with QEXPECT_FAIL is added for it.
Fixes: QTBUG-91001
Change-Id: I7ecaa6c8dc1a1f1b33e67b1af65f552c4ca6ffb1
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/data')
5 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/qpropertyBindingUndefined.qml b/tests/auto/qml/qqmlecmascript/data/qpropertyBindingUndefined.qml new file mode 100644 index 0000000000..757a544b58 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qpropertyBindingUndefined.qml @@ -0,0 +1,6 @@ +import Qt.test 1.0 +ClassWithQProperty { + property int anotherValue: 1 + property bool toggle: false + value: toggle ? undefined : anotherValue +} diff --git a/tests/auto/qml/qqmlecmascript/data/qpropertyBindingUndefined2.qml b/tests/auto/qml/qqmlecmascript/data/qpropertyBindingUndefined2.qml new file mode 100644 index 0000000000..5e08a20987 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qpropertyBindingUndefined2.qml @@ -0,0 +1,6 @@ +import Qt.test 1.0 +ClassWithQObjectProperty { + property int anotherValue: 1 + property bool toggle: false + value: toggle ? undefined : anotherValue +} diff --git a/tests/auto/qml/qqmlecmascript/data/qpropertyBindingUndefinedWithoutReset1.qml b/tests/auto/qml/qqmlecmascript/data/qpropertyBindingUndefinedWithoutReset1.qml new file mode 100644 index 0000000000..c0b5994887 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qpropertyBindingUndefinedWithoutReset1.qml @@ -0,0 +1,6 @@ +import Qt.test 1.0 +ClassWithQProperty { + property int anotherValue: 1 + property bool toggle: false + value2: toggle ? undefined : anotherValue +} diff --git a/tests/auto/qml/qqmlecmascript/data/qpropertyBindingUndefinedWithoutReset2.qml b/tests/auto/qml/qqmlecmascript/data/qpropertyBindingUndefinedWithoutReset2.qml new file mode 100644 index 0000000000..9a74a620d8 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qpropertyBindingUndefinedWithoutReset2.qml @@ -0,0 +1,6 @@ +import Qt.test 1.0 +ClassWithQObjectProperty { + property int anotherValue: 1 + property bool toggle: false + value2: toggle ? undefined : anotherValue +} diff --git a/tests/auto/qml/qqmlecmascript/data/qpropertyBindingUndefinedWithoutReset3.qml b/tests/auto/qml/qqmlecmascript/data/qpropertyBindingUndefinedWithoutReset3.qml new file mode 100644 index 0000000000..61a4008fba --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qpropertyBindingUndefinedWithoutReset3.qml @@ -0,0 +1,6 @@ +import Qt.test 1.0 +ClassWithQCompatProperty { + property int anotherValue: 1 + property bool toggle: false + value2: toggle ? undefined : anotherValue +} |