Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QObjectComputedProperty< Class, T, Offset, Getter > Class Template Reference

\macro Q_OBJECT_COMPAT_PROPERTY(containingClass, type, name, callback) More...

#include <qproperty.h>

+ Inheritance diagram for QObjectComputedProperty< Class, T, Offset, Getter >:
+ Collaboration diagram for QObjectComputedProperty< Class, T, Offset, Getter >:

Public Types

using value_type = T
 
using parameter_type = T
 

Public Member Functions

 QObjectComputedProperty ()=default
 
parameter_type value () const
 
std::conditional_t< QTypeTraits::is_dereferenceable_v< T >, parameter_type, voidoperator-> () const
 
parameter_type operator* () const
 
 operator parameter_type () const
 
constexpr bool hasBinding () const
 
template<typename Functor >
QPropertyChangeHandler< FunctoronValueChanged (Functor f)
 
template<typename Functor >
QPropertyChangeHandler< Functorsubscribe (Functor f)
 
template<typename Functor >
QPropertyNotifier addNotifier (Functor f)
 
QtPrivate::QPropertyBindingDatabindingData () const
 
void notify ()
 

Related Symbols

(Note that these are not member symbols.)

template< typename Class, typename T, auto offset, auto CallbackQObjectBindableProperty ()
 \macro Q_OBJECT_COMPUTED_PROPERTY(containingClass, type, name, callback)
 

Detailed Description

template<typename Class, typename T, auto Offset, auto Getter>
class QObjectComputedProperty< Class, T, Offset, Getter >

\macro Q_OBJECT_COMPAT_PROPERTY(containingClass, type, name, callback)

Since
6.0

Declares a \l QObjectCompatProperty inside containingClass of type type with name name. The argument callback specifies a setter function to be called when the property is changed through the binding.

See also
QObjectBindableProperty, {Qt's Property System}, {Qt Bindable Properties}

\macro Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(containingClass, type, name, callback, value)

Since
6.0

Declares a \l QObjectCompatProperty inside of containingClass of type type with name name. The argument callback specifies a setter function to be called when the property is changed through the binding. value specifies an initialization value.

\inmodule QtCore

The QObjectComputedProperty class is a template class to help port old properties to the bindable property system.

Since
6.0

QObjectComputedProperty is a read-only property which is recomputed on each read. It does not store the computed value. It is one of the Qt internal classes implementing \l {Qt Bindable Properties}. QObjectComputedProperty is usually not used directly, instead an instance of it is created by using the Q_OBJECT_COMPUTED_PROPERTY macro.

See the following example.

class Client{};
{
public:
QList<Client> clients;
bool hasClientsActualCalculation() const { return clients.size() > 0; }
};
class MyClass : public QObject
{
Q_PROPERTY(bool hasClients READ hasClients STORED false BINDABLE bindableHasClients)
public:
QBindable<bool> bindableHasClients()
{
return QBindable<bool>(&d_func()->hasClientsData);
}
bool hasClients() const
{
return d_func()->hasClientsData.value();
}
void addClient(const Client &c)
{
Q_D(MyClass);
d->clients.push_back(c);
// notify that the value could have changed
d->hasClientsData.notify();
}
private:
Q_DECLARE_PRIVATE(MyClass)
};
CustomType(int val, int otherVal)
void setMyVal(int newvalue)
void myValChanged()
QBindable< int > bindableMyVal()
void addClient(const Client &c)
QBindable< int > bindableX()
QBindable< bool > bindableHasClients()
void xChanged()
qsizetype size() const noexcept
Definition qlist.h:397
GLuint GLfloat * val
#define Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(...)
Definition qproperty.h:1266
#define Q_OBJECT_COMPUTED_PROPERTY(Class, Type, name, ...)
Definition qproperty.h:1355
#define Q_OBJECT_BINDABLE_PROPERTY(...)
Definition qproperty.h:1239

The rules for getters in \l {Bindable Property Getters and Setters} also apply for QObjectComputedProperty. Especially, the getter should be trivial and only return the value of the QObjectComputedProperty object. The callback given to the QObjectComputedProperty should usually be a private method which is only called by the QObjectComputedProperty.

No setter is required or allowed, as QObjectComputedProperty is read-only.

To correctly participate in dependency handling, QObjectComputedProperty has to know when its value, the result of the callback given to it, might have changed. Whenever a bindable property used in the callback changes, this happens automatically. If the result of the callback might change because of a change in a value which is not a bindable property, it is the developer's responsibility to call notify on the QObjectComputedProperty object. This will inform dependent properties about the potential change.

Note that calling notify might trigger change handlers in dependent properties, which might in turn use the object the QObjectComputedProperty is a member of. So notify must not be called when in a transitional or invalid state.

QObjectComputedProperty is not suitable for use with a computation that depends on any input that might change without notice, such as the contents of a file.

See also
Q_OBJECT_COMPUTED_PROPERTY, QProperty, QObjectBindableProperty, {Qt's Property System}, {Qt Bindable Properties}

Definition at line 1272 of file qproperty.h.

Member Typedef Documentation

◆ parameter_type

template<typename Class , typename T , auto Offset, auto Getter>
using QObjectComputedProperty< Class, T, Offset, Getter >::parameter_type = T

Definition at line 1287 of file qproperty.h.

◆ value_type

template<typename Class , typename T , auto Offset, auto Getter>
using QObjectComputedProperty< Class, T, Offset, Getter >::value_type = T

Definition at line 1286 of file qproperty.h.

Constructor & Destructor Documentation

◆ QObjectComputedProperty()

template<typename Class , typename T , auto Offset, auto Getter>
QObjectComputedProperty< Class, T, Offset, Getter >::QObjectComputedProperty ( )
default

Member Function Documentation

◆ addNotifier()

template<typename Class , typename T , auto Offset, auto Getter>
template<typename Functor >
QPropertyNotifier QObjectComputedProperty< Class, T, Offset, Getter >::addNotifier ( Functor f)
inline

Definition at line 1334 of file qproperty.h.

◆ bindingData()

template<typename Class , typename T , auto Offset, auto Getter>
QtPrivate::QPropertyBindingData & QObjectComputedProperty< Class, T, Offset, Getter >::bindingData ( ) const
inline

Definition at line 1340 of file qproperty.h.

References qGetBindingStorage(), and storage.

+ Here is the call graph for this function:

◆ hasBinding()

template<typename Class , typename T , auto Offset, auto Getter>
constexpr bool QObjectComputedProperty< Class, T, Offset, Getter >::hasBinding ( ) const
inlineconstexpr

Definition at line 1316 of file qproperty.h.

◆ notify()

template<typename Class , typename T , auto Offset, auto Getter>
void QObjectComputedProperty< Class, T, Offset, Getter >::notify ( )
inline

Definition at line 1346 of file qproperty.h.

References qGetBindingStorage(), and storage.

+ Here is the call graph for this function:

◆ onValueChanged()

template<typename Class , typename T , auto Offset, auto Getter>
template<typename Functor >
QPropertyChangeHandler< Functor > QObjectComputedProperty< Class, T, Offset, Getter >::onValueChanged ( Functor f)
inline

Definition at line 1319 of file qproperty.h.

Referenced by QObjectComputedProperty< Class, T, Offset, Getter >::subscribe().

+ Here is the caller graph for this function:

◆ operator parameter_type()

template<typename Class , typename T , auto Offset, auto Getter>
QObjectComputedProperty< Class, T, Offset, Getter >::operator parameter_type ( ) const
inline

Definition at line 1311 of file qproperty.h.

References QObjectComputedProperty< Class, T, Offset, Getter >::value().

+ Here is the call graph for this function:

◆ operator*()

template<typename Class , typename T , auto Offset, auto Getter>
parameter_type QObjectComputedProperty< Class, T, Offset, Getter >::operator* ( ) const
inline

Definition at line 1306 of file qproperty.h.

References QObjectComputedProperty< Class, T, Offset, Getter >::value().

+ Here is the call graph for this function:

◆ operator->()

template<typename Class , typename T , auto Offset, auto Getter>
std::conditional_t< QTypeTraits::is_dereferenceable_v< T >, parameter_type, void > QObjectComputedProperty< Class, T, Offset, Getter >::operator-> ( ) const
inline

Definition at line 1298 of file qproperty.h.

References QObjectComputedProperty< Class, T, Offset, Getter >::value().

+ Here is the call graph for this function:

◆ subscribe()

template<typename Class , typename T , auto Offset, auto Getter>
template<typename Functor >
QPropertyChangeHandler< Functor > QObjectComputedProperty< Class, T, Offset, Getter >::subscribe ( Functor f)
inline

Definition at line 1326 of file qproperty.h.

References QObjectComputedProperty< Class, T, Offset, Getter >::onValueChanged().

+ Here is the call graph for this function:

◆ value()

template<typename Class , typename T , auto Offset, auto Getter>
parameter_type QObjectComputedProperty< Class, T, Offset, Getter >::value ( ) const
inline

Definition at line 1291 of file qproperty.h.

References qGetBindingStorage(), and QBindingStorage::registerDependency().

Referenced by QObjectComputedProperty< Class, T, Offset, Getter >::operator parameter_type(), QObjectComputedProperty< Class, T, Offset, Getter >::operator*(), and QObjectComputedProperty< Class, T, Offset, Getter >::operator->().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ QObjectBindableProperty()

template<typename Class , typename T , auto Offset, auto Getter>
template< typename Class, typename T, auto offset, auto Callback > QObjectBindableProperty ( )
related

\macro Q_OBJECT_COMPUTED_PROPERTY(containingClass, type, name, callback)

Since
6.0

Declares a \l QObjectComputedProperty inside containingClass of type type with name name. The argument callback specifies a GETTER function to be called when the property is evaluated.

See also
QObjectBindableProperty, {Qt's Property System}, {Qt Bindable Properties}

Constructs a property with a default constructed instance of T.


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