1 /***************************************************************************
2                           modifyconstraintstudentsactivitytagminhoursdailyform.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 "modifyconstraintstudentsactivitytagminhoursdailyform.h"
21 #include "timeconstraint.h"
22 
ModifyConstraintStudentsActivityTagMinHoursDailyForm(QWidget * parent,ConstraintStudentsActivityTagMinHoursDaily * ctr)23 ModifyConstraintStudentsActivityTagMinHoursDailyForm::ModifyConstraintStudentsActivityTagMinHoursDailyForm(QWidget* parent, ConstraintStudentsActivityTagMinHoursDaily* 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 	updateActivityTagsComboBox();
43 
44 	minHoursSpinBox->setMinimum(1);
45 	minHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
46 	minHoursSpinBox->setValue(ctr->minHoursDaily);
47 
48 	allowEmptyDaysCheckBox->setChecked(ctr->allowEmptyDays);
49 }
50 
~ModifyConstraintStudentsActivityTagMinHoursDailyForm()51 ModifyConstraintStudentsActivityTagMinHoursDailyForm::~ModifyConstraintStudentsActivityTagMinHoursDailyForm()
52 {
53 	saveFETDialogGeometry(this);
54 }
55 
updateActivityTagsComboBox()56 void ModifyConstraintStudentsActivityTagMinHoursDailyForm::updateActivityTagsComboBox()
57 {
58 	activityTagsComboBox->clear();
59 	int j=-1;
60 	for(int i=0; i<gt.rules.activityTagsList.count(); i++){
61 		ActivityTag* at=gt.rules.activityTagsList.at(i);
62 		activityTagsComboBox->addItem(at->name);
63 		if(at->name==this->_ctr->activityTagName)
64 			j=i;
65 	}
66 	assert(j>=0);
67 	activityTagsComboBox->setCurrentIndex(j);
68 }
69 
ok()70 void ModifyConstraintStudentsActivityTagMinHoursDailyForm::ok()
71 {
72 	double weight;
73 	QString tmp=weightLineEdit->text();
74 	weight_sscanf(tmp, "%lf", &weight);
75 	if(weight<100.0 || weight>100.0){
76 		QMessageBox::warning(this, tr("FET warning"),
77 			tr("Invalid weight (percentage). It has to be 100"));
78 		return;
79 	}
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 	if(allowEmptyDaysCheckBox->isChecked() && minHoursSpinBox->value()==1){
89 		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."));
90 		return;
91 	}
92 
93 	this->_ctr->weightPercentage=weight;
94 	this->_ctr->activityTagName=activityTagName;
95 	this->_ctr->minHoursDaily=minHoursSpinBox->value();
96 	this->_ctr->allowEmptyDays=allowEmptyDaysCheckBox->isChecked();
97 
98 	gt.rules.internalStructureComputed=false;
99 	setRulesModifiedAndOtherThings(&gt.rules);
100 
101 	this->close();
102 }
103 
cancel()104 void ModifyConstraintStudentsActivityTagMinHoursDailyForm::cancel()
105 {
106 	this->close();
107 }
108