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