summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJuergen Ryannel <juergen.bocklage-ryannel@pelagicore.com>2016-12-05 15:10:04 +0100
committerJuergen Ryannel <juergen.bocklage-ryannel@pelagicore.com>2016-12-05 15:10:04 +0100
commita98033f4cac3247670e2f28cfc7aa3250e64e050 (patch)
tree967151bcc90fc807443e7bb0f67911c0008cedd5 /examples
parent5a90b31c56d7639e3e4bb46e3f196c9efad15812 (diff)
downloadqtivi-qface-a98033f4cac3247670e2f28cfc7aa3250e64e050.tar.gz
WIP: update qtcpp code generator
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/qtcpp/generator/qtcpp.py34
-rw-r--r--examples/qtcpp/generator/templates/interface.cpp14
-rw-r--r--examples/qtcpp/generator/templates/module.cpp10
-rw-r--r--examples/qtcpp/generator/templates/module.h6
-rw-r--r--examples/qtcpp/generator/templates/plugin.cpp4
-rw-r--r--examples/qtcpp/generator/templates/plugin.pri24
-rw-r--r--examples/qtcpp/generator/templates/plugin.pro9
-rw-r--r--examples/qtcpp/generator/templates/project.pri32
-rw-r--r--examples/qtcpp/generator/templates/project.pro33
-rw-r--r--examples/qtcpp/generator/templates/qmldir2
-rw-r--r--examples/qtcpp/generator/templates/struct.cpp5
-rw-r--r--examples/qtcpp/generator/templates/struct.h7
-rw-r--r--examples/qtcpp/generator/templates/structmodel.cpp14
-rw-r--r--examples/qtcpp/generator/templates/structmodel.h15
-rw-r--r--examples/qtcpp/interface/echo.qdl6
15 files changed, 77 insertions, 138 deletions
diff --git a/examples/qtcpp/generator/qtcpp.py b/examples/qtcpp/generator/qtcpp.py
index 479aaa7..081f05a 100755
--- a/examples/qtcpp/generator/qtcpp.py
+++ b/examples/qtcpp/generator/qtcpp.py
@@ -28,7 +28,7 @@ def paramterType(symbol):
elif symbol.type.is_model:
return '{0}Model *{1}'.format(symbol.type.nested, symbol)
else:
- return 'const {0} &{1}'.format(symbol.type, symbol)
+ return 'const Qml{0} &{1}'.format(symbol.type, symbol)
def returnType(symbol):
@@ -48,7 +48,7 @@ def returnType(symbol):
elif symbol.type.is_model:
return '{0}Model*'.format(symbol.type.nested)
else:
- return symbol.type
+ return 'Qml{0}'.format(symbol.type)
def run_generation(input, output):
@@ -59,25 +59,25 @@ def run_generation(input, output):
ctx = {'output': output}
for module in system.modules:
ctx.update({'module': module})
- moduleOutput = generator.apply('{{output}}/{{module|lower}}', ctx)
- ctx.update({'path': moduleOutput})
- generator.write('{{path}}/qmldir', 'qmldir', ctx)
- generator.write('{{path}}/plugin.cpp', 'plugin.cpp', ctx)
- generator.write('{{path}}/plugin.h', 'plugin.h', ctx)
- generator.write('{{path}}/{{module|lower}}.pri', 'project.pri', ctx)
- generator.write('{{path}}/{{module|lower}}.pro', 'project.pro', ctx)
- generator.write('{{path}}/qml{{module.module_name|lower}}module.h', 'module.h', ctx)
- generator.write('{{path}}/qml{{module.module_name|lower}}module.cpp', 'module.cpp', ctx)
+ dst = generator.apply('{{output}}/{{module|lower}}', ctx)
+ ctx.update({'dst': dst})
+ generator.write('{{dst}}/qmldir', 'qmldir', ctx, overwrite=False)
+ generator.write('{{dst}}/plugin.cpp', 'plugin.cpp', ctx, overwrite=False)
+ generator.write('{{dst}}/plugin.h', 'plugin.h', ctx, overwrite=False)
+ generator.write('{{dst}}/{{module|lower}}.pro', 'plugin.pro', ctx, overwrite=False)
+ generator.write('{{dst}}/_generated/{{module|lower}}.pri', 'plugin.pri', ctx)
+ generator.write('{{dst}}/_generated/qml{{module.module_name|lower}}module.h', 'module.h', ctx)
+ generator.write('{{dst}}/_generated/qml{{module.module_name|lower}}module.cpp', 'module.cpp', ctx)
for interface in module.interfaces:
ctx.update({'interface': interface})
- generator.write('{{path}}/qmlabstract{{interface|lower}}.h', 'interface.h', ctx)
- generator.write('{{path}}/qmlabstract{{interface|lower}}.cpp', 'interface.cpp', ctx)
+ generator.write('{{dst}}/_generated/qmlabstract{{interface|lower}}.h', 'interface.h', ctx)
+ generator.write('{{dst}}/_generated/qmlabstract{{interface|lower}}.cpp', 'interface.cpp', ctx)
for struct in module.structs:
ctx.update({'struct': struct})
- generator.write('{{path}}/{{struct|lower}}.h', 'struct.h', ctx)
- generator.write('{{path}}/{{struct|lower}}.cpp', 'struct.cpp', ctx)
- generator.write('{{path}}/{{struct|lower}}model.h', 'structmodel.h', ctx)
- generator.write('{{path}}/{{struct|lower}}model.cpp', 'structmodel.cpp', ctx)
+ generator.write('{{dst}}/_generated/qml{{struct|lower}}.h', 'struct.h', ctx)
+ generator.write('{{dst}}/_generated/qml{{struct|lower}}.cpp', 'struct.cpp', ctx)
+ generator.write('{{dst}}/_generated/qml{{struct|lower}}model.h', 'structmodel.h', ctx)
+ generator.write('{{dst}}/_generated/qml{{struct|lower}}model.cpp', 'structmodel.cpp', ctx)
@click.command()
diff --git a/examples/qtcpp/generator/templates/interface.cpp b/examples/qtcpp/generator/templates/interface.cpp
index 24a15e3..089905f 100644
--- a/examples/qtcpp/generator/templates/interface.cpp
+++ b/examples/qtcpp/generator/templates/interface.cpp
@@ -5,18 +5,10 @@
** Do not edit! All changes made to it will be lost.
****************************************************************************/
-#include <{{interface|lower}}.h>
+#include "{{class|lower}}.h"
#include <QtQml>
-{% set class = 'Qml{0}'.format(interface) %}
-
-QObject* {{interface|lower}}_singletontype_provider(QQmlEngine*, QJSEngine*)
-{
- return new {{class}}();
-}
-
-
{{interface.comment}}
{{class}}::{{class}}(QObject *parent)
: QObject(parent)
@@ -30,7 +22,7 @@ QObject* {{interface|lower}}_singletontype_provider(QQmlEngine*, QJSEngine*)
void {{class}}::registerQmlTypes(const QString& uri, int majorVersion, int minorVersion)
{
- qmlRegisterSingletonType<{{class}}>(uri.toLatin1(), majorVersion, minorVersion, "{{interface}}", {{interface|lower}}_singletontype_provider);
+ qmlRegisterType<{{class}}>(uri.toLatin1(), majorVersion, minorVersion, "{{interface}}");
}
{% for property in interface.properties %}
@@ -54,6 +46,6 @@ void {{class}}::set{{property|upperfirst}}({{ property|parameterType }})
{{operation.comment}}
{{operation|returnType}} {{class}}::{{operation}}({{operation.parameters|map('parameterType')|join(', ')}})
{
- qWarn() << "Not implemented: {{class}}::{{operation}}(...)";
+ qWarning() << "Not implemented: {{class}}::{{operation}}(...)";
}
{% endfor %}
diff --git a/examples/qtcpp/generator/templates/module.cpp b/examples/qtcpp/generator/templates/module.cpp
index 8a24b96..ca0f8c6 100644
--- a/examples/qtcpp/generator/templates/module.cpp
+++ b/examples/qtcpp/generator/templates/module.cpp
@@ -6,7 +6,7 @@
{% set class = 'Qml{0}Module'.format(module.module_name) %}
-#include "qml{{ module|lower }}.h"
+#include "{{class|lower}}.h"
#include <QtQml>
@@ -21,23 +21,23 @@ QObject* {{class|lower}}_singletontype_provider(QQmlEngine*, QJSEngine*)
}
{% for struct in module.structs %}
-{{struct}} {{class}}::create{{struct}}()
+Qml{{struct}} {{class}}::create{{struct}}()
{
- return {{struct}}();
+ return Qml{{struct}}();
}
{% endfor %}
void {{class}}::registerTypes()
{
{% for struct in module.structs %}
- qRegisterMetaType<{{struct}}>();
+ qRegisterMetaType<Qml{{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");
+ 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}}", {{class|lower}}_singletontype_provider);
}
diff --git a/examples/qtcpp/generator/templates/module.h b/examples/qtcpp/generator/templates/module.h
index 535823e..f6bb772 100644
--- a/examples/qtcpp/generator/templates/module.h
+++ b/examples/qtcpp/generator/templates/module.h
@@ -10,8 +10,8 @@
#include <QtCore>
{% for struct in module.structs %}
-#include "{{struct|lower}}.h"
-#include "{{struct|lower}}model.h"
+#include "qml{{struct|lower}}.h"
+#include "qml{{struct|lower}}model.h"
{% endfor %}
class {{class}} : public QObject {
@@ -31,7 +31,7 @@ public:
{% endfor %}
{% for struct in module.structs %}
- Q_INVOKABLE {{struct}} create{{struct}}();
+ Q_INVOKABLE Qml{{struct}} create{{struct}}();
{% endfor %}
static void registerTypes();
diff --git a/examples/qtcpp/generator/templates/plugin.cpp b/examples/qtcpp/generator/templates/plugin.cpp
index 7e5521e..4d222a3 100644
--- a/examples/qtcpp/generator/templates/plugin.cpp
+++ b/examples/qtcpp/generator/templates/plugin.cpp
@@ -12,7 +12,7 @@
#include "{{module_name|lower}}.h"
{% for interface in module.interfaces %}
-#include "{{interface|lower}}.h"
+#include "qmlabstract{{interface|lower}}.h"
{% endfor %}
void Plugin::registerTypes(const char *uri)
@@ -21,6 +21,6 @@ void Plugin::registerTypes(const char *uri)
// @uri {{module|lower}}
{{module_name}}::registerQmlTypes(uri, 1, 0);
{% for interface in module.interfaces %}
- Qml{{interface}}::registerQmlTypes(uri, 1, 0);
+ QmlAbstract{{interface}}::registerQmlTypes(uri, 1, 0);
{% endfor %}
}
diff --git a/examples/qtcpp/generator/templates/plugin.pri b/examples/qtcpp/generator/templates/plugin.pri
index bafed08..31f9aac 100644
--- a/examples/qtcpp/generator/templates/plugin.pri
+++ b/examples/qtcpp/generator/templates/plugin.pri
@@ -1,6 +1,4 @@
{# Copyright (c) Pelagicore AB 2016 #}
-{% from 'helper.tpl' import qualifiedModuleName %}
-{% set moduleName = qualifiedModuleName(module) %}
#############################################################################
## This is an auto-generated file.
## Do not edit! All changes made to it will be lost.
@@ -9,25 +7,25 @@
QT += qml quick
CONFIG += c++11
-
HEADERS += \
- qml{{moduleName|lower}}.h \
+ $$PWD/qml{{module.module_name|lower}}module.h \
{% for interface in module.interfaces %}
- abstract{{interface|lower}}.h \
+ $$PWD/qmlabstract{{interface|lower}}.h \
{% endfor %}
{% for struct in module.structs %}
- {{struct|lower}}.h \
- {{struct|lower}}model.h \
+ $$PWD/qml{{struct|lower}}.h \
+ $$PWD/qml{{struct|lower}}model.h {% if not loop.last %}\{% endif %}
{% endfor %}
- plugin.h
+
SOURCES += \
- qml{{moduleName|lower}}.cpp \
+ $$PWD/qml{{module.module_name|lower}}module.cpp \
{% for interface in module.interfaces %}
- abstract{{interface|lower}}.cpp \
+ $$PWD/qmlabstract{{interface|lower}}.cpp \
{% endfor %}
{% for struct in module.structs %}
- {{struct|lower}}.cpp \
- {{struct|lower}}model.cpp \
+ $$PWD/qml{{struct|lower}}.cpp \
+ $$PWD/qml{{struct|lower}}model.cpp {% if not loop.last %}\{% endif %}
{% endfor %}
- plugin.cpp
+
+
diff --git a/examples/qtcpp/generator/templates/plugin.pro b/examples/qtcpp/generator/templates/plugin.pro
index 045895a..70e1a4f 100644
--- a/examples/qtcpp/generator/templates/plugin.pro
+++ b/examples/qtcpp/generator/templates/plugin.pro
@@ -11,8 +11,15 @@ TARGET = $$qtLibraryTarget({{module|lower}})
uri = {{module}}
-include( {{module|lower}}.pri )
+HEADERS += \
+ plugin.h
+
+
+SOURCES += \
+ plugin.cpp
+
+include( _generated/{{module|lower}}.pri )
DISTFILES = qmldir
diff --git a/examples/qtcpp/generator/templates/project.pri b/examples/qtcpp/generator/templates/project.pri
deleted file mode 100644
index 8527970..0000000
--- a/examples/qtcpp/generator/templates/project.pri
+++ /dev/null
@@ -1,32 +0,0 @@
-{# Copyright (c) Pelagicore AB 2016 #}
-{% set module_name = 'Qml{0}Module'.format(module.module_name) %}
-#############################################################################
-## This is an auto-generated file.
-## Do not edit! All changes made to it will be lost.
-#############################################################################
-
-QT += qml quick
-CONFIG += c++11
-
-
-HEADERS += \
- {{module_name|lower}}.h \
-{% for interface in module.interfaces %}
- {{interface|lower}}.h \
-{% endfor %}
-{% for struct in module.structs %}
- {{struct|lower}}.h \
- {{struct|lower}}model.h \
-{% endfor %}
- plugin.h
-
-SOURCES += \
- {{module_name|lower}}.cpp \
-{% for interface in module.interfaces %}
- {{interface|lower}}.cpp \
-{% endfor %}
-{% for struct in module.structs %}
- {{struct|lower}}.cpp \
- {{struct|lower}}model.cpp \
-{% endfor %}
- plugin.cpp
diff --git a/examples/qtcpp/generator/templates/project.pro b/examples/qtcpp/generator/templates/project.pro
deleted file mode 100644
index 045895a..0000000
--- a/examples/qtcpp/generator/templates/project.pro
+++ /dev/null
@@ -1,33 +0,0 @@
-{# Copyright (c) Pelagicore AB 2016 #}
-#############################################################################
-## This is an auto-generated file.
-## Do not edit! All changes made to it will be lost.
-#############################################################################
-
-TEMPLATE = lib
-QT += qml quick
-CONFIG += qt plugin c++11
-TARGET = $$qtLibraryTarget({{module|lower}})
-
-uri = {{module}}
-
-include( {{module|lower}}.pri )
-
-
-DISTFILES = qmldir
-
-!equals(_PRO_FILE_PWD_, $$OUT_PWD) {
- copy_qmldir.target = $$OUT_PWD/qmldir
- copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir
- copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\"
- QMAKE_EXTRA_TARGETS += copy_qmldir
- PRE_TARGETDEPS += $$copy_qmldir.target
-}
-
-qmldir.files = qmldir
-unix {
- installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /)
- qmldir.path = $$installPath
- target.path = $$installPath
- INSTALLS += target qmldir
-}
diff --git a/examples/qtcpp/generator/templates/qmldir b/examples/qtcpp/generator/templates/qmldir
index 8139dbd..9fe5d2b 100644
--- a/examples/qtcpp/generator/templates/qmldir
+++ b/examples/qtcpp/generator/templates/qmldir
@@ -1,3 +1,3 @@
{# Copyright (c) Pelagicore AB 2016 #}
module {{module}}
-plugin {{module}}
+plugin {{module}} \ No newline at end of file
diff --git a/examples/qtcpp/generator/templates/struct.cpp b/examples/qtcpp/generator/templates/struct.cpp
index 94b6ae7..5b132ec 100644
--- a/examples/qtcpp/generator/templates/struct.cpp
+++ b/examples/qtcpp/generator/templates/struct.cpp
@@ -1,16 +1,17 @@
{# Copyright (c) Pelagicore AB 2016 #}
+{% set class = 'Qml{0}'.format(struct) %}
{% set ampersand = joiner(" &&") %}
/****************************************************************************
** This is an auto-generated file.
** Do not edit! All changes made to it will be lost.
****************************************************************************/
-#include <{{struct|lower}}.h>
+#include "{{class|lower}}.h"
{{struct.comment}}
-bool {{struct}}::operator==(const {{struct}} &other) const
+bool {{class}}::operator==(const {{class}} &other) const
{
return (
{%- for field in struct.fields %}{{ ampersand() }}
diff --git a/examples/qtcpp/generator/templates/struct.h b/examples/qtcpp/generator/templates/struct.h
index 9517512..2e0d6d1 100644
--- a/examples/qtcpp/generator/templates/struct.h
+++ b/examples/qtcpp/generator/templates/struct.h
@@ -1,4 +1,5 @@
{# Copyright (c) Pelagicore AB 2016 #}
+{% set class = 'Qml{0}'.format(struct) %}
/****************************************************************************
** This is an auto-generated file.
** Do not edit! All changes made to it will be lost.
@@ -8,7 +9,7 @@
#include <QtCore>
-class {{struct}}
+class {{class}}
{
Q_GADGET
{% for field in struct.fields %}
@@ -20,9 +21,9 @@ public:
{{field|returnType}} m_{{field}};
{% endfor %}
- bool operator==(const {{struct}} &other) const;
+ bool operator==(const {{class}} &other) const;
};
-Q_DECLARE_METATYPE({{struct}})
+Q_DECLARE_METATYPE({{class}})
diff --git a/examples/qtcpp/generator/templates/structmodel.cpp b/examples/qtcpp/generator/templates/structmodel.cpp
index d03630c..12104b9 100644
--- a/examples/qtcpp/generator/templates/structmodel.cpp
+++ b/examples/qtcpp/generator/templates/structmodel.cpp
@@ -1,11 +1,11 @@
{# Copyright (c) Pelagicore AB 2016 #}
-{% set class = '{0}Model'.format(struct) %}
+{% set class = 'Qml{0}Model'.format(struct) %}
/****************************************************************************
** This is an auto-generated file.
** Do not edit! All changes made to it will be lost.
****************************************************************************/
-#include <{{class|lower}}.h>
+#include "{{class|lower}}.h"
{{class}}::{{class}}(QObject *parent)
: QAbstractListModel(parent)
@@ -20,7 +20,7 @@ int {{class}}::count() const
return m_data.count();
}
-Contact {{class}}::get(int index)
+Qml{{struct}} {{class}}::get(int index)
{
return m_data.value(index);
}
@@ -36,11 +36,11 @@ QVariant {{class}}::data(const QModelIndex &index, int role) const
if(index.row() < 0 || index.row() >= count()) {
return QVariant();
}
- const {{struct}} &{{struct|lower}} = m_data.at(index.row());
+ const Qml{{struct}} &{{struct|lower}} = m_data.at(index.row());
switch(role) {
{% for field in struct.fields %}
case Roles::{{field|upperfirst}}:
- return QVariant::fromValue(contact.m_{{field}});
+ return QVariant::fromValue({{struct|lower}}.m_{{field}});
break;
{% endfor %}
}
@@ -53,7 +53,7 @@ QHash<int, QByteArray> {{class}}::roleNames() const
}
-void {{class}}::insert{{struct}}(int row, const {{struct}} &{{struct|lower}})
+void {{class}}::insert{{struct}}(int row, const Qml{{struct}} &{{struct|lower}})
{
if (row < 0)
row = 0;
@@ -66,7 +66,7 @@ void {{class}}::insert{{struct}}(int row, const {{struct}} &{{struct|lower}})
emit countChanged(count());
}
-void {{class}}::update{{struct}}(int row, const {{struct}} &{{struct|lower}})
+void {{class}}::update{{struct}}(int row, const Qml{{struct}} &{{struct|lower}})
{
if(row < 0 || row >= m_data.count()) {
return;
diff --git a/examples/qtcpp/generator/templates/structmodel.h b/examples/qtcpp/generator/templates/structmodel.h
index ba78e5e..85ed16b 100644
--- a/examples/qtcpp/generator/templates/structmodel.h
+++ b/examples/qtcpp/generator/templates/structmodel.h
@@ -1,4 +1,5 @@
{# Copyright (c) Pelagicore AB 2016 #}
+{% set class = 'Qml{0}Model'.format(struct) %}
/****************************************************************************
** This is an auto-generated file.
** Do not edit! All changes made to it will be lost.
@@ -8,19 +9,19 @@
#include <QtCore>
-#include "{{struct|lower}}.h"
+#include "qml{{struct|lower}}.h"
-class {{struct}}Model : public QAbstractListModel
+class {{class}} : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int count READ count NOTIFY countChanged)
public:
enum Roles { {{struct.fields|map('upperfirst')|join(', ')}} };
- {{struct}}Model(QObject *parent=0);
- Q_INVOKABLE {{struct}} get(int index);
+ {{class}}(QObject *parent=0);
+ Q_INVOKABLE Qml{{struct}} get(int index);
int count() const;
- Q_INVOKABLE void insert{{struct}}(int row, const {{struct}} &{{struct|lower}});
- Q_INVOKABLE void update{{struct}}(int row, const {{struct}} &{{struct|lower}});
+ Q_INVOKABLE void insert{{struct}}(int row, const Qml{{struct}} &{{struct|lower}});
+ Q_INVOKABLE void update{{struct}}(int row, const Qml{{struct}} &{{struct|lower}});
Q_INVOKABLE void remove{{struct}}(int row);
public: // from QAbstractListModel
virtual int rowCount(const QModelIndex &parent) const;
@@ -29,7 +30,7 @@ public: // from QAbstractListModel
Q_SIGNALS:
void countChanged(int count);
private:
- QList<{{struct}}> m_data;
+ QList<Qml{{struct}}> m_data;
QHash<int, QByteArray> m_roleNames;
};
diff --git a/examples/qtcpp/interface/echo.qdl b/examples/qtcpp/interface/echo.qdl
index d308285..bbde9d6 100644
--- a/examples/qtcpp/interface/echo.qdl
+++ b/examples/qtcpp/interface/echo.qdl
@@ -11,5 +11,9 @@ interface Echo {
/*!
* Returns the passed in message
*/
- string echo(string message);
+ void echo(Message message);
+}
+
+struct Message {
+ string text;
}