diff options
-rw-r--r-- | framework/domain/folderlistmodel.cpp | 29 | ||||
-rw-r--r-- | framework/domain/folderlistmodel.h | 10 |
2 files changed, 33 insertions, 6 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(); |
diff --git a/framework/domain/folderlistmodel.h b/framework/domain/folderlistmodel.h index d30393db..a2adc9a9 100644 --- a/framework/domain/folderlistmodel.h +++ b/framework/domain/folderlistmodel.h | |||
@@ -21,7 +21,7 @@ | |||
21 | #pragma once | 21 | #pragma once |
22 | 22 | ||
23 | #include <QObject> | 23 | #include <QObject> |
24 | #include <QIdentityProxyModel> | 24 | #include <QSortFilterProxyModel> |
25 | #include <QSharedPointer> | 25 | #include <QSharedPointer> |
26 | #include <QStringList> | 26 | #include <QStringList> |
27 | 27 | ||
@@ -29,7 +29,7 @@ namespace Sink { | |||
29 | class Query; | 29 | class Query; |
30 | } | 30 | } |
31 | 31 | ||
32 | class FolderListModel : public QIdentityProxyModel | 32 | class FolderListModel : public QSortFilterProxyModel |
33 | { | 33 | { |
34 | Q_OBJECT | 34 | Q_OBJECT |
35 | 35 | ||
@@ -39,7 +39,7 @@ public: | |||
39 | FolderListModel(QObject *parent = Q_NULLPTR); | 39 | FolderListModel(QObject *parent = Q_NULLPTR); |
40 | ~FolderListModel(); | 40 | ~FolderListModel(); |
41 | 41 | ||
42 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | 42 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; |
43 | 43 | ||
44 | enum Roles { | 44 | enum Roles { |
45 | Name = Qt::UserRole + 1, | 45 | Name = Qt::UserRole + 1, |
@@ -49,10 +49,12 @@ public: | |||
49 | }; | 49 | }; |
50 | Q_ENUMS(Roles) | 50 | Q_ENUMS(Roles) |
51 | 51 | ||
52 | QHash<int, QByteArray> roleNames() const; | 52 | QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE; |
53 | 53 | ||
54 | void setAccountId(const QVariant &accountId); | 54 | void setAccountId(const QVariant &accountId); |
55 | QVariant accountId() const; | 55 | QVariant accountId() const; |
56 | protected: | ||
57 | bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE; | ||
56 | 58 | ||
57 | private: | 59 | private: |
58 | void runQuery(const Sink::Query &query); | 60 | void runQuery(const Sink::Query &query); |