diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-12-15 11:09:16 +0100 |
---|---|---|
committer | Andreas Buhr <andreas.buhr@qt.io> | 2021-01-11 15:57:26 +0100 |
commit | 240505457bb1e8280682c7274493a7a6f61a1045 (patch) | |
tree | a0ea1d9f040d6ccc035620a0c76d069461890ada /tests | |
parent | 9f894788dda8407c6221aaa1491cd54a5a2b4cb7 (diff) |
QBindable: Improve read-only support
If we create a QBindable from a const property, we should obtain a
read-only interface. Besides implementing this feature, this patch adds
a isReadOnly method to Q(Untyped)Bindable which can be used to check
whether one can modify the property via the bindable interface.
Task-number: QTBUG-89505
Task-number: QTBUG-89469
Change-Id: Ic36949a5b84c5119e0060ed0a1cf4ac94a66f341
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp index 4559587afd..7de6458406 100644 --- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp +++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp @@ -1048,6 +1048,7 @@ public: } QBindable<int> bindableFoo() { return QBindable<int>(&fooData); } + const QBindable<int> bindableFoo() const { return QBindable<int>(&fooData); } QBindable<int> bindableBar() { return QBindable<int>(&barData); } QBindable<int> bindableRead() { return QBindable<int>(&readData); } QBindable<int> bindableComputed() { return QBindable<int>(&computedData); } @@ -1068,7 +1069,14 @@ public: void tst_QProperty::testNewStuff() { + MyQObject testReadOnly; + testReadOnly.bindableFoo().setBinding([](){return 42;}); + auto bindable = const_cast<const MyQObject&>(testReadOnly).bindableFoo(); + QVERIFY(bindable.hasBinding()); + QVERIFY(bindable.isReadOnly()); + MyQObject object; + QVERIFY(!object.bindableFoo().isReadOnly()); QObject::connect(&object, &MyQObject::fooChanged, &object, &MyQObject::fooHasChanged); QObject::connect(&object, &MyQObject::barChanged, &object, &MyQObject::barHasChanged); |