From 10647ce9da45deedcd58397c7e1d21e61b80b78a Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 21 Feb 2018 17:09:50 +0100 Subject: Allow setting values in value type group properties in "on" assignments Assigning to a group property inside a property value source or interceptor as part of an "on assignment" is perfectly valid. That is because while "color" is a value type property, the on assignment means we're actually setting easing.type (in the example and test) on the property value source, not the color, and that one is a QObject. The same goes for interceptors. Conflicts: src/qml/compiler/qqmlpropertyvalidator.cpp src/qml/qml/qqmlvmemetaobject_p.h tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp Change-Id: I505a658977a578894d6dfb00bf5c65b41e42b12f Task-number: QTBUG-56600 Reviewed-by: Michael Brasser (cherry picked from commit 2659c308792967322564b5088e0e21bb371e0283) --- src/qml/compiler/qqmltypecompiler.cpp | 6 +++++- .../data/groupPropertyInPropertyValueSource.qml | 11 +++++++++++ tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qml/qqmllanguage/data/groupPropertyInPropertyValueSource.qml diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp index 82332dfc35..5a42fc15a6 100644 --- a/src/qml/compiler/qqmltypecompiler.cpp +++ b/src/qml/compiler/qqmltypecompiler.cpp @@ -1914,7 +1914,11 @@ bool QQmlPropertyValidator::validateObject(int objectIndex, const QV4::CompiledD if (binding->type >= QV4::CompiledData::Binding::Type_Object && (pd || binding->isAttachedProperty())) { qSwap(_seenObjectWithId, seenSubObjectWithId); - const bool subObjectValid = validateObject(binding->value.objectIndex, binding, pd && QQmlValueTypeFactory::metaObjectForMetaType(pd->propType)); + const bool populatingValueTypeGroupProperty + = pd + && QQmlValueTypeFactory::metaObjectForMetaType(pd->propType) + && !(binding->flags & QV4::CompiledData::Binding::IsOnAssignment); + const bool subObjectValid = validateObject(binding->value.objectIndex, binding, populatingValueTypeGroupProperty); qSwap(_seenObjectWithId, seenSubObjectWithId); if (!subObjectValid) return false; diff --git a/tests/auto/qml/qqmllanguage/data/groupPropertyInPropertyValueSource.qml b/tests/auto/qml/qqmllanguage/data/groupPropertyInPropertyValueSource.qml new file mode 100644 index 0000000000..579086fa1c --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/groupPropertyInPropertyValueSource.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 + +Rectangle { + ColorAnimation on color { + id: animation + from: "red" + to: "darkgray" + duration: 250 + easing.type: Easing.InOutQuad + } +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 2a519d55f0..5f6185ad01 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -255,6 +256,8 @@ private slots: void deleteSingletons(); + void valueTypeGroupPropertiesInBehavior(); + private: QQmlEngine engine; QStringList defaultImportPathList; @@ -4154,6 +4157,20 @@ void tst_qqmllanguage::deleteSingletons() QVERIFY(singleton.data() == 0); } +void tst_qqmllanguage::valueTypeGroupPropertiesInBehavior() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("groupPropertyInPropertyValueSource.qml")); + VERIFY_ERRORS(0); + QScopedPointer o(component.create()); + QVERIFY(!o.isNull()); + + QObject *animation = qmlContext(o.data())->contextProperty("animation").value(); + QVERIFY(animation); + + QCOMPARE(animation->property("easing").value().type(), QEasingCurve::InOutQuad); +} + QTEST_MAIN(tst_qqmllanguage) #include "tst_qqmllanguage.moc" -- cgit v1.2.3