1 /***************************************************************************
2                           addconstraintteachermaxbuildingchangesperweekform.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 "addconstraintteachermaxbuildingchangesperweekform.h"
23 #include "spaceconstraint.h"
24 
AddConstraintTeacherMaxBuildingChangesPerWeekForm(QWidget * parent)25 AddConstraintTeacherMaxBuildingChangesPerWeekForm::AddConstraintTeacherMaxBuildingChangesPerWeekForm(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 	maxChangesSpinBox->setMinimum(0);
41 	maxChangesSpinBox->setMaximum(gt.rules.nHoursPerDay*gt.rules.nDaysPerWeek);
42 	maxChangesSpinBox->setValue(3);
43 
44 	updateTeachersComboBox();
45 }
46 
~AddConstraintTeacherMaxBuildingChangesPerWeekForm()47 AddConstraintTeacherMaxBuildingChangesPerWeekForm::~AddConstraintTeacherMaxBuildingChangesPerWeekForm()
48 {
49 	saveFETDialogGeometry(this);
50 }
51 
updateTeachersComboBox()52 void AddConstraintTeacherMaxBuildingChangesPerWeekForm::updateTeachersComboBox()
53 {
54 	teachersComboBox->clear();
55 	for(Teacher* tch : qAsConst(gt.rules.teachersList))
56 		teachersComboBox->addItem(tch->name);
57 }
58 
addCurrentConstraint()59 void AddConstraintTeacherMaxBuildingChangesPerWeekForm::addCurrentConstraint()
60 {
61 	SpaceConstraint *ctr=nullptr;
62 
63 	double weight;
64 	QString tmp=weightLineEdit->text();
65 	weight_sscanf(tmp, "%lf", &weight);
66 	if(weight<100.0 || weight>100.0){
67 		QMessageBox::warning(this, tr("FET information"),
68 			tr("Invalid weight (percentage). It has to be 100"));
69 		return;
70 	}
71 
72 	QString teacher_name=teachersComboBox->currentText();
73 	int t=gt.rules.searchTeacher(teacher_name);
74 	if(t==-1){
75 		QMessageBox::warning(this, tr("FET information"),
76 			tr("Invalid teacher"));
77 		return;
78 	}
79 
80 	ctr=new ConstraintTeacherMaxBuildingChangesPerWeek(weight, teacher_name, maxChangesSpinBox->value());
81 
82 	bool tmp2=gt.rules.addSpaceConstraint(ctr);
83 	if(tmp2)
84 		LongTextMessageBox::information(this, tr("FET information"),
85 			tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
86 	else{
87 		QMessageBox::warning(this, tr("FET information"),
88 			tr("Constraint NOT added - please report error"));
89 		delete ctr;
90 	}
91 }
92