-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTask.cpp
More file actions
89 lines (66 loc) · 1.41 KB
/
Task.cpp
File metadata and controls
89 lines (66 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "Task.h"
#include "misc.h"
Task::Task(QObject *parent)
: QObject(parent)
, name("")
, id(-1)
, time(0)
, timeOfToggle(0)
, active(false)
{
}
Task::~Task() {
}
void Task::setId(const int id) {
this->id = id;
}
void Task::setName(const QString name) {
this->name = name;
}
void Task::setTime(const int time) {
// We temporarily stop the timer when setting its time.
// Otherwise the difference between the timer's initial value and its
// stopping time would not equal its duration
bool wasActive = isActive();
setActive(false);
this->time = time;
timeOfToggle = time;
setActive(wasActive);
}
void Task::setActive(bool active) {
bool isToggled = (this->active != active);
this->active = active;
if(isToggled) {
timeOfToggle = time;
emit toggled(active);
}
}
void Task::toggle() {
setActive(!isActive());
}
void Task::tick() {
if(active) {
time++;
}
}
int Task::getId() const {
return id;
}
QString Task::getName() const {
return name;
}
int Task::getTotalTime() const {
return time;
}
int Task::getCurrentDuration() const {
return time - timeOfToggle;
}
bool Task::isActive() const {
return active;
}
QString Task::toText() const {
QString timeString = timeToString(getTotalTime());
return QString("%1 (%2)")
.arg(getName())
.arg(timeString);
}