1 /***************************************************************************
2                           modifyconstraintteacherintervalmaxdaysperweekform.cpp  -  description
3                              -------------------
4     begin                : 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 "modifyconstraintteacherintervalmaxdaysperweekform.h"
21 #include "timeconstraint.h"
22 
ModifyConstraintTeacherIntervalMaxDaysPerWeekForm(QWidget * parent,ConstraintTeacherIntervalMaxDaysPerWeek * ctr)23 ModifyConstraintTeacherIntervalMaxDaysPerWeekForm::ModifyConstraintTeacherIntervalMaxDaysPerWeekForm(QWidget* parent, ConstraintTeacherIntervalMaxDaysPerWeek* 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 	QSize tmp5=startHourComboBox->minimumSizeHint();
39 	Q_UNUSED(tmp5);
40 	QSize tmp6=endHourComboBox->minimumSizeHint();
41 	Q_UNUSED(tmp6);
42 
43 	this->_ctr=ctr;
44 
45 	weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
46 
47 	updateMaxDaysSpinBox();
48 	updateTeachersComboBox();
49 
50 	maxDaysSpinBox->setValue(ctr->maxDaysPerWeek);
51 
52 	for(int i=0; i<gt.rules.nHoursPerDay; i++){
53 		startHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
54 	}
55 	startHourComboBox->setCurrentIndex(ctr->startHour);
56 
57 	for(int i=0; i<gt.rules.nHoursPerDay; i++){
58 		endHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
59 	}
60 	endHourComboBox->addItem(tr("End of day"));
61 	endHourComboBox->setCurrentIndex(ctr->endHour);
62 }
63 
~ModifyConstraintTeacherIntervalMaxDaysPerWeekForm()64 ModifyConstraintTeacherIntervalMaxDaysPerWeekForm::~ModifyConstraintTeacherIntervalMaxDaysPerWeekForm()
65 {
66 	saveFETDialogGeometry(this);
67 }
68 
updateTeachersComboBox()69 void ModifyConstraintTeacherIntervalMaxDaysPerWeekForm::updateTeachersComboBox(){
70 	teachersComboBox->clear();
71 	int i=0, j=-1;
72 	for(int k=0; k<gt.rules.teachersList.size(); k++, i++){
73 		Teacher* tch=gt.rules.teachersList[k];
74 		teachersComboBox->addItem(tch->name);
75 		if(tch->name==this->_ctr->teacherName)
76 			j=i;
77 	}
78 	assert(j>=0);
79 	teachersComboBox->setCurrentIndex(j);
80 }
81 
updateMaxDaysSpinBox()82 void ModifyConstraintTeacherIntervalMaxDaysPerWeekForm::updateMaxDaysSpinBox(){
83 	maxDaysSpinBox->setMinimum(0);
84 	maxDaysSpinBox->setMaximum(gt.rules.nDaysPerWeek);
85 }
86 
ok()87 void ModifyConstraintTeacherIntervalMaxDaysPerWeekForm::ok()
88 {
89 	double weight;
90 	QString tmp=weightLineEdit->text();
91 	weight_sscanf(tmp, "%lf", &weight);
92 	if(weight<0.0 || weight>100.0){
93 		QMessageBox::warning(this, tr("FET information"),
94 			tr("Invalid weight (percentage)"));
95 		return;
96 	}
97 	if(weight!=100.0){
98 		QMessageBox::warning(this, tr("FET information"),
99 			tr("Invalid weight (percentage) - it has to be 100%"));
100 		return;
101 	}
102 
103 	int max_days=maxDaysSpinBox->value();
104 
105 	QString teacher_name=teachersComboBox->currentText();
106 	int teacher_ID=gt.rules.searchTeacher(teacher_name);
107 	if(teacher_ID<0){
108 		QMessageBox::warning(this, tr("FET information"),
109 			tr("Invalid teacher"));
110 		return;
111 	}
112 
113 	int startHour=startHourComboBox->currentIndex();
114 	int endHour=endHourComboBox->currentIndex();
115 	if(startHour<0 || startHour>=gt.rules.nHoursPerDay){
116 		QMessageBox::warning(this, tr("FET information"),
117 		 tr("Start hour invalid"));
118 		return;
119 	}
120 	if(endHour<0 || endHour>gt.rules.nHoursPerDay){
121 		QMessageBox::warning(this, tr("FET information"),
122 		 tr("End hour invalid"));
123 		return;
124 	}
125 	if(endHour<=startHour){
126 		QMessageBox::warning(this, tr("FET information"),
127 		 tr("Start hour cannot be greater or equal than end hour"));
128 		return;
129 	}
130 
131 	this->_ctr->weightPercentage=weight;
132 	this->_ctr->maxDaysPerWeek=max_days;
133 	this->_ctr->teacherName=teacher_name;
134 
135 	this->_ctr->startHour=startHour;
136 	this->_ctr->endHour=endHour;
137 
138 	gt.rules.internalStructureComputed=false;
139 	setRulesModifiedAndOtherThings(&gt.rules);
140 
141 	this->close();
142 }
143 
cancel()144 void ModifyConstraintTeacherIntervalMaxDaysPerWeekForm::cancel()
145 {
146 	this->close();
147 }
148