summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-08-18 12:18:27 +0200
committerLars Knoll <lars.knoll@qt.io>2020-09-02 22:44:29 +0200
commit1e1b88809261854dee47c9bc105cf71e75b75cb9 (patch)
treefe99be6a3049500a2fc50d752a51076a1d4f5a0f /src
parent3b3b190eef036ffefb5275e6f03e9f933d3609ff (diff)
Pass a pointer to the property data into the method evaluating a binding
Make it possible to evaluate the binding but write the result into a different memory location. This will help support compat properties, where the setter does a lot of additional work. Change-Id: Ib60220eb629e3dcb5c0d7004b693e92290dfabe5 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/kernel/qproperty.cpp17
-rw-r--r--src/corelib/kernel/qproperty.h4
-rw-r--r--src/corelib/kernel/qproperty_p.h2
-rw-r--r--src/corelib/kernel/qpropertyprivate.h5
4 files changed, 16 insertions, 12 deletions
diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp
index 52bf9f33e6..b39b4c1c33 100644
--- a/src/corelib/kernel/qproperty.cpp
+++ b/src/corelib/kernel/qproperty.cpp
@@ -88,7 +88,7 @@ void QPropertyBindingPrivate::markDirtyAndNotifyObservers()
staticObserverCallback(propertyDataPtr);
}
-bool QPropertyBindingPrivate::evaluateIfDirtyAndReturnTrueIfValueChanged()
+bool QPropertyBindingPrivate::evaluateIfDirtyAndReturnTrueIfValueChanged(const QUntypedPropertyData *data)
{
if (!dirty)
return false;
@@ -113,10 +113,13 @@ bool QPropertyBindingPrivate::evaluateIfDirtyAndReturnTrueIfValueChanged()
bool changed = false;
+ Q_ASSERT(propertyDataPtr == data);
+ QUntypedPropertyData *mutable_data = const_cast<QUntypedPropertyData *>(data);
+
if (hasBindingWrapper) {
changed = staticBindingWrapper(metaType, propertyDataPtr, evaluationFunction);
} else {
- changed = evaluationFunction(metaType, propertyDataPtr);
+ changed = evaluationFunction(metaType, mutable_data);
}
dirty = false;
@@ -300,13 +303,13 @@ QPropertyBindingPrivate *QPropertyBindingPrivate::currentlyEvaluatingBinding()
return currentBindingEvaluationState ? currentBindingEvaluationState->binding : nullptr;
}
-void QPropertyBindingData::evaluateIfDirty() const
+void QPropertyBindingData::evaluateIfDirty(const QUntypedPropertyData *property) const
{
QPropertyBindingDataPointer d{this};
QPropertyBindingPrivate *binding = d.bindingPtr();
if (!binding)
return;
- binding->evaluateIfDirtyAndReturnTrueIfValueChanged();
+ binding->evaluateIfDirtyAndReturnTrueIfValueChanged(property);
}
void QPropertyBindingData::removeBinding()
@@ -452,7 +455,7 @@ void QPropertyObserverPointer::notify(QPropertyBindingPrivate *triggeringBinding
if (!knownIfPropertyChanged && triggeringBinding) {
knownIfPropertyChanged = true;
- propertyChanged = triggeringBinding->evaluateIfDirtyAndReturnTrueIfValueChanged();
+ propertyChanged = triggeringBinding->evaluateIfDirtyAndReturnTrueIfValueChanged(propertyDataPtr);
}
if (!propertyChanged)
return;
@@ -1446,6 +1449,7 @@ struct QBindingStoragePrivate
QBindingStorage::QBindingStorage()
{
currentlyEvaluatingBinding = &currentBindingEvaluationState;
+ Q_ASSERT(currentlyEvaluatingBinding);
}
QBindingStorage::~QBindingStorage()
@@ -1455,6 +1459,7 @@ QBindingStorage::~QBindingStorage()
void QBindingStorage::maybeUpdateBindingAndRegister(const QUntypedPropertyData *data) const
{
+ Q_ASSERT(currentlyEvaluatingBinding);
QUntypedPropertyData *dd = const_cast<QUntypedPropertyData *>(data);
auto storage = *currentlyEvaluatingBinding ?
QBindingStoragePrivate(d).getAndCreate(dd) :
@@ -1462,7 +1467,7 @@ void QBindingStorage::maybeUpdateBindingAndRegister(const QUntypedPropertyData *
if (!storage)
return;
if (auto *binding = storage->binding())
- binding->evaluateIfDirtyAndReturnTrueIfValueChanged();
+ binding->evaluateIfDirtyAndReturnTrueIfValueChanged(const_cast<QUntypedPropertyData *>(data));
storage->registerWithCurrentlyEvaluatingBinding();
}
diff --git a/src/corelib/kernel/qproperty.h b/src/corelib/kernel/qproperty.h
index 14319f0382..c54d99f131 100644
--- a/src/corelib/kernel/qproperty.h
+++ b/src/corelib/kernel/qproperty.h
@@ -67,7 +67,7 @@ template <typename T>
class QPropertyData : public QUntypedPropertyData
{
protected:
- T val = T();
+ mutable T val = T();
private:
class DisableRValueRefs {};
protected:
@@ -341,7 +341,7 @@ public:
parameter_type value() const
{
if (d.hasBinding())
- d.evaluateIfDirty();
+ d.evaluateIfDirty(this);
d.registerWithCurrentlyEvaluatingBinding();
return this->val;
}
diff --git a/src/corelib/kernel/qproperty_p.h b/src/corelib/kernel/qproperty_p.h
index fbc9a072c3..6c53101129 100644
--- a/src/corelib/kernel/qproperty_p.h
+++ b/src/corelib/kernel/qproperty_p.h
@@ -230,7 +230,7 @@ public:
void unlinkAndDeref();
void markDirtyAndNotifyObservers();
- bool evaluateIfDirtyAndReturnTrueIfValueChanged();
+ bool evaluateIfDirtyAndReturnTrueIfValueChanged(const QUntypedPropertyData *data);
static QPropertyBindingPrivate *get(const QUntypedPropertyBinding &binding)
{ return binding.d.data(); }
diff --git a/src/corelib/kernel/qpropertyprivate.h b/src/corelib/kernel/qpropertyprivate.h
index 6f0e563a28..15e54e9ba8 100644
--- a/src/corelib/kernel/qpropertyprivate.h
+++ b/src/corelib/kernel/qpropertyprivate.h
@@ -87,10 +87,9 @@ class Q_CORE_EXPORT QPropertyBindingData
// notification later when the value changes.
mutable quintptr d_ptr = 0;
friend struct QT_PREPEND_NAMESPACE(QPropertyBindingDataPointer);
+ Q_DISABLE_COPY(QPropertyBindingData)
public:
QPropertyBindingData() = default;
- Q_DISABLE_COPY(QPropertyBindingData)
- QPropertyBindingData(QPropertyBindingData &&other) = delete;
QPropertyBindingData(QPropertyBindingData &&other, QUntypedPropertyData *propertyDataPtr);
QPropertyBindingData &operator=(QPropertyBindingData &&other) = delete;
~QPropertyBindingData();
@@ -105,7 +104,7 @@ public:
QPropertyBindingWrapper guardCallback = nullptr);
QPropertyBindingPrivate *binding() const;
- void evaluateIfDirty() const;
+ void evaluateIfDirty(const QUntypedPropertyData *property) const;
void removeBinding();
void registerWithCurrentlyEvaluatingBinding() const;