{#
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_name }}.h>

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

namespace Union
{
namespace Quick
{

class QuickStyle;

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

public:
    explicit {{ type_name }}Group(QuickStyle *style);

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

    void refreshColors();

{% for property in properties %}
{% if property.is_group %}
    /*!
     * \qmlproperty {{ property.type }}Group {{ type_name }}Group::{{ property.name }}
     *
     * Exposes {{ type_name }}::{{ property.type }} to QML.
     */
    Q_PROPERTY(Union::Quick::{{ property.type}}Group *{{ property.name }} READ {{ property.name }} CONSTANT)
    {{ property.type }}Group *{{ 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 }} {{ type_name }}Group::{{ property.name }}
     *
     * Exposes {{ type_name }}::{{ 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 properties %}
{% if property.is_group %}
    std::unique_ptr<{{ property.type }}Group> m_{{ property.name }};
{% endif %}
{% endfor %}

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

}
}
