1 /***************************************************************************
2                           addconstraintteachersmaxhourscontinuouslyform.cpp  -  description
3                              -------------------
4     begin                : Feb 10, 2005
5     copyright            : (C) 2005 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 "addconstraintteachersmaxhourscontinuouslyform.h"
23 #include "timeconstraint.h"
24 
AddConstraintTeachersMaxHoursContinuouslyForm(QWidget * parent)25 AddConstraintTeachersMaxHoursContinuouslyForm::AddConstraintTeachersMaxHoursContinuouslyForm(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 	updateMaxHoursSpinBox();
38 }
39 
~AddConstraintTeachersMaxHoursContinuouslyForm()40 AddConstraintTeachersMaxHoursContinuouslyForm::~AddConstraintTeachersMaxHoursContinuouslyForm()
41 {
42 	saveFETDialogGeometry(this);
43 }
44 
updateMaxHoursSpinBox()45 void AddConstraintTeachersMaxHoursContinuouslyForm::updateMaxHoursSpinBox(){
46 	maxHoursSpinBox->setMinimum(1);
47 	maxHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
48 	maxHoursSpinBox->setValue(gt.rules.nHoursPerDay);
49 }
50 
addCurrentConstraint()51 void AddConstraintTeachersMaxHoursContinuouslyForm::addCurrentConstraint()
52 {
53 	TimeConstraint *ctr=nullptr;
54 
55 	double weight;
56 	QString tmp=weightLineEdit->text();
57 	weight_sscanf(tmp, "%lf", &weight);
58 	if(weight<0.0 || weight>100.0){
59 		QMessageBox::warning(this, tr("FET information"),
60 			tr("Invalid weight (percentage)"));
61 		return;
62 	}
63 
64 	int max_hours=maxHoursSpinBox->value();
65 
66 	ctr=new ConstraintTeachersMaxHoursContinuously(weight, max_hours);
67 
68 	bool tmp2=gt.rules.addTimeConstraint(ctr);
69 	if(tmp2)
70 		LongTextMessageBox::information(this, tr("FET information"),
71 			tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
72 	else{
73 		QMessageBox::warning(this, tr("FET information"),
74 			tr("Constraint NOT added - please report error"));
75 		delete ctr;
76 	}
77 }
78