aboutsummaryrefslogtreecommitdiffstats
path: root/src/tools/ivigenerator/templates_frontend
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@pelagicore.com>2018-10-16 11:21:27 +0200
committerDominik Holland <dominik.holland@pelagicore.com>2018-10-29 10:47:51 +0000
commite65f8d9783de9b0f24719c8299bc69382c6e9a67 (patch)
treebea6f02a94978bb76aa685a565726ad3fc517870 /src/tools/ivigenerator/templates_frontend
parent3c44b7c2e68bb8df12e7317c3e094732019cba2b (diff)
Add a way to load and parse the data to the QIviSimulationEngine
The new loadSimulationData() function can load a JSON file and store it's content in the IviSimulator singelton. The IviSimulator singleton provides functions to interpret the JSON values and other helpers e.g. checking for min/max/domain values. Task-number: AUTOSUITE-629 Change-Id: I2832cc0b29379144845a8ed295fc2d988273ff0c Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
Diffstat (limited to 'src/tools/ivigenerator/templates_frontend')
-rw-r--r--src/tools/ivigenerator/templates_frontend/struct.cpp.tpl27
-rw-r--r--src/tools/ivigenerator/templates_frontend/struct.h.tpl7
2 files changed, 31 insertions, 3 deletions
diff --git a/src/tools/ivigenerator/templates_frontend/struct.cpp.tpl b/src/tools/ivigenerator/templates_frontend/struct.cpp.tpl
index 43ec933..488f1a9 100644
--- a/src/tools/ivigenerator/templates_frontend/struct.cpp.tpl
+++ b/src/tools/ivigenerator/templates_frontend/struct.cpp.tpl
@@ -43,6 +43,8 @@
#include "{{class|lower}}.h"
+#include <qiviqmlconversion_helper.h>
+
QT_BEGIN_NAMESPACE
class {{class}}Private : public QSharedData
@@ -105,6 +107,31 @@ public:
{
}
+{{class}}::{{class}}(const QVariant &variant)
+ : {{class}}()
+{
+ QVariant value = convertFromJSON(variant);
+ // First try to convert the values to a Map or a List
+ // This is needed as it could also store a QStringList or a Hash
+ if (value.canConvert(QVariant::Map))
+ value.convert(QVariant::Map);
+ if (value.canConvert(QVariant::List))
+ value.convert(QVariant::List);
+
+ if (value.type() == QVariant::Map) {
+ QVariantMap map = value.toMap();
+{% for field in struct.fields %}
+ if (map.contains(QStringLiteral("{{field}}")))
+ d->m_{{field}} = map.value(QStringLiteral("{{field}}")).value<{{field|return_type}}>();
+{% endfor %}
+ } else if (value.type() == QVariant::List) {
+ QVariantList values = value.toList();
+{% for field in struct.fields %}
+ d->m_{{field}} = values.value({{loop.index0}}).value<{{field|return_type}}>();
+{% endfor %}
+ }
+}
+
/*! \internal */
{{class}}::~{{class}}()
{
diff --git a/src/tools/ivigenerator/templates_frontend/struct.h.tpl b/src/tools/ivigenerator/templates_frontend/struct.h.tpl
index ed85fef..da67518 100644
--- a/src/tools/ivigenerator/templates_frontend/struct.h.tpl
+++ b/src/tools/ivigenerator/templates_frontend/struct.h.tpl
@@ -71,10 +71,11 @@ class {{exportsymbol}} {{class}} : public QIviStandardItem
{% endfor %}
Q_CLASSINFO("IviPropertyDomains", "{{ struct.fields|json_domain|replace("\"", "\\\"") }}")
public:
- {{class}}();
- {{class}}(const {{class}} &rhs);
+ Q_INVOKABLE {{class}}();
+ Q_INVOKABLE {{class}}(const {{class}} &rhs);
{{class}} &operator=(const {{class}} &);
- {{class}}({% for field in struct.fields %}{% if not loop.first %}, {% endif %}{{field|return_type}} {{field}}{% endfor %});
+ Q_INVOKABLE {{class}}({% for field in struct.fields %}{% if not loop.first %}, {% endif %}{{field|return_type}} {{field}}{% endfor %});
+ Q_INVOKABLE {{class}}(const QVariant &variant);
~{{class}}();
QString type() const override;