summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qpropertybinding.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2020-04-14 11:03:11 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2020-04-17 11:24:10 +0200
commitf395cedc5b7c5f0aa55387e906e4ad420f887533 (patch)
tree8e0941d3473a3c048dee2ff63e3088121df275ae /src/corelib/kernel/qpropertybinding.cpp
parent4857f0ebd7f4ea422f7a5dc721f0204390adddbb (diff)
Simplify signature of untyped property bindings
Instead of requiring the implementation to do the compare dance, let's do this in the library. This reduces the amount of duplicated code slightly and makes it easier to generate binding code from qml files. Change-Id: Ia3b16cf9769e74d076b669efe4119ab84af3cdf0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel/qpropertybinding.cpp')
-rw-r--r--src/corelib/kernel/qpropertybinding.cpp32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/corelib/kernel/qpropertybinding.cpp b/src/corelib/kernel/qpropertybinding.cpp
index 358977e63e..29b1a4a69a 100644
--- a/src/corelib/kernel/qpropertybinding.cpp
+++ b/src/corelib/kernel/qpropertybinding.cpp
@@ -41,6 +41,7 @@
#include "qproperty_p.h"
#include <QScopedValueRollback>
+#include <QVariant>
QT_BEGIN_NAMESPACE
@@ -80,25 +81,34 @@ bool QPropertyBindingPrivate::evaluateIfDirtyAndReturnTrueIfValueChanged()
BindingEvaluationState evaluationFrame(this);
+ QPropertyBindingError evalError;
QUntypedPropertyBinding::BindingEvaluationResult result;
bool changed = false;
if (metaType.id() == QMetaType::Bool) {
auto propertyPtr = reinterpret_cast<QPropertyBase *>(propertyDataPtr);
- bool temp = propertyPtr->extraBit();
- result = evaluationFunction(metaType, &temp);
- if (auto changedPtr = std::get_if<bool>(&result)) {
- changed = *changedPtr;
- if (changed)
- propertyPtr->setExtraBit(temp);
+ bool newValue = false;
+ evalError = evaluationFunction(metaType, &newValue);
+ if (evalError.type() == QPropertyBindingError::NoError) {
+ if (propertyPtr->extraBit() != newValue) {
+ propertyPtr->setExtraBit(newValue);
+ changed = true;
+ }
}
} else {
- result = evaluationFunction(metaType, propertyDataPtr);
- if (auto changedPtr = std::get_if<bool>(&result))
- changed = *changedPtr;
+ QVariant resultVariant(metaType.id(), nullptr);
+ evalError = evaluationFunction(metaType, resultVariant.data());
+ if (evalError.type() == QPropertyBindingError::NoError) {
+ int compareResult = 0;
+ if (!QMetaType::compare(propertyDataPtr, resultVariant.constData(), metaType.id(), &compareResult) || compareResult != 0) {
+ changed = true;
+ metaType.destruct(propertyDataPtr);
+ metaType.construct(propertyDataPtr, resultVariant.constData());
+ }
+ }
}
- if (auto errorPtr = std::get_if<QPropertyBindingError>(&result))
- error = std::move(*errorPtr);
+ if (evalError.type() != QPropertyBindingError::NoError)
+ error = evalError;
dirty = false;
return changed;