Qt 6.x
The Qt SDK
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/private/qtguiglobal_p.h>
19#include "private/qabstractitemmodel_p.h"
20
21#include <QtCore/qlist.h>
22#include <QtCore/qpair.h>
23#include <QtCore/qstack.h>
24#include <QtCore/qvariant.h>
25#include <QtCore/qdebug.h>
26
27QT_REQUIRE_CONFIG(standarditemmodel);
28
30
32{
33public:
34 inline QStandardItemData() : role(-1) {}
35 inline QStandardItemData(int r, const QVariant &v) :
36 role(r == Qt::EditRole ? Qt::DisplayRole : r), value(v) {}
37 inline QStandardItemData(const std::pair<const int&, const QVariant&> &p) :
38 role(p.first == Qt::EditRole ? Qt::DisplayRole : p.first), value(p.second) {}
39 int role;
41 inline bool operator==(const QStandardItemData &other) const { return role == other.role && value == other.value; }
42};
44
45#ifndef QT_NO_DATASTREAM
46
48{
49 in >> data.role;
50 in >> data.value;
51 return in;
52}
53
55{
56 out << data.role;
57 out << data.value;
58 return out;
59}
60
62{
64 debug.nospace() << data.role
65 << " "
66 << data.value;
67 return debug.space();
68}
69
70#endif // QT_NO_DATASTREAM
71
73{
74 Q_DECLARE_PUBLIC(QStandardItem)
75public:
77 : model(nullptr),
79 rows(0),
80 columns(0),
83 { }
84
85 inline int childIndex(int row, int column) const {
86 if ((row < 0) || (column < 0)
87 || (row >= rowCount()) || (column >= columnCount())) {
88 return -1;
89 }
90 return (row * columnCount()) + column;
91 }
92 inline int childIndex(const QStandardItem *child) const {
93 const int lastChild = children.size() - 1;
94 int &childsLastIndexInParent = child->d_func()->lastKnownIndex;
95 if (childsLastIndexInParent != -1 && childsLastIndexInParent <= lastChild) {
96 if (children.at(childsLastIndexInParent) == child)
97 return childsLastIndexInParent;
98 } else {
99 childsLastIndexInParent = lastChild / 2;
100 }
101
102 // assuming the item is in the vicinity of the previous index, iterate forwards and
103 // backwards through the children
104 int backwardIter = childsLastIndexInParent - 1;
105 int forwardIter = childsLastIndexInParent;
106 for (;;) {
107 if (forwardIter <= lastChild) {
108 if (children.at(forwardIter) == child) {
109 childsLastIndexInParent = forwardIter;
110 break;
111 }
112 ++forwardIter;
113 } else if (backwardIter < 0) {
114 childsLastIndexInParent = -1;
115 break;
116 }
117 if (backwardIter >= 0) {
118 if (children.at(backwardIter) == child) {
119 childsLastIndexInParent = backwardIter;
120 break;
121 }
122 --backwardIter;
123 }
124 }
125 return childsLastIndexInParent;
126 }
128 void setChild(int row, int column, QStandardItem *item,
129 bool emitChanged = false);
130 inline int rowCount() const {
131 return rows;
132 }
133 inline int columnCount() const {
134 return columns;
135 }
137
138 void setModel(QStandardItemModel *mod);
139
140 inline void setParentAndModel(
141 QStandardItem *par,
142 QStandardItemModel *mod) {
143 setModel(mod);
144 parent = par;
145 }
146
147 void changeFlags(bool enable, Qt::ItemFlags f);
148 void setItemData(const QMap<int, QVariant> &roles);
150
151 bool insertRows(int row, int count, const QList<QStandardItem*> &items);
152 bool insertRows(int row, const QList<QStandardItem*> &items);
154
156
161 int rows;
163
165
166 mutable int lastKnownIndex; // this is a cached value
167};
168
170{
171 Q_DECLARE_PUBLIC(QStandardItemModel)
172
173public:
176
177 void init();
178
179 inline QStandardItem *createItem() const {
181 }
182
184 Q_Q(const QStandardItemModel);
185 if (!index.isValid())
186 return root.data();
187 if (index.model() != q)
188 return nullptr;
189 QStandardItem *parent = static_cast<QStandardItem*>(index.internalPointer());
190 if (parent == nullptr)
191 return nullptr;
192 return parent->child(index.row(), index.column());
193 }
194
196 void itemChanged(QStandardItem *item, const QList<int> &roles = QList<int>());
201 void rowsInserted(QStandardItem *parent, int row, int count);
203 void rowsRemoved(QStandardItem *parent, int row, int count);
205
206 void _q_emitItemChanged(const QModelIndex &topLeft,
207 const QModelIndex &bottomRight);
208
210
217};
218
220
221#endif // QSTANDARDITEMMODEL_P_H
\inmodule QtCore\reentrant
Definition qdatastream.h:30
\inmodule QtCore
\inmodule QtCore
\inmodule QtCore
Definition qhash.h:818
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
Definition qmap.h:186
\inmodule QtCore
QObject * parent
Definition qobject.h:61
\inmodule QtCore
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:64
Combined button and popup list for selecting options.
@ DisplayRole
SortOrder
Definition qnamespace.h:120
std::pair< T1, T2 > QPair
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
GLfloat GLfloat f
GLboolean enable
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
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:1264
QDataStream & operator>>(QDataStream &in, QStandardItemData &data)
QDataStream & operator<<(QDataStream &out, const QStandardItemData &data)
#define QT_REQUIRE_CONFIG(feature)
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:145
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:163
QTextStream out(stdout)
[7]
QObject::connect nullptr
QSharedPointer< T > other(t)
[5]
QGraphicsItem * item
QList< QTreeWidgetItem * > items
QLayoutItem * child
[0]