aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Shparber <trollixx@gmail.com>2014-06-24 17:03:08 -0700
committerOleg Shparber <trollixx@gmail.com>2014-06-25 17:31:47 +0200
commit435fb273355566c2888f8f685a369ce689869a14 (patch)
tree30ab03d005681f9a7666d5e76ad98bb419905263
parent57e3ef14fdcf6ae337075b68d374827b12397a7d (diff)
Allow integer values to be assigned QList<qreal> properties
Before this patch it was not possible to assign an integer value to QList<qreal> property, while it worked for non-list properties. Change-Id: Iab00288f7d78f4f76056ab4291700d7f51626de4 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
-rw-r--r--src/qml/compiler/qqmltypecompiler.cpp2
-rw-r--r--src/qml/qml/qqmlproperty.cpp3
-rw-r--r--tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.1.qml2
-rw-r--r--tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.3.qml2
-rw-r--r--tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.4.qml2
-rw-r--r--tests/auto/qml/qqmlecmascript/data/assignSequenceTypes.6.qml2
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp8
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<QList<qreal> >()) {
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<QList<int> >(list);
ok = true;
- } else if (variantType == QVariant::Double && propertyType == qMetaTypeId<QList<qreal> >()) {
+ } else if ((variantType == QVariant::Double || variantType == QVariant::Int)
+ && (propertyType == qMetaTypeId<QList<qreal> >())) {
QList<qreal> list;
list << value.toReal();
v = QVariant::fromValue<QList<qreal> >(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<MySequenceConversionObject *>(component.create());
QVERIFY(object != 0);
QCOMPARE(object->intListProperty(), (QList<int>() << 1 << 2));
- QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1.1 << 2.2));
+ QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1.1 << 2.2 << 3));
QCOMPARE(object->boolListProperty(), (QList<bool>() << false << true));
QCOMPARE(object->urlListProperty(), (QList<QUrl>() << QUrl("http://www.example1.com") << QUrl("http://www.example2.com")));
QCOMPARE(object->stringListProperty(), (QList<QString>() << QLatin1String("one") << QLatin1String("two")));
@@ -5576,7 +5576,7 @@ void tst_qqmlecmascript::assignSequenceTypes()
MySequenceConversionObject *object = qobject_cast<MySequenceConversionObject *>(component.create());
QVERIFY(object != 0);
QCOMPARE(object->intListProperty(), (QList<int>() << 1));
- QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1.1));
+ QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1));
QCOMPARE(object->boolListProperty(), (QList<bool>() << false));
QCOMPARE(object->urlListProperty(), (QList<QUrl>() << QUrl(testFileUrl("example.html"))));
delete object;
@@ -5588,7 +5588,7 @@ void tst_qqmlecmascript::assignSequenceTypes()
MySequenceConversionObject *object = qobject_cast<MySequenceConversionObject *>(component.create());
QVERIFY(object != 0);
QCOMPARE(object->intListProperty(), (QList<int>() << 1 << 2));
- QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1.1 << 2.2));
+ QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1.1 << 2.2 << 3));
QCOMPARE(object->boolListProperty(), (QList<bool>() << false << true));
QCOMPARE(object->urlListProperty(), (QList<QUrl>() << QUrl("http://www.example1.com") << QUrl("http://www.example2.com")));
QCOMPARE(object->stringListProperty(), (QList<QString>() << QLatin1String("one") << QLatin1String("two")));
@@ -5616,7 +5616,7 @@ void tst_qqmlecmascript::assignSequenceTypes()
MySequenceConversionObject *object = qobject_cast<MySequenceConversionObject *>(component.create());
QVERIFY(object != 0);
QCOMPARE(object->intListProperty(), (QList<int>() << 1));
- QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1.1));
+ QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1));
QCOMPARE(object->boolListProperty(), (QList<bool>() << false));
QCOMPARE(object->urlListProperty(), (QList<QUrl>() << QUrl(testFileUrl("example.html"))));
delete object;