diff options
Diffstat (limited to 'src/corelib/itemmodels/qabstractitemmodel.h')
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.h | 88 |
1 files changed, 55 insertions, 33 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h index c4b07d0365..418fc6b864 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.h +++ b/src/corelib/itemmodels/qabstractitemmodel.h @@ -5,11 +5,14 @@ #ifndef QABSTRACTITEMMODEL_H #define QABSTRACTITEMMODEL_H +#include <QtCore/qcompare.h> #include <QtCore/qhash.h> #include <QtCore/qlist.h> #include <QtCore/qobject.h> #include <QtCore/qvariant.h> +#include <tuple> + QT_REQUIRE_CONFIG(itemmodel); QT_BEGIN_NAMESPACE @@ -138,19 +141,16 @@ public: inline QVariant data(int role = Qt::DisplayRole) const; inline void multiData(QModelRoleDataSpan roleDataSpan) const; inline Qt::ItemFlags flags() const; - constexpr inline const QAbstractItemModel *model() const noexcept { return m; } + constexpr inline const QAbstractItemModel *model() const noexcept { return m.get(); } constexpr inline bool isValid() const noexcept { return (r >= 0) && (c >= 0) && (m != nullptr); } - constexpr inline bool operator==(const QModelIndex &other) const noexcept - { return (other.r == r) && (other.i == i) && (other.c == c) && (other.m == m); } - constexpr inline bool operator!=(const QModelIndex &other) const noexcept - { return !(*this == other); } - constexpr inline bool operator<(const QModelIndex &other) const noexcept - { - return r < other.r - || (r == other.r && (c < other.c - || (c == other.c && (i < other.i - || (i == other.i && std::less<const QAbstractItemModel *>()(m, other.m)))))); - } + +private: + constexpr auto asTuple() const noexcept { return std::tie(r, c, i, m); } + friend constexpr bool comparesEqual(const QModelIndex &lhs, const QModelIndex &rhs) noexcept + { return lhs.asTuple() == rhs.asTuple(); } + friend constexpr Qt::strong_ordering compareThreeWay(const QModelIndex &lhs, const QModelIndex &rhs) noexcept + { return QtOrderingPrivate::compareThreeWayMulti(lhs.asTuple(), rhs.asTuple()); } + Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QModelIndex) private: inline QModelIndex(int arow, int acolumn, const void *ptr, const QAbstractItemModel *amodel) noexcept : r(arow), c(acolumn), i(reinterpret_cast<quintptr>(ptr)), m(amodel) {} @@ -158,7 +158,7 @@ private: : r(arow), c(acolumn), i(id), m(amodel) {} int r, c; quintptr i; - const QAbstractItemModel *m; + Qt::totally_ordered_wrapper<const QAbstractItemModel *> m; }; Q_DECLARE_TYPEINFO(QModelIndex, Q_RELOCATABLE_TYPE); @@ -178,17 +178,21 @@ public: QPersistentModelIndex(const QModelIndex &index); QPersistentModelIndex(const QPersistentModelIndex &other); ~QPersistentModelIndex(); - bool operator<(const QPersistentModelIndex &other) const; - bool operator==(const QPersistentModelIndex &other) const; - inline bool operator!=(const QPersistentModelIndex &other) const +#if QT_CORE_REMOVED_SINCE(6, 8) + bool operator<(const QPersistentModelIndex &other) const noexcept; + bool operator==(const QPersistentModelIndex &other) const noexcept; + inline bool operator!=(const QPersistentModelIndex &other) const noexcept { return !operator==(other); } +#endif QPersistentModelIndex &operator=(const QPersistentModelIndex &other); inline QPersistentModelIndex(QPersistentModelIndex &&other) noexcept - : d(qExchange(other.d, nullptr)) {} + : d(std::exchange(other.d, nullptr)) {} QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPersistentModelIndex) void swap(QPersistentModelIndex &other) noexcept { qt_ptr_swap(d, other.d); } - bool operator==(const QModelIndex &other) const; - bool operator!=(const QModelIndex &other) const; +#if QT_CORE_REMOVED_SINCE(6, 8) + bool operator==(const QModelIndex &other) const noexcept; + bool operator!=(const QModelIndex &other) const noexcept; +#endif QPersistentModelIndex &operator=(const QModelIndex &other); operator QModelIndex() const; int row() const; @@ -208,6 +212,18 @@ private: friend size_t qHash(const QPersistentModelIndex &, size_t seed) noexcept; friend bool qHashEquals(const QPersistentModelIndex &a, const QPersistentModelIndex &b) noexcept { return a.d == b.d; } + friend Q_CORE_EXPORT bool + comparesEqual(const QPersistentModelIndex &lhs, const QPersistentModelIndex &rhs) noexcept; + friend Q_CORE_EXPORT bool + comparesEqual(const QPersistentModelIndex &lhs, const QModelIndex &rhs) noexcept; + friend Q_CORE_EXPORT Qt::strong_ordering // ### Qt 7: partial_ordering? + compareThreeWay(const QPersistentModelIndex &lhs, const QPersistentModelIndex &rhs) noexcept; + friend Q_CORE_EXPORT Qt::strong_ordering // ### Qt 7: partial_ordering? + compareThreeWay(const QPersistentModelIndex &lhs, const QModelIndex &rhs) noexcept; +#if !QT_CORE_REMOVED_SINCE(6, 8) + Q_DECLARE_STRONGLY_ORDERED(QPersistentModelIndex) + Q_DECLARE_STRONGLY_ORDERED(QPersistentModelIndex, QModelIndex) +#endif #ifndef QT_NO_DEBUG_STREAM friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QPersistentModelIndex &); #endif @@ -273,28 +289,28 @@ public: virtual Qt::DropActions supportedDropActions() const; virtual Qt::DropActions supportedDragActions() const; - Q_INVOKABLE virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()); - Q_INVOKABLE virtual bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()); - Q_INVOKABLE virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); - Q_INVOKABLE virtual bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()); - Q_INVOKABLE virtual bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, + Q_INVOKABLE Q_REVISION(6, 4) virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()); + Q_INVOKABLE Q_REVISION(6, 4) virtual bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()); + Q_INVOKABLE Q_REVISION(6, 4) virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); + Q_INVOKABLE Q_REVISION(6, 4) virtual bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()); + Q_INVOKABLE Q_REVISION(6, 4) virtual bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild); - Q_INVOKABLE virtual bool moveColumns(const QModelIndex &sourceParent, int sourceColumn, int count, + Q_INVOKABLE Q_REVISION(6, 4) virtual bool moveColumns(const QModelIndex &sourceParent, int sourceColumn, int count, const QModelIndex &destinationParent, int destinationChild); - Q_INVOKABLE inline bool insertRow(int row, const QModelIndex &parent = QModelIndex()); - Q_INVOKABLE inline bool insertColumn(int column, const QModelIndex &parent = QModelIndex()); - Q_INVOKABLE inline bool removeRow(int row, const QModelIndex &parent = QModelIndex()); - Q_INVOKABLE inline bool removeColumn(int column, const QModelIndex &parent = QModelIndex()); - Q_INVOKABLE inline bool moveRow(const QModelIndex &sourceParent, int sourceRow, + Q_INVOKABLE Q_REVISION(6, 4) inline bool insertRow(int row, const QModelIndex &parent = QModelIndex()); + Q_INVOKABLE Q_REVISION(6, 4) inline bool insertColumn(int column, const QModelIndex &parent = QModelIndex()); + Q_INVOKABLE Q_REVISION(6, 4) inline bool removeRow(int row, const QModelIndex &parent = QModelIndex()); + Q_INVOKABLE Q_REVISION(6, 4) inline bool removeColumn(int column, const QModelIndex &parent = QModelIndex()); + Q_INVOKABLE Q_REVISION(6, 4) inline bool moveRow(const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild); - Q_INVOKABLE inline bool moveColumn(const QModelIndex &sourceParent, int sourceColumn, + Q_INVOKABLE Q_REVISION(6, 4) inline bool moveColumn(const QModelIndex &sourceParent, int sourceColumn, const QModelIndex &destinationParent, int destinationChild); Q_INVOKABLE virtual void fetchMore(const QModelIndex &parent); Q_INVOKABLE virtual bool canFetchMore(const QModelIndex &parent) const; Q_INVOKABLE virtual Qt::ItemFlags flags(const QModelIndex &index) const; - Q_INVOKABLE virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); + Q_INVOKABLE Q_REVISION(6, 4) virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); virtual QModelIndex buddy(const QModelIndex &index) const; Q_INVOKABLE virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits = 1, @@ -499,7 +515,13 @@ inline Qt::ItemFlags QModelIndex::flags() const { return m ? m->flags(*this) : Qt::ItemFlags(); } inline size_t qHash(const QModelIndex &index, size_t seed = 0) noexcept -{ return size_t((size_t(index.row()) << 4) + size_t(index.column()) + index.internalId()) ^ seed; } +{ +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) + return qHashMulti(seed, index.row(), index.column(), index.internalId()); +#else + return size_t((size_t(index.row()) << 4) + size_t(index.column()) + index.internalId()) ^ seed; +#endif +} QT_END_NAMESPACE |