summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qproperty.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-08-21 13:00:02 +0200
committerLars Knoll <lars.knoll@qt.io>2020-09-02 22:44:27 +0200
commite6988d4d0bef2c3f474576250cb305a2f00a688b (patch)
tree9412573d07041918349dc2542673467739be73ce /src/corelib/kernel/qproperty.h
parente638e8a28d74af8129aaaf6b67fabbb5dbdf31e4 (diff)
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 <ulf.hermann@qt.io>
Diffstat (limited to 'src/corelib/kernel/qproperty.h')
-rw-r--r--src/corelib/kernel/qproperty.h203
1 files changed, 0 insertions, 203 deletions
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 <typename T, auto Callback, auto ValueGuard=nullptr>
-class QNotifiedProperty
-{
- T val = T();
- QtPrivate::QPropertyBindingData d;
- bool is_equal(const T &v)
- {
- if constexpr (QTypeTraits::has_operator_equal_v<T>) {
- if (v == val)
- return true;
- }
- return false;
- }
-
-public:
- using value_type = T;
- using Class = typename QtPrivate::detail::ExtractClassFromFunctionPointer<decltype(Callback)>::Class;
-private:
- static bool constexpr ValueGuardModifiesArgument = std::is_invocable_r_v<bool, decltype(ValueGuard), Class, T&>;
- static bool constexpr CallbackAcceptsOldValue = std::is_invocable_v<decltype(Callback), Class, T>;
- static bool constexpr HasValueGuard = !std::is_same_v<decltype(ValueGuard), std::nullptr_t>;
-public:
- static_assert(CallbackAcceptsOldValue || std::is_invocable_v<decltype(Callback), Class>);
- static_assert(
- std::is_invocable_r_v<bool, decltype(ValueGuard), Class, T> ||
- ValueGuardModifiesArgument ||
- !HasValueGuard,
- "Guard has wrong signature");
-private:
- static constexpr QtPrivate::QPropertyGuardFunction GuardTE =
- QtPrivate::QPropertyGuardFunctionHelper<T, Class, ValueGuard>::guard;
-public:
-
- QNotifiedProperty() = default;
-
- explicit QNotifiedProperty(const T &initialValue) : val(initialValue) {}
- explicit QNotifiedProperty(T &&initialValue) : val(std::move(initialValue)) {}
-
- QNotifiedProperty(Class *owner, const QPropertyBinding<T> &binding)
- : QNotifiedProperty()
- { setBinding(owner, binding); }
- QNotifiedProperty(Class *owner, QPropertyBinding<T> &&binding)
- : QNotifiedProperty()
- { setBinding(owner, std::move(binding)); }
-
-#ifndef Q_CLANG_QDOC
- template <typename Functor>
- explicit QNotifiedProperty(Class *owner, Functor &&f, const QPropertyBindingSourceLocation &location = QT_PROPERTY_DEFAULT_BINDING_LOCATION,
- typename std::enable_if_t<std::is_invocable_r_v<T, Functor&>> * = 0)
- : QNotifiedProperty(QPropertyBinding<T>(owner, std::forward<Functor>(f), location))
- {}
-#else
- template <typename Functor>
- 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<typename S>
- auto setValue(Class *owner, S &&newValue) -> std::enable_if_t<!ValueGuardModifiesArgument && std::is_same_v<S, 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<ValueGuardModifiesArgument, T, const 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<T> setBinding(Class *owner, const QPropertyBinding<T> &newBinding)
- {
- if constexpr (CallbackAcceptsOldValue) {
- T oldValue = value();
- QPropertyBinding<T> oldBinding(d.setBinding(newBinding, &val, owner, [](void *o, void *oldVal) {
- (reinterpret_cast<Class *>(o)->*Callback)(*reinterpret_cast<T *>(oldVal));
- }, GuardTE));
- notify(owner, &oldValue);
- return oldBinding;
- } else {
- QPropertyBinding<T> oldBinding(d.setBinding(newBinding, &val, owner, [](void *o, void *) {
- (reinterpret_cast<Class *>(o)->*Callback)();
- }, GuardTE));
- notify(owner);
- return oldBinding;
- }
- }
-
- bool setBinding(Class *owner, const QUntypedPropertyBinding &newBinding)
- {
- if (newBinding.valueMetaType().id() != qMetaTypeId<T>())
- return false;
- setBinding(owner, static_cast<const QPropertyBinding<T> &>(newBinding));
- return true;
- }
-
-#ifndef Q_CLANG_QDOC
- template <typename Functor>
- QPropertyBinding<T> setBinding(Class *owner, Functor &&f,
- const QPropertyBindingSourceLocation &location = QT_PROPERTY_DEFAULT_BINDING_LOCATION,
- std::enable_if_t<std::is_invocable_v<Functor>> * = nullptr)
- {
- return setBinding(owner, Qt::makePropertyBinding(std::forward<Functor>(f), location));
- }
-#else
- template <typename Functor>
- QPropertyBinding<T> setBinding(Class *owner, Functor f);
-#endif
-
- bool hasBinding() const { return d.hasBinding(); }
-
- QPropertyBinding<T> binding() const
- {
- return QPropertyBinding<T>(*this);
- }
-
- QPropertyBinding<T> takeBinding()
- {
- return QPropertyBinding<T>(d.setBinding(QUntypedPropertyBinding(), &d));
- }
-
- template<typename Functor>
- QPropertyChangeHandler<Functor> onValueChanged(Functor f);
- template<typename Functor>
- QPropertyChangeHandler<Functor> 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<decltype(Callback), Class>) {
- Q_UNUSED(oldValue);
- (owner->*Callback)();
- } else {
- (owner->*Callback)(*oldValue);
- }
- }
-
- Q_DISABLE_COPY_MOVE(QNotifiedProperty)
-};
-
struct QPropertyObserverPrivate;
struct QPropertyObserverPointer;
@@ -649,27 +467,6 @@ QPropertyChangeHandler<Functor> QProperty<T>::subscribe(Functor f)
return onValueChanged(f);
}
-template <typename T, auto Callback, auto ValueGuard>
-template<typename Functor>
-QPropertyChangeHandler<Functor> QNotifiedProperty<T, Callback, ValueGuard>::onValueChanged(Functor f)
-{
-#if defined(__cpp_lib_is_invocable) && (__cpp_lib_is_invocable >= 201703L)
- static_assert(std::is_invocable_v<Functor>, "Functor callback must be callable without any parameters");
-#endif
- return QPropertyChangeHandler<Functor>(*this, f);
-}
-
-template <typename T, auto Callback, auto ValueGuard>
-template<typename Functor>
-QPropertyChangeHandler<Functor> QNotifiedProperty<T, Callback, ValueGuard>::subscribe(Functor f)
-{
-#if defined(__cpp_lib_is_invocable) && (__cpp_lib_is_invocable >= 201703L)
- static_assert(std::is_invocable_v<Functor>, "Functor callback must be callable without any parameters");
-#endif
- f();
- return onValueChanged(f);
-}
-
template<typename T>
class QPropertyAlias : public QPropertyObserver
{