aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@qt.io>2019-12-06 16:17:42 +0100
committerDominik Holland <dominik.holland@qt.io>2019-12-17 21:45:44 +0100
commitec541913b637bad584d730248458e11b6e49dbe4 (patch)
tree4a0d7232ffddd327b1f91321653d4dbdfc4a0592
parentf1e9eea76ff1e97c635e7676a3bf0158b29d2b30 (diff)
ivigenerator: Fix iterating over the items of a model inside a simulation
From inside the QML simulation it was not possible to properly iterate over all items of a model. The missing count property is added by this commit. In addition the at() method is fixed to return the Q_GADGET based type by copy instead of returning a const ref, as QML cannot cope with that. Change-Id: Id12f05814684d3e9d482601fbaa788dc9c450df3 Fixes: AUTOSUITE-1371 Reviewed-by: Robert Griebl <robert.griebl@qt.io>
-rw-r--r--src/ivicore/qivipagingmodelinterface.cpp4
-rw-r--r--src/ivicore/qivipagingmodelinterface.h2
-rw-r--r--src/tools/ivigenerator/common/pagingmodel_simulation.cpp.tpl10
-rw-r--r--src/tools/ivigenerator/common/pagingmodel_simulation.h.tpl5
-rw-r--r--src/tools/ivigenerator/common/simulation.qmltypes.tpl1
5 files changed, 17 insertions, 5 deletions
diff --git a/src/ivicore/qivipagingmodelinterface.cpp b/src/ivicore/qivipagingmodelinterface.cpp
index 2d528d6..c8fed22 100644
--- a/src/ivicore/qivipagingmodelinterface.cpp
+++ b/src/ivicore/qivipagingmodelinterface.cpp
@@ -123,10 +123,10 @@ QIviPagingModelInterface::QIviPagingModelInterface(QObjectPrivate &dd, QObject *
*/
/*!
- \fn void QIviPagingModelInterface::countChanged(const QUuid &identifier, int newLength)
+ \fn void QIviPagingModelInterface::countChanged(const QUuid &identifier, int count)
This signal is emitted when the current number of items in the QIviPagingModel instance identified by \a identifier changed.
- The new number of items is returned as \a newLength.
+ The new number of items is returned as \a count.
This signal is expected to be emitted after the model instance has requested new data for the first time by calling fetchData() and
should be emitted before the data is returned by emitting the dataFetched() signal.
diff --git a/src/ivicore/qivipagingmodelinterface.h b/src/ivicore/qivipagingmodelinterface.h
index 0f3375a..4a6973e 100644
--- a/src/ivicore/qivipagingmodelinterface.h
+++ b/src/ivicore/qivipagingmodelinterface.h
@@ -69,7 +69,7 @@ protected:
Q_SIGNALS:
void supportedCapabilitiesChanged(const QUuid &identifier, QtIviCoreModule::ModelCapabilities capabilities);
- void countChanged(const QUuid &identifier, int newLength);
+ void countChanged(const QUuid &identifier = QUuid(), int count = -1);
void dataFetched(const QUuid &identifier, const QList<QVariant> &data, int start, bool moreAvailable);
void dataChanged(const QUuid &identifier, const QList<QVariant> &data, int start, int count);
};
diff --git a/src/tools/ivigenerator/common/pagingmodel_simulation.cpp.tpl b/src/tools/ivigenerator/common/pagingmodel_simulation.cpp.tpl
index 3b5ad78..c4f0850 100644
--- a/src/tools/ivigenerator/common/pagingmodel_simulation.cpp.tpl
+++ b/src/tools/ivigenerator/common/pagingmodel_simulation.cpp.tpl
@@ -51,6 +51,11 @@
{
}
+int {{class}}::count() const
+{
+ return m_list.count();
+}
+
void {{class}}::initialize()
{
QIVI_SIMULATION_TRY_CALL({{class}}, "initialize", void);
@@ -87,6 +92,7 @@ void {{class}}::insert(int index, const {{property.type.nested}} &item)
m_list.insert(index, item);
Q_EMIT dataChanged(QUuid(), { QVariant::fromValue(item) }, index, 0);
+ Q_EMIT countChanged(QUuid(), m_list.count());
}
void {{class}}::remove(int index)
@@ -94,6 +100,7 @@ void {{class}}::remove(int index)
m_list.removeAt(index);
Q_EMIT dataChanged(QUuid(), QVariantList(), index, 1);
+ Q_EMIT countChanged(QUuid(), m_list.count());
}
void {{class}}::move(int currentIndex, int newIndex)
@@ -112,6 +119,7 @@ void {{class}}::move(int currentIndex, int newIndex)
void {{class}}::reset()
{
Q_EMIT dataChanged(QUuid(), QVariantList(), 0, m_list.count());
+ Q_EMIT countChanged(QUuid(), 0);
m_list.clear();
}
@@ -121,7 +129,7 @@ void {{class}}::update(int index, const {{property.type.nested}} &item)
Q_EMIT dataChanged(QUuid(), { QVariant::fromValue(item) }, index, 1);
}
-const {{property.type.nested}} &{{class}}::at(int index) const
+{{property.type.nested}} {{class}}::at(int index) const
{
return m_list.at(index);
}
diff --git a/src/tools/ivigenerator/common/pagingmodel_simulation.h.tpl b/src/tools/ivigenerator/common/pagingmodel_simulation.h.tpl
index b67554f..16f16b7 100644
--- a/src/tools/ivigenerator/common/pagingmodel_simulation.h.tpl
+++ b/src/tools/ivigenerator/common/pagingmodel_simulation.h.tpl
@@ -46,10 +46,13 @@
class {{class}} : public QIviPagingModelInterface
{
Q_OBJECT
+ Q_PROPERTY(int count READ count NOTIFY countChanged)
public:
explicit {{class}}(QObject *parent = nullptr);
~{{class}}();
+ int count() const;
+
Q_INVOKABLE void initialize() override;
Q_INVOKABLE void registerInstance(const QUuid &identifier) override;
Q_INVOKABLE void unregisterInstance(const QUuid &identifier) override;
@@ -62,7 +65,7 @@ public Q_SLOTS:
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;
+ {{property.type.nested}} at(int index) const;
private:
QList<{{property.type.nested}}> m_list;
diff --git a/src/tools/ivigenerator/common/simulation.qmltypes.tpl b/src/tools/ivigenerator/common/simulation.qmltypes.tpl
index 80173c8..b8e79dc 100644
--- a/src/tools/ivigenerator/common/simulation.qmltypes.tpl
+++ b/src/tools/ivigenerator/common/simulation.qmltypes.tpl
@@ -103,6 +103,7 @@ Module {
exports: ["{{module|qml_type}}.simulation/{{property|upperfirst}}ModelBackend {{module.majorVersion}}.{{module.minorVersion}}"]
Property { name: "Base"; type: "{{property|upperfirst}}ModelBackend"; isPointer: true }
+ Property { name: "count"; type: "int" }
Method { name: "initialize" }
Method {