aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@pelagicore.com>2018-10-09 11:23:58 +0200
committerDominik Holland <dominik.holland@pelagicore.com>2018-10-15 12:50:11 +0000
commit40d3a80737d0560fb03a8de83860dc567053a96f (patch)
treea9664ca8f021f06ba014f056f0295a636706f980
parent272517c7b9a9ef3221eed7a08fa26b37c0e81722 (diff)
Add helper functions to the autogenerated pagingmodel backend implementations
These helper functions can be used to alter a pagingmodel from QML and script it in a meaningful way without the need to care about the internal paging logic. Change-Id: Iaca947ab738701a93288e845df08ae4d37ec32df Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
-rw-r--r--src/tools/ivigenerator/templates_backend_simulator/pagingmodel.cpp.tpl45
-rw-r--r--src/tools/ivigenerator/templates_backend_simulator/pagingmodel.h.tpl16
2 files changed, 57 insertions, 4 deletions
diff --git a/src/tools/ivigenerator/templates_backend_simulator/pagingmodel.cpp.tpl b/src/tools/ivigenerator/templates_backend_simulator/pagingmodel.cpp.tpl
index 060a377..68433f6 100644
--- a/src/tools/ivigenerator/templates_backend_simulator/pagingmodel.cpp.tpl
+++ b/src/tools/ivigenerator/templates_backend_simulator/pagingmodel.cpp.tpl
@@ -42,6 +42,7 @@
{{class}}::{{class}}(QObject* parent)
: QIviPagingModelInterface(parent)
{
+ qRegisterMetaType<QIviPagingModelInterface*>();
m_list = {{property|default_value}};
}
@@ -85,3 +86,47 @@ void {{class}}::fetchData(const QUuid &identifier, int start, int count)
emit dataFetched(identifier, list, start, max < m_list.count());
}
+
+void {{class}}::insert(int index, const {{property.type.nested}} &item)
+{
+ m_list.insert(index, item);
+
+ emit dataChanged(QUuid(), { QVariant::fromValue(item) }, index, 0);
+}
+
+void {{class}}::remove(int index)
+{
+ m_list.removeAt(index);
+
+ emit dataChanged(QUuid(), QVariantList(), index, 1);
+}
+
+void {{class}}::move(int currentIndex, int newIndex)
+{
+ int min = qMin(currentIndex, newIndex);
+ int max = qMax(currentIndex, newIndex);
+
+ m_list.move(currentIndex, newIndex);
+ QVariantList variantList;
+ for (int i = min; i <= max; i++)
+ variantList.append(QVariant::fromValue(m_list.at(i)));
+
+ emit dataChanged(QUuid(), variantList, min, max - min + 1);
+}
+
+void {{class}}::reset()
+{
+ emit dataChanged(QUuid(), QVariantList(), 0, m_list.count());
+ m_list.clear();
+}
+
+void {{class}}::update(int index, const {{property.type.nested}} &item)
+{
+ m_list[index] = item;
+ emit dataChanged(QUuid(), { QVariant::fromValue(item) }, index, 1);
+}
+
+const {{property.type.nested}} &{{class}}::at(int index) const
+{
+ return m_list.at(index);
+}
diff --git a/src/tools/ivigenerator/templates_backend_simulator/pagingmodel.h.tpl b/src/tools/ivigenerator/templates_backend_simulator/pagingmodel.h.tpl
index 5d664bf..e274ce8 100644
--- a/src/tools/ivigenerator/templates_backend_simulator/pagingmodel.h.tpl
+++ b/src/tools/ivigenerator/templates_backend_simulator/pagingmodel.h.tpl
@@ -49,11 +49,19 @@ public:
explicit {{class}}(QObject *parent = nullptr);
~{{class}}();
- void initialize() override;
- void registerInstance(const QUuid &identifier) override;
- void unregisterInstance(const QUuid &identifier) override;
+ Q_INVOKABLE void initialize() override;
+ Q_INVOKABLE void registerInstance(const QUuid &identifier) override;
+ Q_INVOKABLE void unregisterInstance(const QUuid &identifier) override;
- void fetchData(const QUuid &identifier, int start, int count) override;
+ Q_INVOKABLE void fetchData(const QUuid &identifier, int start, int count) override;
+
+public Q_SLOTS:
+ void insert(int index, const {{property.type.nested}} &item);
+ void remove(int index);
+ void move(int currentIndex, int newIndex);
+ void reset();
+ void update(int index, const {{property.type.nested}} &item);
+ const {{property.type.nested}} &at(int index) const;
private:
QList<{{property.type.nested}}> m_list;