1 /***************************************************************************
2                           modifyconstraintstudentssetmaxhoursdailyform.cpp  -  description
3                              -------------------
4     begin                : July 19, 2007
5     copyright            : (C) 2007 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 "modifyconstraintstudentssetmaxhoursdailyform.h"
21 #include "timeconstraint.h"
22 
ModifyConstraintStudentsSetMaxHoursDailyForm(QWidget * parent,ConstraintStudentsSetMaxHoursDaily * ctr)23 ModifyConstraintStudentsSetMaxHoursDailyForm::ModifyConstraintStudentsSetMaxHoursDailyForm(QWidget* parent, ConstraintStudentsSetMaxHoursDaily* 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 tmp2=studentsComboBox->minimumSizeHint();
36 	Q_UNUSED(tmp2);
37 
38 	this->_ctr=ctr;
39 
40 	weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
41 
42 	updateStudentsComboBox(parent);
43 
44 	maxHoursSpinBox->setMinimum(1);
45 	maxHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
46 	maxHoursSpinBox->setValue(ctr->maxHoursDaily);
47 }
48 
~ModifyConstraintStudentsSetMaxHoursDailyForm()49 ModifyConstraintStudentsSetMaxHoursDailyForm::~ModifyConstraintStudentsSetMaxHoursDailyForm()
50 {
51 	saveFETDialogGeometry(this);
52 }
53 
updateStudentsComboBox(QWidget * parent)54 void ModifyConstraintStudentsSetMaxHoursDailyForm::updateStudentsComboBox(QWidget* parent){
55 	int j=populateStudentsComboBox(studentsComboBox, this->_ctr->students);
56 	if(j<0)
57 		showWarningForInvisibleSubgroupConstraint(parent, this->_ctr->students);
58 	else
59 		assert(j>=0);
60 	studentsComboBox->setCurrentIndex(j);
61 }
62 
ok()63 void ModifyConstraintStudentsSetMaxHoursDailyForm::ok()
64 {
65 	if(studentsComboBox->currentIndex()<0){
66 		showWarningCannotModifyConstraintInvisibleSubgroupConstraint(this, this->_ctr->students);
67 		return;
68 	}
69 
70 	double weight;
71 	QString tmp=weightLineEdit->text();
72 	weight_sscanf(tmp, "%lf", &weight);
73 	if(weight<0.0 || weight>100.0){
74 		QMessageBox::warning(this, tr("FET information"),
75 			tr("Invalid weight (percentage)"));
76 		return;
77 	}
78 
79 	if(weight<100.0){
80 		int t=QMessageBox::warning(this, tr("FET warning"),
81 			tr("You selected a weight less than 100%. The generation algorithm is not perfectly optimized to work with such weights (even"
82 			 " if in practice it might work well). It is recommended to work only with 100% weights for these constraints. Are you sure you want to continue?"),
83 			 QMessageBox::Yes | QMessageBox::Cancel);
84 		if(t==QMessageBox::Cancel)
85 			return;
86 	}
87 
88 	QString students_name=studentsComboBox->currentText();
89 	StudentsSet* s=gt.rules.searchStudentsSet(students_name);
90 	if(s==nullptr){
91 		QMessageBox::warning(this, tr("FET information"),
92 			tr("Invalid students set"));
93 		return;
94 	}
95 
96 	this->_ctr->weightPercentage=weight;
97 	this->_ctr->students=students_name;
98 	this->_ctr->maxHoursDaily=maxHoursSpinBox->value();
99 
100 	gt.rules.internalStructureComputed=false;
101 	setRulesModifiedAndOtherThings(&gt.rules);
102 
103 	this->close();
104 }
105 
cancel()106 void ModifyConstraintStudentsSetMaxHoursDailyForm::cancel()
107 {
108 	this->close();
109 }
110