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
qstandarditemmodel_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QSTANDARDITEMMODEL_P_H
5#define QSTANDARDITEMMODEL_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtGui/qstandarditemmodel.h>
19
20#include <QtGui/private/qtguiglobal_p.h>
21#include "private/qabstractitemmodel_p.h"
22
23#include <QtCore/qlist.h>
24#include <QtCore/qpair.h>
25#include <QtCore/qstack.h>
26#include <QtCore/qvariant.h>
27#include <QtCore/qdebug.h>
28
29QT_REQUIRE_CONFIG(standarditemmodel);
30
32
34{
35public:
36 inline QStandardItemData() : role(-1) {}
37 inline QStandardItemData(int r, const QVariant &v) :
38 role(r == Qt::EditRole ? Qt::DisplayRole : r), value(v) {}
39 inline QStandardItemData(const std::pair<const int&, const QVariant&> &p) :
40 role(p.first == Qt::EditRole ? Qt::DisplayRole : p.first), value(p.second) {}
41 int role;
43 inline bool operator==(const QStandardItemData &other) const { return role == other.role && value == other.value; }
44};
46
47#ifndef QT_NO_DATASTREAM
48
50{
51 in >> data.role;
52 in >> data.value;
53 return in;
54}
55
57{
58 out << data.role;
59 out << data.value;
60 return out;
61}
62
64{
66 debug.nospace() << data.role
67 << " "
68 << data.value;
69 return debug.space();
70}
71
72#endif // QT_NO_DATASTREAM
73
75{
76 Q_DECLARE_PUBLIC(QStandardItem)
77public:
79 : model(nullptr),
81 rows(0),
82 columns(0),
85 { }
86
87 inline int childIndex(int row, int column) const {
88 if ((row < 0) || (column < 0)
89 || (row >= rowCount()) || (column >= columnCount())) {
90 return -1;
91 }
92 return (row * columnCount()) + column;
93 }
94 inline int childIndex(const QStandardItem *child) const {
95 const int lastChild = children.size() - 1;
96 int &childsLastIndexInParent = child->d_func()->lastKnownIndex;
97 if (childsLastIndexInParent != -1 && childsLastIndexInParent <= lastChild) {
98 if (children.at(childsLastIndexInParent) == child)
99 return childsLastIndexInParent;
100 } else {
101 childsLastIndexInParent = lastChild / 2;
102 }
103
104 // assuming the item is in the vicinity of the previous index, iterate forwards and
105 // backwards through the children
106 int backwardIter = childsLastIndexInParent - 1;
107 int forwardIter = childsLastIndexInParent;
108 for (;;) {
109 if (forwardIter <= lastChild) {
110 if (children.at(forwardIter) == child) {
111 childsLastIndexInParent = forwardIter;
112 break;
113 }
114 ++forwardIter;
115 } else if (backwardIter < 0) {
116 childsLastIndexInParent = -1;
117 break;
118 }
119 if (backwardIter >= 0) {
120 if (children.at(backwardIter) == child) {
121 childsLastIndexInParent = backwardIter;
122 break;
123 }
124 --backwardIter;
125 }
126 }
127 return childsLastIndexInParent;
128 }
129 QPair<int, int> position() const;
130 void setChild(int row, int column, QStandardItem *item,
131 bool emitChanged = false);
132 inline int rowCount() const {
133 return rows;
134 }
135 inline int columnCount() const {
136 return columns;
137 }
139
140 void setModel(QStandardItemModel *mod);
141
142 inline void setParentAndModel(
143 QStandardItem *par,
144 QStandardItemModel *mod) {
145 setModel(mod);
146 parent = par;
147 }
148
149 void changeFlags(bool enable, Qt::ItemFlags f);
150 void setItemData(const QMap<int, QVariant> &roles);
151 QMap<int, QVariant> itemData() const;
152
153 bool insertRows(int row, int count, const QList<QStandardItem*> &items);
154 bool insertRows(int row, const QList<QStandardItem*> &items);
155 bool insertColumns(int column, int count, const QList<QStandardItem*> &items);
156
158
161 QList<QStandardItemData> values;
162 QList<QStandardItem *> children;
163 int rows;
165
167
168 mutable int lastKnownIndex; // this is a cached value
169};
170
172{
173 Q_DECLARE_PUBLIC(QStandardItemModel)
174
175public:
178
179 void init();
180
181 inline QStandardItem *createItem() const {
183 }
184
186 Q_Q(const QStandardItemModel);
187 if (!index.isValid())
188 return root.data();
189 if (index.model() != q)
190 return nullptr;
191 QStandardItem *parent = static_cast<QStandardItem*>(index.internalPointer());
192 if (parent == nullptr)
193 return nullptr;
194 return parent->child(index.row(), index.column());
195 }
196
198 void itemChanged(QStandardItem *item, const QList<int> &roles = QList<int>());
203 void rowsInserted(QStandardItem *parent, int row, int count);
205 void rowsRemoved(QStandardItem *parent, int row, int count);
207
208 void _q_emitItemChanged(const QModelIndex &topLeft,
209 const QModelIndex &bottomRight);
210
212
213 QList<QStandardItem *> columnHeaderItems;
214 QList<QStandardItem *> rowHeaderItems;
215 QHash<int, QByteArray> roleNames;
216 QScopedPointer<QStandardItem> root;
219};
220
222
223#endif // QSTANDARDITEMMODEL_P_H
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore
\inmodule QtCore
qsizetype size() const noexcept
Definition qlist.h:397
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
\inmodule QtCore
QObject * parent
Definition qobject.h:73
T * data() const noexcept
Returns the value of the pointer referenced by this object.
QStandardItemData(int r, const QVariant &v)
bool operator==(const QStandardItemData &other) const
QStandardItemData(const std::pair< const int &, const QVariant & > &p)
void sort(QStandardItem *parent, int column, Qt::SortOrder order)
QList< QStandardItem * > rowHeaderItems
void rowsAboutToBeRemoved(QStandardItem *parent, int start, int end)
QStandardItem * createItem() const
void columnsAboutToBeRemoved(QStandardItem *parent, int start, int end)
void columnsRemoved(QStandardItem *parent, int column, int count)
const QStandardItem * itemPrototype
QStandardItem * itemFromIndex(const QModelIndex &index) const
void columnsInserted(QStandardItem *parent, int column, int count)
void columnsAboutToBeInserted(QStandardItem *parent, int start, int end)
void itemChanged(QStandardItem *item, const QList< int > &roles=QList< int >())
void decodeDataRecursive(QDataStream &stream, QStandardItem *item)
QHash< int, QByteArray > roleNames
void rowsAboutToBeInserted(QStandardItem *parent, int start, int end)
void _q_emitItemChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void rowsRemoved(QStandardItem *parent, int row, int count)
QScopedPointer< QStandardItem > root
QList< QStandardItem * > columnHeaderItems
void rowsInserted(QStandardItem *parent, int row, int count)
The QStandardItemModel class provides a generic model for storing custom data.
void setModel(QStandardItemModel *mod)
bool insertColumns(int column, int count, const QList< QStandardItem * > &items)
QList< QStandardItemData > values
QPair< int, int > position() const
void setItemData(const QMap< int, QVariant > &roles)
int childIndex(int row, int column) const
void setChild(int row, int column, QStandardItem *item, bool emitChanged=false)
QMap< int, QVariant > itemData() const
void childDeleted(QStandardItem *child)
int childIndex(const QStandardItem *child) const
void setParentAndModel(QStandardItem *par, QStandardItemModel *mod)
bool insertRows(int row, int count, const QList< QStandardItem * > &items)
QStandardItemModel * model
void sortChildren(int column, Qt::SortOrder order)
QList< QStandardItem * > children
void changeFlags(bool enable, Qt::ItemFlags f)
The QStandardItem class provides an item for use with the QStandardItemModel class.
virtual QStandardItem * clone() const
Returns a copy of this item.
\inmodule QtCore
Definition qvariant.h:65
Combined button and popup list for selecting options.
Definition qcompare.h:63
@ DisplayRole
SortOrder
Definition qnamespace.h:121
EGLStreamKHR stream
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLsizei const GLfloat * v
[13]
GLuint index
[2]
GLboolean r
[2]
GLuint GLuint end
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat f
GLboolean enable
GLuint start
GLint first
GLenum GLenum GLsizei void GLsizei void * column
GLuint in
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLenum GLenum GLsizei void * row
GLfloat GLfloat p
[1]
GLfixed GLfixed GLint GLint order
#define Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(...)
Definition qproperty.h:1266
QDataStream & operator>>(QDataStream &in, QStandardItemData &data)
QDataStream & operator<<(QDataStream &out, const QStandardItemData &data)
#define QT_REQUIRE_CONFIG(feature)
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:158
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180
QTextStream out(stdout)
[7]
QObject::connect nullptr
QSharedPointer< T > other(t)
[5]
QGraphicsItem * item
QList< QTreeWidgetItem * > items
QLayoutItem * child
[0]