1 /* 2 Task.h 3 4 This file is part of Charm, a task-based time tracking application. 5 6 Copyright (C) 2007-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com 7 8 Author: Mirko Boehm <mirko.boehm@kdab.com> 9 10 This program is free software; you can redistribute it and/or modify 11 it under the terms of the GNU General Public License as published by 12 the Free Software Foundation, either version 2 of the License, or 13 (at your option) any later version. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program. If not, see <http://www.gnu.org/licenses/>. 22 */ 23 24 #ifndef TASK_H 25 #define TASK_H 26 27 #include <map> 28 29 #include <QList> 30 #include <QString> 31 #include <QtDebug> 32 #include <QMetaType> 33 #include <QDomElement> 34 #include <QDomDocument> 35 #include <QDateTime> 36 37 typedef int TaskId; 38 Q_DECLARE_METATYPE(TaskId) 39 40 class Task; 41 /** A task list is a list of tasks that belong together. 42 Example: All tasks for one user. */ 43 typedef QList<Task> TaskList; 44 typedef QList<TaskId> TaskIdList; 45 46 /** A task is a category under which events are filed. 47 It has a unique identifier and a name. */ 48 class Task 49 { 50 public: 51 Task(); 52 /** Convenience constructor. */ 53 Task(TaskId id, const QString &name, TaskId parent = 0, bool subscribed = false); 54 55 bool isValid() const; 56 57 bool operator ==(const Task &other) const; 58 bool operator !=(const Task &other) const 59 { 60 return !operator==(other); 61 } 62 63 TaskId id() const; 64 65 void setId(TaskId id); 66 67 QString name() const; 68 69 void setName(const QString &name); 70 71 TaskId parent() const; 72 73 void setParent(TaskId parent); 74 75 bool subscribed() const; 76 77 void setSubscribed(bool value); 78 79 QDateTime validFrom() const; 80 81 void setValidFrom(const QDateTime &); 82 83 QDateTime validUntil() const; 84 85 void setValidUntil(const QDateTime &); 86 87 bool isCurrentlyValid() const; 88 89 void setTrackable(bool trackable); 90 bool trackable() const; 91 92 QString comment() const; 93 void setComment(const QString &comment); 94 95 void dump() const; 96 97 static QString tagName(); 98 static QString taskListTagName(); 99 100 QDomElement toXml(QDomDocument) const; 101 102 static Task fromXml(const QDomElement &, int databaseSchemaVersion = 1); 103 104 static TaskList readTasksElement(const QDomElement &, int databaseSchemaVersion = 1); 105 106 static QDomElement makeTasksElement(QDomDocument, const TaskList &); 107 108 static bool checkForUniqueTaskIds(const TaskList &tasks); 109 110 static bool checkForTreeness(const TaskList &tasks); 111 112 static bool lowerTaskId(const Task &left, const Task &right); 113 114 private: 115 int m_id = 0; 116 int m_parent = 0; 117 QString m_name; 118 bool m_subscribed = false; 119 bool m_trackable = true; 120 /** The timestamp from which the task is valid. */ 121 QDateTime m_validFrom; 122 /** The timestamp after which the task becomes invalid. */ 123 QDateTime m_validUntil; 124 QString m_comment; 125 }; 126 127 Q_DECLARE_METATYPE(TaskIdList) 128 Q_DECLARE_METATYPE(TaskList) 129 Q_DECLARE_METATYPE(Task) 130 131 void dumpTaskList(const TaskList &tasks); 132 133 #endif 134