aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbuiltin/qtcpp/qtcpp.py2
-rw-r--r--builtin/qtcpp/templates/generated.pri4
-rw-r--r--builtin/qtcpp/templates/module.h5
-rw-r--r--builtin/qtcpp/templates/variantmodel.cpp102
-rw-r--r--builtin/qtcpp/templates/variantmodel.h38
-rwxr-xr-xcli.py2
-rw-r--r--qface/helper/qtcpp.py27
7 files changed, 162 insertions, 18 deletions
diff --git a/builtin/qtcpp/qtcpp.py b/builtin/qtcpp/qtcpp.py
index 406fd03..56882a7 100755
--- a/builtin/qtcpp/qtcpp.py
+++ b/builtin/qtcpp/qtcpp.py
@@ -52,6 +52,8 @@ def run(src, dst):
generator.write('generated/qml{{struct|lower}}.cpp', 'struct.cpp', ctx)
generator.write('generated/qml{{struct|lower}}model.h', 'structmodel.h', ctx)
generator.write('generated/qml{{struct|lower}}model.cpp', 'structmodel.cpp', ctx)
+ generator.write('generated/qmlvariantmodel.h', 'variantmodel.h', ctx)
+ generator.write('generated/qmlvariantmodel.cpp', 'variantmodel.cpp', ctx)
@click.command()
diff --git a/builtin/qtcpp/templates/generated.pri b/builtin/qtcpp/templates/generated.pri
index 31f9aac..4baac95 100644
--- a/builtin/qtcpp/templates/generated.pri
+++ b/builtin/qtcpp/templates/generated.pri
@@ -12,17 +12,19 @@ HEADERS += \
{% for interface in module.interfaces %}
$$PWD/qmlabstract{{interface|lower}}.h \
{% endfor %}
+ $$PWD/qmlvariantmodel.h \
{% for struct in module.structs %}
$$PWD/qml{{struct|lower}}.h \
$$PWD/qml{{struct|lower}}model.h {% if not loop.last %}\{% endif %}
{% endfor %}
-
+
SOURCES += \
$$PWD/qml{{module.module_name|lower}}module.cpp \
{% for interface in module.interfaces %}
$$PWD/qmlabstract{{interface|lower}}.cpp \
{% endfor %}
+ $$PWD/qmlvariantmodel.cpp \
{% for struct in module.structs %}
$$PWD/qml{{struct|lower}}.cpp \
$$PWD/qml{{struct|lower}}model.cpp {% if not loop.last %}\{% endif %}
diff --git a/builtin/qtcpp/templates/module.h b/builtin/qtcpp/templates/module.h
index 65ba2db..39b5026 100644
--- a/builtin/qtcpp/templates/module.h
+++ b/builtin/qtcpp/templates/module.h
@@ -9,6 +9,7 @@
#include <QtCore>
+#include "qmlvariantmodel.h"
{% for struct in module.structs %}
#include "qml{{struct|lower}}.h"
#include "qml{{struct|lower}}model.h"
@@ -21,12 +22,12 @@ public:
{% for enum in module.enums %}
{% set comma = joiner(",") %}
- enum {{enum}} {
+ enum {{enum}} {
{%- for member in enum.members -%}
{{ comma() }}
{{member.name}} = {{member.value}}
{%- endfor %}
-
+
};
Q_ENUM({{enum}})
{% endfor %}
diff --git a/builtin/qtcpp/templates/variantmodel.cpp b/builtin/qtcpp/templates/variantmodel.cpp
new file mode 100644
index 0000000..6e197f4
--- /dev/null
+++ b/builtin/qtcpp/templates/variantmodel.cpp
@@ -0,0 +1,102 @@
+{# Copyright (c) Pelagicore AB 2016 #}
+{% set class = 'QmlVariantModel' %}
+/****************************************************************************
+** This is an auto-generated file.
+** Do not edit! All changes made to it will be lost.
+****************************************************************************/
+
+#include "{{class|lower}}.h"
+
+{{class}}::{{class}}(QObject *parent)
+ : QAbstractListModel(parent)
+{
+ m_roleNames.insert(Roles::ModelData, QByteArray("modelData"));
+}
+
+int {{class}}::count() const
+{
+ return m_data.count();
+}
+
+QVariant {{class}}::get(int index)
+{
+ return m_data.value(index);
+}
+
+int {{class}}::rowCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent)
+ return m_data.count();
+}
+
+QVariant {{class}}::data(const QModelIndex &index, int role) const
+{
+ if(index.row() < 0 || index.row() >= count()) {
+ return QVariant();
+ }
+ const QVariant &entry = m_data.at(index.row());
+ switch(role) {
+ case Roles::ModelData:
+ return entry;
+ }
+ return QVariant();
+}
+
+QHash<int, QByteArray> {{class}}::roleNames() const
+{
+ return m_roleNames;
+}
+
+
+void {{class}}::insert(int row, const QVariant &entry)
+{
+ if (row < 0)
+ row = 0;
+ if (row >= m_data.count())
+ row = m_data.count();
+
+ beginInsertRows(QModelIndex(), row, row);
+ m_data.insert(row, entry);
+ endInsertRows();
+ emit countChanged(count());
+}
+
+void {{class}}::reset(const QVariantList entries)
+{
+ beginResetModel();
+ m_data = entries;
+ endResetModel();
+}
+
+void {{class}}::append(const QVariant &entry)
+{
+ insert(m_data.count(), entry);
+}
+
+void {{class}}::update(int row, const QVariant &entry)
+{
+ if(row < 0 || row >= m_data.count()) {
+ return;
+ }
+ m_data[row] = entry;
+ const QModelIndex &index = createIndex(row, 0);
+ emit dataChanged(index, index);
+}
+
+void {{class}}::remove(int row)
+{
+ if(row < 0 || row >= m_data.count()) {
+ return;
+ }
+ beginRemoveRows(QModelIndex(), row, row);
+ m_data.removeAt(row);
+ endRemoveRows();
+}
+
+void {{class}}::clear()
+{
+ beginResetModel();
+ m_data.clear();
+ endResetModel();
+}
+
diff --git a/builtin/qtcpp/templates/variantmodel.h b/builtin/qtcpp/templates/variantmodel.h
new file mode 100644
index 0000000..67be224
--- /dev/null
+++ b/builtin/qtcpp/templates/variantmodel.h
@@ -0,0 +1,38 @@
+{# Copyright (c) Pelagicore AB 2016 #}
+{% set class = 'QmlVariantModel' %}
+/****************************************************************************
+** This is an auto-generated file.
+** Do not edit! All changes made to it will be lost.
+****************************************************************************/
+
+#pragma once
+
+#include <QtCore>
+
+class {{class}} : public QAbstractListModel
+{
+ Q_OBJECT
+ Q_PROPERTY(int count READ count NOTIFY countChanged)
+public:
+ enum Roles { ModelData = Qt::UserRole };
+ {{class}}(QObject *parent=0);
+ Q_INVOKABLE QVariant get(int index);
+ int count() const;
+ void insert(int row, const QVariant &entry);
+ void append(const QVariant &entry);
+ void update(int row, const QVariant &entry);
+ void remove(int row);
+ void reset(const QVariantList entries);
+ void clear();
+public: // from QAbstractListModel
+ virtual int rowCount(const QModelIndex &parent) const;
+ virtual QVariant data(const QModelIndex &index, int role) const;
+ virtual QHash<int, QByteArray> roleNames() const;
+Q_SIGNALS:
+ void countChanged(int count);
+private:
+ QVariantList m_data;
+ QHash<int, QByteArray> m_roleNames;
+};
+
+
diff --git a/cli.py b/cli.py
index c70ecf3..0c4a9d1 100755
--- a/cli.py
+++ b/cli.py
@@ -92,8 +92,6 @@ class RunScriptChangeHandler(FileSystemEventHandler):
def on_modified(self, event):
if event.src_path.endswith('.cache'):
return
- if event.is_directory:
- return
self.run()
def run(self):
diff --git a/qface/helper/qtcpp.py b/qface/helper/qtcpp.py
index aba3176..aa7235a 100644
--- a/qface/helper/qtcpp.py
+++ b/qface/helper/qtcpp.py
@@ -19,6 +19,7 @@ class Filters(object):
@staticmethod
def defaultValue(symbol):
+ prefix = Filters.classPrefix
t = symbol.type # type: qface.domain.TypeSymbol
if t.is_primitive:
if t.is_int:
@@ -41,21 +42,21 @@ class Filters(object):
nested = Filters.returnType(symbol.type.nested)
return 'QVariantList()'.format(nested)
elif symbol.type.is_struct:
- return 'Qml{0}()'.format(symbol.type)
+ return '{0}{1}()'.format(prefix, symbol.type)
elif symbol.type.is_model:
nested = symbol.type.nested
if nested.is_primitive:
- return 'new QmlVariantModel(this)'
+ return 'new {0}VariantModel(this)'.format(prefix)
elif nested.is_complex:
- return 'new Qml{0}Model(this)'.format(nested)
+ return 'new {0}{1}Model(this)'.format(prefix, nested)
return 'XXX'
@staticmethod
def parameterType(symbol):
- classPrefix = Filters.classPrefix
+ prefix = Filters.classPrefix
module_name = symbol.module.module_name
if symbol.type.is_enum:
- return '{0}{1}Module::{2} {3}'.format(classPrefix, module_name, symbol.type, symbol)
+ return '{0}{1}Module::{2} {3}'.format(prefix, module_name, symbol.type, symbol)
if symbol.type.is_void or symbol.type.is_primitive:
if symbol.type.name == 'string':
return 'const QString &{0}'.format(symbol)
@@ -70,19 +71,19 @@ class Filters(object):
elif symbol.type.is_model:
nested = symbol.type.nested
if nested.is_primitive:
- return 'QmlVariantModel *{0}'.format(symbol)
+ return '{0}VariantModel *{1}'.format(prefix, symbol)
elif nested.is_complex:
- return 'Qml{0}Model *{1}'.format(nested, symbol)
+ return '{0}{1}Model *{2}'.format(prefix, nested, symbol)
else:
- return 'const {0}{1} &{2}'.format(classPrefix, symbol.type, symbol)
+ return 'const {0}{1} &{2}'.format(prefix, symbol.type, symbol)
return 'XXX'
@staticmethod
def returnType(symbol):
- classPrefix = Filters.classPrefix
+ prefix = Filters.classPrefix
module_name = symbol.module.module_name
if symbol.type.is_enum:
- return '{0}{1}Module::{2}'.format(classPrefix, module_name, symbol.type)
+ return '{0}{1}Module::{2}'.format(prefix, module_name, symbol.type)
if symbol.type.is_void or symbol.type.is_primitive:
if symbol.type.name == 'string':
return 'QString'
@@ -97,10 +98,10 @@ class Filters(object):
elif symbol.type.is_model:
nested = symbol.type.nested
if nested.is_primitive:
- return 'QmlVariantModel *'
+ return '{0}VariantModel *'.format(prefix)
elif nested.is_complex:
- return 'Qml{0}Model *'.format(nested)
+ return '{0}{1}Model *'.format(prefix, nested)
else:
- return '{0}{1}'.format(classPrefix, symbol.type)
+ return '{0}{1}'.format(prefix, symbol.type)
return 'XXX'