diff options
Diffstat (limited to 'framework/domain/folderlistmodel.cpp')
-rw-r--r-- | framework/domain/folderlistmodel.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
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 @@ | |||
25 | using namespace Sink; | 25 | using namespace Sink; |
26 | using namespace Sink::ApplicationDomain; | 26 | using namespace Sink::ApplicationDomain; |
27 | 27 | ||
28 | FolderListModel::FolderListModel(QObject *parent) : QIdentityProxyModel() | 28 | FolderListModel::FolderListModel(QObject *parent) : QSortFilterProxyModel() |
29 | { | 29 | { |
30 | setDynamicSortFilter(true); | ||
31 | sort(0, Qt::AscendingOrder); | ||
32 | |||
30 | Query query; | 33 | Query query; |
31 | query.liveQuery = true; | 34 | query.liveQuery = true; |
32 | query.request<Folder::Name>().request<Folder::Icon>().request<Folder::Parent>(); | 35 | query.request<Folder::Name>().request<Folder::Icon>().request<Folder::Parent>(); |
@@ -64,7 +67,7 @@ QVariant FolderListModel::data(const QModelIndex &idx, int role) const | |||
64 | case DomainObject: | 67 | case DomainObject: |
65 | return srcIdx.data(Store::DomainObjectRole); | 68 | return srcIdx.data(Store::DomainObjectRole); |
66 | } | 69 | } |
67 | return QIdentityProxyModel::data(idx, role); | 70 | return QSortFilterProxyModel::data(idx, role); |
68 | } | 71 | } |
69 | 72 | ||
70 | void FolderListModel::runQuery(const Query &query) | 73 | void FolderListModel::runQuery(const Query &query) |
@@ -88,6 +91,28 @@ void FolderListModel::setAccountId(const QVariant &accountId) | |||
88 | runQuery(query); | 91 | runQuery(query); |
89 | } | 92 | } |
90 | 93 | ||
94 | static int getPriority(const Sink::ApplicationDomain::Folder &folder) | ||
95 | { | ||
96 | auto specialPurpose = folder.getSpecialPurpose(); | ||
97 | if (specialPurpose.contains(Sink::ApplicationDomain::SpecialPurpose::Mail::inbox)) { | ||
98 | return 10; | ||
99 | } | ||
100 | if (!specialPurpose.isEmpty()) { | ||
101 | return 9; | ||
102 | } | ||
103 | return 0; | ||
104 | } | ||
105 | |||
106 | bool FolderListModel::lessThan(const QModelIndex &left, const QModelIndex &right) const | ||
107 | { | ||
108 | const auto leftFolder = left.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Folder::Ptr>(); | ||
109 | const auto rightFolder = right.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Folder::Ptr>(); | ||
110 | if (getPriority(*leftFolder) < getPriority(*rightFolder)) { | ||
111 | return true; | ||
112 | } | ||
113 | return leftFolder->getName() < rightFolder->getName(); | ||
114 | } | ||
115 | |||
91 | QVariant FolderListModel::accountId() const | 116 | QVariant FolderListModel::accountId() const |
92 | { | 117 | { |
93 | return QVariant(); | 118 | return QVariant(); |