1 /***************************************************************************
2 addconstraintstudentssetmaxgapsperrealdayform.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 "addconstraintstudentssetmaxgapsperrealdayform.h"
23 #include "timeconstraint.h"
24
AddConstraintStudentsSetMaxGapsPerRealDayForm(QWidget * parent)25 AddConstraintStudentsSetMaxGapsPerRealDayForm::AddConstraintStudentsSetMaxGapsPerRealDayForm(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 tmp2=studentsComboBox->minimumSizeHint();
38 Q_UNUSED(tmp2);
39
40 maxGapsSpinBox->setMinimum(0);
41 maxGapsSpinBox->setMaximum(2*gt.rules.nHoursPerDay);
42 maxGapsSpinBox->setValue(2*gt.rules.nHoursPerDay);
43
44 updateStudentsSetComboBox();
45 }
46
~AddConstraintStudentsSetMaxGapsPerRealDayForm()47 AddConstraintStudentsSetMaxGapsPerRealDayForm::~AddConstraintStudentsSetMaxGapsPerRealDayForm()
48 {
49 saveFETDialogGeometry(this);
50 }
51
updateStudentsSetComboBox()52 void AddConstraintStudentsSetMaxGapsPerRealDayForm::updateStudentsSetComboBox()
53 {
54 populateStudentsComboBox(studentsComboBox);
55 }
56
addCurrentConstraint()57 void AddConstraintStudentsSetMaxGapsPerRealDayForm::addCurrentConstraint()
58 {
59 TimeConstraint *ctr=nullptr;
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 QString students_name=studentsComboBox->currentText();
76 StudentsSet* s=gt.rules.searchStudentsSet(students_name);
77 if(s==nullptr){
78 QMessageBox::warning(this, tr("FET information"),
79 tr("Invalid students set"));
80 return;
81 }
82
83 ctr=new ConstraintStudentsSetMaxGapsPerRealDay(weight, maxGapsSpinBox->value(), students_name);
84
85 bool tmp2=gt.rules.addTimeConstraint(ctr);
86 if(tmp2)
87 LongTextMessageBox::information(this, tr("FET information"),
88 tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
89 else{
90 QMessageBox::warning(this, tr("FET information"),
91 tr("Constraint NOT added - please report error"));
92 delete ctr;
93 }
94 }
95