diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-10-28 00:02:59 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-10-28 22:14:56 +0100 |
commit | a45a3b1ece490bcae5cccd858dbe11408a19bee0 (patch) | |
tree | 4bfee963625fab42fc7b9d14608916cb38678994 /src/gui | |
parent | 979c8cf1b75e3e0e0dcf7c718c3fed6fdfdd7ea3 (diff) |
Make comparison operators in gui/painting classes hidden friends
Reduce ADL noise from QColorSpace, QPageSize, and QPageLayout with the
help of a private equals method.
Change-Id: I0082597dd216b982e8d8eb5a4bd7dd29a5d3263b
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/painting/qcolorspace.cpp | 60 | ||||
-rw-r--r-- | src/gui/painting/qcolorspace.h | 13 | ||||
-rw-r--r-- | src/gui/painting/qpagelayout.cpp | 19 | ||||
-rw-r--r-- | src/gui/painting/qpagelayout.h | 11 | ||||
-rw-r--r-- | src/gui/painting/qpagesize.cpp | 18 | ||||
-rw-r--r-- | src/gui/painting/qpagesize.h | 11 |
6 files changed, 74 insertions, 58 deletions
diff --git a/src/gui/painting/qcolorspace.cpp b/src/gui/painting/qcolorspace.cpp index 82aec1e50f..fda235c405 100644 --- a/src/gui/painting/qcolorspace.cpp +++ b/src/gui/painting/qcolorspace.cpp @@ -692,64 +692,68 @@ bool QColorSpace::isValid() const noexcept /*! \fn bool QColorSpace::operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2) - \relates QColorSpace + Returns \c true if colorspace \a colorSpace1 is equal to colorspace \a colorSpace2; otherwise returns \c false */ -bool operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2) + +/*! + \fn bool QColorSpace::operator!=(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2) + + Returns \c true if colorspace \a colorSpace1 is not equal to colorspace \a colorSpace2; + otherwise returns \c false +*/ + +/*! + \internal +*/ +bool QColorSpace::equals(const QColorSpace &other) const { - if (colorSpace1.d_ptr == colorSpace2.d_ptr) + if (d_ptr == other.d_ptr) return true; - if (!colorSpace1.d_ptr || !colorSpace2.d_ptr) + if (!d_ptr || !other.d_ptr) return false; - if (colorSpace1.d_ptr->namedColorSpace && colorSpace2.d_ptr->namedColorSpace) - return colorSpace1.d_ptr->namedColorSpace == colorSpace2.d_ptr->namedColorSpace; + if (d_ptr->namedColorSpace && other.d_ptr->namedColorSpace) + return d_ptr->namedColorSpace == other.d_ptr->namedColorSpace; - const bool valid1 = colorSpace1.isValid(); - const bool valid2 = colorSpace2.isValid(); + const bool valid1 = isValid(); + const bool valid2 = other.isValid(); if (valid1 != valid2) return false; if (!valid1 && !valid2) { - if (!colorSpace1.d_ptr->iccProfile.isEmpty() || !colorSpace2.d_ptr->iccProfile.isEmpty()) - return colorSpace1.d_ptr->iccProfile == colorSpace2.d_ptr->iccProfile; + if (!d_ptr->iccProfile.isEmpty() || !other.d_ptr->iccProfile.isEmpty()) + return d_ptr->iccProfile == other.d_ptr->iccProfile; } // At this point one or both color spaces are unknown, and must be compared in detail instead - if (colorSpace1.primaries() != QColorSpace::Primaries::Custom && colorSpace2.primaries() != QColorSpace::Primaries::Custom) { - if (colorSpace1.primaries() != colorSpace2.primaries()) + if (primaries() != QColorSpace::Primaries::Custom && other.primaries() != QColorSpace::Primaries::Custom) { + if (primaries() != other.primaries()) return false; } else { - if (colorSpace1.d_ptr->toXyz != colorSpace2.d_ptr->toXyz) + if (d_ptr->toXyz != other.d_ptr->toXyz) return false; } - if (colorSpace1.transferFunction() != QColorSpace::TransferFunction::Custom && - colorSpace2.transferFunction() != QColorSpace::TransferFunction::Custom) { - if (colorSpace1.transferFunction() != colorSpace2.transferFunction()) + if (transferFunction() != QColorSpace::TransferFunction::Custom && + other.transferFunction() != QColorSpace::TransferFunction::Custom) { + if (transferFunction() != other.transferFunction()) return false; - if (colorSpace1.transferFunction() == QColorSpace::TransferFunction::Gamma) - return (qAbs(colorSpace1.gamma() - colorSpace2.gamma()) <= (1.0f / 512.0f)); + if (transferFunction() == QColorSpace::TransferFunction::Gamma) + return (qAbs(gamma() - other.gamma()) <= (1.0f / 512.0f)); return true; } - if (colorSpace1.d_ptr->trc[0] != colorSpace2.d_ptr->trc[0] || - colorSpace1.d_ptr->trc[1] != colorSpace2.d_ptr->trc[1] || - colorSpace1.d_ptr->trc[2] != colorSpace2.d_ptr->trc[2]) + if (d_ptr->trc[0] != other.d_ptr->trc[0] || + d_ptr->trc[1] != other.d_ptr->trc[1] || + d_ptr->trc[2] != other.d_ptr->trc[2]) return false; return true; } /*! - \fn bool QColorSpace::operator!=(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2) - - Returns \c true if colorspace \a colorSpace1 is not equal to colorspace \a colorSpace2; - otherwise returns \c false -*/ - -/*! Generates and returns a color space transformation from this color space to \a colorspace. */ diff --git a/src/gui/painting/qcolorspace.h b/src/gui/painting/qcolorspace.h index d31bf1a326..c464a271be 100644 --- a/src/gui/painting/qcolorspace.h +++ b/src/gui/painting/qcolorspace.h @@ -119,8 +119,10 @@ public: void detach(); bool isValid() const noexcept; - friend Q_GUI_EXPORT bool operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2); - friend inline bool operator!=(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2); + friend inline bool operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2) + { return colorSpace1.equals(colorSpace2); } + friend inline bool operator!=(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2) + { return !(colorSpace1 == colorSpace2); } static QColorSpace fromIccProfile(const QByteArray &iccProfile); QByteArray iccProfile() const; @@ -131,6 +133,8 @@ public: private: friend class QColorSpacePrivate; + bool equals(const QColorSpace &other) const; + QExplicitlySharedDataPointer<QColorSpacePrivate> d_ptr; #ifndef QT_NO_DEBUG_STREAM @@ -138,11 +142,6 @@ private: #endif }; -inline bool operator!=(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2) -{ - return !(colorSpace1 == colorSpace2); -} - Q_DECLARE_SHARED(QColorSpace) // QColorSpace stream functions diff --git a/src/gui/painting/qpagelayout.cpp b/src/gui/painting/qpagelayout.cpp index 2634a448a5..def9751aa6 100644 --- a/src/gui/painting/qpagelayout.cpp +++ b/src/gui/painting/qpagelayout.cpp @@ -415,7 +415,7 @@ QPageLayout &QPageLayout::operator=(const QPageLayout &other) */ /*! - \relates QPageLayout + \fn bool QPageLayout::operator==(const QPageLayout &lhs, const QPageLayout &rhs) Returns \c true if page layout \a lhs is equal to page layout \a rhs, i.e. if all the attributes are exactly equal. @@ -427,14 +427,8 @@ QPageLayout &QPageLayout::operator=(const QPageLayout &other) \sa QPageLayout::isEquivalentTo() */ -bool operator==(const QPageLayout &lhs, const QPageLayout &rhs) -{ - return lhs.d == rhs.d || *lhs.d == *rhs.d; -} - /*! - \fn bool operator!=(const QPageLayout &lhs, const QPageLayout &rhs) - \relates QPageLayout + \fn bool QPageLayout::operator!=(const QPageLayout &lhs, const QPageLayout &rhs) Returns \c true if page layout \a lhs is not equal to page layout \a rhs, i.e. if any of the attributes differ. @@ -447,6 +441,15 @@ bool operator==(const QPageLayout &lhs, const QPageLayout &rhs) */ /*! + \internal +*/ +bool QPageLayout::equals(const QPageLayout &other) const +{ + return d == other.d || *d == *other.d; +} + + +/*! Returns \c true if this page layout is equivalent to the \a other page layout, i.e. if the page has the same size, margins and orientation. */ diff --git a/src/gui/painting/qpagelayout.h b/src/gui/painting/qpagelayout.h index a7858edfaf..0b2f7c59dd 100644 --- a/src/gui/painting/qpagelayout.h +++ b/src/gui/painting/qpagelayout.h @@ -132,15 +132,18 @@ public: private: friend class QPageLayoutPrivate; + bool equals(const QPageLayout &other) const; + + friend inline bool operator==(const QPageLayout &lhs, const QPageLayout &rhs) + { return lhs.equals(rhs); } + friend inline bool operator!=(const QPageLayout &lhs, const QPageLayout &rhs) + { return !lhs.equals(rhs); } + QExplicitlySharedDataPointer<QPageLayoutPrivate> d; }; Q_DECLARE_SHARED(QPageLayout) -Q_GUI_EXPORT bool operator==(const QPageLayout &lhs, const QPageLayout &rhs); -inline bool operator!=(const QPageLayout &lhs, const QPageLayout &rhs) -{ return !operator==(lhs, rhs); } - #ifndef QT_NO_DEBUG_STREAM Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QPageLayout &pageLayout); #endif diff --git a/src/gui/painting/qpagesize.cpp b/src/gui/painting/qpagesize.cpp index 7ae3e93f5a..fb7eb45b93 100644 --- a/src/gui/painting/qpagesize.cpp +++ b/src/gui/painting/qpagesize.cpp @@ -1249,20 +1249,15 @@ QPageSize &QPageSize::operator=(const QPageSize &other) */ /*! - \relates QPageSize + \fn bool QPageSize::operator==(const QPageSize &lhs, const QPageSize &rhs) Returns \c true if page size \a lhs is equal to page size \a rhs, i.e. if the page sizes have the same attributes. Current attributes are size and name. */ -bool operator==(const QPageSize &lhs, const QPageSize &rhs) -{ - return lhs.d == rhs.d || *lhs.d == *rhs.d; -} /*! - \fn bool operator!=(const QPageSize &lhs, const QPageSize &rhs) - \relates QPageSize + \fn bool QPageSize::operator!=(const QPageSize &lhs, const QPageSize &rhs) Returns \c true if page size \a lhs is unequal to page size \a rhs, i.e. if the page size has different attributes. Current @@ -1270,6 +1265,15 @@ bool operator==(const QPageSize &lhs, const QPageSize &rhs) */ /*! + \internal +*/ +bool QPageSize::equals(const QPageSize &other) const +{ + return d == other.d || *d == *other.d; +} + + +/*! Returns \c true if this page is equivalent to the \a other page, i.e. if the page has the same size regardless of other attributes like name. */ diff --git a/src/gui/painting/qpagesize.h b/src/gui/painting/qpagesize.h index fbaec0da3f..72d24ed938 100644 --- a/src/gui/painting/qpagesize.h +++ b/src/gui/painting/qpagesize.h @@ -283,6 +283,13 @@ public: private: friend class QPageSizePrivate; friend class QPlatformPrintDevice; + + bool equals(const QPageSize &other) const; + friend inline bool operator==(const QPageSize &lhs, const QPageSize &rhs) + { return lhs.equals(rhs); } + friend inline bool operator!=(const QPageSize &lhs, const QPageSize &rhs) + { return !(lhs == rhs); } + QPageSize(const QString &key, const QSize &pointSize, const QString &name); QPageSize(int windowsId, const QSize &pointSize, const QString &name); QPageSize(QPageSizePrivate &dd); @@ -291,10 +298,6 @@ private: Q_DECLARE_SHARED(QPageSize) -Q_GUI_EXPORT bool operator==(const QPageSize &lhs, const QPageSize &rhs); -inline bool operator!=(const QPageSize &lhs, const QPageSize &rhs) -{ return !operator==(lhs, rhs); } - #ifndef QT_NO_DEBUG_STREAM Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QPageSize &pageSize); #endif |