diff options
Diffstat (limited to 'common/clientapi.h')
-rw-r--r-- | common/clientapi.h | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/common/clientapi.h b/common/clientapi.h index a424424..707e81d 100644 --- a/common/clientapi.h +++ b/common/clientapi.h | |||
@@ -35,6 +35,8 @@ | |||
35 | #include "facadefactory.h" | 35 | #include "facadefactory.h" |
36 | #include "log.h" | 36 | #include "log.h" |
37 | 37 | ||
38 | Q_DECLARE_METATYPE(std::shared_ptr<void>); | ||
39 | |||
38 | namespace async { | 40 | namespace async { |
39 | //This should abstract if we execute from eventloop or in thread. | 41 | //This should abstract if we execute from eventloop or in thread. |
40 | //It supposed to allow the caller to finish the current method before executing the runner. | 42 | //It supposed to allow the caller to finish the current method before executing the runner. |
@@ -75,9 +77,8 @@ public: | |||
75 | // Query all resources and aggregate results | 77 | // Query all resources and aggregate results |
76 | KAsync::iterate(getResources(query.resources, ApplicationDomain::getTypeName<DomainType>())) | 78 | KAsync::iterate(getResources(query.resources, ApplicationDomain::getTypeName<DomainType>())) |
77 | .template each<void, QByteArray>([query, resultSet](const QByteArray &resource, KAsync::Future<void> &future) { | 79 | .template each<void, QByteArray>([query, resultSet](const QByteArray &resource, KAsync::Future<void> &future) { |
78 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resource), resource); | 80 | if (auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resource), resource)) { |
79 | if (facade) { | 81 | facade->load(query, *resultSet).template then<void>([&future](){future.setFinished();}).exec(); |
80 | facade->load(query, resultSet).template then<void>([&future](){future.setFinished();}).exec(); | ||
81 | //Keep the facade alive for the lifetime of the resultSet. | 82 | //Keep the facade alive for the lifetime of the resultSet. |
82 | resultSet->setFacade(facade); | 83 | resultSet->setFacade(facade); |
83 | } else { | 84 | } else { |
@@ -106,15 +107,18 @@ public: | |||
106 | static QSharedPointer<QAbstractItemModel> loadModel(Query query) | 107 | static QSharedPointer<QAbstractItemModel> loadModel(Query query) |
107 | { | 108 | { |
108 | auto model = QSharedPointer<ModelResult<DomainType, typename DomainType::Ptr> >::create(query, QList<QByteArray>() << "summary" << "uid"); | 109 | 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 | auto resultProvider = std::make_shared<ModelResultProvider<DomainType, typename DomainType::Ptr> >(model); |
111 | //Keep the resultprovider alive for as long as the model lives | ||
112 | model->setProperty("resultProvider", QVariant::fromValue(std::shared_ptr<void>(resultProvider))); | ||
110 | 113 | ||
111 | // Query all resources and aggregate results | 114 | // Query all resources and aggregate results |
112 | KAsync::iterate(getResources(query.resources, ApplicationDomain::getTypeName<DomainType>())) | 115 | KAsync::iterate(getResources(query.resources, ApplicationDomain::getTypeName<DomainType>())) |
113 | .template each<void, QByteArray>([query, resultProvider](const QByteArray &resource, KAsync::Future<void> &future) { | 116 | .template each<void, QByteArray>([query, resultProvider](const QByteArray &resource, KAsync::Future<void> &future) { |
114 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resource), resource); | 117 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resource), resource); |
115 | if (facade) { | 118 | if (facade) { |
116 | facade->load(query, resultProvider).template then<void>([&future](){future.setFinished();}).exec(); | 119 | facade->load(query, *resultProvider).template then<void>([&future](){future.setFinished();}).exec(); |
117 | //Keep the facade alive for the lifetime of the resultSet. | 120 | //Keep the facade alive for the lifetime of the resultSet. |
121 | //FIXME this would have to become a list | ||
118 | resultProvider->setFacade(facade); | 122 | resultProvider->setFacade(facade); |
119 | } else { | 123 | } else { |
120 | //Ignore the error and carry on | 124 | //Ignore the error and carry on |