diff options
author | Juergen Bocklage-Ryannel <juergen.bocklage-ryannel@pelagicore.com> | 2017-01-10 21:46:57 +0100 |
---|---|---|
committer | Juergen Bocklage-Ryannel <juergen.bocklage-ryannel@pelagicore.com> | 2017-01-10 21:46:57 +0100 |
commit | fb6601b52997b3c6bf5c643522b91089057b8310 (patch) | |
tree | aab1632c46d8631664a4133496e2244ccc68f3cf | |
parent | 72c858318801f1ed1f677c8d4965534e1b05d268 (diff) | |
download | qtivi-qface-fb6601b52997b3c6bf5c643522b91089057b8310.tar.gz |
Enhanced the model generation with append() and reset() operations.
-rw-r--r-- | examples/qtcpp/generator/templates/structmodel.cpp | 26 | ||||
-rw-r--r-- | examples/qtcpp/generator/templates/structmodel.h | 9 |
2 files changed, 28 insertions, 7 deletions
diff --git a/examples/qtcpp/generator/templates/structmodel.cpp b/examples/qtcpp/generator/templates/structmodel.cpp index 12104b9..3f13cb6 100644 --- a/examples/qtcpp/generator/templates/structmodel.cpp +++ b/examples/qtcpp/generator/templates/structmodel.cpp @@ -41,7 +41,6 @@ QVariant {{class}}::data(const QModelIndex &index, int role) const {% for field in struct.fields %} case Roles::{{field|upperfirst}}: return QVariant::fromValue({{struct|lower}}.m_{{field}}); - break; {% endfor %} } return QVariant(); @@ -53,7 +52,7 @@ QHash<int, QByteArray> {{class}}::roleNames() const } -void {{class}}::insert{{struct}}(int row, const Qml{{struct}} &{{struct|lower}}) +void {{class}}::insert(int row, const Qml{{struct}} &{{struct|lower}}) { if (row < 0) row = 0; @@ -66,7 +65,19 @@ void {{class}}::insert{{struct}}(int row, const Qml{{struct}} &{{struct|lower}}) emit countChanged(count()); } -void {{class}}::update{{struct}}(int row, const Qml{{struct}} &{{struct|lower}}) +void {{class}}::reset(const QList<Qml{{struct}}> data) +{ + beginResetModel(); + m_data = data; + endResetModel(); +} + +void {{class}}::append(const Qml{{struct}} &{{struct|lower}}) +{ + insert(m_data.count(), {{struct|lower}}); +} + +void {{class}}::update(int row, const Qml{{struct}} &{{struct|lower}}) { if(row < 0 || row >= m_data.count()) { return; @@ -76,7 +87,7 @@ void {{class}}::update{{struct}}(int row, const Qml{{struct}} &{{struct|lower}}) emit dataChanged(index, index); } -void {{class}}::remove{{struct}}(int row) +void {{class}}::remove(int row) { if(row < 0 || row >= m_data.count()) { return; @@ -86,3 +97,10 @@ void {{class}}::remove{{struct}}(int row) endRemoveRows(); } +void {{class}}::clear() +{ + beginResetModel(); + m_data.clear(); + endResetModel(); +} + diff --git a/examples/qtcpp/generator/templates/structmodel.h b/examples/qtcpp/generator/templates/structmodel.h index 85ed16b..d212265 100644 --- a/examples/qtcpp/generator/templates/structmodel.h +++ b/examples/qtcpp/generator/templates/structmodel.h @@ -20,9 +20,12 @@ public: {{class}}(QObject *parent=0); Q_INVOKABLE Qml{{struct}} get(int index); int count() const; - 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); + Q_INVOKABLE void insert(int row, const Qml{{struct}} &{{struct|lower}}); + Q_INVOKABLE void append(const Qml{{struct}} &{{struct|lower}}); + Q_INVOKABLE void update(int row, const Qml{{struct}} &{{struct|lower}}); + Q_INVOKABLE void remove(int row); + void reset(const QList<Qml{{struct}}> data); + Q_INVOKABLE void clear(); public: // from QAbstractListModel virtual int rowCount(const QModelIndex &parent) const; virtual QVariant data(const QModelIndex &index, int role) const; |