diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-01-22 11:06:52 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-01-27 15:01:56 +0100 |
commit | 0f4d512dc46cb9d24b58083efdc1fa4631bdbec4 (patch) | |
tree | ca82bee7dc0721e208ad73a2fb6ca2db849bc31e /tests/auto/corelib | |
parent | f07c6f52ac4e336bd49c5d3cdaf89803460ba3bf (diff) |
Q(Untyped)Bindable: add takeBinding method
We missed takeBinding as a supported operation on Q(Untyped)Bindable.
To avoid adding version checks to code dealing with QBindableInterface,
we simply synthesize takeBinding as a combination of binding to retrieve
the binding and setBinding with a default-constructed
QUntypedPropertyBinding.
Change-Id: I43803a0dfe210353d0235f0373d2257f75ffe534
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r-- | tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp index 3b656dae25..31ed610b09 100644 --- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp +++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp @@ -78,6 +78,7 @@ private slots: void notifiedProperty(); void typeNoOperatorEqual(); void bindingValueReplacement(); + void quntypedBindableApi(); void testNewStuff(); void qobjectObservers(); @@ -1008,6 +1009,23 @@ void tst_QProperty::bindingValueReplacement() // QCOMPARE(test.iconText.value(), 42); } +void tst_QProperty::quntypedBindableApi() +{ + QProperty<int> iprop; + QUntypedBindable bindable(&iprop); + QVERIFY(!bindable.hasBinding()); + QVERIFY(bindable.binding().isNull()); + bindable.setBinding(Qt::makePropertyBinding([]() -> int {return 42;})); + QVERIFY(bindable.hasBinding()); + QVERIFY(!bindable.binding().isNull()); + QUntypedPropertyBinding binding = bindable.takeBinding(); + QVERIFY(!bindable.hasBinding()); + bindable.setBinding(binding); + QCOMPARE(iprop.value(), 42); + QUntypedBindable propLess; + QVERIFY(propLess.takeBinding().isNull()); +} + class MyQObject : public QObject { Q_OBJECT |