1 /***************************************************************************
2 modifyconstraintteachermingapsbetweenbuildingchangesform.cpp - description
3 -------------------
4 begin : Feb 10, 2005
5 copyright : (C) 2005 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 "modifyconstraintteachermingapsbetweenbuildingchangesform.h"
21 #include "spaceconstraint.h"
22
ModifyConstraintTeacherMinGapsBetweenBuildingChangesForm(QWidget * parent,ConstraintTeacherMinGapsBetweenBuildingChanges * ctr)23 ModifyConstraintTeacherMinGapsBetweenBuildingChangesForm::ModifyConstraintTeacherMinGapsBetweenBuildingChangesForm(QWidget* parent, ConstraintTeacherMinGapsBetweenBuildingChanges* 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 updateTeachersComboBox();
43
44 minGapsSpinBox->setMinimum(1);
45 minGapsSpinBox->setMaximum(gt.rules.nHoursPerDay);
46 minGapsSpinBox->setValue(ctr->minGapsBetweenBuildingChanges);
47 }
48
~ModifyConstraintTeacherMinGapsBetweenBuildingChangesForm()49 ModifyConstraintTeacherMinGapsBetweenBuildingChangesForm::~ModifyConstraintTeacherMinGapsBetweenBuildingChangesForm()
50 {
51 saveFETDialogGeometry(this);
52 }
53
updateTeachersComboBox()54 void ModifyConstraintTeacherMinGapsBetweenBuildingChangesForm::updateTeachersComboBox()
55 {
56 teachersComboBox->clear();
57 int i=0, j=-1;
58 for(int k=0; k<gt.rules.teachersList.size(); k++, i++){
59 Teacher* tch=gt.rules.teachersList[k];
60 teachersComboBox->addItem(tch->name);
61 if(tch->name==this->_ctr->teacherName)
62 j=i;
63 }
64 assert(j>=0);
65 teachersComboBox->setCurrentIndex(j);
66 }
67
ok()68 void ModifyConstraintTeacherMinGapsBetweenBuildingChangesForm::ok()
69 {
70 double weight;
71 QString tmp=weightLineEdit->text();
72 weight_sscanf(tmp, "%lf", &weight);
73 if(weight<100.0 || weight>100.0){
74 QMessageBox::warning(this, tr("FET information"),
75 tr("Invalid weight (percentage). It has to be 100"));
76 return;
77 }
78
79 QString teacher_name=teachersComboBox->currentText();
80 int t=gt.rules.searchTeacher(teacher_name);
81 if(t==-1){
82 QMessageBox::warning(this, tr("FET information"),
83 tr("Invalid teacher"));
84 return;
85 }
86
87 this->_ctr->weightPercentage=weight;
88 this->_ctr->teacherName=teacher_name;
89 this->_ctr->minGapsBetweenBuildingChanges=minGapsSpinBox->value();
90
91 gt.rules.internalStructureComputed=false;
92 setRulesModifiedAndOtherThings(>.rules);
93
94 this->close();
95 }
96
cancel()97 void ModifyConstraintTeacherMinGapsBetweenBuildingChangesForm::cancel()
98 {
99 this->close();
100 }
101