Verified Commit c767443c authored by Carl Schwan's avatar Carl Schwan 🚴
Browse files

Make TodoModel accessible to QML

parent c0213064
Pipeline #87640 passed with stage
in 5 minutes and 51 seconds
......@@ -146,6 +146,8 @@ ecm_generate_headers(eventviews_CamelCaseagenda_HEADERS
ecm_generate_headers(eventviews_CamelCasetodo_HEADERS
HEADER_NAMES
TodoView
TodoModel
IncidenceTreeModel
REQUIRED_HEADERS eventviews_todo_HEADERS
PREFIX EventViews
RELATIVE todo
......
......@@ -6,6 +6,7 @@
#pragma once
#include "eventviews_export.h"
#include <Akonadi/Item>
#include <QAbstractProxyModel>
......@@ -14,7 +15,7 @@
class IncidenceTreeModelPrivate;
class IncidenceTreeModel : public QAbstractProxyModel
class EVENTVIEWS_EXPORT IncidenceTreeModel : public QAbstractProxyModel
{
Q_OBJECT
public:
......
......@@ -234,6 +234,41 @@ QVariant TodoModel::data(const QModelIndex &index, int role) const
return QVariant();
}
switch (role) {
case SummaryRole:
return todo->summary();
case RecurRole:
if (todo->recurs()) {
if (todo->hasRecurrenceId()) {
return i18nc("yes, an exception to a recurring to-do", "Exception");
} else {
return i18nc("yes, recurring to-do", "Yes");
}
} else {
return i18nc("no, not a recurring to-do", "No");
}
case PriorityRole:
if (todo->priority() == 0) {
return QStringLiteral("--");
}
return todo->priority();
case PercentRole:
return todo->percentComplete();
case StartDateRole:
return todo->hasStartDate() ? QLocale().toString(todo->dtStart().toLocalTime().date(), QLocale::ShortFormat) : QString();
case DueDateRole:
return todo->hasDueDate() ? QLocale().toString(todo->dtDue().toLocalTime().date(), QLocale::ShortFormat) : QString();
case CategoriesRole: {
return todo->categories().join(i18nc("delimiter for joining category/tag names", ","));
}
case DescriptionRole:
return todo->description();
case CalendarRole:
return CalendarSupport::displayName(d->m_calendar.data(), item.parentCollection());
default:
break; // column based model handling
}
if (role == Qt::DisplayRole) {
switch (index.column()) {
case SummaryColumn:
......@@ -859,3 +894,19 @@ QModelIndex TodoModel::buddy(const QModelIndex &index) const
// source model doesn't have the same number of columns.
return index;
}
QHash<int, QByteArray> TodoModel::roleNames() const
{
return {
{SummaryRole, QByteArrayLiteral("summary")},
{RecurRole, QByteArrayLiteral("recur")},
{PriorityRole, QByteArrayLiteral("priority")},
{PercentRole, QByteArrayLiteral("percent")},
{StartDateRole, QByteArrayLiteral("startDate")},
{DueDateRole, QByteArrayLiteral("dueDate")},
{CategoriesRole, QByteArrayLiteral("categories")},
{DescriptionRole, QByteArrayLiteral("description")},
{CalendarRole, QByteArrayLiteral("calendar")},
{Qt::CheckStateRole, QByteArrayLiteral("checked")},
};
}
......@@ -7,6 +7,7 @@
#pragma once
#include "eventviews_export.h"
#include "prefs.h"
#include <Akonadi/Calendar/ETMCalendar>
......@@ -24,7 +25,7 @@ class QMimeData;
class TodoModelPrivate;
class TodoModel : public QAbstractProxyModel
class EVENTVIEWS_EXPORT TodoModel : public QAbstractProxyModel
{
Q_OBJECT
......@@ -45,7 +46,20 @@ public:
};
/** This enum defines the user defined roles of the items in this model */
enum { TodoRole = Akonadi::EntityTreeModel::UserRole + 1, IsRichTextRole, TodoPtrRole };
enum {
TodoRole = Akonadi::EntityTreeModel::UserRole + 1,
TodoPtrRole,
IsRichTextRole,
SummaryRole,
RecurRole,
PriorityRole,
PercentRole,
StartDateRole,
DueDateRole,
CategoriesRole,
DescriptionRole,
CalendarRole,
};
explicit TodoModel(const EventViews::PrefsPtr &preferences, QObject *parent = nullptr);
......@@ -87,6 +101,8 @@ public:
Q_REQUIRED_RESULT QModelIndex buddy(const QModelIndex &index) const override;
Q_REQUIRED_RESULT QHash<int, QByteArray> roleNames() const override;
private:
friend class TodoModelPrivate;
std::unique_ptr<TodoModelPrivate> const d;
......
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