aboutsummaryrefslogtreecommitdiffstats
path: root/qface/builtin/qtcpp/templates/module.cpp
blob: af2d2f1b2c1fdb5bdfe88c5d0960fc126e8722ba (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{# Copyright (c) Pelagicore AB 2016 #}
/****************************************************************************
** This is an auto-generated file.
** Do not edit! All changes made to it will be lost.
****************************************************************************/
{% set class = 'Qml{0}Module'.format(module.module_name) %}


#include "{{class|lower}}.h"

#include <QtQml>

/*!
   \qmlmodule {{module}} 1.0
{% with doc = module.comment|parse_doc %}

   {{doc.brief}}


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


/*!
   \qmltype {{module.module_name}}Module
   \inqmlmodule {{module}}
   \brief API to access module functionality

   Provides the enumerations and data type factories for
   this module.
*/
QObject* {{class|lower}}_singletontype_provider(QQmlEngine*, QJSEngine*)
{
    return new {{class}}();
}

{{class}}::{{class}}(QObject *parent)
    : QObject(parent)
{
}

{% for struct in module.structs %}
/*!
   \qmlmethod {{struct}} {{module.module_name}}Module::create{{struct}}()
   \brief Creates a default constructed data object from type {{struct}}
*/
Qml{{struct}} {{class}}::create{{struct}}()
{
    return Qml{{struct}}();
}
{% endfor %}

void {{class}}::registerTypes()
{
    {% for struct in module.structs %}
    qRegisterMetaType<Qml{{struct}}>();
    {% endfor %}
    {% for enum in module.enums %}
    qRegisterMetaType<{{class}}::{{enum}}>();
    {% endfor %}
}

void {{class}}::registerQmlTypes(const QString& uri, int majorVersion, int minorVersion)
{
    {% for struct in module.structs %}
    qmlRegisterUncreatableType<Qml{{struct}}Model>(uri.toLatin1(), majorVersion, minorVersion, "{{struct}}Model", "Model can not be instantiated from QML");
    {% endfor %}
    qmlRegisterSingletonType<{{class}}>(uri.toLatin1(), majorVersion, minorVersion, "{{module.module_name}}Module", {{class|lower}}_singletontype_provider);
}


{% for enum in module.enums %}
/**
 * \qmlproperty enumeration {{module.module_name}}Module::{{enum}}
 * \list
 {% for member in enum.members %}
 * \li {{member}}
 {% endfor %}
 * \endlist
 */
{% endfor %}