From 07ff70a0da189656daf31c2a5e3e3ba117762af3 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 26 Oct 2020 14:42:52 +0100 Subject: [PATCH] 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 --- .../itemmodels/qitemselectionmodel.cpp | 41 ----- src/corelib/itemmodels/qitemselectionmodel.h | 3 - .../tst_qitemselectionmodel.cpp | 141 ------------------ 3 files changed, 185 deletions(-) diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index a47d760e97..b6a6bff118 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -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 less; - return less(tl.model(), other.tl.model()); -} -#endif - /*! \fn bool QItemSelectionRange::isValid() const diff --git a/src/corelib/itemmodels/qitemselectionmodel.h b/src/corelib/itemmodels/qitemselectionmodel.h index f2545bf93c..488999937d 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.h +++ b/src/corelib/itemmodels/qitemselectionmodel.h @@ -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 { diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp index e9bc0581be..35b70ee103 100644 --- a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp +++ b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp @@ -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("parent1"); - QTest::addColumn("top1"); - QTest::addColumn("left1"); - QTest::addColumn("bottom1"); - QTest::addColumn("right1"); - QTest::addColumn("parent2"); - QTest::addColumn("top2"); - QTest::addColumn("left2"); - QTest::addColumn("bottom2"); - QTest::addColumn("right2"); - QTest::addColumn("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;