summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/clientapi.cpp10
-rw-r--r--common/modelresult.cpp6
-rw-r--r--tests/querytest.cpp16
3 files changed, 30 insertions, 2 deletions
diff --git a/common/clientapi.cpp b/common/clientapi.cpp
index 061d920..644d60c 100644
--- a/common/clientapi.cpp
+++ b/common/clientapi.cpp
@@ -90,7 +90,15 @@ QSharedPointer<QAbstractItemModel> Store::loadModel(Query query)
90 //* The result provider needs to live for as long as results are provided (until the last thread exits). 90 //* The result provider needs to live for as long as results are provided (until the last thread exits).
91 91
92 // Query all resources and aggregate results 92 // Query all resources and aggregate results
93 KAsync::iterate(getResources(query.resources, ApplicationDomain::getTypeName<DomainType>())) 93 auto resources = getResources(query.resources, ApplicationDomain::getTypeName<DomainType>());
94 if (resources.isEmpty()) {
95 Warning() << "No resources available.";
96 auto resultProvider = Akonadi2::ResultProvider<typename DomainType::Ptr>::Ptr::create();
97 model->setEmitter(resultProvider->emitter());
98 resultProvider->initialResultSetComplete(typename DomainType::Ptr());
99 return model;
100 }
101 KAsync::iterate(resources)
94 .template each<void, QByteArray>([query, model](const QByteArray &resource, KAsync::Future<void> &future) { 102 .template each<void, QByteArray>([query, model](const QByteArray &resource, KAsync::Future<void> &future) {
95 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resource), resource); 103 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resource), resource);
96 if (facade) { 104 if (facade) {
diff --git a/common/modelresult.cpp b/common/modelresult.cpp
index d2a7e88..d18dba1 100644
--- a/common/modelresult.cpp
+++ b/common/modelresult.cpp
@@ -203,7 +203,11 @@ void ModelResult<T, Ptr>::fetchEntities(const QModelIndex &parent)
203 const auto id = getIdentifier(parent); 203 const auto id = getIdentifier(parent);
204 mEntityChildrenFetched.insert(id); 204 mEntityChildrenFetched.insert(id);
205 Trace() << "Loading child entities"; 205 Trace() << "Loading child entities";
206 loadEntities(parent.data(DomainObjectRole).template value<Ptr>()); 206 if (loadEntities) {
207 loadEntities(parent.data(DomainObjectRole).template value<Ptr>());
208 } else {
209 Warning() << "No way to fetch entities";
210 }
207} 211}
208 212
209template<class T, class Ptr> 213template<class T, class Ptr>
diff --git a/tests/querytest.cpp b/tests/querytest.cpp
index f0f0766..1192b87 100644
--- a/tests/querytest.cpp
+++ b/tests/querytest.cpp
@@ -43,6 +43,22 @@ private Q_SLOTS:
43 qDebug(); 43 qDebug();
44 } 44 }
45 45
46 void testNoResources()
47 {
48 //Test
49 Akonadi2::Query query;
50 query.resources << "foobar";
51 query.syncOnDemand = false;
52 query.processAll = false;
53 query.liveQuery = true;
54
55 //We fetch before the data is available and rely on the live query mechanism to deliver the actual data
56 auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Mail>(query);
57 QTRY_VERIFY(model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool());
58 QCOMPARE(model->rowCount(), 0);
59 }
60
61
46 void testSingle() 62 void testSingle()
47 { 63 {
48 //Setup 64 //Setup