1 /***************************************************************************
2                           addconstraintteachermaxtwoconsecutivemorningsform.cpp  -  description
3                              -------------------
4     begin                : Oct 15, 2015
5     copyright            : (C) 2015 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 "addconstraintteachermaxtwoconsecutivemorningsform.h"
23 #include "timeconstraint.h"
24 
AddConstraintTeacherMaxTwoConsecutiveMorningsForm(QWidget * parent)25 AddConstraintTeacherMaxTwoConsecutiveMorningsForm::AddConstraintTeacherMaxTwoConsecutiveMorningsForm(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 	updateTeachersComboBox();
41 }
42 
~AddConstraintTeacherMaxTwoConsecutiveMorningsForm()43 AddConstraintTeacherMaxTwoConsecutiveMorningsForm::~AddConstraintTeacherMaxTwoConsecutiveMorningsForm()
44 {
45 	saveFETDialogGeometry(this);
46 }
47 
updateTeachersComboBox()48 void AddConstraintTeacherMaxTwoConsecutiveMorningsForm::updateTeachersComboBox(){
49 	teachersComboBox->clear();
50 	for(int i=0; i<gt.rules.teachersList.size(); i++){
51 		Teacher* tch=gt.rules.teachersList[i];
52 		teachersComboBox->addItem(tch->name);
53 	}
54 }
55 
addCurrentConstraint()56 void AddConstraintTeacherMaxTwoConsecutiveMorningsForm::addCurrentConstraint()
57 {
58 	TimeConstraint *ctr=nullptr;
59 
60 	double weight;
61 	QString tmp=weightLineEdit->text();
62 	weight_sscanf(tmp, "%lf", &weight);
63 	if(weight<0.0 || weight>100.0){
64 		QMessageBox::warning(this, tr("FET information"),
65 			tr("Invalid weight (percentage)"));
66 		return;
67 	}
68 	if(weight!=100.0){
69 		QMessageBox::warning(this, tr("FET information"),
70 			tr("Invalid weight (percentage) - it has to be 100%"));
71 		return;
72 	}
73 
74 	QString teacher_name=teachersComboBox->currentText();
75 	int teacher_ID=gt.rules.searchTeacher(teacher_name);
76 	if(teacher_ID<0){
77 		QMessageBox::warning(this, tr("FET information"),
78 			tr("Invalid teacher"));
79 		return;
80 	}
81 
82 	ctr=new ConstraintTeacherMaxTwoConsecutiveMornings(weight, teacher_name);
83 
84 	bool tmp2=gt.rules.addTimeConstraint(ctr);
85 	if(tmp2)
86 		LongTextMessageBox::information(this, tr("FET information"),
87 			tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
88 	else{
89 		QMessageBox::warning(this, tr("FET information"),
90 			tr("Constraint NOT added - please report error"));
91 		delete ctr;
92 	}
93 }
94