1 /***************************************************************************
2 modifyconstraintstudentssetminafternoonsperweekform.cpp - description
3 -------------------
4 begin : 2020
5 copyright : (C) 2020 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 "modifyconstraintstudentssetminafternoonsperweekform.h"
21 #include "timeconstraint.h"
22
ModifyConstraintStudentsSetMinAfternoonsPerWeekForm(QWidget * parent,ConstraintStudentsSetMinAfternoonsPerWeek * ctr)23 ModifyConstraintStudentsSetMinAfternoonsPerWeekForm::ModifyConstraintStudentsSetMinAfternoonsPerWeekForm(QWidget* parent, ConstraintStudentsSetMinAfternoonsPerWeek* 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 updateMinAfternoonsSpinBox();
43 updateStudentsComboBox(parent);
44
45 minAfternoonsSpinBox->setValue(ctr->minAfternoonsPerWeek);
46 }
47
~ModifyConstraintStudentsSetMinAfternoonsPerWeekForm()48 ModifyConstraintStudentsSetMinAfternoonsPerWeekForm::~ModifyConstraintStudentsSetMinAfternoonsPerWeekForm()
49 {
50 saveFETDialogGeometry(this);
51 }
52
updateStudentsComboBox(QWidget * parent)53 void ModifyConstraintStudentsSetMinAfternoonsPerWeekForm::updateStudentsComboBox(QWidget* parent){
54 int j=populateStudentsComboBox(studentsComboBox, this->_ctr->students);
55 if(j<0)
56 showWarningForInvisibleSubgroupConstraint(parent, this->_ctr->students);
57 else
58 assert(j>=0);
59 studentsComboBox->setCurrentIndex(j);
60 }
61
updateMinAfternoonsSpinBox()62 void ModifyConstraintStudentsSetMinAfternoonsPerWeekForm::updateMinAfternoonsSpinBox(){
63 minAfternoonsSpinBox->setMinimum(0);
64 minAfternoonsSpinBox->setMaximum(gt.rules.nDaysPerWeek/2);
65 }
66
ok()67 void ModifyConstraintStudentsSetMinAfternoonsPerWeekForm::ok()
68 {
69 if(studentsComboBox->currentIndex()<0){
70 showWarningCannotModifyConstraintInvisibleSubgroupConstraint(this, this->_ctr->students);
71 return;
72 }
73
74 double weight;
75 QString tmp=weightLineEdit->text();
76 weight_sscanf(tmp, "%lf", &weight);
77 if(weight<0.0 || weight>100.0){
78 QMessageBox::warning(this, tr("FET information"),
79 tr("Invalid weight (percentage)"));
80 return;
81 }
82 if(weight!=100.0){
83 QMessageBox::warning(this, tr("FET information"),
84 tr("Invalid weight (percentage) - it has to be 100%"));
85 return;
86 }
87
88 int min_afternoons=minAfternoonsSpinBox->value();
89
90 QString students_name=studentsComboBox->currentText();
91 StudentsSet* s=gt.rules.searchStudentsSet(students_name);
92 if(s==nullptr){
93 QMessageBox::warning(this, tr("FET information"),
94 tr("Invalid students set"));
95 return;
96 }
97
98 this->_ctr->weightPercentage=weight;
99 this->_ctr->minAfternoonsPerWeek=min_afternoons;
100 this->_ctr->students=students_name;
101
102 gt.rules.internalStructureComputed=false;
103 setRulesModifiedAndOtherThings(>.rules);
104
105 this->close();
106 }
107
cancel()108 void ModifyConstraintStudentsSetMinAfternoonsPerWeekForm::cancel()
109 {
110 this->close();
111 }
112