diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-20 16:56:34 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-21 10:52:39 +0000 |
commit | f7f1a71ea41579c1ff86c08c16b82e4c84bc891f (patch) | |
tree | 1fb8d3ab1abac801548b02bc77d9f7886a0382ad /src/corelib/tools/qrect.h | |
parent | b39b018f4a54252ee7a9ffada6d0f05f5896baaf (diff) |
Make QPoint*, QSize*, and QRect* binary operators hidden friends
Moves them to class scope, which will avoid them showing up as
possibilities in error messages for missing operators.
Also consolidates how they are compared, so QRectF and QSizeF act
similar to QPointF.
Change-Id: I1e12cb7e5a5c65e85c32281878da03c6136c17de
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/corelib/tools/qrect.h')
-rw-r--r-- | src/corelib/tools/qrect.h | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/src/corelib/tools/qrect.h b/src/corelib/tools/qrect.h index b898696293..23ace7d42d 100644 --- a/src/corelib/tools/qrect.h +++ b/src/corelib/tools/qrect.h @@ -148,8 +148,10 @@ public: [[nodiscard]] static constexpr inline QRect span(const QPoint &p1, const QPoint &p2) noexcept; - friend constexpr inline bool operator==(const QRect &, const QRect &) noexcept; - friend constexpr inline bool operator!=(const QRect &, const QRect &) noexcept; + friend constexpr inline bool operator==(const QRect &r1, const QRect &r2) noexcept + { return r1.x1==r2.x1 && r1.x2==r2.x2 && r1.y1==r2.y1 && r1.y2==r2.y2; } + friend constexpr inline bool operator!=(const QRect &r1, const QRect &r2) noexcept + { return r1.x1!=r2.x1 || r1.x2!=r2.x2 || r1.y1!=r2.y1 || r1.y2!=r2.y2; } friend constexpr inline size_t qHash(const QRect &, size_t) noexcept; #if defined(Q_OS_DARWIN) || defined(Q_QDOC) @@ -450,16 +452,6 @@ inline QRect QRect::united(const QRect &r) const noexcept return *this | r; } -constexpr inline bool operator==(const QRect &r1, const QRect &r2) noexcept -{ - return r1.x1==r2.x1 && r1.x2==r2.x2 && r1.y1==r2.y1 && r1.y2==r2.y2; -} - -constexpr inline bool operator!=(const QRect &r1, const QRect &r2) noexcept -{ - return r1.x1!=r2.x1 || r1.x2!=r2.x2 || r1.y1!=r2.y1 || r1.y2!=r2.y2; -} - constexpr inline size_t qHash(const QRect &r, size_t seed = 0) noexcept { return qHashMulti(seed, r.x1, r.x2, r.y1, r.y2); @@ -611,8 +603,16 @@ public: constexpr inline QRectF &operator+=(const QMarginsF &margins) noexcept; constexpr inline QRectF &operator-=(const QMarginsF &margins) noexcept; - friend constexpr inline bool operator==(const QRectF &, const QRectF &) noexcept; - friend constexpr inline bool operator!=(const QRectF &, const QRectF &) noexcept; + friend constexpr inline bool operator==(const QRectF &r1, const QRectF &r2) noexcept + { + return r1.topLeft() == r2.topLeft() + && r1.size() == r2.size(); + } + friend constexpr inline bool operator!=(const QRectF &r1, const QRectF &r2) noexcept + { + return r1.topLeft() != r2.topLeft() + || r1.size() != r2.size(); + } [[nodiscard]] constexpr inline QRect toRect() const noexcept; [[nodiscard]] QRect toAlignedRect() const noexcept; @@ -860,18 +860,6 @@ inline QRectF QRectF::united(const QRectF &r) const noexcept return *this | r; } -constexpr inline bool operator==(const QRectF &r1, const QRectF &r2) noexcept -{ - return qFuzzyCompare(r1.xp, r2.xp) && qFuzzyCompare(r1.yp, r2.yp) - && qFuzzyCompare(r1.w, r2.w) && qFuzzyCompare(r1.h, r2.h); -} - -constexpr inline bool operator!=(const QRectF &r1, const QRectF &r2) noexcept -{ - return !qFuzzyCompare(r1.xp, r2.xp) || !qFuzzyCompare(r1.yp, r2.yp) - || !qFuzzyCompare(r1.w, r2.w) || !qFuzzyCompare(r1.h, r2.h); -} - constexpr inline QRect QRectF::toRect() const noexcept { // This rounding is designed to minimize the maximum possible difference |