{%+ 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(property, notifiable=True) -%}
Q_PROPERTY({{property|returnType}} {{property}} READ {{property}} {% if not property.readonly %}WRITE set{{property|upperfirst}}{% endif %}{% if not property.const and notifiable %} NOTIFY {{property}}Changed{% endif %})
{%- endmacro %}

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

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

{% macro signal_decl(symbol, postfix="") -%}
void {{symbol}}{{postfix}}({{symbol|parameters}});
{%- endmacro %}

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

{% macro property_setter_impl(class, property, notifiable=True) -%}
/*!
   \qmlproperty {{property.type}} {{class}}::{{property}}
{% with doc = property.comment|parse_doc %}
   \brief {{doc.brief}}

   {{doc.description}}
{% endwith %}
*/

void {{class}}::set{{property|upperfirst}}({{ property|parameterType }})
{
{% if notifiable %}
    if (m_{{property}} != {{property}}) {
        m_{{property}} = {{property}};
        Q_EMIT {{property}}Changed({{property}});
    }
{% else %}
    m_{{property}} = {{property}};
{% endif %}

}
{%- endmacro %}


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


{% macro operation_impl(class, operation) -%}
/*!
   \qmlmethod {{operation.type}} {{class}}::{{operation}}({{operation|parameters}})
{% with doc = operation.comment|parse_doc %}
   \brief {{doc.brief}}
   {{doc.description}}
{% endwith %}
*/
{{operation|returnType}} {{class}}::{{operation}}({{operation|parameters}})
{
    {% for parameter in operation.parameters %}
    Q_UNUSED({{parameter.name}});
    {% endfor %}
    qWarning() << "{{class}}::{{operation}}(...) not implemented";
    return {{operation|defaultValue}};
}
{%- endmacro %}

{% macro operation_decl(operation, ending=";") -%}
    virtual {{operation|returnType}} {{operation}}({{operation|parameters}}){{ending}}
{%- 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 %}

