summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ivicore/qivisearchandbrowsemodel.cpp23
-rw-r--r--src/ivicore/qivisearchandbrowsemodel.h1
-rw-r--r--tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp30
3 files changed, 52 insertions, 2 deletions
diff --git a/src/ivicore/qivisearchandbrowsemodel.cpp b/src/ivicore/qivisearchandbrowsemodel.cpp
index 2c18227..abf2061 100644
--- a/src/ivicore/qivisearchandbrowsemodel.cpp
+++ b/src/ivicore/qivisearchandbrowsemodel.cpp
@@ -216,11 +216,14 @@ void QIviSearchAndBrowseModelPrivate::onFetchMoreThresholdReached()
void QIviSearchAndBrowseModelPrivate::resetModel()
{
Q_Q(QIviSearchAndBrowseModel);
+
q->beginResetModel();
m_itemList.clear();
m_availableChunks.clear();
- q->endResetModel();
m_fetchedDataCount = 0;
+ //Setting this to true to let fetchMore do one first fetchcall.
+ m_moreAvailable = true;
+ q->endResetModel();
if (searchBackend())
setAvailableContenTypes(searchBackend()->availableContentTypes().toList());
@@ -228,7 +231,6 @@ void QIviSearchAndBrowseModelPrivate::resetModel()
checkType();
parseQuery();
- m_moreAvailable = false;
q->fetchMore(QModelIndex());
}
@@ -1342,6 +1344,20 @@ void QIviSearchAndBrowseModel::indexOf(const QVariant &variant, const QJSValue &
}
/*!
+ \qmlmethod SearchAndBrowseModel::reload()
+
+ Resets the model and starts fetching the content again.
+*/
+/*!
+ Resets the model and starts fetching the content again.
+*/
+void QIviSearchAndBrowseModel::reload()
+{
+ Q_D(QIviSearchAndBrowseModel);
+ d->resetModel();
+}
+
+/*!
\reimp
*/
bool QIviSearchAndBrowseModel::canFetchMore(const QModelIndex &parent) const
@@ -1365,6 +1381,9 @@ void QIviSearchAndBrowseModel::fetchMore(const QModelIndex &parent)
if (!d->searchBackend() || d->m_contentType.isEmpty())
return;
+ if (!d->m_moreAvailable)
+ return;
+
d->m_moreAvailable = false;
d->fetchData(-1);
}
diff --git a/src/ivicore/qivisearchandbrowsemodel.h b/src/ivicore/qivisearchandbrowsemodel.h
index fc85aac..cf201e8 100644
--- a/src/ivicore/qivisearchandbrowsemodel.h
+++ b/src/ivicore/qivisearchandbrowsemodel.h
@@ -146,6 +146,7 @@ public:
Q_INVOKABLE void move(int cur_index, int new_index);
//TODO add a C++ version for this, similar to QTimer::singleShot()
Q_INVOKABLE void indexOf(const QVariant &variant, const QJSValue &functor);
+ Q_INVOKABLE void reload();
template <typename T> T at(int i) const {
return data(index(i,0), ItemRole).value<T>();
diff --git a/tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp b/tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp
index d7a2e88..5b90a25 100644
--- a/tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp
+++ b/tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp
@@ -357,6 +357,7 @@ private Q_SLOTS:
void testFetchMore_data();
void testFetchMore();
void testDataChangedMode();
+ void testReload();
void testDataChangedMode_jump();
void testNavigation_data();
void testNavigation();
@@ -607,6 +608,35 @@ void tst_QIviSearchAndBrowseModel::testDataChangedMode()
QCOMPARE(fetchDataSpy.at(0).at(2).toInt(), testIndex + 1);
}
+void tst_QIviSearchAndBrowseModel::testReload()
+{
+ TestServiceObject *service = new TestServiceObject();
+ manager->registerService(service, service->interfaces());
+ service->testBackend()->setCapabilities(QIviSearchAndBrowseModel::SupportsGetSize);
+ service->testBackend()->initializeSimpleData();
+
+ QIviSearchAndBrowseModel model;
+ model.setServiceObject(service);
+
+ QVERIFY(model.serviceObject());
+
+ QVERIFY(model.availableContentTypes().contains("simple"));
+ QSignalSpy countChangedSpy(&model, SIGNAL(countChanged()));
+ model.setContentType("simple");
+ countChangedSpy.wait(100);
+ QVERIFY(countChangedSpy.count());
+
+ QCOMPARE(model.rowCount(), model.chunkSize());
+ countChangedSpy.clear();
+
+ QSignalSpy resetSpy(&model, SIGNAL(modelReset()));
+ model.reload();
+ countChangedSpy.wait(100);
+ QCOMPARE(resetSpy.count(), 1);
+ QCOMPARE(countChangedSpy.count(), 2);
+ QCOMPARE(model.rowCount(), model.chunkSize());
+}
+
void tst_QIviSearchAndBrowseModel::testDataChangedMode_jump()
{
TestServiceObject *service = new TestServiceObject();