diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-01-22 11:06:52 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-01-27 15:01:56 +0100 |
commit | 0f4d512dc46cb9d24b58083efdc1fa4631bdbec4 (patch) | |
tree | ca82bee7dc0721e208ad73a2fb6ca2db849bc31e /src/corelib | |
parent | f07c6f52ac4e336bd49c5d3cdaf89803460ba3bf (diff) |
Q(Untyped)Bindable: add takeBinding method
We missed takeBinding as a supported operation on Q(Untyped)Bindable.
To avoid adding version checks to code dealing with QBindableInterface,
we simply synthesize takeBinding as a combination of binding to retrieve
the binding and setBinding with a default-constructed
QUntypedPropertyBinding.
Change-Id: I43803a0dfe210353d0235f0373d2257f75ffe534
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/kernel/qproperty.cpp | 21 | ||||
-rw-r--r-- | src/corelib/kernel/qproperty.h | 22 |
2 files changed, 42 insertions, 1 deletions
diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp index 342a3d34eb..90df159e88 100644 --- a/src/corelib/kernel/qproperty.cpp +++ b/src/corelib/kernel/qproperty.cpp @@ -788,10 +788,19 @@ QString QPropertyBindingError::description() const */ /*! + \fn QUntypedPropertyBinding QUntypedBindable::takeBinding() + + Removes the currently set binding from the property and returns it. + Returns a default-constructed QUntypedPropertyBinding if no binding is set. + + \since 6.1 +*/ + +/*! \fn bool QUntypedBindable::setBinding(const QUntypedPropertyBinding &binding) Sets the underlying property's binding to \a binding. This does not have any effect - if the QUntypedBindable is read-only, invalid or if \a binding's type does match the + if the QUntypedBindable is read-only, null or if \a binding's type does match the underlying property's type. \sa QUntypedPropertyBinding::valueMetaType() @@ -842,6 +851,16 @@ QString QPropertyBindingError::description() const */ /*! + \fn template <typename T> QPropertyBinding<T> QBindable<T>::takeBinding() + + Removes the currently set binding of the underlying property and returns it. + If the property does not have a binding, the returned \c QPropertyBinding<T> will be invalid. + + \sa setBinding, getBinding, QPropertyBinding<T>::isValid(), hasBinding +*/ + + +/*! \fn template <typename T> void QBindable<T>::setBinding(const QPropertyBinding<T> &binding) Sets the underlying property's binding to \a binding. Does nothing if the QBindable is diff --git a/src/corelib/kernel/qproperty.h b/src/corelib/kernel/qproperty.h index f853eb8634..750d75c4a7 100644 --- a/src/corelib/kernel/qproperty.h +++ b/src/corelib/kernel/qproperty.h @@ -581,6 +581,22 @@ public: { return iface ? iface->makeBinding(data, location) : QUntypedPropertyBinding(); } + + QUntypedPropertyBinding takeBinding() + { + if (!iface) + return QUntypedPropertyBinding {}; + // We do not have a dedicated takeBinding function pointer in the interface + // therefore we synthesize takeBinding by retrieving the binding with binding + // and calling setBinding with a default constructed QUntypedPropertyBinding + // afterwards. + if (!(iface->getBinding && iface->setBinding)) + return QUntypedPropertyBinding {}; + QUntypedPropertyBinding binding = iface->getBinding(data); + iface->setBinding(data, QUntypedPropertyBinding{}); + return binding; + } + void observe(QPropertyObserver *observer) { if (iface) @@ -650,6 +666,12 @@ public: { return static_cast<QPropertyBinding<T> &&>(QUntypedBindable::binding()); } + + QPropertyBinding<T> takeBinding() + { + return static_cast<QPropertyBinding<T> &&>(QUntypedBindable::takeBinding()); + } + using QUntypedBindable::setBinding; QPropertyBinding<T> setBinding(const QPropertyBinding<T> &binding) { |