QColor: unify behavior when passing invalid values to setFoo()
Calling QColor::setFoo() is currently inconsistent - some setter do invalidate the colors, some don't. Unify it by calling invalidate in every setter. Task-number: QTBUG-62452 Change-Id: Ia4f0bd16ea30e9659bc989ffc2b319892438b84b Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>bb10
parent
329eef34f4
commit
03b1d2c449
|
|
@ -1086,6 +1086,7 @@ void QColor::setHsvF(qreal h, qreal s, qreal v, qreal a)
|
|||
|| (v < qreal(0.0) || v > qreal(1.0))
|
||||
|| (a < qreal(0.0) || a > qreal(1.0))) {
|
||||
qWarning("QColor::setHsvF: HSV parameters out of range");
|
||||
invalidate();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1198,7 +1199,8 @@ void QColor::setHslF(qreal h, qreal s, qreal l, qreal a)
|
|||
|| (s < qreal(0.0) || s > qreal(1.0))
|
||||
|| (l < qreal(0.0) || l > qreal(1.0))
|
||||
|| (a < qreal(0.0) || a > qreal(1.0))) {
|
||||
qWarning("QColor::setHsvF: HSV parameters out of range");
|
||||
qWarning("QColor::setHslF: HSL parameters out of range");
|
||||
invalidate();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1224,7 +1226,7 @@ void QColor::setHslF(qreal h, qreal s, qreal l, qreal a)
|
|||
void QColor::setHsl(int h, int s, int l, int a)
|
||||
{
|
||||
if (h < -1 || (uint)s > 255 || (uint)l > 255 || (uint)a > 255) {
|
||||
qWarning("QColor::setHsv: HSV parameters out of range");
|
||||
qWarning("QColor::setHsl: HSL parameters out of range");
|
||||
invalidate();
|
||||
return;
|
||||
}
|
||||
|
|
@ -2719,6 +2721,7 @@ void QColor::setCmyk(int c, int m, int y, int k, int a)
|
|||
|| k < 0 || k > 255
|
||||
|| a < 0 || a > 255) {
|
||||
qWarning("QColor::setCmyk: CMYK parameters out of range");
|
||||
invalidate();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -2748,6 +2751,7 @@ void QColor::setCmykF(qreal c, qreal m, qreal y, qreal k, qreal a)
|
|||
|| k < qreal(0.0) || k > qreal(1.0)
|
||||
|| a < qreal(0.0) || a > qreal(1.0)) {
|
||||
qWarning("QColor::setCmykF: CMYK parameters out of range");
|
||||
invalidate();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1032,6 +1032,15 @@ void tst_QColor::setRgbF()
|
|||
QCOMPARE(qfloat16(b2), qfloat16(b));
|
||||
}
|
||||
}
|
||||
QVERIFY(color.isValid());
|
||||
QColor invalidRgb = color;
|
||||
QColor invalidRgbF = color;
|
||||
QTest::ignoreMessage(QtWarningMsg, "QColor::setRgb: RGB parameters out of range");
|
||||
invalidRgb.setRgb(-1, -1, -1);
|
||||
QTest::ignoreMessage(QtWarningMsg, "QColor::setRgb: RGB parameters out of range");
|
||||
invalidRgbF.setRgb(-1, -1, -1, -1);
|
||||
QVERIFY(!invalidRgb.isValid());
|
||||
QVERIFY(!invalidRgbF.isValid());
|
||||
}
|
||||
|
||||
void tst_QColor::setRgba()
|
||||
|
|
@ -1146,6 +1155,16 @@ void tst_QColor::setHsv()
|
|||
QCOMPARE(v2, v);
|
||||
}
|
||||
}
|
||||
QVERIFY(color.isValid());
|
||||
QVERIFY(color.isValid());
|
||||
QColor invalidHsv = color;
|
||||
QColor invalidHsvF = color;
|
||||
QTest::ignoreMessage(QtWarningMsg, "QColor::setHsv: HSV parameters out of range");
|
||||
invalidHsv.setHsv(-1, -1, -1);
|
||||
QTest::ignoreMessage(QtWarningMsg, "QColor::setHsvF: HSV parameters out of range");
|
||||
invalidHsvF.setHsvF(-1, -1, -1);
|
||||
QVERIFY(!invalidHsv.isValid());
|
||||
QVERIFY(!invalidHsvF.isValid());
|
||||
}
|
||||
|
||||
void tst_QColor::setCmyk()
|
||||
|
|
@ -1271,6 +1290,15 @@ void tst_QColor::setCmyk()
|
|||
QCOMPARE(k2, k);
|
||||
}
|
||||
}
|
||||
QVERIFY(color.isValid());
|
||||
QColor invalidCmyk = color;
|
||||
QColor invalidCmykF = color;
|
||||
QTest::ignoreMessage(QtWarningMsg, "QColor::setCmyk: CMYK parameters out of range");
|
||||
invalidCmyk.setCmyk(-1, -1, -1, -1, -1);
|
||||
QTest::ignoreMessage(QtWarningMsg, "QColor::setCmykF: CMYK parameters out of range");
|
||||
invalidCmykF.setCmykF(-1, -1, -1, -1, -1);
|
||||
QVERIFY(!invalidCmyk.isValid());
|
||||
QVERIFY(!invalidCmykF.isValid());
|
||||
}
|
||||
|
||||
void tst_QColor::setHsl()
|
||||
|
|
@ -1372,6 +1400,15 @@ void tst_QColor::setHsl()
|
|||
QCOMPARE(l2, l);
|
||||
}
|
||||
}
|
||||
QVERIFY(color.isValid());
|
||||
QColor invalidHsl = color;
|
||||
QColor invalidHslF = color;
|
||||
QTest::ignoreMessage(QtWarningMsg, "QColor::setHsl: HSL parameters out of range");
|
||||
invalidHsl.setHsl(-1, -1, -1, -1);
|
||||
QTest::ignoreMessage(QtWarningMsg, "QColor::setHslF: HSL parameters out of range");
|
||||
invalidHslF.setHslF(-1, -1, -1, -1);
|
||||
QVERIFY(!invalidHsl.isValid());
|
||||
QVERIFY(!invalidHslF.isValid());
|
||||
}
|
||||
|
||||
void tst_QColor::toRgb_data()
|
||||
|
|
|
|||
Loading…
Reference in New Issue