Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-12 08:49:39

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