diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp index b993261ac15..b2f1631f21c 100644 --- a/src/gui/painting/qbrush.cpp +++ b/src/gui/painting/qbrush.cpp @@ -974,6 +974,33 @@ bool QBrush::operator==(const QBrush &b) const } } +/*! + \internal +*/ +bool QBrush::doCompareEqualColor(QColor rhs) const noexcept +{ + return style() == Qt::SolidPattern && color() == rhs && d->transform.isIdentity(); +} + +/*! + \internal +*/ +bool QBrush::doCompareEqualStyle(Qt::BrushStyle rhs) const noexcept +{ + switch (rhs) { + case Qt::NoBrush: + case Qt::TexturePattern: + case Qt::LinearGradientPattern: + case Qt::RadialGradientPattern: + case Qt::ConicalGradientPattern: + // A brush constructed only from one of those styles will end up + // using NoBrush (see qbrush_check_type) + return style() == Qt::NoBrush; + default: + return style() == rhs && color() == QColor(0, 0, 0); + } +} + #ifndef QT_NO_DEBUG_STREAM /*! \internal diff --git a/src/gui/painting/qbrush.h b/src/gui/painting/qbrush.h index 0a7dc6cf5d0..69ce983cc1a 100644 --- a/src/gui/painting/qbrush.h +++ b/src/gui/painting/qbrush.h @@ -86,28 +86,18 @@ private: friend class QPainter; friend bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush& brush); + bool doCompareEqualColor(QColor rhs) const noexcept; friend bool comparesEqual(const QBrush &lhs, QColor rhs) noexcept { - return lhs.color() == rhs && lhs.style() == Qt::SolidPattern - && lhs.transform().isIdentity(); + return lhs.doCompareEqualColor(rhs); } Q_DECLARE_EQUALITY_COMPARABLE(QBrush, QColor) Q_DECLARE_EQUALITY_COMPARABLE(QBrush, Qt::GlobalColor) + bool doCompareEqualStyle(Qt::BrushStyle rhs) const noexcept; friend bool comparesEqual(const QBrush &lhs, Qt::BrushStyle rhs) noexcept { - switch (rhs) { - case Qt::NoBrush: - case Qt::TexturePattern: - case Qt::LinearGradientPattern: - case Qt::RadialGradientPattern: - case Qt::ConicalGradientPattern: - // A brush constructed only from one of those styles will end up - // using NoBrush (see qbrush_check_type) - return lhs.style() == Qt::NoBrush; - default: - return lhs.style() == rhs && lhs.color() == QColor(0, 0, 0); - } + return lhs.doCompareEqualStyle(rhs); } Q_DECLARE_EQUALITY_COMPARABLE(QBrush, Qt::BrushStyle) diff --git a/src/gui/painting/qpen.cpp b/src/gui/painting/qpen.cpp index fdab16ff0e4..d974c18728a 100644 --- a/src/gui/painting/qpen.cpp +++ b/src/gui/painting/qpen.cpp @@ -856,6 +856,23 @@ bool QPen::operator==(const QPen &p) const && p.d->cosmetic == d->cosmetic); } +/*! + \internal +*/ +bool QPen::doCompareEqualColor(QColor rhs) const noexcept +{ + return d->brush == rhs && isSolidDefaultLine(); +} + +/*! + \internal +*/ +bool QPen::doCompareEqualStyle(Qt::PenStyle rhs) const +{ + if (rhs == Qt::NoPen) + return style() == Qt::NoPen; + return *this == QPen(rhs); // ### optimize (allocates) +} /*! \fn bool QPen::isDetached() diff --git a/src/gui/painting/qpen.h b/src/gui/painting/qpen.h index 897ebfb8428..14a46415fa9 100644 --- a/src/gui/painting/qpen.h +++ b/src/gui/painting/qpen.h @@ -91,17 +91,17 @@ private: bool isSolidDefaultLine() const noexcept; + bool doCompareEqualColor(QColor rhs) const noexcept; friend bool comparesEqual(const QPen &lhs, QColor rhs) noexcept { - return lhs.brush() == rhs && lhs.isSolidDefaultLine(); + return lhs.doCompareEqualColor(rhs); } Q_DECLARE_EQUALITY_COMPARABLE(QPen, QColor) + bool doCompareEqualStyle(Qt::PenStyle rhs) const; friend bool comparesEqual(const QPen &lhs, Qt::PenStyle rhs) { - if (rhs == Qt::NoPen) - return lhs.style() == Qt::NoPen; - return lhs == QPen(rhs); // allocates + return lhs.doCompareEqualStyle(rhs); } Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QPen, Qt::PenStyle)