aboutsummaryrefslogtreecommitdiffstats
path: root/src/tools/ivigenerator/templates_frontend
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@pelagicore.com>2018-06-22 16:41:16 +0200
committerDominik Holland <dominik.holland@pelagicore.com>2018-07-09 15:39:32 +0000
commit962121dd000f321cfe95c3c113c7fe9b57058777 (patch)
treec0a4b5425bc02f6dd0ac4bdf8d50306eaffc8479 /src/tools/ivigenerator/templates_frontend
parentb3ac38f4dd8cf76b972df20fcd0f4d68518c2ce6 (diff)
Rewrite the autogenerated structs to use QIviStandardItem
Using QIviStandardItem as a base class helps to make all the autogenerated structs usable within QIviPagingModel and all derived classes. In addition changed the autogenerated code to use QSharedData to use COW and implicit sharing. Task-number: AUTOSUITE-584 Change-Id: I45c8932046d36776091459c333b29d33acffc2e0 Reviewed-by: Antti Hölttä <ahoelttae@luxoft.com>
Diffstat (limited to 'src/tools/ivigenerator/templates_frontend')
-rw-r--r--src/tools/ivigenerator/templates_frontend/struct.cpp.tpl68
-rw-r--r--src/tools/ivigenerator/templates_frontend/struct.h.tpl17
2 files changed, 70 insertions, 15 deletions
diff --git a/src/tools/ivigenerator/templates_frontend/struct.cpp.tpl b/src/tools/ivigenerator/templates_frontend/struct.cpp.tpl
index d0309c6..16b8d16 100644
--- a/src/tools/ivigenerator/templates_frontend/struct.cpp.tpl
+++ b/src/tools/ivigenerator/templates_frontend/struct.cpp.tpl
@@ -45,6 +45,34 @@
QT_BEGIN_NAMESPACE
+class {{class}}Private : public QSharedData
+{
+public:
+ {{class}}Private()
+{% for field in struct.fields %}
+ {% if loop.first %}:{% else %},{% endif %} m_{{field}}({{field|default_type_value}})
+{% endfor %}
+ {}
+
+ {{class}}Private(const {{class}}Private &other)
+ : QSharedData(other)
+{% for field in struct.fields %}
+ , m_{{field}}(other.m_{{field}})
+{% endfor %}
+ {}
+
+ {{class}}Private({% for field in struct.fields %}{% if not loop.first %}, {% endif %}{{field|return_type}} {{field}}{% endfor %})
+ : QSharedData()
+{% for field in struct.fields %}
+ , m_{{field}}({{field}})
+{% endfor %}
+ {}
+
+{% for field in struct.fields %}
+ {{field|return_type}} m_{{field}};
+{% endfor %}
+};
+
/*!
\class {{struct}}
\inmodule {{module}}
@@ -52,16 +80,28 @@ QT_BEGIN_NAMESPACE
*/
{{class}}::{{class}}()
-{% for field in struct.fields %}
- {% if loop.first %}:{% else %},{% endif %} m_{{field}}({{field|default_type_value}})
-{% endfor %}
+ : QIviStandardItem()
+ , d(new {{class}}Private)
+{
+}
+
+{{class}}::{{class}}(const {{class}} &rhs)
+ : QIviStandardItem(rhs)
+ , d(rhs.d)
+{
+}
+
+{{class}} &{{class}}::operator=(const {{class}} &rhs)
{
+ QIviStandardItem::operator=(rhs);
+ if (this != &rhs)
+ d.operator=(rhs.d);
+ return *this;
}
{{class}}::{{class}}({% for field in struct.fields %}{% if not loop.first %}, {% endif %}{{field|return_type}} {{field}}{% endfor %})
-{% for field in struct.fields %}
- {% if loop.first %}:{% else %},{% endif %} m_{{field}}({{field}})
-{% endfor %}
+ : QIviStandardItem()
+ , d(new {{class}}Private({% for field in struct.fields %}{% if not loop.first %}, {% endif %}{{field}}{% endfor %}))
{
}
@@ -70,6 +110,11 @@ QT_BEGIN_NAMESPACE
{
}
+QString {{class}}::type() const
+{
+ return QLatin1String("{{struct|lower}}");
+}
+
{% for field in struct.fields %}
/*!
@@ -81,13 +126,13 @@ QT_BEGIN_NAMESPACE
*/
{{ivi.prop_getter(field, class)}}
{
- return m_{{field}};
+ return d->m_{{field}};
}
{% if not field.readonly and not field.const %}
{{ivi.prop_setter(field, class)}}
{
- m_{{field}} = {{field}};
+ d->m_{{field}} = {{field}};
}
{% endif %}
@@ -95,6 +140,9 @@ QT_BEGIN_NAMESPACE
bool operator==(const {{class}} &left, const {{class}} &right) Q_DECL_NOTHROW
{
+ if (left.d == right.d)
+ return true;
+ //FIX me for inheritance
return (
{% for field in struct.fields %}
left.{{field}}() == right.{{field}}() {% if not loop.last %}&&{% endif %}
@@ -110,6 +158,7 @@ bool operator!=(const {{class}} &left, const {{class}} &right) Q_DECL_NOTHROW
QDataStream &operator<<(QDataStream &stream, const {{class}} &obj)
{
+ //FIX me for inheritance
{% for field in struct.fields %}
stream << obj.{{field}}();
{% endfor %}
@@ -118,8 +167,9 @@ QDataStream &operator<<(QDataStream &stream, const {{class}} &obj)
QDataStream &operator>>(QDataStream &stream, {{class}} &obj)
{
+ //FIX me for inheritance
{% for field in struct.fields %}
- stream >> obj.m_{{field}};
+ stream >> obj.d->m_{{field}};
{% endfor %}
return stream;
}
diff --git a/src/tools/ivigenerator/templates_frontend/struct.h.tpl b/src/tools/ivigenerator/templates_frontend/struct.h.tpl
index 5eda736..737bcf0 100644
--- a/src/tools/ivigenerator/templates_frontend/struct.h.tpl
+++ b/src/tools/ivigenerator/templates_frontend/struct.h.tpl
@@ -57,10 +57,13 @@
#include <QObject>
#include <QDataStream>
#include <QDebug>
+#include <QIviStandardItem>
QT_BEGIN_NAMESPACE
-class {{exportsymbol}} {{class}}
+class {{class}}Private;
+
+class {{exportsymbol}} {{class}} : public QIviStandardItem
{
Q_GADGET
{% for field in struct.fields %}
@@ -69,9 +72,13 @@ class {{exportsymbol}} {{class}}
Q_CLASSINFO("IviPropertyDomains", "{{ struct.fields|json_domain|replace("\"", "\\\"") }}")
public:
{{class}}();
+ {{class}}(const {{class}} &rhs);
+ {{class}} &operator=(const {{class}} &);
{{class}}({% for field in struct.fields %}{% if not loop.first %}, {% endif %}{{field|return_type}} {{field}}{% endfor %});
~{{class}}();
+ QString type() const override;
+
{% for field in struct.fields %}
{{ivi.prop_getter(field)}};
{% if not field.readonly and not field.const %}
@@ -79,14 +86,12 @@ public:
{% endif %}
{% endfor %}
-
private:
-{% for field in struct.fields %}
- {{field|return_type}} m_{{field}};
-{% endfor %}
-
+ QSharedDataPointer<{{class}}Private> d;
+ friend {{exportsymbol}} bool operator==(const {{class}} &left, const {{class}} &right) Q_DECL_NOTHROW;
friend {{exportsymbol}} QDataStream &operator>>(QDataStream &stream, {{class}} &obj);
};
+Q_DECLARE_TYPEINFO({{class}}, Q_MOVABLE_TYPE);
{{exportsymbol}} bool operator==(const {{class}} &left, const {{class}} &right) Q_DECL_NOTHROW;
{{exportsymbol}} bool operator!=(const {{class}} &left, const {{class}} &right) Q_DECL_NOTHROW;