summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qproperty.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-08-20 11:01:18 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2020-12-18 13:10:46 +0100
commit10bf3ae90cadbec44c6007190bf16e3c9c7652d8 (patch)
treec23e1aa6ccde0d1878759f7ad955e688b6ae77b9 /src/corelib/kernel/qproperty.cpp
parentabd2cbc12a28f2e962827ac9608d9e0bef6f0489 (diff)
QProperty add markdirty
This adds functionality for marking properties (QProperty and related classes) manually as dirty. This facilliates the integration of bindable properties with non-binable properties and makes it possible for bindable properties to change due to external events. Fixes: QTBUG-89167 Change-Id: I256cf154d914149dacb6cadaba92b13c88c9d027 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/corelib/kernel/qproperty.cpp')
-rw-r--r--src/corelib/kernel/qproperty.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp
index 20efbaa1aa..5dd6507e26 100644
--- a/src/corelib/kernel/qproperty.cpp
+++ b/src/corelib/kernel/qproperty.cpp
@@ -381,6 +381,13 @@ void QPropertyBindingData::notifyObservers(QUntypedPropertyData *propertyDataPtr
observer.notify(d.bindingPtr(), propertyDataPtr);
}
+void QPropertyBindingData::markDirty()
+{
+ QPropertyBindingDataPointer d{this};
+ if (auto *binding = d.bindingPtr())
+ binding->setDirty(true);
+}
+
int QPropertyBindingDataPointer::observerCount() const
{
int count = 0;
@@ -837,6 +844,31 @@ QString QPropertyBindingError::description() const
*/
/*!
+ \fn template <typename T> void QProperty<T>::markDirty()
+
+ Programatically sets the property dirty. Any binding which depends on it will
+ be notified.
+ This can be useful for properties which do not only depend on bindable properties,
+ but also on non-bindable properties or some other state.
+
+ For example, assume we have a \c Circle class, with a non-bindable \c radius property
+ and a corresponding \c radiusChanged signal. We now want to create a property for a
+ cylinders volume, based on a height \c QProperty and an instance of Circle. To ensure
+ that the volume changes, we can call setDirty in a slot connected to radiusChanged.
+ \code
+ Circle circle;
+ QProperty<double> height;
+
+ QProperty<double> volume;
+ volume.setBinding([&]() {return height * std::pi_v<double> * circle.radius() * circle.radius()};
+ QOBject::connect(&circle, &Circle::radiusChanged, [&](){volume.markDirty();});
+ \endcode
+
+ \note Binding to a QObjectBindableProperty's signal does not make sense in general. Bindings
+ across bindable properties get marked dirty automatically.
+*/
+
+/*!
\fn template <typename T> QPropertyBinding<T> QProperty<T>::setBinding(const QPropertyBinding<T> &newBinding)
Associates the value of this property with the provided \a newBinding
@@ -1036,6 +1068,17 @@ QString QPropertyBindingError::description() const
*/
/*!
+ \fn template <typename Class, typename T, auto offset, auto Callback> void QObjectBindableProperty<Class, T, offset, Callback>::markDirty()
+
+ Programatically sets the property dirty. Any binding which depend on it will
+ be notified.
+ This can be useful for properties which do not only depend on bindable properties,
+ but also on non-bindable properties or some other state.
+
+ \sa QProperty<T>::markDirty
+*/
+
+/*!
\fn template <typename Class, typename T, auto offset, auto Callback> QPropertyBinding<T> QObjectBindableProperty<Class, T, offset, Callback>::setBinding(const QPropertyBinding<T> &newBinding)
Associates the value of this property with the provided \a newBinding