aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmltyperegistrar/qqmltypescreator_p.h
blob: 10c5a3d35d542c917194ea82333ef648920efb2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#ifndef QMLTYPESCREATOR_P_H
#define QMLTYPESCREATOR_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include "qqmltypesclassdescription_p.h"
#include "qqmljsstreamwriter_p.h"

#include <QtCore/qstring.h>
#include <QtCore/qset.h>

QT_BEGIN_NAMESPACE

class QmlTypesCreator
{
public:
    QmlTypesCreator() : m_qml(&m_output) {}

    bool generate(const QString &outFileName);

    void setOwnTypes(QVector<MetaType> ownTypes) { m_ownTypes = std::move(ownTypes); }
    void setForeignTypes(QVector<MetaType> foreignTypes) { m_foreignTypes = std::move(foreignTypes); }
    void setReferencedTypes(QList<QAnyStringView> referencedTypes) { m_referencedTypes = std::move(referencedTypes); }
    void setModule(QByteArray module) { m_module = std::move(module); }
    void setVersion(QTypeRevision version) { m_version = version; }

private:
    void writeComponent(const QmlTypesClassDescription &collector);
    void writeClassProperties(const QmlTypesClassDescription &collector);
    void writeType(QAnyStringView type);
    void writeProperties(const Property::Container &properties);
    void writeMethods(const Method::Container &methods, QLatin1StringView type);

    enum class EnumClassesMode { Scoped, Unscoped };
    void writeEnums(const Enum::Container &enums, EnumClassesMode enumClassesMode);

    void writeComponents();
    void writeRootMethods(const MetaType &classDef);

    QByteArray m_output;
    QQmlJSStreamWriter m_qml;
    QVector<MetaType> m_ownTypes;
    QVector<MetaType> m_foreignTypes;
    QList<QAnyStringView> m_referencedTypes;
    QByteArray m_module;
    QTypeRevision m_version = QTypeRevision::zero();
};

QT_END_NAMESPACE

#endif // QMLTYPESCREATOR_P_H