From 630f45719a527f8ee739b03bc62f886badea6df3 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 13 Dec 2016 16:24:31 +0100 Subject: 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. --- framework/domain/identitiesmodel.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'framework/domain/identitiesmodel.cpp') 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 @@ */ #include "identitiesmodel.h" #include +#include + +using namespace Sink; IdentitiesModel::IdentitiesModel(QObject *parent) : QIdentityProxyModel() { Sink::Query query; query.setFlags(Sink::Query::LiveQuery); - query.requestedProperties << "name" << "username" << "address" << "account"; + query.request() + .request() + .request(); runQuery(query); } @@ -53,21 +58,21 @@ QVariant IdentitiesModel::data(const QModelIndex &idx, int role) const auto srcIdx = mapToSource(idx); switch (role) { case Name: - return srcIdx.sibling(srcIdx.row(), 0).data(Qt::DisplayRole).toString(); + return srcIdx.data(Sink::Store::DomainObjectRole).value()->getName(); case Username: - return srcIdx.sibling(srcIdx.row(), 1).data(Qt::DisplayRole).toString(); + return srcIdx.data(Sink::Store::DomainObjectRole).value()->getName(); case Address: - return srcIdx.sibling(srcIdx.row(), 2).data(Qt::DisplayRole).toString(); + return srcIdx.data(Sink::Store::DomainObjectRole).value()->getAddress(); case IdentityId: - return srcIdx.data(Sink::Store::DomainObjectBaseRole).value()->identifier(); + return srcIdx.data(Sink::Store::DomainObjectRole).value()->identifier(); case AccountId: - return srcIdx.data(Sink::Store::DomainObjectBaseRole).value()->getProperty("account").toByteArray(); + return srcIdx.data(Sink::Store::DomainObjectRole).value()->getAccount(); case AccountName: { - const auto accountId = srcIdx.sibling(srcIdx.row(), 3).data(Qt::DisplayRole).toByteArray(); + const auto accountId = srcIdx.data(Sink::Store::DomainObjectRole).value()->getAccount(); return mAccountNames.value(accountId); } case AccountIcon: { - const auto accountId = srcIdx.sibling(srcIdx.row(), 3).data(Qt::DisplayRole).toByteArray(); + const auto accountId = srcIdx.data(Sink::Store::DomainObjectRole).value()->getAccount(); return mAccountIcons.value(accountId); } case DisplayName: { @@ -85,8 +90,8 @@ void IdentitiesModel::runQuery(const Sink::Query &query) Sink::Store::fetchAll(Sink::Query()) .syncThen >([this](const QList &accounts) { for (const auto &account : accounts) { - mAccountNames.insert(account->identifier(), account->getProperty("name").toString()); - mAccountIcons.insert(account->identifier(), account->getProperty("icon").toString()); + mAccountNames.insert(account->identifier(), account->getName()); + mAccountIcons.insert(account->identifier(), account->getIcon()); } emit layoutChanged(); }).exec(); -- cgit v1.2.3