summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2021-02-03 10:16:18 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2021-04-16 16:49:29 +0200
commitcf42a0fe5e525efa9a399694cc6882c6e811c286 (patch)
tree5c7489ade522716e67fddba7772beab6ee240488 /tests/auto
parentd72067c93833e9787a45aeddee800faab0d2d40a (diff)
Remove lazy binding evaluation
Too much of the existing code in Qt requires eager evaluation without large scale modifications. Combined with the fact that supporting both eager and lazy evaluation has a high maintenance burden, keeping lazy evaluation, at least in its current state, is not worth it. This does not diminish other benefits of the new property system, which include - a C++ API to setup and modify bindings and - faster execution compared to QML's existing bindings and the ability to use them without having a QML engine. We do no longer benefit from doing less work thanks to laziness. A later commit will introduce grouping support to recapture some of this benefit. [ChangeLog][Import Behavior Change][QProperty] QProperty uses always eager evaluation now when a dependency in a binding changes. Change-Id: I34694fd5c7bcb1d31a0052d2e3da8b68d016671b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Andreas Buhr <andreas.buhr@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp98
1 files changed, 11 insertions, 87 deletions
diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
index 848226713c..12fd124b18 100644
--- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
+++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
@@ -95,7 +95,6 @@ private slots:
void noFakeDependencies();
void bindablePropertyWithInitialization();
- void markDirty();
};
void tst_QProperty::functorBinding()
@@ -129,8 +128,8 @@ void tst_QProperty::multipleDependencies()
QProperty<int> sum;
sum.setBinding([&]() { return firstDependency + secondDependency; });
- QCOMPARE(QPropertyBindingDataPointer::get(firstDependency).observerCount(), 0);
- QCOMPARE(QPropertyBindingDataPointer::get(secondDependency).observerCount(), 0);
+ QCOMPARE(QPropertyBindingDataPointer::get(firstDependency).observerCount(), 1);
+ QCOMPARE(QPropertyBindingDataPointer::get(secondDependency).observerCount(), 1);
QCOMPARE(sum.value(), int(3));
QCOMPARE(QPropertyBindingDataPointer::get(firstDependency).observerCount(), 1);
@@ -484,23 +483,22 @@ class BindingLoopTester : public QObject
void tst_QProperty::bindingLoop()
{
- QScopedPointer<QProperty<int>> firstProp;
+ QProperty<int> firstProp;
QProperty<int> secondProp([&]() -> int {
- return firstProp ? firstProp->value() : 0;
+ return firstProp.value();
});
QProperty<int> thirdProp([&]() -> int {
return secondProp.value();
});
- firstProp.reset(new QProperty<int>());
- firstProp->setBinding([&]() -> int {
- return secondProp.value();
+ firstProp.setBinding([&]() -> int {
+ return secondProp.value() + thirdProp.value();
});
- QCOMPARE(thirdProp.value(), 0);
- QCOMPARE(secondProp.binding().error().type(), QPropertyBindingError::BindingLoop);
+ thirdProp.setValue(10);
+ QCOMPARE(firstProp.binding().error().type(), QPropertyBindingError::BindingLoop);
{
@@ -1200,7 +1198,9 @@ void tst_QProperty::qobjectObservers()
MyQObject object;
int onValueChangedCalled = 0;
{
- auto handler = object.bindableFoo().onValueChanged([&onValueChangedCalled]() { ++onValueChangedCalled;});
+ auto handler = object.bindableFoo().onValueChanged([&onValueChangedCalled]() {
+ ++onValueChangedCalled;
+ });
QCOMPARE(onValueChangedCalled, 0);
object.setFoo(10);
@@ -1606,82 +1606,6 @@ void tst_QProperty::bindablePropertyWithInitialization()
QCOMPARE(tester.prop3().anotherValue, 20);
}
-class MarkDirtyTester : public QObject
-{
- Q_OBJECT
-public:
- Q_PROPERTY(int value1 READ value1 WRITE setValue1 BINDABLE bindableValue1)
- Q_PROPERTY(int value2 READ value2 WRITE setValue1 BINDABLE bindableValue2)
- Q_PROPERTY(int computed READ computed BINDABLE bindableComputed)
-
- inline static int staticValue = 0;
-
- int value1() const {return m_value1;}
- void setValue1(int val) {m_value1 = val;}
- QBindable<int> bindableValue1() {return { &m_value1 };}
-
- int value2() const {return m_value2;}
- void setValue2(int val) { m_value2.setValue(val); }
- QBindable<int> bindableValue2() {return { &m_value2 };}
-
- int computed() const { return staticValue + m_value1; }
- QBindable<int> bindableComputed() {return {&m_computed};}
-
- void incrementStaticValue() {
- ++staticValue;
- m_computed.markDirty();
- }
-
- void markValue1Dirty() {
- m_value1.markDirty();
- }
-
- void markValue2Dirty() {
- m_value2.markDirty();
- }
-private:
- Q_OBJECT_BINDABLE_PROPERTY(MarkDirtyTester, int, m_value1, nullptr)
- Q_OBJECT_COMPAT_PROPERTY(MarkDirtyTester, int, m_value2, &MarkDirtyTester::setValue2)
- Q_OBJECT_COMPUTED_PROPERTY(MarkDirtyTester, int, m_computed, &MarkDirtyTester::computed)
-};
-
-void tst_QProperty::markDirty()
-{
- {
- QProperty<int> testProperty;
- int changeCounter = 0;
- auto handler = testProperty.onValueChanged([&](){++changeCounter;});
- testProperty.markDirty();
- QCOMPARE(changeCounter, 1);
- }
- {
- MarkDirtyTester dirtyTester;
- int computedChangeCounter = 0;
- int value1ChangeCounter = 0;
- auto handler = dirtyTester.bindableComputed().onValueChanged([&](){
- computedChangeCounter++;
- });
- auto handler2 = dirtyTester.bindableValue1().onValueChanged([&](){
- value1ChangeCounter++;
- });
- dirtyTester.incrementStaticValue();
- QCOMPARE(computedChangeCounter, 1);
- QCOMPARE(dirtyTester.computed(), 1);
- dirtyTester.markValue1Dirty();
- QCOMPARE(value1ChangeCounter, 1);
- QCOMPARE(computedChangeCounter, 1);
- }
- {
- MarkDirtyTester dirtyTester;
- int changeCounter = 0;
- auto handler = dirtyTester.bindableValue2().onValueChanged([&](){
- changeCounter++;
- });
- dirtyTester.markValue2Dirty();
- QCOMPARE(changeCounter, 1);
- }
-}
-
QTEST_MAIN(tst_QProperty);
#include "tst_qproperty.moc"