1 /***************************************************************************
2 modifyconstraintteachersafternoonintervalmaxdaysperweekform.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 "modifyconstraintteachersafternoonintervalmaxdaysperweekform.h"
21 #include "timeconstraint.h"
22
ModifyConstraintTeachersAfternoonIntervalMaxDaysPerWeekForm(QWidget * parent,ConstraintTeachersAfternoonIntervalMaxDaysPerWeek * ctr)23 ModifyConstraintTeachersAfternoonIntervalMaxDaysPerWeekForm::ModifyConstraintTeachersAfternoonIntervalMaxDaysPerWeekForm(QWidget* parent, ConstraintTeachersAfternoonIntervalMaxDaysPerWeek* ctr): QDialog(parent)
24 {
25 setupUi(this);
26
27 okPushButton->setDefault(true);
28
29 connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
30 connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
31
32 centerWidgetOnScreen(this);
33 restoreFETDialogGeometry(this);
34
35 QSize tmp5=startHourComboBox->minimumSizeHint();
36 Q_UNUSED(tmp5);
37 QSize tmp6=endHourComboBox->minimumSizeHint();
38 Q_UNUSED(tmp6);
39
40 this->_ctr=ctr;
41
42 weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
43
44 updateMaxDaysSpinBox();
45 maxDaysSpinBox->setValue(ctr->maxDaysPerWeek);
46
47 for(int i=0; i<gt.rules.nHoursPerDay; i++){
48 startHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
49 }
50 startHourComboBox->setCurrentIndex(ctr->startHour);
51
52 for(int i=0; i<gt.rules.nHoursPerDay; i++){
53 endHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
54 }
55 endHourComboBox->addItem(tr("End of day"));
56 endHourComboBox->setCurrentIndex(ctr->endHour);
57 }
58
~ModifyConstraintTeachersAfternoonIntervalMaxDaysPerWeekForm()59 ModifyConstraintTeachersAfternoonIntervalMaxDaysPerWeekForm::~ModifyConstraintTeachersAfternoonIntervalMaxDaysPerWeekForm()
60 {
61 saveFETDialogGeometry(this);
62 }
63
updateMaxDaysSpinBox()64 void ModifyConstraintTeachersAfternoonIntervalMaxDaysPerWeekForm::updateMaxDaysSpinBox(){
65 maxDaysSpinBox->setMinimum(0);
66 maxDaysSpinBox->setMaximum(gt.rules.nDaysPerWeek/2);
67 }
68
ok()69 void ModifyConstraintTeachersAfternoonIntervalMaxDaysPerWeekForm::ok()
70 {
71 double weight;
72 QString tmp=weightLineEdit->text();
73 weight_sscanf(tmp, "%lf", &weight);
74 if(weight<0.0 || weight>100.0){
75 QMessageBox::warning(this, tr("FET information"),
76 tr("Invalid weight (percentage)"));
77 return;
78 }
79 if(weight!=100.0){
80 QMessageBox::warning(this, tr("FET information"),
81 tr("Invalid weight (percentage) - it has to be 100%"));
82 return;
83 }
84
85 int max_days=maxDaysSpinBox->value();
86
87 int startHour=startHourComboBox->currentIndex();
88 int endHour=endHourComboBox->currentIndex();
89 if(startHour<0 || startHour>=gt.rules.nHoursPerDay){
90 QMessageBox::warning(this, tr("FET information"),
91 tr("Start hour invalid"));
92 return;
93 }
94 if(endHour<0 || endHour>gt.rules.nHoursPerDay){
95 QMessageBox::warning(this, tr("FET information"),
96 tr("End hour invalid"));
97 return;
98 }
99 if(endHour<=startHour){
100 QMessageBox::warning(this, tr("FET information"),
101 tr("Start hour cannot be greater or equal than end hour"));
102 return;
103 }
104
105 this->_ctr->weightPercentage=weight;
106 this->_ctr->maxDaysPerWeek=max_days;
107
108 this->_ctr->startHour=startHour;
109 this->_ctr->endHour=endHour;
110
111 gt.rules.internalStructureComputed=false;
112 setRulesModifiedAndOtherThings(>.rules);
113
114 this->close();
115 }
116
cancel()117 void ModifyConstraintTeachersAfternoonIntervalMaxDaysPerWeekForm::cancel()
118 {
119 this->close();
120 }
121