diff --git a/src/plugins/qmldesigner/core/model/texttomodelmerger.cpp b/src/plugins/qmldesigner/core/model/texttomodelmerger.cpp index 7439cbf97ba4da090283c5021df15e8e49c75262..dd264fbfd75f4aee006a840c7de0987eedb4e413 100644 --- a/src/plugins/qmldesigner/core/model/texttomodelmerger.cpp +++ b/src/plugins/qmldesigner/core/model/texttomodelmerger.cpp @@ -179,6 +179,8 @@ static inline int propertyType(const QString &typeName) return QMetaType::type("int"); else if (typeName == QLatin1String("real")) return QMetaType::type("double"); + else if (typeName == QLatin1String("double")) + return QMetaType::type("double"); else if (typeName == QLatin1String("string")) return QMetaType::type("QString"); else if (typeName == QLatin1String("url")) @@ -650,9 +652,16 @@ QVariant TextToModelMerger::convertToVariant(const ModelNode &node, if (!astType.isEmpty()) { const int type = propertyType(astType); - QVariant value(cleanedValue); - value.convert(static_cast<QVariant::Type>(type)); - return value; + if (type == QMetaType::type("QVariant")) { + if (cleanedValue.isNull()) // Explicitly isNull, NOT isEmpty! + return QVariant(static_cast<QVariant::Type>(type)); + else + return QVariant(cleanedValue); + } else { + QVariant value = QVariant(cleanedValue); + value.convert(static_cast<QVariant::Type>(type)); + return value; + } const QString typeName = QMetaType::typeName(type); return Internal::PropertyParser::read(typeName, astValue, nodeMetaInfo.metaInfo()); diff --git a/tests/auto/qml/qmldesigner/coretests/testcore.cpp b/tests/auto/qml/qmldesigner/coretests/testcore.cpp index 8c4d94308e7b47056e86fb91be7ecbb8321be563..2d5123fcbdcd65b95e7a12e3984e9386a4f9c9a0 100644 --- a/tests/auto/qml/qmldesigner/coretests/testcore.cpp +++ b/tests/auto/qml/qmldesigner/coretests/testcore.cpp @@ -451,13 +451,13 @@ void TestCore::testRewriterDynamicProperties() QVERIFY(rootModelNode.hasVariantProperty("d")); QCOMPARE(rootModelNode.variantProperty("d").dynamicTypeName(), QString("double")); QCOMPARE(rootModelNode.variantProperty("d").value().type(), QVariant::Double); - QCOMPARE(testRewriterView1->rootModelNode().variantProperty("b").value().toDouble(), 0.0); + QCOMPARE(testRewriterView1->rootModelNode().variantProperty("d").value().toDouble(), 0.0); QVERIFY(rootModelNode.hasVariantProperty("dd")); QCOMPARE(testRewriterView1->rootModelNode().variantProperty("dd").value().toDouble(), 1.1); QVERIFY(rootModelNode.hasVariantProperty("r")); - QCOMPARE(rootModelNode.variantProperty("r").dynamicTypeName(), QString("double")); + QCOMPARE(rootModelNode.variantProperty("r").dynamicTypeName(), QString("real")); QCOMPARE(rootModelNode.variantProperty("r").value().type(), QVariant::Double); QCOMPARE(testRewriterView1->rootModelNode().variantProperty("r").value().toDouble(), 0.0); @@ -490,7 +490,7 @@ void TestCore::testRewriterDynamicProperties() QVERIFY(rootModelNode.hasVariantProperty("t")); QCOMPARE(rootModelNode.variantProperty("t").dynamicTypeName(), QString("date")); - QCOMPARE(rootModelNode.variantProperty("t").value().type(), QVariant::Color); + QCOMPARE(rootModelNode.variantProperty("t").value().type(), QVariant::Date); QCOMPARE(testRewriterView1->rootModelNode().variantProperty("t").value().value<QDate>(), QDate()); QVERIFY(rootModelNode.hasVariantProperty("tt")); @@ -498,10 +498,12 @@ void TestCore::testRewriterDynamicProperties() QVERIFY(rootModelNode.hasVariantProperty("v")); QCOMPARE(rootModelNode.variantProperty("v").dynamicTypeName(), QString("var")); - QCOMPARE(rootModelNode.variantProperty("v").value().type(), QVariant::Invalid); + const int type = rootModelNode.variantProperty("v").value().type(); + QCOMPARE(type, QMetaType::type("QVariant")); QVERIFY(rootModelNode.hasVariantProperty("vv")); - QCOMPARE(testRewriterView1->rootModelNode().variantProperty("vv").value().value<QString>(), QString("hello")); + const QString inThere = testRewriterView1->rootModelNode().variantProperty("vv").value().value<QString>(); + QCOMPARE(inThere, QString("Hello")); // test model2text // QPlainTextEdit textEdit2;