Skip to content

Commit

Permalink
Allow setting values in value type group properties in "on" assignments
Browse files Browse the repository at this point in the history
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.

Change-Id: I505a658977a578894d6dfb00bf5c65b41e42b12f
Task-number: QTBUG-56600
Reviewed-by: Michael Brasser <michael.brasser@live.com>
(cherry picked from commit 2659c308792967322564b5088e0e21bb371e0283)
  • Loading branch information
tronical committed Feb 26, 2018
1 parent ec4c897 commit ded165b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/qml/compiler/qqmlpropertyvalidator.cpp
Expand Up @@ -196,7 +196,13 @@ QVector<QQmlCompileError> QQmlPropertyValidator::validateObject(int objectIndex,
}

if (binding->type >= QV4::CompiledData::Binding::Type_Object && (pd || binding->isAttachedProperty())) {
const QVector<QQmlCompileError> subObjectValidatorErrors = 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 QVector<QQmlCompileError> subObjectValidatorErrors
= validateObject(binding->value.objectIndex, binding,
populatingValueTypeGroupProperty);
if (!subObjectValidatorErrors.isEmpty())
return subObjectValidatorErrors;
}
Expand Down
@@ -0,0 +1,11 @@
import QtQuick 2.0

Rectangle {
ColorAnimation on color {
id: animation
from: "red"
to: "darkgray"
duration: 250
easing.type: Easing.InOutQuad
}
}
17 changes: 17 additions & 0 deletions tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
Expand Up @@ -38,6 +38,7 @@
#include <QFont>
#include <QQmlFileSelector>
#include <QFileSelector>
#include <QEasingCurve>

#include <private/qqmlproperty_p.h>
#include <private/qqmlmetatype_p.h>
Expand Down Expand Up @@ -275,6 +276,8 @@ private slots:

void thisInQmlScope();

void valueTypeGroupPropertiesInBehavior();

private:
QQmlEngine engine;
QStringList defaultImportPathList;
Expand Down Expand Up @@ -4619,6 +4622,20 @@ void tst_qqmllanguage::thisInQmlScope()
QCOMPARE(o->property("y"), QVariant(42));
}

void tst_qqmllanguage::valueTypeGroupPropertiesInBehavior()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("groupPropertyInPropertyValueSource.qml"));
VERIFY_ERRORS(0);
QScopedPointer<QObject> o(component.create());
QVERIFY(!o.isNull());

QObject *animation = qmlContext(o.data())->contextProperty("animation").value<QObject*>();
QVERIFY(animation);

QCOMPARE(animation->property("easing").value<QEasingCurve>().type(), QEasingCurve::InOutQuad);
}

QTEST_MAIN(tst_qqmllanguage)

#include "tst_qqmllanguage.moc"

0 comments on commit ded165b

Please sign in to comment.