diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-08-05 12:21:13 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-08-06 15:20:46 +0200 |
commit | bbc8fcaefa1cc4c8dafb4d1453990154c7b00d3c (patch) | |
tree | 743018b0719338cf0fc560c2a59ecc2219bb4aed | |
parent | 0d929de1743e9574f7972c9f5b84592202601a00 (diff) | |
download | kube-bbc8fcaefa1cc4c8dafb4d1453990154c7b00d3c.tar.gz kube-bbc8fcaefa1cc4c8dafb4d1453990154c7b00d3c.zip |
A calendar filter
-rw-r--r-- | framework/qml/CheckBox.qml | 2 | ||||
-rw-r--r-- | framework/src/domain/daylongeventmodel.cpp | 15 | ||||
-rw-r--r-- | framework/src/domain/daylongeventmodel.h | 5 | ||||
-rw-r--r-- | framework/src/domain/perioddayeventmodel.cpp | 14 | ||||
-rw-r--r-- | framework/src/domain/perioddayeventmodel.h | 5 | ||||
-rw-r--r-- | framework/src/entitymodel.cpp | 47 | ||||
-rw-r--r-- | framework/src/entitymodel.h | 32 | ||||
-rw-r--r-- | framework/src/frameworkplugin.cpp | 1 | ||||
-rw-r--r-- | views/calendar/qml/View.qml | 7 | ||||
-rw-r--r-- | views/calendar/qml/WeekView.qml | 3 |
10 files changed, 123 insertions, 8 deletions
diff --git a/framework/qml/CheckBox.qml b/framework/qml/CheckBox.qml index 17654536..ce4df209 100644 --- a/framework/qml/CheckBox.qml +++ b/framework/qml/CheckBox.qml | |||
@@ -17,7 +17,7 @@ | |||
17 | */ | 17 | */ |
18 | 18 | ||
19 | import QtQuick 2.7 | 19 | import QtQuick 2.7 |
20 | import QtQuick.Templates 2.0 as T | 20 | import QtQuick.Templates 2.2 as T |
21 | import org.kube.framework 1.0 as Kube | 21 | import org.kube.framework 1.0 as Kube |
22 | 22 | ||
23 | T.CheckBox { | 23 | T.CheckBox { |
diff --git a/framework/src/domain/daylongeventmodel.cpp b/framework/src/domain/daylongeventmodel.cpp index 7775310b..53b50652 100644 --- a/framework/src/domain/daylongeventmodel.cpp +++ b/framework/src/domain/daylongeventmodel.cpp | |||
@@ -99,6 +99,10 @@ bool DayLongEventModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourc | |||
99 | auto idx = sourceModel()->index(sourceRow, 0, sourceParent); | 99 | auto idx = sourceModel()->index(sourceRow, 0, sourceParent); |
100 | auto event = idx.data(Sink::Store::DomainObjectRole).value<Event::Ptr>(); | 100 | auto event = idx.data(Sink::Store::DomainObjectRole).value<Event::Ptr>(); |
101 | 101 | ||
102 | if (!mCalendarFilter.contains(event->getCalendar())) { | ||
103 | return false; | ||
104 | } | ||
105 | |||
102 | auto eventStart = event->getStartTime().date(); | 106 | auto eventStart = event->getStartTime().date(); |
103 | auto eventEnd = event->getEndTime().date(); | 107 | auto eventEnd = event->getEndTime().date(); |
104 | 108 | ||
@@ -141,3 +145,14 @@ void DayLongEventModel::setPeriodLength(int length) | |||
141 | mPeriodLength = length; | 145 | mPeriodLength = length; |
142 | invalidateFilter(); | 146 | invalidateFilter(); |
143 | } | 147 | } |
148 | |||
149 | QSet<QByteArray> DayLongEventModel::calendarFilter() const | ||
150 | { | ||
151 | return mCalendarFilter; | ||
152 | } | ||
153 | |||
154 | void DayLongEventModel::setCalendarFilter(const QSet<QByteArray> &filter) | ||
155 | { | ||
156 | mCalendarFilter = filter; | ||
157 | invalidateFilter(); | ||
158 | } | ||
diff --git a/framework/src/domain/daylongeventmodel.h b/framework/src/domain/daylongeventmodel.h index 12827bef..cd7f4e4b 100644 --- a/framework/src/domain/daylongeventmodel.h +++ b/framework/src/domain/daylongeventmodel.h | |||
@@ -35,6 +35,7 @@ class KUBE_EXPORT DayLongEventModel : public QSortFilterProxyModel | |||
35 | 35 | ||
36 | Q_PROPERTY(QVariant start READ periodStart WRITE setPeriodStart) | 36 | Q_PROPERTY(QVariant start READ periodStart WRITE setPeriodStart) |
37 | Q_PROPERTY(int length READ periodLength WRITE setPeriodLength) | 37 | Q_PROPERTY(int length READ periodLength WRITE setPeriodLength) |
38 | Q_PROPERTY(QSet<QByteArray> calendarFilter READ calendarFilter WRITE setCalendarFilter) | ||
38 | 39 | ||
39 | public: | 40 | public: |
40 | using Event = Sink::ApplicationDomain::Event; | 41 | using Event = Sink::ApplicationDomain::Event; |
@@ -64,11 +65,15 @@ public: | |||
64 | int periodLength() const; | 65 | int periodLength() const; |
65 | void setPeriodLength(int); | 66 | void setPeriodLength(int); |
66 | 67 | ||
68 | QSet<QByteArray> calendarFilter() const; | ||
69 | void setCalendarFilter(const QSet<QByteArray> &); | ||
70 | |||
67 | private: | 71 | private: |
68 | QByteArray getColor(const QByteArray &calendar) const; | 72 | QByteArray getColor(const QByteArray &calendar) const; |
69 | 73 | ||
70 | QSharedPointer<QAbstractItemModel> mModel; | 74 | QSharedPointer<QAbstractItemModel> mModel; |
71 | QSharedPointer<EntityCacheInterface> mCalendarCache; | 75 | QSharedPointer<EntityCacheInterface> mCalendarCache; |
76 | QSet<QByteArray> mCalendarFilter; | ||
72 | 77 | ||
73 | QDate mPeriodStart; | 78 | QDate mPeriodStart; |
74 | int mPeriodLength = 7; | 79 | int mPeriodLength = 7; |
diff --git a/framework/src/domain/perioddayeventmodel.cpp b/framework/src/domain/perioddayeventmodel.cpp index ed853129..149c0fcb 100644 --- a/framework/src/domain/perioddayeventmodel.cpp +++ b/framework/src/domain/perioddayeventmodel.cpp | |||
@@ -83,6 +83,9 @@ void PeriodDayEventModel::partitionData() | |||
83 | SinkWarning() << "Invalid date in the eventModel, ignoring..."; | 83 | SinkWarning() << "Invalid date in the eventModel, ignoring..."; |
84 | continue; | 84 | continue; |
85 | } | 85 | } |
86 | if (!mCalendarFilter.contains(event->getCalendar())) { | ||
87 | continue; | ||
88 | } | ||
86 | 89 | ||
87 | int bucket = bucketOf(eventDate); | 90 | int bucket = bucketOf(eventDate); |
88 | SinkTrace() << "Adding event:" << event->getSummary() << "in bucket #" << bucket; | 91 | SinkTrace() << "Adding event:" << event->getSummary() << "in bucket #" << bucket; |
@@ -322,3 +325,14 @@ void PeriodDayEventModel::setPeriodLength(int length) | |||
322 | mPeriodLength = length; | 325 | mPeriodLength = length; |
323 | updateQuery(); | 326 | updateQuery(); |
324 | } | 327 | } |
328 | |||
329 | QSet<QByteArray> PeriodDayEventModel::calendarFilter() const | ||
330 | { | ||
331 | return mCalendarFilter; | ||
332 | } | ||
333 | |||
334 | void PeriodDayEventModel::setCalendarFilter(const QSet<QByteArray> &filter) | ||
335 | { | ||
336 | mCalendarFilter = filter; | ||
337 | updateQuery(); | ||
338 | } | ||
diff --git a/framework/src/domain/perioddayeventmodel.h b/framework/src/domain/perioddayeventmodel.h index 2d1d0177..2f53486c 100644 --- a/framework/src/domain/perioddayeventmodel.h +++ b/framework/src/domain/perioddayeventmodel.h | |||
@@ -86,6 +86,7 @@ class KUBE_EXPORT PeriodDayEventModel : public QAbstractItemModel | |||
86 | 86 | ||
87 | Q_PROPERTY(QVariant start READ periodStart WRITE setPeriodStart) | 87 | Q_PROPERTY(QVariant start READ periodStart WRITE setPeriodStart) |
88 | Q_PROPERTY(int length READ periodLength WRITE setPeriodLength) | 88 | Q_PROPERTY(int length READ periodLength WRITE setPeriodLength) |
89 | Q_PROPERTY(QSet<QByteArray> calendarFilter READ calendarFilter WRITE setCalendarFilter) | ||
89 | 90 | ||
90 | public: | 91 | public: |
91 | using Event = Sink::ApplicationDomain::Event; | 92 | using Event = Sink::ApplicationDomain::Event; |
@@ -122,6 +123,9 @@ public: | |||
122 | int periodLength() const; | 123 | int periodLength() const; |
123 | void setPeriodLength(int); | 124 | void setPeriodLength(int); |
124 | 125 | ||
126 | QSet<QByteArray> calendarFilter() const; | ||
127 | void setCalendarFilter(const QSet<QByteArray> &); | ||
128 | |||
125 | private: | 129 | private: |
126 | void updateQuery(); | 130 | void updateQuery(); |
127 | void partitionData(); | 131 | void partitionData(); |
@@ -137,6 +141,7 @@ private: | |||
137 | QSharedPointer<QAbstractItemModel> eventModel; | 141 | QSharedPointer<QAbstractItemModel> eventModel; |
138 | QVector<QList<QSharedPointer<Event>>> partitionedEvents; | 142 | QVector<QList<QSharedPointer<Event>>> partitionedEvents; |
139 | QSharedPointer<EntityCacheInterface> mCalendarCache; | 143 | QSharedPointer<EntityCacheInterface> mCalendarCache; |
144 | QSet<QByteArray> mCalendarFilter; | ||
140 | 145 | ||
141 | static const constexpr quintptr DAY_ID = std::numeric_limits<quintptr>::max(); | 146 | static const constexpr quintptr DAY_ID = std::numeric_limits<quintptr>::max(); |
142 | }; | 147 | }; |
diff --git a/framework/src/entitymodel.cpp b/framework/src/entitymodel.cpp index 5a79fdf2..e2a4ea2d 100644 --- a/framework/src/entitymodel.cpp +++ b/framework/src/entitymodel.cpp | |||
@@ -36,7 +36,7 @@ EntityModel::~EntityModel() | |||
36 | 36 | ||
37 | } | 37 | } |
38 | 38 | ||
39 | QHash< int, QByteArray > EntityModel::roleNames() const | 39 | QHash<int, QByteArray> EntityModel::roleNames() const |
40 | { | 40 | { |
41 | return mRoleNames; | 41 | return mRoleNames; |
42 | } | 42 | } |
@@ -152,3 +152,48 @@ QVariantMap EntityModel::data(int row) const | |||
152 | } | 152 | } |
153 | return map; | 153 | return map; |
154 | } | 154 | } |
155 | |||
156 | |||
157 | CheckableEntityModel::CheckableEntityModel(QObject *parent) : EntityModel(parent) | ||
158 | { | ||
159 | } | ||
160 | |||
161 | CheckableEntityModel::~CheckableEntityModel() | ||
162 | { | ||
163 | |||
164 | } | ||
165 | |||
166 | QHash<int, QByteArray > CheckableEntityModel::roleNames() const | ||
167 | { | ||
168 | auto roleNames = EntityModel::roleNames(); | ||
169 | roleNames.insert(Qt::CheckStateRole, "checked"); | ||
170 | return roleNames; | ||
171 | } | ||
172 | |||
173 | QVariant CheckableEntityModel::data(const QModelIndex &index, int role) const | ||
174 | { | ||
175 | if (role == Qt::CheckStateRole) { | ||
176 | const auto identifier = EntityModel::data(index, Qt::UserRole + 1).toByteArray(); | ||
177 | return mCheckedEntities.contains(identifier); | ||
178 | } | ||
179 | return EntityModel::data(index, role); | ||
180 | } | ||
181 | |||
182 | bool CheckableEntityModel::setData(const QModelIndex &index, const QVariant &value, int role) | ||
183 | { | ||
184 | if (role == Qt::CheckStateRole) { | ||
185 | const auto identifier = EntityModel::data(index, Qt::UserRole + 1).toByteArray(); | ||
186 | if (value.toBool()) { | ||
187 | mCheckedEntities.insert(identifier); | ||
188 | } else { | ||
189 | mCheckedEntities.remove(identifier); | ||
190 | } | ||
191 | emit checkedEntitiesChanged(); | ||
192 | } | ||
193 | return EntityModel::setData(index, value, role); | ||
194 | } | ||
195 | |||
196 | QSet<QByteArray> CheckableEntityModel::checkedEntities() const | ||
197 | { | ||
198 | return mCheckedEntities; | ||
199 | } | ||
diff --git a/framework/src/entitymodel.h b/framework/src/entitymodel.h index add66d78..e8c294a0 100644 --- a/framework/src/entitymodel.h +++ b/framework/src/entitymodel.h | |||
@@ -21,6 +21,8 @@ | |||
21 | #include "kube_export.h" | 21 | #include "kube_export.h" |
22 | #include <QSharedPointer> | 22 | #include <QSharedPointer> |
23 | #include <QSortFilterProxyModel> | 23 | #include <QSortFilterProxyModel> |
24 | #include <QSet> | ||
25 | #include <QByteArray> | ||
24 | 26 | ||
25 | namespace Sink { | 27 | namespace Sink { |
26 | class Query; | 28 | class Query; |
@@ -43,13 +45,12 @@ public: | |||
43 | SuccessStatus, | 45 | SuccessStatus, |
44 | }; | 46 | }; |
45 | Q_ENUMS(Status) | 47 | Q_ENUMS(Status) |
46 | |||
47 | EntityModel(QObject *parent = Q_NULLPTR); | 48 | EntityModel(QObject *parent = Q_NULLPTR); |
48 | ~EntityModel(); | 49 | virtual ~EntityModel(); |
49 | 50 | ||
50 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; | 51 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
51 | 52 | ||
52 | QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE; | 53 | virtual QHash<int, QByteArray> roleNames() const override; |
53 | 54 | ||
54 | void setAccountId(const QString &); | 55 | void setAccountId(const QString &); |
55 | QString accountId() const; | 56 | QString accountId() const; |
@@ -74,3 +75,26 @@ private: | |||
74 | QString mAccountId; | 75 | QString mAccountId; |
75 | QString mType; | 76 | QString mType; |
76 | }; | 77 | }; |
78 | |||
79 | |||
80 | class KUBE_EXPORT CheckableEntityModel : public EntityModel { | ||
81 | |||
82 | Q_OBJECT | ||
83 | |||
84 | Q_PROPERTY (QSet<QByteArray> checkedEntities READ checkedEntities NOTIFY checkedEntitiesChanged) | ||
85 | public: | ||
86 | CheckableEntityModel(QObject *parent = Q_NULLPTR); | ||
87 | virtual ~CheckableEntityModel(); | ||
88 | |||
89 | QHash<int, QByteArray> roleNames() const override; | ||
90 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||
91 | bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; | ||
92 | |||
93 | QSet<QByteArray> checkedEntities() const; | ||
94 | |||
95 | signals: | ||
96 | void checkedEntitiesChanged(); | ||
97 | |||
98 | private: | ||
99 | QSet<QByteArray> mCheckedEntities; | ||
100 | }; | ||
diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp index 5fc4eb27..f0261206 100644 --- a/framework/src/frameworkplugin.cpp +++ b/framework/src/frameworkplugin.cpp | |||
@@ -174,6 +174,7 @@ void FrameworkPlugin::registerTypes (const char *uri) | |||
174 | qmlRegisterType<TextDocumentHandler>(uri, 1, 0, "TextDocumentHandler"); | 174 | qmlRegisterType<TextDocumentHandler>(uri, 1, 0, "TextDocumentHandler"); |
175 | qmlRegisterType<LogModel>(uri, 1, 0, "LogModel"); | 175 | qmlRegisterType<LogModel>(uri, 1, 0, "LogModel"); |
176 | qmlRegisterType<EntityModel>(uri, 1, 0, "EntityModel"); | 176 | qmlRegisterType<EntityModel>(uri, 1, 0, "EntityModel"); |
177 | qmlRegisterType<CheckableEntityModel>(uri, 1, 0, "CheckableEntityModel"); | ||
177 | 178 | ||
178 | qmlRegisterType<AccountFactory>(uri, 1, 0, "AccountFactory"); | 179 | qmlRegisterType<AccountFactory>(uri, 1, 0, "AccountFactory"); |
179 | qmlRegisterType<AccountsModel>(uri, 1, 0, "AccountsModel"); | 180 | qmlRegisterType<AccountsModel>(uri, 1, 0, "AccountsModel"); |
diff --git a/views/calendar/qml/View.qml b/views/calendar/qml/View.qml index 3fc5d021..ac446b88 100644 --- a/views/calendar/qml/View.qml +++ b/views/calendar/qml/View.qml | |||
@@ -120,7 +120,8 @@ RowLayout { | |||
120 | } | 120 | } |
121 | spacing: Kube.Units.smallSpacing | 121 | spacing: Kube.Units.smallSpacing |
122 | Repeater { | 122 | Repeater { |
123 | model: Kube.EntityModel { | 123 | model: Kube.CheckableEntityModel { |
124 | id: calendarModel | ||
124 | type: "calendar" | 125 | type: "calendar" |
125 | roles: ["name", "color"] | 126 | roles: ["name", "color"] |
126 | } | 127 | } |
@@ -131,7 +132,8 @@ RowLayout { | |||
131 | spacing: Kube.Units.smallSpacing | 132 | spacing: Kube.Units.smallSpacing |
132 | Kube.CheckBox { | 133 | Kube.CheckBox { |
133 | opacity: 0.9 | 134 | opacity: 0.9 |
134 | checked: true | 135 | checked: model.checked |
136 | onToggled: model.checked = checked | ||
135 | } | 137 | } |
136 | Kube.Label { | 138 | Kube.Label { |
137 | text: model.name | 139 | text: model.name |
@@ -158,5 +160,6 @@ RowLayout { | |||
158 | Layout.fillWidth: true | 160 | Layout.fillWidth: true |
159 | currentDate: root.currentDate | 161 | currentDate: root.currentDate |
160 | startDate: root.selectedDate | 162 | startDate: root.selectedDate |
163 | calendarFilter: calendarModel.checkedEntities | ||
161 | } | 164 | } |
162 | } | 165 | } |
diff --git a/views/calendar/qml/WeekView.qml b/views/calendar/qml/WeekView.qml index 980ec432..2d16b772 100644 --- a/views/calendar/qml/WeekView.qml +++ b/views/calendar/qml/WeekView.qml | |||
@@ -30,6 +30,7 @@ FocusScope { | |||
30 | property var hourHeight: Kube.Units.gridUnit * 2 | 30 | property var hourHeight: Kube.Units.gridUnit * 2 |
31 | property date currentDate | 31 | property date currentDate |
32 | property date startDate: currentDate | 32 | property date startDate: currentDate |
33 | property var calendarFilter | ||
33 | 34 | ||
34 | Item { | 35 | Item { |
35 | anchors { | 36 | anchors { |
@@ -94,6 +95,7 @@ FocusScope { | |||
94 | model: Kube.DayLongEventModel { | 95 | model: Kube.DayLongEventModel { |
95 | start: root.startDate | 96 | start: root.startDate |
96 | length: root.daysToShow | 97 | length: root.daysToShow |
98 | calendarFilter: root.calendarFilter | ||
97 | } | 99 | } |
98 | 100 | ||
99 | delegate: Item { | 101 | delegate: Item { |
@@ -181,6 +183,7 @@ FocusScope { | |||
181 | model: Kube.PeriodDayEventModel { | 183 | model: Kube.PeriodDayEventModel { |
182 | start: root.startDate | 184 | start: root.startDate |
183 | length: root.daysToShow | 185 | length: root.daysToShow |
186 | calendarFilter: root.calendarFilter | ||
184 | } | 187 | } |
185 | delegate: Rectangle { | 188 | delegate: Rectangle { |
186 | id: dayDelegate | 189 | id: dayDelegate |