-
Notifications
You must be signed in to change notification settings - Fork 2
/
schedule_table.cpp
64 lines (50 loc) · 1.64 KB
/
schedule_table.cpp
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
#include "schedule_table.h"
#include "ui_schedule_table.h"
#include <QTableWidgetItem>
#include <QColor>
#include <utility>
#include "appointment.h"
ScheduleTable::ScheduleTable(QWidget *parent) :
QDialog(parent),
ui(new Ui::ScheduleTable)
{
ui->setupUi(this);
tableWidget = ui->tableWidget;
}
ScheduleTable::~ScheduleTable()
{
delete ui;
}
void ScheduleTable::setData(const std::vector<Worker*>& workers) {
tableWidget->setColumnCount(workers.size());
bool shades[rows][workers.size()];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < workers.size(); j++) {
shades[i][j] = false;
}
}
for (int i = 0; i < workers.size(); i++) {
labels << workers[i]->getName().c_str();
for (auto& appointment : workers[i]->getSchedule()) {
auto start = appointment.getTimeOfDayStart();
auto end = appointment.getTimeOfDayEnd();
auto startSec = (start - shiftStart).total_seconds();
auto endSec = (end - shiftStart).total_seconds();
int startIdx = floorf(startSec / (mins_f * 60));
int endIdx = ceilf(endSec / (mins_f * 60));
for (int j = startIdx; j < endIdx; j++) {
shades[j][i] = true;
}
}
}
tableWidget->setHorizontalHeaderLabels(labels);
for (int i = 0; i < rows; i++) {
for (int j = 0; j < workers.size(); j++) {
QTableWidgetItem* qtwi = new QTableWidgetItem("");
if (shades[i][j]) {
qtwi->setBackground(QColor(34, 49, 63));
}
tableWidget->setItem(i, j, qtwi);
}
}
}