diff options
Diffstat (limited to 'src/corelib/itemmodels/qabstractitemmodel.h')
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.h | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h index e56412241a..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(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 @@ -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 |