25
25
#ifndef KOTODOMODEL_H
26
26
#define KOTODOMODEL_H
28
#include <kcalcore/todo.h>
28
30
#include <QAbstractItemModel>
29
#include <QStringList>
34
#include <Akonadi/Item>
36
using namespace KCalCore;
38
namespace CalendarSupport {
44
class IncidenceChangerBase;
40
class IncidenceChanger;
49
44
@author Thomas Thrainer
74
explicit KOTodoModel( Calendar *cal, QObject *parent = 0 );
71
explicit KOTodoModel( QObject *parent = 0 );
75
72
virtual ~KOTodoModel();
77
74
/** Set the calendar */
78
void setCalendar( Calendar *cal );
75
void setCalendar( CalendarSupport::Calendar *cal );
79
76
/** Resets the model and deletes the whole todo tree */
81
78
/** Reloads all todos from the Calendar provided during construction */
82
79
void reloadTodos();
83
80
/** Reloads only the specified todo (if the incidence is a todo) */
84
void processChange( Incidence *incidence, int action );
81
void processChange( const Akonadi::Item &incidence, int action );
86
/** Creates a new todo with the given text as summary under the given parent */
87
QModelIndex addTodo( const QString &summary,
88
const QModelIndex &parent = QModelIndex(),
89
const QStringList &categories = QStringList() );
90
/** Copy the todo with the given index to the given date */
91
void copyTodo( const QModelIndex &index, const QDate &date );
83
Akonadi::Item todoForIndex( const QModelIndex &idx ) const;
93
85
/** Sets the incidence changer used to edit incidences (todos)
95
87
* @param changer Pointer to the changer to use.
97
void setIncidenceChanger( IncidenceChangerBase *changer )
89
void setIncidenceChanger( CalendarSupport::IncidenceChanger *changer )
98
90
{ mChanger = changer; }
100
92
virtual Qt::ItemFlags flags( const QModelIndex &index ) const;
149
141
/** Move the TodoTreeNode if the relationship of the todo's parent has
150
142
* changed and return a model index to the current node.
152
QModelIndex moveIfParentChanged( TodoTreeNode *curNode, Todo *todo,
144
QModelIndex moveIfParentChanged( TodoTreeNode *curNode, const Akonadi::Item &todo,
153
145
bool addParentIfMissing );
155
/** Recursively find a todo.
157
* @param todo Pointer to the todo to find.
158
* @return Pointer to the TodoTreeNode node which represents the todo
159
* searched for or 0 if not found.
161
TodoTreeNode *findTodo( const Todo *todo ) const;
147
/** Recursively find a todo.
149
* @param uid uid to the todo to find.
150
* @return Pointer to the TodoTreeNode node which represents the todo
151
* searched for or 0 if not found.
153
TodoTreeNode *findTodo( const QString &uid ) const;
164
156
* If the todo is overdue or due today, the expandIndex signal
168
160
* @param todo the todo whose parents will be expanded if needed
170
void expandTodoIfNeeded( const Todo *todo );
162
void expandTodoIfNeeded( const Akonadi::Item &todo );
173
165
* Returns true if there's a loop, e.g.: t1 is parent of
176
168
* @param todo the todo that will be checked
178
bool isInHierarchyLoop( const Todo *todo ) const;
170
bool isInHierarchyLoop( const KCalCore::Todo::Ptr &todo ) const;
180
172
/** Insert a todo at the right place in the todo tree.
185
177
* recursively linked todos.
186
178
* @return Pointer to the newly inserted TodoTreeNode node.
188
TodoTreeNode *insertTodo( Todo *todo, bool checkRelated = true );
180
TodoTreeNode *insertTodo( const Akonadi::Item &todo, bool checkRelated = true );
190
182
/** Count of columns each item has */
191
183
const int mColumnCount;
193
185
/** Calendar to get data from */
186
CalendarSupport::Calendar *mCalendar;
195
187
/** Root elements of the todo tree. */
196
188
TodoTreeNode *mRootNode;
197
189
/** Hash to speed up searching todo by their uid */
198
QHash<QString, TodoTreeNode*> mTodoHash;
200
/** This IncidenceChanger is used to change todos */
201
IncidenceChangerBase *mChanger;
190
QHash<Akonadi::Item::Id, TodoTreeNode*> mTodoHash;
192
QHash<QString, TodoTreeNode*> mTodoUidHash;
194
/** This CalendarSupport::IncidenceChanger is used to change todos */
195
CalendarSupport::IncidenceChanger *mChanger;
203
197
/** Display the todos without hierarchy? */
207
DndFactory *mDndFactory;