diff options
Diffstat (limited to 'framework/src/domain/folderlistmodel.cpp')
-rw-r--r-- | framework/src/domain/folderlistmodel.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/framework/src/domain/folderlistmodel.cpp b/framework/src/domain/folderlistmodel.cpp index 0abc70c5..1fe2abe6 100644 --- a/framework/src/domain/folderlistmodel.cpp +++ b/framework/src/domain/folderlistmodel.cpp | |||
@@ -26,11 +26,20 @@ | |||
26 | using namespace Sink; | 26 | using namespace Sink; |
27 | using namespace Sink::ApplicationDomain; | 27 | using namespace Sink::ApplicationDomain; |
28 | 28 | ||
29 | FolderListModel::FolderListModel(QObject *parent) : QSortFilterProxyModel() | 29 | FolderListModel::FolderListModel(QObject *parent) : KRecursiveFilterProxyModel() |
30 | { | 30 | { |
31 | setDynamicSortFilter(true); | 31 | setDynamicSortFilter(true); |
32 | sort(0, Qt::AscendingOrder); | 32 | sort(0, Qt::AscendingOrder); |
33 | 33 | ||
34 | //Automatically fetch all folders, otherwise the recursive filtering does not work. | ||
35 | QObject::connect(this, &QSortFilterProxyModel::sourceModelChanged, [this] () { | ||
36 | QObject::connect(sourceModel(), &QAbstractItemModel::rowsInserted, sourceModel(), [this] (QModelIndex parent, int first, int last) { | ||
37 | for (int row = first; row <= last; row++) { | ||
38 | auto idx = sourceModel()->index(row, 0, parent); | ||
39 | sourceModel()->fetchMore(idx); | ||
40 | } | ||
41 | }); | ||
42 | }); | ||
34 | } | 43 | } |
35 | 44 | ||
36 | FolderListModel::~FolderListModel() | 45 | FolderListModel::~FolderListModel() |
@@ -99,7 +108,6 @@ void FolderListModel::setAccountId(const QVariant &accountId) | |||
99 | auto query = Query(); | 108 | auto query = Query(); |
100 | query.resourceFilter<SinkResource::Account>(account); | 109 | query.resourceFilter<SinkResource::Account>(account); |
101 | query.setFlags(Sink::Query::LiveQuery | Sink::Query::UpdateStatus); | 110 | query.setFlags(Sink::Query::LiveQuery | Sink::Query::UpdateStatus); |
102 | query.filter<Folder::Enabled>(true); | ||
103 | query.request<Folder::Name>() | 111 | query.request<Folder::Name>() |
104 | .request<Folder::Icon>() | 112 | .request<Folder::Icon>() |
105 | .request<Folder::Parent>() | 113 | .request<Folder::Parent>() |
@@ -144,6 +152,14 @@ bool FolderListModel::lessThan(const QModelIndex &left, const QModelIndex &right | |||
144 | return leftPriority < rightPriority; | 152 | return leftPriority < rightPriority; |
145 | } | 153 | } |
146 | 154 | ||
155 | bool FolderListModel::acceptRow(int sourceRow, const QModelIndex &sourceParent) const | ||
156 | { | ||
157 | auto index = sourceModel()->index(sourceRow, 0, sourceParent); | ||
158 | const auto folder = index.data(Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::Folder::Ptr>(); | ||
159 | const auto enabled = folder->getEnabled(); | ||
160 | return enabled; | ||
161 | } | ||
162 | |||
147 | void FolderListModel::setFolderId(const QVariant &folderId) | 163 | void FolderListModel::setFolderId(const QVariant &folderId) |
148 | { | 164 | { |
149 | const auto folder = folderId.toString().toUtf8(); | 165 | const auto folder = folderId.toString().toUtf8(); |