-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgantt.cpp
More file actions
208 lines (195 loc) · 7.46 KB
/
gantt.cpp
File metadata and controls
208 lines (195 loc) · 7.46 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include "gantt.h"
/**
* @brief Create a Gantt object
* @param db
*/
gantt::gantt(database *db)
{
this->db = db;
this->table->setAlternatingRowColors(true);
this->table->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
this->table->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
this->table->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
this->table->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
this->table->verticalHeader ()->setDefaultSectionSize(20);
QCoreApplication::instance()->installEventFilter(this);
this->targetItem = this->table->item(1, 0);
this->table->setEditTriggers(QAbstractItemView::NoEditTriggers);
this->table->setStyleSheet("QHeaderView::section{background-color: rgb(24, 26, 31); "
"color : rgb(214,216,218);} "
"QTableWidget {gridline-color: rgb(170,170,170); "
"alternate-background-color: rgb(47, 51, 61);background-color: rgb(24, 26, 31);}");
}
/**
* @brief gantt::~gantt
*/
gantt::~gantt()
{
this->db = NULL;
delete db;
this->table = NULL;
this->targetItem = NULL;
delete this->table;
delete this->targetItem;
}
/**
* @brief Build Gantt (item delegate painting)
* @param lst
* @param lstNumb
* @param col
* @param dayLength
* @param displayFrom
*/
void gantt::build(QStringList lst, QStringList lstNumb, int col, int dayLength[7], QDate displayFrom, bool editMode)
{
int row = lst.length();
QSqlQuery *optt = new QSqlQuery(this->db->db);
optt->exec("SELECT opt1 FROM parms");
optt->first();
int opt = optt->value("opt1").toInt();
QStringList headerH;
QStringList headerV;
this->table->setRowCount(row+1);
this->table->setColumnCount(col+1);
int day;
headerV << "Availability";
for(int i = 0; i<row; i++)
{
std::string s = lst.at(i).toStdString();
const char *a = s.c_str();
headerV << a;
}
headerH << "Completion";
for(int i = 0; i<col; i++)
{
std::string s = displayFrom.addDays(i).toString("dd-MM-yyyy").toStdString();
std::string k;
day = displayFrom.addDays(i).dayOfWeek();
switch (day) {
case 1:
k = "Mon "+s;
break;
case 2:
k = "Tue "+s;
break;
case 3:
k = "Wed "+s;
break;
case 4:
k = "Thu "+s;
break;
case 5:
k = "Fri "+s;
break;
case 6:
k = "Sat "+s;
break;
case 7:
k = "Sun "+s;
break;
}
const char *a = k.c_str();
headerH << a;
}
this->table->setHorizontalHeaderLabels(headerH);
this->table->setVerticalHeaderLabels(headerV);
int da;
int w = this->table->width()/(col+1);
this->table->setColumnWidth(0, 1*20);
//Completion
for(int j = 0; j<row; j++)
{
QSqlQueryModel *q = new QSqlQueryModel;
QString stcol = "SELECT duration as d FROM task WHERE number="
+QDateTime::fromString(lstNumb[j],"yyyyMMddhhmmssz").toString("yyyyMMddhhmmssz");
q->setQuery(stcol, db->db);
float ratio = float(db->getAlloc(QDateTime::fromString(lstNumb[j],"yyyyMMddhhmmssz")))/float(q->record(0).value("d").toInt());
int ratio1 = floor(5*ratio);
if(ratio1>5) ratio1 = 5;
std::vector<int> vect = {};
vect.push_back(ratio1);
QTableWidgetItem *item = new QTableWidgetItem;
StarRating sR(vect, 1,
QDateTime::currentDateTime(), QDateTime::currentDateTime(), Qt::red, false);
sR.setDB(this->db);
item->setData(0, QVariant::fromValue(sR));
table->setItem(j+1, 0, item);
}
for(int i = 0; i<col; i++)
{
da = displayFrom.addDays(i).dayOfWeek();
if(this->table->width()/(col+1)<(20*dayLength[da-1])) w = 20*dayLength[da-1];
if (dayLength[da-1] == 0) w = 20;
this->table->setItemDelegate(new StarDelegate);
StarDelegate *sD = static_cast<StarDelegate *>(this->table->itemDelegate());
sD->setAllocInt(opt);
std::vector<int> vect = {};
//Allocation count
if(opt)
{
for(int k = 0; k < dayLength[da-1]; k++)
{
int val = floor(5*db->isAllocated(QDateTime(displayFrom.addDays(i)), k)/opt);
if(val>5) val = 5;
vect.push_back(val);
}
}
else
{
for(int k = 0; k < dayLength[da-1]; k++)
{
if(db->isAllocated(QDateTime(displayFrom.addDays(i)), k))
vect.push_back(2);
else
vect.push_back(0);
}
}
QTableWidgetItem *item = new QTableWidgetItem;
StarRating sR(vect, dayLength[da-1],
QDateTime::currentDateTime(), QDateTime::currentDateTime(), Qt::transparent, false);
sR.setDB(this->db);
item->setData(0, QVariant::fromValue(sR));
table->setItem(0, i+1, item);
for(int j = 0; j<row; j++)
{
if(dayLength[da-1])
{
std::vector<int> vect = {};
for(int k = 0; k < dayLength[da-1]; k++) vect.push_back(0);
QSqlQueryModel *colo = new QSqlQueryModel;
QString stcol = "SELECT color as cl FROM task WHERE number="
+QDateTime::fromString(lstNumb[j],"yyyyMMddhhmmssz").toString("yyyyMMddhhmmssz");
colo->setQuery(stcol, db->db);
QSqlQueryModel *ct = new QSqlQueryModel;
QString st = "SELECT COUNT(*) as ct FROM allocation WHERE parentTask="
+QDateTime::fromString(lstNumb[j],"yyyyMMddhhmmssz").toString("yyyyMMddhhmmssz")+
" AND day="+displayFrom.addDays(i).toString("yyyyMMdd");
ct->setQuery(st, db->db);
QSqlQueryModel *mod = new QSqlQueryModel;
QString str = "SELECT value as val FROM allocation WHERE parentTask="
+QDateTime::fromString(lstNumb[j],"yyyyMMddhhmmssz").toString("yyyyMMddhhmmssz")+
" AND day="+displayFrom.addDays(i).toString("yyyyMMdd");
mod->setQuery(str, db->db);
QColor starColor = QColor(colo->record(0).value("cl").toString());
if(ct->record(0).value("ct").toInt())
for(int l = 0; l<ct->record(0).value("ct").toInt(); l++)
if(mod->record(l).value("val").toInt()<dayLength[da-1])
vect[mod->record(l).value("val").toInt()]++;
QTableWidgetItem *item = new QTableWidgetItem;
StarRating sR(vect, dayLength[da-1],
QDateTime::fromString(lstNumb[j],"yyyyMMddhhmmssz") , QDateTime(displayFrom.addDays(i)), starColor);
sR.setDB(this->db);
item->setData(0, QVariant::fromValue(sR));
table->setItem(j+1, i+1, item);
this->targetItem = this->table->item(j+1, i+1);
if(editMode)
this->table->openPersistentEditor(targetItem);
else
this->table->closePersistentEditor(targetItem);
}
}
this->table->setColumnWidth(i+1, w);
this->table->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
}
this->table->update();
}