diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-08-03 13:49:56 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-08-03 13:56:58 +0200 |
commit | 2085b83960cbb8e4693cf48a5bd265aa946256de (patch) | |
tree | 58f5d6f7ff18cd63ac0aa8827dadfbb66e269083 /framework/src/domain | |
parent | 064367aec304708591f5cd4d010ed462119a0323 (diff) | |
download | kube-2085b83960cbb8e4693cf48a5bd265aa946256de.tar.gz kube-2085b83960cbb8e4693cf48a5bd265aa946256de.zip |
Weekview with calendar colors
Diffstat (limited to 'framework/src/domain')
-rw-r--r-- | framework/src/domain/daylongeventmodel.cpp | 13 | ||||
-rw-r--r-- | framework/src/domain/daylongeventmodel.h | 6 | ||||
-rw-r--r-- | framework/src/domain/perioddayeventmodel.cpp | 15 | ||||
-rw-r--r-- | framework/src/domain/perioddayeventmodel.h | 6 |
4 files changed, 39 insertions, 1 deletions
diff --git a/framework/src/domain/daylongeventmodel.cpp b/framework/src/domain/daylongeventmodel.cpp index 0ea73709..1b47edda 100644 --- a/framework/src/domain/daylongeventmodel.cpp +++ b/framework/src/domain/daylongeventmodel.cpp | |||
@@ -25,6 +25,8 @@ | |||
25 | #include <sink/query.h> | 25 | #include <sink/query.h> |
26 | #include <sink/store.h> | 26 | #include <sink/store.h> |
27 | 27 | ||
28 | #include "entitycache.h" | ||
29 | |||
28 | DayLongEventModel::DayLongEventModel(QObject *parent) : QSortFilterProxyModel(parent) | 30 | DayLongEventModel::DayLongEventModel(QObject *parent) : QSortFilterProxyModel(parent) |
29 | { | 31 | { |
30 | Sink::Query query; | 32 | Sink::Query query; |
@@ -33,11 +35,14 @@ DayLongEventModel::DayLongEventModel(QObject *parent) : QSortFilterProxyModel(pa | |||
33 | query.request<Event::Description>(); | 35 | query.request<Event::Description>(); |
34 | query.request<Event::StartTime>(); | 36 | query.request<Event::StartTime>(); |
35 | query.request<Event::EndTime>(); | 37 | query.request<Event::EndTime>(); |
38 | query.request<Event::Calendar>(); | ||
36 | 39 | ||
37 | query.filter<Event::AllDay>(true); | 40 | query.filter<Event::AllDay>(true); |
38 | 41 | ||
39 | mModel = Sink::Store::loadModel<Event>(query); | 42 | mModel = Sink::Store::loadModel<Event>(query); |
40 | 43 | ||
44 | mCalendarCache = EntityCache<Calendar, Calendar::Color>::Ptr::create(); | ||
45 | |||
41 | setSourceModel(mModel.data()); | 46 | setSourceModel(mModel.data()); |
42 | } | 47 | } |
43 | 48 | ||
@@ -48,9 +53,15 @@ QHash<int, QByteArray> DayLongEventModel::roleNames() const | |||
48 | {Description, "description"}, | 53 | {Description, "description"}, |
49 | {StartDate, "starts"}, | 54 | {StartDate, "starts"}, |
50 | {Duration, "duration"}, | 55 | {Duration, "duration"}, |
56 | {Color, "color"}, | ||
51 | }; | 57 | }; |
52 | } | 58 | } |
53 | 59 | ||
60 | QByteArray DayLongEventModel::getColor(const QByteArray &calendar) const | ||
61 | { | ||
62 | return mCalendarCache->getProperty(calendar, "color").toByteArray(); | ||
63 | } | ||
64 | |||
54 | QVariant DayLongEventModel::data(const QModelIndex &idx, int role) const | 65 | QVariant DayLongEventModel::data(const QModelIndex &idx, int role) const |
55 | { | 66 | { |
56 | auto srcIdx = mapToSource(idx); | 67 | auto srcIdx = mapToSource(idx); |
@@ -71,6 +82,8 @@ QVariant DayLongEventModel::data(const QModelIndex &idx, int role) const | |||
71 | } | 82 | } |
72 | case Duration: | 83 | case Duration: |
73 | return event->getStartTime().date().daysTo(event->getEndTime().date()); | 84 | return event->getStartTime().date().daysTo(event->getEndTime().date()); |
85 | case Color: | ||
86 | return getColor(event->getCalendar()); | ||
74 | } | 87 | } |
75 | 88 | ||
76 | return QSortFilterProxyModel::data(idx, role); | 89 | return QSortFilterProxyModel::data(idx, role); |
diff --git a/framework/src/domain/daylongeventmodel.h b/framework/src/domain/daylongeventmodel.h index 21bcbfba..12827bef 100644 --- a/framework/src/domain/daylongeventmodel.h +++ b/framework/src/domain/daylongeventmodel.h | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <QSortFilterProxyModel> | 28 | #include <QSortFilterProxyModel> |
29 | #include <QVector> | 29 | #include <QVector> |
30 | 30 | ||
31 | class EntityCacheInterface; | ||
31 | class KUBE_EXPORT DayLongEventModel : public QSortFilterProxyModel | 32 | class KUBE_EXPORT DayLongEventModel : public QSortFilterProxyModel |
32 | { | 33 | { |
33 | Q_OBJECT | 34 | Q_OBJECT |
@@ -37,6 +38,7 @@ class KUBE_EXPORT DayLongEventModel : public QSortFilterProxyModel | |||
37 | 38 | ||
38 | public: | 39 | public: |
39 | using Event = Sink::ApplicationDomain::Event; | 40 | using Event = Sink::ApplicationDomain::Event; |
41 | using Calendar = Sink::ApplicationDomain::Calendar; | ||
40 | 42 | ||
41 | enum Roles | 43 | enum Roles |
42 | { | 44 | { |
@@ -44,6 +46,7 @@ public: | |||
44 | Description, | 46 | Description, |
45 | StartDate, | 47 | StartDate, |
46 | Duration, | 48 | Duration, |
49 | Color | ||
47 | }; | 50 | }; |
48 | Q_ENUM(Roles); | 51 | Q_ENUM(Roles); |
49 | 52 | ||
@@ -62,7 +65,10 @@ public: | |||
62 | void setPeriodLength(int); | 65 | void setPeriodLength(int); |
63 | 66 | ||
64 | private: | 67 | private: |
68 | QByteArray getColor(const QByteArray &calendar) const; | ||
69 | |||
65 | QSharedPointer<QAbstractItemModel> mModel; | 70 | QSharedPointer<QAbstractItemModel> mModel; |
71 | QSharedPointer<EntityCacheInterface> mCalendarCache; | ||
66 | 72 | ||
67 | QDate mPeriodStart; | 73 | QDate mPeriodStart; |
68 | int mPeriodLength = 7; | 74 | int mPeriodLength = 7; |
diff --git a/framework/src/domain/perioddayeventmodel.cpp b/framework/src/domain/perioddayeventmodel.cpp index c5f2c197..4463e252 100644 --- a/framework/src/domain/perioddayeventmodel.cpp +++ b/framework/src/domain/perioddayeventmodel.cpp | |||
@@ -29,6 +29,8 @@ | |||
29 | #include <QJsonObject> | 29 | #include <QJsonObject> |
30 | #include <QMetaEnum> | 30 | #include <QMetaEnum> |
31 | 31 | ||
32 | #include <entitycache.h> | ||
33 | |||
32 | PeriodDayEventModel::PeriodDayEventModel(QObject *parent) | 34 | PeriodDayEventModel::PeriodDayEventModel(QObject *parent) |
33 | : QAbstractItemModel(parent), partitionedEvents(7) | 35 | : QAbstractItemModel(parent), partitionedEvents(7) |
34 | { | 36 | { |
@@ -43,6 +45,7 @@ void PeriodDayEventModel::updateQuery() | |||
43 | query.request<Event::Description>(); | 45 | query.request<Event::Description>(); |
44 | query.request<Event::StartTime>(); | 46 | query.request<Event::StartTime>(); |
45 | query.request<Event::EndTime>(); | 47 | query.request<Event::EndTime>(); |
48 | query.request<Event::Calendar>(); | ||
46 | 49 | ||
47 | auto periodEnd = mPeriodStart.addDays(mPeriodLength); | 50 | auto periodEnd = mPeriodStart.addDays(mPeriodLength); |
48 | 51 | ||
@@ -59,6 +62,8 @@ void PeriodDayEventModel::updateQuery() | |||
59 | QObject::connect(eventModel.data(), &QAbstractItemModel::rowsMoved, this, &PeriodDayEventModel::partitionData); | 62 | QObject::connect(eventModel.data(), &QAbstractItemModel::rowsMoved, this, &PeriodDayEventModel::partitionData); |
60 | QObject::connect(eventModel.data(), &QAbstractItemModel::rowsRemoved, this, &PeriodDayEventModel::partitionData); | 63 | QObject::connect(eventModel.data(), &QAbstractItemModel::rowsRemoved, this, &PeriodDayEventModel::partitionData); |
61 | 64 | ||
65 | mCalendarCache = EntityCache<Calendar, Calendar::Color>::Ptr::create(); | ||
66 | |||
62 | partitionData(); | 67 | partitionData(); |
63 | } | 68 | } |
64 | 69 | ||
@@ -157,6 +162,11 @@ int PeriodDayEventModel::columnCount(const QModelIndex &parent) const | |||
157 | return eventModel->columnCount(); | 162 | return eventModel->columnCount(); |
158 | } | 163 | } |
159 | 164 | ||
165 | QByteArray PeriodDayEventModel::getColor(const QByteArray &calendar) const | ||
166 | { | ||
167 | return mCalendarCache->getProperty(calendar, "color").toByteArray(); | ||
168 | } | ||
169 | |||
160 | QVariant PeriodDayEventModel::data(const QModelIndex &id, int role) const | 170 | QVariant PeriodDayEventModel::data(const QModelIndex &id, int role) const |
161 | { | 171 | { |
162 | if (id.internalId() == DAY_ID) { | 172 | if (id.internalId() == DAY_ID) { |
@@ -184,7 +194,7 @@ QVariant PeriodDayEventModel::data(const QModelIndex &id, int role) const | |||
184 | {"description", data(eventId, Description)}, | 194 | {"description", data(eventId, Description)}, |
185 | {"starts", startTime.hour() + startTime.minute() / 60.}, | 195 | {"starts", startTime.hour() + startTime.minute() / 60.}, |
186 | {"duration", data(eventId, Duration)}, | 196 | {"duration", data(eventId, Duration)}, |
187 | {"color", "#134bab"}, | 197 | {"color", data(eventId, Color)}, |
188 | {"indention", 0}, | 198 | {"indention", 0}, |
189 | }); | 199 | }); |
190 | } | 200 | } |
@@ -213,6 +223,8 @@ QVariant PeriodDayEventModel::data(const QModelIndex &id, int role) const | |||
213 | auto end = event->getEndTime(); | 223 | auto end = event->getEndTime(); |
214 | return start.secsTo(end) / 3600; | 224 | return start.secsTo(end) / 3600; |
215 | } | 225 | } |
226 | case Color: | ||
227 | return getColor(event->getCalendar()); | ||
216 | default: | 228 | default: |
217 | SinkWarning() << "Unknown role for event:" << QMetaEnum::fromType<Roles>().valueToKey(role); | 229 | SinkWarning() << "Unknown role for event:" << QMetaEnum::fromType<Roles>().valueToKey(role); |
218 | return {}; | 230 | return {}; |
@@ -229,6 +241,7 @@ QHash<int, QByteArray> PeriodDayEventModel::roleNames() const | |||
229 | {Description, "description"}, | 241 | {Description, "description"}, |
230 | {StartTime, "starts"}, | 242 | {StartTime, "starts"}, |
231 | {Duration, "duration"}, | 243 | {Duration, "duration"}, |
244 | {Color, "color"} | ||
232 | }; | 245 | }; |
233 | } | 246 | } |
234 | 247 | ||
diff --git a/framework/src/domain/perioddayeventmodel.h b/framework/src/domain/perioddayeventmodel.h index a7d9cea8..a0410e2e 100644 --- a/framework/src/domain/perioddayeventmodel.h +++ b/framework/src/domain/perioddayeventmodel.h | |||
@@ -78,6 +78,8 @@ | |||
78 | // | '--- List of event pointers for that day | 78 | // | '--- List of event pointers for that day |
79 | // '--- Partition / day | 79 | // '--- Partition / day |
80 | // | 80 | // |
81 | |||
82 | class EntityCacheInterface; | ||
81 | class KUBE_EXPORT PeriodDayEventModel : public QAbstractItemModel | 83 | class KUBE_EXPORT PeriodDayEventModel : public QAbstractItemModel |
82 | { | 84 | { |
83 | Q_OBJECT | 85 | Q_OBJECT |
@@ -87,6 +89,7 @@ class KUBE_EXPORT PeriodDayEventModel : public QAbstractItemModel | |||
87 | 89 | ||
88 | public: | 90 | public: |
89 | using Event = Sink::ApplicationDomain::Event; | 91 | using Event = Sink::ApplicationDomain::Event; |
92 | using Calendar = Sink::ApplicationDomain::Calendar; | ||
90 | 93 | ||
91 | enum Roles | 94 | enum Roles |
92 | { | 95 | { |
@@ -96,6 +99,7 @@ public: | |||
96 | Description, | 99 | Description, |
97 | StartTime, | 100 | StartTime, |
98 | Duration, | 101 | Duration, |
102 | Color | ||
99 | }; | 103 | }; |
100 | Q_ENUM(Roles); | 104 | Q_ENUM(Roles); |
101 | PeriodDayEventModel(QObject *parent = nullptr); | 105 | PeriodDayEventModel(QObject *parent = nullptr); |
@@ -120,6 +124,7 @@ public: | |||
120 | private: | 124 | private: |
121 | void updateQuery(); | 125 | void updateQuery(); |
122 | void partitionData(); | 126 | void partitionData(); |
127 | QByteArray getColor(const QByteArray &calendar) const; | ||
123 | 128 | ||
124 | int bucketOf(const QDate &candidate) const; | 129 | int bucketOf(const QDate &candidate) const; |
125 | 130 | ||
@@ -128,6 +133,7 @@ private: | |||
128 | 133 | ||
129 | QSharedPointer<QAbstractItemModel> eventModel; | 134 | QSharedPointer<QAbstractItemModel> eventModel; |
130 | QVector<QList<QSharedPointer<Event>>> partitionedEvents; | 135 | QVector<QList<QSharedPointer<Event>>> partitionedEvents; |
136 | QSharedPointer<EntityCacheInterface> mCalendarCache; | ||
131 | 137 | ||
132 | static const constexpr quintptr DAY_ID = std::numeric_limits<quintptr>::max(); | 138 | static const constexpr quintptr DAY_ID = std::numeric_limits<quintptr>::max(); |
133 | }; | 139 | }; |