1 /***************************************************************************
2                           addconstraintteachersmaxspanperrealdayform.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 "addconstraintteachersmaxspanperrealdayform.h"
23 #include "timeconstraint.h"
24 
AddConstraintTeachersMaxSpanPerRealDayForm(QWidget * parent)25 AddConstraintTeachersMaxSpanPerRealDayForm::AddConstraintTeachersMaxSpanPerRealDayForm(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 	maxSpanSpinBox->setMinimum(1);
38 	maxSpanSpinBox->setMaximum(2*gt.rules.nHoursPerDay);
39 	maxSpanSpinBox->setValue(2*gt.rules.nHoursPerDay);
40 
41 	exceptionCheckBox->setChecked(false);
42 }
43 
~AddConstraintTeachersMaxSpanPerRealDayForm()44 AddConstraintTeachersMaxSpanPerRealDayForm::~AddConstraintTeachersMaxSpanPerRealDayForm()
45 {
46 	saveFETDialogGeometry(this);
47 }
48 
addCurrentConstraint()49 void AddConstraintTeachersMaxSpanPerRealDayForm::addCurrentConstraint()
50 {
51 	TimeConstraint *ctr=nullptr;
52 
53 	double weight;
54 	QString tmp=weightLineEdit->text();
55 	weight_sscanf(tmp, "%lf", &weight);
56 	if(weight<0.0 || weight>100.0){
57 		QMessageBox::warning(this, tr("FET information"),
58 			tr("Invalid weight (percentage)"));
59 		return;
60 	}
61 	if(weight!=100.0){
62 		QMessageBox::warning(this, tr("FET information"),
63 			tr("Invalid weight (percentage) - it must be 100%"));
64 		return;
65 	}
66 
67 	ctr=new ConstraintTeachersMaxSpanPerRealDay(weight, maxSpanSpinBox->value(), exceptionCheckBox->isChecked());
68 
69 	bool tmp2=gt.rules.addTimeConstraint(ctr);
70 	if(tmp2)
71 		LongTextMessageBox::information(this, tr("FET information"),
72 			tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
73 	else{
74 		QMessageBox::warning(this, tr("FET information"),
75 			tr("Constraint NOT added - please report error"));
76 		delete ctr;
77 	}
78 }
79