- recover from backup files
[Sak.git] / task.h
blob4b435a9f601cbe13bc0339353576837f1d317b5f
1 #ifndef TASK_H_
2 #define TASK_H_
4 #include <QtGui>
5 #include <QXmlStreamWriter>
6 #include <QXmlStreamReader>
7 #include <math.h>
9 #define DATETIMEFORMAT "yyyy/MM/dd hh:mm:ss"
12 struct Task
14 struct SubTask
16 SubTask(const QString& t=QString()) : title(t), active(true) {}
17 QString title, description;
18 QColor bgColor, fgColor;
19 double totHours;
20 bool active;
23 struct Hit
25 Hit(const QDateTime& t=QDateTime::currentDateTime(), unsigned int d=0)
26 : timestamp(t)
27 , duration(d) {}
28 QDateTime timestamp;
29 int duration;
30 bool operator<(const Hit& o) const {
31 return timestamp < o.timestamp;
35 Task() : estimatedHours(0), bgColor(Qt::white), fgColor(Qt::black), active(true), totHours(0) {}
36 QString title, description;
37 QStringList tags;
38 QString url;
39 QDate dueDate;
40 int estimatedHours;
41 QPixmap icon;
42 QColor bgColor, fgColor;
43 QHash< QString, SubTask > subTasks;
44 QHash< QString, QList< Hit > > hits; // hits for each subtask
45 bool active;
47 void updateSubTasks();
48 double totHours, totOverestimation;
49 double workedHours(const QDateTime& from, const QDateTime& to) const;
50 // also set totHours
51 bool checkConsistency();
52 // get hours from value
53 static double hours(int v) { return (double)v/60.0; }
56 static inline bool operator == (const Task::Hit& h1, const Task::Hit& h2) {
57 return h1.timestamp == h2.timestamp && h1.duration == h2.duration;
60 // Used by gui
61 struct HitElement
63 Task* task;
64 QString subtask;
65 QDateTime timestamp;
66 int duration;
67 bool editable;
68 HitElement(Task* t = 0, const QString& subtask = QString(), const QDateTime& tt = QDateTime(), int d=0, bool edit=true)
69 : task(t)
70 , subtask(subtask)
71 , timestamp(tt)
72 , duration(d)
73 , editable(edit) {}
74 static double overestimations(const QList<HitElement>&, QVector<double>&, double&);
75 bool operator<(const HitElement& o) const {
76 return timestamp < o.timestamp;
79 Q_DECLARE_METATYPE(HitElement)
82 inline QDebug & operator << (QDebug & out, Task::Hit& taskHit)
84 out << taskHit.timestamp << ":" << taskHit.duration;
85 return out;
88 QDataStream & operator<< ( QDataStream & out, const Task & task );
89 QDataStream & operator>> ( QDataStream & in, Task & task );
92 QDataStream & operator<< ( QDataStream & out, const Task::Hit & hit );
93 QDataStream & operator>> ( QDataStream & in, Task::Hit & hit );
96 QXmlStreamWriter & operator<< ( QXmlStreamWriter & out, const Task & task );
97 QXmlStreamReader & operator>> ( QXmlStreamReader & in, Task & task );
100 #endif