1 /***************************************************************************
2 modifyconstraintteachersactivitytagmaxhourscontinuouslyform.cpp - description
3 -------------------
4 begin : 2009
5 copyright : (C) 2009 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 "modifyconstraintteachersactivitytagmaxhourscontinuouslyform.h"
21 #include "timeconstraint.h"
22
ModifyConstraintTeachersActivityTagMaxHoursContinuouslyForm(QWidget * parent,ConstraintTeachersActivityTagMaxHoursContinuously * ctr)23 ModifyConstraintTeachersActivityTagMaxHoursContinuouslyForm::ModifyConstraintTeachersActivityTagMaxHoursContinuouslyForm(QWidget* parent, ConstraintTeachersActivityTagMaxHoursContinuously* 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 tmp4=activityTagsComboBox->minimumSizeHint();
36 Q_UNUSED(tmp4);
37
38 this->_ctr=ctr;
39
40 weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
41
42 updateMaxHoursSpinBox();
43
44 maxHoursSpinBox->setValue(ctr->maxHoursContinuously);
45
46 activityTagsComboBox->clear();
47 int j=-1;
48 for(int k=0; k<gt.rules.activityTagsList.count(); k++){
49 ActivityTag* at=gt.rules.activityTagsList.at(k);
50 activityTagsComboBox->addItem(at->name);
51 if(at->name==this->_ctr->activityTagName)
52 j=k;
53 }
54 assert(j>=0);
55 activityTagsComboBox->setCurrentIndex(j);
56 }
57
~ModifyConstraintTeachersActivityTagMaxHoursContinuouslyForm()58 ModifyConstraintTeachersActivityTagMaxHoursContinuouslyForm::~ModifyConstraintTeachersActivityTagMaxHoursContinuouslyForm()
59 {
60 saveFETDialogGeometry(this);
61 }
62
updateMaxHoursSpinBox()63 void ModifyConstraintTeachersActivityTagMaxHoursContinuouslyForm::updateMaxHoursSpinBox(){
64 maxHoursSpinBox->setMinimum(1);
65 maxHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
66 }
67
ok()68 void ModifyConstraintTeachersActivityTagMaxHoursContinuouslyForm::ok()
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 int max_hours=maxHoursSpinBox->value();
80
81 QString activityTagName=activityTagsComboBox->currentText();
82 int ati=gt.rules.searchActivityTag(activityTagName);
83 if(ati<0){
84 QMessageBox::warning(this, tr("FET warning"), tr("Invalid activity tag"));
85 return;
86 }
87
88 this->_ctr->weightPercentage=weight;
89 this->_ctr->maxHoursContinuously=max_hours;
90 this->_ctr->activityTagName=activityTagName;
91
92 gt.rules.internalStructureComputed=false;
93 setRulesModifiedAndOtherThings(>.rules);
94
95 this->close();
96 }
97
cancel()98 void ModifyConstraintTeachersActivityTagMaxHoursContinuouslyForm::cancel()
99 {
100 this->close();
101 }
102