diff options
-rw-r--r-- | src/tools/ivigenerator/templates_frontend/struct.cpp.tpl | 68 | ||||
-rw-r--r-- | src/tools/ivigenerator/templates_frontend/struct.h.tpl | 17 |
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; |