summaryrefslogtreecommitdiff
path: root/generator/qtcpp/templates/module.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'generator/qtcpp/templates/module.cpp')
-rw-r--r--generator/qtcpp/templates/module.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/generator/qtcpp/templates/module.cpp b/generator/qtcpp/templates/module.cpp
new file mode 100644
index 0000000..b3d8d19
--- /dev/null
+++ b/generator/qtcpp/templates/module.cpp
@@ -0,0 +1,43 @@
+{# 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 "qml{{ module|lower }}.h"
+
+#include <QtQml>
+
+QObject* {{class|lower}}_singletontype_provider(QQmlEngine*, QJSEngine*)
+{
+ return new {{class}}();
+}
+
+{{class}}::{{class}}(QObject *parent)
+ : QObject(parent)
+{
+}
+
+{% for struct in module.structs %}
+{{struct}} {{class}}::create{{struct}}()
+{
+ return {{struct}}();
+}
+{% endfor %}
+
+void {{class}}::registerTypes()
+{
+ {% for struct in module.structs %}
+ qRegisterMetaType<{{struct}}>();
+ {% endfor %}
+}
+
+void {{class}}::registerQmlTypes(const QString& uri, int majorVersion, int minorVersion)
+{
+ {% for struct in module.structs %}
+ qmlRegisterUncreatableType<{{struct}}Model>(uri.toLatin1(), majorVersion, minorVersion, "{{struct}}Model", "Model can not be instantiated from QML");
+ {% endfor %}
+ qmlRegisterSingletonType<{{class}}>(uri.toLatin1(), majorVersion, minorVersion, "{{module}}", {{class|lower}}_singletontype_provider);
+}