1 /***************************************************************************
2                           modifyconstraintteachermaxgapsperdayform.cpp  -  description
3                              -------------------
4     begin                : Jan 21, 2008
5     copyright            : (C) 2008 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 "modifyconstraintteachermaxgapsperdayform.h"
21 #include "timeconstraint.h"
22 
ModifyConstraintTeacherMaxGapsPerDayForm(QWidget * parent,ConstraintTeacherMaxGapsPerDay * ctr)23 ModifyConstraintTeacherMaxGapsPerDayForm::ModifyConstraintTeacherMaxGapsPerDayForm(QWidget* parent, ConstraintTeacherMaxGapsPerDay* ctr): QDialog(parent)
24 {
25 	setupUi(this);
26 
27 	okPushButton->setDefault(true);
28 
29 	connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
30 	connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
31 
32 	centerWidgetOnScreen(this);
33 	restoreFETDialogGeometry(this);
34 
35 	QSize tmp1=teachersComboBox->minimumSizeHint();
36 	Q_UNUSED(tmp1);
37 
38 	this->_ctr=ctr;
39 
40 	weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
41 
42 	maxGapsSpinBox->setMinimum(0);
43 	maxGapsSpinBox->setMaximum(gt.rules.nHoursPerDay);
44 	maxGapsSpinBox->setValue(ctr->maxGaps);
45 
46 	teachersComboBox->clear();
47 	int i=0, j=-1;
48 	for(int k=0; k<gt.rules.teachersList.size(); k++, i++){
49 		Teacher* tch=gt.rules.teachersList[k];
50 		teachersComboBox->addItem(tch->name);
51 		if(tch->name==this->_ctr->teacherName)
52 			j=i;
53 	}
54 	assert(j>=0);
55 	teachersComboBox->setCurrentIndex(j);
56 }
57 
~ModifyConstraintTeacherMaxGapsPerDayForm()58 ModifyConstraintTeacherMaxGapsPerDayForm::~ModifyConstraintTeacherMaxGapsPerDayForm()
59 {
60 	saveFETDialogGeometry(this);
61 }
62 
ok()63 void ModifyConstraintTeacherMaxGapsPerDayForm::ok()
64 {
65 	double weight;
66 	QString tmp=weightLineEdit->text();
67 	weight_sscanf(tmp, "%lf", &weight);
68 	if(weight<0.0 || weight>100.0){
69 		QMessageBox::warning(this, tr("FET information"),
70 			tr("Invalid weight (percentage)"));
71 		return;
72 	}
73 	if(weight!=100.0){
74 		QMessageBox::warning(this, tr("FET information"),
75 			tr("Invalid weight (percentage) - it must be 100%"));
76 		return;
77 	}
78 
79 	this->_ctr->weightPercentage=weight;
80 
81 	this->_ctr->maxGaps=maxGapsSpinBox->value();
82 
83 	QString teacher_name=teachersComboBox->currentText();
84 	int teacher_ID=gt.rules.searchTeacher(teacher_name);
85 	if(teacher_ID<0){
86 		QMessageBox::warning(this, tr("FET information"),
87 			tr("Invalid teacher"));
88 		return;
89 	}
90 	this->_ctr->teacherName=teacher_name;
91 
92 	gt.rules.internalStructureComputed=false;
93 	setRulesModifiedAndOtherThings(&gt.rules);
94 
95 	this->close();
96 }
97 
cancel()98 void ModifyConstraintTeacherMaxGapsPerDayForm::cancel()
99 {
100 	this->close();
101 }
102