MauiKit Calendar

todosortfilterproxymodel.h
1// SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com>
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <Akonadi/CalendarUtils>
7#include <Akonadi/ETMCalendar>
8#include <Akonadi/IncidenceTreeModel>
9#include <Akonadi/TodoModel>
10#include <KConfigWatcher>
11#include <KFormat>
12#include <KSharedConfig>
13#include <QObject>
14#include <QSortFilterProxyModel>
15#include <QTimer>
16
17class Filter;
18
19class TodoSortFilterProxyModel : public QSortFilterProxyModel
20{
22 Q_PROPERTY(Akonadi::IncidenceChanger *incidenceChanger READ incidenceChanger WRITE setIncidenceChanger NOTIFY incidenceChangerChanged)
23 Q_PROPERTY(Akonadi::ETMCalendar::Ptr calendar READ calendar WRITE setCalendar NOTIFY calendarChanged)
24 Q_PROPERTY(Filter *filterObject READ filterObject WRITE setFilterObject NOTIFY filterObjectChanged)
25 Q_PROPERTY(int showCompleted READ showCompleted WRITE setShowCompleted NOTIFY showCompletedChanged)
26 Q_PROPERTY(int sortBy READ sortBy WRITE setSortBy NOTIFY sortByChanged)
27 Q_PROPERTY(bool sortAscending READ sortAscending WRITE setSortAscending NOTIFY sortAscendingChanged)
28 Q_PROPERTY(bool showCompletedSubtodosInIncomplete READ showCompletedSubtodosInIncomplete WRITE setShowCompletedSubtodosInIncomplete NOTIFY
29 showCompletedSubtodosInIncompleteChanged)
30
31public:
32 enum Roles {
33 StartTimeRole = Akonadi::TodoModel::CalendarRole + 1,
34 EndTimeRole,
35 DisplayDueDateRole,
36 LocationRole,
37 AllDayRole,
38 CompletedRole,
39 PriorityRole,
40 ColorRole,
41 CollectionIdRole,
42 DurationStringRole,
43 RecursRole,
44 IsOverdueRole,
45 IncidenceIdRole,
46 IncidenceTypeRole,
47 IncidenceTypeStrRole,
48 IncidenceTypeIconRole,
49 IncidencePtrRole,
50 TagsRole,
51 ItemRole,
52 CategoriesRole,
53 CategoriesDisplayRole,
54 TreeDepthRole,
55 TopMostParentSummaryRole, // These three here are used to help us conserve the proper sections
56 TopMostParentDueDateRole, // in the Kirigami TreeListView, which otherwise will create new
57 TopMostParentPriorityRole, // sections for subtasks
58 };
59 Q_ENUM(Roles)
60
61 enum BaseTodoModelColumns {
62 SummaryColumn = Akonadi::TodoModel::SummaryColumn,
63 PriorityColumn = Akonadi::TodoModel::PriorityColumn,
64 PercentColumn = Akonadi::TodoModel::PercentColumn,
65 StartDateColumn = Akonadi::TodoModel::StartDateColumn,
66 DueDateColumn = Akonadi::TodoModel::DueDateColumn,
67 CategoriesColumn = Akonadi::TodoModel::CategoriesColumn,
68 DescriptionColumn = Akonadi::TodoModel::DescriptionColumn,
69 CalendarColumn = Akonadi::TodoModel::CalendarColumn,
70 };
71 Q_ENUM(BaseTodoModelColumns)
72
73 enum ShowComplete {
74 ShowAll = 0,
75 ShowCompleteOnly,
76 ShowIncompleteOnly,
77 };
78 Q_ENUM(ShowComplete)
79
80 enum DueDateDisplayFormat {
81 DisplayDateOnly,
82 DisplayDateTimeAndIfOverdue,
83 };
84 Q_ENUM(DueDateDisplayFormat)
85
86 explicit TodoSortFilterProxyModel(QObject *parent = nullptr);
87 ~TodoSortFilterProxyModel() = default;
88
89 int columnCount(const QModelIndex &parent) const override;
90 QHash<int, QByteArray> roleNames() const override;
91 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
92 bool filterAcceptsRow(int row, const QModelIndex &sourceParent) const override;
93
94 bool filterAcceptsRowCheck(int row, const QModelIndex &sourceParent) const;
95 bool hasAcceptedChildren(int row, const QModelIndex &sourceParent) const;
96
97 Akonadi::ETMCalendar::Ptr calendar() const;
98 Akonadi::IncidenceChanger *incidenceChanger() const;
99 int showCompleted() const;
100 Filter *filterObject() const;
101 int sortBy() const;
102 bool sortAscending() const;
103 bool showCompletedSubtodosInIncomplete() const;
104
106 void calendarChanged();
107 void filterObjectAboutToChange();
108 void filterObjectChanged();
109 void showCompletedChanged();
110 void sortByChanged();
111 void sortAscendingChanged();
112 void showCompletedSubtodosInIncompleteChanged();
113 void incidenceChangerChanged();
114
115public Q_SLOTS:
116 void setCalendar(Akonadi::ETMCalendar::Ptr &calendar);
117 void setIncidenceChanger(Akonadi::IncidenceChanger *changer);
118 void setFilterObject(Filter *filterObject);
119 void setShowCompleted(const int showCompleted);
120 void setSortBy(const int sortBy);
121 void setSortAscending(const bool sortAscending);
122 void setShowCompletedSubtodosInIncomplete(const bool showCompletedSubtodosInIncomplete);
123
124 void sortTodoModel();
125 void filterTodoName(const QString &name, const int showCompleted = ShowAll);
126
127protected:
128 bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
129
130private Q_SLOTS:
131 void setColorCache(const QHash<QString, QColor> colorCache);
132
133 void loadColors();
134 void updateDateLabels();
135 void emitDateDataChanged(const QModelIndex &idx);
136
137private:
138 QHash<QString, QColor> colorCache() const;
139 QString todoDueDateDisplayString(const KCalendarCore::Todo::Ptr todo, const DueDateDisplayFormat format) const;
140
141 int compareStartDates(const QModelIndex &left, const QModelIndex &right) const;
142 int compareDueDates(const QModelIndex &left, const QModelIndex &right) const;
143 int compareCompletedDates(const QModelIndex &left, const QModelIndex &right) const;
144 int comparePriorities(const QModelIndex &left, const QModelIndex &right) const;
145 int compareCompletion(const QModelIndex &left, const QModelIndex &right) const;
146
147 Akonadi::ETMCalendar::Ptr m_calendar;
150 Akonadi::IncidenceChanger *m_lastSetChanger = nullptr;
151 QHash<QString, QColor> m_colors;
152 KConfigWatcher::Ptr m_colorWatcher;
153 int m_showCompleted = ShowComplete::ShowAll;
154 int m_showCompletedStore; // For when searches happen
155 Filter *m_filterObject = nullptr;
156 int m_sortColumn = DueDateColumn;
157 bool m_sortAscending = false;
158 bool m_showCompletedSubtodosInIncomplete = true;
159 KFormat m_format;
160 QTimer m_dateRefreshTimer;
161 int m_dateRefreshTimerInterval = 60000; // msecs
162 QDate m_lastDateRefreshDate = QDate::currentDate();
163};
QDate currentDate()
Q_ENUM(...)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
DisplayRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Sep 27 2024 11:56:15 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.