Incidenceeditor

freebusyganttproxymodel.cpp
1/*
2 SPDX-FileCopyrightText: 2010 Casey Link <unnamedrambler@gmail.com>
3 SPDX-FileCopyrightText: 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "freebusyganttproxymodel.h"
9#include <CalendarSupport/FreeBusyItemModel>
10
11#include <KCalendarCore/FreeBusyPeriod>
12#include <KGanttGraphicsView>
13
14#include <KLocalizedString>
15
16#include <QLocale>
17
18using namespace IncidenceEditorNG;
19
20FreeBusyGanttProxyModel::FreeBusyGanttProxyModel(QObject *parent)
21 : QSortFilterProxyModel(parent)
22{
23}
24
25QVariant FreeBusyGanttProxyModel::data(const QModelIndex &index, int role) const
26{
27 if (!index.isValid()) {
28 return {};
29 }
30 QModelIndex source_index = mapToSource(index);
31
32 // if the index is not valid, then its a toplevel item, which is an attendee
33 if (!source_index.parent().isValid()) {
34 switch (role) {
36 return KGantt::TypeMulti;
37 case Qt::DisplayRole:
38 return source_index.data(Qt::DisplayRole);
39 default:
40 return {};
41 }
42 }
43
44 // if the index is valid, then it corresponds to a free busy period
45 auto period = sourceModel()->data(source_index, CalendarSupport::FreeBusyItemModel::FreeBusyPeriodRole).value<KCalendarCore::FreeBusyPeriod>();
46
47 switch (role) {
49 return KGantt::TypeTask;
51 return period.start().toLocalTime();
53 return period.end().toLocalTime();
55 return QColor(Qt::red);
56 case Qt::ToolTipRole:
57 return tooltipify(period);
58 case Qt::DisplayRole:
59 return sourceModel()->data(source_index.parent(), Qt::DisplayRole);
60 default:
61 return {};
62 }
63}
64
65QString FreeBusyGanttProxyModel::tooltipify(const KCalendarCore::FreeBusyPeriod &period) const
66{
67 QString toolTip = QStringLiteral("<qt>");
68 toolTip += QLatin1StringView("<b>") + i18nc("@info:tooltip", "Free/Busy Period") + QLatin1StringView("</b>");
69 toolTip += QStringLiteral("<hr>");
70 if (!period.summary().isEmpty()) {
71 toolTip += QLatin1StringView("<i>") + i18nc("@info:tooltip", "Summary:") + QLatin1StringView("</i>") + QStringLiteral("&nbsp;");
72 toolTip += period.summary();
73 toolTip += QStringLiteral("<br>");
74 }
75 if (!period.location().isEmpty()) {
76 toolTip += QLatin1StringView("<i>") + i18nc("@info:tooltip", "Location:") + QLatin1StringView("</i>") + QStringLiteral("&nbsp;");
77 toolTip += period.location();
78 toolTip += QStringLiteral("<br>");
79 }
80 toolTip += QStringLiteral("<i>") + i18nc("@info:tooltip period start time", "Start:") + QStringLiteral("</i>") + QStringLiteral("&nbsp;");
81 toolTip += QLocale().toString(period.start().toLocalTime(), QLocale::ShortFormat);
82 toolTip += QStringLiteral("<br>");
83 toolTip += QStringLiteral("<i>") + i18nc("@info:tooltip period end time", "End:") + QStringLiteral("</i>") + QStringLiteral("&nbsp;");
84 toolTip += QLocale().toString(period.end().toLocalTime(), QLocale::ShortFormat);
85 toolTip += QStringLiteral("<br>");
86 toolTip += QStringLiteral("</qt>");
87 return toolTip;
88}
89
90#include "moc_freebusyganttproxymodel.cpp"
QDateTime end() const
QDateTime start() const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QDateTime toLocalTime() const const
QString toString(QDate date, FormatType format) const const
QVariant data(int role) const const
bool isValid() const const
QModelIndex parent() const const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const const override
bool isEmpty() const const
DisplayRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:16:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.