1 /***************************************************************************
2 teachersstatisticform.cpp - description
3 -------------------
4 begin : March 25, 2006
5 copyright : (C) 2006 by Lalescu Liviu
6 email : Please see https://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software: you can redistribute it and/or modify *
12 * it under the terms of the GNU Affero General Public License as *
13 * published by the Free Software Foundation, either version 3 of the *
14 * License, or (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 #include "teachersstatisticsform.h"
19
20 #include "timetable_defs.h"
21 #include "timetable.h"
22
23 #include "fet.h"
24
25 #include <Qt>
26
27 #include <QString>
28 #include <QStringList>
29
30 #include <QTableWidget>
31 #include <QHeaderView>
32
33 #include <QSet>
34 #include <QHash>
35
TeachersStatisticsForm(QWidget * parent)36 TeachersStatisticsForm::TeachersStatisticsForm(QWidget* parent): QDialog(parent)
37 {
38 setupUi(this);
39
40 closeButton->setDefault(true);
41
42 connect(hideFullTeachersCheckBox, SIGNAL(toggled(bool)), this, SLOT(hideFullTeachersCheckBoxModified()));
43
44 connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
45
46 tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
47 tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
48
49 centerWidgetOnScreen(this);
50 restoreFETDialogGeometry(this);
51
52 QHash<QString, QSet<Activity*>> activitiesForTeacher;
53
54 for(Activity* act : qAsConst(gt.rules.activitiesList))
55 if(act->active)
56 for(const QString& teacherName : qAsConst(act->teachersNames)){
57 QSet<Activity*> acts=activitiesForTeacher.value(teacherName, QSet<Activity*>());
58 acts.insert(act);
59 activitiesForTeacher.insert(teacherName, acts);
60 }
61
62 for(int i=0; i<gt.rules.teachersList.size(); i++){
63 Teacher* t=gt.rules.teachersList[i];
64
65 int nSubActivities=0;
66 int nHours=0;
67
68 QSet<Activity*> acts=activitiesForTeacher.value(t->name, QSet<Activity*>());
69
70 for(Activity* act : qAsConst(acts)){
71 if(act->active){
72 nSubActivities++;
73 nHours+=act->duration;
74 }
75 else{
76 assert(0);
77 }
78 }
79
80 names.append(t->name);
81 subactivities.append(nSubActivities);
82 durations.append(nHours);
83 targets.append(t->targetNumberOfHours);
84
85 if(nHours==t->targetNumberOfHours)
86 hideFullTeacher.append(true);
87 else
88 hideFullTeacher.append(false);
89 }
90
91 hideFullTeachersCheckBoxModified();
92 }
93
~TeachersStatisticsForm()94 TeachersStatisticsForm::~TeachersStatisticsForm()
95 {
96 saveFETDialogGeometry(this);
97 }
98
hideFullTeachersCheckBoxModified()99 void TeachersStatisticsForm::hideFullTeachersCheckBoxModified()
100 {
101 tableWidget->clear();
102
103 int n_rows=0;
104 for(bool b : qAsConst(hideFullTeacher))
105 if(!(hideFullTeachersCheckBox->isChecked() && b))
106 n_rows++;
107
108 tableWidget->setColumnCount(4);
109 tableWidget->setRowCount(n_rows);
110
111 QStringList columns;
112 columns<<tr("Teacher");
113 columns<<tr("No. of activities");
114 columns<<tr("Duration");
115 columns<<tr("Target duration", "It means the target duration of activities for each teacher");
116
117 tableWidget->setHorizontalHeaderLabels(columns);
118
119 int j=0;
120 for(int i=0; i<gt.rules.teachersList.count(); i++){
121 if(!(hideFullTeachersCheckBox->isChecked() && hideFullTeacher.at(i))){
122 QTableWidgetItem* newItem=new QTableWidgetItem(names.at(i));
123 newItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
124 tableWidget->setItem(j, 0, newItem);
125
126 newItem=new QTableWidgetItem(CustomFETString::number(subactivities.at(i)));
127 newItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
128 tableWidget->setItem(j, 1, newItem);
129
130 newItem=new QTableWidgetItem(CustomFETString::number(durations.at(i)));
131 newItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
132 tableWidget->setItem(j, 2, newItem);
133
134 newItem=new QTableWidgetItem(CustomFETString::number(targets.at(i)));
135 newItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
136 tableWidget->setItem(j, 3, newItem);
137
138 j++;
139 }
140 }
141
142 tableWidget->resizeColumnsToContents();
143 tableWidget->resizeRowsToContents();
144 }
145