diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2020-04-29 12:41:36 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-05-28 21:08:51 +0000 |
commit | 36f69229253480116de72a7ef46c3bdde1e805e5 (patch) | |
tree | ea94df7ec60092acabcf749cab64d009fd3a5fcc /src/corelib/kernel/qpropertyprivate.h | |
parent | 66d6943478c3ae76f996c2cd2fdf04fee4fcb767 (diff) |
Implement support for QProperty<T> with a static observer
A common pattern in Qt Quick will be QProperty members that are
connected to a callback that needs to perform something when the value
changes, for example emitting a compatibility signal or marking scene
graph node data dirty.
To make such a pattern more efficient, a new QNotifiedProperty type is
introduced that offers the same API as QProperty<T>, with two changes:
(1) The template instantiation not only takes the property type as
parameter but also a callback pointer-to-member.
(2) Since that member itself cannot be called without an instance
and to avoid storing an instance pointer permanently, the API for
setBinding and setValue are adjusted to also take the instance
pointer. For the former it gets stored in the binding, for the
latter it is used to invoke the callback after setting the new
value.
Change-Id: I85cc1d1d1c0472164c4ae87808cfdc0d0b1475e1
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/corelib/kernel/qpropertyprivate.h')
-rw-r--r-- | src/corelib/kernel/qpropertyprivate.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/corelib/kernel/qpropertyprivate.h b/src/corelib/kernel/qpropertyprivate.h index 4b0b09d9db..7a2c6a5b77 100644 --- a/src/corelib/kernel/qpropertyprivate.h +++ b/src/corelib/kernel/qpropertyprivate.h @@ -82,7 +82,9 @@ public: bool hasBinding() const { return d_ptr & BindingBit; } - QUntypedPropertyBinding setBinding(const QUntypedPropertyBinding &newBinding, void *propertyDataPtr); + QUntypedPropertyBinding setBinding(const QUntypedPropertyBinding &newBinding, + void *propertyDataPtr, void *staticObserver = nullptr, + void (*staticObserverCallback)(void*) = nullptr); QPropertyBindingPrivate *binding(); void evaluateIfDirty(); |