File indexing completed on 2025-09-17 09:09:06
0001
0002
0003
0004
0005 #ifndef QABSTRACTITEMMODEL_H
0006 #define QABSTRACTITEMMODEL_H
0007
0008 #include <QtCore/qcompare.h>
0009 #include <QtCore/qhash.h>
0010 #include <QtCore/qlist.h>
0011 #include <QtCore/qobject.h>
0012 #include <QtCore/qvariant.h>
0013
0014 QT_REQUIRE_CONFIG(itemmodel);
0015
0016 QT_BEGIN_NAMESPACE
0017
0018 class QModelRoleData
0019 {
0020 int m_role;
0021 QVariant m_data;
0022
0023 public:
0024 explicit QModelRoleData(int role) noexcept
0025 : m_role(role)
0026 {}
0027
0028 constexpr int role() const noexcept { return m_role; }
0029 constexpr QVariant &data() noexcept { return m_data; }
0030 constexpr const QVariant &data() const noexcept { return m_data; }
0031
0032 template <typename T>
0033 constexpr void setData(T &&value) noexcept(noexcept(m_data.setValue(std::forward<T>(value))))
0034 { m_data.setValue(std::forward<T>(value)); }
0035
0036 void clearData() noexcept { m_data.clear(); }
0037 };
0038
0039 Q_DECLARE_TYPEINFO(QModelRoleData, Q_RELOCATABLE_TYPE);
0040
0041 class QModelRoleDataSpan;
0042
0043 namespace QtPrivate {
0044 template <typename T, typename Enable = void>
0045 struct IsContainerCompatibleWithModelRoleDataSpan : std::false_type {};
0046
0047 template <typename T>
0048 struct IsContainerCompatibleWithModelRoleDataSpan<T, std::enable_if_t<std::conjunction_v<
0049
0050 std::is_convertible<decltype( std::data(std::declval<T &>()) ), QModelRoleData *>,
0051
0052 std::is_convertible<decltype( std::size(std::declval<T &>()) ), qsizetype>,
0053
0054 std::is_convertible<
0055 typename std::iterator_traits<decltype( std::begin(std::declval<T &>()) )>::value_type,
0056 QModelRoleData
0057 >,
0058 std::is_convertible<
0059 decltype( std::begin(std::declval<T &>()) != std::end(std::declval<T &>()) ),
0060 bool>,
0061
0062 std::negation<std::is_same<std::decay_t<T>, QModelRoleDataSpan>>
0063 >>> : std::true_type {};
0064 }
0065
0066 class QModelRoleDataSpan
0067 {
0068 QModelRoleData *m_modelRoleData = nullptr;
0069 qsizetype m_len = 0;
0070
0071 template <typename T>
0072 using if_compatible_container = std::enable_if_t<QtPrivate::IsContainerCompatibleWithModelRoleDataSpan<T>::value, bool>;
0073
0074 public:
0075 constexpr QModelRoleDataSpan() noexcept {}
0076
0077 constexpr QModelRoleDataSpan(QModelRoleData &modelRoleData) noexcept
0078 : m_modelRoleData(&modelRoleData),
0079 m_len(1)
0080 {}
0081
0082 constexpr QModelRoleDataSpan(QModelRoleData *modelRoleData, qsizetype len)
0083 : m_modelRoleData(modelRoleData),
0084 m_len(len)
0085 {}
0086
0087 template <typename Container, if_compatible_container<Container> = true>
0088 constexpr QModelRoleDataSpan(Container &c) noexcept(noexcept(std::data(c)) && noexcept(std::size(c)))
0089 : m_modelRoleData(std::data(c)),
0090 m_len(qsizetype(std::size(c)))
0091 {}
0092
0093 constexpr qsizetype size() const noexcept { return m_len; }
0094 constexpr qsizetype length() const noexcept { return m_len; }
0095 constexpr QModelRoleData *data() const noexcept { return m_modelRoleData; }
0096 constexpr QModelRoleData *begin() const noexcept { return m_modelRoleData; }
0097 constexpr QModelRoleData *end() const noexcept { return m_modelRoleData + m_len; }
0098 constexpr QModelRoleData &operator[](qsizetype index) const { return m_modelRoleData[index]; }
0099
0100 constexpr QVariant *dataForRole(int role) const
0101 {
0102 #ifdef __cpp_lib_constexpr_algorithms
0103 auto result = std::find_if(begin(), end(), [role](const QModelRoleData &roleData) {
0104 return roleData.role() == role;
0105 });
0106 #else
0107 auto result = begin();
0108 const auto e = end();
0109 for (; result != e; ++result) {
0110 if (result->role() == role)
0111 break;
0112 }
0113 #endif
0114
0115 return Q_ASSERT(result != end()), &result->data();
0116 }
0117 };
0118
0119 Q_DECLARE_TYPEINFO(QModelRoleDataSpan, Q_RELOCATABLE_TYPE);
0120
0121 class QAbstractItemModel;
0122 class QPersistentModelIndex;
0123
0124 class QModelIndex
0125 {
0126 friend class QAbstractItemModel;
0127 public:
0128 constexpr inline QModelIndex() noexcept : r(-1), c(-1), i(0), m(nullptr) {}
0129
0130 constexpr inline int row() const noexcept { return r; }
0131 constexpr inline int column() const noexcept { return c; }
0132 constexpr inline quintptr internalId() const noexcept { return i; }
0133 inline void *internalPointer() const noexcept { return reinterpret_cast<void*>(i); }
0134 inline const void *constInternalPointer() const noexcept { return reinterpret_cast<const void *>(i); }
0135 inline QModelIndex parent() const;
0136 inline QModelIndex sibling(int row, int column) const;
0137 inline QModelIndex siblingAtColumn(int column) const;
0138 inline QModelIndex siblingAtRow(int row) const;
0139 inline QVariant data(int role = Qt::DisplayRole) const;
0140 inline void multiData(QModelRoleDataSpan roleDataSpan) const;
0141 inline Qt::ItemFlags flags() const;
0142 constexpr inline const QAbstractItemModel *model() const noexcept { return m.get(); }
0143 constexpr inline bool isValid() const noexcept { return (r >= 0) && (c >= 0) && (m != nullptr); }
0144
0145 private:
0146 friend constexpr bool comparesEqual(const QModelIndex &lhs, const QModelIndex &rhs) noexcept
0147 {
0148 return lhs.r == rhs.r && lhs.c == rhs.c && lhs.i == rhs.i && lhs.m == rhs.m;
0149 }
0150 friend constexpr Qt::strong_ordering compareThreeWay(const QModelIndex &lhs, const QModelIndex &rhs) noexcept
0151 {
0152 if (auto val = Qt::compareThreeWay(lhs.r, rhs.r); !is_eq(val))
0153 return val;
0154 if (auto val = Qt::compareThreeWay(lhs.c, rhs.c); !is_eq(val))
0155 return val;
0156 if (auto val = Qt::compareThreeWay(lhs.i, rhs.i); !is_eq(val))
0157 return val;
0158 if (auto val = Qt::compareThreeWay(lhs.m, rhs.m); !is_eq(val))
0159 return val;
0160 return Qt::strong_ordering::equivalent;
0161 }
0162 Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QModelIndex)
0163 private:
0164 inline QModelIndex(int arow, int acolumn, const void *ptr, const QAbstractItemModel *amodel) noexcept
0165 : r(arow), c(acolumn), i(reinterpret_cast<quintptr>(ptr)), m(amodel) {}
0166 constexpr inline QModelIndex(int arow, int acolumn, quintptr id, const QAbstractItemModel *amodel) noexcept
0167 : r(arow), c(acolumn), i(id), m(amodel) {}
0168 int r, c;
0169 quintptr i;
0170 Qt::totally_ordered_wrapper<const QAbstractItemModel *> m;
0171 };
0172 Q_DECLARE_TYPEINFO(QModelIndex, Q_RELOCATABLE_TYPE);
0173
0174 #ifndef QT_NO_DEBUG_STREAM
0175 Q_CORE_EXPORT QDebug operator<<(QDebug, const QModelIndex &);
0176 #endif
0177
0178 class QPersistentModelIndexData;
0179
0180
0181 size_t qHash(const QPersistentModelIndex &index, size_t seed = 0) noexcept;
0182
0183 class Q_CORE_EXPORT QPersistentModelIndex
0184 {
0185 public:
0186 QPersistentModelIndex();
0187 QPersistentModelIndex(const QModelIndex &index);
0188 QPersistentModelIndex(const QPersistentModelIndex &other);
0189 ~QPersistentModelIndex();
0190 #if QT_CORE_REMOVED_SINCE(6, 8)
0191 bool operator<(const QPersistentModelIndex &other) const noexcept;
0192 bool operator==(const QPersistentModelIndex &other) const noexcept;
0193 inline bool operator!=(const QPersistentModelIndex &other) const noexcept
0194 { return !operator==(other); }
0195 #endif
0196 QPersistentModelIndex &operator=(const QPersistentModelIndex &other);
0197 inline QPersistentModelIndex(QPersistentModelIndex &&other) noexcept
0198 : d(std::exchange(other.d, nullptr)) {}
0199 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPersistentModelIndex)
0200 void swap(QPersistentModelIndex &other) noexcept { qt_ptr_swap(d, other.d); }
0201 #if QT_CORE_REMOVED_SINCE(6, 8)
0202 bool operator==(const QModelIndex &other) const noexcept;
0203 bool operator!=(const QModelIndex &other) const noexcept;
0204 #endif
0205 QPersistentModelIndex &operator=(const QModelIndex &other);
0206 operator QModelIndex() const;
0207 int row() const;
0208 int column() const;
0209 void *internalPointer() const;
0210 const void *constInternalPointer() const;
0211 quintptr internalId() const;
0212 QModelIndex parent() const;
0213 QModelIndex sibling(int row, int column) const;
0214 QVariant data(int role = Qt::DisplayRole) const;
0215 void multiData(QModelRoleDataSpan roleDataSpan) const;
0216 Qt::ItemFlags flags() const;
0217 const QAbstractItemModel *model() const;
0218 bool isValid() const;
0219 private:
0220 QPersistentModelIndexData *d;
0221 friend size_t qHash(const QPersistentModelIndex &, size_t seed) noexcept;
0222 friend bool qHashEquals(const QPersistentModelIndex &a, const QPersistentModelIndex &b) noexcept
0223 { return a.d == b.d; }
0224 friend Q_CORE_EXPORT bool
0225 comparesEqual(const QPersistentModelIndex &lhs, const QPersistentModelIndex &rhs) noexcept;
0226 friend Q_CORE_EXPORT bool
0227 comparesEqual(const QPersistentModelIndex &lhs, const QModelIndex &rhs) noexcept;
0228 friend Q_CORE_EXPORT Qt::strong_ordering
0229 compareThreeWay(const QPersistentModelIndex &lhs, const QPersistentModelIndex &rhs) noexcept;
0230 friend Q_CORE_EXPORT Qt::strong_ordering
0231 compareThreeWay(const QPersistentModelIndex &lhs, const QModelIndex &rhs) noexcept;
0232 #if !QT_CORE_REMOVED_SINCE(6, 8)
0233 Q_DECLARE_STRONGLY_ORDERED(QPersistentModelIndex)
0234 Q_DECLARE_STRONGLY_ORDERED(QPersistentModelIndex, QModelIndex)
0235 #endif
0236 #ifndef QT_NO_DEBUG_STREAM
0237 friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QPersistentModelIndex &);
0238 #endif
0239 };
0240 Q_DECLARE_SHARED(QPersistentModelIndex)
0241
0242 inline size_t qHash(const QPersistentModelIndex &index, size_t seed) noexcept
0243 { return qHash(index.d, seed); }
0244
0245
0246 #ifndef QT_NO_DEBUG_STREAM
0247 Q_CORE_EXPORT QDebug operator<<(QDebug, const QPersistentModelIndex &);
0248 #endif
0249
0250 typedef QList<QModelIndex> QModelIndexList;
0251
0252 class QMimeData;
0253 class QAbstractItemModelPrivate;
0254 class QTransposeProxyModelPrivate;
0255 template <class Key, class T> class QMap;
0256
0257
0258 class Q_CORE_EXPORT QAbstractItemModel : public QObject
0259 {
0260 Q_OBJECT
0261
0262 friend class QPersistentModelIndexData;
0263 friend class QAbstractItemViewPrivate;
0264 friend class QAbstractProxyModel;
0265 public:
0266
0267 explicit QAbstractItemModel(QObject *parent = nullptr);
0268 virtual ~QAbstractItemModel();
0269
0270 Q_INVOKABLE bool hasIndex(int row, int column, const QModelIndex &parent = QModelIndex()) const;
0271 Q_INVOKABLE virtual QModelIndex index(int row, int column,
0272 const QModelIndex &parent = QModelIndex()) const = 0;
0273 Q_INVOKABLE virtual QModelIndex parent(const QModelIndex &child) const = 0;
0274
0275 Q_INVOKABLE virtual QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
0276 Q_INVOKABLE virtual int rowCount(const QModelIndex &parent = QModelIndex()) const = 0;
0277 Q_INVOKABLE virtual int columnCount(const QModelIndex &parent = QModelIndex()) const = 0;
0278 Q_INVOKABLE virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
0279
0280 Q_INVOKABLE virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const = 0;
0281 Q_INVOKABLE virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
0282
0283 Q_INVOKABLE virtual QVariant headerData(int section, Qt::Orientation orientation,
0284 int role = Qt::DisplayRole) const;
0285 virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value,
0286 int role = Qt::EditRole);
0287
0288 virtual QMap<int, QVariant> itemData(const QModelIndex &index) const;
0289 virtual bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles);
0290 virtual bool clearItemData(const QModelIndex &index);
0291
0292 virtual QStringList mimeTypes() const;
0293 virtual QMimeData *mimeData(const QModelIndexList &indexes) const;
0294 virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action,
0295 int row, int column, const QModelIndex &parent) const;
0296 virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action,
0297 int row, int column, const QModelIndex &parent);
0298 virtual Qt::DropActions supportedDropActions() const;
0299 virtual Qt::DropActions supportedDragActions() const;
0300
0301 Q_INVOKABLE Q_REVISION(6, 4) virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
0302 Q_INVOKABLE Q_REVISION(6, 4) virtual bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex());
0303 Q_INVOKABLE Q_REVISION(6, 4) virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
0304 Q_INVOKABLE Q_REVISION(6, 4) virtual bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex());
0305 Q_INVOKABLE Q_REVISION(6, 4) virtual bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count,
0306 const QModelIndex &destinationParent, int destinationChild);
0307 Q_INVOKABLE Q_REVISION(6, 4) virtual bool moveColumns(const QModelIndex &sourceParent, int sourceColumn, int count,
0308 const QModelIndex &destinationParent, int destinationChild);
0309
0310 Q_INVOKABLE Q_REVISION(6, 4) inline bool insertRow(int row, const QModelIndex &parent = QModelIndex());
0311 Q_INVOKABLE Q_REVISION(6, 4) inline bool insertColumn(int column, const QModelIndex &parent = QModelIndex());
0312 Q_INVOKABLE Q_REVISION(6, 4) inline bool removeRow(int row, const QModelIndex &parent = QModelIndex());
0313 Q_INVOKABLE Q_REVISION(6, 4) inline bool removeColumn(int column, const QModelIndex &parent = QModelIndex());
0314 Q_INVOKABLE Q_REVISION(6, 4) inline bool moveRow(const QModelIndex &sourceParent, int sourceRow,
0315 const QModelIndex &destinationParent, int destinationChild);
0316 Q_INVOKABLE Q_REVISION(6, 4) inline bool moveColumn(const QModelIndex &sourceParent, int sourceColumn,
0317 const QModelIndex &destinationParent, int destinationChild);
0318
0319 Q_INVOKABLE virtual void fetchMore(const QModelIndex &parent);
0320 Q_INVOKABLE virtual bool canFetchMore(const QModelIndex &parent) const;
0321 Q_INVOKABLE virtual Qt::ItemFlags flags(const QModelIndex &index) const;
0322 Q_INVOKABLE Q_REVISION(6, 4) virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
0323 virtual QModelIndex buddy(const QModelIndex &index) const;
0324 Q_INVOKABLE virtual QModelIndexList match(const QModelIndex &start, int role,
0325 const QVariant &value, int hits = 1,
0326 Qt::MatchFlags flags =
0327 Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const;
0328 virtual QSize span(const QModelIndex &index) const;
0329
0330 virtual QHash<int,QByteArray> roleNames() const;
0331
0332 using QObject::parent;
0333
0334 enum LayoutChangeHint
0335 {
0336 NoLayoutChangeHint,
0337 VerticalSortHint,
0338 HorizontalSortHint
0339 };
0340 Q_ENUM(LayoutChangeHint)
0341
0342 enum class CheckIndexOption {
0343 NoOption = 0x0000,
0344 IndexIsValid = 0x0001,
0345 DoNotUseParent = 0x0002,
0346 ParentIsInvalid = 0x0004,
0347 };
0348 Q_ENUM(CheckIndexOption)
0349 Q_DECLARE_FLAGS(CheckIndexOptions, CheckIndexOption)
0350
0351 [[nodiscard]] bool checkIndex(const QModelIndex &index, CheckIndexOptions options = CheckIndexOption::NoOption) const;
0352
0353 virtual void multiData(const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const;
0354
0355 Q_SIGNALS:
0356 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
0357 const QList<int> &roles = QList<int>());
0358 void headerDataChanged(Qt::Orientation orientation, int first, int last);
0359 void layoutChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint);
0360 void layoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint);
0361
0362 void rowsAboutToBeInserted(const QModelIndex &parent, int first, int last, QPrivateSignal);
0363 void rowsInserted(const QModelIndex &parent, int first, int last, QPrivateSignal);
0364
0365 void rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal);
0366 void rowsRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal);
0367
0368 void columnsAboutToBeInserted(const QModelIndex &parent, int first, int last, QPrivateSignal);
0369 void columnsInserted(const QModelIndex &parent, int first, int last, QPrivateSignal);
0370
0371 void columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal);
0372 void columnsRemoved(const QModelIndex &parent, int first, int last, QPrivateSignal);
0373
0374 void modelAboutToBeReset(QPrivateSignal);
0375 void modelReset(QPrivateSignal);
0376
0377 void rowsAboutToBeMoved( const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow, QPrivateSignal);
0378 void rowsMoved( const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow, QPrivateSignal);
0379
0380 void columnsAboutToBeMoved( const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn, QPrivateSignal);
0381 void columnsMoved( const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn, QPrivateSignal);
0382
0383 public Q_SLOTS:
0384 virtual bool submit();
0385 virtual void revert();
0386
0387 protected Q_SLOTS:
0388 virtual void resetInternalData();
0389
0390 protected:
0391 QAbstractItemModel(QAbstractItemModelPrivate &dd, QObject *parent = nullptr);
0392
0393 inline QModelIndex createIndex(int row, int column, const void *data = nullptr) const;
0394 inline QModelIndex createIndex(int row, int column, quintptr id) const;
0395
0396 void encodeData(const QModelIndexList &indexes, QDataStream &stream) const;
0397 bool decodeData(int row, int column, const QModelIndex &parent, QDataStream &stream);
0398
0399 void beginInsertRows(const QModelIndex &parent, int first, int last);
0400 void endInsertRows();
0401
0402 void beginRemoveRows(const QModelIndex &parent, int first, int last);
0403 void endRemoveRows();
0404
0405 bool beginMoveRows(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow);
0406 void endMoveRows();
0407
0408 void beginInsertColumns(const QModelIndex &parent, int first, int last);
0409 void endInsertColumns();
0410
0411 void beginRemoveColumns(const QModelIndex &parent, int first, int last);
0412 void endRemoveColumns();
0413
0414 bool beginMoveColumns(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationColumn);
0415 void endMoveColumns();
0416
0417 void beginResetModel();
0418 void endResetModel();
0419
0420 void changePersistentIndex(const QModelIndex &from, const QModelIndex &to);
0421 void changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to);
0422 QModelIndexList persistentIndexList() const;
0423
0424 private:
0425 Q_DECLARE_PRIVATE(QAbstractItemModel)
0426 Q_DISABLE_COPY(QAbstractItemModel)
0427 };
0428
0429 Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractItemModel::CheckIndexOptions)
0430
0431 inline bool QAbstractItemModel::insertRow(int arow, const QModelIndex &aparent)
0432 { return insertRows(arow, 1, aparent); }
0433 inline bool QAbstractItemModel::insertColumn(int acolumn, const QModelIndex &aparent)
0434 { return insertColumns(acolumn, 1, aparent); }
0435 inline bool QAbstractItemModel::removeRow(int arow, const QModelIndex &aparent)
0436 { return removeRows(arow, 1, aparent); }
0437 inline bool QAbstractItemModel::removeColumn(int acolumn, const QModelIndex &aparent)
0438 { return removeColumns(acolumn, 1, aparent); }
0439 inline bool QAbstractItemModel::moveRow(const QModelIndex &sourceParent, int sourceRow,
0440 const QModelIndex &destinationParent, int destinationChild)
0441 { return moveRows(sourceParent, sourceRow, 1, destinationParent, destinationChild); }
0442 inline bool QAbstractItemModel::moveColumn(const QModelIndex &sourceParent, int sourceColumn,
0443 const QModelIndex &destinationParent, int destinationChild)
0444 { return moveColumns(sourceParent, sourceColumn, 1, destinationParent, destinationChild); }
0445 inline QModelIndex QAbstractItemModel::createIndex(int arow, int acolumn, const void *adata) const
0446 { return QModelIndex(arow, acolumn, adata, this); }
0447 inline QModelIndex QAbstractItemModel::createIndex(int arow, int acolumn, quintptr aid) const
0448 { return QModelIndex(arow, acolumn, aid, this); }
0449
0450 class Q_CORE_EXPORT QAbstractTableModel : public QAbstractItemModel
0451 {
0452 Q_OBJECT
0453
0454 public:
0455 explicit QAbstractTableModel(QObject *parent = nullptr);
0456 ~QAbstractTableModel();
0457
0458 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0459 QModelIndex sibling(int row, int column, const QModelIndex &idx) const override;
0460 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
0461 int row, int column, const QModelIndex &parent) override;
0462
0463 Qt::ItemFlags flags(const QModelIndex &index) const override;
0464
0465 using QObject::parent;
0466
0467 protected:
0468 QAbstractTableModel(QAbstractItemModelPrivate &dd, QObject *parent);
0469
0470 private:
0471 Q_DISABLE_COPY(QAbstractTableModel)
0472 QModelIndex parent(const QModelIndex &child) const override;
0473 bool hasChildren(const QModelIndex &parent) const override;
0474 };
0475
0476 class Q_CORE_EXPORT QAbstractListModel : public QAbstractItemModel
0477 {
0478 Q_OBJECT
0479
0480 public:
0481 explicit QAbstractListModel(QObject *parent = nullptr);
0482 ~QAbstractListModel();
0483
0484 QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override;
0485 QModelIndex sibling(int row, int column, const QModelIndex &idx) const override;
0486 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
0487 int row, int column, const QModelIndex &parent) override;
0488
0489 Qt::ItemFlags flags(const QModelIndex &index) const override;
0490
0491 using QObject::parent;
0492
0493 protected:
0494 QAbstractListModel(QAbstractItemModelPrivate &dd, QObject *parent);
0495
0496 private:
0497 Q_DISABLE_COPY(QAbstractListModel)
0498 QModelIndex parent(const QModelIndex &child) const override;
0499 int columnCount(const QModelIndex &parent) const override;
0500 bool hasChildren(const QModelIndex &parent) const override;
0501 };
0502
0503
0504
0505 inline QModelIndex QModelIndex::parent() const
0506 { return m ? m->parent(*this) : QModelIndex(); }
0507
0508 inline QModelIndex QModelIndex::sibling(int arow, int acolumn) const
0509 { return m ? (r == arow && c == acolumn) ? *this : m->sibling(arow, acolumn, *this) : QModelIndex(); }
0510
0511 inline QModelIndex QModelIndex::siblingAtColumn(int acolumn) const
0512 { return m ? (c == acolumn) ? *this : m->sibling(r, acolumn, *this) : QModelIndex(); }
0513
0514 inline QModelIndex QModelIndex::siblingAtRow(int arow) const
0515 { return m ? (r == arow) ? *this : m->sibling(arow, c, *this) : QModelIndex(); }
0516
0517 inline QVariant QModelIndex::data(int arole) const
0518 { return m ? m->data(*this, arole) : QVariant(); }
0519
0520 inline void QModelIndex::multiData(QModelRoleDataSpan roleDataSpan) const
0521 { if (m) m->multiData(*this, roleDataSpan); }
0522
0523 inline Qt::ItemFlags QModelIndex::flags() const
0524 { return m ? m->flags(*this) : Qt::ItemFlags(); }
0525
0526 inline size_t qHash(const QModelIndex &index, size_t seed = 0) noexcept
0527 {
0528 #if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)
0529 return qHashMulti(seed, index.row(), index.column(), index.internalId());
0530 #else
0531 return size_t((size_t(index.row()) << 4) + size_t(index.column()) + index.internalId()) ^ seed;
0532 #endif
0533 }
0534
0535 QT_END_NAMESPACE
0536
0537 QT_DECL_METATYPE_EXTERN(QModelIndexList, Q_CORE_EXPORT)
0538
0539 #endif