From 2085b83960cbb8e4693cf48a5bd265aa946256de Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 3 Aug 2018 13:49:56 +0200 Subject: Weekview with calendar colors --- framework/src/domain/daylongeventmodel.cpp | 13 +++++++++++++ framework/src/domain/daylongeventmodel.h | 6 ++++++ framework/src/domain/perioddayeventmodel.cpp | 15 ++++++++++++++- framework/src/domain/perioddayeventmodel.h | 6 ++++++ 4 files changed, 39 insertions(+), 1 deletion(-) (limited to 'framework/src/domain') 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 @@ #include #include +#include "entitycache.h" + DayLongEventModel::DayLongEventModel(QObject *parent) : QSortFilterProxyModel(parent) { Sink::Query query; @@ -33,11 +35,14 @@ DayLongEventModel::DayLongEventModel(QObject *parent) : QSortFilterProxyModel(pa query.request(); query.request(); query.request(); + query.request(); query.filter(true); mModel = Sink::Store::loadModel(query); + mCalendarCache = EntityCache::Ptr::create(); + setSourceModel(mModel.data()); } @@ -48,9 +53,15 @@ QHash DayLongEventModel::roleNames() const {Description, "description"}, {StartDate, "starts"}, {Duration, "duration"}, + {Color, "color"}, }; } +QByteArray DayLongEventModel::getColor(const QByteArray &calendar) const +{ + return mCalendarCache->getProperty(calendar, "color").toByteArray(); +} + QVariant DayLongEventModel::data(const QModelIndex &idx, int role) const { auto srcIdx = mapToSource(idx); @@ -71,6 +82,8 @@ QVariant DayLongEventModel::data(const QModelIndex &idx, int role) const } case Duration: return event->getStartTime().date().daysTo(event->getEndTime().date()); + case Color: + return getColor(event->getCalendar()); } 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 @@ #include #include +class EntityCacheInterface; class KUBE_EXPORT DayLongEventModel : public QSortFilterProxyModel { Q_OBJECT @@ -37,6 +38,7 @@ class KUBE_EXPORT DayLongEventModel : public QSortFilterProxyModel public: using Event = Sink::ApplicationDomain::Event; + using Calendar = Sink::ApplicationDomain::Calendar; enum Roles { @@ -44,6 +46,7 @@ public: Description, StartDate, Duration, + Color }; Q_ENUM(Roles); @@ -62,7 +65,10 @@ public: void setPeriodLength(int); private: + QByteArray getColor(const QByteArray &calendar) const; + QSharedPointer mModel; + QSharedPointer mCalendarCache; QDate mPeriodStart; 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 @@ #include #include +#include + PeriodDayEventModel::PeriodDayEventModel(QObject *parent) : QAbstractItemModel(parent), partitionedEvents(7) { @@ -43,6 +45,7 @@ void PeriodDayEventModel::updateQuery() query.request(); query.request(); query.request(); + query.request(); auto periodEnd = mPeriodStart.addDays(mPeriodLength); @@ -59,6 +62,8 @@ void PeriodDayEventModel::updateQuery() QObject::connect(eventModel.data(), &QAbstractItemModel::rowsMoved, this, &PeriodDayEventModel::partitionData); QObject::connect(eventModel.data(), &QAbstractItemModel::rowsRemoved, this, &PeriodDayEventModel::partitionData); + mCalendarCache = EntityCache::Ptr::create(); + partitionData(); } @@ -157,6 +162,11 @@ int PeriodDayEventModel::columnCount(const QModelIndex &parent) const return eventModel->columnCount(); } +QByteArray PeriodDayEventModel::getColor(const QByteArray &calendar) const +{ + return mCalendarCache->getProperty(calendar, "color").toByteArray(); +} + QVariant PeriodDayEventModel::data(const QModelIndex &id, int role) const { if (id.internalId() == DAY_ID) { @@ -184,7 +194,7 @@ QVariant PeriodDayEventModel::data(const QModelIndex &id, int role) const {"description", data(eventId, Description)}, {"starts", startTime.hour() + startTime.minute() / 60.}, {"duration", data(eventId, Duration)}, - {"color", "#134bab"}, + {"color", data(eventId, Color)}, {"indention", 0}, }); } @@ -213,6 +223,8 @@ QVariant PeriodDayEventModel::data(const QModelIndex &id, int role) const auto end = event->getEndTime(); return start.secsTo(end) / 3600; } + case Color: + return getColor(event->getCalendar()); default: SinkWarning() << "Unknown role for event:" << QMetaEnum::fromType().valueToKey(role); return {}; @@ -229,6 +241,7 @@ QHash PeriodDayEventModel::roleNames() const {Description, "description"}, {StartTime, "starts"}, {Duration, "duration"}, + {Color, "color"} }; } 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 @@ // | '--- List of event pointers for that day // '--- Partition / day // + +class EntityCacheInterface; class KUBE_EXPORT PeriodDayEventModel : public QAbstractItemModel { Q_OBJECT @@ -87,6 +89,7 @@ class KUBE_EXPORT PeriodDayEventModel : public QAbstractItemModel public: using Event = Sink::ApplicationDomain::Event; + using Calendar = Sink::ApplicationDomain::Calendar; enum Roles { @@ -96,6 +99,7 @@ public: Description, StartTime, Duration, + Color }; Q_ENUM(Roles); PeriodDayEventModel(QObject *parent = nullptr); @@ -120,6 +124,7 @@ public: private: void updateQuery(); void partitionData(); + QByteArray getColor(const QByteArray &calendar) const; int bucketOf(const QDate &candidate) const; @@ -128,6 +133,7 @@ private: QSharedPointer eventModel; QVector>> partitionedEvents; + QSharedPointer mCalendarCache; static const constexpr quintptr DAY_ID = std::numeric_limits::max(); }; -- cgit v1.2.3