From 435fb273355566c2888f8f685a369ce689869a14 Mon Sep 17 00:00:00 2001 From: Oleg Shparber Date: Tue, 24 Jun 2014 17:03:08 -0700 Subject: Allow integer values to be assigned QList properties Before this patch it was not possible to assign an integer value to QList property, while it worked for non-list properties. Change-Id: Iab00288f7d78f4f76056ab4291700d7f51626de4 Reviewed-by: Simon Hausmann --- src/qml/compiler/qqmltypecompiler.cpp | 2 +- src/qml/qml/qqmlproperty.cpp | 3 ++- tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.1.qml | 2 +- tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.3.qml | 2 +- tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.4.qml | 2 +- tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.6.qml | 2 +- tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 8 ++++---- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp index e1f68a6dac..e2636a57c3 100644 --- a/src/qml/compiler/qqmltypecompiler.cpp +++ b/src/qml/compiler/qqmltypecompiler.cpp @@ -2244,7 +2244,7 @@ bool QQmlPropertyValidator::validateLiteralBinding(QQmlPropertyCache *propertyCa // generate single literal value assignment to a list property if required if (property->propType == qMetaTypeId >()) { if (binding->type != QV4::CompiledData::Binding::Type_Number) { - recordError(binding->valueLocation, tr("Invalid property assignment: real or array of reals expected")); + recordError(binding->valueLocation, tr("Invalid property assignment: number or array of numbers expected")); return false; } break; diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index 1075b53c5e..c9d5f76fbd 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -1427,7 +1427,8 @@ bool QQmlPropertyPrivate::write(QObject *object, list << value.toInt(); v = QVariant::fromValue >(list); ok = true; - } else if (variantType == QVariant::Double && propertyType == qMetaTypeId >()) { + } else if ((variantType == QVariant::Double || variantType == QVariant::Int) + && (propertyType == qMetaTypeId >())) { QList list; list << value.toReal(); v = QVariant::fromValue >(list); diff --git a/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.1.qml b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.1.qml index be283fdda1..027fdbdfcb 100644 --- a/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.1.qml +++ b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.1.qml @@ -3,7 +3,7 @@ import Qt.test 1.0 MySequenceConversionObject { intListProperty: [1, 2] - qrealListProperty: [1.1, 2.2] + qrealListProperty: [1.1, 2.2, 3] boolListProperty: [false, true] urlListProperty: [ "http://www.example1.com", "http://www.example2.com" ] stringListProperty: [ "one", "two" ] diff --git a/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.3.qml b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.3.qml index ad8a92e317..e486feb96c 100644 --- a/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.3.qml +++ b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.3.qml @@ -3,7 +3,7 @@ import Qt.test 1.0 MySequenceConversionObject { intListProperty: 1 - qrealListProperty: 1.1 + qrealListProperty: 1 boolListProperty: false urlListProperty: Qt.resolvedUrl("example.html") } diff --git a/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.4.qml b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.4.qml index a9f2e642d1..10e49af8e0 100644 --- a/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.4.qml +++ b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.4.qml @@ -4,7 +4,7 @@ import Qt.test 1.0 MySequenceConversionObject { Component.onCompleted: { intListProperty = [1, 2] - qrealListProperty = [1.1, 2.2] + qrealListProperty = [1.1, 2.2, 3] boolListProperty = [false, true] urlListProperty = [ "http://www.example1.com", "http://www.example2.com" ] stringListProperty = [ "one", "two" ] diff --git a/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.6.qml b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.6.qml index 7a794eb694..bc72b78af7 100644 --- a/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.6.qml +++ b/tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.6.qml @@ -4,7 +4,7 @@ import Qt.test 1.0 MySequenceConversionObject { Component.onCompleted: { intListProperty = 1; - qrealListProperty = 1.1; + qrealListProperty = 1; boolListProperty = false; urlListProperty = Qt.resolvedUrl("example.html"); } diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 770d6b8197..35fb42f02d 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -5548,7 +5548,7 @@ void tst_qqmlecmascript::assignSequenceTypes() MySequenceConversionObject *object = qobject_cast(component.create()); QVERIFY(object != 0); QCOMPARE(object->intListProperty(), (QList() << 1 << 2)); - QCOMPARE(object->qrealListProperty(), (QList() << 1.1 << 2.2)); + QCOMPARE(object->qrealListProperty(), (QList() << 1.1 << 2.2 << 3)); QCOMPARE(object->boolListProperty(), (QList() << false << true)); QCOMPARE(object->urlListProperty(), (QList() << QUrl("http://www.example1.com") << QUrl("http://www.example2.com"))); QCOMPARE(object->stringListProperty(), (QList() << QLatin1String("one") << QLatin1String("two"))); @@ -5576,7 +5576,7 @@ void tst_qqmlecmascript::assignSequenceTypes() MySequenceConversionObject *object = qobject_cast(component.create()); QVERIFY(object != 0); QCOMPARE(object->intListProperty(), (QList() << 1)); - QCOMPARE(object->qrealListProperty(), (QList() << 1.1)); + QCOMPARE(object->qrealListProperty(), (QList() << 1)); QCOMPARE(object->boolListProperty(), (QList() << false)); QCOMPARE(object->urlListProperty(), (QList() << QUrl(testFileUrl("example.html")))); delete object; @@ -5588,7 +5588,7 @@ void tst_qqmlecmascript::assignSequenceTypes() MySequenceConversionObject *object = qobject_cast(component.create()); QVERIFY(object != 0); QCOMPARE(object->intListProperty(), (QList() << 1 << 2)); - QCOMPARE(object->qrealListProperty(), (QList() << 1.1 << 2.2)); + QCOMPARE(object->qrealListProperty(), (QList() << 1.1 << 2.2 << 3)); QCOMPARE(object->boolListProperty(), (QList() << false << true)); QCOMPARE(object->urlListProperty(), (QList() << QUrl("http://www.example1.com") << QUrl("http://www.example2.com"))); QCOMPARE(object->stringListProperty(), (QList() << QLatin1String("one") << QLatin1String("two"))); @@ -5616,7 +5616,7 @@ void tst_qqmlecmascript::assignSequenceTypes() MySequenceConversionObject *object = qobject_cast(component.create()); QVERIFY(object != 0); QCOMPARE(object->intListProperty(), (QList() << 1)); - QCOMPARE(object->qrealListProperty(), (QList() << 1.1)); + QCOMPARE(object->qrealListProperty(), (QList() << 1)); QCOMPARE(object->boolListProperty(), (QList() << false)); QCOMPARE(object->urlListProperty(), (QList() << QUrl(testFileUrl("example.html")))); delete object; -- cgit v1.2.3