1 /***************************************************************************
2 modifyconstraintteacherminafternoonsperweekform.cpp - description
3 -------------------
4 begin : 2009
5 copyright : (C) 2009 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 "modifyconstraintteacherminafternoonsperweekform.h"
21 #include "timeconstraint.h"
22
ModifyConstraintTeacherMinAfternoonsPerWeekForm(QWidget * parent,ConstraintTeacherMinAfternoonsPerWeek * ctr)23 ModifyConstraintTeacherMinAfternoonsPerWeekForm::ModifyConstraintTeacherMinAfternoonsPerWeekForm(QWidget* parent, ConstraintTeacherMinAfternoonsPerWeek* 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 updateMinAfternoonsSpinBox();
43 updateTeachersComboBox();
44
45 minAfternoonsSpinBox->setValue(ctr->minAfternoonsPerWeek);
46 }
47
~ModifyConstraintTeacherMinAfternoonsPerWeekForm()48 ModifyConstraintTeacherMinAfternoonsPerWeekForm::~ModifyConstraintTeacherMinAfternoonsPerWeekForm()
49 {
50 saveFETDialogGeometry(this);
51 }
52
updateTeachersComboBox()53 void ModifyConstraintTeacherMinAfternoonsPerWeekForm::updateTeachersComboBox(){
54 teachersComboBox->clear();
55 int i=0, j=-1;
56 for(int k=0; k<gt.rules.teachersList.size(); k++, i++){
57 Teacher* tch=gt.rules.teachersList[k];
58 teachersComboBox->addItem(tch->name);
59 if(tch->name==this->_ctr->teacherName)
60 j=i;
61 }
62 assert(j>=0);
63 teachersComboBox->setCurrentIndex(j);
64 }
65
updateMinAfternoonsSpinBox()66 void ModifyConstraintTeacherMinAfternoonsPerWeekForm::updateMinAfternoonsSpinBox(){
67 minAfternoonsSpinBox->setMinimum(1);
68 minAfternoonsSpinBox->setMaximum(gt.rules.nDaysPerWeek/2);
69 }
70
ok()71 void ModifyConstraintTeacherMinAfternoonsPerWeekForm::ok()
72 {
73 double weight;
74 QString tmp=weightLineEdit->text();
75 weight_sscanf(tmp, "%lf", &weight);
76 if(weight<0.0 || weight>100.0){
77 QMessageBox::warning(this, tr("FET information"),
78 tr("Invalid weight (percentage)"));
79 return;
80 }
81 if(weight!=100.0){
82 QMessageBox::warning(this, tr("FET information"),
83 tr("Invalid weight (percentage) - it has to be 100%"));
84 return;
85 }
86
87 int min_afternoons=minAfternoonsSpinBox->value();
88
89 QString teacher_name=teachersComboBox->currentText();
90 int teacher_ID=gt.rules.searchTeacher(teacher_name);
91 if(teacher_ID<0){
92 QMessageBox::warning(this, tr("FET information"),
93 tr("Invalid teacher"));
94 return;
95 }
96
97 this->_ctr->weightPercentage=weight;
98 this->_ctr->minAfternoonsPerWeek=min_afternoons;
99 this->_ctr->teacherName=teacher_name;
100
101 gt.rules.internalStructureComputed=false;
102 setRulesModifiedAndOtherThings(>.rules);
103
104 this->close();
105 }
106
cancel()107 void ModifyConstraintTeacherMinAfternoonsPerWeekForm::cancel()
108 {
109 this->close();
110 }
111