Merge branch 'master' of github.com:zanettea/SAK
[Sak.git] / task.h
blobc11ca34d924c7982fe23ec0bcc92eba6f3bfd948
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 QDate dueDate;
38 int estimatedHours;
39 QPixmap icon;
40 QColor bgColor, fgColor;
41 QHash< QString, SubTask > subTasks;
42 QHash< QString, QList< Hit > > hits; // hits for each subtask
43 bool active;
45 void updateSubTasks();
46 double totHours, totOverestimation;
47 double workedHours(const QDateTime& from, const QDateTime& to) const;
48 // also set totHours
49 bool checkConsistency();
50 // get hours from value
51 static double hours(int v) { return (double)v/60.0; }
54 static inline bool operator == (const Task::Hit& h1, const Task::Hit& h2) {
55 return h1.timestamp == h2.timestamp && h1.duration == h2.duration;
58 // Used by gui
59 struct HitElement
61 Task* task;
62 QString subtask;
63 QDateTime timestamp;
64 int duration;
65 bool editable;
66 HitElement(Task* t = 0, const QString& subtask = QString(), const QDateTime& tt = QDateTime(), int d=0, bool edit=true)
67 : task(t)
68 , subtask(subtask)
69 , timestamp(tt)
70 , duration(d)
71 , editable(edit) {}
72 static double overestimations(const QList<HitElement>&, QVector<double>&, double&);
73 bool operator<(const HitElement& o) const {
74 return timestamp < o.timestamp;
77 Q_DECLARE_METATYPE(HitElement)
80 QDataStream & operator<< ( QDataStream & out, const Task & task );
81 QDataStream & operator>> ( QDataStream & in, Task & task );
84 QDataStream & operator<< ( QDataStream & out, const Task::Hit & hit );
85 QDataStream & operator>> ( QDataStream & in, Task::Hit & hit );
88 QXmlStreamWriter & operator<< ( QXmlStreamWriter & out, const Task & task );
89 QXmlStreamReader & operator>> ( QXmlStreamReader & in, Task & task );
92 #endif