Eventviews

timelineitem.cpp
1/*
2 SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
3 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
4 SPDX-FileCopyrightText: 2010 Andras Mantia <andras@kdab.com>
5
6 SPDX-License-Identifier: GPL-2.0-or-later
7*/
8
9#include "timelineitem.h"
10
11#include <Akonadi/CalendarUtils>
12
13#include <KGanttGlobal>
14
15#include <KCalUtils/IncidenceFormatter>
16
17using namespace KCalendarCore;
18using namespace KCalUtils;
19using namespace EventViews;
20
21TimelineItem::TimelineItem(const Akonadi::CollectionCalendar::Ptr &calendar, uint index, QStandardItemModel *model, QObject *parent)
22 : QObject(parent)
23 , mCalendar(calendar)
24 , mModel(model)
25 , mIndex(index)
26{
27 mModel->removeRow(mIndex);
28 auto dummyItem = new QStandardItem;
29 dummyItem->setData(KGantt::TypeTask, KGantt::ItemTypeRole);
30 mModel->insertRow(mIndex, dummyItem);
31}
32
33TimelineItem::~TimelineItem()
34{
35 mModel->removeRow(mIndex);
36}
37
38void TimelineItem::insertIncidence(const Akonadi::Item &aitem, const QDateTime &_start, const QDateTime &_end)
39{
41 QDateTime start(_start);
42 QDateTime end(_end);
43 if (!start.isValid()) {
44 start = incidence->dtStart().toLocalTime();
45 }
46 if (!end.isValid()) {
47 end = incidence->dateTime(Incidence::RoleEnd).toLocalTime();
48 }
49 if (incidence->allDay()) {
50 end = end.addDays(1);
51 }
52
53 using ItemList = QList<QStandardItem *>;
54 ItemList list = mItemMap.value(aitem.id());
55 for (ItemList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it) {
56 if (static_cast<TimelineSubItem *>(*it)->startTime() == start && static_cast<TimelineSubItem *>(*it)->endTime() == end) {
57 return;
58 }
59 }
60
61 auto item = new TimelineSubItem(aitem, this);
62
63 item->setStartTime(start);
64 item->setOriginalStart(start);
65 item->setEndTime(end);
66 item->setData(mColor, Qt::DecorationRole);
67
68 list = mModel->takeRow(mIndex);
69
70 mItemMap[aitem.id()].append(item);
71
72 list.append(mItemMap[aitem.id()]);
73
74 mModel->insertRow(mIndex, list);
75}
76
77void TimelineItem::removeIncidence(const Akonadi::Item &incidence)
78{
79 qDeleteAll(mItemMap.value(incidence.id()));
80 mItemMap.remove(incidence.id());
81}
82
83void TimelineItem::moveItems(const Akonadi::Item &incidence, int delta, int duration)
84{
85 using ItemList = QList<QStandardItem *>;
86 ItemList list = mItemMap.value(incidence.id());
87 const ItemList::ConstIterator end(list.constEnd());
88 for (ItemList::ConstIterator it = list.constBegin(); it != end; ++it) {
89 QDateTime start = static_cast<TimelineSubItem *>(*it)->originalStart();
90 start = start.addSecs(delta);
91 static_cast<TimelineSubItem *>(*it)->setStartTime(start);
92 static_cast<TimelineSubItem *>(*it)->setOriginalStart(start);
93 static_cast<TimelineSubItem *>(*it)->setEndTime(start.addSecs(duration));
94 }
95}
96
97void TimelineItem::setColor(const QColor &color)
98{
99 mColor = color;
100}
101
102Akonadi::CollectionCalendar::Ptr TimelineItem::calendar() const
103{
104 return mCalendar;
105}
106
107TimelineSubItem::TimelineSubItem(const Akonadi::Item &incidence, TimelineItem *parent)
108 : QStandardItem()
109 , mIncidence(incidence)
110 , mParent(parent)
111 , mToolTipNeedsUpdate(true)
112{
113 setData(KGantt::TypeTask, KGantt::ItemTypeRole);
114 if (!Akonadi::CalendarUtils::incidence(incidence)->isReadOnly()) {
116 }
117}
118
119TimelineSubItem::~TimelineSubItem() = default;
120
121void TimelineSubItem::setStartTime(const QDateTime &dt)
122{
124}
125
126QDateTime TimelineSubItem::startTime() const
127{
129}
130
131void TimelineSubItem::setEndTime(const QDateTime &dt)
132{
134}
135
136QDateTime TimelineSubItem::endTime() const
137{
139}
140
141void TimelineSubItem::updateToolTip()
142{
143 if (!mToolTipNeedsUpdate) {
144 return;
145 }
146
147 mToolTipNeedsUpdate = false;
148
149 const auto name = Akonadi::CalendarUtils::displayName(mParent->calendar()->model(), mIncidence.parentCollection());
150 setData(IncidenceFormatter::toolTipStr(name, Akonadi::CalendarUtils::incidence(mIncidence), originalStart().date(), true), Qt::ToolTipRole);
151}
152
153#include "moc_timelineitem.cpp"
Collection & parentCollection()
Id id() const
Q_SCRIPTABLE Q_NOREPLY void start()
AKONADI_CALENDAR_EXPORT KCalendarCore::Incidence::Ptr incidence(const Akonadi::Item &item)
AKONADI_CALENDAR_EXPORT QString displayName(Akonadi::ETMCalendar *calendar, const Akonadi::Collection &collection)
Namespace EventViews provides facilities for displaying incidences, including events,...
Definition agenda.h:33
KCALUTILS_EXPORT QString toolTipStr(const QString &sourceName, const KCalendarCore::IncidenceBase::Ptr &incidence, QDate date=QDate(), bool richText=true)
KCRASH_EXPORT void setFlags(KCrash::CrashFlags flags)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QString name(StandardAction id)
const QList< QKeySequence > & end()
bool removeRow(int row, const QModelIndex &parent)
QDateTime addSecs(qint64 s) const const
void append(QList< T > &&value)
const_iterator constBegin() const const
const_iterator constEnd() const const
size_type remove(const Key &key)
T value(const Key &key, const T &defaultValue) const const
virtual QVariant data(int role) const const
virtual void setData(const QVariant &value, int role)
bool insertRow(int row, const QModelIndex &parent)
QList< QStandardItem * > takeRow(int row)
DecorationRole
ItemIsSelectable
QDateTime toDateTime() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:56 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.