-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTaskStatisticsDialog.cpp
More file actions
82 lines (65 loc) · 2.38 KB
/
TaskStatisticsDialog.cpp
File metadata and controls
82 lines (65 loc) · 2.38 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
#include "TaskStatisticsDialog.h"
#include "ui_TaskStatisticsDialog.h"
#include "TaskLogger.h"
#include "TaskHistoryDialog.h"
#include "misc.h"
TaskStatisticsDialog::TaskStatisticsDialog(Task *task, QWidget *parent)
: QDialog(parent)
, ui(new Ui::TaskStatisticsDialog)
, task(task)
, totalTime(0)
, timeToday(0)
, timeThisWeek(0)
, timeThisMonth(0)
, timeThisYear(0)
, averageDuration(0)
, longestDuration(0)
{
ui->setupUi(this);
setWindowTitle(task->getName() + " - Statistics");
connect(ui->showHistoryButton, SIGNAL(clicked()), this, SLOT(showHistoryDialog()));
int numSessions = 0;
const QList<TaskSession> taskSessions = TaskLogger::getInstance()->getTaskSessions();
TaskSession taskSession;
foreach(taskSession, taskSessions) {
if(taskSession.taskId == task->getId()) {
QDate sessionDate = QDateTime::fromTime_t(taskSession.time).date();
if(sessionDate.day() == QDate::currentDate().day()) {
timeToday += taskSession.duration;
}
if(sessionDate.weekNumber() == QDate::currentDate().weekNumber()) {
timeThisWeek += taskSession.duration;
}
if(sessionDate.month() == QDate::currentDate().month()) {
timeThisMonth += taskSession.duration;
}
if(sessionDate.year() == QDate::currentDate().year()) {
timeThisYear += taskSession.duration;
}
totalTime += taskSession.duration;
longestDuration = qMax(longestDuration, taskSession.duration);
numSessions++;
}
}
if(numSessions > 0) {
averageDuration = qRound(float(totalTime) / numSessions);
}
ui->totalTime->setText(timeToString(totalTime));
ui->timeToday->setText(timeToString(timeToday));
ui->timeThisMonth->setText(timeToString(timeThisMonth));
ui->timeThisWeek->setText(timeToString(timeThisWeek));
ui->timeThisYear->setText(timeToString(timeThisYear));
// ui->averageDuration->setText(timeToString(averageDuration));
// ui->longestDuration->setText(timeToString(longestDuration));
// Resize to minimum size
resize(0, 0);
}
TaskStatisticsDialog::~TaskStatisticsDialog()
{
delete ui;
}
void TaskStatisticsDialog::showHistoryDialog() {
TaskHistoryDialog dialog(this);
dialog.showTask(task);
dialog.exec();
}