diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2020-04-15 20:23:28 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2020-04-30 19:39:25 +0200 |
commit | 3d7265db9075db7b22b241b659f23d392d62d804 (patch) | |
tree | 902bb831d91f39b89d4481dca9381a18abb5dac3 /src/corelib/kernel/qtmetamacros.h | |
parent | b480acb3720c0d61c5c69a2b861af63b9d7c9f86 (diff) |
Provide a way of exposing private QProperties with a fake API
The API reduces the amount of manual plumbing required to offer a
conceptual property through the traditional setter/getter API as well as
through QProperty<T> API. Since the latter would require inlining the
type and thus making it impossible to add new properties without
breaking binary compatibility, this patch introduces a fake API that
behaves similar but does not contain the property by value.
Change-Id: Ib9bccd867f0e4e36a520e5583ba348e728284253
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel/qtmetamacros.h')
-rw-r--r-- | src/corelib/kernel/qtmetamacros.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/corelib/kernel/qtmetamacros.h b/src/corelib/kernel/qtmetamacros.h index 2dcd6948aa..fb89722847 100644 --- a/src/corelib/kernel/qtmetamacros.h +++ b/src/corelib/kernel/qtmetamacros.h @@ -91,6 +91,34 @@ QT_BEGIN_NAMESPACE #define Q_INTERFACES(x) QT_ANNOTATE_CLASS(qt_interfaces, x) #define Q_PROPERTY(...) QT_ANNOTATE_CLASS(qt_property, __VA_ARGS__) #define Q_PRIVATE_PROPERTY(d, text) QT_ANNOTATE_CLASS2(qt_private_property, d, text) +#define Q_PRIVATE_QPROPERTY(accessor, type, name, setter, ...) \ + struct _qt_property_api_##name { \ + type value() const; \ + type operator()() const { return value(); } \ + void setValue(type &&); \ + void setValue(const type &); \ + void operator=(const type &v) { setValue(v); } \ + void operator=(type &&v) { setValue(std::move(v)); } \ + QPropertyBinding<type> setBinding(const QPropertyBinding<type> &); \ + QPropertyBinding<type> setBinding(QPropertyBinding<type> &&); \ + QPropertyBinding<type> operator=(const QPropertyBinding<type> &b) { return setBinding(b); } \ + QPropertyBinding<type> operator=(QPropertyBinding<type> &&b) { return setBinding(std::move(b)); } \ + bool setBinding(const QUntypedPropertyBinding &); \ + template <typename Functor> \ + QPropertyBinding<type> setBinding(Functor f, \ + const QPropertyBindingSourceLocation &location = QT_PROPERTY_DEFAULT_BINDING_LOCATION) \ + { \ + return setBinding(Qt::makePropertyBinding(f, location)); \ + } \ + bool hasBinding() const; \ + QPropertyBinding<type> binding() const; \ + QPropertyBinding<type> takeBinding(); \ + }; \ + void setter(const type &value); +#define Q_PRIVATE_QPROPERTIES_BEGIN union { +#define Q_PRIVATE_QPROPERTY_IMPL(name) \ + _qt_property_api_##name name; +#define Q_PRIVATE_QPROPERTIES_END }; #ifndef Q_REVISION # define Q_REVISION(...) #endif @@ -211,6 +239,10 @@ private: \ #define Q_INTERFACES(x) Q_INTERFACES(x) #define Q_PROPERTY(text) Q_PROPERTY(text) #define Q_PRIVATE_PROPERTY(d, text) Q_PRIVATE_PROPERTY(d, text) +#define Q_PRIVATE_QPROPERTY(accessor, type, name, setter, ...) Q_PRIVATE_QPROPERTY(accessor, type, name, setter, __VA_ARGS__) +#define Q_PRIVATE_QPROPERTIES_BEGIN +#define Q_PRIVATE_QPROPERTY_IMPL(name) +#define Q_PRIVATE_QPROPERTIES_END #define Q_REVISION(...) Q_REVISION(__VA_ARGS__) #define Q_OVERRIDE(text) Q_OVERRIDE(text) #define Q_ENUMS(x) Q_ENUMS(x) |