diff options
author | Minijackson <minijackson@riseup.net> | 2018-05-14 16:19:43 +0200 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2018-05-15 11:36:32 +0200 |
commit | b234c6c74ba76e8d58ab9a55ab1054eb761697e1 (patch) | |
tree | 116d2ec96bb51919ae7c1c274b31178f1faf059b | |
parent | d353ec997f06891455dce9b51333687da670a03e (diff) | |
download | kube-b234c6c74ba76e8d58ab9a55ab1054eb761697e1.tar.gz kube-b234c6c74ba76e8d58ab9a55ab1054eb761697e1.zip |
Implement DayLongEventModel and integrate it to calendar
-rw-r--r-- | framework/src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | framework/src/domain/daylongeventmodel.cpp | 123 | ||||
-rw-r--r-- | framework/src/domain/daylongeventmodel.h | 69 | ||||
-rw-r--r-- | framework/src/domain/perioddayeventmodel.cpp | 2 | ||||
-rw-r--r-- | framework/src/domain/perioddayeventmodel.h | 2 | ||||
-rw-r--r-- | framework/src/frameworkplugin.cpp | 2 | ||||
-rw-r--r-- | tests/teststore.cpp | 4 | ||||
-rw-r--r-- | views/calendar/main.qml | 59 | ||||
-rw-r--r-- | views/calendar/qml/DaylongEvents.qml | 18 | ||||
-rw-r--r-- | views/calendar/qml/WeekView.qml | 5 |
10 files changed, 269 insertions, 16 deletions
diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt index d80fe284..fab7bf20 100644 --- a/framework/src/CMakeLists.txt +++ b/framework/src/CMakeLists.txt | |||
@@ -20,6 +20,7 @@ add_library(kubeframework SHARED | |||
20 | domain/maillistmodel.cpp | 20 | domain/maillistmodel.cpp |
21 | domain/folderlistmodel.cpp | 21 | domain/folderlistmodel.cpp |
22 | domain/perioddayeventmodel.cpp | 22 | domain/perioddayeventmodel.cpp |
23 | domain/daylongeventmodel.cpp | ||
23 | domain/composercontroller.cpp | 24 | domain/composercontroller.cpp |
24 | domain/modeltest.cpp | 25 | domain/modeltest.cpp |
25 | domain/retriever.cpp | 26 | domain/retriever.cpp |
diff --git a/framework/src/domain/daylongeventmodel.cpp b/framework/src/domain/daylongeventmodel.cpp new file mode 100644 index 00000000..c6d5776e --- /dev/null +++ b/framework/src/domain/daylongeventmodel.cpp | |||
@@ -0,0 +1,123 @@ | |||
1 | /* | ||
2 | Copyright (c) 2018 Michael Bohlender <michael.bohlender@kdemail.net> | ||
3 | Copyright (c) 2018 Christian Mollekopf <mollekopf@kolabsys.com> | ||
4 | Copyright (c) 2018 Rémi Nicole <minijackson@riseup.net> | ||
5 | |||
6 | This library is free software; you can redistribute it and/or modify it | ||
7 | under the terms of the GNU Library General Public License as published by | ||
8 | the Free Software Foundation; either version 2 of the License, or (at your | ||
9 | option) any later version. | ||
10 | |||
11 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
14 | License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Library General Public License | ||
17 | along with this library; see the file COPYING.LIB. If not, write to the | ||
18 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
19 | 02110-1301, USA. | ||
20 | */ | ||
21 | |||
22 | #include "daylongeventmodel.h" | ||
23 | |||
24 | #include <sink/log.h> | ||
25 | #include <sink/query.h> | ||
26 | #include <sink/store.h> | ||
27 | |||
28 | DayLongEventModel::DayLongEventModel(QObject *parent) : QSortFilterProxyModel(parent) | ||
29 | { | ||
30 | Sink::Query query; | ||
31 | query.setFlags(Sink::Query::LiveQuery); | ||
32 | query.request<Event::Summary>(); | ||
33 | query.request<Event::Description>(); | ||
34 | query.request<Event::StartTime>(); | ||
35 | query.request<Event::EndTime>(); | ||
36 | |||
37 | query.filter<Event::AllDay>(true); | ||
38 | |||
39 | eventModel = Sink::Store::loadModel<Event>(query); | ||
40 | |||
41 | setSourceModel(eventModel.data()); | ||
42 | } | ||
43 | |||
44 | QHash<int, QByteArray> DayLongEventModel::roleNames() const | ||
45 | { | ||
46 | return { | ||
47 | {Summary, "summary"}, | ||
48 | {Description, "description"}, | ||
49 | {StartDate, "starts"}, | ||
50 | {Duration, "duration"}, | ||
51 | }; | ||
52 | } | ||
53 | |||
54 | QVariant DayLongEventModel::data(const QModelIndex &idx, int role) const | ||
55 | { | ||
56 | auto srcIdx = mapToSource(idx); | ||
57 | auto event = srcIdx.data(Sink::Store::DomainObjectRole).value<Event::Ptr>(); | ||
58 | |||
59 | switch (role) { | ||
60 | case Summary: | ||
61 | return event->getSummary(); | ||
62 | case Description: | ||
63 | return event->getDescription(); | ||
64 | case StartDate: { | ||
65 | auto dayIndex = mPeriodStart.daysTo(event->getStartTime().date()); | ||
66 | if (dayIndex < 0) { | ||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | return dayIndex; | ||
71 | } | ||
72 | case Duration: | ||
73 | return event->getStartTime().date().daysTo(event->getEndTime().date()); | ||
74 | } | ||
75 | |||
76 | return QSortFilterProxyModel::data(idx, role); | ||
77 | } | ||
78 | |||
79 | bool DayLongEventModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const | ||
80 | { | ||
81 | auto idx = sourceModel()->index(sourceRow, 0, sourceParent); | ||
82 | auto event = idx.data(Sink::Store::DomainObjectRole).value<Event::Ptr>(); | ||
83 | |||
84 | auto eventStart = event->getStartTime().date(); | ||
85 | auto eventEnd = event->getEndTime().date(); | ||
86 | |||
87 | if (!eventStart.isValid() || !eventEnd.isValid()) { | ||
88 | SinkWarning() << "Invalid date in the eventModel, ignoring..."; | ||
89 | return false; | ||
90 | } | ||
91 | |||
92 | return eventStart < mPeriodStart.addDays(mPeriodLength) && eventEnd >= mPeriodStart; | ||
93 | } | ||
94 | |||
95 | QDate DayLongEventModel::periodStart() const | ||
96 | { | ||
97 | return mPeriodStart; | ||
98 | } | ||
99 | |||
100 | void DayLongEventModel::setPeriodStart(const QDate &start) | ||
101 | { | ||
102 | if (!start.isValid()) { | ||
103 | SinkWarning() << "Passed an invalid starting date in setPeriodStart, ignoring..."; | ||
104 | return; | ||
105 | } | ||
106 | |||
107 | mPeriodStart = start; | ||
108 | } | ||
109 | |||
110 | void DayLongEventModel::setPeriodStart(const QVariant &start) | ||
111 | { | ||
112 | setPeriodStart(start.toDate()); | ||
113 | } | ||
114 | |||
115 | int DayLongEventModel::periodLength() const | ||
116 | { | ||
117 | return mPeriodLength; | ||
118 | } | ||
119 | |||
120 | void DayLongEventModel::setPeriodLength(int length) | ||
121 | { | ||
122 | mPeriodLength = length; | ||
123 | } | ||
diff --git a/framework/src/domain/daylongeventmodel.h b/framework/src/domain/daylongeventmodel.h new file mode 100644 index 00000000..a4a291df --- /dev/null +++ b/framework/src/domain/daylongeventmodel.h | |||
@@ -0,0 +1,69 @@ | |||
1 | /* | ||
2 | Copyright (c) 2018 Michael Bohlender <michael.bohlender@kdemail.net> | ||
3 | Copyright (c) 2018 Christian Mollekopf <mollekopf@kolabsys.com> | ||
4 | Copyright (c) 2018 Rémi Nicole <minijackson@riseup.net> | ||
5 | |||
6 | This library is free software; you can redistribute it and/or modify it | ||
7 | under the terms of the GNU Library General Public License as published by | ||
8 | the Free Software Foundation; either version 2 of the License, or (at your | ||
9 | option) any later version. | ||
10 | |||
11 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
14 | License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU Library General Public License | ||
17 | along with this library; see the file COPYING.LIB. If not, write to the | ||
18 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
19 | 02110-1301, USA. | ||
20 | */ | ||
21 | |||
22 | #pragma once | ||
23 | #include "kube_export.h" | ||
24 | #include <sink/applicationdomaintype.h> | ||
25 | |||
26 | #include <QList> | ||
27 | #include <QSharedPointer> | ||
28 | #include <QSortFilterProxyModel> | ||
29 | #include <QVector> | ||
30 | |||
31 | class KUBE_EXPORT DayLongEventModel : public QSortFilterProxyModel | ||
32 | { | ||
33 | Q_OBJECT | ||
34 | |||
35 | Q_PROPERTY(QVariant start READ periodStart WRITE setPeriodStart) | ||
36 | Q_PROPERTY(int length READ periodLength WRITE setPeriodLength) | ||
37 | |||
38 | public: | ||
39 | using Event = Sink::ApplicationDomain::Event; | ||
40 | |||
41 | enum Roles | ||
42 | { | ||
43 | Summary = Qt::UserRole + 1, | ||
44 | Description, | ||
45 | StartDate, | ||
46 | Duration, | ||
47 | }; | ||
48 | Q_ENUM(Roles); | ||
49 | |||
50 | DayLongEventModel(QObject *parent = nullptr); | ||
51 | ~DayLongEventModel() = default; | ||
52 | |||
53 | QHash<int, QByteArray> roleNames() const override; | ||
54 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||
55 | |||
56 | bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; | ||
57 | |||
58 | QDate periodStart() const; | ||
59 | void setPeriodStart(const QDate &); | ||
60 | void setPeriodStart(const QVariant &); | ||
61 | int periodLength() const; | ||
62 | void setPeriodLength(int); | ||
63 | |||
64 | private: | ||
65 | QSharedPointer<QAbstractItemModel> eventModel; | ||
66 | |||
67 | QDate mPeriodStart; | ||
68 | int mPeriodLength = 7; | ||
69 | }; | ||
diff --git a/framework/src/domain/perioddayeventmodel.cpp b/framework/src/domain/perioddayeventmodel.cpp index 637e5584..827b4d4f 100644 --- a/framework/src/domain/perioddayeventmodel.cpp +++ b/framework/src/domain/perioddayeventmodel.cpp | |||
@@ -39,6 +39,8 @@ PeriodDayEventModel::PeriodDayEventModel(QObject *parent) | |||
39 | query.request<Event::StartTime>(); | 39 | query.request<Event::StartTime>(); |
40 | query.request<Event::EndTime>(); | 40 | query.request<Event::EndTime>(); |
41 | 41 | ||
42 | query.filter<Event::AllDay>(false); | ||
43 | |||
42 | eventModel = Sink::Store::loadModel<Event>(query); | 44 | eventModel = Sink::Store::loadModel<Event>(query); |
43 | 45 | ||
44 | QObject::connect(eventModel.data(), &QAbstractItemModel::dataChanged, this, &PeriodDayEventModel::partitionData); | 46 | QObject::connect(eventModel.data(), &QAbstractItemModel::dataChanged, this, &PeriodDayEventModel::partitionData); |
diff --git a/framework/src/domain/perioddayeventmodel.h b/framework/src/domain/perioddayeventmodel.h index ab04df50..9458fc03 100644 --- a/framework/src/domain/perioddayeventmodel.h +++ b/framework/src/domain/perioddayeventmodel.h | |||
@@ -33,6 +33,8 @@ | |||
33 | // Facility used to get a restricted period into a Sink model comprised of | 33 | // Facility used to get a restricted period into a Sink model comprised of |
34 | // events, partitioned according to the day the events take place. | 34 | // events, partitioned according to the day the events take place. |
35 | // | 35 | // |
36 | // Day-long events are filtered out. | ||
37 | // | ||
36 | // Model Format | 38 | // Model Format |
37 | // ============ | 39 | // ============ |
38 | // | 40 | // |
diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp index 2eb53237..91d7a5dd 100644 --- a/framework/src/frameworkplugin.cpp +++ b/framework/src/frameworkplugin.cpp | |||
@@ -23,6 +23,7 @@ | |||
23 | #include "domain/maillistmodel.h" | 23 | #include "domain/maillistmodel.h" |
24 | #include "domain/folderlistmodel.h" | 24 | #include "domain/folderlistmodel.h" |
25 | #include "domain/perioddayeventmodel.h" | 25 | #include "domain/perioddayeventmodel.h" |
26 | #include "domain/daylongeventmodel.h" | ||
26 | #include "domain/composercontroller.h" | 27 | #include "domain/composercontroller.h" |
27 | #include "domain/mime/messageparser.h" | 28 | #include "domain/mime/messageparser.h" |
28 | #include "domain/retriever.h" | 29 | #include "domain/retriever.h" |
@@ -122,6 +123,7 @@ void FrameworkPlugin::registerTypes (const char *uri) | |||
122 | qmlRegisterType<FolderListModel>(uri, 1, 0, "FolderListModel"); | 123 | qmlRegisterType<FolderListModel>(uri, 1, 0, "FolderListModel"); |
123 | qmlRegisterType<MailListModel>(uri, 1, 0, "MailListModel"); | 124 | qmlRegisterType<MailListModel>(uri, 1, 0, "MailListModel"); |
124 | qmlRegisterType<PeriodDayEventModel>(uri, 1, 0, "PeriodDayEventModel"); | 125 | qmlRegisterType<PeriodDayEventModel>(uri, 1, 0, "PeriodDayEventModel"); |
126 | qmlRegisterType<DayLongEventModel>(uri, 1, 0, "DayLongEventModel"); | ||
125 | qmlRegisterType<ComposerController>(uri, 1, 0, "ComposerController"); | 127 | qmlRegisterType<ComposerController>(uri, 1, 0, "ComposerController"); |
126 | qmlRegisterType<Kube::ControllerAction>(uri, 1, 0, "ControllerAction"); | 128 | qmlRegisterType<Kube::ControllerAction>(uri, 1, 0, "ControllerAction"); |
127 | qmlRegisterType<MessageParser>(uri, 1, 0, "MessageParser"); | 129 | qmlRegisterType<MessageParser>(uri, 1, 0, "MessageParser"); |
diff --git a/tests/teststore.cpp b/tests/teststore.cpp index 3a60676d..73e34101 100644 --- a/tests/teststore.cpp +++ b/tests/teststore.cpp | |||
@@ -160,6 +160,10 @@ static void createEvent(const QVariantMap &object, const QByteArray &calendarId | |||
160 | calcoreEvent->setDtStart(startTime); | 160 | calcoreEvent->setDtStart(startTime); |
161 | calcoreEvent->setDtEnd(endTime); | 161 | calcoreEvent->setDtEnd(endTime); |
162 | 162 | ||
163 | if (object.contains("allDay")) { | ||
164 | calcoreEvent->setAllDay(object["allDay"].toBool()); | ||
165 | } | ||
166 | |||
163 | auto ical = KCalCore::ICalFormat().toICalString(calcoreEvent); | 167 | auto ical = KCalCore::ICalFormat().toICalString(calcoreEvent); |
164 | sinkEvent.setIcal(ical.toUtf8()); | 168 | sinkEvent.setIcal(ical.toUtf8()); |
165 | 169 | ||
diff --git a/views/calendar/main.qml b/views/calendar/main.qml index 26898685..e3915e74 100644 --- a/views/calendar/main.qml +++ b/views/calendar/main.qml | |||
@@ -74,10 +74,67 @@ ApplicationWindow { | |||
74 | { | 74 | { |
75 | resource: "caldavresource", | 75 | resource: "caldavresource", |
76 | summary: "Test Event4", | 76 | summary: "Test Event4", |
77 | description: "This is test event #3", | 77 | description: "This is test event #4", |
78 | starts: "2018-04-12T22:00:00", | 78 | starts: "2018-04-12T22:00:00", |
79 | ends: "2018-04-15T03:00:00", | 79 | ends: "2018-04-15T03:00:00", |
80 | }, | 80 | }, |
81 | { | ||
82 | resource: "caldavresource", | ||
83 | summary: "!!! Test Event5", | ||
84 | description: "!!! This is test event #5", | ||
85 | starts: "2018-04-22T22:00:00", | ||
86 | ends: "2018-04-25T03:00:00", | ||
87 | }, | ||
88 | |||
89 | // Day-long events | ||
90 | { | ||
91 | resource: "caldavresource", | ||
92 | summary: "Test day-long event1", | ||
93 | description: "This is test day-long event #1", | ||
94 | starts: "2018-04-10T00:00:00", | ||
95 | ends: "2018-04-14T00:00:00", | ||
96 | allDay: true, | ||
97 | }, | ||
98 | { | ||
99 | resource: "caldavresource", | ||
100 | summary: "Test day-long event2", | ||
101 | description: "This is test day-long event #2", | ||
102 | starts: "2018-04-11T00:00:00", | ||
103 | ends: "2018-04-23T00:00:00", | ||
104 | allDay: true, | ||
105 | }, | ||
106 | { | ||
107 | resource: "caldavresource", | ||
108 | summary: "Test day-long event3", | ||
109 | description: "This is test day-long event #3", | ||
110 | starts: "2018-04-01T00:00:00", | ||
111 | ends: "2018-04-13T00:00:00", | ||
112 | allDay: true, | ||
113 | }, | ||
114 | { | ||
115 | resource: "caldavresource", | ||
116 | summary: "Test day-long event4", | ||
117 | description: "This is test day-long event #4", | ||
118 | starts: "2018-04-01T00:00:00", | ||
119 | ends: "2018-04-25T00:00:00", | ||
120 | allDay: true, | ||
121 | }, | ||
122 | { | ||
123 | resource: "caldavresource", | ||
124 | summary: "!!! Test day-long event5", | ||
125 | description: "!!! This is test day-long event #5", | ||
126 | starts: "2018-04-01T00:00:00", | ||
127 | ends: "2018-04-05T00:00:00", | ||
128 | allDay: true, | ||
129 | }, | ||
130 | { | ||
131 | resource: "caldavresource", | ||
132 | summary: "!!! Test day-long event6", | ||
133 | description: "!!! This is test day-long event #6", | ||
134 | starts: "2018-04-23T00:00:00", | ||
135 | ends: "2018-04-25T00:00:00", | ||
136 | allDay: true, | ||
137 | }, | ||
81 | ], | 138 | ], |
82 | }], | 139 | }], |
83 | } | 140 | } |
diff --git a/views/calendar/qml/DaylongEvents.qml b/views/calendar/qml/DaylongEvents.qml index 340c9d79..a07b66dd 100644 --- a/views/calendar/qml/DaylongEvents.qml +++ b/views/calendar/qml/DaylongEvents.qml | |||
@@ -1,16 +1,8 @@ | |||
1 | import QtQuick 2.7 | 1 | import QtQuick 2.7 |
2 | 2 | ||
3 | ListModel { | 3 | import org.kube.framework 1.0 as Kube |
4 | ListElement { | 4 | |
5 | color: "#af1a6a" | 5 | Kube.DayLongEventModel { |
6 | starts: 1 | 6 | start: "2018-04-09" |
7 | duration: 4 | 7 | length: 7 |
8 | text: "Baustelle Adalbertstr." | ||
9 | } | ||
10 | ListElement { | ||
11 | color: "#134bab" | ||
12 | starts: 0 | ||
13 | duration: 6 | ||
14 | text: "Urlaub" | ||
15 | } | ||
16 | } | 8 | } |
diff --git a/views/calendar/qml/WeekView.qml b/views/calendar/qml/WeekView.qml index f798e489..5272e6a4 100644 --- a/views/calendar/qml/WeekView.qml +++ b/views/calendar/qml/WeekView.qml | |||
@@ -97,7 +97,8 @@ FocusScope { | |||
97 | width: root.dayWidth * model.duration | 97 | width: root.dayWidth * model.duration |
98 | height: parent.height | 98 | height: parent.height |
99 | x: root.dayWidth * model.starts | 99 | x: root.dayWidth * model.starts |
100 | color: model.color | 100 | //color: model.color |
101 | color: "#af1a6a" | ||
101 | border.width: 1 | 102 | border.width: 1 |
102 | border.color: Kube.Colors.viewBackgroundColor | 103 | border.color: Kube.Colors.viewBackgroundColor |
103 | 104 | ||
@@ -107,7 +108,7 @@ FocusScope { | |||
107 | leftMargin: Kube.Units.smallSpacing | 108 | leftMargin: Kube.Units.smallSpacing |
108 | } | 109 | } |
109 | color: Kube.Colors.highlightedTextColor | 110 | color: Kube.Colors.highlightedTextColor |
110 | text: model.text | 111 | text: model.summary |
111 | } | 112 | } |
112 | } | 113 | } |
113 | } | 114 | } |