summaryrefslogtreecommitdiffstats
path: root/framework/src/domain
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-08-20 13:55:56 -0600
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-08-20 13:55:56 -0600
commitf6e6cd8a5c8ef2d8d7e331834dff026646be543e (patch)
tree68fda89590301378d1e2658498451a1c43f55aea /framework/src/domain
parentc6d028cebbfce9e4d9437ace37a5ac327eaee25d (diff)
downloadkube-f6e6cd8a5c8ef2d8d7e331834dff026646be543e.tar.gz
kube-f6e6cd8a5c8ef2d8d7e331834dff026646be543e.zip
Filter enabled folders using a krecursivefilterproxymodel
The KRecursiveFilterProxyModel is necessary until Qt 5.10 when QSortFilterProxyModel will support recursive filtering. For the recursive filtering to work we need to make all data available, so we trigger fetchMore on all added indexes.
Diffstat (limited to 'framework/src/domain')
-rw-r--r--framework/src/domain/folderlistmodel.cpp20
-rw-r--r--framework/src/domain/folderlistmodel.h7
2 files changed, 21 insertions, 6 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 @@
26using namespace Sink; 26using namespace Sink;
27using namespace Sink::ApplicationDomain; 27using namespace Sink::ApplicationDomain;
28 28
29FolderListModel::FolderListModel(QObject *parent) : QSortFilterProxyModel() 29FolderListModel::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
36FolderListModel::~FolderListModel() 45FolderListModel::~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
155bool 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
147void FolderListModel::setFolderId(const QVariant &folderId) 163void FolderListModel::setFolderId(const QVariant &folderId)
148{ 164{
149 const auto folder = folderId.toString().toUtf8(); 165 const auto folder = folderId.toString().toUtf8();
diff --git a/framework/src/domain/folderlistmodel.h b/framework/src/domain/folderlistmodel.h
index 0e412202..738cf4a0 100644
--- a/framework/src/domain/folderlistmodel.h
+++ b/framework/src/domain/folderlistmodel.h
@@ -20,16 +20,14 @@
20 20
21#pragma once 21#pragma once
22 22
23#include <QObject> 23#include <krecursivefilterproxymodel.h>
24#include <QSortFilterProxyModel>
25#include <QSharedPointer> 24#include <QSharedPointer>
26#include <QStringList>
27 25
28namespace Sink { 26namespace Sink {
29 class Query; 27 class Query;
30} 28}
31 29
32class FolderListModel : public QSortFilterProxyModel 30class FolderListModel : public KRecursiveFilterProxyModel
33{ 31{
34 Q_OBJECT 32 Q_OBJECT
35 33
@@ -69,6 +67,7 @@ public:
69 QVariant folderId() const; 67 QVariant folderId() const;
70protected: 68protected:
71 bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE; 69 bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE;
70 bool acceptRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_OVERRIDE;
72 71
73private: 72private:
74 void runQuery(const Sink::Query &query); 73 void runQuery(const Sink::Query &query);