fixes and improvements
[Sak.git] / task.h
blob58467c89e6a1acef4657c38f7fd2a569fcbc5625
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 QDate dueDate;
39 int estimatedHours;
40 QPixmap icon;
41 QColor bgColor, fgColor;
42 QHash< QString, SubTask > subTasks;
43 QHash< QString, QList< Hit > > hits; // hits for each subtask
44 bool active;
46 void updateSubTasks();
47 double totHours, totOverestimation;
48 double workedHours(const QDateTime& from, const QDateTime& to) const;
49 // also set totHours
50 bool checkConsistency();
51 // get hours from value
52 static double hours(int v) { return (double)v/60.0; }
55 static inline bool operator == (const Task::Hit& h1, const Task::Hit& h2) {
56 return h1.timestamp == h2.timestamp && h1.duration == h2.duration;
59 // Used by gui
60 struct HitElement
62 Task* task;
63 QString subtask;
64 QDateTime timestamp;
65 int duration;
66 bool editable;
67 HitElement(Task* t = 0, const QString& subtask = QString(), const QDateTime& tt = QDateTime(), int d=0, bool edit=true)
68 : task(t)
69 , subtask(subtask)
70 , timestamp(tt)
71 , duration(d)
72 , editable(edit) {}
73 static double overestimations(const QList<HitElement>&, QVector<double>&, double&);
74 bool operator<(const HitElement& o) const {
75 return timestamp < o.timestamp;
78 Q_DECLARE_METATYPE(HitElement)
81 inline QDebug & operator << (QDebug & out, Task::Hit& taskHit)
83 out << taskHit.timestamp << ":" << taskHit.duration;
84 return out;
87 QDataStream & operator<< ( QDataStream & out, const Task & task );
88 QDataStream & operator>> ( QDataStream & in, Task & task );
91 QDataStream & operator<< ( QDataStream & out, const Task::Hit & hit );
92 QDataStream & operator>> ( QDataStream & in, Task::Hit & hit );
95 QXmlStreamWriter & operator<< ( QXmlStreamWriter & out, const Task & task );
96 QXmlStreamReader & operator>> ( QXmlStreamReader & in, Task & task );
99 #endif