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
qabstractitemmodel.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QABSTRACTITEMMODEL_H
6#define QABSTRACTITEMMODEL_H
7
8#include <QtCore/qhash.h>
9#include <QtCore/qlist.h>
10#include <QtCore/qobject.h>
11#include <QtCore/qvariant.h>
12
14
16
18{
19 int m_role;
20 QVariant m_data;
21
22public:
23 explicit QModelRoleData(int role) noexcept
24 : m_role(role)
25 {}
26
27 constexpr int role() const noexcept { return m_role; }
28 constexpr QVariant &data() noexcept { return m_data; }
29 constexpr const QVariant &data() const noexcept { return m_data; }
30
31 template <typename T>
32 constexpr void setData(T &&value) noexcept(noexcept(m_data.setValue(std::forward<T>(value))))
33 { m_data.setValue(std::forward<T>(value)); }
34
35 void clearData() noexcept { m_data.clear(); }
36};
37
39
41
42namespace QtPrivate {
43template <typename T, typename Enable = void>
45
46template <typename T>
47struct IsContainerCompatibleWithModelRoleDataSpan<T, std::enable_if_t<std::conjunction_v<
48 // lacking concepts and ranges, we accept any T whose std::data yields a suitable pointer ...
49 std::is_convertible<decltype( std::data(std::declval<T &>()) ), QModelRoleData *>,
50 // ... and that has a suitable size ...
51 std::is_convertible<decltype( std::size(std::declval<T &>()) ), qsizetype>,
52 // ... and it's a range as it defines an iterator-like API
53 std::is_convertible<
54 typename std::iterator_traits<decltype( std::begin(std::declval<T &>()) )>::value_type,
55 QModelRoleData
56 >,
57 std::is_convertible<
58 decltype( std::begin(std::declval<T &>()) != std::end(std::declval<T &>()) ),
59 bool>,
60 // Don't make an accidental copy constructor
61 std::negation<std::is_same<std::decay_t<T>, QModelRoleDataSpan>>
62 >>> : std::true_type {};
63} // namespace QtPrivate
64
66{
67 QModelRoleData *m_modelRoleData = nullptr;
68 qsizetype m_len = 0;
69
70 template <typename T>
71 using if_compatible_container = std::enable_if_t<QtPrivate::IsContainerCompatibleWithModelRoleDataSpan<T>::value, bool>;
72
73public:
74 constexpr QModelRoleDataSpan() noexcept {}
75
76 constexpr QModelRoleDataSpan(QModelRoleData &modelRoleData) noexcept
77 : m_modelRoleData(&modelRoleData),
78 m_len(1)
79 {}
80
82 : m_modelRoleData(modelRoleData),
83 m_len(len)
84 {}
85
86 template <typename Container, if_compatible_container<Container> = true>
87 constexpr QModelRoleDataSpan(Container &c) noexcept(noexcept(std::data(c)) && noexcept(std::size(c)))
88 : m_modelRoleData(std::data(c)),
89 m_len(qsizetype(std::size(c)))
90 {}
91
92 constexpr qsizetype size() const noexcept { return m_len; }
93 constexpr qsizetype length() const noexcept { return m_len; }
94 constexpr QModelRoleData *data() const noexcept { return m_modelRoleData; }
95 constexpr QModelRoleData *begin() const noexcept { return m_modelRoleData; }
96 constexpr QModelRoleData *end() const noexcept { return m_modelRoleData + m_len; }
97 constexpr QModelRoleData &operator[](qsizetype index) const { return m_modelRoleData[index]; }
98
99 constexpr QVariant *dataForRole(int role) const
100 {
101#ifdef __cpp_lib_constexpr_algorithms
102 auto result = std::find_if(begin(), end(), [role](const QModelRoleData &roleData) {
103 return roleData.role() == role;
104 });
105#else
106 auto result = begin();
107 const auto e = end();
108 for (; result != e; ++result) {
109 if (result->role() == role)
110 break;
111 }
112#endif
113
114 return Q_ASSERT(result != end()), &result->data();
115 }
116};
117
119
122
124{
125 friend class QAbstractItemModel;
126public:
127 constexpr inline QModelIndex() noexcept : r(-1), c(-1), i(0), m(nullptr) {}
128 // compiler-generated copy/move ctors/assignment operators are fine!
129 constexpr inline int row() const noexcept { return r; }
130 constexpr inline int column() const noexcept { return c; }
131 constexpr inline quintptr internalId() const noexcept { return i; }
132 inline void *internalPointer() const noexcept { return reinterpret_cast<void*>(i); }
133 inline const void *constInternalPointer() const noexcept { return reinterpret_cast<const void *>(i); }
134 inline QModelIndex parent() const;
135 inline QModelIndex sibling(int row, int column) const;
136 inline QModelIndex siblingAtColumn(int column) const;
137 inline QModelIndex siblingAtRow(int row) const;
138 inline QVariant data(int role = Qt::DisplayRole) const;
139 inline void multiData(QModelRoleDataSpan roleDataSpan) const;
140 inline Qt::ItemFlags flags() const;
141 constexpr inline const QAbstractItemModel *model() const noexcept { return m; }
142 constexpr inline bool isValid() const noexcept { return (r >= 0) && (c >= 0) && (m != nullptr); }
143 constexpr inline bool operator==(const QModelIndex &other) const noexcept
144 { return (other.r == r) && (other.i == i) && (other.c == c) && (other.m == m); }
145 constexpr inline bool operator!=(const QModelIndex &other) const noexcept
146 { return !(*this == other); }
147 constexpr inline bool operator<(const QModelIndex &other) const noexcept
148 {
149 return r < other.r
150 || (r == other.r && (c < other.c
151 || (c == other.c && (i < other.i
152 || (i == other.i && std::less<const QAbstractItemModel *>()(m, other.m))))));
153 }
154private:
155 inline QModelIndex(int arow, int acolumn, const void *ptr, const QAbstractItemModel *amodel) noexcept
156 : r(arow), c(acolumn), i(reinterpret_cast<quintptr>(ptr)), m(amodel) {}
157 constexpr inline QModelIndex(int arow, int acolumn, quintptr id, const QAbstractItemModel *amodel) noexcept
158 : r(arow), c(acolumn), i(id), m(amodel) {}
159 int r, c;
160 quintptr i;
161 const QAbstractItemModel *m;
162};
164
165#ifndef QT_NO_DEBUG_STREAM
166Q_CORE_EXPORT QDebug operator<<(QDebug, const QModelIndex &);
167#endif
168
170
171// qHash is a friend, but we can't use default arguments for friends (§8.3.6.4)
172size_t qHash(const QPersistentModelIndex &index, size_t seed = 0) noexcept;
173
174class Q_CORE_EXPORT QPersistentModelIndex
175{
176public:
181 bool operator<(const QPersistentModelIndex &other) const noexcept;
182 bool operator==(const QPersistentModelIndex &other) const noexcept;
183 inline bool operator!=(const QPersistentModelIndex &other) const noexcept
184 { return !operator==(other); }
187 : d(std::exchange(other.d, nullptr)) {}
188 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPersistentModelIndex)
190 bool operator==(const QModelIndex &other) const noexcept;
191 bool operator!=(const QModelIndex &other) const noexcept;
192 QPersistentModelIndex &operator=(const QModelIndex &other);
193 operator QModelIndex() const;
194 int row() const;
195 int column() const;
196 void *internalPointer() const;
197 const void *constInternalPointer() const;
198 quintptr internalId() const;
199 QModelIndex parent() const;
200 QModelIndex sibling(int row, int column) const;
201 QVariant data(int role = Qt::DisplayRole) const;
202 void multiData(QModelRoleDataSpan roleDataSpan) const;
203 Qt::ItemFlags flags() const;
204 const QAbstractItemModel *model() const;
205 bool isValid() const;
206private:
208 friend size_t qHash(const QPersistentModelIndex &, size_t seed) noexcept;
209 friend bool qHashEquals(const QPersistentModelIndex &a, const QPersistentModelIndex &b) noexcept
210 { return a.d == b.d; }
211#ifndef QT_NO_DEBUG_STREAM
212 friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QPersistentModelIndex &);
213#endif
214};
215Q_DECLARE_SHARED(QPersistentModelIndex)
216
217inline size_t qHash(const QPersistentModelIndex &index, size_t seed) noexcept
218{ return qHash(index.d, seed); }
219
220
221#ifndef QT_NO_DEBUG_STREAM
222Q_CORE_EXPORT QDebug operator<<(QDebug, const QPersistentModelIndex &);
223#endif
224
225typedef QList<QModelIndex> QModelIndexList;
226
227class QMimeData;
230template <class Key, class T> class QMap;
231
232
233class Q_CORE_EXPORT QAbstractItemModel : public QObject
234{
236
240public:
241
242 explicit QAbstractItemModel(QObject *parent = nullptr);
243 virtual ~QAbstractItemModel();
244
245 Q_INVOKABLE bool hasIndex(int row, int column, const QModelIndex &parent = QModelIndex()) const;
247 const QModelIndex &parent = QModelIndex()) const = 0;
248 Q_INVOKABLE virtual QModelIndex parent(const QModelIndex &child) const = 0;
249
250 Q_INVOKABLE virtual QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
251 Q_INVOKABLE virtual int rowCount(const QModelIndex &parent = QModelIndex()) const = 0;
252 Q_INVOKABLE virtual int columnCount(const QModelIndex &parent = QModelIndex()) const = 0;
253 Q_INVOKABLE virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
254
255 Q_INVOKABLE virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const = 0;
256 Q_INVOKABLE virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
257
258 Q_INVOKABLE virtual QVariant headerData(int section, Qt::Orientation orientation,
259 int role = Qt::DisplayRole) const;
260 virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value,
261 int role = Qt::EditRole);
262
263 virtual QMap<int, QVariant> itemData(const QModelIndex &index) const;
264 virtual bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles);
265 virtual bool clearItemData(const QModelIndex &index);
266
267 virtual QStringList mimeTypes() const;
268 virtual QMimeData *mimeData(const QModelIndexList &indexes) const;
269 virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action,
270 int row, int column, const QModelIndex &parent) const;
271 virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action,
272 int row, int column, const QModelIndex &parent);
273 virtual Qt::DropActions supportedDropActions() const;
274 virtual Qt::DropActions supportedDragActions() const;
275
276 Q_INVOKABLE Q_REVISION(6, 4) virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
277 Q_INVOKABLE Q_REVISION(6, 4) virtual bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex());
278 Q_INVOKABLE Q_REVISION(6, 4) virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
279 Q_INVOKABLE Q_REVISION(6, 4) virtual bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex());
280 Q_INVOKABLE Q_REVISION(6, 4) virtual bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count,
281 const QModelIndex &destinationParent, int destinationChild);
282 Q_INVOKABLE Q_REVISION(6, 4) virtual bool moveColumns(const QModelIndex &sourceParent, int sourceColumn, int count,
283 const QModelIndex &destinationParent, int destinationChild);
284
285 Q_INVOKABLE Q_REVISION(6, 4) inline bool insertRow(int row, const QModelIndex &parent = QModelIndex());
286 Q_INVOKABLE Q_REVISION(6, 4) inline bool insertColumn(int column, const QModelIndex &parent = QModelIndex());
287 Q_INVOKABLE Q_REVISION(6, 4) inline bool removeRow(int row, const QModelIndex &parent = QModelIndex());
288 Q_INVOKABLE Q_REVISION(6, 4) inline bool removeColumn(int column, const QModelIndex &parent = QModelIndex());
289 Q_INVOKABLE Q_REVISION(6, 4) inline bool moveRow(const QModelIndex &sourceParent, int sourceRow,
290 const QModelIndex &destinationParent, int destinationChild);
291 Q_INVOKABLE Q_REVISION(6, 4) inline bool moveColumn(const QModelIndex &sourceParent, int sourceColumn,
292 const QModelIndex &destinationParent, int destinationChild);
293
294 Q_INVOKABLE virtual void fetchMore(const QModelIndex &parent);
295 Q_INVOKABLE virtual bool canFetchMore(const QModelIndex &parent) const;
296 Q_INVOKABLE virtual Qt::ItemFlags flags(const QModelIndex &index) const;
297 Q_INVOKABLE Q_REVISION(6, 4) virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
298 virtual QModelIndex buddy(const QModelIndex &index) const;
299 Q_INVOKABLE virtual QModelIndexList match(const QModelIndex &start, int role,
300 const QVariant &value, int hits = 1,
301 Qt::MatchFlags flags =
302 Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const;
303 virtual QSize span(const QModelIndex &index) const;
304
305 virtual QHash<int,QByteArray> roleNames() const;
306
307 using QObject::parent;
308
315 Q_ENUM(LayoutChangeHint)
316
317 enum class CheckIndexOption {
318 NoOption = 0x0000,
319 IndexIsValid = 0x0001,
320 DoNotUseParent = 0x0002,
321 ParentIsInvalid = 0x0004,
322 };
323 Q_ENUM(CheckIndexOption)
324 Q_DECLARE_FLAGS(CheckIndexOptions, CheckIndexOption)
325
326 [[nodiscard]] bool checkIndex(const QModelIndex &index, CheckIndexOptions options = CheckIndexOption::NoOption) const;
327
328 virtual void multiData(const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const;
329
331 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
332 const QList<int> &roles = QList<int>());
333 void headerDataChanged(Qt::Orientation orientation, int first, int last);
334 void layoutChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint);
335 void layoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint);
336
337 void rowsAboutToBeInserted(const QModelIndex &parent, int first, int last, QPrivateSignal);
338 void rowsInserted(const QModelIndex &parent, int first, int last, QPrivateSignal);
339
340 void rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal);
341 void rowsRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal);
342
343 void columnsAboutToBeInserted(const QModelIndex &parent, int first, int last, QPrivateSignal);
344 void columnsInserted(const QModelIndex &parent, int first, int last, QPrivateSignal);
345
346 void columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal);
347 void columnsRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal);
348
349 void modelAboutToBeReset(QPrivateSignal);
350 void modelReset(QPrivateSignal);
351
352 void rowsAboutToBeMoved( const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow, QPrivateSignal);
353 void rowsMoved( const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow, QPrivateSignal);
354
355 void columnsAboutToBeMoved( const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn, QPrivateSignal);
356 void columnsMoved( const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn, QPrivateSignal);
357
358public Q_SLOTS:
359 virtual bool submit();
360 virtual void revert();
361
362protected Q_SLOTS:
363 virtual void resetInternalData();
364
365protected:
367
368 inline QModelIndex createIndex(int row, int column, const void *data = nullptr) const;
369 inline QModelIndex createIndex(int row, int column, quintptr id) const;
370
371 void encodeData(const QModelIndexList &indexes, QDataStream &stream) const;
372 bool decodeData(int row, int column, const QModelIndex &parent, QDataStream &stream);
373
374 void beginInsertRows(const QModelIndex &parent, int first, int last);
375 void endInsertRows();
376
377 void beginRemoveRows(const QModelIndex &parent, int first, int last);
378 void endRemoveRows();
379
380 bool beginMoveRows(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow);
381 void endMoveRows();
382
383 void beginInsertColumns(const QModelIndex &parent, int first, int last);
384 void endInsertColumns();
385
386 void beginRemoveColumns(const QModelIndex &parent, int first, int last);
387 void endRemoveColumns();
388
389 bool beginMoveColumns(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationColumn);
390 void endMoveColumns();
391
392 void beginResetModel();
393 void endResetModel();
394
395 void changePersistentIndex(const QModelIndex &from, const QModelIndex &to);
396 void changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to);
397 QModelIndexList persistentIndexList() const;
398
399private:
400 Q_DECLARE_PRIVATE(QAbstractItemModel)
401 Q_DISABLE_COPY(QAbstractItemModel)
402};
403
404Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractItemModel::CheckIndexOptions)
405
406inline bool QAbstractItemModel::insertRow(int arow, const QModelIndex &aparent)
407{ return insertRows(arow, 1, aparent); }
408inline bool QAbstractItemModel::insertColumn(int acolumn, const QModelIndex &aparent)
409{ return insertColumns(acolumn, 1, aparent); }
410inline bool QAbstractItemModel::removeRow(int arow, const QModelIndex &aparent)
411{ return removeRows(arow, 1, aparent); }
412inline bool QAbstractItemModel::removeColumn(int acolumn, const QModelIndex &aparent)
413{ return removeColumns(acolumn, 1, aparent); }
414inline bool QAbstractItemModel::moveRow(const QModelIndex &sourceParent, int sourceRow,
416{ return moveRows(sourceParent, sourceRow, 1, destinationParent, destinationChild); }
417inline bool QAbstractItemModel::moveColumn(const QModelIndex &sourceParent, int sourceColumn,
419{ return moveColumns(sourceParent, sourceColumn, 1, destinationParent, destinationChild); }
420inline QModelIndex QAbstractItemModel::createIndex(int arow, int acolumn, const void *adata) const
421{ return QModelIndex(arow, acolumn, adata, this); }
422inline QModelIndex QAbstractItemModel::createIndex(int arow, int acolumn, quintptr aid) const
423{ return QModelIndex(arow, acolumn, aid, this); }
424
425class Q_CORE_EXPORT QAbstractTableModel : public QAbstractItemModel
426{
428
429public:
430 explicit QAbstractTableModel(QObject *parent = nullptr);
432
433 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
434 QModelIndex sibling(int row, int column, const QModelIndex &idx) const override;
435 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
436 int row, int column, const QModelIndex &parent) override;
437
438 Qt::ItemFlags flags(const QModelIndex &index) const override;
439
440 using QObject::parent;
441
442protected:
444
445private:
446 Q_DISABLE_COPY(QAbstractTableModel)
447 QModelIndex parent(const QModelIndex &child) const override;
448 bool hasChildren(const QModelIndex &parent) const override;
449};
450
451class Q_CORE_EXPORT QAbstractListModel : public QAbstractItemModel
452{
454
455public:
456 explicit QAbstractListModel(QObject *parent = nullptr);
458
459 QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override;
460 QModelIndex sibling(int row, int column, const QModelIndex &idx) const override;
461 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
462 int row, int column, const QModelIndex &parent) override;
463
464 Qt::ItemFlags flags(const QModelIndex &index) const override;
465
466 using QObject::parent;
467
468protected:
470
471private:
472 Q_DISABLE_COPY(QAbstractListModel)
473 QModelIndex parent(const QModelIndex &child) const override;
474 int columnCount(const QModelIndex &parent) const override;
475 bool hasChildren(const QModelIndex &parent) const override;
476};
477
478// inline implementations
479
481{ return m ? m->parent(*this) : QModelIndex(); }
482
483inline QModelIndex QModelIndex::sibling(int arow, int acolumn) const
484{ return m ? (r == arow && c == acolumn) ? *this : m->sibling(arow, acolumn, *this) : QModelIndex(); }
485
487{ return m ? (c == acolumn) ? *this : m->sibling(r, acolumn, *this) : QModelIndex(); }
488
490{ return m ? (r == arow) ? *this : m->sibling(arow, c, *this) : QModelIndex(); }
491
492inline QVariant QModelIndex::data(int arole) const
493{ return m ? m->data(*this, arole) : QVariant(); }
494
495inline void QModelIndex::multiData(QModelRoleDataSpan roleDataSpan) const
496{ if (m) m->multiData(*this, roleDataSpan); }
497
498inline Qt::ItemFlags QModelIndex::flags() const
499{ return m ? m->flags(*this) : Qt::ItemFlags(); }
500
501inline size_t qHash(const QModelIndex &index, size_t seed = 0) noexcept
502{
503#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)
504 return qHashMulti(seed, index.row(), index.column(), index.internalId());
505#else
506 return size_t((size_t(index.row()) << 4) + size_t(index.column()) + index.internalId()) ^ seed;
507#endif
508}
509
511
513
514#endif // QABSTRACTITEMMODEL_H
NSData * m_data
void rowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow, QPrivateSignal)
void modelAboutToBeReset(QPrivateSignal)
void columnsRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted after columns have been removed from the model.
LayoutChangeHint
This enum describes the way the model changes layout.
void rowsAboutToBeInserted(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted just before rows are inserted into the model.
void columnsAboutToBeInserted(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted just before columns are inserted into the model.
void modelReset(QPrivateSignal)
Q_INVOKABLE int int const QModelIndex & destinationParent
void layoutAboutToBeChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
This signal is emitted whenever the data in an existing item changes.
virtual Q_INVOKABLE int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
void columnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn, QPrivateSignal)
virtual Q_INVOKABLE QModelIndex parent(const QModelIndex &child) const =0
void columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted just before columns are removed from the model.
Q_INVOKABLE int int const QModelIndex int destinationChild
void layoutChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
Q_INVOKABLE int sourceRow
void headerDataChanged(Qt::Orientation orientation, int first, int last)
This signal is emitted whenever a header is changed.
void rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted just before rows are removed from the model.
void rowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow, QPrivateSignal)
virtual Q_INVOKABLE int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
void rowsInserted(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted after rows have been inserted into the model.
Q_INVOKABLE int sourceColumn
void columnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn, QPrivateSignal)
QModelIndex createIndex(int row, int column, const void *data=nullptr) const
Creates a model index for the given row and column with the internal pointer ptr.
void columnsInserted(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted after columns have been inserted into the model.
virtual Q_INVOKABLE QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
virtual Q_INVOKABLE QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index.
void rowsRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal)
This signal is emitted after rows have been removed from the model.
The QAbstractProxyModel class provides a base class for proxy item models that can do sorting,...
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore
\inmodule QtCore
Definition qhash.h:820
Definition qmap.h:187
\inmodule QtCore
Definition qmimedata.h:16
\inmodule QtCore
QModelIndex siblingAtColumn(int column) const
Returns the sibling at column for the current row.
constexpr bool operator==(const QModelIndex &other) const noexcept
Returns {true} if this model index refers to the same location as the other model index; otherwise re...
QVariant data(int role=Qt::DisplayRole) const
Returns the data for the given role for the item referred to by the index.
QModelIndex siblingAtRow(int row) const
Returns the sibling at row for the current column.
constexpr int row() const noexcept
Returns the row this model index refers to.
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
constexpr const QAbstractItemModel * model() const noexcept
Returns a pointer to the model containing the item that this index refers to.
constexpr bool operator<(const QModelIndex &other) const noexcept
Qt::ItemFlags flags() const
constexpr QModelIndex() noexcept
Creates a new empty model index.
constexpr int column() const noexcept
Returns the column this model index refers to.
void * internalPointer() const noexcept
Returns a {void} {*} pointer used by the model to associate the index with the internal data structur...
constexpr bool isValid() const noexcept
Returns {true} if this model index is valid; otherwise returns {false}.
void multiData(QModelRoleDataSpan roleDataSpan) const
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
const void * constInternalPointer() const noexcept
Returns a {const void} {*} pointer used by the model to associate the index with the internal data st...
constexpr bool operator!=(const QModelIndex &other) const noexcept
Returns {true} if this model index does not refer to the same location as the other model index; othe...
constexpr quintptr internalId() const noexcept
Returns a {quintptr} used by the model to associate the index with the internal data structure.
constexpr QModelRoleData & operator[](qsizetype index) const
Returns a modifiable reference to the QModelRoleData at position index in the span.
constexpr qsizetype length() const noexcept
Returns the length of the span represented by this object.
constexpr qsizetype size() const noexcept
Returns the length of the span represented by this object.
constexpr QModelRoleDataSpan(QModelRoleData &modelRoleData) noexcept
Constructs an QModelRoleDataSpan spanning over modelRoleData, seen as a 1-element array.
constexpr QVariant * dataForRole(int role) const
Returns the data associated with the first QModelRoleData in the span that has its role equal to role...
constexpr QModelRoleData * begin() const noexcept
Returns a pointer to the beginning of the span represented by this object.
constexpr QModelRoleData * end() const noexcept
Returns a pointer to the imaginary element one past the end of the span represented by this object.
constexpr QModelRoleDataSpan(QModelRoleData *modelRoleData, qsizetype len)
Constructs an QModelRoleDataSpan spanning over the array beginning at modelRoleData and with length l...
constexpr QModelRoleDataSpan() noexcept
Constructs an empty QModelRoleDataSpan.
constexpr QModelRoleData * data() const noexcept
Returns a pointer to the beginning of the span represented by this object.
constexpr QModelRoleDataSpan(Container &c) noexcept(noexcept(std::data(c)) &&noexcept(std::size(c)))
Constructs an QModelRoleDataSpan spanning over the container c, which can be any contiguous container...
\inmodule QtCore
constexpr const QVariant & data() const noexcept
Returns the data held by this object.
void clearData() noexcept
Clears the data held by this object.
constexpr QVariant & data() noexcept
Returns the data held by this object as a modifiable reference.
constexpr int role() const noexcept
Returns the role held by this object.
constexpr void setData(T &&value) noexcept(noexcept(m_data.setValue(std::forward< T >(value))))
Sets the data held by this object to value.
QModelRoleData(int role) noexcept
Constructs a QModelRoleData object for the given role.
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
friend bool qHashEquals(const QPersistentModelIndex &a, const QPersistentModelIndex &b) noexcept
bool operator!=(const QPersistentModelIndex &other) const noexcept
QPersistentModelIndex(QPersistentModelIndex &&other) noexcept
Move-constructs a QPersistentModelIndex instance, making it point at the same object that other was p...
\inmodule QtCore
Definition qsize.h:25
\inmodule QtCore
\inmodule QtCore
Definition qvariant.h:65
void * data()
Returns a pointer to the contained object as a generic void* that can be written to.
Combined button and popup list for selecting options.
\macro QT_NO_KEYWORDS >
Definition qcompare.h:63
Orientation
Definition qnamespace.h:98
@ EditRole
@ DisplayRole
DropAction
Q_CORE_EXPORT QDebug operator<<(QDebug, const QModelIndex &)
size_t qHash(const QPersistentModelIndex &index, size_t seed=0) noexcept
QList< QModelIndex > QModelIndexList
constexpr bool operator!=(const timespec &t1, const timespec &t2)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
EGLStreamKHR stream
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
constexpr QtPrivate::QHashMultiReturnType< T... > qHashMulti(size_t seed, const T &... args) noexcept(std::conjunction_v< QtPrivate::QNothrowHashable< T >... >)
static ControlElement< T > * ptr(QWidget *widget)
#define QT_DECL_METATYPE_EXTERN(TYPE, EXPORT)
Definition qmetatype.h:1388
GLboolean GLboolean GLboolean b
const GLfloat * m
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint index
[2]
GLboolean r
[2]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLbitfield flags
GLuint start
GLint first
GLenum GLenum GLsizei void GLsizei void * column
const GLubyte * c
GLenum GLenum GLsizei void * row
GLenum GLenum GLsizei void GLsizei void void * span
GLuint64EXT * result
[6]
GLenum GLsizei len
GLfixed GLfixed GLint GLint order
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
Definition qrandom.cpp:1220
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
static bool operator<(const QSettingsIniKey &k1, const QSettingsIniKey &k2)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
constexpr void qt_ptr_swap(T *&lhs, T *&rhs) noexcept
Definition qswap.h:29
#define QT_REQUIRE_CONFIG(feature)
#define Q_ENUM(x)
#define Q_OBJECT
#define Q_REVISION(...)
#define Q_INVOKABLE
#define Q_SLOTS
#define Q_SIGNALS
static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen)
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:158
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180
size_t quintptr
Definition qtypes.h:167
ptrdiff_t qsizetype
Definition qtypes.h:165
model setHeaderData(0, Qt::Horizontal, tr("Name"))
QSqlQueryModel * model
[16]
beginInsertRows(parent, 2, 4)
[0]
beginMoveRows(sourceParent, 2, 4, destinationParent, 2)
[5]
std::array< QModelRoleData, 3 > roleData
[13]
beginInsertColumns(parent, 4, 6)
[2]
beginRemoveColumns(parent, 4, 6)
[4]
beginRemoveRows(parent, 2, 3)
[1]
model multiData(index, span)
mimeData setData("text/csv", csvData)
QMimeData * mimeData
QSharedPointer< T > other(t)
[5]
this swap(other)
flay removeRow(2)
flay insertRow(2, "User:", le)
QLayoutItem * child
[0]