From 797c301157937a4904debdbedff5a97bd9a718f4 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 25 Oct 2016 20:15:43 +0200 Subject: Sort folders --- framework/domain/folderlistmodel.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'framework/domain/folderlistmodel.cpp') diff --git a/framework/domain/folderlistmodel.cpp b/framework/domain/folderlistmodel.cpp index 7cf5ad5d..e96488c8 100644 --- a/framework/domain/folderlistmodel.cpp +++ b/framework/domain/folderlistmodel.cpp @@ -25,8 +25,11 @@ using namespace Sink; using namespace Sink::ApplicationDomain; -FolderListModel::FolderListModel(QObject *parent) : QIdentityProxyModel() +FolderListModel::FolderListModel(QObject *parent) : QSortFilterProxyModel() { + setDynamicSortFilter(true); + sort(0, Qt::AscendingOrder); + Query query; query.liveQuery = true; query.request().request().request(); @@ -64,7 +67,7 @@ QVariant FolderListModel::data(const QModelIndex &idx, int role) const case DomainObject: return srcIdx.data(Store::DomainObjectRole); } - return QIdentityProxyModel::data(idx, role); + return QSortFilterProxyModel::data(idx, role); } void FolderListModel::runQuery(const Query &query) @@ -88,6 +91,28 @@ void FolderListModel::setAccountId(const QVariant &accountId) runQuery(query); } +static int getPriority(const Sink::ApplicationDomain::Folder &folder) +{ + auto specialPurpose = folder.getSpecialPurpose(); + if (specialPurpose.contains(Sink::ApplicationDomain::SpecialPurpose::Mail::inbox)) { + return 10; + } + if (!specialPurpose.isEmpty()) { + return 9; + } + return 0; +} + +bool FolderListModel::lessThan(const QModelIndex &left, const QModelIndex &right) const +{ + const auto leftFolder = left.data(Sink::Store::DomainObjectRole).value(); + const auto rightFolder = right.data(Sink::Store::DomainObjectRole).value(); + if (getPriority(*leftFolder) < getPriority(*rightFolder)) { + return true; + } + return leftFolder->getName() < rightFolder->getName(); +} + QVariant FolderListModel::accountId() const { return QVariant(); -- cgit v1.2.3