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