diff options
Diffstat (limited to 'src/corelib/itemmodels/qabstractitemmodel.cpp')
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.cpp | 102 |
1 files changed, 54 insertions, 48 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index c1749526bc..216db3b42a 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -288,6 +288,9 @@ void QPersistentModelIndexData::destroy(QPersistentModelIndexData *data) \brief The QPersistentModelIndex class is used to locate data in a data model. \ingroup model-view + \compares strong + \compareswith strong QModelIndex + \endcompareswith A QPersistentModelIndex is a model index that can be stored by an application, and later used to access information in a model. @@ -375,45 +378,53 @@ QPersistentModelIndex::~QPersistentModelIndex() } /*! - Returns \c{true} if this persistent model index is equal to the \a other - persistent model index; otherwise returns \c{false}. + \fn bool QPersistentModelIndex::operator==(const QPersistentModelIndex &lhs, const QPersistentModelIndex &rhs) + Returns \c{true} if \a lhs persistent model index is equal to the \a rhs + persistent model index; otherwise returns \c{false}. - The internal data pointer, row, column, and model values in the persistent - model index are used when comparing with another persistent model index. + The internal data pointer, row, column, and model values in the persistent + model index are used when comparing with another persistent model index. */ -bool QPersistentModelIndex::operator==(const QPersistentModelIndex &other) const noexcept +/*! + \fn bool QPersistentModelIndex::operator!=(const QPersistentModelIndex &lhs, const QPersistentModelIndex &rhs) + \since 4.2 + + Returns \c{true} if \a lhs persistent model index is not equal to the \a rhs + persistent model index; otherwise returns \c{false}. +*/ +bool comparesEqual(const QPersistentModelIndex &lhs, const QPersistentModelIndex &rhs) noexcept { - if (d && other.d) - return d->index == other.d->index; - return d == other.d; + if (lhs.d && rhs.d) + return lhs.d->index == rhs.d->index; + return lhs.d == rhs.d; } /*! + \fn bool QPersistentModelIndex::operator<(const QPersistentModelIndex &lhs, const QPersistentModelIndex &rhs) \since 4.1 - Returns \c{true} if this persistent model index is smaller than the \a other + Returns \c{true} if \a lhs persistent model index is smaller than the \a rhs persistent model index; otherwise returns \c{false}. The internal data pointer, row, column, and model values in the persistent model index are used when comparing with another persistent model index. */ - -bool QPersistentModelIndex::operator<(const QPersistentModelIndex &other) const noexcept +Qt::strong_ordering compareThreeWay(const QPersistentModelIndex &lhs, + const QPersistentModelIndex &rhs) noexcept { - if (d && other.d) - return d->index < other.d->index; + if (lhs.d && rhs.d) + return compareThreeWay(lhs.d->index, rhs.d->index); - return std::less<>{}(d, other.d); + using Qt::totally_ordered_wrapper; + return compareThreeWay(totally_ordered_wrapper{lhs.d}, totally_ordered_wrapper{rhs.d}); } -/*! - \fn bool QPersistentModelIndex::operator!=(const QPersistentModelIndex &other) const - \since 4.2 - - Returns \c{true} if this persistent model index is not equal to the \a - other persistent model index; otherwise returns \c{false}. -*/ +Qt::strong_ordering compareThreeWay(const QPersistentModelIndex &lhs, + const QModelIndex &rhs) noexcept +{ + return compareThreeWay(lhs.d ? lhs.d->index : QModelIndex{}, rhs); +} /*! Sets the persistent model index to refer to the same item in a model @@ -470,32 +481,26 @@ QPersistentModelIndex::operator QModelIndex() const } /*! - Returns \c{true} if this persistent model index refers to the same location as - the \a other model index; otherwise returns \c{false}. + \fn bool QPersistentModelIndex::operator==(const QPersistentModelIndex &lhs, const QModelIndex &rhs) + Returns \c{true} if \a lhs persistent model index refers to the same location as + the \a rhs model index; otherwise returns \c{false}. The internal data pointer, row, column, and model values in the persistent model index are used when comparing with another model index. -*/ - -bool QPersistentModelIndex::operator==(const QModelIndex &other) const noexcept -{ - if (d) - return d->index == other; - return !other.isValid(); -} + */ /*! - \fn bool QPersistentModelIndex::operator!=(const QModelIndex &other) const + \fn bool QPersistentModelIndex::operator!=(const QPersistentModelIndex &lhs, const QModelIndex &rhs) - Returns \c{true} if this persistent model index does not refer to the same - location as the \a other model index; otherwise returns \c{false}. + Returns \c{true} if \a lhs persistent model index does not refer to the same + location as the \a rhs model index; otherwise returns \c{false}. */ -bool QPersistentModelIndex::operator!=(const QModelIndex &other) const noexcept +bool comparesEqual(const QPersistentModelIndex &lhs, const QModelIndex &rhs) noexcept { - if (d) - return d->index != other; - return other.isValid(); + if (lhs.d) + return lhs.d->index == rhs; + return !rhs.isValid(); } /*! @@ -686,6 +691,7 @@ QDebug operator<<(QDebug dbg, const QPersistentModelIndex &idx) class QEmptyItemModel : public QAbstractItemModel { + Q_OBJECT public: explicit QEmptyItemModel(QObject *parent = nullptr) : QAbstractItemModel(parent) {} QModelIndex index(int, int, const QModelIndex &) const override { return QModelIndex(); } @@ -1157,6 +1163,7 @@ void QAbstractItemModel::resetInternalData() \ingroup model-view + \compares strong This class is used as an index into item models derived from QAbstractItemModel. The index is used by item views, delegates, and @@ -1327,24 +1334,22 @@ void QAbstractItemModel::resetInternalData() */ /*! - \fn bool QModelIndex::operator==(const QModelIndex &other) const + \fn bool QModelIndex::operator==(const QModelIndex &lhs, const QModelIndex &rhs) - Returns \c{true} if this model index refers to the same location as the - \a other model index; otherwise returns \c{false}. + Returns \c{true} if \a lhs model index refers to the same location as the + \a rhs model index; otherwise returns \c{false}. The internal data pointer, row, column, and model values are used when comparing with another model index. */ - /*! - \fn bool QModelIndex::operator!=(const QModelIndex &other) const + \fn bool QModelIndex::operator!=(const QModelIndex &lhs, const QModelIndex &rhs) - Returns \c{true} if this model index does not refer to the same location as - the \a other model index; otherwise returns \c{false}. + Returns \c{true} if \a lhs model index does not refer to the same location as + the \a rhs model index; otherwise returns \c{false}. */ - /*! \fn QModelIndex QModelIndex::parent() const @@ -4123,10 +4128,10 @@ bool QAbstractListModel::dropMimeData(const QMimeData *data, Qt::DropAction acti */ /*! - \fn bool QModelIndex::operator<(const QModelIndex &other) const + \fn bool QModelIndex::operator<(const QModelIndex &lhs, const QModelIndex &rhs) \since 4.1 - Returns \c{true} if this model index is smaller than the \a other + Returns \c{true} if \a lhs model index is smaller than the \a rhs model index; otherwise returns \c{false}. The less than calculation is not directly useful to developers - the way that indexes @@ -4169,3 +4174,4 @@ void QAbstractItemModelPrivate::Persistent::insertMultiAtEnd(const QModelIndex& QT_END_NAMESPACE #include "moc_qabstractitemmodel.cpp" +#include "qabstractitemmodel.moc" |