diff options
Diffstat (limited to 'framework/domain/identitiesmodel.cpp')
-rw-r--r-- | framework/domain/identitiesmodel.cpp | 25 |
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 | |||
23 | using namespace Sink; | ||
21 | 24 | ||
22 | IdentitiesModel::IdentitiesModel(QObject *parent) : QIdentityProxyModel() | 25 | IdentitiesModel::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(); |