1 /***************************************************************************
2 addconstraintteachermaxhoursperallafternoonsform.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 "longtextmessagebox.h"
21
22 #include "addconstraintteachermaxhoursperallafternoonsform.h"
23 #include "timeconstraint.h"
24
AddConstraintTeacherMaxHoursPerAllAfternoonsForm(QWidget * parent)25 AddConstraintTeacherMaxHoursPerAllAfternoonsForm::AddConstraintTeacherMaxHoursPerAllAfternoonsForm(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
~AddConstraintTeacherMaxHoursPerAllAfternoonsForm()49 AddConstraintTeacherMaxHoursPerAllAfternoonsForm::~AddConstraintTeacherMaxHoursPerAllAfternoonsForm()
50 {
51 saveFETDialogGeometry(this);
52 }
53
updateMaxHoursSpinBox()54 void AddConstraintTeacherMaxHoursPerAllAfternoonsForm::updateMaxHoursSpinBox(){
55 maxHoursSpinBox->setMinimum(0);
56 maxHoursSpinBox->setMaximum(gt.rules.nDaysPerWeek*gt.rules.nHoursPerDay/2);
57 maxHoursSpinBox->setValue(gt.rules.nDaysPerWeek*gt.rules.nHoursPerDay/2);
58 }
59
addCurrentConstraint()60 void AddConstraintTeacherMaxHoursPerAllAfternoonsForm::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 if(weight!=100.0){
73 QMessageBox::warning(this, tr("FET information"),
74 tr("Invalid weight (percentage) - must be 100%"));
75 return;
76 }
77
78 QString teacher_name=teachersComboBox->currentText();
79 int teacher_ID=gt.rules.searchTeacher(teacher_name);
80 if(teacher_ID<0){
81 QMessageBox::warning(this, tr("FET information"),
82 tr("Invalid teacher"));
83 return;
84 }
85
86 int max_hours=maxHoursSpinBox->value();
87
88 ctr=new ConstraintTeacherMaxHoursPerAllAfternoons(weight, max_hours, teacher_name);
89
90 bool tmp2=gt.rules.addTimeConstraint(ctr);
91 if(tmp2)
92 LongTextMessageBox::information(this, tr("FET information"),
93 tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
94 else{
95 QMessageBox::warning(this, tr("FET information"),
96 tr("Constraint NOT added - please report error"));
97 delete ctr;
98 }
99 }
100