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
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// Qt-Security score:significant reason:default
5
6#ifndef QABSTRACTITEMMODEL_H
7#define QABSTRACTITEMMODEL_H
8
9#include <QtCore/qcompare.h>
10#include <QtCore/qhash.h>
11#include <QtCore/qlist.h>
12#include <QtCore/qobject.h>
13#include <QtCore/qvariant.h>
14
16
17QT_BEGIN_NAMESPACE
18
19class QCollator;
20
22{
23 int m_role;
24 QVariant m_data;
25
26public:
27 explicit QModelRoleData(int role) noexcept
28 : m_role(role)
29 {}
30
31 constexpr int role() const noexcept { return m_role; }
32 constexpr QVariant &data() noexcept { return m_data; }
33 constexpr const QVariant &data() const noexcept { return m_data; }
34
35 template <typename T>
36 constexpr void setData(T &&value) noexcept(noexcept(m_data.setValue(std::forward<T>(value))))
37 { m_data.setValue(std::forward<T>(value)); }
38
39 void clearData() noexcept { m_data.clear(); }
40};
41
43
45
46namespace QtPrivate {
47template <typename T, typename Enable = void>
49
50template <typename T>
52 // lacking concepts and ranges, we accept any T whose std::data yields a suitable pointer ...
53 std::is_convertible<decltype( std::data(std::declval<T &>()) ), QModelRoleData *>,
54 // ... and that has a suitable size ...
55 std::is_convertible<decltype( std::size(std::declval<T &>()) ), qsizetype>,
56 // ... and it's a range as it defines an iterator-like API
58 typename std::iterator_traits<decltype( std::begin(std::declval<T &>()) )>::value_type,
60 >,
62 decltype( std::begin(std::declval<T &>()) != std::end(std::declval<T &>()) ),
63 bool>,
64 // Don't make an accidental copy constructor
66 >>> : std::true_type {};
67} // namespace QtPrivate
68
70{
71 QModelRoleData *m_modelRoleData = nullptr;
72 qsizetype m_len = 0;
73
74 template <typename T>
76
77public:
78 constexpr QModelRoleDataSpan() noexcept {}
79
80 constexpr QModelRoleDataSpan(QModelRoleData &modelRoleData) noexcept
81 : m_modelRoleData(&modelRoleData),
82 m_len(1)
83 {}
84
85 constexpr QModelRoleDataSpan(QModelRoleData *modelRoleData, qsizetype len)
86 : m_modelRoleData(modelRoleData),
87 m_len(len)
88 {}
89
90 template <typename Container, if_compatible_container<Container> = true>
91 constexpr QModelRoleDataSpan(Container &c) noexcept(noexcept(std::data(c)) && noexcept(std::size(c)))
94 {}
95
96 constexpr qsizetype size() const noexcept { return m_len; }
97 constexpr qsizetype length() const noexcept { return m_len; }
98 constexpr QModelRoleData *data() const noexcept { return m_modelRoleData; }
99 constexpr QModelRoleData *begin() const noexcept { return m_modelRoleData; }
100 constexpr QModelRoleData *end() const noexcept { return m_modelRoleData + m_len; }
101 constexpr QModelRoleData &operator[](qsizetype index) const { return m_modelRoleData[index]; }
102
103 constexpr QVariant *dataForRole(int role) const
104 {
105#ifdef __cpp_lib_constexpr_algorithms
106 auto result = std::find_if(begin(), end(), [role](const QModelRoleData &roleData) {
107 return roleData.role() == role;
108 });
109#else
110 auto result = begin();
111 const auto e = end();
112 for (; result != e; ++result) {
113 if (result->role() == role)
114 break;
115 }
116#endif
117
118 return Q_ASSERT(result != end()), &result->data();
119 }
120};
121
123
124class QAbstractItemModel;
125class QPersistentModelIndex;
126
128{
129 friend class QAbstractItemModel;
130public:
131 constexpr inline QModelIndex() noexcept : r(-1), c(-1), i(0), m(nullptr) {}
132 // compiler-generated copy/move ctors/assignment operators are fine!
133 constexpr inline int row() const noexcept { return r; }
134 constexpr inline int column() const noexcept { return c; }
135 constexpr inline quintptr internalId() const noexcept { return i; }
136 inline void *internalPointer() const noexcept { return reinterpret_cast<void*>(i); }
137 inline const void *constInternalPointer() const noexcept { return reinterpret_cast<const void *>(i); }
138 inline QModelIndex parent() const;
139 inline QModelIndex sibling(int row, int column) const;
140 inline QModelIndex siblingAtColumn(int column) const;
141 inline QModelIndex siblingAtRow(int row) const;
142 inline QVariant data(int role = Qt::DisplayRole) const;
143 inline void multiData(QModelRoleDataSpan roleDataSpan) const;
144 inline Qt::ItemFlags flags() const;
145 constexpr inline const QAbstractItemModel *model() const noexcept { return m.get(); }
146 constexpr inline bool isValid() const noexcept { return (r >= 0) && (c >= 0) && (m != nullptr); }
147
148private:
149 friend constexpr bool comparesEqual(const QModelIndex &lhs, const QModelIndex &rhs) noexcept
150 {
151 return lhs.r == rhs.r && lhs.c == rhs.c && lhs.i == rhs.i && lhs.m == rhs.m;
152 }
153 friend constexpr Qt::strong_ordering compareThreeWay(const QModelIndex &lhs, const QModelIndex &rhs) noexcept
154 {
155 if (auto val = Qt::compareThreeWay(lhs.r, rhs.r); !is_eq(val))
156 return val;
157 if (auto val = Qt::compareThreeWay(lhs.c, rhs.c); !is_eq(val))
158 return val;
159 if (auto val = Qt::compareThreeWay(lhs.i, rhs.i); !is_eq(val))
160 return val;
161 if (auto val = Qt::compareThreeWay(lhs.m, rhs.m); !is_eq(val))
162 return val;
163 return Qt::strong_ordering::equivalent;
164 }
166private:
167 inline QModelIndex(int arow, int acolumn, const void *ptr, const QAbstractItemModel *amodel) noexcept
168 : r(arow), c(acolumn), i(reinterpret_cast<quintptr>(ptr)), m(amodel) {}
169 constexpr inline QModelIndex(int arow, int acolumn, quintptr id, const QAbstractItemModel *amodel) noexcept
170 : r(arow), c(acolumn), i(id), m(amodel) {}
171 int r, c;
172 quintptr i;
173 Qt::totally_ordered_wrapper<const QAbstractItemModel *> m;
174};
176
177#ifndef QT_NO_DEBUG_STREAM
178Q_CORE_EXPORT QDebug operator<<(QDebug, const QModelIndex &);
179#endif
180
182
183// qHash is a friend, but we can't use default arguments for friends (§8.3.6.4)
184size_t qHash(const QPersistentModelIndex &index, size_t seed = 0) noexcept;
185
186class Q_CORE_EXPORT QPersistentModelIndex
187{
188public:
189 QPersistentModelIndex();
190 QPersistentModelIndex(const QModelIndex &index);
191 QPersistentModelIndex(const QPersistentModelIndex &other);
192 ~QPersistentModelIndex();
193#if QT_CORE_REMOVED_SINCE(6, 8)
194 bool operator<(const QPersistentModelIndex &other) const noexcept;
195 bool operator==(const QPersistentModelIndex &other) const noexcept;
196 inline bool operator!=(const QPersistentModelIndex &other) const noexcept
197 { return !operator==(other); }
198#endif
199 QPersistentModelIndex &operator=(const QPersistentModelIndex &other);
200 inline QPersistentModelIndex(QPersistentModelIndex &&other) noexcept
201 : d(std::exchange(other.d, nullptr)) {}
202 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPersistentModelIndex)
203 void swap(QPersistentModelIndex &other) noexcept { qt_ptr_swap(d, other.d); }
204#if QT_CORE_REMOVED_SINCE(6, 8)
205 bool operator==(const QModelIndex &other) const noexcept;
206 bool operator!=(const QModelIndex &other) const noexcept;
207#endif
208 QPersistentModelIndex &operator=(const QModelIndex &other);
209 operator QModelIndex() const;
210 int row() const;
211 int column() const;
212 void *internalPointer() const;
213 const void *constInternalPointer() const;
214 quintptr internalId() const;
215 QModelIndex parent() const;
216 QModelIndex sibling(int row, int column) const;
217 QVariant data(int role = Qt::DisplayRole) const;
218 void multiData(QModelRoleDataSpan roleDataSpan) const;
219 Qt::ItemFlags flags() const;
220 const QAbstractItemModel *model() const;
221 bool isValid() const;
222private:
223 QPersistentModelIndexData *d;
224 friend size_t qHash(const QPersistentModelIndex &, size_t seed) noexcept;
225 friend bool qHashEquals(const QPersistentModelIndex &a, const QPersistentModelIndex &b) noexcept
226 { return a.d == b.d; }
227 friend Q_CORE_EXPORT bool
228 comparesEqual(const QPersistentModelIndex &lhs, const QPersistentModelIndex &rhs) noexcept;
229 friend Q_CORE_EXPORT bool
230 comparesEqual(const QPersistentModelIndex &lhs, const QModelIndex &rhs) noexcept;
231 friend Q_CORE_EXPORT Qt::strong_ordering // ### Qt 7: partial_ordering?
232 compareThreeWay(const QPersistentModelIndex &lhs, const QPersistentModelIndex &rhs) noexcept;
233 friend Q_CORE_EXPORT Qt::strong_ordering // ### Qt 7: partial_ordering?
234 compareThreeWay(const QPersistentModelIndex &lhs, const QModelIndex &rhs) noexcept;
235#if !QT_CORE_REMOVED_SINCE(6, 8)
236 Q_DECLARE_STRONGLY_ORDERED(QPersistentModelIndex)
237 Q_DECLARE_STRONGLY_ORDERED(QPersistentModelIndex, QModelIndex)
238#endif
239#ifndef QT_NO_DEBUG_STREAM
240 friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QPersistentModelIndex &);
241#endif
242};
244
245inline size_t qHash(const QPersistentModelIndex &index, size_t seed) noexcept
246{ return qHash(index.d, seed); }
247
248
249#ifndef QT_NO_DEBUG_STREAM
250Q_CORE_EXPORT QDebug operator<<(QDebug, const QPersistentModelIndex &);
251#endif
252
254
255class QMimeData;
256class QAbstractItemModelPrivate;
257class QTransposeProxyModelPrivate;
258template <class Key, class T> class QMap;
259
260
261class Q_CORE_EXPORT QAbstractItemModel : public QObject
262{
263 Q_OBJECT
264
265 friend class QPersistentModelIndexData;
266 friend class QAbstractItemViewPrivate;
267 friend class QAbstractProxyModel;
268public:
269
270 explicit QAbstractItemModel(QObject *parent = nullptr);
271 virtual ~QAbstractItemModel();
272
273 Q_INVOKABLE bool hasIndex(int row, int column, const QModelIndex &parent = QModelIndex()) const;
274 Q_INVOKABLE virtual QModelIndex index(int row, int column,
275 const QModelIndex &parent = QModelIndex()) const = 0;
276 Q_INVOKABLE virtual QModelIndex parent(const QModelIndex &child) const = 0;
277
278 Q_INVOKABLE virtual QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
279 Q_INVOKABLE virtual int rowCount(const QModelIndex &parent = QModelIndex()) const = 0;
280 Q_INVOKABLE virtual int columnCount(const QModelIndex &parent = QModelIndex()) const = 0;
281 Q_INVOKABLE virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
282
283 Q_INVOKABLE virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const = 0;
284 Q_INVOKABLE virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
285
286 Q_INVOKABLE virtual QVariant headerData(int section, Qt::Orientation orientation,
287 int role = Qt::DisplayRole) const;
288 virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value,
289 int role = Qt::EditRole);
290
291 virtual QMap<int, QVariant> itemData(const QModelIndex &index) const;
292 virtual bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles);
293 virtual bool clearItemData(const QModelIndex &index);
294
295 virtual QStringList mimeTypes() const;
296 virtual QMimeData *mimeData(const QModelIndexList &indexes) const;
297 virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action,
298 int row, int column, const QModelIndex &parent) const;
299 virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action,
300 int row, int column, const QModelIndex &parent);
301 virtual Qt::DropActions supportedDropActions() const;
302 virtual Qt::DropActions supportedDragActions() const;
303
304 Q_INVOKABLE Q_REVISION(6, 4) virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
305 Q_INVOKABLE Q_REVISION(6, 4) virtual bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex());
306 Q_INVOKABLE Q_REVISION(6, 4) virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
307 Q_INVOKABLE Q_REVISION(6, 4) virtual bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex());
308 Q_INVOKABLE Q_REVISION(6, 4) virtual bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count,
309 const QModelIndex &destinationParent, int destinationChild);
310 Q_INVOKABLE Q_REVISION(6, 4) virtual bool moveColumns(const QModelIndex &sourceParent, int sourceColumn, int count,
311 const QModelIndex &destinationParent, int destinationChild);
312
313 Q_INVOKABLE Q_REVISION(6, 4) inline bool insertRow(int row, const QModelIndex &parent = QModelIndex());
314 Q_INVOKABLE Q_REVISION(6, 4) inline bool insertColumn(int column, const QModelIndex &parent = QModelIndex());
315 Q_INVOKABLE Q_REVISION(6, 4) inline bool removeRow(int row, const QModelIndex &parent = QModelIndex());
316 Q_INVOKABLE Q_REVISION(6, 4) inline bool removeColumn(int column, const QModelIndex &parent = QModelIndex());
317 Q_INVOKABLE Q_REVISION(6, 4) inline bool moveRow(const QModelIndex &sourceParent, int sourceRow,
318 const QModelIndex &destinationParent, int destinationChild);
319 Q_INVOKABLE Q_REVISION(6, 4) inline bool moveColumn(const QModelIndex &sourceParent, int sourceColumn,
320 const QModelIndex &destinationParent, int destinationChild);
321
322 Q_INVOKABLE virtual void fetchMore(const QModelIndex &parent);
323 Q_INVOKABLE virtual bool canFetchMore(const QModelIndex &parent) const;
324 Q_INVOKABLE virtual Qt::ItemFlags flags(const QModelIndex &index) const;
325 Q_INVOKABLE Q_REVISION(6, 4) virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
326 virtual QModelIndex buddy(const QModelIndex &index) const;
327 Q_INVOKABLE virtual QModelIndexList match(const QModelIndex &start, int role,
328 const QVariant &value, int hits = 1,
329 Qt::MatchFlags flags =
330 Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const;
331 virtual QSize span(const QModelIndex &index) const;
332
333 virtual QHash<int,QByteArray> roleNames() const;
334
335 using QObject::parent;
336
337 enum LayoutChangeHint
338 {
339 NoLayoutChangeHint,
340 VerticalSortHint,
341 HorizontalSortHint
342 };
343 Q_ENUM(LayoutChangeHint)
344
345 enum class CheckIndexOption {
346 NoOption = 0x0000,
347 IndexIsValid = 0x0001,
348 DoNotUseParent = 0x0002,
349 ParentIsInvalid = 0x0004,
350 };
351 Q_ENUM(CheckIndexOption)
352 Q_DECLARE_FLAGS(CheckIndexOptions, CheckIndexOption)
353
354 [[nodiscard]] bool checkIndex(const QModelIndex &index, CheckIndexOptions options = CheckIndexOption::NoOption) const;
355
356 virtual void multiData(const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const;
357
358Q_SIGNALS:
359 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
360 const QList<int> &roles = QList<int>());
361 void headerDataChanged(Qt::Orientation orientation, int first, int last);
362 void layoutChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint);
363 void layoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint);
364
365 void rowsAboutToBeInserted(const QModelIndex &parent, int first, int last, QPrivateSignal);
366 void rowsInserted(const QModelIndex &parent, int first, int last, QPrivateSignal);
367
368 void rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal);
369 void rowsRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal);
370
371 void columnsAboutToBeInserted(const QModelIndex &parent, int first, int last, QPrivateSignal);
372 void columnsInserted(const QModelIndex &parent, int first, int last, QPrivateSignal);
373
374 void columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal);
375 void columnsRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal);
376
377 void modelAboutToBeReset(QPrivateSignal);
378 void modelReset(QPrivateSignal);
379
380 void rowsAboutToBeMoved( const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow, QPrivateSignal);
381 void rowsMoved( const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow, QPrivateSignal);
382
383 void columnsAboutToBeMoved( const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn, QPrivateSignal);
384 void columnsMoved( const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn, QPrivateSignal);
385
386public Q_SLOTS:
387 virtual bool submit();
388 virtual void revert();
389
390protected Q_SLOTS:
391 virtual void resetInternalData();
392
393protected:
394 QAbstractItemModel(QAbstractItemModelPrivate &dd, QObject *parent = nullptr);
395
396 inline QModelIndex createIndex(int row, int column, const void *data = nullptr) const;
397 inline QModelIndex createIndex(int row, int column, quintptr id) const;
398
399 void encodeData(const QModelIndexList &indexes, QDataStream &stream) const;
400 bool decodeData(int row, int column, const QModelIndex &parent, QDataStream &stream);
401
402 void beginInsertRows(const QModelIndex &parent, int first, int last);
403 void endInsertRows();
404
405 void beginRemoveRows(const QModelIndex &parent, int first, int last);
406 void endRemoveRows();
407
408 bool beginMoveRows(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow);
409 void endMoveRows();
410
411 void beginInsertColumns(const QModelIndex &parent, int first, int last);
412 void endInsertColumns();
413
414 void beginRemoveColumns(const QModelIndex &parent, int first, int last);
415 void endRemoveColumns();
416
417 bool beginMoveColumns(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationColumn);
418 void endMoveColumns();
419
420 void beginResetModel();
421 void endResetModel();
422
423 void changePersistentIndex(const QModelIndex &from, const QModelIndex &to);
424 void changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to);
425 QModelIndexList persistentIndexList() const;
426
427 static Qt::weak_ordering compareData(const QVariant &lhs, const QVariant &rhs,
428 const QCollator *collator = nullptr);
429
430private:
431 Q_DECLARE_PRIVATE(QAbstractItemModel)
432 Q_DISABLE_COPY(QAbstractItemModel)
433};
434
435Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractItemModel::CheckIndexOptions)
436
437inline bool QAbstractItemModel::insertRow(int arow, const QModelIndex &aparent)
438{ return insertRows(arow, 1, aparent); }
439inline bool QAbstractItemModel::insertColumn(int acolumn, const QModelIndex &aparent)
440{ return insertColumns(acolumn, 1, aparent); }
441inline bool QAbstractItemModel::removeRow(int arow, const QModelIndex &aparent)
442{ return removeRows(arow, 1, aparent); }
443inline bool QAbstractItemModel::removeColumn(int acolumn, const QModelIndex &aparent)
444{ return removeColumns(acolumn, 1, aparent); }
445inline bool QAbstractItemModel::moveRow(const QModelIndex &sourceParent, int sourceRow,
446 const QModelIndex &destinationParent, int destinationChild)
447{ return moveRows(sourceParent, sourceRow, 1, destinationParent, destinationChild); }
448inline bool QAbstractItemModel::moveColumn(const QModelIndex &sourceParent, int sourceColumn,
449 const QModelIndex &destinationParent, int destinationChild)
450{ return moveColumns(sourceParent, sourceColumn, 1, destinationParent, destinationChild); }
451inline QModelIndex QAbstractItemModel::createIndex(int arow, int acolumn, const void *adata) const
452{ return QModelIndex(arow, acolumn, adata, this); }
453inline QModelIndex QAbstractItemModel::createIndex(int arow, int acolumn, quintptr aid) const
454{ return QModelIndex(arow, acolumn, aid, this); }
455
456class Q_CORE_EXPORT QAbstractTableModel : public QAbstractItemModel
457{
458 Q_OBJECT
459
460public:
461 explicit QAbstractTableModel(QObject *parent = nullptr);
462 ~QAbstractTableModel();
463
464 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
465 QModelIndex sibling(int row, int column, const QModelIndex &idx) const override;
466 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
467 int row, int column, const QModelIndex &parent) override;
468
469 Qt::ItemFlags flags(const QModelIndex &index) const override;
470
471 using QObject::parent;
472
473protected:
474 QAbstractTableModel(QAbstractItemModelPrivate &dd, QObject *parent);
475
476private:
477 Q_DECLARE_PRIVATE(QAbstractItemModel) // no own private type
478 Q_DISABLE_COPY(QAbstractTableModel)
479 QModelIndex parent(const QModelIndex &child) const override;
480 bool hasChildren(const QModelIndex &parent) const override;
481};
482
483class Q_CORE_EXPORT QAbstractListModel : public QAbstractItemModel
484{
485 Q_OBJECT
486
487public:
488 explicit QAbstractListModel(QObject *parent = nullptr);
489 ~QAbstractListModel();
490
491 QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override;
492 QModelIndex sibling(int row, int column, const QModelIndex &idx) const override;
493 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
494 int row, int column, const QModelIndex &parent) override;
495
496 Qt::ItemFlags flags(const QModelIndex &index) const override;
497
498 using QObject::parent;
499
500protected:
501 QAbstractListModel(QAbstractItemModelPrivate &dd, QObject *parent);
502
503private:
504 Q_DECLARE_PRIVATE(QAbstractItemModel) // no own private type
505 Q_DISABLE_COPY(QAbstractListModel)
506 QModelIndex parent(const QModelIndex &child) const override;
507 int columnCount(const QModelIndex &parent) const override;
508 bool hasChildren(const QModelIndex &parent) const override;
509};
510
511// inline implementations
512
514{ return m ? m->parent(*this) : QModelIndex(); }
515
516inline QModelIndex QModelIndex::sibling(int arow, int acolumn) const
517{ return m ? (r == arow && c == acolumn) ? *this : m->sibling(arow, acolumn, *this) : QModelIndex(); }
518
519inline QModelIndex QModelIndex::siblingAtColumn(int acolumn) const
520{ return m ? (c == acolumn) ? *this : m->sibling(r, acolumn, *this) : QModelIndex(); }
521
522inline QModelIndex QModelIndex::siblingAtRow(int arow) const
523{ return m ? (r == arow) ? *this : m->sibling(arow, c, *this) : QModelIndex(); }
524
525inline QVariant QModelIndex::data(int arole) const
526{ return m ? m->data(*this, arole) : QVariant(); }
527
528inline void QModelIndex::multiData(QModelRoleDataSpan roleDataSpan) const
529{ if (m) m->multiData(*this, roleDataSpan); }
530
532{ return m ? m->flags(*this) : Qt::ItemFlags(); }
533
534inline size_t qHash(const QModelIndex &index, size_t seed = 0) noexcept
535{
536#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)
537 return qHashMulti(seed, index.row(), index.column(), index.internalId());
538#else
539 return size_t((size_t(index.row()) << 4) + size_t(index.column()) + index.internalId()) ^ seed;
540#endif
541}
542
543QT_END_NAMESPACE
544
545QT_DECL_METATYPE_EXTERN(QModelIndexList, Q_CORE_EXPORT)
546
547#endif // QABSTRACTITEMMODEL_H
Definition qmap.h:295
\inmodule QtCore
QModelIndex siblingAtColumn(int column) const
Returns the sibling at column for the current row.
QVariant data(int role=Qt::DisplayRole) const
Returns the data for the given role for the item referred to by the index, or a default-constructed Q...
constexpr int row() const noexcept
Returns the row this model index refers to.
friend constexpr bool comparesEqual(const QModelIndex &lhs, const QModelIndex &rhs) noexcept
QModelIndex siblingAtRow(int row) const
Returns the sibling at row for the current column.
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.
Qt::ItemFlags flags() const
constexpr bool isValid() const noexcept
Returns {true} if this model index is valid; otherwise returns {false}.
void * internalPointer() const noexcept
Returns a {void} {*} pointer used by the model to associate the index with the internal data structur...
friend constexpr Qt::strong_ordering compareThreeWay(const QModelIndex &lhs, const QModelIndex &rhs) noexcept
void multiData(QModelRoleDataSpan roleDataSpan) const
constexpr QModelIndex() noexcept
Creates a new empty model index.
constexpr int column() const noexcept
Returns the column this model index refers to.
QModelIndex sibling(int row, int column) const
Returns the sibling at row and column.
constexpr quintptr internalId() const noexcept
Returns a {quintptr} used by the model to associate the index with the internal data structure.
const void * constInternalPointer() const noexcept
Returns a {const void} {*} pointer used by the model to associate the index with the internal data st...
constexpr qsizetype size() const noexcept
Returns the length 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 QModelRoleData * begin() const noexcept
Returns a pointer to the beginning of the span represented by this object.
constexpr QModelRoleDataSpan() noexcept
Constructs an empty QModelRoleDataSpan.
constexpr qsizetype length() const noexcept
Returns the length 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...
constexpr QModelRoleData & operator[](qsizetype index) const
Returns a modifiable reference to the QModelRoleData at position index in the span.
constexpr QModelRoleData * data() const noexcept
Returns a pointer to the beginning 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(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...
\inmodule QtCore
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.
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.
QModelRoleData(int role) noexcept
Constructs a QModelRoleData object for the given role.
constexpr const QVariant & data() const noexcept
Returns the data held by this object.
Combined button and popup list for selecting options.
bool comparesEqual(const QPersistentModelIndex &lhs, const QModelIndex &rhs) noexcept
Qt::strong_ordering compareThreeWay(const QPersistentModelIndex &lhs, const QPersistentModelIndex &rhs) noexcept
static uint typeOfVariant(const QVariant &value)
QDebug operator<<(QDebug dbg, const QModelIndex &idx)
Qt::strong_ordering compareThreeWay(const QPersistentModelIndex &lhs, const QModelIndex &rhs) noexcept
QDebug operator<<(QDebug dbg, const QPersistentModelIndex &idx)
bool comparesEqual(const QPersistentModelIndex &lhs, const QPersistentModelIndex &rhs) noexcept
Q_GLOBAL_STATIC(DefaultRoleNames, qDefaultRoleNames, { { Qt::DisplayRole, "display" }, { Qt::DecorationRole, "decoration" }, { Qt::EditRole, "edit" }, { Qt::ToolTipRole, "toolTip" }, { Qt::StatusTipRole, "statusTip" }, { Qt::WhatsThisRole, "whatsThis" }, }) const QHash< int
size_t qHash(const QModelIndex &index, size_t seed=0) noexcept
Q_DECLARE_TYPEINFO(QModelRoleDataSpan, Q_RELOCATABLE_TYPE)
QT_REQUIRE_CONFIG(itemmodel)
QList< QModelIndex > QModelIndexList
size_t qHash(const QPersistentModelIndex &index, size_t seed=0) noexcept
Q_DECLARE_TYPEINFO(QModelIndex, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(QModelRoleData, Q_RELOCATABLE_TYPE)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2582
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)