![]() |
Qt 6.x
The Qt SDK
|
\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 |
![]() | |
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 = std::conditional_t< std::is_pointer_v< T >, const T &, std::conditional_t< QTypeTraits::is_dereferenceable_v< T >, const T &, void > > |
Public Member Functions | |
QProperty ()=default | |
Constructs a property with a default constructed instance of T. | |
QProperty (parameter_type initialValue) | |
QProperty (rvalue_ref initialValue) | |
QProperty (const QPropertyBinding< T > &binding) | |
Constructs a property that is tied to the provided binding expression. | |
template<typename Functor > | |
QProperty (Functor &&f, const QPropertyBindingSourceLocation &location=QT_PROPERTY_DEFAULT_BINDING_LOCATION, typename std::enable_if_t< std::is_invocable_r_v< T, Functor & > > *=nullptr) | |
~QProperty ()=default | |
Destroys the property. | |
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 (rvalue_ref newValue) |
void | setValue (parameter_type newValue) |
Assigns newValue to this property and removes the property's associated binding, if present. | |
QProperty< T > & | operator= (rvalue_ref newValue) |
QProperty< T > & | operator= (parameter_type newValue) |
Assigns newValue to this property and returns a reference to this QProperty. | |
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 |
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 |
![]() | |
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. | |
Related Symbols | |
(Note that these are not member symbols.) | |
void | beginPropertyUpdateGroup () |
void | endPropertyUpdateGroup () |
Additional Inherited Members | |
![]() | |
T | val = T() |
![]() | |
static constexpr bool | UseReferences = !(std::is_arithmetic_v<T> || std::is_enum_v<T> || std::is_pointer_v<T>) |
\inmodule QtCore
The QProperty class is a template class that enables automatic property bindings.
QProperty<T> is one of the classes implementing \l {Qt Bindable Properties}. It is a container that holds an instance of T. You can assign a value to it and you can read it via the value() function or the T conversion operator. You can also tie the property to an expression that computes the value dynamically, the binding expression. It is represented as a C++ lambda and can be used to express relationships between different properties in your application.
QProperty<T>::onValueChanged, QProperty::takeBinding and QBindable::hasBinding
If the property is BINDABLE, then the engine will use the change-tracking inherent to the C++ property system for getting notified about changes; and won't rely on signals being emitted.
Definition at line 348 of file qproperty.h.
using QProperty< T >::arrow_operator_result = typename QPropertyData<T>::arrow_operator_result |
Definition at line 364 of file qproperty.h.
using QProperty< T >::parameter_type = typename QPropertyData<T>::parameter_type |
Definition at line 362 of file qproperty.h.
using QProperty< T >::rvalue_ref = typename QPropertyData<T>::rvalue_ref |
Definition at line 363 of file qproperty.h.
using QProperty< T >::value_type = typename QPropertyData<T>::value_type |
Definition at line 361 of file qproperty.h.
|
default |
Constructs a property with a default constructed instance of T.
|
inlineexplicit |
Definition at line 367 of file qproperty.h.
|
inlineexplicit |
Definition at line 368 of file qproperty.h.
|
inlineexplicit |
Constructs a property that is tied to the provided binding 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.
Definition at line 369 of file qproperty.h.
References QProperty< T >::binding(), and QProperty< T >::setBinding().
|
inlineexplicit |
Definition at line 374 of file qproperty.h.
Destroys the property.
|
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 496 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 470 of file qproperty.h.
References d.
Referenced by QProperty< T >::QProperty().
|
inline |
Definition at line 502 of file qproperty.h.
References d.
|
inline |
Definition at line 468 of file qproperty.h.
References d.
|
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 481 of file qproperty.h.
Referenced by QProperty< T >::subscribe().
|
inline |
Definition at line 407 of file qproperty.h.
References QProperty< T >::value().
|
inline |
Definition at line 402 of file qproperty.h.
References QProperty< T >::value().
|
inline |
Definition at line 390 of file qproperty.h.
References QPropertyData< T >::val, and QProperty< T >::value().
|
inline |
Assigns newValue to this property and returns a reference to this QProperty.
Definition at line 436 of file qproperty.h.
References QProperty< T >::setValue().
|
inline |
Definition at line 430 of file qproperty.h.
References QProperty< T >::setValue().
|
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.
Definition at line 442 of file qproperty.h.
References d.
Referenced by QProperty< T >::QProperty(), QProperty< T >::setBinding(), and QProperty< T >::setBinding().
|
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 447 of file qproperty.h.
References QMetaType::id(), QUntypedPropertyBinding::isNull(), QProperty< T >::setBinding(), and QUntypedPropertyBinding::valueMetaType().
|
inline |
Definition at line 457 of file qproperty.h.
References Qt::makePropertyBinding(), and QProperty< T >::setBinding().
|
inline |
Assigns newValue to this property and removes the property's associated binding, if present.
Definition at line 421 of file qproperty.h.
References d.
|
inline |
Definition at line 412 of file qproperty.h.
References d.
Referenced by QProperty< T >::operator=(), and QProperty< T >::operator=().
|
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 can be copied and 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 488 of file qproperty.h.
References QProperty< T >::onValueChanged().
|
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 475 of file qproperty.h.
References d.
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 384 of file qproperty.h.
References d, and QPropertyData< T >::val.
Referenced by QProperty< T >::operator parameter_type(), QProperty< T >::operator*(), and QProperty< T >::operator->().
|
related |
Marks the beginning of a property update group. Inside this group, changing a property does neither immediately update any dependent properties nor does it trigger change notifications. Those are instead deferred until the group is ended by a call to endPropertyUpdateGroup.
Groups can be nested. In that case, the deferral ends only after the outermost group has been ended.
Definition at line 190 of file qproperty.cpp.
References bindingStatus, QBindingStatus::groupUpdateData, and QPropertyDelayedNotifications::ref.
|
related |
Ends a property update group. If the outermost group has been ended, and deferred binding evaluations and notifications happen now.
Definition at line 210 of file qproperty.cpp.
References bindingStatus, i, QPropertyBindingPrivate::notifyNonRecursive(), and Q_ASSERT.