From f18b66ac6cfc734d217ec9d44876774f25e5d900 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Mon, 2 Jul 2012 09:10:49 +1000 Subject: Make Behaviors work correctly with value types. When a value type is referenced by sub-component a grouped property is built. This code path did not handle behaviors being declared on the entire value type. Add support for value interceptors in this code path. Also issue an additional write to the value type property before calling the interceptor on components that are not being intercepted, so that the other sub-components don't get stale values during write back. Task-number: QTBUG-22625 Change-Id: I3365f422dfa1ab2e536e19575efcceceffb85e10 Reviewed-by: Michael Brasser --- tests/auto/qml/qqmlvaluetypes/testtypes.h | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'tests/auto/qml/qqmlvaluetypes/testtypes.h') 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(); + + 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 -- cgit v1.2.3