From e4173bc7bce0eb3cd046c2c1cc77e52d87cc5554 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 9 Sep 2024 20:56:56 +0200 Subject: [PATCH] QItemSelectionModel: simplify QItemSelectionRange::intersects() Simplify QItemSelectionRange::intersects() and make it more readable. Task-number: QTBUG-113137 Change-Id: I20f78192e59f5a878a5db2c177d8ee89d8872b2c Reviewed-by: David Faure --- .../itemmodels/qitemselectionmodel.cpp | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index 5110cdd9299..387daa655f1 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -185,14 +185,19 @@ QT_IMPL_METATYPE_EXTERN(QItemSelection) bool QItemSelectionRange::intersects(const QItemSelectionRange &other) const { // isValid() and parent() last since they are more expensive - return (model() == other.model() - && ((top() <= other.top() && bottom() >= other.top()) - || (top() >= other.top() && top() <= other.bottom())) - && ((left() <= other.left() && right() >= other.left()) - || (left() >= other.left() && left() <= other.right())) - && parent() == other.parent() - && isValid() && other.isValid() - ); + if (model() != other.model()) + return false; + + if (top() > other.bottom() || bottom() < other.top()) + return false; + + if (left() > other.right() || right() < other.left()) + return false; + + if (parent() != other.parent()) + return false; + + return isValid() && other.isValid(); } /*!