diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2019-10-07 10:56:35 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-10-08 09:28:49 +0200 |
commit | e80ef5934e71bcc52bdcabb6d3fe1d1b100d75c4 (patch) | |
tree | bb05031efb0546694f5cefb40a87577eefb83ce4 /tests | |
parent | e5f3e7149b7e130c375c1419f1f804dfeaf578aa (diff) |
Add a property "valid" to the color value type
This gives users a more convenient way to determine if a particular
color is valid. Before you had to actually compare with an invalid
color.
Fixes: QTBUG-78325
Change-Id: Id86bc46a48aa11da3e6654d2940d758d2b0e784f
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmlvaluetypes/data/color_read.qml | 3 | ||||
-rw-r--r-- | tests/auto/qml/qqmlvaluetypes/testtypes.h | 3 | ||||
-rw-r--r-- | tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp | 5 |
3 files changed, 11 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlvaluetypes/data/color_read.qml b/tests/auto/qml/qqmlvaluetypes/data/color_read.qml index 73d2b921a7..a2d303b507 100644 --- a/tests/auto/qml/qqmlvaluetypes/data/color_read.qml +++ b/tests/auto/qml/qqmlvaluetypes/data/color_read.qml @@ -12,4 +12,7 @@ MyTypeObject { property real hsl_s: color.hslSaturation property real hsl_l: color.hslLightness property variant copy: color + + property bool valid: color.valid + property bool invalid: invalidColor.valid } diff --git a/tests/auto/qml/qqmlvaluetypes/testtypes.h b/tests/auto/qml/qqmlvaluetypes/testtypes.h index bcfe4028c6..798c96e188 100644 --- a/tests/auto/qml/qqmlvaluetypes/testtypes.h +++ b/tests/auto/qml/qqmlvaluetypes/testtypes.h @@ -69,6 +69,7 @@ class MyTypeObject : public QObject Q_PROPERTY(QMatrix4x4 matrix READ matrix WRITE setMatrix NOTIFY changed) Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed) Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY changed) + Q_PROPERTY(QColor invalidColor READ invalidColor CONSTANT) Q_PROPERTY(QVariant variant READ variant NOTIFY changed) public: @@ -168,6 +169,8 @@ public: QColor color() const { return m_color; } void setColor(const QColor &v) { m_color = v; emit changed(); } + QColor invalidColor() const { return QColor(); } + QVariant variant() const { return sizef(); } void emitRunScript() { emit runScript(); } diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp index a55da25a91..3e9047cc5a 100644 --- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp +++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp @@ -935,6 +935,11 @@ void tst_qqmlvaluetypes::color() QCOMPARE(qRound(object->property("hsl_s").toDouble() * 100), 74); QCOMPARE(qRound(object->property("hsl_l").toDouble() * 100), 54); + QCOMPARE(object->property("valid").userType(), QMetaType::Bool); + QVERIFY(object->property("valid").toBool()); + QCOMPARE(object->property("invalid").userType(), QMetaType::Bool); + QVERIFY(!object->property("invalid").toBool()); + QColor comparison; comparison.setRedF(0.2); comparison.setGreenF(0.88); |