1 /***************************************************************************
2 modifyconstraintteacherminrestinghoursform.cpp - description
3 -------------------
4 begin : 2017
5 copyright : (C) 2017 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 "modifyconstraintteacherminrestinghoursform.h"
21 #include "timeconstraint.h"
22
ModifyConstraintTeacherMinRestingHoursForm(QWidget * parent,ConstraintTeacherMinRestingHours * ctr)23 ModifyConstraintTeacherMinRestingHoursForm::ModifyConstraintTeacherMinRestingHoursForm(QWidget* parent, ConstraintTeacherMinRestingHours* 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
38 this->_ctr=ctr;
39
40 weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
41
42 circularCheckBox->setChecked(ctr->circular);
43
44 minRestingHoursSpinBox->setMinimum(1);
45 minRestingHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
46 minRestingHoursSpinBox->setValue(ctr->minRestingHours);
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
~ModifyConstraintTeacherMinRestingHoursForm()60 ModifyConstraintTeacherMinRestingHoursForm::~ModifyConstraintTeacherMinRestingHoursForm()
61 {
62 saveFETDialogGeometry(this);
63 }
64
ok()65 void ModifyConstraintTeacherMinRestingHoursForm::ok()
66 {
67 double weight;
68 QString tmp=weightLineEdit->text();
69 weight_sscanf(tmp, "%lf", &weight);
70 if(weight<0.0 || weight>100.0){
71 QMessageBox::warning(this, tr("FET information"),
72 tr("Invalid weight (percentage)"));
73 return;
74 }
75 if(weight!=100.0){
76 QMessageBox::warning(this, tr("FET information"),
77 tr("Invalid weight (percentage) - it must be 100%"));
78 return;
79 }
80
81 this->_ctr->weightPercentage=weight;
82
83 this->_ctr->minRestingHours=minRestingHoursSpinBox->value();
84 this->_ctr->circular=circularCheckBox->isChecked();
85
86 QString teacher_name=teachersComboBox->currentText();
87 int teacher_ID=gt.rules.searchTeacher(teacher_name);
88 if(teacher_ID<0){
89 QMessageBox::warning(this, tr("FET information"),
90 tr("Invalid teacher"));
91 return;
92 }
93 this->_ctr->teacherName=teacher_name;
94
95 gt.rules.internalStructureComputed=false;
96 setRulesModifiedAndOtherThings(>.rules);
97
98 this->close();
99 }
100
cancel()101 void ModifyConstraintTeacherMinRestingHoursForm::cancel()
102 {
103 this->close();
104 }
105