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/perioddayeventmodel.cpp | |
parent | 064367aec304708591f5cd4d010ed462119a0323 (diff) | |
download | kube-2085b83960cbb8e4693cf48a5bd265aa946256de.tar.gz kube-2085b83960cbb8e4693cf48a5bd265aa946256de.zip |
Weekview with calendar colors
Diffstat (limited to 'framework/src/domain/perioddayeventmodel.cpp')
-rw-r--r-- | framework/src/domain/perioddayeventmodel.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
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 | ||