Eventviews

coloredtodoproxymodel.cpp
1/*
2 SPDX-FileCopyrightText: 2023 Kevin Ottens <ervin@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
5*/
6
7#include "coloredtodoproxymodel.h"
8
9#include <Akonadi/TodoModel>
10
11class ColoredTodoProxyModelPrivate
12{
13public:
14 ColoredTodoProxyModelPrivate(const EventViews::PrefsPtr &preferences)
15 : m_preferences(preferences)
16 {
17 }
18
19 EventViews::PrefsPtr m_preferences;
20};
21
22static bool isDueToday(const KCalendarCore::Todo::Ptr &todo)
23{
24 return !todo->isCompleted() && todo->dtDue().date() == QDate::currentDate();
25}
26
27ColoredTodoProxyModel::ColoredTodoProxyModel(const EventViews::PrefsPtr &preferences, QObject *parent)
28 : QIdentityProxyModel(parent)
29 , d(new ColoredTodoProxyModelPrivate(preferences))
30{
31}
32
33ColoredTodoProxyModel::~ColoredTodoProxyModel() = default;
34
35QVariant ColoredTodoProxyModel::data(const QModelIndex &index, int role) const
36{
37 if (role == Qt::BackgroundRole) {
38 const auto todo = QIdentityProxyModel::data(index, Akonadi::TodoModel::TodoPtrRole).value<KCalendarCore::Todo::Ptr>();
39 if (!todo) {
40 return {};
41 }
42
43 if (todo->isOverdue()) {
44 return QVariant(QBrush(d->m_preferences->todoOverdueColor()));
45 } else if (isDueToday(todo)) {
46 return QVariant(QBrush(d->m_preferences->todoDueTodayColor()));
47 } else {
48 return {};
49 }
50 }
51
52 return QIdentityProxyModel::data(index, role);
53}
AKONADI_CALENDAR_EXPORT KCalendarCore::Todo::Ptr todo(const Akonadi::Item &item)
const QList< QKeySequence > & preferences()
virtual QVariant data(const QModelIndex &index, int role) const const=0
QDate currentDate()
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
BackgroundRole
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:11 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.