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
qqmltreemodeltotablemodel_p_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 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 QQmlTreeModelToTableModel_H
5#define QQmlTreeModelToTableModel_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 purely as an
12// implementation detail. 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 "qtqmlmodelsglobal_p.h"
19
20#include <QtCore/qset.h>
21#include <QtCore/qpointer.h>
22#include <QtCore/qabstractitemmodel.h>
23#include <QtCore/qitemselectionmodel.h>
24
26
28
29class Q_QMLMODELS_EXPORT QQmlTreeModelToTableModel : public QAbstractItemModel
30{
32 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelChanged FINAL)
33 Q_PROPERTY(QModelIndex rootIndex READ rootIndex WRITE setRootIndex RESET resetRootIndex NOTIFY rootIndexChanged FINAL)
34
35 struct TreeItem;
36
37public:
39
41 QModelIndex rootIndex() const;
42 void setRootIndex(const QModelIndex &idx);
43 void resetRootIndex();
44
45 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
46 QModelIndex parent(const QModelIndex &child) const override;
47
48 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
49 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
50
51 enum {
52 DepthRole = Qt::UserRole - 5,
56 ModelIndexRole
57 };
58
59 QHash<int, QByteArray> roleNames() const override;
60 QVariant data(const QModelIndex &, int role) const override;
61 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
62 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
63 Qt::ItemFlags flags(const QModelIndex &index) const override;
64
65 void clearModelData();
66
67 bool isVisible(const QModelIndex &index);
68 bool childrenVisible(const QModelIndex &index);
69
70 QModelIndex mapToModel(const QModelIndex &index) const;
71 QModelIndex mapFromModel(const QModelIndex &index) const;
72 QModelIndex mapToModel(int row) const;
73
74 Q_INVOKABLE QItemSelection selectionForRowRange(const QModelIndex &fromIndex, const QModelIndex &toIndex) const;
75
76 void showModelTopLevelItems(bool doInsertRows = true);
77 void showModelChildItems(const TreeItem &parent, int start, int end, bool doInsertRows = true, bool doExpandPendingRows = true);
78
79 int itemIndex(const QModelIndex &index) const;
80 void expandPendingRows(bool doInsertRows = true);
81 int lastChildIndex(const QModelIndex &index) const;
82 void removeVisibleRows(int startIndex, int endIndex, bool doRemoveRows = true);
83
84 void dump() const;
85 bool testConsistency(bool dumpOnFail = false) const;
86
88
94
95public Q_SLOTS:
96 void expand(const QModelIndex &);
97 void collapse(const QModelIndex &);
99 bool isExpanded(const QModelIndex &) const;
100 bool isExpanded(int row) const;
101 bool hasChildren(int row) const;
102 bool hasSiblings(int row) const;
103 int depthAtRow(int row) const;
104 void expandRow(int n);
105 void expandRecursively(int row, int depth);
106 void collapseRow(int n);
107 void collapseRecursively(int row);
108
109private Q_SLOTS:
110 void modelHasBeenDestroyed();
111 void modelHasBeenReset();
112 void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
113 void modelLayoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint);
114 void modelLayoutChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint);
115 void modelRowsAboutToBeInserted(const QModelIndex & parent, int start, int end);
116 void modelRowsAboutToBeMoved(const QModelIndex & sourceParent, int sourceStart, int sourceEnd, const QModelIndex & destinationParent, int destinationRow);
117 void modelRowsAboutToBeRemoved(const QModelIndex & parent, int start, int end);
118 void modelRowsInserted(const QModelIndex & parent, int start, int end);
119 void modelRowsMoved(const QModelIndex & sourceParent, int sourceStart, int sourceEnd, const QModelIndex & destinationParent, int destinationRow);
120 void modelRowsRemoved(const QModelIndex & parent, int start, int end);
121 void modelColumnsAboutToBeInserted(const QModelIndex & parent, int start, int end);
122 void modelColumnsAboutToBeRemoved(const QModelIndex & parent, int start, int end);
123 void modelColumnsInserted(const QModelIndex & parent, int start, int end);
124 void modelColumnsRemoved(const QModelIndex & parent, int start, int end);
125
126private:
127 struct TreeItem {
129 int depth;
130 bool expanded;
131
132 explicit TreeItem(const QModelIndex &idx = QModelIndex(), int d = 0, int e = false)
133 : index(idx), depth(d), expanded(e)
134 { }
135
136 inline bool operator== (const TreeItem &other) const
137 {
138 return this->index == other.index;
139 }
140 };
141
142 struct DataChangedParams {
143 QModelIndex topLeft;
144 QModelIndex bottomRight;
145 QVector<int> roles;
146 };
147
148 struct SignalFreezer {
149 SignalFreezer(QQmlTreeModelToTableModel *parent) : m_parent(parent) {
150 m_parent->enableSignalAggregation();
151 }
152 ~SignalFreezer() { m_parent->disableSignalAggregation(); }
153
154 private:
156 };
157
158 void enableSignalAggregation();
159 void disableSignalAggregation();
160 bool isAggregatingSignals() const { return m_signalAggregatorStack > 0; }
161 void queueDataChanged(const QModelIndex &topLeft,
162 const QModelIndex &bottomRight,
163 const QVector<int> &roles);
164 void emitQueuedSignals();
165 void connectToModel();
166
167 QPointer<QAbstractItemModel> m_model = nullptr;
168 QPersistentModelIndex m_rootIndex;
169 QList<TreeItem> m_items;
170 QSet<QPersistentModelIndex> m_expandedItems;
171 QList<TreeItem> m_itemsToExpand;
172 mutable int m_lastItemIndex = 0;
173 bool m_visibleRowsMoved = false;
174 bool m_modelLayoutChanged = false;
175 int m_signalAggregatorStack = 0;
176 QVector<DataChangedParams> m_queuedDataChanged;
177 std::array<QMetaObject::Connection, 15> m_connections;
178 int m_column = 0;
179};
180
182
183#endif // QQmlTreeModelToTableModel_H
LayoutChangeHint
This enum describes the way the model changes layout.
virtual Q_INVOKABLE bool hasChildren(const QModelIndex &parent=QModelIndex()) const
Returns {true} if parent has any children; otherwise returns {false}.
\inmodule QtCore
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:103
void modelChanged(QAbstractItemModel *model)
void collapsed(const QModelIndex &index)
void expanded(const QModelIndex &index)
\inmodule QtCore
Definition qvariant.h:65
Combined button and popup list for selecting options.
Orientation
Definition qnamespace.h:98
@ UserRole
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLint GLenum GLsizei GLsizei GLsizei depth
GLuint index
[2]
GLuint GLuint end
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLbitfield flags
GLuint start
GLfloat n
GLenum GLenum GLsizei void GLsizei void * column
GLenum GLenum GLsizei void * row
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
Definition qrandom.cpp:1220
static QString dump(const QByteArray &)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_INVOKABLE
#define Q_SLOTS
#define Q_SIGNALS
static uint toIndex(ExecutionEngine *e, const Value &v)
#define explicit
view setModel(model)
[17] //! [18]
QSqlQueryModel * model
[16]
mimeData setData("text/csv", csvData)
QSharedPointer< T > other(t)
[5]
edit isVisible()
QLayoutItem * child
[0]