Commit bd66b70b authored by Claudio Cambra's avatar Claudio Cambra
Browse files

Add list section headings to tasks view

parent e03e10c9
Pipeline #98187 failed with stage
in 5 minutes and 44 seconds
......@@ -37,6 +37,47 @@ TreeListView {
currentIndex: -1
clip: true
section.criteria: sortBy === Kalendar.TodoSortFilterProxyModel.SummaryColumn ?
ViewSection.FirstCharacter : ViewSection.FullString
section.property: switch(sortBy) {
case Kalendar.TodoSortFilterProxyModel.PriorityColumn:
return "topMostParentPriority";
case Kalendar.TodoSortFilterProxyModel.DueDateColumn:
return "topMostParentDueDate";
case Kalendar.TodoSortFilterProxyModel.SummaryColumn:
default:
return "topMostParentSummary";
}
section.delegate: Kirigami.AbstractListItem {
separatorVisible: false
sectionDelegate: true
hoverEnabled: false
activeFocusOnTab: false
contentItem: Kirigami.Heading {
text: {
switch(sortBy) {
case Kalendar.TodoSortFilterProxyModel.PriorityColumn:
return section !== "--" ? i18n("Priority %1", section) : i18n("No set priority");
case Kalendar.TodoSortFilterProxyModel.DueDateColumn:
let sectionDate = new Date(section);
return !isNaN(sectionDate.getTime()) ? LabelUtils.todoDateTimeLabel(new Date(section), true, false) : section;
case Kalendar.TodoSortFilterProxyModel.SummaryColumn:
default:
return section;
}
}
readonly property bool isOverdue: section === i18n("Overdue")
readonly property bool isToday: DateUtils.sameDay(new Date(section), new Date())
level: 3
font.weight: Font.Bold
color: isOverdue ? Kirigami.Theme.negativeTextColor : isToday ? Kirigami.Theme.highlightColor : Kirigami.Theme.textColor
}
}
MouseArea {
id: incidenceDeselectorMouseArea
anchors.fill: parent
......
......@@ -211,9 +211,9 @@ function todoDateTimeLabel(datetime, allDay, completed) {
i18nc("%1 is the time, spaces included to allow use of 'empty' string when an event is allday and has no time", " at %1 ", datetime.toLocaleTimeString(Qt.locale(), 1));
if(DateUtils.sameDay(datetime, now)) {
return (datetime > now || allDay) && !completed ?
i18nc("No space since the %1 string, which includes the time (or not), includes this space", "Today%1", timeString) :
i18nc("No space since the %1 string, which includes the time (or not), includes this space", "Today%1(overdue)", timeString);
return (datetime > now) && !completed && !allDay ?
i18nc("No space since the %1 string, which includes the time (or not), includes this space", "Today%1(overdue)", timeString) :
i18nc("No space since the %1 string, which includes the time (or not), includes this space", "Today%1", timeString);
} else if(DateUtils.sameDay(DateUtils.addDaysToDate(datetime, - 1), now)) { // Tomorrow
return i18nc("No space since the %1 string, which includes the time (or not), includes this space", "Tomorrow%1", timeString);
} else if(DateUtils.sameDay(DateUtils.addDaysToDate(datetime, 1), now)) { // Yesterday
......
// SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com>
// SPDX-License-Identifier: LGPL-2.1-or-later
#include <QDateTime>
#include <extratodomodel.h>
ExtraTodoModel::ExtraTodoModel(QObject *parent)
......@@ -111,14 +112,29 @@ QVariant ExtraTodoModel::data(const QModelIndex &index, int role) const
return todoPtr->categories();
} else if (role == Roles::CategoriesDisplayRole) {
return todoPtr->categories().join(i18nc("List separator", ", "));
} else if (role == Roles::TreeDepthRole) {
} else if (role == Roles::TreeDepthRole || role == TopMostParentSummary || role == TopMostParentDueDate || role == TopMostParentPriority) {
int depth = 0;
auto idx = index;
while (idx.parent().isValid()) {
idx = idx.parent();
depth++;
}
return depth;
auto todo = idx.data(TodoModel::TodoPtrRole).value<KCalendarCore::Todo::Ptr>();
switch (role) {
case Roles::TreeDepthRole:
return depth;
case TopMostParentSummary:
return todo->summary();
case TopMostParentDueDate: {
bool isOverdue = (todo->hasDueDate() && todo->dtDue().date() < QDate::currentDate() && todo->allDay())
|| (todo->hasDueDate() && todo->dtDue() < QDateTime::currentDateTime() && !todo->allDay());
return isOverdue ? i18n("Overdue") : todo->hasDueDate() ? todo->dtDue().toString() : i18n("No set date");
}
case TopMostParentPriority:
return todo->priority();
}
}
return KExtraColumnsProxyModel::data(index, role);
......@@ -149,6 +165,9 @@ QHash<int, QByteArray> ExtraTodoModel::roleNames() const
roleNames[Roles::CategoriesRole] = "todoCategories"; // Simply 'categories' causes issues
roleNames[Roles::CategoriesDisplayRole] = "categoriesDisplay";
roleNames[Roles::TreeDepthRole] = "treeDepth";
roleNames[Roles::TopMostParentDueDate] = "topMostParentDueDate";
roleNames[Roles::TopMostParentSummary] = "topMostParentSummary";
roleNames[Roles::TopMostParentPriority] = "topMostParentPriority";
return roleNames;
}
......
......@@ -43,7 +43,10 @@ public:
ItemRole,
CategoriesRole,
CategoriesDisplayRole,
TreeDepthRole
TreeDepthRole,
TopMostParentSummary, // These three here are used to help us conserve the proper sections
TopMostParentDueDate, // in the Kirigami TreeListView, which otherwise will create new
TopMostParentPriority // sections for subtasks
};
Q_ENUM(Roles);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment