1 /***************************************************************************
2 addconstraintteachersactivitytagminhoursdailyform.cpp - description
3 -------------------
4 begin : 2019
5 copyright : (C) 2019 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 "longtextmessagebox.h"
21
22 #include "addconstraintteachersactivitytagminhoursdailyform.h"
23 #include "timeconstraint.h"
24
AddConstraintTeachersActivityTagMinHoursDailyForm(QWidget * parent)25 AddConstraintTeachersActivityTagMinHoursDailyForm::AddConstraintTeachersActivityTagMinHoursDailyForm(QWidget* parent): QDialog(parent)
26 {
27 setupUi(this);
28
29 addConstraintPushButton->setDefault(true);
30
31 connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addCurrentConstraint()));
32 connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
33
34 centerWidgetOnScreen(this);
35 restoreFETDialogGeometry(this);
36
37 QSize tmp4=activityTagsComboBox->minimumSizeHint();
38 Q_UNUSED(tmp4);
39
40 updateMinHoursSpinBox();
41
42 allowEmptyDaysCheckBox->setChecked(false);
43
44 activityTagsComboBox->clear();
45 for(ActivityTag* at : qAsConst(gt.rules.activityTagsList))
46 activityTagsComboBox->addItem(at->name);
47 }
48
~AddConstraintTeachersActivityTagMinHoursDailyForm()49 AddConstraintTeachersActivityTagMinHoursDailyForm::~AddConstraintTeachersActivityTagMinHoursDailyForm()
50 {
51 saveFETDialogGeometry(this);
52 }
53
updateMinHoursSpinBox()54 void AddConstraintTeachersActivityTagMinHoursDailyForm::updateMinHoursSpinBox(){
55 minHoursSpinBox->setMinimum(1);
56 minHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
57 minHoursSpinBox->setValue(1);
58 }
59
addCurrentConstraint()60 void AddConstraintTeachersActivityTagMinHoursDailyForm::addCurrentConstraint()
61 {
62 TimeConstraint *ctr=nullptr;
63
64 double weight;
65 QString tmp=weightLineEdit->text();
66 weight_sscanf(tmp, "%lf", &weight);
67 if(weight<100.0 || weight>100.0){
68 QMessageBox::warning(this, tr("FET warning"),
69 tr("Invalid weight (percentage). It has to be 100"));
70 return;
71 }
72
73 QString activityTagName=activityTagsComboBox->currentText();
74 int activityTagIndex=gt.rules.searchActivityTag(activityTagName);
75 if(activityTagIndex<0){
76 QMessageBox::warning(this, tr("FET warning"),
77 tr("Invalid activity tag"));
78 return;
79 }
80
81 if(allowEmptyDaysCheckBox->isChecked() && minHoursSpinBox->value()==1){
82 QMessageBox::warning(this, tr("FET warning"), tr("Allow empty days is selected and min hours daily is 1, so this would be a useless constraint."));
83 return;
84 }
85
86 int min_hours=minHoursSpinBox->value();
87
88 ctr=new ConstraintTeachersActivityTagMinHoursDaily(weight, min_hours, allowEmptyDaysCheckBox->isChecked(), activityTagName);
89
90 bool tmp2=gt.rules.addTimeConstraint(ctr);
91 if(tmp2)
92 LongTextMessageBox::information(this, tr("FET information"),
93 tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
94 else{
95 QMessageBox::warning(this, tr("FET information"),
96 tr("Constraint NOT added - please report error"));
97 delete ctr;
98 }
99 }
100