1 //
2 //
3 // Description: This file is part of FET
4 //
5 //
6 // Author: Lalescu Liviu <Please see https://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)>
7 // Copyright (C) 2020 Liviu Lalescu <https://lalescu.ro/liviu/>
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 "timetable_defs.h"
19 #include "timetable.h"
20 #include "fet.h"
21 #include "modifyteacherform.h"
22 #include "teacher.h"
23 //#include "teachersubjectsqualificationsform.h"
24 
25 #include "longtextmessagebox.h"
26 
27 #include <QMessageBox>
28 
29 #include <QListWidget>
30 #include <QAbstractItemView>
31 
32 #include <QCoreApplication>
33 
34 #include <QSplitter>
35 #include <QSettings>
36 #include <QObject>
37 #include <QMetaObject>
38 
39 extern const QString COMPANY;
40 extern const QString PROGRAM;
41 
42 extern bool students_schedule_ready;
43 extern bool teachers_schedule_ready;
44 extern bool rooms_schedule_ready;
45 
ModifyTeacherForm(QWidget * parent,Teacher * _tch)46 ModifyTeacherForm::ModifyTeacherForm(QWidget* parent, Teacher* _tch): QDialog(parent)
47 {
48 	setupUi(this);
49 
50 	tch=_tch;
51 
52 	teacherNameLineEdit->setText(tch->name);
53 	teacherNameLineEdit->selectAll();
54 	teacherNameLineEdit->setFocus();
55 
56 	okPushButton->setDefault(true);
57 
58 	connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
59 	connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
60 	connect(helpPushButton, SIGNAL(clicked()), this, SLOT(help()));
61 
62 	centerWidgetOnScreen(this);
63 	restoreFETDialogGeometry(this);
64 
65 	if(gt.rules.mode==MORNINGS_AFTERNOONS){
66 		if(tch->morningsAfternoonsBehavior==TEACHER_MORNINGS_AFTERNOONS_BEHAVIOR_NOT_INITIALIZED){
67 			unrestrictedRadioButton->setChecked(false);
68 			exclusiveRadioButton->setChecked(false);
69 			oneDayExceptionRadioButton->setChecked(false);
70 			twoDaysExceptionRadioButton->setChecked(false);
71 			threeDaysExceptionRadioButton->setChecked(false);
72 			fourDaysExceptionRadioButton->setChecked(false);
73 			fiveDaysExceptionRadioButton->setChecked(false);
74 		}
75 		else if(tch->morningsAfternoonsBehavior==TEACHER_UNRESTRICTED_MORNINGS_AFTERNOONS)
76 			unrestrictedRadioButton->setChecked(true);
77 		else if(tch->morningsAfternoonsBehavior==TEACHER_MORNING_OR_EXCLUSIVELY_AFTERNOON)
78 			exclusiveRadioButton->setChecked(true);
79 		else if(tch->morningsAfternoonsBehavior==TEACHER_ONE_DAY_EXCEPTION)
80 			oneDayExceptionRadioButton->setChecked(true);
81 		else if(tch->morningsAfternoonsBehavior==TEACHER_TWO_DAYS_EXCEPTION)
82 			twoDaysExceptionRadioButton->setChecked(true);
83 		else if(tch->morningsAfternoonsBehavior==TEACHER_THREE_DAYS_EXCEPTION)
84 			threeDaysExceptionRadioButton->setChecked(true);
85 		else if(tch->morningsAfternoonsBehavior==TEACHER_FOUR_DAYS_EXCEPTION)
86 			fourDaysExceptionRadioButton->setChecked(true);
87 		else if(tch->morningsAfternoonsBehavior==TEACHER_FIVE_DAYS_EXCEPTION)
88 			fiveDaysExceptionRadioButton->setChecked(true);
89 		else
90 			assert(0);
91 	}
92 	else{
93 		unrestrictedRadioButton->setChecked(false);
94 		exclusiveRadioButton->setChecked(false);
95 		oneDayExceptionRadioButton->setChecked(false);
96 		twoDaysExceptionRadioButton->setChecked(false);
97 		threeDaysExceptionRadioButton->setChecked(false);
98 		fourDaysExceptionRadioButton->setChecked(false);
99 		fiveDaysExceptionRadioButton->setChecked(false);
100 
101 		morningsAfternoonsGroupBox->setEnabled(false);
102 	}
103 }
104 
~ModifyTeacherForm()105 ModifyTeacherForm::~ModifyTeacherForm()
106 {
107 	saveFETDialogGeometry(this);
108 }
109 
ok()110 void ModifyTeacherForm::ok()
111 {
112 	QString tn=teacherNameLineEdit->text();
113 	if(tn.isEmpty()){
114 		QMessageBox::information(this, tr("FET information"), tr("Incorrect name"));
115 		return;
116 	}
117 
118 	QString oldName=tch->name;
119 	if(tn!=oldName && gt.rules.searchTeacher(tn)>=0){
120 		QMessageBox::information(this, tr("FET information"), tr("Incorrect name - another teacher has this name"));
121 		return;
122 	}
123 
124 	int newMab=TEACHER_MORNINGS_AFTERNOONS_BEHAVIOR_NOT_INITIALIZED;
125 
126 	if(gt.rules.mode==MORNINGS_AFTERNOONS){
127 		if(unrestrictedRadioButton->isChecked()){
128 			newMab=TEACHER_UNRESTRICTED_MORNINGS_AFTERNOONS;
129 		}
130 		else if(exclusiveRadioButton->isChecked()){
131 			newMab=TEACHER_MORNING_OR_EXCLUSIVELY_AFTERNOON;
132 		}
133 		else if(oneDayExceptionRadioButton->isChecked()){
134 			newMab=TEACHER_ONE_DAY_EXCEPTION;
135 		}
136 		else if(twoDaysExceptionRadioButton->isChecked()){
137 			newMab=TEACHER_TWO_DAYS_EXCEPTION;
138 		}
139 		else if(threeDaysExceptionRadioButton->isChecked()){
140 			newMab=TEACHER_THREE_DAYS_EXCEPTION;
141 		}
142 		else if(fourDaysExceptionRadioButton->isChecked()){
143 			newMab=TEACHER_FOUR_DAYS_EXCEPTION;
144 		}
145 		else if(fiveDaysExceptionRadioButton->isChecked()){
146 			newMab=TEACHER_FIVE_DAYS_EXCEPTION;
147 		}
148 		else{
149 			QMessageBox::information(this, tr("FET warning"), tr("Please select an option for the mornings afternoons behavior.")+QString(" ")+
150 			 tr("You can press the Help button to read the information on how to correctly choose this option."));
151 			return;
152 		}
153 
154 		assert(newMab!=TEACHER_MORNINGS_AFTERNOONS_BEHAVIOR_NOT_INITIALIZED);
155 	}
156 
157 	if(tn!=oldName){
158 		gt.rules.modifyTeacher(oldName, tn);
159 
160 		tch->morningsAfternoonsBehavior=newMab;
161 	}
162 	else{
163 		tch->morningsAfternoonsBehavior=newMab;
164 
165 		gt.rules.internalStructureComputed=false;
166 		setRulesModifiedAndOtherThings(&gt.rules);
167 
168 		teachers_schedule_ready=false;
169 		students_schedule_ready=false;
170 		rooms_schedule_ready=false;
171 	}
172 
173 	this->close();
174 }
175 
cancel()176 void ModifyTeacherForm::cancel()
177 {
178 	this->close();
179 }
180 
help()181 void ModifyTeacherForm::help()
182 {
183 	QString s;
184 
185 	if(gt.rules.mode==MORNINGS_AFTERNOONS){
186 		s+=QCoreApplication::translate("MorningsAfternoonsTeacherBehavior", "To allow the teacher to work only in the morning or in the afternoon on each day but not both, use the option 'Exclusive'.");
187 		s+="\n\n";
188 		s+=QCoreApplication::translate("MorningsAfternoonsTeacherBehavior", "To allow the teacher to work only in the morning or in the afternoon on each day, not both, but with the exception of a single day"
189 		 " in which the teacher can work both in the morning and in the afternoon, use 'One day exception'.");
190 		s+="\n\n";
191 		s+=QCoreApplication::translate("MorningsAfternoonsTeacherBehavior", "Similarly, to say that a teacher should work in the morning or in the afternoon, not both, but with the exception of two days in which"
192 		 " the teacher can work both in the morning and in the afternoon, use 'Two days exception'.");
193 		s+="\n\n";
194 		s+=QCoreApplication::translate("MorningsAfternoonsTeacherBehavior", "Similarly, you can say that a teacher should work in the morning or in the afternoon, not both, but with the exception of three, four, or"
195 		 " five days exceptions in which the teacher can work both in the morning and in the afternoon: 'Three days exception', 'Four days exception',"
196 		 " 'Five days exception'.");
197 		s+="\n\n";
198 		s+=QCoreApplication::translate("MorningsAfternoonsTeacherBehavior", "To allow the teacher to work both in the morning and afternoon on each day, use the option 'Unrestricted'.");
199 	}
200 	else{
201 		s+=tr("Since you are not using the mornings-afternoons mode of FET, you need to simply input a non-existing teacher name.");
202 	}
203 
204 	LongTextMessageBox::largeInformation(this, tr("FET help"), s);
205 }
206