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

Use up to date version of eventviews todomodel and incidencetreemodel and use...

Use up to date version of eventviews todomodel and incidencetreemodel and use eventview's todo sorting mthod, fixing bugs
parent 54509ef6
Pipeline #97861 failed with stage
in 4 minutes and 24 seconds
......@@ -54,9 +54,9 @@ Kirigami.ScrollablePage {
property int sortBy: switch (Kalendar.Config.sort) {
case Kalendar.Config.DueTime:
return Kalendar.TodoSortFilterProxyModel.EndTimeColumn;
return Kalendar.TodoSortFilterProxyModel.DueDateColumn;
case Kalendar.Config.Priority:
return Kalendar.TodoSortFilterProxyModel.PriorityIntColumn;
return Kalendar.TodoSortFilterProxyModel.PriorityColumn;
case Kalendar.Config.Alphabetically:
return Kalendar.TodoSortFilterProxyModel.SummaryColumn;
}
......
......@@ -35,6 +35,10 @@ QVariant ExtraTodoModel::extraColumnData(const QModelIndex &parent, int row, int
const auto todoItem = index(row, extraColumn, parent).data(TodoModel::TodoRole).value<Akonadi::Item>();
const auto todoPtr = CalendarSupport::todo(todoItem);
if (todoPtr == nullptr) {
return QVariant();
}
switch (extraColumn) {
case StartTimeColumn:
return todoPtr->dtStart();
......@@ -58,6 +62,10 @@ QVariant ExtraTodoModel::data(const QModelIndex &index, int role) const
auto collectionId = todoItem.parentCollection().id();
auto todoPtr = CalendarSupport::todo(todoItem);
if (todoPtr == nullptr) {
return QVariant();
}
if (role == Roles::StartTimeRole) {
return todoPtr->dtStart();
} else if (role == Roles::EndTimeRole) {
......
......@@ -75,14 +75,14 @@ static PreNode::List sortedPrenodes(const PreNode::List &nodes)
return sorted;
}
IncidenceTreeModel::Private::Private(IncidenceTreeModel *qq, const QStringList &mimeTypes)
IncidenceTreeModelPrivate::IncidenceTreeModelPrivate(IncidenceTreeModel *qq, const QStringList &mimeTypes)
: QObject()
, m_mimeTypes(mimeTypes)
, q(qq)
{
}
int IncidenceTreeModel::Private::rowForNode(const Node::Ptr &node) const
int IncidenceTreeModelPrivate::rowForNode(const Node::Ptr &node) const
{
// Returns it's row number
const int row = node->parentNode ? node->parentNode->directChilds.indexOf(node) : m_toplevelNodeList.indexOf(node);
......@@ -90,9 +90,8 @@ int IncidenceTreeModel::Private::rowForNode(const Node::Ptr &node) const
return row;
}
void IncidenceTreeModel::Private::assert_and_dump(bool condition, const QString &message)
void IncidenceTreeModelPrivate::assert_and_dump(bool condition, const QString &)
{
Q_UNUSED(message)
if (!condition) {
// qCCritical(CALENDARVIEW_LOG) << "This should never happen: " << message;
dumpTree();
......@@ -100,14 +99,14 @@ void IncidenceTreeModel::Private::assert_and_dump(bool condition, const QString
}
}
void IncidenceTreeModel::Private::dumpTree()
void IncidenceTreeModelPrivate::dumpTree()
{
// for (const Node::Ptr &node : std::as_const(m_toplevelNodeList)) {
// qCDebug(CALENDARVIEW_LOG) << node;
//}
/*for (const Node::Ptr &node : std::as_const(m_toplevelNodeList)) {
//qCDebug(CALENDARVIEW_LOG) << node;
}*/
}
QModelIndex IncidenceTreeModel::Private::indexForNode(const Node::Ptr &node) const
QModelIndex IncidenceTreeModelPrivate::indexForNode(const Node::Ptr &node) const
{
if (!node) {
return {};
......@@ -118,7 +117,7 @@ QModelIndex IncidenceTreeModel::Private::indexForNode(const Node::Ptr &node) con
return q->createIndex(row, 0, node.data());
}
void IncidenceTreeModel::Private::reset(bool silent)
void IncidenceTreeModelPrivate::reset(bool silent)
{
if (!silent) {
q->beginResetModel();
......@@ -142,12 +141,12 @@ void IncidenceTreeModel::Private::reset(bool silent)
}
}
void IncidenceTreeModel::Private::onHeaderDataChanged(Qt::Orientation orientation, int first, int last)
void IncidenceTreeModelPrivate::onHeaderDataChanged(Qt::Orientation orientation, int first, int last)
{
Q_EMIT q->headerDataChanged(orientation, first, last);
}
void IncidenceTreeModel::Private::onDataChanged(const QModelIndex &begin, const QModelIndex &end)
void IncidenceTreeModelPrivate::onDataChanged(const QModelIndex &begin, const QModelIndex &end)
{
Q_ASSERT(begin.isValid());
Q_ASSERT(end.isValid());
......@@ -258,7 +257,7 @@ void IncidenceTreeModel::Private::onDataChanged(const QModelIndex &begin, const
}
}
void IncidenceTreeModel::Private::onRowsAboutToBeInserted(const QModelIndex &parent, int, int)
void IncidenceTreeModelPrivate::onRowsAboutToBeInserted(const QModelIndex &parent, int, int)
{
// We are a reparenting proxy, the source proxy is flat
Q_ASSERT(!parent.isValid());
......@@ -267,7 +266,7 @@ void IncidenceTreeModel::Private::onRowsAboutToBeInserted(const QModelIndex &par
// parent yet.
}
PreNode::Ptr IncidenceTreeModel::Private::prenodeFromSourceRow(int row) const
PreNode::Ptr IncidenceTreeModelPrivate::prenodeFromSourceRow(int row) const
{
PreNode::Ptr node = PreNode::Ptr(new PreNode());
node->sourceIndex = q->sourceModel()->index(row, 0, QModelIndex());
......@@ -287,7 +286,7 @@ PreNode::Ptr IncidenceTreeModel::Private::prenodeFromSourceRow(int row) const
return node;
}
void IncidenceTreeModel::Private::onRowsInserted(const QModelIndex &parent, int begin, int end)
void IncidenceTreeModelPrivate::onRowsInserted(const QModelIndex &parent, int begin, int end)
{
// QElapsedTimer timer;
// timer.start();
......@@ -317,7 +316,7 @@ void IncidenceTreeModel::Private::onRowsInserted(const QModelIndex &parent, int
// qCDebug(CALENDARVIEW_LOG) << "Took " << timer.elapsed() << " to insert " << end-begin+1;
}
void IncidenceTreeModel::Private::insertNode(const PreNode::Ptr &prenode, bool silent)
void IncidenceTreeModelPrivate::insertNode(const PreNode::Ptr &prenode, bool silent)
{
KCalendarCore::Incidence::Ptr incidence = prenode->incidence;
Akonadi::Item item = prenode->item;
......@@ -335,7 +334,7 @@ void IncidenceTreeModel::Private::insertNode(const PreNode::Ptr &prenode, bool s
if (m_uidMap.contains(node->uid)) {
// qCWarning(CALENDARVIEW_LOG) << "Duplicate incidence detected:"
// << "uid=" << node->uid << ". File a bug against the resource. collection=" << item.storageCollectionId();
//<< "uid=" << node->uid << ". File a bug against the resource. collection=" << item.storageCollectionId();
return;
}
......@@ -420,7 +419,7 @@ void IncidenceTreeModel::Private::insertNode(const PreNode::Ptr &prenode, bool s
}
// Sorts children first parents last
Node::List IncidenceTreeModel::Private::sorted(const Node::List &nodes) const
Node::List IncidenceTreeModelPrivate::sorted(const Node::List &nodes) const
{
if (nodes.isEmpty()) {
return nodes;
......@@ -437,7 +436,7 @@ Node::List IncidenceTreeModel::Private::sorted(const Node::List &nodes) const
return sorted;
}
void IncidenceTreeModel::Private::onRowsAboutToBeRemoved(const QModelIndex &parent, int begin, int end)
void IncidenceTreeModelPrivate::onRowsAboutToBeRemoved(const QModelIndex &parent, int begin, int end)
{
// QElapsedTimer timer;
// timer.start();
......@@ -479,7 +478,7 @@ void IncidenceTreeModel::Private::onRowsAboutToBeRemoved(const QModelIndex &pare
// qCDebug(CALENDARVIEW_LOG) << "Took " << timer.elapsed() << " to remove " << end-begin+1;
}
void IncidenceTreeModel::Private::removeNode(const Node::Ptr &node)
void IncidenceTreeModelPrivate::removeNode(const Node::Ptr &node)
{
Q_ASSERT(node);
// qCDebug(CALENDARVIEW_LOG) << "Dealing with parent: " << node->id << node.data()
......@@ -534,7 +533,7 @@ void IncidenceTreeModel::Private::removeNode(const Node::Ptr &node)
m_removedNodes << node.data();
}
void IncidenceTreeModel::Private::onRowsRemoved(const QModelIndex &parent, int begin, int end)
void IncidenceTreeModelPrivate::onRowsRemoved(const QModelIndex &parent, int begin, int end)
{
Q_UNUSED(parent)
Q_UNUSED(begin)
......@@ -542,88 +541,88 @@ void IncidenceTreeModel::Private::onRowsRemoved(const QModelIndex &parent, int b
// Nothing to do here, see comment on ::onRowsAboutToBeRemoved()
}
void IncidenceTreeModel::Private::onModelAboutToBeReset()
void IncidenceTreeModelPrivate::onModelAboutToBeReset()
{
q->beginResetModel();
}
void IncidenceTreeModel::Private::onModelReset()
void IncidenceTreeModelPrivate::onModelReset()
{
reset(/**silent=*/false);
q->endResetModel();
}
void IncidenceTreeModel::Private::onLayoutAboutToBeChanged()
void IncidenceTreeModelPrivate::onLayoutAboutToBeChanged()
{
Q_ASSERT(q->persistentIndexList().isEmpty());
Q_EMIT q->layoutAboutToBeChanged();
}
void IncidenceTreeModel::Private::onLayoutChanged()
void IncidenceTreeModelPrivate::onLayoutChanged()
{
reset(/**silent=*/true);
Q_ASSERT(q->persistentIndexList().isEmpty());
Q_EMIT q->layoutChanged();
}
void IncidenceTreeModel::Private::onRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)
void IncidenceTreeModelPrivate::onRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)
{
// Not implemented yet
Q_ASSERT(false);
}
void IncidenceTreeModel::Private::setSourceModel(QAbstractItemModel *model)
void IncidenceTreeModelPrivate::setSourceModel(QAbstractItemModel *model)
{
q->beginResetModel();
if (q->sourceModel()) {
disconnect(q->sourceModel(), &IncidenceTreeModel::dataChanged, this, &IncidenceTreeModel::Private::onDataChanged);
disconnect(q->sourceModel(), &IncidenceTreeModel::dataChanged, this, &IncidenceTreeModelPrivate::onDataChanged);
disconnect(q->sourceModel(), &IncidenceTreeModel::headerDataChanged, this, &IncidenceTreeModel::Private::onHeaderDataChanged);
disconnect(q->sourceModel(), &IncidenceTreeModel::headerDataChanged, this, &IncidenceTreeModelPrivate::onHeaderDataChanged);
disconnect(q->sourceModel(), &IncidenceTreeModel::rowsInserted, this, &IncidenceTreeModel::Private::onRowsInserted);
disconnect(q->sourceModel(), &IncidenceTreeModel::rowsInserted, this, &IncidenceTreeModelPrivate::onRowsInserted);
disconnect(q->sourceModel(), &IncidenceTreeModel::rowsRemoved, this, &IncidenceTreeModel::Private::onRowsRemoved);
disconnect(q->sourceModel(), &IncidenceTreeModel::rowsRemoved, this, &IncidenceTreeModelPrivate::onRowsRemoved);
disconnect(q->sourceModel(), &IncidenceTreeModel::rowsMoved, this, &IncidenceTreeModel::Private::onRowsMoved);
disconnect(q->sourceModel(), &IncidenceTreeModel::rowsMoved, this, &IncidenceTreeModelPrivate::onRowsMoved);
disconnect(q->sourceModel(), &IncidenceTreeModel::rowsAboutToBeInserted, this, &IncidenceTreeModel::Private::onRowsAboutToBeInserted);
disconnect(q->sourceModel(), &IncidenceTreeModel::rowsAboutToBeInserted, this, &IncidenceTreeModelPrivate::onRowsAboutToBeInserted);
disconnect(q->sourceModel(), &IncidenceTreeModel::rowsAboutToBeRemoved, this, &IncidenceTreeModel::Private::onRowsAboutToBeRemoved);
disconnect(q->sourceModel(), &IncidenceTreeModel::rowsAboutToBeRemoved, this, &IncidenceTreeModelPrivate::onRowsAboutToBeRemoved);
disconnect(q->sourceModel(), &IncidenceTreeModel::modelAboutToBeReset, this, &IncidenceTreeModel::Private::onModelAboutToBeReset);
disconnect(q->sourceModel(), &IncidenceTreeModel::modelAboutToBeReset, this, &IncidenceTreeModelPrivate::onModelAboutToBeReset);
disconnect(q->sourceModel(), &IncidenceTreeModel::modelReset, this, &IncidenceTreeModel::Private::onModelReset);
disconnect(q->sourceModel(), &IncidenceTreeModel::modelReset, this, &IncidenceTreeModelPrivate::onModelReset);
disconnect(q->sourceModel(), &IncidenceTreeModel::layoutAboutToBeChanged, this, &IncidenceTreeModel::Private::onLayoutAboutToBeChanged);
disconnect(q->sourceModel(), &IncidenceTreeModel::layoutAboutToBeChanged, this, &IncidenceTreeModelPrivate::onLayoutAboutToBeChanged);
disconnect(q->sourceModel(), &IncidenceTreeModel::layoutChanged, this, &IncidenceTreeModel::Private::onLayoutChanged);
disconnect(q->sourceModel(), &IncidenceTreeModel::layoutChanged, this, &IncidenceTreeModelPrivate::onLayoutChanged);
}
q->QAbstractProxyModel::setSourceModel(model);
if (q->sourceModel()) {
connect(q->sourceModel(), &IncidenceTreeModel::dataChanged, this, &IncidenceTreeModel::Private::onDataChanged);
connect(q->sourceModel(), &IncidenceTreeModel::dataChanged, this, &IncidenceTreeModelPrivate::onDataChanged);
connect(q->sourceModel(), &IncidenceTreeModel::headerDataChanged, this, &IncidenceTreeModel::Private::onHeaderDataChanged);
connect(q->sourceModel(), &IncidenceTreeModel::headerDataChanged, this, &IncidenceTreeModelPrivate::onHeaderDataChanged);
connect(q->sourceModel(), &IncidenceTreeModel::rowsAboutToBeInserted, this, &IncidenceTreeModel::Private::onRowsAboutToBeInserted);
connect(q->sourceModel(), &IncidenceTreeModel::rowsAboutToBeInserted, this, &IncidenceTreeModelPrivate::onRowsAboutToBeInserted);
connect(q->sourceModel(), &IncidenceTreeModel::rowsInserted, this, &IncidenceTreeModel::Private::onRowsInserted);
connect(q->sourceModel(), &IncidenceTreeModel::rowsInserted, this, &IncidenceTreeModelPrivate::onRowsInserted);
connect(q->sourceModel(), &IncidenceTreeModel::rowsAboutToBeRemoved, this, &IncidenceTreeModel::Private::onRowsAboutToBeRemoved);
connect(q->sourceModel(), &IncidenceTreeModel::rowsAboutToBeRemoved, this, &IncidenceTreeModelPrivate::onRowsAboutToBeRemoved);
connect(q->sourceModel(), &IncidenceTreeModel::rowsRemoved, this, &IncidenceTreeModel::Private::onRowsRemoved);
connect(q->sourceModel(), &IncidenceTreeModel::rowsRemoved, this, &IncidenceTreeModelPrivate::onRowsRemoved);
connect(q->sourceModel(), &IncidenceTreeModel::rowsMoved, this, &IncidenceTreeModel::Private::onRowsMoved);
connect(q->sourceModel(), &IncidenceTreeModel::rowsMoved, this, &IncidenceTreeModelPrivate::onRowsMoved);
connect(q->sourceModel(), &IncidenceTreeModel::modelAboutToBeReset, this, &IncidenceTreeModel::Private::onModelAboutToBeReset);
connect(q->sourceModel(), &IncidenceTreeModel::modelAboutToBeReset, this, &IncidenceTreeModelPrivate::onModelAboutToBeReset);
connect(q->sourceModel(), &IncidenceTreeModel::modelReset, this, &IncidenceTreeModel::Private::onModelReset);
connect(q->sourceModel(), &IncidenceTreeModel::modelReset, this, &IncidenceTreeModelPrivate::onModelReset);
connect(q->sourceModel(), &IncidenceTreeModel::layoutAboutToBeChanged, this, &IncidenceTreeModel::Private::onLayoutAboutToBeChanged);
connect(q->sourceModel(), &IncidenceTreeModel::layoutAboutToBeChanged, this, &IncidenceTreeModelPrivate::onLayoutAboutToBeChanged);
connect(q->sourceModel(), &IncidenceTreeModel::layoutChanged, this, &IncidenceTreeModel::Private::onLayoutChanged);
connect(q->sourceModel(), &IncidenceTreeModel::layoutChanged, this, &IncidenceTreeModelPrivate::onLayoutChanged);
}
reset(/**silent=*/true);
......@@ -632,22 +631,19 @@ void IncidenceTreeModel::Private::setSourceModel(QAbstractItemModel *model)
IncidenceTreeModel::IncidenceTreeModel(QObject *parent)
: QAbstractProxyModel(parent)
, d(new Private(this, QStringList()))
, d(new IncidenceTreeModelPrivate(this, QStringList()))
{
setObjectName(QStringLiteral("IncidenceTreeModel"));
}
IncidenceTreeModel::IncidenceTreeModel(const QStringList &mimeTypes, QObject *parent)
: QAbstractProxyModel(parent)
, d(new Private(this, mimeTypes))
, d(new IncidenceTreeModelPrivate(this, mimeTypes))
{
setObjectName(QStringLiteral("IncidenceTreeModel"));
}
IncidenceTreeModel::~IncidenceTreeModel()
{
delete d;
}
IncidenceTreeModel::~IncidenceTreeModel() = default;
QVariant IncidenceTreeModel::data(const QModelIndex &index, int role) const
{
......@@ -697,7 +693,7 @@ QModelIndex IncidenceTreeModel::mapFromSource(const QModelIndex &sourceIndex) co
{
if (!sourceIndex.isValid()) {
// qCWarning(CALENDARVIEW_LOG) << "IncidenceTreeModel::mapFromSource() source index is invalid";
// Q_ASSERT( false );
// Q_ASSERT( false );
return {};
}
......
......@@ -17,6 +17,10 @@
#include <QAbstractProxyModel>
#include <memory>
class IncidenceTreeModelPrivate;
class EVENTVIEWS_EXPORT IncidenceTreeModel : public QAbstractProxyModel
{
Q_OBJECT
......@@ -82,6 +86,6 @@ Q_SIGNALS:
void batchInsertionFinished();
private:
class Private;
Private *const d;
friend class IncidenceTreeModelPrivate;
std::unique_ptr<IncidenceTreeModelPrivate> const d;
};
......@@ -53,11 +53,11 @@ struct PreNode {
}
};
class IncidenceTreeModel::Private : public QObject
class IncidenceTreeModelPrivate : public QObject
{
Q_OBJECT
public:
Private(IncidenceTreeModel *qq, const QStringList &mimeTypes);
IncidenceTreeModelPrivate(IncidenceTreeModel *qq, const QStringList &mimeTypes);
void reset(bool silent = false);
void insertNode(const PreNode::Ptr &node, bool silent = false);
void insertNode(const QModelIndex &sourceIndex, bool silent = false);
......
/*
SPDX-FileCopyrightText: 2008 Thomas Thrainer <tom_t@gmx.at>
SPDX-FileCopyrightText: 2012 Sérgio Martins <iamsergio@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later WITH LicenseRef-Qt-Commercial-exception-1.0
SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
*/
#include "incidencetreemodel.h"
......@@ -50,14 +49,14 @@ static bool isDueToday(const KCalendarCore::Todo::Ptr &todo)
return !todo->isCompleted() && todo->dtDue().date() == QDate::currentDate();
}
TodoModel::Private::Private(const EventViews::PrefsPtr &preferences, TodoModel *qq)
TodoModelPrivate::TodoModelPrivate(const EventViews::PrefsPtr &preferences, TodoModel *qq)
: QObject()
, m_preferences(preferences)
, q(qq)
{
}
Akonadi::Item TodoModel::Private::findItemByUid(const QString &uid, const QModelIndex &parent) const
Akonadi::Item TodoModelPrivate::findItemByUid(const QString &uid, const QModelIndex &parent) const
{
Q_ASSERT(!uid.isEmpty());
auto treeModel = qobject_cast<IncidenceTreeModel *>(q->sourceModel());
......@@ -84,7 +83,7 @@ Akonadi::Item TodoModel::Private::findItemByUid(const QString &uid, const QModel
return item;
}
void TodoModel::Private::onDataChanged(const QModelIndex &begin, const QModelIndex &end)
void TodoModelPrivate::onDataChanged(const QModelIndex &begin, const QModelIndex &end)
{
Q_ASSERT(begin.isValid());
Q_ASSERT(end.isValid());
......@@ -94,12 +93,12 @@ void TodoModel::Private::onDataChanged(const QModelIndex &begin, const QModelInd
Q_EMIT q->dataChanged(proxyBegin, proxyEnd.sibling(proxyEnd.row(), TodoModel::ColumnCount - 1));
}
void TodoModel::Private::onHeaderDataChanged(Qt::Orientation orientation, int first, int last)
void TodoModelPrivate::onHeaderDataChanged(Qt::Orientation orientation, int first, int last)
{
Q_EMIT q->headerDataChanged(orientation, first, last);
}
void TodoModel::Private::onRowsAboutToBeInserted(const QModelIndex &parent, int begin, int end)
void TodoModelPrivate::onRowsAboutToBeInserted(const QModelIndex &parent, int begin, int end)
{
const QModelIndex index = q->mapFromSource(parent);
Q_ASSERT(!(parent.isValid() ^ index.isValid())); // Both must be valid, or both invalid
......@@ -108,12 +107,12 @@ void TodoModel::Private::onRowsAboutToBeInserted(const QModelIndex &parent, int
q->beginInsertRows(index, begin, end);
}
void TodoModel::Private::onRowsInserted(const QModelIndex &, int, int)
void TodoModelPrivate::onRowsInserted(const QModelIndex &, int, int)
{
q->endInsertRows();
}
void TodoModel::Private::onRowsAboutToBeRemoved(const QModelIndex &parent, int begin, int end)
void TodoModelPrivate::onRowsAboutToBeRemoved(const QModelIndex &parent, int begin, int end)
{
const QModelIndex index = q->mapFromSource(parent);
Q_ASSERT(!(parent.isValid() ^ index.isValid())); // Both must be valid, or both invalid
......@@ -122,16 +121,16 @@ void TodoModel::Private::onRowsAboutToBeRemoved(const QModelIndex &parent, int b
q->beginRemoveRows(index, begin, end);
}
void TodoModel::Private::onRowsRemoved(const QModelIndex &, int, int)
void TodoModelPrivate::onRowsRemoved(const QModelIndex &, int, int)
{
q->endRemoveRows();
}
void TodoModel::Private::onRowsAboutToBeMoved(const QModelIndex &sourceParent,
int sourceStart,
int sourceEnd,
const QModelIndex &destinationParent,
int destinationRow)
void TodoModelPrivate::onRowsAboutToBeMoved(const QModelIndex &sourceParent,
int sourceStart,
int sourceEnd,
const QModelIndex &destinationParent,
int destinationRow)
{
Q_UNUSED(sourceParent)
Q_UNUSED(sourceStart)
......@@ -144,22 +143,22 @@ void TodoModel::Private::onRowsAboutToBeMoved(const QModelIndex &sourceParent,
*/
}
void TodoModel::Private::onRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)
void TodoModelPrivate::onRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)
{
/*q->endMoveRows();*/
}
void TodoModel::Private::onModelAboutToBeReset()
void TodoModelPrivate::onModelAboutToBeReset()
{
q->beginResetModel();
}
void TodoModel::Private::onModelReset()
void TodoModelPrivate::onModelReset()
{
q->endResetModel();
}
void TodoModel::Private::onLayoutAboutToBeChanged()
void TodoModelPrivate::onLayoutAboutToBeChanged()
{
Q_ASSERT(m_persistentIndexes.isEmpty());
Q_ASSERT(m_layoutChangePersistentIndexes.isEmpty());
......@@ -177,7 +176,7 @@ void TodoModel::Private::onLayoutAboutToBeChanged()
Q_EMIT q->layoutAboutToBeChanged();
}
void TodoModel::Private::onLayoutChanged()
void TodoModelPrivate::onLayoutChanged()
{
for (int i = 0; i < m_persistentIndexes.size(); ++i) {
QModelIndex newIndex_col0 = q->mapFromSource(m_layoutChangePersistentIndexes.at(i));
......@@ -195,15 +194,12 @@ void TodoModel::Private::onLayoutChanged()
TodoModel::TodoModel(const EventViews::PrefsPtr &preferences, QObject *parent)
: QAbstractProxyModel(parent)
, d(new Private(preferences, this))
, d(new TodoModelPrivate(preferences, this))
{
setObjectName(QStringLiteral("TodoModel"));
}
TodoModel::~TodoModel()
{
delete d;
}
TodoModel::~TodoModel() = default;
QVariant TodoModel::data(const QModelIndex &index, int role) const
{
......@@ -220,7 +216,7 @@ QVariant TodoModel::data(const QModelIndex &index, int role) const
const auto item = sourceIndex.data(Akonadi::EntityTreeModel::ItemRole).value<Akonadi::Item>();
if (!item.isValid()) {
// qCWarning(CALENDARVIEW_LOG) << "Invalid index: " << sourceIndex;
// Q_ASSERT( false );
// Q_ASSERT( false );
return QVariant();
}
const KCalendarCore::Todo::Ptr todo = CalendarSupport::todo(item);
......@@ -297,6 +293,8 @@ QVariant TodoModel::data(const QModelIndex &index, int role) const
return todo->hasStartDate() ? QLocale().toString(todo->dtStart().toLocalTime().date(), QLocale::ShortFormat) : QVariant(QString());
case DueDateColumn:
return todo->hasDueDate() ? QLocale().toString(todo->dtDue().toLocalTime().date(), QLocale::ShortFormat) : QVariant(QString());
case CompletedDateColumn:
return todo->hasCompletedDate() ? QLocale().toString(todo->completed().toLocalTime().date(), QLocale::ShortFormat) : QVariant(QString());
case CategoriesColumn: {
QString categories = todo->categories().join(i18nc("delimiter for joining category/tag names", ","));
return QVariant(categories);
......@@ -323,6 +321,8 @@ QVariant TodoModel::data(const QModelIndex &index, int role) const
return QVariant(todo->dtStart().date());
case DueDateColumn:
return QVariant(todo->dtDue().date());
case CompletedDateColumn:
return QVariant(todo->completed().date());
case CategoriesColumn:
return QVariant(todo->categories());
case DescriptionColumn:
......@@ -368,15 +368,12 @@ QVariant TodoModel::data(const QModelIndex &index, int role) const
// icon for recurring todos
// It's in the summary column so you don't accidentally click
// the checkbox ( which increments the next occurrence date ).
// category colour
if (role == Qt::DecorationRole && index.column() == SummaryColumn) {
if (todo->recurs()) {
return QVariant(QIcon::fromTheme(QStringLiteral("task-recurring")));
}
}
// category colour
if (role == Qt::DecorationRole && index.column() == SummaryColumn) {
QStringList categories = todo->categories();
const QStringList categories = todo->categories();
return categories.isEmpty() ? QVariant() : QVariant(CalendarSupport::KCalPrefs::instance()->categoryColor(categories.first()));
} else if (role == Qt::DecorationRole) {
return QVariant();
......@@ -386,6 +383,10 @@ QVariant TodoModel::data(const QModelIndex &index, int role) const
return QVariant::fromValue(item);
}
if (role == TodoPtrRole) {
return QVariant::fromValue(todo);
}
if (role == IsRichTextRole) {
if (index.column() == SummaryColumn) {
return QVariant(todo->summaryIsRich());
......@@ -532,54 +533,60 @@ void TodoModel::setSourceModel(QAbstractItemModel *model)
beginResetModel();
if (sourceModel()) {
disconnect(sourceModel(), &QAbstractItemModel::dataChanged, d, &TodoModel::Private::onDataChanged);
disconnect(sourceModel(), &QAbstractItemModel::headerDataChanged, d, &TodoModel::Private::onHeaderDataChanged);
disconnect(sourceModel(), SIGNAL(dataChanged(QModelIndex, QModelIndex)), d.get(), SLOT(onDataChanged(QModelIndex, QModelIndex)));
disconnect(sourceModel(), SIGNAL(headerDataChanged(Qt::Orientation, int, int)), d.get(), SLOT(onHeaderDataChanged(Qt::Orientation, int, int)));
disconnect(sourceModel(), &QAbstractItemModel::rowsInserted, d, &TodoModel::Private::onRowsInserted);
disconnect(sourceModel(), SIGNAL(rowsInserted(QModelIndex, int, int)), d.get(), SLOT(onRowsInserted(QModelIndex, int, int)));
disconnect(sourceModel(), &QAbstractItemModel::rowsRemoved, d, &TodoModel::Private::onRowsRemoved);
disconnect(sourceModel(), SIGNAL(rowsRemoved(QModelIndex, int, int)), d.get(), SLOT(onRowsRemoved(QModelIndex, int, int)));
disconnect(sourceModel(), &QAbstractItemModel::rowsMoved, d, &TodoModel::Private::onRowsMoved);
disconnect(sourceModel(),
SIGNAL(rowsMoved(QModelIndex, int, int, QModelIndex, int)),
d.get(),
SLOT(onRowsMoved(QModelIndex, int, int, QModelIndex, int)));
disconnect(sourceModel(), &QAbstractItemModel::rowsAboutToBeInserted, d, &TodoModel::Private::onRowsAboutToBeInserted);
disconnect(sourceModel(), SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), d.get(), SLOT(onRowsAboutToBeInserted(QModelIndex, int, int)));
disconnect(sourceModel(), &QAbstractItemModel::rowsAboutToBeRemoved, d, &TodoModel::Private::onRowsAboutToBeRemoved);
disconnect(sourceModel(), SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), d.get(), SLOT(onRowsAboutToBeRemoved(QModelIndex, int, int)));
disconnect(sourceModel(), &QAbstractItemModel::modelAboutToBeReset, d, &TodoModel::Private::onModelAboutToBeReset);
disconnect(sourceModel(), SIGNAL(modelAboutToBeReset()), d.get(), SLOT(onModelAboutToBeReset()));
disconnect(sourceModel(), &QAbstractItemModel::modelReset, d, &TodoModel::Private::onModelReset);
disconnect(sourceModel(), SIGNAL(modelReset()), d.get(), SLOT(onModelReset()));
disconnect(sourceModel(), &QAbstractItemModel::layoutAboutToBeChanged, d, &TodoModel::Private::onLayoutAboutToBeChanged);
disconnect(sourceModel(), SIGNAL(layoutAboutToBeChanged()), d.get(), SLOT(onLayoutAboutToBeChanged()));