1 /***************************************************************************
2 modifyconstraintteacherminhoursdailyform.cpp - description
3 -------------------
4 begin : Sept 21, 2007
5 copyright : (C) 2007 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 "modifyconstraintteacherminhoursdailyform.h"
21 #include "timeconstraint.h"
22
ModifyConstraintTeacherMinHoursDailyForm(QWidget * parent,ConstraintTeacherMinHoursDaily * ctr)23 ModifyConstraintTeacherMinHoursDailyForm::ModifyConstraintTeacherMinHoursDailyForm(QWidget* parent, ConstraintTeacherMinHoursDaily* 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 allowEmptyDaysCheckBox->setChecked(ctr->allowEmptyDays);
43
44 connect(allowEmptyDaysCheckBox, SIGNAL(toggled(bool)), this, SLOT(allowEmptyDaysCheckBoxToggled())); //after setChecked(...)
45
46 updateMinHoursSpinBox();
47
48 minHoursSpinBox->setValue(ctr->minHoursDaily);
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
~ModifyConstraintTeacherMinHoursDailyForm()62 ModifyConstraintTeacherMinHoursDailyForm::~ModifyConstraintTeacherMinHoursDailyForm()
63 {
64 saveFETDialogGeometry(this);
65 }
66
updateMinHoursSpinBox()67 void ModifyConstraintTeacherMinHoursDailyForm::updateMinHoursSpinBox(){
68 minHoursSpinBox->setMinimum(2);
69 minHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
70 }
71
ok()72 void ModifyConstraintTeacherMinHoursDailyForm::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(!allowEmptyDaysCheckBox->isChecked()){
89 if(gt.rules.mode!=MORNINGS_AFTERNOONS){
90 QMessageBox::warning(this, tr("FET information"), tr("Allow empty days check box must be checked. If you need to not allow empty days for the teachers, "
91 "please use the constraint teachers min days per week"));
92 return;
93 }
94 else{
95 QMessageBox::warning(this, tr("FET information"), tr("Allow empty days check box must be checked. If you need to not allow empty days for a teacher, "
96 "please use the constraint teacher min days per week (but the min days per week constraint is for real days. You can also use the "
97 "constraints teacher min mornings/afternoons per week.)"));
98 return;
99 }
100 }
101
102 int min_hours=minHoursSpinBox->value();
103
104 QString teacher_name=teachersComboBox->currentText();
105 int teacher_ID=gt.rules.searchTeacher(teacher_name);
106 if(teacher_ID<0){
107 QMessageBox::warning(this, tr("FET information"),
108 tr("Invalid teacher"));
109 return;
110 }
111
112 this->_ctr->weightPercentage=weight;
113 this->_ctr->minHoursDaily=min_hours;
114 this->_ctr->teacherName=teacher_name;
115
116 this->_ctr->allowEmptyDays=allowEmptyDaysCheckBox->isChecked();
117
118 gt.rules.internalStructureComputed=false;
119 setRulesModifiedAndOtherThings(>.rules);
120
121 this->close();
122 }
123
cancel()124 void ModifyConstraintTeacherMinHoursDailyForm::cancel()
125 {
126 this->close();
127 }
128
allowEmptyDaysCheckBoxToggled()129 void ModifyConstraintTeacherMinHoursDailyForm::allowEmptyDaysCheckBoxToggled()
130 {
131 bool k=allowEmptyDaysCheckBox->isChecked();
132
133 if(!k){
134 allowEmptyDaysCheckBox->setChecked(true);
135 if(gt.rules.mode!=MORNINGS_AFTERNOONS)
136 QMessageBox::information(this, tr("FET information"), tr("This check box must remain checked. If you really need to not allow empty days for the teachers,"
137 " please use constraint teachers min days per week"));
138 else
139 QMessageBox::information(this, tr("FET information"), tr("This check box must remain checked. If you really need to not allow empty days for this teacher,"
140 " please use constraint teacher min days per week (but the min days per week constraint is for real days. You can also use the "
141 "constraints teacher min mornings/afternoons per week.)"));
142 }
143 }
144