diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-08-18 22:33:41 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-09-02 22:44:29 +0200 |
commit | 5b81c80b464ac27b70546ad5ae8cc09e131d30c5 (patch) | |
tree | ad492d37011b47b7b283d047c0f0907d3669be99 /src/corelib/kernel/qpropertyprivate.h | |
parent | 918c61f275e8a9b46459f425df3b69961955a81d (diff) |
Add QObjectCompatProperty
Add a compatibility property class that makes porting to the new
property system as simple as possible.
Binding evaluation for those compat properties is eager, as we
do not control possible side effects of the code in the existing
setters.
Change-Id: Ic56347abb49e40631ec73e88c6d40d4bdb05ca29
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel/qpropertyprivate.h')
-rw-r--r-- | src/corelib/kernel/qpropertyprivate.h | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/src/corelib/kernel/qpropertyprivate.h b/src/corelib/kernel/qpropertyprivate.h index 15e54e9ba8..dd344c209a 100644 --- a/src/corelib/kernel/qpropertyprivate.h +++ b/src/corelib/kernel/qpropertyprivate.h @@ -76,10 +76,8 @@ namespace QtPrivate { // writes binding result into dataPtr using QPropertyBindingFunction = std::function<bool(QMetaType metaType, QUntypedPropertyData *dataPtr)>; - -using QPropertyBindingWrapper = bool(*)(QMetaType, QUntypedPropertyData *dataPtr, - QPropertyBindingFunction); using QPropertyObserverCallback = void (*)(QUntypedPropertyData *); +using QPropertyBindingWrapper = bool(*)(QMetaType, QUntypedPropertyData *dataPtr, QPropertyBindingFunction); class Q_CORE_EXPORT QPropertyBindingData { @@ -101,7 +99,8 @@ public: QUntypedPropertyBinding setBinding(const QUntypedPropertyBinding &newBinding, QUntypedPropertyData *propertyDataPtr, QPropertyObserverCallback staticObserverCallback = nullptr, - QPropertyBindingWrapper guardCallback = nullptr); + QPropertyBindingWrapper bindingWrapper = nullptr); + QPropertyBindingPrivate *binding() const; void evaluateIfDirty(const QUntypedPropertyData *property) const; @@ -188,30 +187,6 @@ namespace detail { } } -// type erased guard functions, casts its arguments to the correct types -template<typename T, typename Class, auto Guard, bool = std::is_same_v<decltype(Guard), std::nullptr_t>> -struct QPropertyGuardFunctionHelper -{ - static constexpr QPropertyBindingWrapper guard = nullptr; -}; -template<typename T, typename Class, auto Guard> -struct QPropertyGuardFunctionHelper<T, Class, Guard, false> -{ - static auto guard(QMetaType metaType, QUntypedPropertyData *dataPtr, - QPropertyBindingFunction eval, void *owner) -> bool - { - T t = T(); - eval(metaType, &t); - if (!(static_cast<Class *>(owner)->*Guard)(t)) - return false; - T *data = static_cast<T *>(dataPtr); - if (*data == t) - return false; - *data = std::move(t); - return true; - }; -}; - } // namespace QtPrivate QT_END_NAMESPACE |