diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-11-19 18:14:09 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-11-19 18:14:09 +0100 |
commit | c4a6746e4420b580fe35cc89783de4dbc3205ac6 (patch) | |
tree | e58905f13653d44671ca0e88388f83d26c5a3a28 | |
parent | 8d5684292ef92f32487ba32df716a00c4a0841b5 (diff) | |
download | sink-c4a6746e4420b580fe35cc89783de4dbc3205ac6.tar.gz sink-c4a6746e4420b580fe35cc89783de4dbc3205ac6.zip |
The parent is always an object, so we might as well make that explicit
-rw-r--r-- | common/facade.h | 13 | ||||
-rw-r--r-- | common/modelresult.h | 17 | ||||
-rw-r--r-- | common/resultprovider.h | 8 | ||||
-rw-r--r-- | tests/clientapitest.cpp | 2 |
4 files changed, 18 insertions, 22 deletions
diff --git a/common/facade.h b/common/facade.h index d150d60..8b8a2a8 100644 --- a/common/facade.h +++ b/common/facade.h | |||
@@ -172,7 +172,7 @@ public: | |||
172 | KAsync::Job<void> load(const Akonadi2::Query &query, Akonadi2::ResultProviderInterface<typename DomainType::Ptr> &resultProvider) Q_DECL_OVERRIDE | 172 | KAsync::Job<void> load(const Akonadi2::Query &query, Akonadi2::ResultProviderInterface<typename DomainType::Ptr> &resultProvider) Q_DECL_OVERRIDE |
173 | { | 173 | { |
174 | //We delegate loading of initial data to the result provider, os it can decide for itself what it needs to load. | 174 | //We delegate loading of initial data to the result provider, os it can decide for itself what it needs to load. |
175 | resultProvider.setFetcher([this, query, &resultProvider](const QByteArray &parent) { | 175 | resultProvider.setFetcher([this, query, &resultProvider](const typename DomainType::Ptr &parent) { |
176 | const qint64 newRevision = executeInitialQuery(query, parent, resultProvider); | 176 | const qint64 newRevision = executeInitialQuery(query, parent, resultProvider); |
177 | mResourceAccess->sendRevisionReplayedCommand(newRevision); | 177 | mResourceAccess->sendRevisionReplayedCommand(newRevision); |
178 | }); | 178 | }); |
@@ -358,11 +358,16 @@ private: | |||
358 | }, resultProvider); | 358 | }, resultProvider); |
359 | } | 359 | } |
360 | 360 | ||
361 | qint64 executeInitialQuery(const Akonadi2::Query &query, const QByteArray &parent, Akonadi2::ResultProviderInterface<typename DomainType::Ptr> &resultProvider) | 361 | qint64 executeInitialQuery(const Akonadi2::Query &query, const typename DomainType::Ptr &parent, Akonadi2::ResultProviderInterface<typename DomainType::Ptr> &resultProvider) |
362 | { | 362 | { |
363 | Trace() << "Running initial query for parent:" << parent; | ||
364 | auto modifiedQuery = query; | 363 | auto modifiedQuery = query; |
365 | modifiedQuery.propertyFilter.insert("parent", parent); | 364 | if (parent) { |
365 | Trace() << "Running initial query for parent:" << parent->identifier(); | ||
366 | modifiedQuery.propertyFilter.insert("parent", parent->identifier()); | ||
367 | } else { | ||
368 | Trace() << "Running initial query for toplevel"; | ||
369 | modifiedQuery.propertyFilter.insert("parent", QVariant()); | ||
370 | } | ||
366 | return load(modifiedQuery, [&](Akonadi2::Storage::Transaction &transaction, QSet<QByteArray> &remainingFilters) -> ResultSet { | 371 | return load(modifiedQuery, [&](Akonadi2::Storage::Transaction &transaction, QSet<QByteArray> &remainingFilters) -> ResultSet { |
367 | return loadInitialResultSet(modifiedQuery, transaction, remainingFilters); | 372 | return loadInitialResultSet(modifiedQuery, transaction, remainingFilters); |
368 | }, resultProvider); | 373 | }, resultProvider); |
diff --git a/common/modelresult.h b/common/modelresult.h index 1675e60..26f96d8 100644 --- a/common/modelresult.h +++ b/common/modelresult.h | |||
@@ -179,20 +179,11 @@ public: | |||
179 | { | 179 | { |
180 | const auto id = getIdentifier(parent); | 180 | const auto id = getIdentifier(parent); |
181 | mEntityChildrenFetched[id] = true; | 181 | mEntityChildrenFetched[id] = true; |
182 | QByteArray parentIdentifier; | 182 | Trace() << "Loading child entities"; |
183 | if (!parent.isValid()) { | 183 | loadEntities(parent.data(DomainObjectRole).template value<Ptr>()); |
184 | qDebug() << "no parent"; | ||
185 | } else { | ||
186 | qDebug() << "parent is valid"; | ||
187 | auto object = parent.data(DomainObjectRole).template value<Ptr>(); | ||
188 | Q_ASSERT(object); | ||
189 | parentIdentifier = object->identifier(); | ||
190 | } | ||
191 | Trace() << "Loading child entities of: " << parentIdentifier; | ||
192 | loadEntities(parentIdentifier); | ||
193 | } | 184 | } |
194 | 185 | ||
195 | void setFetcher(const std::function<void(const QByteArray &parent)> &fetcher) | 186 | void setFetcher(const std::function<void(const Ptr &parent)> &fetcher) |
196 | { | 187 | { |
197 | Trace() << "Setting fetcher"; | 188 | Trace() << "Setting fetcher"; |
198 | loadEntities = fetcher; | 189 | loadEntities = fetcher; |
@@ -206,6 +197,6 @@ private: | |||
206 | QMap<qint64 /* entity id */, bool> mEntityChildrenFetched; | 197 | QMap<qint64 /* entity id */, bool> mEntityChildrenFetched; |
207 | QList<QByteArray> mPropertyColumns; | 198 | QList<QByteArray> mPropertyColumns; |
208 | Akonadi2::Query mQuery; | 199 | Akonadi2::Query mQuery; |
209 | std::function<void(const QByteArray &)> loadEntities; | 200 | std::function<void(const Ptr &)> loadEntities; |
210 | }; | 201 | }; |
211 | 202 | ||
diff --git a/common/resultprovider.h b/common/resultprovider.h index 0d23127..921cd6b 100644 --- a/common/resultprovider.h +++ b/common/resultprovider.h | |||
@@ -53,7 +53,7 @@ public: | |||
53 | virtual void initialResultSetComplete() = 0; | 53 | virtual void initialResultSetComplete() = 0; |
54 | virtual void complete() = 0; | 54 | virtual void complete() = 0; |
55 | virtual void clear() = 0; | 55 | virtual void clear() = 0; |
56 | virtual void setFetcher(const std::function<void(const QByteArray &parent)> &fetcher) | 56 | virtual void setFetcher(const std::function<void(const T &parent)> &fetcher) |
57 | { | 57 | { |
58 | } | 58 | } |
59 | 59 | ||
@@ -141,7 +141,7 @@ public: | |||
141 | return true; | 141 | return true; |
142 | } | 142 | } |
143 | 143 | ||
144 | void setFetcher(const std::function<void(const QByteArray &parent)> &fetcher) | 144 | void setFetcher(const std::function<void(const Ptr &parent)> &fetcher) |
145 | { | 145 | { |
146 | if (auto model = mModel.toStrongRef()) { | 146 | if (auto model = mModel.toStrongRef()) { |
147 | model->setFetcher(fetcher); | 147 | model->setFetcher(fetcher); |
@@ -297,9 +297,9 @@ public: | |||
297 | return mResultEmitter.toStrongRef().isNull(); | 297 | return mResultEmitter.toStrongRef().isNull(); |
298 | } | 298 | } |
299 | 299 | ||
300 | void setFetcher(const std::function<void(const QByteArray &parent)> &fetcher) | 300 | void setFetcher(const std::function<void(const T &parent)> &fetcher) |
301 | { | 301 | { |
302 | fetcher(QByteArray()); | 302 | fetcher(T()); |
303 | } | 303 | } |
304 | 304 | ||
305 | private: | 305 | private: |
diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index 9202e29..ce11221 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp | |||
@@ -30,7 +30,7 @@ public: | |||
30 | KAsync::Job<void> load(const Akonadi2::Query &query, Akonadi2::ResultProviderInterface<typename T::Ptr> &resultProvider) Q_DECL_OVERRIDE | 30 | KAsync::Job<void> load(const Akonadi2::Query &query, Akonadi2::ResultProviderInterface<typename T::Ptr> &resultProvider) Q_DECL_OVERRIDE |
31 | { | 31 | { |
32 | capturedResultProvider = &resultProvider; | 32 | capturedResultProvider = &resultProvider; |
33 | resultProvider.setFetcher([query, &resultProvider, this](const QByteArray &) { | 33 | resultProvider.setFetcher([query, &resultProvider, this](const typename T::Ptr &) { |
34 | for (const auto &res : results) { | 34 | for (const auto &res : results) { |
35 | qDebug() << "Parent filter " << query.propertyFilter.value("parent").toByteArray() << res->identifier(); | 35 | qDebug() << "Parent filter " << query.propertyFilter.value("parent").toByteArray() << res->identifier(); |
36 | if (!query.propertyFilter.contains("parent") || query.propertyFilter.value("parent").toByteArray() == res->getProperty("parent").toByteArray()) { | 36 | if (!query.propertyFilter.contains("parent") || query.propertyFilter.value("parent").toByteArray() == res->getProperty("parent").toByteArray()) { |