1 /***************************************************************************
2 modifyconstraintactivitiesendteachersdayform.cpp - description
3 -------------------
4 begin : 2020
5 copyright : (C) 2020 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 "modifyconstraintactivitiesendteachersdayform.h"
21 #include "timeconstraint.h"
22
ModifyConstraintActivitiesEndTeachersDayForm(QWidget * parent,ConstraintActivitiesEndTeachersDay * ctr)23 ModifyConstraintActivitiesEndTeachersDayForm::ModifyConstraintActivitiesEndTeachersDayForm(QWidget* parent, ConstraintActivitiesEndTeachersDay* ctr): QDialog(parent)
24 {
25 setupUi(this);
26
27 okPushButton->setDefault(true);
28
29 connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
30 connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
31
32 centerWidgetOnScreen(this);
33 restoreFETDialogGeometry(this);
34
35 QSize tmp1=teachersComboBox->minimumSizeHint();
36 Q_UNUSED(tmp1);
37 QSize tmp2=studentsComboBox->minimumSizeHint();
38 Q_UNUSED(tmp2);
39 QSize tmp3=subjectsComboBox->minimumSizeHint();
40 Q_UNUSED(tmp3);
41 QSize tmp4=activityTagsComboBox->minimumSizeHint();
42 Q_UNUSED(tmp4);
43
44 this->_ctr=ctr;
45
46 updateTeachersComboBox();
47 updateStudentsComboBox(parent);
48 updateSubjectsComboBox();
49 updateActivityTagsComboBox();
50
51 weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
52 }
53
~ModifyConstraintActivitiesEndTeachersDayForm()54 ModifyConstraintActivitiesEndTeachersDayForm::~ModifyConstraintActivitiesEndTeachersDayForm()
55 {
56 saveFETDialogGeometry(this);
57 }
58
updateTeachersComboBox()59 void ModifyConstraintActivitiesEndTeachersDayForm::updateTeachersComboBox(){
60 int i=0, j=-1;
61 teachersComboBox->clear();
62 teachersComboBox->addItem("");
63 if(this->_ctr->teacherName=="")
64 j=i;
65 i++;
66 for(int k=0; k<gt.rules.teachersList.size(); k++){
67 Teacher* t=gt.rules.teachersList[k];
68 teachersComboBox->addItem(t->name);
69 if(t->name==this->_ctr->teacherName)
70 j=i;
71 i++;
72 }
73 assert(j>=0);
74 teachersComboBox->setCurrentIndex(j);
75 }
76
updateStudentsComboBox(QWidget * parent)77 void ModifyConstraintActivitiesEndTeachersDayForm::updateStudentsComboBox(QWidget* parent){
78 int i=0, j=-1;
79 studentsComboBox->clear();
80 studentsComboBox->addItem("");
81 if(this->_ctr->studentsName=="")
82 j=i;
83 i++;
84 for(int m=0; m<gt.rules.yearsList.size(); m++){
85 StudentsYear* sty=gt.rules.yearsList[m];
86 studentsComboBox->addItem(sty->name);
87 if(sty->name==this->_ctr->studentsName)
88 j=i;
89 i++;
90 for(int n=0; n<sty->groupsList.size(); n++){
91 StudentsGroup* stg=sty->groupsList[n];
92 studentsComboBox->addItem(stg->name);
93 if(stg->name==this->_ctr->studentsName)
94 j=i;
95 i++;
96 if(SHOW_SUBGROUPS_IN_COMBO_BOXES) for(int p=0; p<stg->subgroupsList.size(); p++){
97 StudentsSubgroup* sts=stg->subgroupsList[p];
98 studentsComboBox->addItem(sts->name);
99 if(sts->name==this->_ctr->studentsName)
100 j=i;
101 i++;
102 }
103 }
104 }
105 if(j<0)
106 showWarningForInvisibleSubgroupConstraint(parent, this->_ctr->studentsName);
107 else
108 assert(j>=0);
109 studentsComboBox->setCurrentIndex(j);
110 }
111
updateSubjectsComboBox()112 void ModifyConstraintActivitiesEndTeachersDayForm::updateSubjectsComboBox(){
113 int i=0, j=-1;
114 subjectsComboBox->clear();
115 subjectsComboBox->addItem("");
116 if(this->_ctr->subjectName=="")
117 j=i;
118 i++;
119 for(int k=0; k<gt.rules.subjectsList.size(); k++){
120 Subject* s=gt.rules.subjectsList[k];
121 subjectsComboBox->addItem(s->name);
122 if(s->name==this->_ctr->subjectName)
123 j=i;
124 i++;
125 }
126 assert(j>=0);
127 subjectsComboBox->setCurrentIndex(j);
128 }
129
updateActivityTagsComboBox()130 void ModifyConstraintActivitiesEndTeachersDayForm::updateActivityTagsComboBox(){
131 int i=0, j=-1;
132 activityTagsComboBox->clear();
133 activityTagsComboBox->addItem("");
134 if(this->_ctr->activityTagName=="")
135 j=i;
136 i++;
137 for(int k=0; k<gt.rules.activityTagsList.size(); k++){
138 ActivityTag* s=gt.rules.activityTagsList[k];
139 activityTagsComboBox->addItem(s->name);
140 if(s->name==this->_ctr->activityTagName)
141 j=i;
142 i++;
143 }
144 assert(j>=0);
145 activityTagsComboBox->setCurrentIndex(j);
146 }
147
ok()148 void ModifyConstraintActivitiesEndTeachersDayForm::ok()
149 {
150 if(studentsComboBox->currentIndex()<0){
151 showWarningCannotModifyConstraintInvisibleSubgroupConstraint(this, this->_ctr->studentsName);
152 return;
153 }
154
155 double weight;
156 QString tmp=weightLineEdit->text();
157 weight_sscanf(tmp, "%lf", &weight);
158 if(weight<0.0 || weight>100.0){
159 QMessageBox::warning(this, tr("FET information"),
160 tr("Invalid weight (percentage)"));
161 return;
162 }
163 if(weight!=100.0){
164 QMessageBox::warning(this, tr("FET information"),
165 tr("Invalid weight (percentage) - it must be 100%"));
166 return;
167 }
168
169 QString teacher=teachersComboBox->currentText();
170 if(teacher!="")
171 assert(gt.rules.searchTeacher(teacher)>=0);
172
173 QString students=studentsComboBox->currentText();
174 if(students!="")
175 assert(gt.rules.searchStudentsSet(students)!=nullptr);
176
177 QString subject=subjectsComboBox->currentText();
178 if(subject!="")
179 assert(gt.rules.searchSubject(subject)>=0);
180
181 QString activityTag=activityTagsComboBox->currentText();
182 if(activityTag!="")
183 assert(gt.rules.searchActivityTag(activityTag)>=0);
184
185 this->_ctr->weightPercentage=weight;
186 this->_ctr->teacherName=teacher;
187 this->_ctr->studentsName=students;
188 this->_ctr->subjectName=subject;
189 this->_ctr->activityTagName=activityTag;
190
191 gt.rules.internalStructureComputed=false;
192 setRulesModifiedAndOtherThings(>.rules);
193
194 this->close();
195 }
196
cancel()197 void ModifyConstraintActivitiesEndTeachersDayForm::cancel()
198 {
199 this->close();
200 }
201