1 /***************************************************************************
2 addconstraintteacherafternoonintervalmaxdaysperweekform.cpp - description
3 -------------------
4 begin : 2020
5 copyright : (C) 2020 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 <QMessageBox>
19
20 #include "longtextmessagebox.h"
21
22 #include "addconstraintteacherafternoonintervalmaxdaysperweekform.h"
23 #include "timeconstraint.h"
24
AddConstraintTeacherAfternoonIntervalMaxDaysPerWeekForm(QWidget * parent)25 AddConstraintTeacherAfternoonIntervalMaxDaysPerWeekForm::AddConstraintTeacherAfternoonIntervalMaxDaysPerWeekForm(QWidget* parent): QDialog(parent)
26 {
27 setupUi(this);
28
29 addConstraintPushButton->setDefault(true);
30
31 connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addCurrentConstraint()));
32 connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
33
34 centerWidgetOnScreen(this);
35 restoreFETDialogGeometry(this);
36
37 QSize tmp1=teachersComboBox->minimumSizeHint();
38 Q_UNUSED(tmp1);
39
40 QSize tmp5=startHourComboBox->minimumSizeHint();
41 Q_UNUSED(tmp5);
42 QSize tmp6=endHourComboBox->minimumSizeHint();
43 Q_UNUSED(tmp6);
44
45 updateMaxDaysSpinBox();
46 updateTeachersComboBox();
47 updateStartHoursComboBox();
48 updateEndHoursComboBox();
49 }
50
~AddConstraintTeacherAfternoonIntervalMaxDaysPerWeekForm()51 AddConstraintTeacherAfternoonIntervalMaxDaysPerWeekForm::~AddConstraintTeacherAfternoonIntervalMaxDaysPerWeekForm()
52 {
53 saveFETDialogGeometry(this);
54 }
55
updateTeachersComboBox()56 void AddConstraintTeacherAfternoonIntervalMaxDaysPerWeekForm::updateTeachersComboBox(){
57 teachersComboBox->clear();
58 for(int i=0; i<gt.rules.teachersList.size(); i++){
59 Teacher* tch=gt.rules.teachersList[i];
60 teachersComboBox->addItem(tch->name);
61 }
62 }
63
updateMaxDaysSpinBox()64 void AddConstraintTeacherAfternoonIntervalMaxDaysPerWeekForm::updateMaxDaysSpinBox(){
65 maxDaysSpinBox->setMinimum(0);
66 maxDaysSpinBox->setMaximum(gt.rules.nDaysPerWeek/2);
67 maxDaysSpinBox->setValue(gt.rules.nDaysPerWeek/2);
68 }
69
updateStartHoursComboBox()70 void AddConstraintTeacherAfternoonIntervalMaxDaysPerWeekForm::updateStartHoursComboBox()
71 {
72 startHourComboBox->clear();
73 for(int i=0; i<gt.rules.nHoursPerDay; i++)
74 startHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
75 startHourComboBox->setCurrentIndex(gt.rules.nHoursPerDay-1);
76 }
77
updateEndHoursComboBox()78 void AddConstraintTeacherAfternoonIntervalMaxDaysPerWeekForm::updateEndHoursComboBox()
79 {
80 endHourComboBox->clear();
81 for(int i=0; i<gt.rules.nHoursPerDay; i++)
82 endHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
83 endHourComboBox->addItem(tr("End of day"));
84 endHourComboBox->setCurrentIndex(gt.rules.nHoursPerDay);
85 }
86
addCurrentConstraint()87 void AddConstraintTeacherAfternoonIntervalMaxDaysPerWeekForm::addCurrentConstraint()
88 {
89 TimeConstraint *ctr=nullptr;
90
91 double weight;
92 QString tmp=weightLineEdit->text();
93 weight_sscanf(tmp, "%lf", &weight);
94 if(weight<0.0 || weight>100.0){
95 QMessageBox::warning(this, tr("FET information"),
96 tr("Invalid weight (percentage)"));
97 return;
98 }
99 if(weight!=100.0){
100 QMessageBox::warning(this, tr("FET information"),
101 tr("Invalid weight (percentage) - it has to be 100%"));
102 return;
103 }
104
105 int max_days=maxDaysSpinBox->value();
106
107 QString teacher_name=teachersComboBox->currentText();
108 int teacher_ID=gt.rules.searchTeacher(teacher_name);
109 if(teacher_ID<0){
110 QMessageBox::warning(this, tr("FET information"),
111 tr("Invalid teacher"));
112 return;
113 }
114
115 int startHour=startHourComboBox->currentIndex();
116 int endHour=endHourComboBox->currentIndex();
117 if(startHour<0 || startHour>=gt.rules.nHoursPerDay){
118 QMessageBox::warning(this, tr("FET information"),
119 tr("Start hour invalid"));
120 return;
121 }
122 if(endHour<0 || endHour>gt.rules.nHoursPerDay){
123 QMessageBox::warning(this, tr("FET information"),
124 tr("End hour invalid"));
125 return;
126 }
127 if(endHour<=startHour){
128 QMessageBox::warning(this, tr("FET information"),
129 tr("Start hour cannot be greater or equal than end hour"));
130 return;
131 }
132
133 ctr=new ConstraintTeacherAfternoonIntervalMaxDaysPerWeek(weight, max_days, teacher_name, startHour, endHour);
134
135 bool tmp2=gt.rules.addTimeConstraint(ctr);
136 if(tmp2)
137 LongTextMessageBox::information(this, tr("FET information"),
138 tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
139 else{
140 QMessageBox::warning(this, tr("FET information"),
141 tr("Constraint NOT added - please report error"));
142 delete ctr;
143 }
144 }
145