1 /***************************************************************************
2 addconstraintteachermaxhoursdailyrealdaysform.cpp - description
3 -------------------
4 begin : 2021
5 copyright : (C) 2021 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 "addconstraintteachermaxhoursdailyrealdaysform.h"
23 #include "timeconstraint.h"
24
AddConstraintTeacherMaxHoursDailyRealDaysForm(QWidget * parent)25 AddConstraintTeacherMaxHoursDailyRealDaysForm::AddConstraintTeacherMaxHoursDailyRealDaysForm(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 updateMaxHoursSpinBox();
41
42 teachersComboBox->clear();
43 for(int i=0; i<gt.rules.teachersList.size(); i++){
44 Teacher* tch=gt.rules.teachersList[i];
45 teachersComboBox->addItem(tch->name);
46 }
47 }
48
~AddConstraintTeacherMaxHoursDailyRealDaysForm()49 AddConstraintTeacherMaxHoursDailyRealDaysForm::~AddConstraintTeacherMaxHoursDailyRealDaysForm()
50 {
51 saveFETDialogGeometry(this);
52 }
53
updateMaxHoursSpinBox()54 void AddConstraintTeacherMaxHoursDailyRealDaysForm::updateMaxHoursSpinBox(){
55 maxHoursSpinBox->setMinimum(1);
56 maxHoursSpinBox->setMaximum(2*gt.rules.nHoursPerDay);
57 maxHoursSpinBox->setValue(2*gt.rules.nHoursPerDay);
58 }
59
addCurrentConstraint()60 void AddConstraintTeacherMaxHoursDailyRealDaysForm::addCurrentConstraint()
61 {
62 TimeConstraint *ctr=nullptr;
63
64 double weight;
65 QString tmp=weightLineEdit->text();
66 weight_sscanf(tmp, "%lf", &weight);
67 if(weight<0.0 || weight>100.0){
68 QMessageBox::warning(this, tr("FET information"),
69 tr("Invalid weight (percentage)"));
70 return;
71 }
72
73 if(weight<100.0){
74 int t=QMessageBox::warning(this, tr("FET warning"),
75 tr("You selected a weight less than 100%. The generation algorithm is not perfectly optimized to work with such weights (even"
76 " if in practice it might work well). It is recommended to work only with 100% weights for these constraints. Are you sure you want to continue?"),
77 QMessageBox::Yes | QMessageBox::Cancel);
78 if(t==QMessageBox::Cancel)
79 return;
80 }
81
82 QString teacher_name=teachersComboBox->currentText();
83 int teacher_ID=gt.rules.searchTeacher(teacher_name);
84 if(teacher_ID<0){
85 QMessageBox::warning(this, tr("FET information"),
86 tr("Invalid teacher"));
87 return;
88 }
89
90 int max_hours=maxHoursSpinBox->value();
91
92 ctr=new ConstraintTeacherMaxHoursDailyRealDays(weight, max_hours, teacher_name);
93
94 bool tmp2=gt.rules.addTimeConstraint(ctr);
95 if(tmp2)
96 LongTextMessageBox::information(this, tr("FET information"),
97 tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
98 else{
99 QMessageBox::warning(this, tr("FET information"),
100 tr("Constraint NOT added - please report error"));
101 delete ctr;
102 }
103 }
104