diff --git a/src/corelib/kernel/qproperty.h b/src/corelib/kernel/qproperty.h index 02d1c1eb94..1f45caee49 100644 --- a/src/corelib/kernel/qproperty.h +++ b/src/corelib/kernel/qproperty.h @@ -316,13 +316,9 @@ public: explicit QProperty(parameter_type initialValue) : QPropertyData(initialValue) {} explicit QProperty(rvalue_ref initialValue) : QPropertyData(std::move(initialValue)) {} QProperty(QProperty &&other) : QPropertyData(std::move(other.val)), d(std::move(other.d), this) { notify(); } - QProperty &operator=(QProperty &&other) { this->val = std::move(other.val); d.moveAssign(std::move(other.d), this); notify(); return *this; } - QProperty(const QPropertyBinding &binding) + explicit QProperty(const QPropertyBinding &binding) : QProperty() - { operator=(binding); } - QProperty(QPropertyBinding &&binding) - : QProperty() - { operator=(std::move(binding)); } + { setBinding(binding); } #ifndef Q_CLANG_QDOC template explicit QProperty(Functor &&f, const QPropertyBindingSourceLocation &location = QT_PROPERTY_DEFAULT_BINDING_LOCATION, @@ -333,6 +329,13 @@ public: template explicit QProperty(Functor &&f); #endif + QProperty &operator=(QProperty &&other) + { + this->val = std::move(other.val); + d.moveAssign(std::move(other.d), this); + notify(); + return *this; + } ~QProperty() = default; parameter_type value() const @@ -395,12 +398,6 @@ public: return *this; } - QProperty &operator=(const QPropertyBinding &newBinding) - { - setBinding(newBinding); - return *this; - } - QPropertyBinding setBinding(const QPropertyBinding &newBinding) { QPropertyBinding oldBinding(d.setBinding(newBinding, this)); @@ -532,18 +529,6 @@ public: return *this; } - QPropertyAlias &operator=(const QPropertyBinding &newBinding) - { - setBinding(newBinding); - return *this; - } - - QPropertyAlias &operator=(QPropertyBinding &&newBinding) - { - setBinding(std::move(newBinding)); - return *this; - } - QPropertyBinding setBinding(const QPropertyBinding &newBinding) { if (auto *p = aliasedProperty()) diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp index 97c4f5b752..4f250992c9 100644 --- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp +++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp @@ -78,7 +78,7 @@ void tst_QProperty::functorBinding() { QProperty property([]() { return 42; }); QCOMPARE(property.value(), int(42)); - property = Qt::makePropertyBinding([]() { return 100; }); + property.setBinding([]() { return 100; }); QCOMPARE(property.value(), int(100)); property.setBinding([]() { return 50; }); QCOMPARE(property.value(), int(50)); @@ -88,7 +88,7 @@ void tst_QProperty::basicDependencies() { QProperty right(100); - QProperty left = Qt::makePropertyBinding(right); + QProperty left(Qt::makePropertyBinding(right)); QCOMPARE(left.value(), int(100)); @@ -103,7 +103,7 @@ void tst_QProperty::multipleDependencies() QProperty secondDependency(2); QProperty sum; - sum = Qt::makePropertyBinding([&]() { return firstDependency + secondDependency; }); + sum.setBinding([&]() { return firstDependency + secondDependency; }); QCOMPARE(QPropertyBindingDataPointer::get(firstDependency).observerCount(), 0); QCOMPARE(QPropertyBindingDataPointer::get(secondDependency).observerCount(), 0); @@ -139,8 +139,7 @@ void tst_QProperty::bindingWithDeletedDependency() QProperty bindingReturnsDynamicProperty(false); - QProperty propertySelector; - propertySelector = Qt::makePropertyBinding([&]() { + QProperty propertySelector([&]() { if (bindingReturnsDynamicProperty && !dynamicProperty.isNull()) return dynamicProperty->value(); else @@ -167,10 +166,10 @@ void tst_QProperty::recursiveDependency() QProperty first(1); QProperty second; - second = Qt::makePropertyBinding(first); + second.setBinding(Qt::makePropertyBinding(first)); QProperty third; - third = Qt::makePropertyBinding(second); + third.setBinding(Qt::makePropertyBinding(second)); QCOMPARE(third.value(), int(1)); @@ -184,13 +183,13 @@ void tst_QProperty::bindingAfterUse() QProperty propWithBindingLater(1); QProperty propThatUsesFirstProp; - propThatUsesFirstProp = Qt::makePropertyBinding(propWithBindingLater); + propThatUsesFirstProp.setBinding(Qt::makePropertyBinding(propWithBindingLater)); QCOMPARE(propThatUsesFirstProp.value(), int(1)); QCOMPARE(QPropertyBindingDataPointer::get(propWithBindingLater).observerCount(), 1); QProperty injectedValue(42); - propWithBindingLater = Qt::makePropertyBinding(injectedValue); + propWithBindingLater.setBinding(Qt::makePropertyBinding(injectedValue)); QCOMPARE(propThatUsesFirstProp.value(), int(42)); QCOMPARE(QPropertyBindingDataPointer::get(propWithBindingLater).observerCount(), 1); @@ -201,16 +200,16 @@ void tst_QProperty::switchBinding() QProperty first(1); QProperty propWithChangingBinding; - propWithChangingBinding = Qt::makePropertyBinding(first); + propWithChangingBinding.setBinding(Qt::makePropertyBinding(first)); QCOMPARE(propWithChangingBinding.value(), 1); QProperty output; - output = Qt::makePropertyBinding(propWithChangingBinding); + output.setBinding(Qt::makePropertyBinding(propWithChangingBinding)); QCOMPARE(output.value(), 1); QProperty second(2); - propWithChangingBinding = Qt::makePropertyBinding(second); + propWithChangingBinding.setBinding(Qt::makePropertyBinding(second)); QCOMPARE(output.value(), 2); } @@ -219,8 +218,7 @@ void tst_QProperty::avoidDependencyAllocationAfterFirstEval() QProperty firstDependency(1); QProperty secondDependency(10); - QProperty propWithBinding; - propWithBinding = Qt::makePropertyBinding([&]() { return firstDependency + secondDependency; }); + QProperty propWithBinding([&]() { return firstDependency + secondDependency; }); QCOMPARE(propWithBinding.value(), int(11)); @@ -242,8 +240,7 @@ void tst_QProperty::propertyArrays() expectedSum += i; } - QProperty sum; - sum = Qt::makePropertyBinding([&]() { + QProperty sum([&]() { return std::accumulate(properties.begin(), properties.end(), 0); }); @@ -258,8 +255,7 @@ void tst_QProperty::boolProperty() { QProperty first(true); QProperty second(false); - QProperty all; - all = Qt::makePropertyBinding([&]() { return first && second; }); + QProperty all([&]() { return first && second; }); QCOMPARE(all.value(), false); @@ -274,7 +270,7 @@ void tst_QProperty::takeBinding() QVERIFY(existingBinding.isNull()); QProperty first(100); - QProperty second = Qt::makePropertyBinding(first); + QProperty second(Qt::makePropertyBinding(first)); QCOMPARE(second.value(), int(100)); @@ -287,7 +283,7 @@ void tst_QProperty::takeBinding() second = 25; QCOMPARE(second.value(), int(25)); - second = existingBinding; + second.setBinding(existingBinding); QCOMPARE(second.value(), int(10)); QVERIFY(!existingBinding.isNull()); } @@ -295,7 +291,7 @@ void tst_QProperty::takeBinding() void tst_QProperty::replaceBinding() { QProperty first(100); - QProperty second = Qt::makePropertyBinding(first); + QProperty second(Qt::makePropertyBinding(first)); QCOMPARE(second.value(), 100); @@ -303,7 +299,7 @@ void tst_QProperty::replaceBinding() auto oldBinding = second.setBinding(constantBinding); QCOMPARE(second.value(), 42); - second = oldBinding; + second.setBinding(oldBinding); QCOMPARE(second.value(), 100); } @@ -312,8 +308,8 @@ void tst_QProperty::swap() QProperty firstDependency(1); QProperty secondDependency(2); - QProperty first = Qt::makePropertyBinding(firstDependency); - QProperty second = Qt::makePropertyBinding(secondDependency); + QProperty first(Qt::makePropertyBinding(firstDependency)); + QProperty second(Qt::makePropertyBinding(secondDependency)); QCOMPARE(first.value(), 1); QCOMPARE(second.value(), 2); @@ -337,20 +333,20 @@ void tst_QProperty::moveNotifies() QProperty first(1); QProperty second(2); - QProperty propertyInTheMiddle = Qt::makePropertyBinding(first); + QProperty propertyInTheMiddle(Qt::makePropertyBinding(first)); - QProperty finalProp1 = Qt::makePropertyBinding(propertyInTheMiddle); - QProperty finalProp2 = Qt::makePropertyBinding(propertyInTheMiddle); + QProperty finalProp1(Qt::makePropertyBinding(propertyInTheMiddle)); + QProperty finalProp2(Qt::makePropertyBinding(propertyInTheMiddle)); QCOMPARE(finalProp1.value(), 1); QCOMPARE(finalProp2.value(), 1); QCOMPARE(QPropertyBindingDataPointer::get(propertyInTheMiddle).observerCount(), 2); - QProperty other = Qt::makePropertyBinding(second); + QProperty other(Qt::makePropertyBinding(second)); QCOMPARE(other.value(), 2); - QProperty otherDep = Qt::makePropertyBinding(other); + QProperty otherDep(Qt::makePropertyBinding(other)); QCOMPARE(otherDep.value(), 2); QCOMPARE(QPropertyBindingDataPointer::get(other).observerCount(), 1); @@ -366,7 +362,7 @@ void tst_QProperty::moveCtor() { QProperty first(1); - QProperty intermediate = Qt::makePropertyBinding(first); + QProperty intermediate(Qt::makePropertyBinding(first)); QCOMPARE(intermediate.value(), 1); QCOMPARE(QPropertyBindingDataPointer::get(first).observerCount(), 1); @@ -443,7 +439,7 @@ void tst_QProperty::changeHandlerThroughBindings() { QProperty trigger(false); QProperty blockTrigger(false); - QProperty condition = Qt::makePropertyBinding([&]() { + QProperty condition([&]() { bool triggerValue = trigger; bool blockTriggerValue = blockTrigger; return triggerValue && !blockTriggerValue; @@ -479,7 +475,7 @@ void tst_QProperty::dontTriggerDependenciesIfUnchangedValue() QProperty property(42); bool triggered = false; - QProperty observer = Qt::makePropertyBinding([&]() { triggered = true; return property.value(); }); + QProperty observer([&]() { triggered = true; return property.value(); }); QCOMPARE(observer.value(), 42); QVERIFY(triggered); @@ -502,7 +498,7 @@ void tst_QProperty::bindingSourceLocation() void tst_QProperty::bindingError() { - QProperty prop = Qt::makePropertyBinding([]() -> int { + QProperty prop([]() -> int { QPropertyBindingError error(QPropertyBindingError::UnknownError, QLatin1String("my error")); QPropertyBindingPrivate::currentlyEvaluatingBinding()->setError(std::move(error)); return 0; @@ -515,16 +511,16 @@ void tst_QProperty::bindingLoop() { QScopedPointer> firstProp; - QProperty secondProp = Qt::makePropertyBinding([&]() -> int { + QProperty secondProp([&]() -> int { return firstProp ? firstProp->value() : 0; }); - QProperty thirdProp = Qt::makePropertyBinding([&]() -> int { + QProperty thirdProp([&]() -> int { return secondProp.value(); }); firstProp.reset(new QProperty()); - *firstProp = Qt::makePropertyBinding([&]() -> int { + firstProp->setBinding([&]() -> int { return secondProp.value(); }); @@ -558,7 +554,7 @@ void tst_QProperty::changePropertyFromWithinChangeHandler() void tst_QProperty::changePropertyFromWithinChangeHandlerThroughDependency() { QProperty sourceProperty(100); - QProperty property = Qt::makePropertyBinding(sourceProperty); + QProperty property(Qt::makePropertyBinding(sourceProperty)); bool resetPropertyOnChange = false; int changeHandlerCallCount = 0; @@ -599,7 +595,7 @@ void tst_QProperty::settingPropertyValueDoesRemoveBinding() { QProperty source(42); - QProperty property = Qt::makePropertyBinding(source); + QProperty property(Qt::makePropertyBinding(source)); QCOMPARE(property.value(), 42); QVERIFY(!property.binding().isNull()); @@ -825,7 +821,7 @@ void tst_QProperty::typeNoOperatorEqual() Uncomparable u2 = { 27 }; QProperty p1; - QProperty p2 = Qt::makePropertyBinding(p1); + QProperty p2(Qt::makePropertyBinding(p1)); QCOMPARE(p1.value().data, p2.value().data); p1.setValue(u1); @@ -835,7 +831,7 @@ void tst_QProperty::typeNoOperatorEqual() QCOMPARE(p1.value().data, u1.data); QCOMPARE(p2.value().data, u2.data); - QProperty p3 = Qt::makePropertyBinding(p1); + QProperty p3(Qt::makePropertyBinding(p1)); p1.setValue(u1); QCOMPARE(p1.value().data, p3.value().data);