Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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:
bool hasClientsActualCalculation() const { return clients.size() > 0; }
};
class MyClass : public QObject
{
Q_PROPERTY(bool hasClients READ hasClients STORED false BINDABLE bindableHasClients)
public:
{
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()
\inmodule QtCore
Definition qproperty.h:812
QPropertyBinding< T > setBinding(const QPropertyBinding< T > &binding)
Sets the underlying property's binding to binding.
Definition qproperty.h:849
qsizetype size() const noexcept
Definition qlist.h:399
\inmodule QtCore
Definition qproperty.h:352
bool hasBinding() const
Returns true if the underlying property has a binding.
Definition qproperty.h:788
GLuint GLfloat * val
#define Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(...)
Definition qproperty.h:1267
#define Q_OBJECT_COMPUTED_PROPERTY(Class, Type, name, ...)
Definition qproperty.h:1356
#define Q_OBJECT_BINDABLE_PROPERTY(...)
Definition qproperty.h:1240

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 1273 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 1288 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 1287 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 1335 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 1341 of file qproperty.h.

◆ hasBinding()

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

Definition at line 1317 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 1347 of file qproperty.h.

◆ 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 1320 of file qproperty.h.

◆ 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 1312 of file qproperty.h.

◆ operator*()

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

Definition at line 1307 of file qproperty.h.

◆ 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 1299 of file qproperty.h.

◆ 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 1327 of file qproperty.h.

◆ value()

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

Definition at line 1292 of file qproperty.h.

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: