1 /***************************************************************************
2                           modifyconstraintteacheractivitytagmaxhoursdailyrealdaysform.cpp  -  description
3                              -------------------
4     begin                : 2021
5     copyright            : (C) 2021 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 "modifyconstraintteacheractivitytagmaxhoursdailyrealdaysform.h"
21 #include "timeconstraint.h"
22 
ModifyConstraintTeacherActivityTagMaxHoursDailyRealDaysForm(QWidget * parent,ConstraintTeacherActivityTagMaxHoursDailyRealDays * ctr)23 ModifyConstraintTeacherActivityTagMaxHoursDailyRealDaysForm::ModifyConstraintTeacherActivityTagMaxHoursDailyRealDaysForm(QWidget* parent, ConstraintTeacherActivityTagMaxHoursDailyRealDays* 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 	QSize tmp4=activityTagsComboBox->minimumSizeHint();
38 	Q_UNUSED(tmp4);
39 
40 	this->_ctr=ctr;
41 
42 	weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
43 
44 	updateMaxHoursSpinBox();
45 
46 	maxHoursSpinBox->setValue(ctr->maxHoursDaily);
47 
48 	teachersComboBox->clear();
49 	int i=0, j=-1;
50 	for(int k=0; k<gt.rules.teachersList.size(); k++, i++){
51 		Teacher* tch=gt.rules.teachersList[k];
52 		teachersComboBox->addItem(tch->name);
53 		if(tch->name==this->_ctr->teacherName)
54 			j=i;
55 	}
56 	assert(j>=0);
57 	teachersComboBox->setCurrentIndex(j);
58 
59 	j=-1;
60 	activityTagsComboBox->clear();
61 	for(int k=0; k<gt.rules.activityTagsList.count(); k++){
62 		ActivityTag* at=gt.rules.activityTagsList.at(k);
63 		activityTagsComboBox->addItem(at->name);
64 		if(at->name==this->_ctr->activityTagName)
65 			j=k;
66 	}
67 	assert(j>=0);
68 	activityTagsComboBox->setCurrentIndex(j);
69 }
70 
~ModifyConstraintTeacherActivityTagMaxHoursDailyRealDaysForm()71 ModifyConstraintTeacherActivityTagMaxHoursDailyRealDaysForm::~ModifyConstraintTeacherActivityTagMaxHoursDailyRealDaysForm()
72 {
73 	saveFETDialogGeometry(this);
74 }
75 
updateMaxHoursSpinBox()76 void ModifyConstraintTeacherActivityTagMaxHoursDailyRealDaysForm::updateMaxHoursSpinBox(){
77 	maxHoursSpinBox->setMinimum(1);
78 	maxHoursSpinBox->setMaximum(2*gt.rules.nHoursPerDay);
79 }
80 
ok()81 void ModifyConstraintTeacherActivityTagMaxHoursDailyRealDaysForm::ok()
82 {
83 	double weight;
84 	QString tmp=weightLineEdit->text();
85 	weight_sscanf(tmp, "%lf", &weight);
86 	if(weight<0.0 || weight>100.0){
87 		QMessageBox::warning(this, tr("FET information"),
88 			tr("Invalid weight (percentage)"));
89 		return;
90 	}
91 
92 	int max_hours=maxHoursSpinBox->value();
93 
94 	QString teacher_name=teachersComboBox->currentText();
95 	int teacher_ID=gt.rules.searchTeacher(teacher_name);
96 	if(teacher_ID<0){
97 		QMessageBox::warning(this, tr("FET warning"),
98 			tr("Invalid teacher"));
99 		return;
100 	}
101 
102 	QString activityTagName=activityTagsComboBox->currentText();
103 	int ati=gt.rules.searchActivityTag(activityTagName);
104 	if(ati<0){
105 		QMessageBox::warning(this, tr("FET warning"), tr("Invalid activity tag"));
106 		return;
107 	}
108 
109 	this->_ctr->weightPercentage=weight;
110 	this->_ctr->maxHoursDaily=max_hours;
111 	this->_ctr->teacherName=teacher_name;
112 	this->_ctr->activityTagName=activityTagName;
113 
114 	gt.rules.internalStructureComputed=false;
115 	setRulesModifiedAndOtherThings(&gt.rules);
116 
117 	this->close();
118 }
119 
cancel()120 void ModifyConstraintTeacherActivityTagMaxHoursDailyRealDaysForm::cancel()
121 {
122 	this->close();
123 }
124