1 /***************************************************************************
2 addconstraintteachersmaxgapsperrealdayform.cpp - description
3 -------------------
4 begin : 2018
5 copyright : (C) 2018 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 "longtextmessagebox.h"
21
22 #include "addconstraintteachermaxgapsperrealdayform.h"
23 #include "timeconstraint.h"
24
AddConstraintTeacherMaxGapsPerRealDayForm(QWidget * parent)25 AddConstraintTeacherMaxGapsPerRealDayForm::AddConstraintTeacherMaxGapsPerRealDayForm(QWidget* parent): QDialog(parent)
26 {
27 setupUi(this);
28
29 addConstraintPushButton->setDefault(true);
30
31 connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addCurrentConstraint()));
32 connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
33
34 centerWidgetOnScreen(this);
35 restoreFETDialogGeometry(this);
36
37 QSize tmp1=teachersComboBox->minimumSizeHint();
38 Q_UNUSED(tmp1);
39
40 maxGapsSpinBox->setMinimum(0);
41 maxGapsSpinBox->setMaximum(2*gt.rules.nHoursPerDay);
42 maxGapsSpinBox->setValue(2*gt.rules.nHoursPerDay);
43
44 exceptionCheckBox->setChecked(false);
45
46 teachersComboBox->clear();
47 for(int i=0; i<gt.rules.teachersList.size(); i++){
48 Teacher* tch=gt.rules.teachersList[i];
49 teachersComboBox->addItem(tch->name);
50 }
51 }
52
~AddConstraintTeacherMaxGapsPerRealDayForm()53 AddConstraintTeacherMaxGapsPerRealDayForm::~AddConstraintTeacherMaxGapsPerRealDayForm()
54 {
55 saveFETDialogGeometry(this);
56 }
57
addCurrentConstraint()58 void AddConstraintTeacherMaxGapsPerRealDayForm::addCurrentConstraint()
59 {
60 TimeConstraint *ctr=nullptr;
61
62 double weight;
63 QString tmp=weightLineEdit->text();
64 weight_sscanf(tmp, "%lf", &weight);
65 if(weight<0.0 || weight>100.0){
66 QMessageBox::warning(this, tr("FET information"),
67 tr("Invalid weight (percentage)"));
68 return;
69 }
70 if(weight!=100.0){
71 QMessageBox::warning(this, tr("FET information"),
72 tr("Invalid weight (percentage) - it must be 100%"));
73 return;
74 }
75
76 QString teacher_name=teachersComboBox->currentText();
77 int teacher_ID=gt.rules.searchTeacher(teacher_name);
78 if(teacher_ID<0){
79 QMessageBox::warning(this, tr("FET information"),
80 tr("Invalid teacher"));
81 return;
82 }
83
84 ctr=new ConstraintTeacherMaxGapsPerRealDay(weight, teacher_name, maxGapsSpinBox->value(), exceptionCheckBox->isChecked());
85
86 bool tmp2=gt.rules.addTimeConstraint(ctr);
87 if(tmp2)
88 LongTextMessageBox::information(this, tr("FET information"),
89 tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
90 else{
91 QMessageBox::warning(this, tr("FET information"),
92 tr("Constraint NOT added - please report error"));
93 delete ctr;
94 }
95 }
96