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
qrangemodel.h
Go to the documentation of this file.
1// Copyright (C) 2025 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// Qt-Security score:significant reason:default
4
5#ifndef QRANGEMODEL_H
6#define QRANGEMODEL_H
7
8#include <QtCore/qrangemodel_impl.h>
9
10QT_BEGIN_NAMESPACE
11
12class QRangeModelPrivate;
13
14class Q_CORE_EXPORT QRangeModel : public QAbstractItemModel
15{
16 Q_OBJECT
17 Q_PROPERTY(QHash<int, QByteArray> roleNames READ roleNames WRITE setRoleNames RESET resetRoleNames
18 NOTIFY roleNamesChanged FINAL)
19
20public:
21 enum class RowCategory {
22 Default,
23 MultiRoleItem,
24 };
25
26 template <typename T>
27 struct RowOptions {};
28
29 template <typename T>
30 struct ItemAccess {};
31
32 template <typename Range,
33 QRangeModelDetails::if_table_range<Range> = true>
34 explicit QRangeModel(Range &&range, QObject *parent = nullptr)
35 : QRangeModel(new QGenericTableItemModelImpl<Range>(std::forward<Range>(range), this), parent)
36 {}
37
38 template <typename Range,
39 QRangeModelDetails::if_tree_range<Range> = true>
40 explicit QRangeModel(Range &&range, QObject *parent = nullptr)
41 : QRangeModel(std::forward<Range>(range), QRangeModelDetails::DefaultTreeProtocol<Range>{},
42 parent)
43 {}
44
45 template <typename Range, typename Protocol,
46 QRangeModelDetails::if_tree_range<Range, Protocol> = true>
47 explicit QRangeModel(Range &&range, Protocol &&protocol, QObject *parent = nullptr)
48 : QRangeModel(new QGenericTreeItemModelImpl<Range, Protocol>(std::forward<Range>(range),
49 std::forward<Protocol>(protocol),
50 this),
51 parent)
52 {}
53
54 ~QRangeModel() override;
55
56 QModelIndex index(int row, int column, const QModelIndex &parent = {}) const final;
57 QModelIndex parent(const QModelIndex &child) const final;
58 QModelIndex sibling(int row, int column, const QModelIndex &index) const final;
59 int rowCount(const QModelIndex &parent = {}) const final;
60 int columnCount(const QModelIndex &parent = {}) const final;
61 Qt::ItemFlags flags(const QModelIndex &index) const override;
62 QVariant headerData(int section, Qt::Orientation orientation,
63 int role = Qt::DisplayRole) const override;
64 bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &data,
65 int role = Qt::EditRole) override;
66 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
67 bool setData(const QModelIndex &index, const QVariant &data, int role = Qt::EditRole) override;
68 QMap<int, QVariant> itemData(const QModelIndex &index) const override;
69 bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &data) override;
70 bool clearItemData(const QModelIndex &index) override;
71 bool insertColumns(int column, int count, const QModelIndex &parent = {}) final;
72 bool removeColumns(int column, int count, const QModelIndex &parent = {}) final;
73 bool moveColumns(const QModelIndex &sourceParent, int sourceColumn, int count,
74 const QModelIndex &destParent, int destColumn) final;
75 bool insertRows(int row, int count, const QModelIndex &parent = {}) final;
76 bool removeRows(int row, int count, const QModelIndex &parent = {}) final;
77 bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count,
78 const QModelIndex &destParent, int destRow) final;
79
80 QHash<int, QByteArray> roleNames() const override;
81 void setRoleNames(const QHash<int, QByteArray> &names);
82 void resetRoleNames();
83
84 bool canFetchMore(const QModelIndex &parent) const override;
85 void fetchMore(const QModelIndex &parent) override;
86
87 bool hasChildren(const QModelIndex &parent = QModelIndex()) const final;
88 QModelIndex buddy(const QModelIndex &index) const override;
89 bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
90 const QModelIndex &parent) const override;
91 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
92 const QModelIndex &parent) override;
93 QMimeData *mimeData(const QModelIndexList &indexes) const override;
94 QStringList mimeTypes() const override;
95 QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits,
96 Qt::MatchFlags flags) const override;
97 void multiData(const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const override;
98 void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
99 QSize span(const QModelIndex &index) const override;
100 Qt::DropActions supportedDragActions() const override;
101 Qt::DropActions supportedDropActions() const override;
102
103Q_SIGNALS:
104 void roleNamesChanged();
105
106protected Q_SLOTS:
107 void resetInternalData() override;
108
109protected:
110 bool event(QEvent *) override;
111 bool eventFilter(QObject *, QEvent *) override;
112
113private:
114 Q_DISABLE_COPY_MOVE(QRangeModel)
115 Q_DECLARE_PRIVATE(QRangeModel)
116
117 explicit QRangeModel(QRangeModelImplBase *impl, QObject *parent);
118 friend class QRangeModelImplBase;
119};
120
121// implementation of forwarders
122QModelIndex QRangeModelImplBase::createIndex(int row, int column, const void *ptr) const
123{
124 return m_rangeModel->createIndex(row, column, ptr);
125}
126void QRangeModelImplBase::changePersistentIndexList(const QModelIndexList &from,
127 const QModelIndexList &to)
128{
129 m_rangeModel->changePersistentIndexList(from, to);
130}
131void QRangeModelImplBase::dataChanged(const QModelIndex &from, const QModelIndex &to,
132 const QList<int> &roles)
133{
134 m_rangeModel->dataChanged(from, to, roles);
135}
136void QRangeModelImplBase::beginInsertColumns(const QModelIndex &parent, int start, int count)
137{
138 m_rangeModel->beginInsertColumns(parent, start, count);
139}
140void QRangeModelImplBase::endInsertColumns()
141{
142 m_rangeModel->endInsertColumns();
143}
144void QRangeModelImplBase::beginRemoveColumns(const QModelIndex &parent, int start, int count)
145{
146 m_rangeModel->beginRemoveColumns(parent, start, count);
147}
148void QRangeModelImplBase::endRemoveColumns()
149{
150 m_rangeModel->endRemoveColumns();
151}
152bool QRangeModelImplBase::beginMoveColumns(const QModelIndex &sourceParent, int sourceFirst,
153 int sourceLast, const QModelIndex &destParent,
154 int destColumn)
155{
156 return m_rangeModel->beginMoveColumns(sourceParent, sourceFirst, sourceLast,
157 destParent, destColumn);
158}
159void QRangeModelImplBase::endMoveColumns()
160{
161 m_rangeModel->endMoveColumns();
162}
163
164void QRangeModelImplBase::beginInsertRows(const QModelIndex &parent, int start, int count)
165{
166 m_rangeModel->beginInsertRows(parent, start, count);
167}
168void QRangeModelImplBase::endInsertRows()
169{
170 m_rangeModel->endInsertRows();
171}
172void QRangeModelImplBase::beginRemoveRows(const QModelIndex &parent, int start, int count)
173{
174 m_rangeModel->beginRemoveRows(parent, start, count);
175}
176void QRangeModelImplBase::endRemoveRows()
177{
178 m_rangeModel->endRemoveRows();
179}
180bool QRangeModelImplBase::beginMoveRows(const QModelIndex &sourceParent, int sourceFirst,
181 int sourceLast,
182 const QModelIndex &destParent, int destRow)
183{
184 return m_rangeModel->beginMoveRows(sourceParent, sourceFirst, sourceLast, destParent, destRow);
185}
186void QRangeModelImplBase::endMoveRows()
187{
188 m_rangeModel->endMoveRows();
189}
190QAbstractItemModel &QRangeModelImplBase::itemModel()
191{
192 return *m_rangeModel;
193}
194const QAbstractItemModel &QRangeModelImplBase::itemModel() const
195{
196 return *m_rangeModel;
197}
198
199// Helper templates that we can forward declare in the _impl header,
200// where QRangeModel is not yet defined.
202{
203template <typename T>
205
206template <typename T>
208}
209
210QT_END_NAMESPACE
211
212
213#endif // QRANGEMODEL_H
\inmodule QtCore
Definition qrangemodel.h:15