1 /***************************************************************************
2 addconstraintstudentssetactivitytagmaxhoursdailyrealdaysform.cpp - description
3 -------------------
4 begin : 2021
5 copyright : (C) 2021 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 "addconstraintstudentssetactivitytagmaxhoursdailyrealdaysform.h"
23 #include "timeconstraint.h"
24
AddConstraintStudentsSetActivityTagMaxHoursDailyRealDaysForm(QWidget * parent)25 AddConstraintStudentsSetActivityTagMaxHoursDailyRealDaysForm::AddConstraintStudentsSetActivityTagMaxHoursDailyRealDaysForm(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 tmp2=studentsComboBox->minimumSizeHint();
38 Q_UNUSED(tmp2);
39 QSize tmp4=activityTagsComboBox->minimumSizeHint();
40 Q_UNUSED(tmp4);
41
42 maxHoursSpinBox->setMinimum(1);
43 maxHoursSpinBox->setMaximum(2*gt.rules.nHoursPerDay);
44 maxHoursSpinBox->setValue(2*gt.rules.nHoursPerDay);
45
46 updateStudentsSetComboBox();
47
48 updateActivityTagsComboBox();
49 }
50
~AddConstraintStudentsSetActivityTagMaxHoursDailyRealDaysForm()51 AddConstraintStudentsSetActivityTagMaxHoursDailyRealDaysForm::~AddConstraintStudentsSetActivityTagMaxHoursDailyRealDaysForm()
52 {
53 saveFETDialogGeometry(this);
54 }
55
updateStudentsSetComboBox()56 void AddConstraintStudentsSetActivityTagMaxHoursDailyRealDaysForm::updateStudentsSetComboBox()
57 {
58 populateStudentsComboBox(studentsComboBox);
59 }
60
updateActivityTagsComboBox()61 void AddConstraintStudentsSetActivityTagMaxHoursDailyRealDaysForm::updateActivityTagsComboBox()
62 {
63 for(ActivityTag* at : qAsConst(gt.rules.activityTagsList))
64 activityTagsComboBox->addItem(at->name);
65 }
66
addCurrentConstraint()67 void AddConstraintStudentsSetActivityTagMaxHoursDailyRealDaysForm::addCurrentConstraint()
68 {
69 TimeConstraint *ctr=nullptr;
70
71 double weight;
72 QString tmp=weightLineEdit->text();
73 weight_sscanf(tmp, "%lf", &weight);
74 if(weight<0.0 || weight>100.0){
75 QMessageBox::warning(this, tr("FET information"),
76 tr("Invalid weight"));
77 return;
78 }
79
80 int maxHours=maxHoursSpinBox->value();
81
82 QString students_name=studentsComboBox->currentText();
83 StudentsSet* s=gt.rules.searchStudentsSet(students_name);
84 if(s==nullptr){
85 QMessageBox::warning(this, tr("FET warning"),
86 tr("Invalid students set"));
87 return;
88 }
89
90 QString activityTagName=activityTagsComboBox->currentText();
91 int acttagindex=gt.rules.searchActivityTag(activityTagName);
92 if(acttagindex<0){
93 QMessageBox::warning(this, tr("FET warning"), tr("Invalid activity tag"));
94 return;
95 }
96
97 ctr=new ConstraintStudentsSetActivityTagMaxHoursDailyRealDays(weight, maxHours, students_name, activityTagName);
98
99 bool tmp2=gt.rules.addTimeConstraint(ctr);
100 if(tmp2)
101 LongTextMessageBox::information(this, tr("FET information"),
102 tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
103 else{
104 QMessageBox::warning(this, tr("FET information"),
105 tr("Constraint NOT added - please report error"));
106 delete ctr;
107 }
108 }
109