diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-03-09 08:41:55 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-05-12 14:07:36 +0200 |
commit | 45db3fae3ab44428c09800997230e6ad1865a05c (patch) | |
tree | a813b54ac5d5b8a720fdaac97c2d85960724320c /tests | |
parent | 13b78840439f61baf2011077985dbb972a3fa91c (diff) |
QQmlProperty: Implement DontRemoveBinding support for QProperty
The animation system currently relies on being able to write to
properties through the meatobject system without breaking their
bindings. This patch ensures that the DontRemoveBinding flag is honoured
for QProperty based bindings, too.
It is implemented by setting the private stick flag on the binding
before doing the write and then removing it again after the write is
done. This roundabout approach is necessary as the BindableInterface
does not expose the setValueBypassingBindings functionality, and simply
writing to the propertyDataPtr would prove disastrous in the case of
QObjectCompatProperty.
Fixes: QTBUG-91689
Change-Id: Ife1afb9c94190f1c4e9658a7193aba6dbdaa281f
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp index 63029f16dd..a1eae50048 100644 --- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp +++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp @@ -197,6 +197,8 @@ private slots: void underscorePropertyChangeHandler(); void signalExpressionWithoutObject(); + + void dontRemoveQPropertyBinding(); private: QQmlEngine engine; }; @@ -2273,6 +2275,31 @@ void tst_qqmlproperty::signalExpressionWithoutObject() QVERIFY(!expr); } +void tst_qqmlproperty::dontRemoveQPropertyBinding() +{ + QObject object; + QQmlProperty objectName(&object, "objectName"); + QVERIFY(objectName.isBindable()); + QProperty<QString> name("hello"); + object.bindableObjectName().setBinding(Qt::makePropertyBinding(name)); + QVERIFY(object.bindableObjectName().hasBinding()); + + // A write with DontRemoveBinding preserves the binding + QQmlPropertyPrivate::write(objectName, u"goodbye"_qs, QQmlPropertyData::DontRemoveBinding); + QVERIFY(object.bindableObjectName().hasBinding()); + // but changes the value + QCOMPARE(object.objectName(), u"goodbye"_qs); + // subsequent binding evaluations change the value again + name = u"hello, again"_qs; + QCOMPARE(object.objectName(), name.value()); + + // The binding is only preserved by the write which had DontRemoveBinding set + // any further write will remove the binding + QQmlPropertyPrivate::write(objectName, u"goodbye"_qs, QQmlPropertyData::WriteFlags{}); + QCOMPARE(object.objectName(), u"goodbye"_qs); + QVERIFY(!object.bindableObjectName().hasBinding()); +} + QTEST_MAIN(tst_qqmlproperty) #include "tst_qqmlproperty.moc" |