diff --git a/src/corelib/tools/qmargins.cpp b/src/corelib/tools/qmargins.cpp index 1d2cb7d6e5d..fbb431e7a43 100644 --- a/src/corelib/tools/qmargins.cpp +++ b/src/corelib/tools/qmargins.cpp @@ -14,6 +14,10 @@ QT_BEGIN_NAMESPACE \ingroup painting \since 4.6 + \compares equality + \compareswith equality QMarginsF + \endcompareswith + \brief The QMargins class defines the four margins of a rectangle. QMargin defines a set of four margins; left, top, right, and bottom, @@ -107,15 +111,15 @@ QT_BEGIN_NAMESPACE */ /*! - \fn bool QMargins::operator==(const QMargins &m1, const QMargins &m2) + \fn bool QMargins::operator==(const QMargins &lhs, const QMargins &rhs) - Returns \c true if \a m1 and \a m2 are equal; otherwise returns \c false. + Returns \c true if \a lhs and \a rhs are equal; otherwise returns \c false. */ /*! - \fn bool QMargins::operator!=(const QMargins &m1, const QMargins &m2) + \fn bool QMargins::operator!=(const QMargins &lhs, const QMargins &rhs) - Returns \c true if \a m1 and \a m2 are different; otherwise returns \c false. + Returns \c true if \a lhs and \a rhs are different; otherwise returns \c false. */ /*! @@ -438,6 +442,10 @@ QDebug operator<<(QDebug dbg, const QMargins &m) \ingroup painting \since 5.3 + \compares equality + \compareswith equality QMargins + \endcompareswith + \brief The QMarginsF class defines the four margins of a rectangle. QMarginsF defines a set of four margins; left, top, right, and bottom, diff --git a/src/corelib/tools/qmargins.h b/src/corelib/tools/qmargins.h index 63c0b2a8e23..feaa91824a1 100644 --- a/src/corelib/tools/qmargins.h +++ b/src/corelib/tools/qmargins.h @@ -4,6 +4,7 @@ #ifndef QMARGINS_H #define QMARGINS_H +#include #include #include @@ -54,19 +55,14 @@ private: int m_right; int m_bottom; - friend constexpr inline bool operator==(const QMargins &m1, const QMargins &m2) noexcept + friend constexpr bool comparesEqual(const QMargins &lhs, const QMargins &rhs) noexcept { - return - m1.m_left == m2.m_left && - m1.m_top == m2.m_top && - m1.m_right == m2.m_right && - m1.m_bottom == m2.m_bottom; - } - - friend constexpr inline bool operator!=(const QMargins &m1, const QMargins &m2) noexcept - { - return !(m1 == m2); + return lhs.m_left == rhs.m_left + && lhs.m_top == rhs.m_top + && lhs.m_right == rhs.m_right + && lhs.m_bottom == rhs.m_bottom; } + Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QMargins) template (); + QTestPrivate::testEqualityOperatorsCompile(); + QTestPrivate::testEqualityOperatorsCompile(); +} + void tst_QMargins::comparison_data() { QTest::addColumn("lhs");