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
QModelRoleData Class Reference

\inmodule QtCore More...

#include <qabstractitemmodel.h>

+ Collaboration diagram for QModelRoleData:

Public Member Functions

 QModelRoleData (int role) noexcept
 Constructs a QModelRoleData object for the given role.
 
constexpr int role () const noexcept
 Returns the role held by this object.
 
constexpr QVariantdata () noexcept
 Returns the data held by this object as a modifiable reference.
 
constexpr const QVariantdata () const noexcept
 Returns the data held by this object.
 
template<typename T >
constexpr void setData (T &&value) noexcept(noexcept(m_data.setValue(std::forward< T >(value))))
 Sets the data held by this object to value.
 
void clearData () noexcept
 Clears the data held by this object.
 

Detailed Description

\inmodule QtCore

Since
6.0

The QModelRoleData class holds a role and the data associated to that role.

QModelRoleData objects store an item role (which is a value from the Qt::ItemDataRole enumeration, or an arbitrary integer for a custom role) as well as the data associated with that role.

A QModelRoleData object is typically created by views or delegates, setting which role they want to fetch the data for. The object is then passed to models (see QAbstractItemModel::multiData()), which populate the data corresponding to the role stored. Finally, the view visualizes the data retrieved from the model.

See also
{Model/View Programming}, QModelRoleDataSpan

Definition at line 17 of file qabstractitemmodel.h.

Constructor & Destructor Documentation

◆ QModelRoleData()

QModelRoleData::QModelRoleData ( int role)
inlineexplicitnoexcept

Constructs a QModelRoleData object for the given role.

See also
Qt::ItemDataRole

Definition at line 23 of file qabstractitemmodel.h.

Member Function Documentation

◆ clearData()

void QModelRoleData::clearData ( )
inlinenoexcept

Clears the data held by this object.

Note that the role is unchanged; only the data is cleared.

See also
data()

Definition at line 35 of file qabstractitemmodel.h.

References m_data.

◆ data() [1/2]

const QVariant & QModelRoleData::data ( ) const
inlineconstexprnoexcept

Returns the data held by this object.

See also
setData()

Definition at line 29 of file qabstractitemmodel.h.

References m_data.

◆ data() [2/2]

QVariant & QModelRoleData::data ( )
inlineconstexprnoexcept

Returns the data held by this object as a modifiable reference.

See also
setData()

Definition at line 28 of file qabstractitemmodel.h.

References m_data.

◆ role()

int QModelRoleData::role ( ) const
inlineconstexprnoexcept

Returns the role held by this object.

See also
Qt::ItemDataRole

Definition at line 27 of file qabstractitemmodel.h.

◆ setData()

template<typename T >
template< typename T > void QModelRoleData::setData ( T && value)
inlineconstexprnoexcept

Sets the data held by this object to value.

value must be of a datatype which can be stored in a QVariant.

See also
data(), clearData(), Q_DECLARE_METATYPE

Definition at line 32 of file qabstractitemmodel.h.

References m_data.


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