Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\inmodule QtCore More...
#include <qproperty.h>
Public Types | |
using | value_type = typename QPropertyData<T>::value_type |
using | parameter_type = typename QPropertyData<T>::parameter_type |
using | rvalue_ref = typename QPropertyData<T>::rvalue_ref |
using | arrow_operator_result = typename QPropertyData<T>::arrow_operator_result |
Public Types inherited from QPropertyData< T > | |
using | value_type = T |
using | parameter_type = std::conditional_t<UseReferences, const T &, T> |
using | rvalue_ref = typename std::conditional_t<UseReferences, T &&, DisableRValueRefs> |
using | arrow_operator_result |
Public Member Functions | |
QObjectBindableProperty ()=default | |
QObjectBindableProperty (const T &initialValue) | |
Constructs a property with the provided initialValue. | |
QObjectBindableProperty (T &&initialValue) | |
Move-Constructs a property with the provided initialValue. | |
QObjectBindableProperty (const QPropertyBinding< T > &binding) | |
template<typename Functor > | |
QObjectBindableProperty (Functor &&f, const QPropertyBindingSourceLocation &location=QT_PROPERTY_DEFAULT_BINDING_LOCATION, typename std::enable_if_t< std::is_invocable_r_v< T, Functor & > > *=nullptr) | |
parameter_type | value () const |
Returns the value of the property. | |
arrow_operator_result | operator-> () const |
parameter_type | operator* () const |
operator parameter_type () const | |
void | setValue (parameter_type t) |
void | notify () |
Programmatically signals a change of the property. | |
void | setValue (rvalue_ref t) |
Assigns newValue to this property and removes the property's associated binding, if present. | |
QObjectBindableProperty & | operator= (rvalue_ref newValue) |
QObjectBindableProperty & | operator= (parameter_type newValue) |
QPropertyBinding< T > | setBinding (const QPropertyBinding< T > &newBinding) |
Associates the value of this property with the provided newBinding expression and returns the previously associated binding. | |
bool | setBinding (const QUntypedPropertyBinding &newBinding) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Associates the value of this property with the provided newBinding expression. | |
template<typename Functor > | |
QPropertyBinding< T > | setBinding (Functor &&f, const QPropertyBindingSourceLocation &location=QT_PROPERTY_DEFAULT_BINDING_LOCATION, std::enable_if_t< std::is_invocable_v< Functor > > *=nullptr) |
bool | hasBinding () const |
Returns true if the property is associated with a binding; false otherwise. | |
QPropertyBinding< T > | binding () const |
Returns the binding expression that is associated with this property. | |
QPropertyBinding< T > | takeBinding () |
Disassociates the binding expression from this property and returns it. | |
template<typename Functor > | |
QPropertyChangeHandler< Functor > | onValueChanged (Functor f) |
Registers the given functor f as a callback that shall be called whenever the value of the property changes. | |
template<typename Functor > | |
QPropertyChangeHandler< Functor > | subscribe (Functor f) |
Subscribes the given functor f as a callback that is called immediately and whenever the value of the property changes in the future. | |
template<typename Functor > | |
QPropertyNotifier | addNotifier (Functor f) |
Subscribes the given functor f as a callback that is called whenever the value of the property changes. | |
const QtPrivate::QPropertyBindingData & | bindingData () const |
Public Member Functions inherited from QPropertyData< T > | |
QPropertyData ()=default | |
QPropertyData (parameter_type t) | |
QPropertyData (rvalue_ref t) | |
~QPropertyData ()=default | |
parameter_type | valueBypassingBindings () const |
Returns the data stored in this property. | |
void | setValueBypassingBindings (parameter_type v) |
Sets the data value stored in this property to v. | |
void | setValueBypassingBindings (rvalue_ref v) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the data value stored in this property to v. | |
Additional Inherited Members | |
Protected Attributes inherited from QPropertyData< T > | |
T | val = T() |
Static Protected Attributes inherited from QPropertyData< T > | |
static constexpr bool | UseReferences = !(std::is_arithmetic_v<T> || std::is_enum_v<T> || std::is_pointer_v<T>) |
\inmodule QtCore
The QObjectBindableProperty class is a template class that enables automatic property bindings for property data stored in QObject derived classes.
QObjectBindableProperty is a generic container that holds an instance of T and behaves mostly like \l QProperty. It is one of the classes implementing \l {Qt Bindable Properties}. Unlike QProperty, it stores its management data structure in the surrounding QObject. The extra template parameters are used to identify the surrounding class and a member function of that class acting as a change handler.
You can use QObjectBindableProperty to add binding support to code that uses Q_PROPERTY. The getter and setter methods must be adapted carefully according to the rules described in \l {Bindable Property Getters and Setters}.
In order to invoke the change signal on property changes, use QObjectBindableProperty and pass the change signal as a callback.
A simple example is given in the following.
QObjectBindableProperty is usually not used directly, instead an instance of it is created by using the Q_OBJECT_BINDABLE_PROPERTY macro.
Use the Q_OBJECT_BINDABLE_PROPERTY macro in the class declaration to declare the property as bindable.
If you need to directly initialize the property with some non-default value, you can use the Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS macro. It accepts a value for the initialization as one of its parameters.
Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS does not support multiple arguments directly. If your property requires multiple arguments for initialization, please explicitly call the specific constructor.
The change handler can optionally accept one argument, of the same type as the property, in which case it is passed the new value of the property. Otherwise, it should take no arguments.
If the property does not need a changed notification, you can leave out the "NOTIFY xChanged" in the Q_PROPERTY macro as well as the last argument of the Q_OBJECT_BINDABLE_PROPERTY and Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS macros.
Definition at line 1023 of file qproperty.h.
using QObjectBindableProperty< Class, T, Offset, Signal >::arrow_operator_result = typename QPropertyData<T>::arrow_operator_result |
Definition at line 1052 of file qproperty.h.
using QObjectBindableProperty< Class, T, Offset, Signal >::parameter_type = typename QPropertyData<T>::parameter_type |
Definition at line 1050 of file qproperty.h.
using QObjectBindableProperty< Class, T, Offset, Signal >::rvalue_ref = typename QPropertyData<T>::rvalue_ref |
Definition at line 1051 of file qproperty.h.
using QObjectBindableProperty< Class, T, Offset, Signal >::value_type = typename QPropertyData<T>::value_type |
Definition at line 1049 of file qproperty.h.
|
default |
|
inlineexplicit |
Constructs a property with the provided initialValue.
Definition at line 1055 of file qproperty.h.
|
inlineexplicit |
Move-Constructs a property with the provided initialValue.
Definition at line 1056 of file qproperty.h.
|
inlineexplicit |
Definition at line 1057 of file qproperty.h.
References QObjectBindableProperty< Class, T, Offset, Signal >::setBinding().
|
inlineexplicit |
Definition at line 1062 of file qproperty.h.
|
inline |
Subscribes the given functor f as a callback that is called whenever the value of the property changes.
The callback f is expected to be a type that has a plain call operator {()} without any parameters. This means that you can provide a C++ lambda expression, a std::function or even a custom struct with a call operator.
The returned property change handler object keeps track of the subscription. When it goes out of scope, the callback is unsubscribed.
This method is in some cases easier to use than onValueChanged(), as the returned object is not a template. It can therefore more easily be stored, e.g. as a member in a class.
Definition at line 1199 of file qproperty.h.
|
inline |
Returns the binding expression that is associated with this property.
A default constructed QPropertyBinding<T> will be returned if no such association exists.
Definition at line 1172 of file qproperty.h.
|
inline |
Definition at line 1205 of file qproperty.h.
|
inline |
Returns true if the property is associated with a binding; false otherwise.
Definition at line 1166 of file qproperty.h.
|
inline |
Programmatically signals a change of the property.
Any binding which depend on it will be notified, and if the property has a signal, it will be emitted.
This can be useful in combination with setValueBypassingBindings to defer signalling the change until a class invariant has been restored.
Definition at line 1110 of file qproperty.h.
References QObjectBindableProperty< Class, T, Offset, Signal >::notify().
Referenced by QObjectBindableProperty< Class, T, Offset, Signal >::notify(), QObjectBindableProperty< Class, T, Offset, Signal >::setValue(), and QObjectBindableProperty< Class, T, Offset, Signal >::setValue().
|
inline |
Registers the given functor f as a callback that shall be called whenever the value of the property changes.
On each value change, the handler is either called immediately, or deferred, depending on the context.
The callback f is expected to be a type that has a plain call operator {()} without any parameters. This means that you can provide a C++ lambda expression, a std::function or even a custom struct with a call operator.
The returned property change handler object keeps track of the registration. When it goes out of scope, the callback is de-registered.
Definition at line 1184 of file qproperty.h.
References QPropertyChangeHandler< Functor >::QPropertyChangeHandler().
|
inline |
Definition at line 1094 of file qproperty.h.
References QObjectBindableProperty< Class, T, Offset, Signal >::value().
|
inline |
Definition at line 1089 of file qproperty.h.
References QObjectBindableProperty< Class, T, Offset, Signal >::value().
|
inline |
Definition at line 1077 of file qproperty.h.
References QObjectBindableProperty< Class, T, Offset, Signal >::value().
|
inline |
Definition at line 1132 of file qproperty.h.
|
inline |
Definition at line 1126 of file qproperty.h.
|
inline |
Associates the value of this property with the provided newBinding expression and returns the previously associated binding.
The property's value is set to the result of evaluating the new binding. Whenever a dependency of the binding changes, the binding will be re-evaluated, and the property's value gets updated accordingly. When the property value changes, the owner is notified via the Callback function.
Definition at line 1138 of file qproperty.h.
Referenced by QObjectBindableProperty< Class, T, Offset, Signal >::QObjectBindableProperty(), QObjectBindableProperty< Class, T, Offset, Signal >::setBinding(), QObjectBindableProperty< Class, T, Offset, Signal >::setBinding(), and QObjectBindableProperty< Class, T, Offset, Signal >::takeBinding().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Associates the value of this property with the provided newBinding expression.
The property's value is set to the result of evaluating the new binding. Whenever a dependency of the binding changes, the binding will be re-evaluated, and the property's value gets updated accordingly.
Returns true
if the type of this property is the same as the type the binding function returns; false
otherwise.
Definition at line 1145 of file qproperty.h.
References QObjectBindableProperty< Class, T, Offset, Signal >::setBinding().
|
inline |
Definition at line 1155 of file qproperty.h.
References QObjectBindableProperty< Class, T, Offset, Signal >::setBinding().
|
inline |
Definition at line 1099 of file qproperty.h.
References QObjectBindableProperty< Class, T, Offset, Signal >::notify().
|
inline |
Assigns newValue to this property and removes the property's associated binding, if present.
If the property value changes as a result, calls the Callback function on owner.
Definition at line 1115 of file qproperty.h.
References QObjectBindableProperty< Class, T, Offset, Signal >::notify().
|
inline |
Subscribes the given functor f as a callback that is called immediately and whenever the value of the property changes in the future.
On each value change, the handler is either called immediately, or deferred, depending on the context.
The callback f is expected to be a type that has a plain call operator {()} without any parameters. This means that you can provide a C++ lambda expression, a std::function or even a custom struct with a call operator.
The returned property change handler object keeps track of the subscription. When it goes out of scope, the callback is unsubscribed.
Definition at line 1191 of file qproperty.h.
|
inline |
Disassociates the binding expression from this property and returns it.
After calling this function, the value of the property will only change if you assign a new value to it, or when a new binding is set.
Definition at line 1178 of file qproperty.h.
References QObjectBindableProperty< Class, T, Offset, Signal >::setBinding().
|
inline |
Returns the value of the property.
This may evaluate a binding expression that is tied to this property, before returning the value.
Definition at line 1071 of file qproperty.h.
Referenced by QObjectBindableProperty< Class, T, Offset, Signal >::operator parameter_type(), QObjectBindableProperty< Class, T, Offset, Signal >::operator*(), and QObjectBindableProperty< Class, T, Offset, Signal >::operator->().