Qx v0.6
Qt Extensions Library
|
Bindable is a wrapper class around binding-enabled properties that provides uniform access, regardless of the specific type. More...
#include <qx/core/qx-property.h>
Public Member Functions | |
Bindable () | |
Bindable (AbstractBindableProperty< T > &bp) | |
Bindable (const AbstractBindableProperty< T > &bp) | |
Bindable (QObject *obj, const char *property) | |
Bindable (QObject *obj, const QMetaProperty &property) | |
template<std::invocable Functor> | |
void | addLifetimeNotifier (Functor &&f) const |
template<std::invocable Functor> | |
PropertyNotifier | addNotifier (Functor &&f) const |
PropertyBinding< T > | binding () const |
bool | hasBinding () const |
bool | isReadOnly () const |
bool | isValid () const |
operator const T & () const | |
const T & | operator* () const |
decltype(auto) | operator-> () const |
Bindable & | operator= (const T &newValue) noexcept |
Bindable & | operator= (T &&newValue) noexcept |
void | removeBinding () |
PropertyBinding< T > | setBinding (const PropertyBinding< T > &binding) |
template<std::invocable Functor> | |
PropertyBinding< T > | setBinding (Functor &&f) |
void | setValue (const T &newValue) |
void | setValue (T &&newValue) |
void | setValueBypassingBindings (const T &v) |
void | setValueBypassingBindings (T &&v) |
template<std::invocable Functor> | |
PropertyNotifier | subscribe (Functor &&f) const |
template<std::invocable Functor> | |
void | subscribeLifetime (Functor &&f) const |
PropertyBinding< T > | takeBinding () |
const T & | value () const |
const T & | valueBypassingBindings () const |
Bindable acts as a convenience type for sharing access to any concrete bindable property without the need to use interface pointers directly, via a thin, cheap to copy wrapper.
The methods of this class essentially mirror those of AbstractBindableProperty and an instance of this class can be used in an identical fashion as the property it shadows.
Additionally, the constructors that take a QObject pointer can be used to wrap a property of a classes based on it (i.e. those created using Q_PROPERTY()), which are not already bindable.
Due to the abstraction that this class provides, instances may be "read-only", meaning that any attempt to use a non-const method will fail and a warning will be emitted. The contexts in which this is the case are noted in the documentation for the constructors of this class. Use isReadOnly() to check if a particular instance cannot mutate the property it wraps.
Since the Qx Bindable Properties System does not directly interact with the native Qt equivalent, the aforementioned constructor of QBindable will need to be used to bind to the property of any any QObject derived typed that does not have accessor methods to underlying Qx bindable properties (e.g. Qx::Property), even if the property in question is already bindable using Qt's system.
The best way to create a QObject-based class that natively uses Qx properties is to add instances of Property as class members and provide an accessor method to them that returns a Qx::Bindable, like so:
|
inline |
Constructs an invalid Bindable.
|
inline |
Constructs a Bindable wrapper for the bindable property bp.
|
inline |
|
inline |
Constructs a Bindable wrapper for property property of obj.
The property must have a notify signal, and you must access the property through the created Bindable (e.g. via value(), etc.) instead of the normal property READ function (or MEMBER) to enable dependency tracking.
When binding using a lambda, you may prefer to capture the QBindable by value to avoid the cost of calling this constructor in the binding expression.
|
inline |
Constructs a Bindable wrapper for the property named property of obj.
See Bindable(QObject*, const QMetaProperty&).
|
inline |
Same as addNotifier(), but the lifetime of the subscription is tied to the lifetime of the property so no change handler object is returned.
|
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.
|
inline |
Returns the binding expression that is associated with this property. A default constructed PropertyBinding will be returned if no such association exists.
|
inline |
Returns true
if the property has a binding associated with it; otherwise, returns false.
|
inline |
|
inline |
Returns true
if the Bindable is valid; otherwise, returns false
.
A binding is invalid if there was an issue the arguments passed to its constructor, like a null pointer or a property being specified that does not actually belong to the preceding object, or if the default constructor was used.
|
inline |
Type-conversion operator for a const reference to the underlying type.
|
inline |
Same as value().
|
inline |
Returns a pointer to the underlying property data (bindings are still respected).
|
inlinenoexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inlinenoexcept |
Assigns newValue to the property and returns a reference to this bindable.
|
inline |
Disassociates the binding expression from this property. 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.
|
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 binding 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.
|
inline |
Associates the value of this property with the provided functor f 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.
|
inline |
Assigns newValue to this property and removes the property's associated binding, if present.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Directly sets the value of the property to v.
This is generally only used by a derived class to control how the underlying data is written when a copy of T is provided, but there are some cases (like maintaining class invariants) where it is useful externally.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Directly sets the value of this property to v.
This is generally only used by a derived class to control how the underlying data is written when an rvalue of T is provided, but there are some cases (like maintaining class invariants) where it is useful externally.
|
inline |
Same as invoking f (e.g. f()
), followed by addNotifier(f)
.
That is, the callback functor is called immediately before it's registered.
|
inline |
Same as invoking f (e.g. f()
), followed by addLifetimeNotifier(f)
.
That is, the callback functor is called immediately before it's registered.
|
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.
|
inline |
Returns the value of the property. This may evaluate a binding expression that is tied to this property, before returning the value.
|
inline |
Returns the direct value of the property.
This is generally only used by a derived class to control how the underlying data is read when requested, but there are some cases where it is useful externally.