Fix ExtendedRgb and Rgb encoding comparisons

ExtendedRgb should be treated as Rgb as it can be an automatic upgrade.

Pick-to: 5.15
Change-Id: I2942a1067ed5cacb2f60f303f467887cb44c36dd
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
Allan Sandfeld Jensen 2020-05-26 12:14:02 +02:00
parent 0ea99a68f9
commit d80a98d525
2 changed files with 30 additions and 0 deletions

View File

@ -2883,6 +2883,8 @@ QColor &QColor::operator=(Qt::GlobalColor color) noexcept
Returns \c true if this color has the same color specification and component values as \a color; Returns \c true if this color has the same color specification and component values as \a color;
otherwise returns \c false. otherwise returns \c false.
ExtendedRgb and Rgb specifications are considered matching in this context.
\sa spec() \sa spec()
*/ */
bool QColor::operator==(const QColor &color) const noexcept bool QColor::operator==(const QColor &color) const noexcept
@ -2896,6 +2898,12 @@ bool QColor::operator==(const QColor &color) const noexcept
|| ct.ahsl.lightness == USHRT_MAX || ct.ahsl.lightness == USHRT_MAX
|| color.ct.ahsl.lightness == USHRT_MAX) || color.ct.ahsl.lightness == USHRT_MAX)
&& (qAbs(ct.ahsl.lightness - color.ct.ahsl.lightness)) < 50); && (qAbs(ct.ahsl.lightness - color.ct.ahsl.lightness)) < 50);
} else if ((cspec == ExtendedRgb || color.cspec == ExtendedRgb) &&
(cspec == color.cspec || cspec == Rgb || color.cspec == Rgb)) {
return qFuzzyCompare(alphaF(), color.alphaF())
&& qFuzzyCompare(redF(), color.redF())
&& qFuzzyCompare(greenF(), color.greenF())
&& qFuzzyCompare(blueF(), color.blueF());
} else { } else {
return (cspec == color.cspec return (cspec == color.cspec
&& ct.argb.alpha == color.ct.argb.alpha && ct.argb.alpha == color.ct.argb.alpha
@ -2912,6 +2920,8 @@ bool QColor::operator==(const QColor &color) const noexcept
Returns \c true if this color has different color specification or component values from Returns \c true if this color has different color specification or component values from
\a color; otherwise returns \c false. \a color; otherwise returns \c false.
ExtendedRgb and Rgb specifications are considered matching in this context.
\sa spec() \sa spec()
*/ */
bool QColor::operator!=(const QColor &color) const noexcept bool QColor::operator!=(const QColor &color) const noexcept

View File

@ -106,6 +106,8 @@ private slots:
void achromaticHslHue(); void achromaticHslHue();
void equality();
void premultiply(); void premultiply();
void unpremultiply_sse4(); void unpremultiply_sse4();
void qrgba64(); void qrgba64();
@ -1682,6 +1684,24 @@ void tst_QColor::achromaticHslHue()
QCOMPARE(hsl.hslHue(), -1); QCOMPARE(hsl.hslHue(), -1);
} }
void tst_QColor::equality()
{
QColor red = Qt::red;
QColor black = Qt::black;
QCOMPARE(red, red);
QCOMPARE(black, black);
QVERIFY(red != black);
// Encodings must match
QVERIFY(red != red.toHsv());
QVERIFY(black.toHsl() != black);
// Except for ExtendedRgb and Rgb, as it can be an automatic upgrade.
QCOMPARE(red, red.toExtendedRgb());
QCOMPARE(black.toExtendedRgb(), black);
}
void tst_QColor::premultiply() void tst_QColor::premultiply()
{ {
// Tests that qPremultiply(qUnpremultiply(x)) returns x. // Tests that qPremultiply(qUnpremultiply(x)) returns x.