diff options
author | Dominik Holland <dominik.holland@qt.io> | 2020-01-17 12:24:06 +0100 |
---|---|---|
committer | Dominik Holland <dominik.holland@qt.io> | 2020-01-21 16:03:09 +0100 |
commit | 45317b232c926276555f8dc100be21988ea46405 (patch) | |
tree | 41a793f540f18911622836d97301bfff4a19a626 | |
parent | 895d5505bb74148a4464947b31bfdbb4c11f5637 (diff) | |
download | qtivi-45317b232c926276555f8dc100be21988ea46405.tar.gz |
simulation: Fix struct initialization using JSON dictionaries
Instead of using a list of values to fill all members, it is also possible
to use a dictionary, which is more expressive.
This fixes the conversion function and adds an autotest for it.
Change-Id: I7b817a26622f95c7e9fe4d3ff853310c5ad87f32
Reviewed-by: Robert Griebl <robert.griebl@qt.io>
-rw-r--r-- | src/ivicore/qiviqmlconversion_helper.cpp | 6 | ||||
-rw-r--r-- | tests/auto/core/qivisimulationglobalobject/tst_qivisimulationglobalobject.cpp | 2 |
2 files changed, 3 insertions, 5 deletions
diff --git a/src/ivicore/qiviqmlconversion_helper.cpp b/src/ivicore/qiviqmlconversion_helper.cpp index f73eb41..2b13b7c 100644 --- a/src/ivicore/qiviqmlconversion_helper.cpp +++ b/src/ivicore/qiviqmlconversion_helper.cpp @@ -143,10 +143,6 @@ QVariant qtivi_convertFromJSON(const QVariant &value) return QVariant(); } - QVariantList values = value.toList(); - for (auto i = values.begin(); i != values.end(); ++i) - *i = qtivi_convertFromJSON(*i); - void *gadget = QMetaType::create(typeId); if (!Q_UNLIKELY(gadget)) { qWarning("Couldn't create a new instance of %s", QMetaType::typeName(typeId)); @@ -167,7 +163,7 @@ QVariant qtivi_convertFromJSON(const QVariant &value) return QVariant(); } - mo->method(moIdx).invokeOnGadget(gadget, Q_ARG(QVariant, QVariant(values))); + mo->method(moIdx).invokeOnGadget(gadget, Q_ARG(QVariant, QVariant(value))); return QVariant(typeId, gadget); } } diff --git a/tests/auto/core/qivisimulationglobalobject/tst_qivisimulationglobalobject.cpp b/tests/auto/core/qivisimulationglobalobject/tst_qivisimulationglobalobject.cpp index 1603b5f..546520a 100644 --- a/tests/auto/core/qivisimulationglobalobject/tst_qivisimulationglobalobject.cpp +++ b/tests/auto/core/qivisimulationglobalobject/tst_qivisimulationglobalobject.cpp @@ -344,6 +344,8 @@ void tst_QIviSimulationGlobalObject::testParseDomainValue_data() << QVariant::fromValue(SimpleAPI::EnumValue1); QTest::newRow("TestStruct by list") << "{ \"type\": \"TestStruct\", \"value\": [ 100, true ] }" << QVariant::fromValue(TestStruct(100, true)); + QTest::newRow("TestStruct by map") << "{ \"type\": \"TestStruct\", \"value\": { \"intProperty\": 100, \"boolProperty\": true } }" + << QVariant::fromValue(TestStruct(100, true)); } void tst_QIviSimulationGlobalObject::testParseDomainValue() |