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
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 QVariant & data () noexcept
 Returns the data held by this object as a modifiable reference.
constexpr const QVariant & data () 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 21 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 27 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 39 of file qabstractitemmodel.h.

◆ data() [1/2]

const QVariant & QModelRoleData::data ( ) const
inlineconstexprnoexcept

Returns the data held by this object.

See also
setData()

Definition at line 33 of file qabstractitemmodel.h.

◆ data() [2/2]

QVariant & QModelRoleData::data ( )
inlineconstexprnoexcept

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

See also
setData()

Definition at line 32 of file qabstractitemmodel.h.

◆ role()

int QModelRoleData::role ( ) const
inlineconstexprnoexcept

Returns the role held by this object.

See also
Qt::ItemDataRole

Definition at line 31 of file qabstractitemmodel.h.

Referenced by QModelRoleDataSpan::dataForRole().

Here is the caller graph for this function:

◆ setData()

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 36 of file qabstractitemmodel.h.


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