{%+ macro enum_decl(enum) -%}
    enum {{enum}}Enum {
    {% for member in enum.members %}
        {{member.name}} = {{member.value}}{% if not loop.last %},{%endif%}

    {% endfor %}
    };
    {% if enum.is_flag %}
    Q_DECLARE_FLAGS({{enum}}Enums, {{enum}}Enum)
    Q_FLAG({{enum}}Enum)
    {% else %}
    Q_ENUM({{enum}}Enum)
    {% endif %}
{%- endmacro %}

{% macro property_decl(property, notifiable=True, writeable=True) -%}
Q_PROPERTY({{property|qt.returnType}} {{property}} READ {{property}}{% if property.writeable and writeable%} WRITE set{{property|upperfirst}}{% endif %}{% if not property.const and notifiable %} NOTIFY {{property}}Changed{% endif %})
{%- endmacro %}

{% macro property_pusher_decl(property, ending=";", prefix='') -%}
{{prefix}} void push{{property|upperfirst}}({{ property|qt.parameterType }}){{ending}}
{%- endmacro %}

{% macro property_setter_decl(property, ending=";", prefix='', verb="set") -%}
{{prefix}}void {{verb}}{{property|upperfirst}}({{ property|qt.parameterType }}){{ending}}
{%- endmacro %}

{% macro property_getter_decl(property, ending=";", prefix='') -%}
{{prefix}}{{property|qt.returnType}} {{property}}() const{{ending}}
{%- endmacro %}

{% macro signal_decl(symbol, postfix="", verb="", full=False) -%}
{% if full -%}
void {{symbol}}{{postfix}}({{symbol|qt.parameters}});
{%- else -%}
void {{symbol}}{{postfix}}();
{%- endif %}
{%- endmacro %}

{% macro property_member_decl(property) -%}
{{property|qt.returnType}} m_{{property}};
{%- endmacro %}

{% macro property_pusher_impl(class, property, notifiable=True) -%}
void {{class}}::push{{property|upperfirst}}({{ property|qt.parameterType }})
{
    qDebug() << Q_FUNC_INFO << {{property}};
{% if notifiable %}
    if (m_{{property}} != {{property}}) {
        m_{{property}} = {{property}};
        Q_EMIT {{property}}Changed();
    }
{% else %}
    m_{{property}} = {{property}};
{% endif %}
}
{%- endmacro %}

{% macro property_setter_impl(class, property, notifiable=True, verb="set") -%}
/*!
   \qmlproperty {{property.type}} {{class}}::{{property}}
{% with doc = property.comment|parse_doc %}
   \brief {{doc.brief|join(" ")}}
   {{doc.description|join("\n   ")}}
{% endwith %}
*/
void {{class}}::{{verb}}{{property|upperfirst}}({{ property|qt.parameterType }})
{
    qDebug() << Q_FUNC_INFO << {{property}};
{% if notifiable %}
    if (m_{{property}} != {{property}}) {
        m_{{property}} = {{property}};
        Q_EMIT {{property}}Changed();
    }
{% else %}
    m_{{property}} = {{property}};
{% endif %}
}
{%- endmacro %}


{% macro property_getter_impl(class, property) -%}
{{property|qt.returnType}} {{class}}::{{property}}() const
{
    return m_{{property}};
}
{%- endmacro %}


{% macro operation_impl(class, operation, void=False, doc=True) -%}
{% if doc %}
/*!
   \qmlmethod {{operation.type}} {{class}}::{{operation}}({{operation|qt.parameters}})
{% with doc = operation.comment|parse_doc %}
   \brief {{doc.brief}}
   {{doc.description|join("\n   ")}}
{% endwith %}
*/
{% endif %}
{% if not void -%}{{operation|qt.returnType}}{%- else %}void{% endif %} {{class}}::{{operation}}({{operation|qt.parameters}})
{
    {% for parameter in operation.parameters %}
    Q_UNUSED({{parameter.name}});
    {% endfor %}
    qDebug() << Q_FUNC_INFO << "not implemented";
    {% if not void %}
    return {{operation|qt.defaultValue}};
    {% endif %}
}
{%- endmacro %}

{% macro operation_impl_start(class, operation, void=False, doc=True) -%}
{% if not void -%}{{operation|qt.returnType}}{%- else %}void{% endif %} {{class}}::{{operation}}({{operation|qt.parameters}})
{%- endmacro %}

{% macro operation_decl(operation, ending=";", void=False) -%}
{% if void %}
virtual void {{operation}}({{operation|qt.parameters}}){{ending}}
{%- else %}
virtual {{operation|qt.returnType}} {{operation}}({{operation|qt.parameters}}){{ending}}
{%- endif %}
{%- endmacro %}

{% macro autogenerated(prefix="//") -%}

{{prefix}} This is an auto-generated file.
{{prefix}} Do not edit! All changes made to it will be lost.

{%- endmacro %}

{% macro preserved(prefix="//") -%}
{{prefix}} This is a preserved file.
{{prefix}} Changes will not be overriden by the generator.
{{prefix}} To reset the file you need to delete it first.
{%- endmacro %}

{% macro struct_setter_line(property) -%}
inline void set{{property|upperfirst}}({{ property|qt.parameterType }}) { m_{{property}} = {{property}}; }
{%- endmacro %}


{% macro struct_getter_line(property) -%}
inline {{property|qt.returnType}} {{property}}() const { return m_{{property}}; }
{%- endmacro %}

