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
src_corelib_kernel_qabstractitemmodel.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4//! [0]
5beginInsertRows(parent, 2, 4);
6//! [0]
7
8
9//! [1]
10beginInsertRows(parent, 4, 5);
11//! [1]
12
13
14//! [2]
15beginRemoveRows(parent, 2, 3);
16//! [2]
17
18
19//! [3]
20beginInsertColumns(parent, 4, 6);
21//! [3]
22
23
24//! [4]
25beginInsertColumns(parent, 6, 8);
26//! [4]
27
28
29//! [5]
30beginRemoveColumns(parent, 4, 6);
31//! [5]
32
33
34//! [6]
35beginMoveRows(sourceParent, 2, 4, destinationParent, 2);
36//! [6]
37
38
39//! [7]
40beginMoveRows(sourceParent, 2, 4, destinationParent, 6);
41//! [7]
42
43
44//! [8]
45beginMoveRows(parent, 2, 2, parent, 0);
46//! [8]
47
48
49//! [9]
50beginMoveRows(parent, 2, 2, parent, 4);
51//! [9]
52
53
54//! [12]
56{
58public:
63
64 ...
65
75
76private slots:
78 {
80 }
81
82private:
84};
85//! [12]
86
87//! [13]
88QVariant text = model->data(index, Qt::DisplayRole);
89QVariant decoration = model->data(index, Qt::DecorationRole);
90QVariant checkState = model->data(index, Qt::CheckStateRole);
91// etc.
92//! [13]
93
94//! [14]
96 QModelRoleData(Qt::DisplayRole),
97 QModelRoleData(Qt::DecorationRole),
98 QModelRoleData(Qt::CheckStateRole)
99} };
100
101// Usually, this is not necessary: A QModelRoleDataSpan
102// will be built automatically for you when passing an array-like
103// container to multiData().
105
106model->multiData(index, span);
107
108// Use roleData[0].data(), roleData[1].data(), etc.
109//! [14]
110
111//! [15]
112void MyModel::multiData(const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const
113{
114 for (QModelRoleData &roleData : roleDataSpan) {
115 int role = roleData.role();
116
117 // ... obtain the data for index and role ...
118
119 roleData.setData(result);
120 }
121}
122//! [15]
123
124//! [16]
125QVariant MyModel::data(const QModelIndex &index, int role) const
126{
127 QModelRoleData roleData(role);
128 multiData(index, roleData);
129 return roleData.data();
130}
131//! [16]
beginInsertRows(parent, 2, 4)
[0]
QModelRoleDataSpan span(roleData)
std::array< QModelRoleData, 3 > roleData
[13]
beginMoveRows(sourceParent, 2, 4, destinationParent, 2)
[5]
beginInsertColumns(parent, 4, 6)
[2]
beginRemoveColumns(parent, 4, 6)
[4]
beginRemoveRows(parent, 2, 3)
[1]