![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore More...
#include <qabstractitemmodel.h>
Collaboration diagram for QModelRoleDataSpan:Public Member Functions | |
| constexpr | QModelRoleDataSpan () noexcept |
| Constructs an empty QModelRoleDataSpan. | |
| constexpr | QModelRoleDataSpan (QModelRoleData &modelRoleData) noexcept |
| Constructs an QModelRoleDataSpan spanning over modelRoleData, seen as a 1-element array. | |
| constexpr | QModelRoleDataSpan (QModelRoleData *modelRoleData, qsizetype len) |
| Constructs an QModelRoleDataSpan spanning over the array beginning at modelRoleData and with length len. | |
| template<typename Container , if_compatible_container< Container > = true> | |
| constexpr | QModelRoleDataSpan (Container &c) noexcept(noexcept(std::data(c)) &&noexcept(std::size(c))) |
| Constructs an QModelRoleDataSpan spanning over the container c, which can be any contiguous container of QModelRoleData objects. | |
| constexpr qsizetype | size () const noexcept |
| Returns the length of the span represented by this object. | |
| constexpr qsizetype | length () const noexcept |
| Returns the length of the span represented by this object. | |
| constexpr QModelRoleData * | data () const noexcept |
| Returns a pointer to the beginning of the span represented by this object. | |
| constexpr QModelRoleData * | begin () const noexcept |
| Returns a pointer to the beginning of the span represented by this object. | |
| constexpr QModelRoleData * | end () const noexcept |
| Returns a pointer to the imaginary element one past the end of the span represented by this object. | |
| constexpr QModelRoleData & | operator[] (qsizetype index) const |
| Returns a modifiable reference to the QModelRoleData at position index in the span. | |
| constexpr QVariant * | dataForRole (int role) const |
| Returns the data associated with the first QModelRoleData in the span that has its role equal to role. | |
\inmodule QtCore
The QModelRoleDataSpan class provides a span over QModelRoleData objects.
A QModelRoleDataSpan is used as an abstraction over an array of QModelRoleData objects.
Like a view, QModelRoleDataSpan provides a small object (pointer and size) that can be passed to functions that need to examine the contents of the array. A QModelRoleDataSpan can be constructed from any array-like sequence (plain arrays, QVector, std::vector, QVarLengthArray, and so on). Moreover, it does not own the sequence, which must therefore be kept alive longer than any QModelRoleDataSpan objects referencing it.
Unlike a view, QModelRoleDataSpan is a span, so it allows for modifications to the underlying elements.
QModelRoleDataSpan's main use case is making it possible for a model to return the data corresponding to different roles in one call.
In order to draw one element from a model, a view (through its delegates) will generally request multiple roles for the same index by calling {data()} as many times as needed:
QModelRoleDataSpan allows a view to request the same data using just one function call.
This is achieved by having the view prepare a suitable array of QModelRoleData objects, each initialized with the role that should be fetched. The array is then wrapped in a QModelRoleDataSpan object, which is then passed to a model's {multiData()} function.
Views are encouraged to store the array of QModelRoleData objects (and, possibly, the corresponding span) and re-use it in subsequent calls to the model. This allows to reduce the memory allocations related with creating and returning QVariant objects.
Finally, given a QModelRoleDataSpan object, the model's responsibility is to fill in the data corresponding to each role in the span. How this is done depends on the concrete model class. Here's a sketch of a possible implementation that iterates over the span and uses {setData()} on each element:
Definition at line 65 of file qabstractitemmodel.h.
|
inlineconstexprnoexcept |
Constructs an empty QModelRoleDataSpan.
Its data() will be set to \nullptr, and its length to zero.
Definition at line 74 of file qabstractitemmodel.h.
|
inlineconstexprnoexcept |
Constructs an QModelRoleDataSpan spanning over modelRoleData, seen as a 1-element array.
Definition at line 76 of file qabstractitemmodel.h.
|
inlineconstexpr |
Constructs an QModelRoleDataSpan spanning over the array beginning at modelRoleData and with length len.
Definition at line 81 of file qabstractitemmodel.h.
|
inlineconstexprnoexcept |
Constructs an QModelRoleDataSpan spanning over the container c, which can be any contiguous container of QModelRoleData objects.
For instance, it can be a {QVector<QModelRoleData>}, a {std::array<QModelRoleData, 10>} and so on.
Definition at line 87 of file qabstractitemmodel.h.
|
inlineconstexprnoexcept |
Returns a pointer to the beginning of the span represented by this object.
Definition at line 95 of file qabstractitemmodel.h.
Referenced by dataForRole().
Here is the caller graph for this function:
|
inlineconstexprnoexcept |
Returns a pointer to the beginning of the span represented by this object.
Definition at line 94 of file qabstractitemmodel.h.
|
inlineconstexpr |
Returns the data associated with the first QModelRoleData in the span that has its role equal to role.
If such a QModelRoleData object does not exist, the behavior is undefined.
Definition at line 99 of file qabstractitemmodel.h.
References begin(), e, end(), Q_ASSERT, and roleData.
Referenced by QStyledItemDelegate::initStyleOption().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inlineconstexprnoexcept |
Returns a pointer to the imaginary element one past the end of the span represented by this object.
Definition at line 96 of file qabstractitemmodel.h.
Referenced by dataForRole().
Here is the caller graph for this function:
|
inlineconstexprnoexcept |
Returns the length of the span represented by this object.
Definition at line 93 of file qabstractitemmodel.h.
|
inlineconstexpr |
Returns a modifiable reference to the QModelRoleData at position index in the span.
Definition at line 97 of file qabstractitemmodel.h.
|
inlineconstexprnoexcept |
Returns the length of the span represented by this object.
Definition at line 92 of file qabstractitemmodel.h.