-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
1272 lines (1129 loc) · 41.3 KB
/
mainwindow.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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
designHomePage();
designPage();
designParms();
designGanttPage();
designConnections();
designArchive();
designChargePage();
ui->stackedWidget->layout()->addWidget(ui->page_6);
ui->stackedWidget->layout()->addWidget(ui->page);
ui->stackedWidget->layout()->addWidget(ui->page_2);
ui->stackedWidget->layout()->addWidget(ui->page_3);
ui->stackedWidget->layout()->addWidget(ui->page_5);
ui->stackedWidget->layout()->addWidget(ui->page_4);
ui->stackedWidget->setCurrentIndex(crtPage);
this->selector->setStyleSheet("QPushButton{"
"font: 87 14pt;"
"border-color: #66767A;"
"color: black;"
"background-color: #9BB3B9;"
"border : 2px solid;"
"border-radius : 15px;"
"height : 1em;"
"width : 1em;}"
"QPushButton:hover{"
"background-color: #66767A;"
"color: #A6C0C6;"
"border-color: #A6C0C6;}"
"QPushButton:pressed{"
"background-color: #A6C0C6;"
"color: #66767A;"
"border-color: #66767A;}");
selector->setText("Menu");
QGridLayout *fl = new QGridLayout;
QWidget *widget = new QWidget();
widget->setStyleSheet("QWidget {color: #E6E6E8;}");
fl->addWidget(ui->stackedWidget, 0, 0, 2, 10);
fl->addWidget(selector, 0, 9, 1, 1);
widget->setLayout(fl);
this->setCentralWidget(widget);
this->setWindowState(Qt::WindowMaximized);
this->setWindowTitle("The Efficient Guy !");
this->setWindowIcon(QIcon(QCoreApplication::applicationDirPath() +"/icone.ico"));
connect(selector, SIGNAL(clicked()), this, SLOT(showMenu()));
}
/**
* @brief MainWindow::~MainWindow
*/
MainWindow::~MainWindow()
{
QSqlQueryModel *model4 = new QSqlQueryModel;
model4->setQuery("SELECT AVG(valeur) as val FROM (SELECT COUNT(*) as valeur FROM target GROUP BY parentTask)", db->db);
QSqlQueryModel *model5 = new QSqlQueryModel;
model5->setQuery("SELECT COUNT(*) as cnt FROM task", db->db);
QSqlQueryModel *model6 = new QSqlQueryModel;
model6->setQuery("SELECT COUNT(*) as cnt FROM task WHERE active=1", db->db);
this->db->updateMiscellaneous(this->timer->elapsed());
db->CloseDB();
this->db = NULL;
delete db;
this->crtDb = NULL;
this->subdbl = NULL;
this->bef = NULL;
this->aft = NULL;
this->adder = NULL;
this->g = NULL;
this->t1 = NULL;
this->t2 = NULL;
this->t3 = NULL;
this->t4 = NULL;
this->t5 = NULL;
this->timer = NULL;
this->ganttDisp = NULL;
this->b = NULL;
this->pageL = NULL;
this->col = NULL;
delete crtDb;
delete subdbl;
delete bef;
delete aft;
delete adder;
delete g;
delete t1;
delete t2;
delete t3;
delete t4;
delete t5;
delete timer;
delete ganttDisp;
delete b;
delete pageL;
delete col;
delete ui;
}
/**
* @brief Edit links between buttons and actions
*/
void MainWindow::designConnections()
{
connect(this->adder, SIGNAL(clicked()), this, SLOT(createTask()));
connect(this->bef, SIGNAL(clicked()), this, SLOT(prevDb()));
connect(this->aft, SIGNAL(clicked()), this, SLOT(nextDb()));
connect(ui->spinMonday, SIGNAL(valueChanged(int)), this, SLOT(setMon(int)));
connect(ui->spinTuesday, SIGNAL(valueChanged(int)), this, SLOT(setTue(int)));
connect(ui->spinWednesday, SIGNAL(valueChanged(int)), this, SLOT(setWed(int)));
connect(ui->spinThursday, SIGNAL(valueChanged(int)), this, SLOT(setThu(int)));
connect(ui->spinFriday, SIGNAL(valueChanged(int)), this, SLOT(setFri(int)));
connect(ui->spinSaturday, SIGNAL(valueChanged(int)), this, SLOT(setSat(int)));
connect(ui->spinSunday, SIGNAL(valueChanged(int)), this, SLOT(setSun(int)));
connect(ui->overloadOpt, SIGNAL(valueChanged(int)), this, SLOT(setOpt(int)));
connect(ui->displayTo, SIGNAL(dateChanged(QDate)), this, SLOT(rngGantt()));
connect(ui->displayArchive, SIGNAL(clicked()), this, SLOT(rngGantt()));
connect(ui->editModeButton, SIGNAL(clicked()), this, SLOT(rngGantt()));
connect(ui->displayFrom, SIGNAL(dateChanged(QDate)), this, SLOT(rngGantt()));
connect(ui->displayFrom, SIGNAL(dateChanged(QDate)), this, SLOT(rngGantt()));
connect(ui->stackedWidget, SIGNAL(currentChanged(int)), this, SLOT(refreshSelector(int)));
connect(ui->addDb, SIGNAL(clicked()), this, SLOT(addDb()));
connect(ui->dlDb, SIGNAL(clicked()), this, SLOT(dlDb()));
connect(ui->page_6, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(ShowContextMenu(const QPoint &)));
}
/**
* @brief Refresh the asked page (on screen swap)
* @param i
*/
void MainWindow::refreshSelector(int i)
{
switch(i)
{
case 0 :
loadHomePage();
break;
case 1 :
reloadPage();
break;
case 2 :
rngGantt();
break;
case 3:
loadPage();
break;
case 4:
loadArchive();
break;
}
}
/**
* @brief Refresh kanban
*/
void MainWindow::reloadPage()
{
QList<tray *> trays = this->findChildren<tray *>();
foreach(tray* T, trays)
{
QList<task *> tasks = T->findChildren<task *>();
foreach(task* t, tasks)
t->close();
load(T);
}
}
/**
* @brief Close DB and clean trays
*/
void MainWindow::kill()
{
db->CloseDB();
db->db.removeDatabase(db->db.connectionName());
QList<tray *> trays = this->findChildren<tray *>();
foreach(tray* T, trays)
{
QList<task *> tasks = T->findChildren<task *>();
foreach(task* t, tasks)
{
t->~task();
}
}
QList<postit *> note = ui->page_6->findChildren<postit *>();
foreach(postit* p, note)
p->~postit();
}
/**
* @brief Go to the previous Db
*/
void MainWindow::prevDb()
{
QString nameDb = db->prevDb();
kill();
this->db = new database(nameDb);
t1->changeDb(db);
t2->changeDb(db);
t3->changeDb(db);
t4->changeDb(db);
QList<tray *> trays = this->findChildren<tray *>();
foreach(tray* T, trays)
{
load(T);
}
crtDb->setText(nameDb.remove(".db"));
this->g->changeDb(db);
rngGantt();
update();
loadHomePage();
QSqlQueryModel *Notes = new QSqlQueryModel;
Notes->setQuery("SELECT id, x, y, text FROM note", db->db);
for(int i = 0; i<Notes->rowCount(); i++)
{
QPoint p = {Notes->record(i).value(1).toInt(), Notes->record(i).value(2).toInt()};
new postit(ui->page_6, db, p, Notes->record(i).value(3).toString(), Notes->record(i).value(0).toInt());
}
}
/**
* @brief Go to the next DB
*/
void MainWindow::nextDb()
{
QString nameDb = db->nextDb();
kill();
this->db = new database(nameDb);
t1->changeDb(db);
t2->changeDb(db);
t3->changeDb(db);
t4->changeDb(db);
QList<tray *> trays = this->findChildren<tray *>();
foreach(tray* T, trays)
{
load(T);
}
crtDb->setText(nameDb.remove(".db"));
this->g->changeDb(db);
rngGantt();
update();
loadHomePage();
QSqlQueryModel *Notes = new QSqlQueryModel;
Notes->setQuery("SELECT id, x, y, text FROM note", db->db);
for(int i = 0; i<Notes->rowCount(); i++)
{
QPoint p = {Notes->record(i).value(1).toInt(), Notes->record(i).value(2).toInt()};
new postit(ui->page_6, db, p, Notes->record(i).value(3).toString(), Notes->record(i).value(0).toInt());
}
}
void MainWindow::designHomePage()
{
QVBoxLayout *ml = new QVBoxLayout;
QHBoxLayout *dbl = new QHBoxLayout;
QGridLayout *ssubl = new QGridLayout;
ssubl->addWidget(ui->graphics_Time, 0, 0);//Time spent on app (1 color)
ssubl->addWidget(ui->graphics_Avg, 0, 1);// Average time spent per task (several colors)
ssubl->addWidget(ui->graphics_Active, 0, 2);//Active task count evolution (several colors)
ssubl->addWidget(ui->graphics_Duration, 1, 0);//Avergage estimed time (several colors)
ssubl->addWidget(ui->graphics_Allocation, 1, 1);//Average Allocation (several colors)
ssubl->addWidget(ui->graphics_Overall, 1, 2);//Overall active count (1 color)
subdbl->setAlignment(Qt::AlignHCenter);
bef->setText("<");
bef->setMaximumSize(40, 40);
aft->setText(">");
aft->setMaximumSize(40, 40);
dbl->addStretch(1);
dbl->addWidget(bef);
dbl->addWidget(crtDb);
dbl->addWidget(aft);
dbl->addStretch(1);
ml->addItem(dbl);
ml->addWidget(subdbl);
ml->addItem(ssubl);
ui->page_6->setLayout(ml);
ui->page_6->setContextMenuPolicy(Qt::CustomContextMenu);
loadHomePage();
QSqlQueryModel *Notes = new QSqlQueryModel;
Notes->setQuery("SELECT id, x, y, text FROM note", db->db);
for(int i = 0; i<Notes->rowCount(); i++)
{
QPoint p = {Notes->record(i).value(1).toInt(), Notes->record(i).value(2).toInt()};
new postit(ui->page_6, db, p, Notes->record(i).value(3).toString(), Notes->record(i).value(0).toInt());
}
}
void MainWindow::loadHomePage()
{
QFont font;
font.setPixelSize(18);
QStringList dbNames = this->db->getDbNames();
subdbl->clear();
subdbl->setFont(font);
QString dbNamesStr;
for(int i = 0; i<dbNames.length(); i++)
{
dbNamesStr += dbNames.at(i);
dbNamesStr += " ";
}
subdbl->setText(dbNamesStr);
this->db->updateMiscellaneous(0);
QSqlQuery *timeElap = new QSqlQuery(db->db);
timeElap->exec("SELECT SUM(spentTime) FROM miscellaneous");
timeElap->first();
QSqlQueryModel *generalMod = new QSqlQueryModel;
generalMod->setQuery("SELECT id, avgTask, activeTask, spentTime, avgTask0, avgTask1, avgTask2, avgTask3,"
" avgTask4, avgTask5, activeTask0, activeTask1, activeTask2, activeTask3,"
" activeTask4, activeTask5, estimedTime0, estimedTime1, estimedTime2, estimedTime3,"
" estimedTime4, estimedTime5, allocated0, allocated1, allocated2, allocated3,"
" allocated4, allocated5 FROM miscellaneous ORDER BY id DESC LIMIT 10", db->db);
float max = 0;
QLineSeries *spentTimeLines = new QLineSeries();
for(int i = 0; i<10; i++)
{
spentTimeLines->append(10-i,(generalMod->record(i).value(3).toInt()/1000)/60);
if(((generalMod->record(i).value(3).toInt()/1000)/60)>max)
max = ((generalMod->record(i).value(3).toInt()/1000)/60);
}
QPen pen = spentTimeLines->pen();
pen.setWidth(5);
pen.setBrush(QBrush(QColor("#11AEBF")));
spentTimeLines->setPen(pen);
QBrush brush;
brush.setColor(QColor::fromRgb(49, 54, 63));
QChart *chart = new QChart();
chart->addSeries(spentTimeLines);
chart->legend()->hide();
chart->setTitle("Time. ("+myTime(timeElap->record().value(0).toInt(), 0)+")");
chart->setBackgroundBrush(brush);
QValueAxis *axisX = new QValueAxis;
axisX->setTickCount(10);
axisX->setLabelFormat("%i");
chart->addAxis(axisX, Qt::AlignBottom);
spentTimeLines->attachAxis(axisX);
QValueAxis *axisY = new QValueAxis;
axisY->setLabelFormat("%i");
axisY->setTitleText("Amount (mn)");
chart->addAxis(axisY, Qt::AlignLeft);
spentTimeLines->attachAxis(axisY);
axisY->setRange(0, max+(0.1*max));
//Chart avgTask
QChart *chart2 = new QChart();
QValueAxis *avgTaskX = new QValueAxis;
avgTaskX->setTickCount(10);
avgTaskX->setLabelFormat("%i");
chart2->addAxis(avgTaskX, Qt::AlignBottom);
QValueAxis *avgTaskY = new QValueAxis;
avgTaskY->setLabelFormat("%i");
avgTaskY->setTitleText("Targets per task");
chart2->addAxis(avgTaskY, Qt::AlignLeft);
max = 0;
for(int p = 0; p<6; p++)
{
QLineSeries *avgTaskLines = new QLineSeries();
QPen avgTaskPen = avgTaskLines->pen();
avgTaskPen.setWidth(5);
avgTaskPen.setBrush(QBrush(QColor(PrioToColor(p))));
avgTaskLines->setPen(avgTaskPen);
for(int i = 0; i<10; i++)
{
avgTaskLines->append(10-i,generalMod->record(i).value(4+p).toReal());
if(generalMod->record(i).value(4+p).toReal()>max)
max = generalMod->record(i).value(4+p).toReal();
}
chart2->addSeries(avgTaskLines);
avgTaskLines->attachAxis(avgTaskX);
avgTaskLines->attachAxis(avgTaskY);
}
chart2->legend()->hide();
chart2->setTitle("Average targets per task");
chart2->setBackgroundBrush(brush);
avgTaskY->setRange(0, max+(0.1*max));
//Chart activeTask
QChart *chart3 = new QChart();
QValueAxis *actTaskX = new QValueAxis;
actTaskX->setTickCount(10);
actTaskX->setLabelFormat("%i");
chart3->addAxis(actTaskX, Qt::AlignBottom);
QValueAxis *actTaskY = new QValueAxis;
actTaskY->setLabelFormat("%i");
actTaskY->setTitleText("Active tasks");
chart3->addAxis(actTaskY, Qt::AlignLeft);
max = 0;
for(int p = 0; p<6; p++)
{
QLineSeries *actTaskLines = new QLineSeries();
QPen actTaskPen = actTaskLines->pen();
actTaskPen.setWidth(5);
actTaskPen.setBrush(QBrush(QColor(PrioToColor(p))));
actTaskLines->setPen(actTaskPen);
for(int i = 0; i<10; i++)
{
actTaskLines->append(10-i,generalMod->record(i).value(10+p).toInt());
if(generalMod->record(i).value(10+p).toInt()>max)
max = generalMod->record(i).value(10+p).toInt();
}
chart3->addSeries(actTaskLines);
actTaskLines->attachAxis(actTaskX);
actTaskLines->attachAxis(actTaskY);
}
chart3->legend()->hide();
chart3->setTitle("Active tasks");
chart3->setBackgroundBrush(brush);
actTaskY->setRange(0, max+1);
actTaskY->setTickInterval(1+((int(max)+1)%10));
//Chart estimedTime
QChart *chart4 = new QChart();
QValueAxis *estimedTimeX = new QValueAxis;
estimedTimeX->setTickCount(10);
estimedTimeX->setLabelFormat("%i");
chart4->addAxis(estimedTimeX, Qt::AlignBottom);
QValueAxis *estimedTimeY = new QValueAxis;
estimedTimeY->setLabelFormat("%i");
estimedTimeY->setTitleText("Estimed time (d)");
chart4->addAxis(estimedTimeY, Qt::AlignLeft);
max = 0;
for(int p = 0; p<6; p++)
{
QLineSeries *estimedTimeLines = new QLineSeries();
QPen estimedTimePen = estimedTimeLines->pen();
estimedTimePen.setWidth(5);
estimedTimePen.setBrush(QBrush(QColor(PrioToColor(p))));
estimedTimeLines->setPen(estimedTimePen);
for(int i = 0; i<10; i++)
{
estimedTimeLines->append(10-i,generalMod->record(i).value(16+p).toInt());
if(generalMod->record(i).value(16+p).toInt()>max)
max = generalMod->record(i).value(16+p).toInt();
}
chart4->addSeries(estimedTimeLines);
estimedTimeLines->attachAxis(estimedTimeX);
estimedTimeLines->attachAxis(estimedTimeY);
}
chart4->legend()->hide();
chart4->setTitle("Processing time");
chart4->setBackgroundBrush(brush);
estimedTimeY->setRange(0, max+(0.1*max));
//Chart allocated
QChart *chart5 = new QChart();
QValueAxis *allocatedX = new QValueAxis;
allocatedX->setTickCount(10);
allocatedX->setLabelFormat("%i");
chart5->addAxis(allocatedX, Qt::AlignBottom);
QValueAxis *allocatedY = new QValueAxis;
allocatedY->setLabelFormat("%i");
allocatedY->setTitleText("Allocated (h)");
chart5->addAxis(allocatedY, Qt::AlignLeft);
max = 0;
for(int p = 0; p<6; p++)
{
QLineSeries *allocatedLines = new QLineSeries();
QPen allocatedPen = allocatedLines->pen();
allocatedPen.setWidth(5);
allocatedPen.setBrush(QBrush(QColor(PrioToColor(p))));
allocatedLines->setPen(allocatedPen);
for(int i = 0; i<10; i++)
{
allocatedLines->append(10-i,generalMod->record(i).value(22+p).toInt());
if(generalMod->record(i).value(22+p).toInt()>max)
max = generalMod->record(i).value(22+p).toInt();
}
chart5->addSeries(allocatedLines);
allocatedLines->attachAxis(allocatedX);
allocatedLines->attachAxis(allocatedY);
}
chart5->legend()->hide();
chart5->setTitle("Allocated time");
chart5->setBackgroundBrush(brush);
allocatedY->setRange(0, max+(0.1*max));
//Chart tot
QChart *chart6 = new QChart();
QValueAxis *totX = new QValueAxis;
totX->setTickCount(10);
totX->setLabelFormat("%i");
chart6->addAxis(totX, Qt::AlignBottom);
QValueAxis *totY = new QValueAxis;
totY->setLabelFormat("%i");
totY->setTitleText("Amount");
chart6->addAxis(totY, Qt::AlignLeft);
max = 0;
float min = generalMod->record(0).value(1).toInt();
for(int p = 0; p<2; p++)
{
QLineSeries *totLines = new QLineSeries();
QPen totPen = totLines->pen();
totPen.setWidth(5);
totPen.setBrush(QBrush(QColor(PrioToColor(p+2))));
totLines->setPen(totPen);
for(int i = 0; i<10; i++)
{
totLines->append(10-i,generalMod->record(i).value(1+p).toInt());
if(generalMod->record(i).value(1+p).toReal()>max)
max = generalMod->record(i).value(1+p).toReal();
if(generalMod->record(i).value(1+p).toReal()<min)
min = generalMod->record(i).value(1+p).toReal();
}
chart6->addSeries(totLines);
totLines->attachAxis(totX);
totLines->attachAxis(totY);
}
chart6->legend()->hide();
chart6->setTitle("Total task and archive count");
chart6->setBackgroundBrush(brush);
totY->setRange(min-(0.1*min), max+(0.1*max));
QBrush axisBrush(Qt::white);
axisX->setLabelsBrush(axisBrush);
axisY->setLabelsBrush(axisBrush);
avgTaskX->setLabelsBrush(axisBrush);
avgTaskY->setLabelsBrush(axisBrush);
actTaskX->setLabelsBrush(axisBrush);
actTaskY->setLabelsBrush(axisBrush);
estimedTimeX->setLabelsBrush(axisBrush);
estimedTimeY->setLabelsBrush(axisBrush);
allocatedX->setLabelsBrush(axisBrush);
allocatedY->setLabelsBrush(axisBrush);
totX->setLabelsBrush(axisBrush);
totY->setLabelsBrush(axisBrush);
chart->setTitleFont(font);
chart->setTitleBrush(QBrush(Qt::white));
axisX->setTitleBrush(QBrush(Qt::white));
axisY->setTitleBrush(QBrush(Qt::white));
chart2->setTitleFont(font);
chart2->setTitleBrush(QBrush(Qt::white));
avgTaskX->setTitleBrush(QBrush(Qt::white));
avgTaskY->setTitleBrush(QBrush(Qt::white));
chart3->setTitleFont(font);
chart3->setTitleBrush(QBrush(Qt::white));
actTaskX->setTitleBrush(QBrush(Qt::white));
actTaskY->setTitleBrush(QBrush(Qt::white));
chart4->setTitleFont(font);
chart4->setTitleBrush(QBrush(Qt::white));
estimedTimeX->setTitleBrush(QBrush(Qt::white));
estimedTimeY->setTitleBrush(QBrush(Qt::white));
chart5->setTitleFont(font);
chart5->setTitleBrush(QBrush(Qt::white));
allocatedX->setTitleBrush(QBrush(Qt::white));
allocatedY->setTitleBrush(QBrush(Qt::white));
chart6->setTitleFont(font);
chart6->setTitleBrush(QBrush(Qt::white));
totX->setTitleBrush(QBrush(Qt::white));
totY->setTitleBrush(QBrush(Qt::white));
ui->graphics_Time->setChart(chart);
ui->graphics_Avg->setChart(chart2);
ui->graphics_Active->setChart(chart3);
ui->graphics_Duration->setChart(chart4);
ui->graphics_Allocation->setChart(chart5);
ui->graphics_Overall->setChart(chart6);
}
/**
* @brief Design Kanban page
*/
void MainWindow::designPage()
{
crtDb->setStyleSheet("QLabel{font-weight : 600;font-size : 18pt;"
"color: rgb(200, 200, 200);}");
crtDb->setAlignment(Qt::AlignCenter);
crtDb->setText(db->db.databaseName().remove(".db"));
crtDb->setMaximumWidth((this->width()+30)/4);
crtDb->setMinimumHeight(40);
load(this->t1);
load(this->t2);
load(this->t3);
load(this->t4);
pageL->addItem(b);
b->addWidget(this->adder);
b->addStretch(1);
this->adder->setText("+");
this->adder->setStyleSheet("QPushButton{"
"font: 87 14pt;"
"border-color: #66767A;"
"color: black;"
"background-color: #9BB3B9;"
"border : 2px solid;"
"border-radius : 15px;"
"height : 1em;"
"width : 1em;}"
"QPushButton:hover{"
"background-color: #66767A;"
"color: #A6C0C6;"
"border-color: #A6C0C6;}"
"QPushButton:pressed{"
"background-color: #A6C0C6;"
"color: #66767A;"
"border-color: #66767A;}");
col->addWidget(t1);
col->addSpacing(10);
col->addWidget(t2);
col->addSpacing(10);
col->addWidget(t3);
col->addSpacing(10);
col->addWidget(t4);
pageL->addItem(col);
ui->page->setLayout(pageL);
}
/**
* @brief Add a task to the Todo list
*/
void MainWindow::createTask()
{
task *w = new task(db, this);
t2->layout->addWidget(w);
}
/**
* @brief Charge trays of task (mainly on app load)
* @param t
*/
void MainWindow::load(tray *t)
{
QString str = "SELECT COUNT(*) as cnt FROM task WHERE tray="+QString::fromStdString(std::to_string(t->getId()))+" AND active=1";
QSqlQueryModel *modelTaskCount = new QSqlQueryModel;
modelTaskCount->setQuery(str, db->db);
QString str1 = "SELECT number, priority, duration, tray, itemCount, "
"color, deadline, title FROM task WHERE tray="+QString::fromStdString(std::to_string(t->getId()))+
" AND active=1 ORDER BY priority DESC";
QSqlQueryModel *modelTask = new QSqlQueryModel;
modelTask->setQuery(str1, db->db);
for(int i = 0; i<modelTaskCount->record(0).value("cnt").toInt(); i++)//through tasks
{
task *aTask = new task;
aTask->set(QDateTime::fromString(modelTask->record(i).value("number").toString(),"yyyyMMddhhmmssz"),
this->db,
modelTask->record(i).value("priority").toInt(),
modelTask->record(i).value("duration").toInt(),
modelTask->record(i).value("tray").toInt(),
modelTask->record(i).value("itemCount").toInt(),
modelTask->record(i).value("color").toString(),
modelTask->record(i).value("deadline").toDateTime(),
modelTask->record(i).value("title").toString());
QString str2 ="SELECT COUNT(*) as cnt1 FROM target WHERE parentTask="+modelTask->record(i).value("number").toString();
QSqlQueryModel *modelTargetCount = new QSqlQueryModel;
modelTargetCount->setQuery(str2, db->db);
QString str3 ="SELECT number, title, state FROM target WHERE parentTask="+modelTask->record(i).value("number").toString()+" ORDER BY state";
QSqlQueryModel *modelTarget = new QSqlQueryModel;
modelTarget->setQuery(str3, db->db);
if(aTask->itemCount)
aTask->completion->setMaximum(aTask->itemCount);
else
aTask->completion->setMaximum(1);
for(int k = 0; k<modelTargetCount->record(0).value("cnt1").toInt(); k++)//through target
{
target *targ = new target;
targ->set(QDateTime::fromString(modelTarget->record(k).value("number").toString(),"yyyyMMddhhmmssz"),
modelTarget->record(k).value("state").toBool(),
modelTarget->record(k).value("title").toString(),
aTask->get(),
this->db);
if(modelTarget->record(k).value("state").toBool())
aTask->completion->setValue(aTask->completion->value()+1);
connect(targ->c, SIGNAL(stateChanged(int)), aTask, SLOT(completionVal(int)));
connect(targ->b, SIGNAL(clicked(bool)), aTask, SLOT(deleteTarget(bool)));
aTask->layout->addWidget(targ);
}
aTask->color();
t->layout->addWidget(aTask);
t->layout->setAlignment(Qt::AlignTop);
}
}
/**
* @brief Design the parameters page
*/
void MainWindow::designParms()
{
QStringList l = this->db->getDbNames();
ui->comboDb->addItem(" ");
ui->comboDb->addItems(l);
QVBoxLayout *mainLay = new QVBoxLayout;
QHBoxLayout *dbl = new QHBoxLayout;
QHBoxLayout *dbls = new QHBoxLayout;
QHBoxLayout *lhf = new QHBoxLayout;
QHBoxLayout *lhs = new QHBoxLayout;
QHBoxLayout *lht = new QHBoxLayout;
QHBoxLayout *lhfo = new QHBoxLayout;
/*mainLay->setAlignment(Qt::AlignCenter);
dbl->setAlignment(Qt::AlignCenter);
lhf->setAlignment(Qt::AlignCenter);
lhs->setAlignment(Qt::AlignCenter);
lht->setAlignment(Qt::AlignCenter);
lhfo->setAlignment(Qt::AlignCenter);*/
QSqlQuery *query = new QSqlQuery(db->db);
query->exec("SELECT monday, tuesday, wednesday, thursday, friday, saturday, sunday, opt1 FROM parms");
query->first();
ui->spinMonday->setValue(query->value("monday").toInt());
ui->spinTuesday->setValue(query->value("tuesday").toInt());
ui->spinWednesday->setValue(query->value("wednesday").toInt());
ui->spinThursday->setValue(query->value("thursday").toInt());
ui->spinFriday->setValue(query->value("friday").toInt());
ui->spinSaturday->setValue(query->value("saturday").toInt());
ui->spinSunday->setValue(query->value("sunday").toInt());
ui->overloadOpt->setValue(query->value("opt1").toInt());
mainLay->addWidget(ui->overloadOpt);
mainLay->addWidget(ui->labDb);
dbl->addWidget(ui->dbName);
dbl->addWidget(ui->addDb);
mainLay->addItem(dbl);
dbls->addWidget(ui->comboDb);
dbls->addWidget(ui->dlDb);
mainLay->addItem(dbls);
mainLay->addWidget(ui->labDay);
lhf->addWidget(ui->label);
lhf->addWidget(ui->spinMonday);
lhf->addWidget(ui->label_5);
lhf->addWidget(ui->spinFriday);
mainLay->addItem(lhf);
lhs->addWidget(ui->label_2);
lhs->addWidget(ui->spinTuesday);
lhs->addWidget(ui->label_6);
lhs->addWidget(ui->spinSaturday);
mainLay->addItem(lhs);
lht->addWidget(ui->label_3);
lht->addWidget(ui->spinWednesday);
lht->addWidget(ui->label_7);
lht->addWidget(ui->spinSunday);
mainLay->addItem(lht);
lhfo->addWidget(ui->label_4);
lhfo->addWidget(ui->spinThursday);
mainLay->addItem(lhfo);
ui->page_4->setLayout(mainLay);
}
/**
* @brief Design the Gantt page
*/
void MainWindow::designGanttPage()
{
QHBoxLayout *lh = new QHBoxLayout;
lh->addWidget(ui->displayFrom);
lh->addWidget(ui->displayTo);
lh->addWidget(ui->displayArchive);
lh->addWidget(ui->editModeButton);
lh->addStretch(1);
ui->displayFrom->setDate(QDate::currentDate());
ui->displayTo->setDate(QDate::currentDate().addDays(14));
ui->displayArchive->setChecked(false);
ui->page_2->setLayout(ganttDisp);
ganttDisp->addItem(lh);
rngGantt();
ganttDisp->addWidget(this->g->table);
update();
}
/**
* @brief Refresh a Gantt in the specified time range
*/
void MainWindow::rngGantt()
{
QSqlQuery *vac = new QSqlQuery(db->db);
if(ui->editModeButton->isChecked())
ui->editModeButton->setText("View Mode");
else
{
ui->editModeButton->setText("Edit Mode");
vac->exec("VACUUM");
}
if(ui->displayArchive->isChecked())
ui->displayArchive->setText("Hide archives");
else
ui->displayArchive->setText("Display archives");
int dayLength[7];
QStringList lst;
QStringList lstNumb;
QSqlQuery *query = new QSqlQuery(db->db);
if(ui->displayArchive->isChecked())
query->exec("SELECT COUNT(*) FROM task");
else
query->exec("SELECT COUNT(*) FROM task WHERE active=1");
query->first();
QSqlQueryModel *modelTask = new QSqlQueryModel;
modelTask->setQuery("SELECT * FROM parms", db->db);
for(int i = 0; i<7; i++)
{
dayLength[i] = modelTask->record(0).value(i).toInt();
}
QSqlQueryModel *titles = new QSqlQueryModel;
if(ui->displayArchive->isChecked())
titles->setQuery("SELECT title as title, number as numb FROM task ORDER BY priority DESC", db->db);
else
titles->setQuery("SELECT title as title, number as numb FROM task WHERE active=1 ORDER BY priority DESC", db->db);
for(int i = 0; i<query->value(0).toInt(); i++)
{
lst << titles->record(i).value("title").toString();
lstNumb << titles->record(i).value("numb").toString();
}
this->g->build(lst, lstNumb, ui->displayFrom->date().daysTo(ui->displayTo->date())+1,
dayLength, ui->displayFrom->date(), ui->editModeButton->isChecked());
ganttDisp->update();
}
/**
* @brief Refresh Charge page
*/
void MainWindow::loadPage()
{
QLineSeries *lines = new QLineSeries();
for(int i = 0; i<ui->displayFrom->date().daysTo(ui->displayTo->date()); i++)
lines->append(QDateTime(ui->displayFrom->date().addDays(i)).toMSecsSinceEpoch(),
db->dayOccupation(QDateTime(ui->displayFrom->date().addDays(i))));
QPen pen = lines->pen();
pen.setWidth(5);
pen.setBrush(QBrush(QColor("#F25244")));
lines->setPen(pen);
QBrush brush;
brush.setColor(QColor::fromRgb(49, 54, 63));
QChart *chart = new QChart();
chart->addSeries(lines);
chart->legend()->hide();
chart->setTitle("Charge in %");
chart->setBackgroundBrush(brush);
QDateTimeAxis *axisX = new QDateTimeAxis;
axisX->setTickCount(ui->displayFrom->date().daysTo(ui->displayTo->date()));
axisX->setFormat("dd MMM");
axisX->setTitleText("Date");
chart->addAxis(axisX, Qt::AlignBottom);
lines->attachAxis(axisX);
QValueAxis *axisY = new QValueAxis;
axisY->setRange(0, 100);
axisY->setTickCount(11);
axisY->setLabelFormat("%i");
axisY->setTitleText("Amount (%)");
chart->addAxis(axisY, Qt::AlignLeft);
lines->attachAxis(axisY);
QFont font;
font.setPixelSize(18);
chart->setTitleFont(font);
chart->setTitleBrush(QBrush(Qt::white));
axisX->setTitleBrush(QBrush(Qt::white));
axisY->setTitleBrush(QBrush(Qt::white));
QBrush axisBrush(Qt::white);
axisX->setLabelsBrush(axisBrush);
axisY->setLabelsBrush(axisBrush);
ui->graphicsView->setChart(chart);
ui->graphicsView->setRenderHints(QPainter::Antialiasing);
int l[6] = {};
QBarSet *set = new QBarSet("Count");
QStringList prio;
QSqlQueryModel *model3 = new QSqlQueryModel;
model3->setQuery("SELECT COUNT(*) as cnt, priority as pr FROM task WHERE active = 1 GROUP BY priority ORDER BY priority ASC", db->db);
for(int i = 0; i < model3->rowCount(); ++i)
l[model3->record(i).value("pr").toInt()] = model3->record(i).value("cnt").toInt();
for(int i = 0; i < 6; ++i)
{
*set << l[i];
prio << QString::number(i);
}
QBarSeries *barseries = new QBarSeries();
barseries->append(set);
QChart *chart2 = new QChart();
chart2->addSeries(barseries);
chart2->setTitle("Priority distribution");
chart2->setBackgroundBrush(brush);
chart2->legend()->hide();
QBarCategoryAxis *axisX1 = new QBarCategoryAxis();
axisX1->append(prio);
chart2->addAxis(axisX1, Qt::AlignBottom);
barseries->attachAxis(axisX1);
axisX1->setTitleText("Priority");
QValueAxis *axisY1 = new QValueAxis();
chart2->addAxis(axisY1, Qt::AlignLeft);
axisY1->setLabelFormat("%i");
barseries->attachAxis(axisY1);
axisY1->setTitleText("Count");
chart2->setTitleFont(font);
chart2->setTitleBrush(QBrush(Qt::white));
axisX1->setTitleBrush(QBrush(Qt::white));
axisY1->setTitleBrush(QBrush(Qt::white));
axisX1->setLabelsBrush(axisBrush);
axisY1->setLabelsBrush(axisBrush);
ui->graphicsView_2->setChart(chart2);
ui->graphicsView_2->setRenderHints(QPainter::Antialiasing);
}
void MainWindow::designChargePage()
{
QHBoxLayout *l = new QHBoxLayout;
l->addWidget(ui->graphicsView);
l->addWidget(ui->graphicsView_2);
loadPage();
ui->page_3->setLayout(l);
}
/**
* @brief Refresh archive page (kill all, recreate)
*/
void MainWindow::loadArchive()
{
QList<task *> tasks = t5->findChildren<task *>();
foreach(task* t, tasks)
t->close();
QString str = "SELECT COUNT(*) as cnt FROM task WHERE active=0";