diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-13 19:21:52 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-13 19:21:52 +0100 |
commit | 1aa82ab9cfacca1ee9af9f9137caeede55f89230 (patch) | |
tree | de1b6e2193fdc4213178da748beb5c388d01af0a /common/resultprovider.h | |
parent | 1999bbb377561e6e83c126de536a26df18870970 (diff) | |
download | sink-1aa82ab9cfacca1ee9af9f9137caeede55f89230.tar.gz sink-1aa82ab9cfacca1ee9af9f9137caeede55f89230.zip |
Load entities from multiple resources
Diffstat (limited to 'common/resultprovider.h')
-rw-r--r-- | common/resultprovider.h | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/common/resultprovider.h b/common/resultprovider.h index d50f3f6..d94ad44 100644 --- a/common/resultprovider.h +++ b/common/resultprovider.h | |||
@@ -235,6 +235,11 @@ class ResultEmitter { | |||
235 | public: | 235 | public: |
236 | typedef QSharedPointer<ResultEmitter<DomainType> > Ptr; | 236 | typedef QSharedPointer<ResultEmitter<DomainType> > Ptr; |
237 | 237 | ||
238 | virtual ~ResultEmitter() | ||
239 | { | ||
240 | |||
241 | } | ||
242 | |||
238 | void onAdded(const std::function<void(const DomainType&)> &handler) | 243 | void onAdded(const std::function<void(const DomainType&)> &handler) |
239 | { | 244 | { |
240 | addHandler = handler; | 245 | addHandler = handler; |
@@ -306,7 +311,12 @@ public: | |||
306 | mFetcher = fetcher; | 311 | mFetcher = fetcher; |
307 | } | 312 | } |
308 | 313 | ||
309 | std::function<void(const DomainType &parent)> mFetcher; | 314 | virtual void fetch(const DomainType &parent) |
315 | { | ||
316 | if (mFetcher) { | ||
317 | mFetcher(parent); | ||
318 | } | ||
319 | } | ||
310 | 320 | ||
311 | private: | 321 | private: |
312 | friend class ResultProvider<DomainType>; | 322 | friend class ResultProvider<DomainType>; |
@@ -317,8 +327,51 @@ private: | |||
317 | std::function<void(const DomainType&)> initialResultSetCompleteHandler; | 327 | std::function<void(const DomainType&)> initialResultSetCompleteHandler; |
318 | std::function<void(void)> completeHandler; | 328 | std::function<void(void)> completeHandler; |
319 | std::function<void(void)> clearHandler; | 329 | std::function<void(void)> clearHandler; |
330 | |||
331 | std::function<void(const DomainType &parent)> mFetcher; | ||
320 | ThreadBoundary mThreadBoundary; | 332 | ThreadBoundary mThreadBoundary; |
321 | }; | 333 | }; |
322 | 334 | ||
335 | template<class DomainType> | ||
336 | class AggregatingResultEmitter : public ResultEmitter<DomainType> { | ||
337 | public: | ||
338 | typedef QSharedPointer<AggregatingResultEmitter<DomainType> > Ptr; | ||
339 | |||
340 | void addEmitter(const typename ResultEmitter<DomainType>::Ptr &emitter) | ||
341 | { | ||
342 | emitter->onAdded([this](const DomainType &value) { | ||
343 | this->add(value); | ||
344 | }); | ||
345 | emitter->onModified([this](const DomainType &value) { | ||
346 | this->modify(value); | ||
347 | }); | ||
348 | emitter->onRemoved([this](const DomainType &value) { | ||
349 | this->remove(value); | ||
350 | }); | ||
351 | emitter->onInitialResultSetComplete([this](const DomainType &value) { | ||
352 | this->initialResultSetComplete(value); | ||
353 | }); | ||
354 | emitter->onComplete([this]() { | ||
355 | this->complete(); | ||
356 | }); | ||
357 | emitter->onClear([this]() { | ||
358 | this->clear(); | ||
359 | }); | ||
360 | mEmitter << emitter; | ||
361 | } | ||
362 | |||
363 | void fetch(const DomainType &parent) Q_DECL_OVERRIDE | ||
364 | { | ||
365 | for (const auto &emitter : mEmitter) { | ||
366 | emitter->fetch(parent); | ||
367 | } | ||
368 | } | ||
369 | |||
370 | private: | ||
371 | QList<typename ResultEmitter<DomainType>::Ptr> mEmitter; | ||
372 | }; | ||
373 | |||
374 | |||
375 | |||
323 | } | 376 | } |
324 | 377 | ||