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