1 /***************************************************************************
2 addconstraintstudentssetmaxhourscontinuouslyform.cpp - description
3 -------------------
4 begin : July 19, 2007
5 copyright : (C) 2007 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 "addconstraintstudentssetmaxhourscontinuouslyform.h"
23 #include "timeconstraint.h"
24
AddConstraintStudentsSetMaxHoursContinuouslyForm(QWidget * parent)25 AddConstraintStudentsSetMaxHoursContinuouslyForm::AddConstraintStudentsSetMaxHoursContinuouslyForm(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 maxHoursSpinBox->setMinimum(1);
41 maxHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
42 maxHoursSpinBox->setValue(gt.rules.nHoursPerDay);
43
44 updateStudentsSetComboBox();
45 }
46
~AddConstraintStudentsSetMaxHoursContinuouslyForm()47 AddConstraintStudentsSetMaxHoursContinuouslyForm::~AddConstraintStudentsSetMaxHoursContinuouslyForm()
48 {
49 saveFETDialogGeometry(this);
50 }
51
updateStudentsSetComboBox()52 void AddConstraintStudentsSetMaxHoursContinuouslyForm::updateStudentsSetComboBox()
53 {
54 populateStudentsComboBox(studentsComboBox);
55 }
56
addCurrentConstraint()57 void AddConstraintStudentsSetMaxHoursContinuouslyForm::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"));
67 return;
68 }
69
70 int maxHours=maxHoursSpinBox->value();
71
72 QString students_name=studentsComboBox->currentText();
73 StudentsSet* s=gt.rules.searchStudentsSet(students_name);
74 if(s==nullptr){
75 QMessageBox::warning(this, tr("FET information"),
76 tr("Invalid students set"));
77 return;
78 }
79
80 ctr=new ConstraintStudentsSetMaxHoursContinuously(weight, maxHours, students_name);
81
82 bool tmp2=gt.rules.addTimeConstraint(ctr);
83 if(tmp2)
84 LongTextMessageBox::information(this, tr("FET information"),
85 tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
86 else{
87 QMessageBox::warning(this, tr("FET information"),
88 tr("Constraint NOT added - please report error"));
89 delete ctr;
90 }
91 }
92