QItemSelectionRange: use new comparison helper macros
Replace public operators operator==(), operator!=() of QItemSelectionRange class to friend methods comparesEqual(). Use QT_CORE_REMOVED_SINCE and removed_api.cpp to get rid of current comparison methods and replace them with a friend. Task-number: QTBUG-120304 Change-Id: Ideff990c942d5ee1c89a93ac2081cc5d7067b23f Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>bb10
parent
a87764789f
commit
6324075a2d
|
|
@ -959,6 +959,8 @@ bool QFileInfo::operator==(const QFileInfo &fileinfo) const
|
|||
return comparesEqual(*this, fileinfo);
|
||||
}
|
||||
|
||||
#include "qitemselectionmodel.h" // inlined API
|
||||
|
||||
#include "qjsonarray.h"
|
||||
|
||||
bool QJsonArray::operator==(const QJsonArray &other) const
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ QT_IMPL_METATYPE_EXTERN(QItemSelection)
|
|||
|
||||
\ingroup model-view
|
||||
|
||||
\compares equality
|
||||
|
||||
A QItemSelectionRange contains information about a range of
|
||||
selected items in a model. A range of items is a contiguous array
|
||||
of model items, extending to cover a number of adjacent rows and
|
||||
|
|
@ -216,17 +218,17 @@ QItemSelectionRange QItemSelectionRange::intersected(const QItemSelectionRange &
|
|||
}
|
||||
|
||||
/*!
|
||||
\fn bool QItemSelectionRange::operator==(const QItemSelectionRange &other) const
|
||||
\fn bool QItemSelectionRange::operator==(const QItemSelectionRange &lhs, const QItemSelectionRange &rhs)
|
||||
|
||||
Returns \c true if the selection range is exactly the same as the \a other
|
||||
Returns \c true if \a lhs selection range is exactly the same as the \a rhs
|
||||
range given; otherwise returns \c false.
|
||||
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QItemSelectionRange::operator!=(const QItemSelectionRange &other) const
|
||||
\fn bool QItemSelectionRange::operator!=(const QItemSelectionRange &lhs, const QItemSelectionRange &rhs)
|
||||
|
||||
Returns \c true if the selection range differs from the \a other range given;
|
||||
Returns \c true if \a lhs selection range differs from the \a rhs range given;
|
||||
otherwise returns \c false.
|
||||
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -57,12 +57,12 @@ public:
|
|||
bool intersects(const QItemSelectionRange &other) const;
|
||||
QItemSelectionRange intersected(const QItemSelectionRange &other) const;
|
||||
|
||||
|
||||
#if QT_CORE_REMOVED_SINCE(6, 8)
|
||||
inline bool operator==(const QItemSelectionRange &other) const
|
||||
{ return (tl == other.tl && br == other.br); }
|
||||
{ return comparesEqual(*this, other); }
|
||||
inline bool operator!=(const QItemSelectionRange &other) const
|
||||
{ return !operator==(other); }
|
||||
|
||||
{ return !operator==(other); }
|
||||
#endif
|
||||
inline bool isValid() const
|
||||
{
|
||||
return (tl.isValid() && br.isValid() && tl.parent() == br.parent()
|
||||
|
|
@ -74,6 +74,12 @@ public:
|
|||
QModelIndexList indexes() const;
|
||||
|
||||
private:
|
||||
friend bool comparesEqual(const QItemSelectionRange &lhs,
|
||||
const QItemSelectionRange &rhs) noexcept
|
||||
{
|
||||
return (lhs.tl == rhs.tl && lhs.br == rhs.br);
|
||||
}
|
||||
Q_DECLARE_EQUALITY_COMPARABLE(QItemSelectionRange)
|
||||
QPersistentModelIndex tl, br;
|
||||
};
|
||||
Q_DECLARE_TYPEINFO(QItemSelectionRange, Q_RELOCATABLE_TYPE);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
||||
|
||||
#include <QTest>
|
||||
#include <QtTest/private/qcomparisontesthelper_p.h>
|
||||
#include <QtTest/private/qpropertytesthelper_p.h>
|
||||
#include <QSignalSpy>
|
||||
|
||||
|
|
@ -24,6 +25,7 @@ public slots:
|
|||
void cleanupTestCase();
|
||||
void init();
|
||||
private slots:
|
||||
void compareCompiles();
|
||||
void clear_data();
|
||||
void clear();
|
||||
void clearAndSelect();
|
||||
|
|
@ -213,6 +215,11 @@ void tst_QItemSelectionModel::init()
|
|||
model->insertRow(0, QModelIndex());
|
||||
}
|
||||
|
||||
void tst_QItemSelectionModel::compareCompiles()
|
||||
{
|
||||
QTestPrivate::testEqualityOperatorsCompile<QItemSelectionRange>();
|
||||
}
|
||||
|
||||
void tst_QItemSelectionModel::clear_data()
|
||||
{
|
||||
QTest::addColumn<QModelIndexList>("indexList");
|
||||
|
|
@ -2714,6 +2721,9 @@ void tst_QItemSelectionModel::QTBUG48402()
|
|||
model.removeRows(removeTop, removeBottom - removeTop + 1);
|
||||
|
||||
QCOMPARE(QItemSelectionRange(helper.tl, helper.br), QItemSelectionRange(dtl, dbr));
|
||||
QT_TEST_EQUALITY_OPS(QItemSelectionRange(helper.tl, helper.br), QItemSelectionRange(dtl, dbr), true);
|
||||
QT_TEST_EQUALITY_OPS(QItemSelectionRange(), QItemSelectionRange(), true);
|
||||
QT_TEST_EQUALITY_OPS(QItemSelectionRange(helper.tl, helper.br), QItemSelectionRange(), false);
|
||||
}
|
||||
|
||||
void tst_QItemSelectionModel::QTBUG58851_data()
|
||||
|
|
|
|||
Loading…
Reference in New Issue