summaryrefslogtreecommitdiffstats
path: root/framework/domain/identitiesmodel.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-12-13 16:24:31 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-12-16 14:54:14 +0100
commit630f45719a527f8ee739b03bc62f886badea6df3 (patch)
treeb9d859cbfedb30ad8a9570e3b87a419bf24ba6c7 /framework/domain/identitiesmodel.cpp
parentb1a2e2de201985a00980bead5272977cda4ef637 (diff)
downloadkube-630f45719a527f8ee739b03bc62f886badea6df3.tar.gz
kube-630f45719a527f8ee739b03bc62f886badea6df3.zip
Revamp of composercontroller to use actions more.
Instead of setting all properties individually we directly assign all properties to a context that we assign to the actions. This way actions can automatically update themselves as new data becomes available, and we avoid the setter/getter boilerplate, at the cost of a less explicit interface (But that could be improved by allowing to define the required properties of a context in c++). By relying on prehandler/posthandler to execute certain actions we simplify the control flow and enable the future extension with handlers that i.e. do encryption etc.
Diffstat (limited to 'framework/domain/identitiesmodel.cpp')
-rw-r--r--framework/domain/identitiesmodel.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/framework/domain/identitiesmodel.cpp b/framework/domain/identitiesmodel.cpp
index 8f5c4963..33cc191c 100644
--- a/framework/domain/identitiesmodel.cpp
+++ b/framework/domain/identitiesmodel.cpp
@@ -18,12 +18,17 @@
18*/ 18*/
19#include "identitiesmodel.h" 19#include "identitiesmodel.h"
20#include <sink/store.h> 20#include <sink/store.h>
21#include <sink/log.h>
22
23using namespace Sink;
21 24
22IdentitiesModel::IdentitiesModel(QObject *parent) : QIdentityProxyModel() 25IdentitiesModel::IdentitiesModel(QObject *parent) : QIdentityProxyModel()
23{ 26{
24 Sink::Query query; 27 Sink::Query query;
25 query.setFlags(Sink::Query::LiveQuery); 28 query.setFlags(Sink::Query::LiveQuery);
26 query.requestedProperties << "name" << "username" << "address" << "account"; 29 query.request<Sink::ApplicationDomain::Identity::Name>()
30 .request<Sink::ApplicationDomain::Identity::Address>()
31 .request<Sink::ApplicationDomain::Identity::Account>();
27 runQuery(query); 32 runQuery(query);
28} 33}
29 34
@@ -53,21 +58,21 @@ QVariant IdentitiesModel::data(const QModelIndex &idx, int role) const
53 auto srcIdx = mapToSource(idx); 58 auto srcIdx = mapToSource(idx);
54 switch (role) { 59 switch (role) {
55 case Name: 60 case Name:
56 return srcIdx.sibling(srcIdx.row(), 0).data(Qt::DisplayRole).toString(); 61 return srcIdx.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Identity::Ptr>()->getName();
57 case Username: 62 case Username:
58 return srcIdx.sibling(srcIdx.row(), 1).data(Qt::DisplayRole).toString(); 63 return srcIdx.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Identity::Ptr>()->getName();
59 case Address: 64 case Address:
60 return srcIdx.sibling(srcIdx.row(), 2).data(Qt::DisplayRole).toString(); 65 return srcIdx.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Identity::Ptr>()->getAddress();
61 case IdentityId: 66 case IdentityId:
62 return srcIdx.data(Sink::Store::DomainObjectBaseRole).value<Sink::ApplicationDomain::ApplicationDomainType::Ptr>()->identifier(); 67 return srcIdx.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Identity::Ptr>()->identifier();
63 case AccountId: 68 case AccountId:
64 return srcIdx.data(Sink::Store::DomainObjectBaseRole).value<Sink::ApplicationDomain::ApplicationDomainType::Ptr>()->getProperty("account").toByteArray(); 69 return srcIdx.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Identity::Ptr>()->getAccount();
65 case AccountName: { 70 case AccountName: {
66 const auto accountId = srcIdx.sibling(srcIdx.row(), 3).data(Qt::DisplayRole).toByteArray(); 71 const auto accountId = srcIdx.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Identity::Ptr>()->getAccount();
67 return mAccountNames.value(accountId); 72 return mAccountNames.value(accountId);
68 } 73 }
69 case AccountIcon: { 74 case AccountIcon: {
70 const auto accountId = srcIdx.sibling(srcIdx.row(), 3).data(Qt::DisplayRole).toByteArray(); 75 const auto accountId = srcIdx.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Identity::Ptr>()->getAccount();
71 return mAccountIcons.value(accountId); 76 return mAccountIcons.value(accountId);
72 } 77 }
73 case DisplayName: { 78 case DisplayName: {
@@ -85,8 +90,8 @@ void IdentitiesModel::runQuery(const Sink::Query &query)
85 Sink::Store::fetchAll<Sink::ApplicationDomain::SinkAccount>(Sink::Query()) 90 Sink::Store::fetchAll<Sink::ApplicationDomain::SinkAccount>(Sink::Query())
86 .syncThen<void, QList<Sink::ApplicationDomain::SinkAccount::Ptr> >([this](const QList<Sink::ApplicationDomain::SinkAccount::Ptr> &accounts) { 91 .syncThen<void, QList<Sink::ApplicationDomain::SinkAccount::Ptr> >([this](const QList<Sink::ApplicationDomain::SinkAccount::Ptr> &accounts) {
87 for (const auto &account : accounts) { 92 for (const auto &account : accounts) {
88 mAccountNames.insert(account->identifier(), account->getProperty("name").toString()); 93 mAccountNames.insert(account->identifier(), account->getName());
89 mAccountIcons.insert(account->identifier(), account->getProperty("icon").toString()); 94 mAccountIcons.insert(account->identifier(), account->getIcon());
90 } 95 }
91 emit layoutChanged(); 96 emit layoutChanged();
92 }).exec(); 97 }).exec();