diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-11-13 19:34:47 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-11-13 19:34:47 +0100 |
commit | 09aafbd1373b5d1152ac7a453a140a7f76c2e90e (patch) | |
tree | 10e33196c4dd0d69a223f7b047d1a4ef256e4705 /common/clientapi.h | |
parent | 10d19014fe2c9c02f2bc3e19732cbe340e316076 (diff) | |
download | sink-09aafbd1373b5d1152ac7a453a140a7f76c2e90e.tar.gz sink-09aafbd1373b5d1152ac7a453a140a7f76c2e90e.zip |
It's starting to work
Diffstat (limited to 'common/clientapi.h')
-rw-r--r-- | common/clientapi.h | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/common/clientapi.h b/common/clientapi.h index 9a32188..a424424 100644 --- a/common/clientapi.h +++ b/common/clientapi.h | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <QString> | 23 | #include <QString> |
24 | #include <QSharedPointer> | 24 | #include <QSharedPointer> |
25 | #include <QEventLoop> | 25 | #include <QEventLoop> |
26 | #include <QAbstractItemModel> | ||
26 | #include <functional> | 27 | #include <functional> |
27 | #include <memory> | 28 | #include <memory> |
28 | 29 | ||
@@ -101,11 +102,34 @@ public: | |||
101 | /** | 102 | /** |
102 | * Asynchronusly load a dataset with tree structure information | 103 | * Asynchronusly load a dataset with tree structure information |
103 | */ | 104 | */ |
104 | // template <class DomainType> | 105 | template <class DomainType> |
105 | // static TreeSet<DomainType> loadTree(Query) | 106 | static QSharedPointer<QAbstractItemModel> loadModel(Query query) |
106 | // { | 107 | { |
108 | auto model = QSharedPointer<ModelResult<DomainType, typename DomainType::Ptr> >::create(query, QList<QByteArray>() << "summary" << "uid"); | ||
109 | auto resultProvider = QSharedPointer<ModelResultProvider<DomainType, typename DomainType::Ptr> >::create(model); | ||
110 | |||
111 | // Query all resources and aggregate results | ||
112 | KAsync::iterate(getResources(query.resources, ApplicationDomain::getTypeName<DomainType>())) | ||
113 | .template each<void, QByteArray>([query, resultProvider](const QByteArray &resource, KAsync::Future<void> &future) { | ||
114 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resource), resource); | ||
115 | if (facade) { | ||
116 | facade->load(query, resultProvider).template then<void>([&future](){future.setFinished();}).exec(); | ||
117 | //Keep the facade alive for the lifetime of the resultSet. | ||
118 | resultProvider->setFacade(facade); | ||
119 | } else { | ||
120 | //Ignore the error and carry on | ||
121 | future.setFinished(); | ||
122 | } | ||
123 | }).template then<void>([query, resultProvider]() { | ||
124 | resultProvider->initialResultSetComplete(); | ||
125 | if (!query.liveQuery) { | ||
126 | resultProvider->complete(); | ||
127 | } | ||
128 | }).exec(); | ||
129 | |||
130 | return model; | ||
131 | } | ||
107 | 132 | ||
108 | // } | ||
109 | template <class DomainType> | 133 | template <class DomainType> |
110 | static std::shared_ptr<StoreFacade<DomainType> > getFacade(const QByteArray &resourceInstanceIdentifier) | 134 | static std::shared_ptr<StoreFacade<DomainType> > getFacade(const QByteArray &resourceInstanceIdentifier) |
111 | { | 135 | { |