1 /***************************************************************************
2 modifyconstraintteacherminhourspermorningform.cpp - description
3 -------------------
4 begin : 2019
5 copyright : (C) 2019 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 "modifyconstraintteacherminhourspermorningform.h"
21 #include "timeconstraint.h"
22
ModifyConstraintTeacherMinHoursPerMorningForm(QWidget * parent,ConstraintTeacherMinHoursPerMorning * ctr)23 ModifyConstraintTeacherMinHoursPerMorningForm::ModifyConstraintTeacherMinHoursPerMorningForm(QWidget* parent, ConstraintTeacherMinHoursPerMorning* 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 tmp1=teachersComboBox->minimumSizeHint();
36 Q_UNUSED(tmp1);
37
38 this->_ctr=ctr;
39
40 weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
41
42 allowEmptyMorningsCheckBox->setChecked(ctr->allowEmptyMornings);
43
44 connect(allowEmptyMorningsCheckBox, SIGNAL(toggled(bool)), this, SLOT(allowEmptyMorningsCheckBoxToggled())); //after setChecked(...)
45
46 updateMinHoursSpinBox();
47
48 minHoursSpinBox->setValue(ctr->minHoursPerMorning);
49
50 teachersComboBox->clear();
51 int i=0, j=-1;
52 for(int k=0; k<gt.rules.teachersList.size(); k++, i++){
53 Teacher* tch=gt.rules.teachersList[k];
54 teachersComboBox->addItem(tch->name);
55 if(tch->name==this->_ctr->teacherName)
56 j=i;
57 }
58 assert(j>=0);
59 teachersComboBox->setCurrentIndex(j);
60 }
61
~ModifyConstraintTeacherMinHoursPerMorningForm()62 ModifyConstraintTeacherMinHoursPerMorningForm::~ModifyConstraintTeacherMinHoursPerMorningForm()
63 {
64 saveFETDialogGeometry(this);
65 }
66
updateMinHoursSpinBox()67 void ModifyConstraintTeacherMinHoursPerMorningForm::updateMinHoursSpinBox(){
68 minHoursSpinBox->setMinimum(2);
69 minHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
70 }
71
ok()72 void ModifyConstraintTeacherMinHoursPerMorningForm::ok()
73 {
74 double weight;
75 QString tmp=weightLineEdit->text();
76 weight_sscanf(tmp, "%lf", &weight);
77 if(weight<0.0 || weight>100.0){
78 QMessageBox::warning(this, tr("FET information"),
79 tr("Invalid weight (percentage)"));
80 return;
81 }
82 if(weight!=100.0){
83 QMessageBox::warning(this, tr("FET information"),
84 tr("Invalid weight (percentage) - must be 100%"));
85 return;
86 }
87
88 if(!allowEmptyMorningsCheckBox->isChecked()){
89 QMessageBox::warning(this, tr("FET information"), tr("Allow empty mornings check box must be checked. If you need to not allow empty mornings for a teacher, "
90 "please use the constraint teacher min mornings per week."));
91 return;
92 }
93
94 int min_hours=minHoursSpinBox->value();
95
96 QString teacher_name=teachersComboBox->currentText();
97 int teacher_ID=gt.rules.searchTeacher(teacher_name);
98 if(teacher_ID<0){
99 QMessageBox::warning(this, tr("FET information"),
100 tr("Invalid teacher"));
101 return;
102 }
103
104 this->_ctr->weightPercentage=weight;
105 this->_ctr->minHoursPerMorning=min_hours;
106 this->_ctr->teacherName=teacher_name;
107
108 this->_ctr->allowEmptyMornings=allowEmptyMorningsCheckBox->isChecked();
109
110 gt.rules.internalStructureComputed=false;
111 setRulesModifiedAndOtherThings(>.rules);
112
113 this->close();
114 }
115
cancel()116 void ModifyConstraintTeacherMinHoursPerMorningForm::cancel()
117 {
118 this->close();
119 }
120
allowEmptyMorningsCheckBoxToggled()121 void ModifyConstraintTeacherMinHoursPerMorningForm::allowEmptyMorningsCheckBoxToggled()
122 {
123 bool k=allowEmptyMorningsCheckBox->isChecked();
124
125 if(!k){
126 allowEmptyMorningsCheckBox->setChecked(true);
127 QMessageBox::information(this, tr("FET information"), tr("This check box must remain checked. If you really need to not allow empty mornings for this teacher,"
128 " please use constraint teacher min mornings per week."));
129 }
130 }
131