diff options
Diffstat (limited to 'tests/auto')
6 files changed, 127 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlvaluetypes/data/grouped_interceptors_component.qml b/tests/auto/qml/qqmlvaluetypes/data/grouped_interceptors_component.qml new file mode 100644 index 0000000000..7b8b587542 --- /dev/null +++ b/tests/auto/qml/qqmlvaluetypes/data/grouped_interceptors_component.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyColorObject { + color: "#8000FF" + MyFloatSetInterceptor on color.r {} +} diff --git a/tests/auto/qml/qqmlvaluetypes/data/grouped_interceptors_ignore.qml b/tests/auto/qml/qqmlvaluetypes/data/grouped_interceptors_ignore.qml new file mode 100644 index 0000000000..f1a498cb67 --- /dev/null +++ b/tests/auto/qml/qqmlvaluetypes/data/grouped_interceptors_ignore.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyColorObject { + color: "#8000FF" + MyFloatIgnoreInterceptor on color.r {} +} diff --git a/tests/auto/qml/qqmlvaluetypes/data/grouped_interceptors_value.qml b/tests/auto/qml/qqmlvaluetypes/data/grouped_interceptors_value.qml new file mode 100644 index 0000000000..1d6194c041 --- /dev/null +++ b/tests/auto/qml/qqmlvaluetypes/data/grouped_interceptors_value.qml @@ -0,0 +1,10 @@ +import Test 1.0 + +MyColorObject { + color.r: 0.1 + color.g: 0.2 + color.b: 0.3 + color.a: 0.4 + + MyColorInterceptor on color {} +} diff --git a/tests/auto/qml/qqmlvaluetypes/testtypes.cpp b/tests/auto/qml/qqmlvaluetypes/testtypes.cpp index ef9f268b2f..16f8b3ce55 100644 --- a/tests/auto/qml/qqmlvaluetypes/testtypes.cpp +++ b/tests/auto/qml/qqmlvaluetypes/testtypes.cpp @@ -45,4 +45,8 @@ void registerTypes() qmlRegisterType<MyTypeObject>("Test", 1, 0, "MyTypeObject"); qmlRegisterType<MyConstantValueSource>("Test", 1, 0, "MyConstantValueSource"); qmlRegisterType<MyOffsetValueInterceptor>("Test", 1, 0, "MyOffsetValueInterceptor"); + qmlRegisterType<MyColorObject>("Test", 1, 0, "MyColorObject"); + qmlRegisterType<MyColorInterceptor>("Test", 1, 0, "MyColorInterceptor"); + qmlRegisterType<MyFloatSetInterceptor>("Test", 1, 0, "MyFloatSetInterceptor"); + qmlRegisterType<MyFloatIgnoreInterceptor>("Test", 1, 0, "MyFloatIgnoreInterceptor"); } diff --git a/tests/auto/qml/qqmlvaluetypes/testtypes.h b/tests/auto/qml/qqmlvaluetypes/testtypes.h index 813c58567f..f4ad151cdf 100644 --- a/tests/auto/qml/qqmlvaluetypes/testtypes.h +++ b/tests/auto/qml/qqmlvaluetypes/testtypes.h @@ -214,6 +214,66 @@ private: QQmlProperty prop; }; +// This test interceptor deliberately swizzles RGBA -> ABGR +class MyColorInterceptor : public QObject, public QQmlPropertyValueInterceptor +{ + Q_OBJECT + Q_INTERFACES(QQmlPropertyValueInterceptor) +public: + virtual void setTarget(const QQmlProperty &p) { prop = p; } + virtual void write(const QVariant &v) + { + QColor c = v.value<QColor>(); + + int r, g, b, a; + c.getRgb(&r, &g, &b, &a); + c.setRgb(a, b, g, r); + + QQmlPropertyPrivate::write(prop, c, QQmlPropertyPrivate::BypassInterceptor); + } + +private: + QQmlProperty prop; +}; + +class MyFloatSetInterceptor : public QObject, public QQmlPropertyValueInterceptor +{ + Q_OBJECT + Q_INTERFACES(QQmlPropertyValueInterceptor) +public: + virtual void setTarget(const QQmlProperty &p) { prop = p; } + virtual void write(const QVariant &) + { + QQmlPropertyPrivate::write(prop, 0.0f, QQmlPropertyPrivate::BypassInterceptor); + } + +private: + QQmlProperty prop; +}; + +class MyFloatIgnoreInterceptor : public QObject, public QQmlPropertyValueInterceptor +{ + Q_OBJECT + Q_INTERFACES(QQmlPropertyValueInterceptor) +public: + virtual void setTarget(const QQmlProperty &) {} + virtual void write(const QVariant &) {} +}; + +class MyColorObject : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QColor color READ color WRITE setColor) + +public: + MyColorObject() {} + + QColor m_color; + QColor color() const { return m_color; } + void setColor(const QColor &v) { m_color = v; } +}; + void registerTypes(); #endif // TESTTYPES_H diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp index 0c890dea74..f038b9dbfb 100644 --- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp +++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp @@ -95,6 +95,8 @@ private slots: void bindingsSpliceCorrectly(); void nonValueTypeComparison(); void initializeByWrite(); + void groupedInterceptors(); + void groupedInterceptors_data(); private: QQmlEngine engine; @@ -1346,6 +1348,45 @@ void tst_qqmlvaluetypes::initializeByWrite() delete object; } +void tst_qqmlvaluetypes::groupedInterceptors_data() +{ + QTest::addColumn<QString>("qmlfile"); + QTest::addColumn<QColor>("expectedInitialColor"); + QTest::addColumn<QColor>("setColor"); + QTest::addColumn<QColor>("expectedFinalColor"); + + QColor c0, c1, c2; + c0.setRgbF(0.1f, 0.2f, 0.3f, 0.4f); + c1.setRgbF(0.2f, 0.4f, 0.6f, 0.8f); + c2.setRgbF(0.8f, 0.6f, 0.4f, 0.2f); + + QTest::newRow("value-interceptor") << QString::fromLatin1("grouped_interceptors_value.qml") << c0 << c1 << c2; + QTest::newRow("component-interceptor") << QString::fromLatin1("grouped_interceptors_component.qml") << QColor(128, 0, 255) << QColor(50, 100, 200) << QColor(0, 100, 200); + QTest::newRow("ignore-interceptor") << QString::fromLatin1("grouped_interceptors_ignore.qml") << QColor(128, 0, 255) << QColor(50, 100, 200) << QColor(128, 100, 200); +} + +void tst_qqmlvaluetypes::groupedInterceptors() +{ + QFETCH(QString, qmlfile); + QFETCH(QColor, expectedInitialColor); + QFETCH(QColor, setColor); + QFETCH(QColor, expectedFinalColor); + + QQmlComponent component(&engine, testFileUrl(qmlfile)); + QObject *object = component.create(); + QVERIFY(object != 0); + + QColor initialColor = object->property("color").value<QColor>(); + QCOMPARE(initialColor, expectedInitialColor); + + object->setProperty("color", setColor); + + QColor finalColor = object->property("color").value<QColor>(); + QCOMPARE(finalColor, expectedFinalColor); + + delete object; +} + QTEST_MAIN(tst_qqmlvaluetypes) #include "tst_qqmlvaluetypes.moc" |