summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-08-29 14:02:36 +0200
committerLars Knoll <lars.knoll@qt.io>2020-09-02 22:44:29 +0200
commit927647cd032cd2e43bae3184b879586849ffee50 (patch)
treeedbd80d955448306e273cb136f21e5f514c5d86a /tests
parent91a24f6cd71f03b001dc6a0a8dba23efe744033d (diff)
Fix QPropertyAlias to work with all kinds of properties
So far QPropertyAlias was limited to working with QProperty<T>. Change the implementation, so it can be constructed from any property or even a QBindable<T>. Change-Id: I175cffe94a9ef332367d39faa976eb065b0e6ffe Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
index f5652eb599..9bc2ce26b6 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 qobjectObservers();
void compatBindings();
void metaProperty();
+ void aliasOnMetaProperty();
};
void tst_QProperty::functorBinding()
@@ -1210,6 +1211,42 @@ void tst_QProperty::metaProperty()
QCOMPARE(object.fooData.value(), 1);
}
+void tst_QProperty::aliasOnMetaProperty()
+{
+ MyQObject object;
+ QPropertyAlias<int> alias(object.bindableFoo());
+
+ QVERIFY(alias.isValid());
+ QCOMPARE(alias.value(), object.foo());
+ QVERIFY(!alias.hasBinding());
+
+ object.setFoo(42);
+ QCOMPARE(alias.value(), 42);
+
+ auto f = [&object]() -> int {
+ return object.barData;
+ };
+ object.bindableFoo().setBinding(f);
+ QVERIFY(alias.hasBinding());
+ QCOMPARE(alias.value(), object.bar());
+
+ object.setBar(111);
+ QCOMPARE(alias.value(), 111);
+
+ int changedCount = 0;
+ auto observer = alias.onValueChanged([&changedCount]() { ++changedCount; });
+ QCOMPARE(changedCount, 0);
+ object.setBar(666);
+ QCOMPARE(changedCount, 1);
+
+ alias.setBinding([&object]() { return object.read(); });
+ QCOMPARE(changedCount, 2);
+ QCOMPARE(alias.value(), 0);
+ object.readData = 100;
+ QCOMPARE(changedCount, 3);
+ QCOMPARE(alias.value(), 100);
+}
+
QTEST_MAIN(tst_QProperty);
#include "tst_qproperty.moc"