Qx v0.6
Qt Extensions Library
Loading...
Searching...
No Matches
Qx::AbstractBindableProperty< T > Class Template Referenceabstract

The AbstractBindableProperty class provides the baseline feature for bindable properties of the Qx Bindable Properties System. More...

#include <qx/core/qx-property.h>

Inheritance diagram for Qx::AbstractBindableProperty< T >:
[legend]

Public Member Functions

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
 
 operator const T & () const
 
const T & operator* () const
 
decltype(auto) operator-> () const
 
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)
 
virtual void setValueBypassingBindings (T &&v)=0
 
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
 
virtual const T & valueBypassingBindings () const =0
 

Protected Member Functions

 AbstractBindableProperty ()
 
 AbstractBindableProperty (AbstractBindableProperty &&other) noexcept=default
 
AbstractBindablePropertyoperator= (AbstractBindableProperty &&other) noexcept=default
 

Detailed Description

template<typename T>
class Qx::AbstractBindableProperty< T >

AbstractBindableProperty is the standard interface shared by all bindable properties and contains most of the functionality that any given implementation will provide to user code; that is, most individual implementations are minimal annex that simply dictate how the underlying data of the property is read/written, and the bulk of the Bindable Properties System is contained within this base class.

You can assign a value to properties and you can read them via value(), operator*(), or operator const T&(). You can also tie a property to an expression that computes the value dynamically, called a "binding expression". The binding expression can be any C++ functor, though most often a lambda, and can be used to express relationships between different properties in your application.

See also
Property.

Constructor & Destructor Documentation

◆ AbstractBindableProperty() [1/2]

template<typename T >
Qx::AbstractBindableProperty< T >::AbstractBindableProperty ( )
inlineprotected

Constructs an AbstractBindableProperty.

◆ AbstractBindableProperty() [2/2]

template<typename T >
Qx::AbstractBindableProperty< T >::AbstractBindableProperty ( AbstractBindableProperty< T > && other)
protecteddefaultnoexcept

Move-constructs an AbstractBindableProperty using other.

Member Function Documentation

◆ addLifetimeNotifier()

template<typename T >
template<std::invocable Functor>
void Qx::AbstractBindableProperty< T >::addLifetimeNotifier ( Functor && f) const
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.

Warning
Be sure that any data referenced in f lives as long as the property itself.
See also
addNotifier() and subscribeLifetime().

◆ addNotifier()

template<typename T >
template<std::invocable Functor>
PropertyNotifier Qx::AbstractBindableProperty< T >::addNotifier ( Functor && f) const
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.

See also
addLifetimeNotifier() and subscribe().

◆ binding()

template<typename T >
PropertyBinding< T > Qx::AbstractBindableProperty< T >::binding ( ) const
inline

Returns the binding expression that is associated with this property. A default constructed PropertyBinding will be returned if no such association exists.

◆ hasBinding()

template<typename T >
bool Qx::AbstractBindableProperty< T >::hasBinding ( ) const
inline

Returns true if the property has a binding associated with it; otherwise, returns false.

◆ operator const T &()

template<typename T >
Qx::AbstractBindableProperty< T >::operator const T & ( ) const
inline

Type-conversion operator for a const reference to the underlying type.

◆ operator*()

template<typename T >
const T & Qx::AbstractBindableProperty< T >::operator* ( ) const
inline

Same as value().

◆ operator->()

template<typename T >
const T * Qx::AbstractBindableProperty< T >::operator-> ( ) const
inline

Returns a pointer to the underlying property data (bindings are still respected).

See also
value().

◆ operator=()

template<typename T >
AbstractBindableProperty & Qx::AbstractBindableProperty< T >::operator= ( AbstractBindableProperty< T > && other)
protecteddefaultnoexcept

Move-assigns an AbstractBindableProperty using other.

◆ removeBinding()

template<typename T >
void Qx::AbstractBindableProperty< T >::removeBinding ( )
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.

See also
takeBinding() and setBinding().

◆ setBinding() [1/2]

template<typename T >
PropertyBinding< T > Qx::AbstractBindableProperty< T >::setBinding ( const PropertyBinding< T > & binding)
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.

◆ setBinding() [2/2]

template<typename T >
template<std::invocable Functor>
PropertyBinding< T > Qx::AbstractBindableProperty< T >::setBinding ( Functor && f)
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.

◆ setValue() [1/2]

template<typename T >
void Qx::AbstractBindableProperty< T >::setValue ( const T & newValue)
inline

Assigns newValue to this property and removes the property's associated binding, if present.

See also
binding() and beginPropertyUpdateGroup().

◆ setValue() [2/2]

template<typename T >
void Qx::AbstractBindableProperty< T >::setValue ( T && newValue)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ setValueBypassingBindings() [1/2]

template<typename T >
void Qx::AbstractBindableProperty< T >::setValueBypassingBindings ( const T & v)
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.

Note
Using this method will bypass any potential binding registered for this property.

◆ setValueBypassingBindings() [2/2]

template<typename T >
void Qx::AbstractBindableProperty< T >::setValueBypassingBindings ( T && v)
pure virtual

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.

Note
Using this method will bypass any potential binding registered for this property.

Implemented in Qx::Property< T >.

◆ subscribe()

template<typename T >
template<std::invocable Functor>
PropertyNotifier Qx::AbstractBindableProperty< T >::subscribe ( Functor && f) const
inline

Same as invoking f (e.g. f()), followed by addNotifier(f).

That is, the callback functor is called immediately before it's registered.

See also
subscribeLifetime() and addNotifier().

◆ subscribeLifetime()

template<typename T >
template<std::invocable Functor>
void Qx::AbstractBindableProperty< T >::subscribeLifetime ( Functor && f) const
inline

Same as invoking f (e.g. f()), followed by addLifetimeNotifier(f).

That is, the callback functor is called immediately before it's registered.

See also
subscribe() and addLifetimeNotifier().

◆ takeBinding()

template<typename T >
PropertyBinding< T > Qx::AbstractBindableProperty< T >::takeBinding ( )
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.

See also
removeBinding() and setBinding().

◆ value()

template<typename T >
const T & Qx::AbstractBindableProperty< T >::value ( ) const
inline

Returns the value of the property. This may evaluate a binding expression that is tied to this property, before returning the value.

See also
value().

◆ valueBypassingBindings()

template<typename T >
const T & Qx::AbstractBindableProperty< T >::valueBypassingBindings ( ) const
pure virtual

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.

Note
Using this method will not register the property access with any currently executing binding.

Implemented in Qx::Property< T >.


The documentation for this class was generated from the following files: