From e6988d4d0bef2c3f474576250cb305a2f00a688b Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 21 Aug 2020 13:00:02 +0200 Subject: Remove QNotifiedProperty and Q_PRIVATE_QPROPERTY And all related functionality. This is being replaced by Q_BINDABLE_PROPERTY and Q_OBJECT_BINDABLE_PROPERTY in the next few commits. The new infrastructure coming will play nicer along with the existing property system. Commented out some autotests, that will get reimplemented with the updated infrastructure. Change-Id: I50c30bd4d5c6c6b6471f8eb93870e27d86f5a009 Reviewed-by: Ulf Hermann --- src/corelib/kernel/qproperty.h | 203 ----------------------------------------- 1 file changed, 203 deletions(-) (limited to 'src/corelib/kernel/qproperty.h') diff --git a/src/corelib/kernel/qproperty.h b/src/corelib/kernel/qproperty.h index ef738ccc5a..ff2a5c883f 100644 --- a/src/corelib/kernel/qproperty.h +++ b/src/corelib/kernel/qproperty.h @@ -366,188 +366,6 @@ namespace Qt { } } -template -class QNotifiedProperty -{ - T val = T(); - QtPrivate::QPropertyBindingData d; - bool is_equal(const T &v) - { - if constexpr (QTypeTraits::has_operator_equal_v) { - if (v == val) - return true; - } - return false; - } - -public: - using value_type = T; - using Class = typename QtPrivate::detail::ExtractClassFromFunctionPointer::Class; -private: - static bool constexpr ValueGuardModifiesArgument = std::is_invocable_r_v; - static bool constexpr CallbackAcceptsOldValue = std::is_invocable_v; - static bool constexpr HasValueGuard = !std::is_same_v; -public: - static_assert(CallbackAcceptsOldValue || std::is_invocable_v); - static_assert( - std::is_invocable_r_v || - ValueGuardModifiesArgument || - !HasValueGuard, - "Guard has wrong signature"); -private: - static constexpr QtPrivate::QPropertyGuardFunction GuardTE = - QtPrivate::QPropertyGuardFunctionHelper::guard; -public: - - QNotifiedProperty() = default; - - explicit QNotifiedProperty(const T &initialValue) : val(initialValue) {} - explicit QNotifiedProperty(T &&initialValue) : val(std::move(initialValue)) {} - - QNotifiedProperty(Class *owner, const QPropertyBinding &binding) - : QNotifiedProperty() - { setBinding(owner, binding); } - QNotifiedProperty(Class *owner, QPropertyBinding &&binding) - : QNotifiedProperty() - { setBinding(owner, std::move(binding)); } - -#ifndef Q_CLANG_QDOC - template - explicit QNotifiedProperty(Class *owner, Functor &&f, const QPropertyBindingSourceLocation &location = QT_PROPERTY_DEFAULT_BINDING_LOCATION, - typename std::enable_if_t> * = 0) - : QNotifiedProperty(QPropertyBinding(owner, std::forward(f), location)) - {} -#else - template - explicit QNotifiedProperty(Class *owner, Functor &&f); -#endif - - ~QNotifiedProperty() = default; - - T value() const - { - if (d.hasBinding()) - d.evaluateIfDirty(); - d.registerWithCurrentlyEvaluatingBinding(); - return val; - } - - operator T() const - { - return value(); - } - - template - auto setValue(Class *owner, S &&newValue) -> std::enable_if_t, void> - { - if constexpr (HasValueGuard) { - if (!(owner->*ValueGuard)(newValue)) - return; - } - if (is_equal(newValue)) - return; - if constexpr (CallbackAcceptsOldValue) { - T oldValue = value(); - val = std::move(newValue); - notify(owner, &oldValue); - } else { - val = std::move(newValue); - notify(owner); - } - d.removeBinding(); - } - - void setValue(Class *owner, std::conditional_t newValue) - { - if constexpr (HasValueGuard) { - if (!(owner->*ValueGuard)(newValue)) - return; - } - if (is_equal(newValue)) - return; - if constexpr (CallbackAcceptsOldValue) { - T oldValue = value(); - val = newValue; - notify(owner, &oldValue); - } else { - val = newValue; - notify(owner); - } - d.removeBinding(); - } - - QPropertyBinding setBinding(Class *owner, const QPropertyBinding &newBinding) - { - if constexpr (CallbackAcceptsOldValue) { - T oldValue = value(); - QPropertyBinding oldBinding(d.setBinding(newBinding, &val, owner, [](void *o, void *oldVal) { - (reinterpret_cast(o)->*Callback)(*reinterpret_cast(oldVal)); - }, GuardTE)); - notify(owner, &oldValue); - return oldBinding; - } else { - QPropertyBinding oldBinding(d.setBinding(newBinding, &val, owner, [](void *o, void *) { - (reinterpret_cast(o)->*Callback)(); - }, GuardTE)); - notify(owner); - return oldBinding; - } - } - - bool setBinding(Class *owner, const QUntypedPropertyBinding &newBinding) - { - if (newBinding.valueMetaType().id() != qMetaTypeId()) - return false; - setBinding(owner, static_cast &>(newBinding)); - return true; - } - -#ifndef Q_CLANG_QDOC - template - QPropertyBinding setBinding(Class *owner, Functor &&f, - const QPropertyBindingSourceLocation &location = QT_PROPERTY_DEFAULT_BINDING_LOCATION, - std::enable_if_t> * = nullptr) - { - return setBinding(owner, Qt::makePropertyBinding(std::forward(f), location)); - } -#else - template - QPropertyBinding setBinding(Class *owner, Functor f); -#endif - - bool hasBinding() const { return d.hasBinding(); } - - QPropertyBinding binding() const - { - return QPropertyBinding(*this); - } - - QPropertyBinding takeBinding() - { - return QPropertyBinding(d.setBinding(QUntypedPropertyBinding(), &d)); - } - - template - QPropertyChangeHandler onValueChanged(Functor f); - template - QPropertyChangeHandler subscribe(Functor f); - - const QtPrivate::QPropertyBindingData &bindingData() const { return d; } -private: - void notify(Class *owner, T *oldValue=nullptr) - { - d.notifyObservers(&d); - if constexpr (std::is_invocable_v) { - Q_UNUSED(oldValue); - (owner->*Callback)(); - } else { - (owner->*Callback)(*oldValue); - } - } - - Q_DISABLE_COPY_MOVE(QNotifiedProperty) -}; - struct QPropertyObserverPrivate; struct QPropertyObserverPointer; @@ -649,27 +467,6 @@ QPropertyChangeHandler QProperty::subscribe(Functor f) return onValueChanged(f); } -template -template -QPropertyChangeHandler QNotifiedProperty::onValueChanged(Functor f) -{ -#if defined(__cpp_lib_is_invocable) && (__cpp_lib_is_invocable >= 201703L) - static_assert(std::is_invocable_v, "Functor callback must be callable without any parameters"); -#endif - return QPropertyChangeHandler(*this, f); -} - -template -template -QPropertyChangeHandler QNotifiedProperty::subscribe(Functor f) -{ -#if defined(__cpp_lib_is_invocable) && (__cpp_lib_is_invocable >= 201703L) - static_assert(std::is_invocable_v, "Functor callback must be callable without any parameters"); -#endif - f(); - return onValueChanged(f); -} - template class QPropertyAlias : public QPropertyObserver { -- cgit v1.2.3