1 /***************************************************************************
2                           modifyconstraintteacherhomeroomform.cpp  -  description
3                              -------------------
4     begin                : 8 Apr 2005
5     copyright            : (C) 2005 by Liviu Lalescu
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 "modifyconstraintteacherhomeroomform.h"
21 #include "spaceconstraint.h"
22 
ModifyConstraintTeacherHomeRoomForm(QWidget * parent,ConstraintTeacherHomeRoom * ctr)23 ModifyConstraintTeacherHomeRoomForm::ModifyConstraintTeacherHomeRoomForm(QWidget* parent, ConstraintTeacherHomeRoom* ctr): QDialog(parent)
24 {
25 	setupUi(this);
26 
27 	okPushButton->setDefault(true);
28 
29 	connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
30 	connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
31 
32 	centerWidgetOnScreen(this);
33 	restoreFETDialogGeometry(this);
34 
35 	QSize tmp1=teachersComboBox->minimumSizeHint();
36 	Q_UNUSED(tmp1);
37 
38 	QSize tmp5=roomsComboBox->minimumSizeHint();
39 	Q_UNUSED(tmp5);
40 
41 	this->_ctr=ctr;
42 
43 	weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
44 
45 	updateTeachersComboBox();
46 	updateRoomsComboBox();
47 }
48 
~ModifyConstraintTeacherHomeRoomForm()49 ModifyConstraintTeacherHomeRoomForm::~ModifyConstraintTeacherHomeRoomForm()
50 {
51 	saveFETDialogGeometry(this);
52 }
53 
updateTeachersComboBox()54 void ModifyConstraintTeacherHomeRoomForm::updateTeachersComboBox(){
55 	teachersComboBox->clear();
56 	int i=0, j=-1;
57 	for(int k=0; k<gt.rules.teachersList.size(); k++, i++){
58 		Teacher* tch=gt.rules.teachersList[k];
59 		teachersComboBox->addItem(tch->name);
60 		if(tch->name==this->_ctr->teacherName)
61 			j=i;
62 	}
63 	assert(j>=0);
64 	teachersComboBox->setCurrentIndex(j);
65 }
66 
updateRoomsComboBox()67 void ModifyConstraintTeacherHomeRoomForm::updateRoomsComboBox()
68 {
69 	int i=0, j=-1;
70 	roomsComboBox->clear();
71 	for(int k=0; k<gt.rules.roomsList.size(); k++){
72 		Room* rm=gt.rules.roomsList[k];
73 		roomsComboBox->addItem(rm->name);
74 		if(rm->name==this->_ctr->roomName)
75 			j=i;
76 		i++;
77 	}
78 	assert(j>=0);
79 	roomsComboBox->setCurrentIndex(j);
80 }
81 
cancel()82 void ModifyConstraintTeacherHomeRoomForm::cancel()
83 {
84 	this->close();
85 }
86 
ok()87 void ModifyConstraintTeacherHomeRoomForm::ok()
88 {
89 	double weight;
90 	QString tmp=weightLineEdit->text();
91 	weight_sscanf(tmp, "%lf", &weight);
92 	if(weight<0.0 || weight>100){
93 		QMessageBox::warning(this, tr("FET information"),
94 			tr("Invalid weight"));
95 		return;
96 	}
97 
98 	QString teacher=teachersComboBox->currentText();
99 	assert(gt.rules.searchTeacher(teacher)>=0);
100 
101 	int i=roomsComboBox->currentIndex();
102 	if(i<0 || roomsComboBox->count()<=0){
103 		QMessageBox::warning(this, tr("FET information"),
104 			tr("Invalid room"));
105 		return;
106 	}
107 	QString room=roomsComboBox->currentText();
108 
109 	this->_ctr->weightPercentage=weight;
110 	this->_ctr->roomName=room;
111 	this->_ctr->teacherName=teacher;
112 
113 	gt.rules.internalStructureComputed=false;
114 	setRulesModifiedAndOtherThings(&gt.rules);
115 
116 	this->close();
117 }
118