1 /***************************************************************************
2 modifyconstraintteachermaxzerogapsperafternoonform.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 "modifyconstraintteachermaxzerogapsperafternoonform.h"
21 #include "timeconstraint.h"
22
ModifyConstraintTeacherMaxZeroGapsPerAfternoonForm(QWidget * parent,ConstraintTeacherMaxZeroGapsPerAfternoon * ctr)23 ModifyConstraintTeacherMaxZeroGapsPerAfternoonForm::ModifyConstraintTeacherMaxZeroGapsPerAfternoonForm(QWidget* parent, ConstraintTeacherMaxZeroGapsPerAfternoon* 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 teachersComboBox->clear();
43 int i=0, j=-1;
44 for(int k=0; k<gt.rules.teachersList.size(); k++, i++){
45 Teacher* tch=gt.rules.teachersList[k];
46 teachersComboBox->addItem(tch->name);
47 if(tch->name==this->_ctr->teacherName)
48 j=i;
49 }
50 assert(j>=0);
51 teachersComboBox->setCurrentIndex(j);
52 }
53
~ModifyConstraintTeacherMaxZeroGapsPerAfternoonForm()54 ModifyConstraintTeacherMaxZeroGapsPerAfternoonForm::~ModifyConstraintTeacherMaxZeroGapsPerAfternoonForm()
55 {
56 saveFETDialogGeometry(this);
57 }
58
ok()59 void ModifyConstraintTeacherMaxZeroGapsPerAfternoonForm::ok()
60 {
61 double weight;
62 QString tmp=weightLineEdit->text();
63 weight_sscanf(tmp, "%lf", &weight);
64 if(weight<0.0 || weight>100.0){
65 QMessageBox::warning(this, tr("FET information"),
66 tr("Invalid weight (percentage)"));
67 return;
68 }
69 if(weight!=100.0){
70 QMessageBox::warning(this, tr("FET information"),
71 tr("Invalid weight (percentage) - it must be 100%"));
72 return;
73 }
74
75 this->_ctr->weightPercentage=weight;
76
77 QString teacher_name=teachersComboBox->currentText();
78 int teacher_ID=gt.rules.searchTeacher(teacher_name);
79 if(teacher_ID<0){
80 QMessageBox::warning(this, tr("FET information"),
81 tr("Invalid teacher"));
82 return;
83 }
84 this->_ctr->teacherName=teacher_name;
85
86 gt.rules.internalStructureComputed=false;
87 setRulesModifiedAndOtherThings(>.rules);
88
89 this->close();
90 }
91
cancel()92 void ModifyConstraintTeacherMaxZeroGapsPerAfternoonForm::cancel()
93 {
94 this->close();
95 }
96