{#
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
SPDX-FileCopyrightText: 2024 Arjen Hiemstra <ahiemstra@heimr.nl>

This is the template that is used to generate headers for QML grouped properties.

REUSE-IgnoreStart
#}
// SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
// SPDX-FileCopyrightText: 2024 Arjen Hiemstra <ahiemstra@heimr.nl>
//
// This file is automatically generated from qml_group.h.j2.
// To regenerate, run `tools/propertygenerator/generate_properties.py`.
{# REUSE-IgnoreEnd #}

#pragma once

{#
The include list may contain extra newlines that are hard to get rid of with the
template but that clang format doesn't like, so disable format for that.
#}
// clang-format off
#include <QJSValue>
#include <QObject>
#include <QProperty>
#include <qqmlregistration.h>

{% for include in system_includes | sort %}
#include <{{ include }}>
{% endfor %}

#include <properties/{{ type }}.h>

{% for property in children %}
{% if property.children %}
#include "{{ property.type }}Quick.h"
{% endif %}
{% endfor %}
// clang-format on

namespace Union
{
namespace Quick
{

class QuickStyle;

{%- set group_name = type + "Quick" %}

/*!
 * \qmltype {{ group_name }}
 * \inqmlmodule org.kde.union.impl
 * \ingroup qtquick-properties
 *
 * \brief A group object exposing the properties of {{ type }} to QML.
 */
class {{ group_name }} : public QObject
{
    Q_OBJECT
    QML_ANONYMOUS

public:
    explicit {{ group_name }}(QuickStyle *style);

    void update(Union::Properties::{{ type }} *newState);
    Q_SIGNAL void updated();

    void refreshColors();

{% for property in children %}
{% if property.children %}
    /*!
     * \qmlproperty {{ property.type }}Quick {{ group_name }}::{{ property.name }}
     *
     * Exposes {{ type }}::{{ property.type }} to QML.
     */
    Q_PROPERTY(Union::Quick::{{ property.type}}Quick *{{ property.name }} READ {{ property.name }} CONSTANT)
    {{ property.type }}Quick *{{ property.name }}() const;
{% else %}
{#
    We use QJSValue here to be able to communicate the "undefined" state to the
    QML engine. This ensures that if a property is not provided by the style, we
    also don't provide a property to QML and instead allow its default handling
    to take over.
#}
    /*!
     * \qmlproperty {{ property.type }} {{ group_name }}::{{ property.name }}
     *
     * Exposes {{ type }}::{{ property.name }} to QML.
     */
    Q_PROPERTY(QJSValue {{ property.name }} READ {{ property.name }} NOTIFY {{ property.name }}Changed)
    QJSValue {{ property.name }}() const;
    Q_SIGNAL void {{ property.name }}Changed();
{% endif %}

{% endfor %}
{% if extra_code and "public" in extra_code %}
{{ extra_code["public"] | render }}

{% endif %}
private:
    QuickStyle *m_style = nullptr;
{% for property in children %}
{% if property.children %}
    std::unique_ptr<{{ property.type }}Quick> m_{{ property.name }};
{% endif %}
{% endfor %}

    Union::Properties::{{ type }} *m_state = nullptr;
{% if extra_code and "private" in extra_code %}
{{ extra_code["private"] | render }}
{% endif %}
};

}
}
