From 455809b0e5d6e80406867aa8f5a74aa10a39bf35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Nicole?= Date: Tue, 15 May 2018 12:01:09 +0200 Subject: Implement DayLongEventModel and integrate it to the calendar Summary: Fixes T8697 Reviewers: cmollekopf Reviewed By: cmollekopf Tags: #kube Maniphest Tasks: T8697 Differential Revision: https://phabricator.kde.org/D12875 --- framework/qml/Colors.qml | 1 + framework/src/CMakeLists.txt | 1 + framework/src/domain/daylongeventmodel.cpp | 123 +++++++++++++++++++++++++++ framework/src/domain/daylongeventmodel.h | 69 +++++++++++++++ framework/src/domain/perioddayeventmodel.cpp | 2 + framework/src/domain/perioddayeventmodel.h | 2 + framework/src/frameworkplugin.cpp | 2 + tests/teststore.cpp | 4 + views/calendar/main.qml | 59 ++++++++++++- views/calendar/qml/DaylongEvents.qml | 18 ++-- views/calendar/qml/WeekView.qml | 5 +- 11 files changed, 270 insertions(+), 16 deletions(-) create mode 100644 framework/src/domain/daylongeventmodel.cpp create mode 100644 framework/src/domain/daylongeventmodel.h diff --git a/framework/qml/Colors.qml b/framework/qml/Colors.qml index f85436bc..271d3564 100644 --- a/framework/qml/Colors.qml +++ b/framework/qml/Colors.qml @@ -34,6 +34,7 @@ Item { property string bewareOrange: "#f67400" property string dangerRed: "#ed1515" property string darkCharcoalGrey: "#232629" + property string jazzberryJam: "#af1a6a" property string lightgrey: "lightgrey" //Colorusage: 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 domain/maillistmodel.cpp domain/folderlistmodel.cpp domain/perioddayeventmodel.cpp + domain/daylongeventmodel.cpp domain/composercontroller.cpp domain/modeltest.cpp domain/retriever.cpp diff --git a/framework/src/domain/daylongeventmodel.cpp b/framework/src/domain/daylongeventmodel.cpp new file mode 100644 index 00000000..0ea73709 --- /dev/null +++ b/framework/src/domain/daylongeventmodel.cpp @@ -0,0 +1,123 @@ +/* + Copyright (c) 2018 Michael Bohlender + Copyright (c) 2018 Christian Mollekopf + Copyright (c) 2018 Rémi Nicole + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#include "daylongeventmodel.h" + +#include +#include +#include + +DayLongEventModel::DayLongEventModel(QObject *parent) : QSortFilterProxyModel(parent) +{ + Sink::Query query; + query.setFlags(Sink::Query::LiveQuery); + query.request(); + query.request(); + query.request(); + query.request(); + + query.filter(true); + + mModel = Sink::Store::loadModel(query); + + setSourceModel(mModel.data()); +} + +QHash DayLongEventModel::roleNames() const +{ + return { + {Summary, "summary"}, + {Description, "description"}, + {StartDate, "starts"}, + {Duration, "duration"}, + }; +} + +QVariant DayLongEventModel::data(const QModelIndex &idx, int role) const +{ + auto srcIdx = mapToSource(idx); + auto event = srcIdx.data(Sink::Store::DomainObjectRole).value(); + + switch (role) { + case Summary: + return event->getSummary(); + case Description: + return event->getDescription(); + case StartDate: { + auto dayIndex = mPeriodStart.daysTo(event->getStartTime().date()); + if (dayIndex < 0) { + return 0; + } + + return dayIndex; + } + case Duration: + return event->getStartTime().date().daysTo(event->getEndTime().date()); + } + + return QSortFilterProxyModel::data(idx, role); +} + +bool DayLongEventModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const +{ + auto idx = sourceModel()->index(sourceRow, 0, sourceParent); + auto event = idx.data(Sink::Store::DomainObjectRole).value(); + + auto eventStart = event->getStartTime().date(); + auto eventEnd = event->getEndTime().date(); + + if (!eventStart.isValid() || !eventEnd.isValid()) { + SinkWarning() << "Invalid date in the event model, ignoring..."; + return false; + } + + return eventStart < mPeriodStart.addDays(mPeriodLength) && eventEnd >= mPeriodStart; +} + +QDate DayLongEventModel::periodStart() const +{ + return mPeriodStart; +} + +void DayLongEventModel::setPeriodStart(const QDate &start) +{ + if (!start.isValid()) { + SinkWarning() << "Passed an invalid starting date in setPeriodStart, ignoring..."; + return; + } + + mPeriodStart = start; +} + +void DayLongEventModel::setPeriodStart(const QVariant &start) +{ + setPeriodStart(start.toDate()); +} + +int DayLongEventModel::periodLength() const +{ + return mPeriodLength; +} + +void DayLongEventModel::setPeriodLength(int length) +{ + mPeriodLength = length; +} diff --git a/framework/src/domain/daylongeventmodel.h b/framework/src/domain/daylongeventmodel.h new file mode 100644 index 00000000..21bcbfba --- /dev/null +++ b/framework/src/domain/daylongeventmodel.h @@ -0,0 +1,69 @@ +/* + Copyright (c) 2018 Michael Bohlender + Copyright (c) 2018 Christian Mollekopf + Copyright (c) 2018 Rémi Nicole + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#pragma once +#include "kube_export.h" +#include + +#include +#include +#include +#include + +class KUBE_EXPORT DayLongEventModel : public QSortFilterProxyModel +{ + Q_OBJECT + + Q_PROPERTY(QVariant start READ periodStart WRITE setPeriodStart) + Q_PROPERTY(int length READ periodLength WRITE setPeriodLength) + +public: + using Event = Sink::ApplicationDomain::Event; + + enum Roles + { + Summary = Qt::UserRole + 1, + Description, + StartDate, + Duration, + }; + Q_ENUM(Roles); + + DayLongEventModel(QObject *parent = nullptr); + ~DayLongEventModel() = default; + + QHash roleNames() const override; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + + bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; + + QDate periodStart() const; + void setPeriodStart(const QDate &); + void setPeriodStart(const QVariant &); + int periodLength() const; + void setPeriodLength(int); + +private: + QSharedPointer mModel; + + QDate mPeriodStart; + int mPeriodLength = 7; +}; 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) query.request(); query.request(); + query.filter(false); + eventModel = Sink::Store::loadModel(query); 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 @@ // Facility used to get a restricted period into a Sink model comprised of // events, partitioned according to the day the events take place. // +// Day-long events are filtered out. +// // Model Format // ============ // 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 @@ #include "domain/maillistmodel.h" #include "domain/folderlistmodel.h" #include "domain/perioddayeventmodel.h" +#include "domain/daylongeventmodel.h" #include "domain/composercontroller.h" #include "domain/mime/messageparser.h" #include "domain/retriever.h" @@ -122,6 +123,7 @@ void FrameworkPlugin::registerTypes (const char *uri) qmlRegisterType(uri, 1, 0, "FolderListModel"); qmlRegisterType(uri, 1, 0, "MailListModel"); qmlRegisterType(uri, 1, 0, "PeriodDayEventModel"); + qmlRegisterType(uri, 1, 0, "DayLongEventModel"); qmlRegisterType(uri, 1, 0, "ComposerController"); qmlRegisterType(uri, 1, 0, "ControllerAction"); qmlRegisterType(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 calcoreEvent->setDtStart(startTime); calcoreEvent->setDtEnd(endTime); + if (object.contains("allDay")) { + calcoreEvent->setAllDay(object["allDay"].toBool()); + } + auto ical = KCalCore::ICalFormat().toICalString(calcoreEvent); sinkEvent.setIcal(ical.toUtf8()); 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 { { resource: "caldavresource", summary: "Test Event4", - description: "This is test event #3", + description: "This is test event #4", starts: "2018-04-12T22:00:00", ends: "2018-04-15T03:00:00", }, + { + resource: "caldavresource", + summary: "!!! Test Event5", + description: "!!! This is test event #5", + starts: "2018-04-22T22:00:00", + ends: "2018-04-25T03:00:00", + }, + + // Day-long events + { + resource: "caldavresource", + summary: "Test day-long event1", + description: "This is test day-long event #1", + starts: "2018-04-10T00:00:00", + ends: "2018-04-14T00:00:00", + allDay: true, + }, + { + resource: "caldavresource", + summary: "Test day-long event2", + description: "This is test day-long event #2", + starts: "2018-04-11T00:00:00", + ends: "2018-04-23T00:00:00", + allDay: true, + }, + { + resource: "caldavresource", + summary: "Test day-long event3", + description: "This is test day-long event #3", + starts: "2018-04-01T00:00:00", + ends: "2018-04-13T00:00:00", + allDay: true, + }, + { + resource: "caldavresource", + summary: "Test day-long event4", + description: "This is test day-long event #4", + starts: "2018-04-01T00:00:00", + ends: "2018-04-25T00:00:00", + allDay: true, + }, + { + resource: "caldavresource", + summary: "!!! Test day-long event5", + description: "!!! This is test day-long event #5", + starts: "2018-04-01T00:00:00", + ends: "2018-04-05T00:00:00", + allDay: true, + }, + { + resource: "caldavresource", + summary: "!!! Test day-long event6", + description: "!!! This is test day-long event #6", + starts: "2018-04-23T00:00:00", + ends: "2018-04-25T00:00:00", + allDay: true, + }, ], }], } 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 @@ import QtQuick 2.7 -ListModel { - ListElement { - color: "#af1a6a" - starts: 1 - duration: 4 - text: "Baustelle Adalbertstr." - } - ListElement { - color: "#134bab" - starts: 0 - duration: 6 - text: "Urlaub" - } +import org.kube.framework 1.0 as Kube + +Kube.DayLongEventModel { + start: "2018-04-09" + length: 7 } diff --git a/views/calendar/qml/WeekView.qml b/views/calendar/qml/WeekView.qml index f798e489..bcf037fa 100644 --- a/views/calendar/qml/WeekView.qml +++ b/views/calendar/qml/WeekView.qml @@ -97,7 +97,8 @@ FocusScope { width: root.dayWidth * model.duration height: parent.height x: root.dayWidth * model.starts - color: model.color + //color: model.color + color: Kube.Colors.jazzberryJam border.width: 1 border.color: Kube.Colors.viewBackgroundColor @@ -107,7 +108,7 @@ FocusScope { leftMargin: Kube.Units.smallSpacing } color: Kube.Colors.highlightedTextColor - text: model.text + text: model.summary } } } -- cgit v1.2.3