Remove QItemSelectionRange's operator<()
As advocated in a ### Qt 6 comment. [ChangeLog][QtCore][QItemSelectionRange] QItemSelectionRange no longer supports ordering. The prior ordering was inconsistent with equality and should not be needed. Task-number: QTBUG-85700 Change-Id: I5eb372c203cae19db40fa67f706d911785652d5f Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
29c113d912
commit
07ff70a0da
@ -260,47 +260,6 @@ QItemSelectionRange QItemSelectionRange::intersected(const QItemSelectionRange &
|
||||
|
||||
*/
|
||||
|
||||
#if QT_DEPRECATED_SINCE(5, 15)
|
||||
/*!
|
||||
Returns \c true if the selection range is less than the \a other
|
||||
range given; otherwise returns \c false.
|
||||
|
||||
The less than calculation is not directly useful to developers - the way that ranges
|
||||
with different parents compare is not defined. This operator only exists so that the
|
||||
class can be used with QMap.
|
||||
|
||||
*/
|
||||
bool QItemSelectionRange::operator<(const QItemSelectionRange &other) const
|
||||
{
|
||||
// ### Qt 6: This is inconsistent with op== and needs to be fixed, nay,
|
||||
// ### removed, but cannot, because it was inline up to and including 5.9
|
||||
|
||||
// Comparing parents will compare the models, but if two equivalent ranges
|
||||
// in two different models have invalid parents, they would appear the same
|
||||
if (other.tl.model() == tl.model()) {
|
||||
// parent has to be calculated, so we only do so once.
|
||||
const QModelIndex topLeftParent = tl.parent();
|
||||
const QModelIndex otherTopLeftParent = other.tl.parent();
|
||||
if (topLeftParent == otherTopLeftParent) {
|
||||
if (other.tl.row() == tl.row()) {
|
||||
if (other.tl.column() == tl.column()) {
|
||||
if (other.br.row() == br.row()) {
|
||||
return br.column() < other.br.column();
|
||||
}
|
||||
return br.row() < other.br.row();
|
||||
}
|
||||
return tl.column() < other.tl.column();
|
||||
}
|
||||
return tl.row() < other.tl.row();
|
||||
}
|
||||
return topLeftParent < otherTopLeftParent;
|
||||
}
|
||||
|
||||
std::less<const QAbstractItemModel *> less;
|
||||
return less(tl.model(), other.tl.model());
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\fn bool QItemSelectionRange::isValid() const
|
||||
|
||||
|
@ -98,9 +98,6 @@ public:
|
||||
{ return (tl == other.tl && br == other.br); }
|
||||
inline bool operator!=(const QItemSelectionRange &other) const
|
||||
{ return !operator==(other); }
|
||||
#if QT_DEPRECATED_SINCE(5, 15)
|
||||
QT_DEPRECATED bool operator<(const QItemSelectionRange &other) const;
|
||||
#endif
|
||||
|
||||
inline bool isValid() const
|
||||
{
|
||||
|
@ -82,10 +82,6 @@ private slots:
|
||||
void layoutChangedWithAllSelected2();
|
||||
void layoutChangedTreeSelection();
|
||||
void deselectRemovedMiddleRange();
|
||||
#if QT_DEPRECATED_SINCE(5, 15)
|
||||
void rangeOperatorLessThan_data();
|
||||
void rangeOperatorLessThan();
|
||||
#endif
|
||||
void setModel();
|
||||
|
||||
void testDifferentModels();
|
||||
@ -2447,143 +2443,6 @@ static QStandardItemModel* getModel(QObject *parent)
|
||||
return model;
|
||||
}
|
||||
|
||||
#if QT_DEPRECATED_SINCE(5, 15)
|
||||
enum Result {
|
||||
LessThan,
|
||||
NotLessThan,
|
||||
NotEqual
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(Result);
|
||||
|
||||
void tst_QItemSelectionModel::rangeOperatorLessThan_data()
|
||||
{
|
||||
QTest::addColumn<int>("parent1");
|
||||
QTest::addColumn<int>("top1");
|
||||
QTest::addColumn<int>("left1");
|
||||
QTest::addColumn<int>("bottom1");
|
||||
QTest::addColumn<int>("right1");
|
||||
QTest::addColumn<int>("parent2");
|
||||
QTest::addColumn<int>("top2");
|
||||
QTest::addColumn<int>("left2");
|
||||
QTest::addColumn<int>("bottom2");
|
||||
QTest::addColumn<int>("right2");
|
||||
QTest::addColumn<Result>("result");
|
||||
|
||||
QTest::newRow("lt01") << -1 << 0 << 0 << 3 << 3
|
||||
<< -1 << 0 << 0 << 3 << 3 << NotLessThan;
|
||||
|
||||
QTest::newRow("lt02") << -1 << 0 << 0 << 2 << 3
|
||||
<< -1 << 0 << 0 << 3 << 3 << LessThan;
|
||||
QTest::newRow("lt03") << -1 << 0 << 0 << 3 << 2
|
||||
<< -1 << 0 << 0 << 3 << 3 << LessThan;
|
||||
QTest::newRow("lt04") << -1 << 0 << 0 << 2 << 2
|
||||
<< -1 << 0 << 0 << 3 << 3 << LessThan;
|
||||
|
||||
QTest::newRow("lt05") << -1 << 0 << 0 << 3 << 3
|
||||
<< -1 << 0 << 0 << 2 << 3 << NotLessThan;
|
||||
QTest::newRow("lt06") << -1 << 0 << 0 << 3 << 3
|
||||
<< -1 << 0 << 0 << 3 << 2 << NotLessThan;
|
||||
QTest::newRow("lt07") << -1 << 0 << 0 << 3 << 3
|
||||
<< -1 << 0 << 0 << 2 << 2 << NotLessThan;
|
||||
|
||||
QTest::newRow("lt08") << -1 << 0 << 0 << 3 << 3
|
||||
<< 0 << 0 << 0 << 3 << 3 << NotEqual;
|
||||
QTest::newRow("lt09") << 1 << 0 << 0 << 3 << 3
|
||||
<< 0 << 0 << 0 << 3 << 3 << NotEqual;
|
||||
QTest::newRow("lt10") << 1 << 0 << 0 << 1 << 1
|
||||
<< 0 << 2 << 2 << 3 << 3 << NotEqual;
|
||||
QTest::newRow("lt11") << 1 << 2 << 2 << 3 << 3
|
||||
<< 0 << 0 << 0 << 1 << 1 << NotEqual;
|
||||
|
||||
QTest::newRow("lt12") << -1 << 0 << 0 << 1 << 1
|
||||
<< -1 << 2 << 2 << 3 << 3 << LessThan;
|
||||
QTest::newRow("lt13") << -1 << 2 << 2 << 3 << 3
|
||||
<< -1 << 0 << 0 << 1 << 1 << NotLessThan;
|
||||
QTest::newRow("lt14") << 1 << 0 << 0 << 1 << 1
|
||||
<< 1 << 2 << 2 << 3 << 3 << LessThan;
|
||||
QTest::newRow("lt15") << 1 << 2 << 2 << 3 << 3
|
||||
<< 1 << 0 << 0 << 1 << 1 << NotLessThan;
|
||||
|
||||
QTest::newRow("lt16") << -1 << 0 << 0 << 2 << 2
|
||||
<< -1 << 1 << 1 << 3 << 3 << LessThan;
|
||||
QTest::newRow("lt17") << -1 << 1 << 1 << 3 << 3
|
||||
<< -1 << 0 << 0 << 2 << 2 << NotLessThan;
|
||||
QTest::newRow("lt18") << 1 << 0 << 0 << 2 << 2
|
||||
<< 1 << 1 << 1 << 3 << 3 << LessThan;
|
||||
QTest::newRow("lt19") << 1 << 1 << 1 << 3 << 3
|
||||
<< 1 << 0 << 0 << 2 << 2 << NotLessThan;
|
||||
}
|
||||
|
||||
void tst_QItemSelectionModel::rangeOperatorLessThan()
|
||||
{
|
||||
QStandardItemModel *model1 = getModel(this);
|
||||
QStandardItemModel *model2 = getModel(this);
|
||||
|
||||
QFETCH(int, parent1);
|
||||
QFETCH(int, top1);
|
||||
QFETCH(int, left1);
|
||||
QFETCH(int, bottom1);
|
||||
QFETCH(int, right1);
|
||||
QFETCH(int, parent2);
|
||||
QFETCH(int, top2);
|
||||
QFETCH(int, left2);
|
||||
QFETCH(int, bottom2);
|
||||
QFETCH(int, right2);
|
||||
QFETCH(Result, result);
|
||||
|
||||
QModelIndex p1 = model1->index(parent1, 0);
|
||||
|
||||
QModelIndex tl1 = model1->index(top1, left1, p1);
|
||||
QModelIndex br1 = model1->index(bottom1, right1, p1);
|
||||
|
||||
QItemSelectionRange r1(tl1, br1);
|
||||
|
||||
QModelIndex p2 = model1->index(parent2, 0);
|
||||
|
||||
QModelIndex tl2 = model1->index(top2, left2, p2);
|
||||
QModelIndex br2 = model1->index(bottom2, right2, p2);
|
||||
|
||||
QItemSelectionRange r2(tl2, br2);
|
||||
|
||||
if (result == LessThan)
|
||||
QVERIFY(r1 < r2);
|
||||
else if (result == NotLessThan)
|
||||
QVERIFY(!(r1 < r2));
|
||||
else if (result == NotEqual)
|
||||
if (!(r1 < r2))
|
||||
QVERIFY(r2 < r1);
|
||||
|
||||
// Ranges in different models are always non-equal
|
||||
|
||||
QModelIndex p3 = model2->index(parent1, 0);
|
||||
|
||||
QModelIndex tl3 = model2->index(top1, left1, p3);
|
||||
QModelIndex br3 = model2->index(bottom1, right1, p3);
|
||||
|
||||
QItemSelectionRange r3(tl3, br3);
|
||||
|
||||
if (!(r1 < r3))
|
||||
QVERIFY(r3 < r1);
|
||||
|
||||
if (!(r2 < r3))
|
||||
QVERIFY(r3 < r2);
|
||||
|
||||
QModelIndex p4 = model2->index(parent2, 0);
|
||||
|
||||
QModelIndex tl4 = model2->index(top2, left2, p4);
|
||||
QModelIndex br4 = model2->index(bottom2, right2, p4);
|
||||
|
||||
QItemSelectionRange r4(tl4, br4);
|
||||
|
||||
if (!(r1 < r4))
|
||||
QVERIFY(r4 < r1);
|
||||
|
||||
if (!(r2 < r4))
|
||||
QVERIFY(r4 < r2);
|
||||
}
|
||||
#endif
|
||||
|
||||
void tst_QItemSelectionModel::setModel()
|
||||
{
|
||||
QItemSelectionModel sel;
|
||||
|
Loading…
Reference in New Issue
Block a user