1 /***************************************************************************
2                           addconstraintteachersactivitytagmaxhoursdailyform.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 "longtextmessagebox.h"
21 
22 #include "addconstraintteachersactivitytagmaxhoursdailyform.h"
23 #include "timeconstraint.h"
24 
AddConstraintTeachersActivityTagMaxHoursDailyForm(QWidget * parent)25 AddConstraintTeachersActivityTagMaxHoursDailyForm::AddConstraintTeachersActivityTagMaxHoursDailyForm(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 	updateMaxHoursSpinBox();
41 
42 	activityTagsComboBox->clear();
43 	for(ActivityTag* at : qAsConst(gt.rules.activityTagsList))
44 		activityTagsComboBox->addItem(at->name);
45 }
46 
~AddConstraintTeachersActivityTagMaxHoursDailyForm()47 AddConstraintTeachersActivityTagMaxHoursDailyForm::~AddConstraintTeachersActivityTagMaxHoursDailyForm()
48 {
49 	saveFETDialogGeometry(this);
50 }
51 
updateMaxHoursSpinBox()52 void AddConstraintTeachersActivityTagMaxHoursDailyForm::updateMaxHoursSpinBox(){
53 	maxHoursSpinBox->setMinimum(1);
54 	maxHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
55 	maxHoursSpinBox->setValue(gt.rules.nHoursPerDay);
56 }
57 
addCurrentConstraint()58 void AddConstraintTeachersActivityTagMaxHoursDailyForm::addCurrentConstraint()
59 {
60 	TimeConstraint *ctr=nullptr;
61 
62 	double weight;
63 	QString tmp=weightLineEdit->text();
64 	weight_sscanf(tmp, "%lf", &weight);
65 	if(weight<0.0 || weight>100.0){
66 		QMessageBox::warning(this, tr("FET warning"),
67 			tr("Invalid weight (percentage)"));
68 		return;
69 	}
70 
71 	QString activityTagName=activityTagsComboBox->currentText();
72 	int activityTagIndex=gt.rules.searchActivityTag(activityTagName);
73 	if(activityTagIndex<0){
74 		QMessageBox::warning(this, tr("FET warning"),
75 			tr("Invalid activity tag"));
76 		return;
77 	}
78 
79 	int max_hours=maxHoursSpinBox->value();
80 
81 	ctr=new ConstraintTeachersActivityTagMaxHoursDaily(weight, max_hours, activityTagName);
82 
83 	bool tmp2=gt.rules.addTimeConstraint(ctr);
84 	if(tmp2)
85 		LongTextMessageBox::information(this, tr("FET information"),
86 			tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
87 	else{
88 		QMessageBox::warning(this, tr("FET information"),
89 			tr("Constraint NOT added - please report error"));
90 		delete ctr;
91 	}
92 }
93