summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qline.h
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2024-04-05 11:59:30 +0200
committerIvan Solovev <ivan.solovev@qt.io>2024-05-10 15:33:39 +0200
commit2a847dd93b1b9cc363eefa27686d78a4bc399d1e (patch)
tree490d7b81768321102e01919a6a96c0712147a2ba /src/corelib/tools/qline.h
parentfa0d77e290f5ccb5afa7d02716f8726aa6b810e6 (diff)
QLine(F): use comparison helper macros
Also explicitly add QLineF vs QLine comparison. Previously such comparison was implicitly converting QLine to QLineF, and doing the fuzzy comparison. The new operators are directly calling operator==(QPointF, QPoint), which also does the fuzzy comparison, so the old behavior is preserved. Remove the old relational operators using QT_CORE_REMOVED_SINCE, but also wrap the new operators in !defined(QT_CORE_REMOVED_SINCE). That is required, because on Windows the instantiation of QMetaTypeInterface<QLine(F)> happens in removed_api.cpp (as both qline.h and qmetatype.h are already included there). If we just add removed member operators into removed_api.cpp, the metatype interface will not be able to create an equals() function, because of the ambiguity in equality operators (member vs friend). That's why we have to exclude the new friend operators from removed_api.cpp. Done-with: Fabian Kosmale <fabian.kosmale@qt.io> Task-number: QTBUG-120308 Change-Id: Ibbf5ec077f69c75da0d36a8be5596acd0fcd44d0 Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>
Diffstat (limited to 'src/corelib/tools/qline.h')
-rw-r--r--src/corelib/tools/qline.h34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/corelib/tools/qline.h b/src/corelib/tools/qline.h
index e23ffbe9d5..45f0bae94f 100644
--- a/src/corelib/tools/qline.h
+++ b/src/corelib/tools/qline.h
@@ -48,12 +48,20 @@ public:
inline void setPoints(const QPoint &p1, const QPoint &p2);
inline void setLine(int x1, int y1, int x2, int y2);
+#if QT_CORE_REMOVED_SINCE(6, 8)
constexpr inline bool operator==(const QLine &d) const noexcept;
- constexpr inline bool operator!=(const QLine &d) const noexcept { return !(*this == d); }
+ constexpr inline bool operator!=(const QLine &d) const noexcept { return !operator==(d); }
+#endif
[[nodiscard]] constexpr inline QLineF toLineF() const noexcept;
private:
+ friend constexpr bool comparesEqual(const QLine &lhs, const QLine &rhs) noexcept
+ { return lhs.pt1 == rhs.pt1 && lhs.pt2 == rhs.pt2; }
+#if !QT_CORE_REMOVED_SINCE(6, 8)
+ Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QLine)
+#endif
+
QPoint pt1, pt2;
};
Q_DECLARE_TYPEINFO(QLine, Q_PRIMITIVE_TYPE);
@@ -161,10 +169,12 @@ inline void QLine::setLine(int aX1, int aY1, int aX2, int aY2)
pt2 = QPoint(aX2, aY2);
}
+#if QT_CORE_REMOVED_SINCE(6, 8)
constexpr inline bool QLine::operator==(const QLine &d) const noexcept
{
- return pt1 == d.pt1 && pt2 == d.pt2;
+ return comparesEqual(*this, d);
}
+#endif
#ifndef QT_NO_DEBUG_STREAM
Q_CORE_EXPORT QDebug operator<<(QDebug d, const QLine &p);
@@ -233,12 +243,24 @@ public:
inline void setPoints(const QPointF &p1, const QPointF &p2);
inline void setLine(qreal x1, qreal y1, qreal x2, qreal y2);
+#if QT_CORE_REMOVED_SINCE(6, 8)
constexpr inline bool operator==(const QLineF &d) const;
- constexpr inline bool operator!=(const QLineF &d) const { return !(*this == d); }
+ constexpr inline bool operator!=(const QLineF &d) const { return !operator==(d); }
+#endif
constexpr QLine toLine() const;
private:
+ friend constexpr bool comparesEqual(const QLineF &lhs, const QLineF &rhs) noexcept
+ { return lhs.pt1 == rhs.pt1 && lhs.pt2 == rhs.pt2; }
+#if !QT_CORE_REMOVED_SINCE(6, 8)
+ Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QLineF)
+#endif
+
+ friend constexpr bool comparesEqual(const QLineF &lhs, const QLine &rhs) noexcept
+ { return comparesEqual(lhs, rhs.toLineF()); }
+ Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QLineF, QLine)
+
QPointF pt1, pt2;
};
Q_DECLARE_TYPEINFO(QLineF, Q_PRIMITIVE_TYPE);
@@ -383,12 +405,12 @@ inline void QLineF::setLine(qreal aX1, qreal aY1, qreal aX2, qreal aY2)
pt2 = QPointF(aX2, aY2);
}
-
+#if QT_CORE_REMOVED_SINCE(6, 8)
constexpr inline bool QLineF::operator==(const QLineF &d) const
{
- return pt1 == d.pt1 && pt2 == d.pt2;
+ return comparesEqual(*this, d);
}
-
+#endif
#ifndef QT_NO_DEBUG_STREAM