1 /***************************************************************************
2                           modifyconstraintsubjectactivitytagpreferredroomform.cpp  -  description
3                              -------------------
4     begin                : 18 Aug 2007
5     copyright            : (C) 2007 by Liviu Lalescu
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 "modifyconstraintsubjectactivitytagpreferredroomform.h"
21 #include "spaceconstraint.h"
22 
ModifyConstraintSubjectActivityTagPreferredRoomForm(QWidget * parent,ConstraintSubjectActivityTagPreferredRoom * ctr)23 ModifyConstraintSubjectActivityTagPreferredRoomForm::ModifyConstraintSubjectActivityTagPreferredRoomForm(QWidget* parent, ConstraintSubjectActivityTagPreferredRoom* 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 tmp3=subjectsComboBox->minimumSizeHint();
36 	Q_UNUSED(tmp3);
37 	QSize tmp4=activityTagsComboBox->minimumSizeHint();
38 	Q_UNUSED(tmp4);
39 
40 	QSize tmp5=roomsComboBox->minimumSizeHint();
41 	Q_UNUSED(tmp5);
42 
43 	this->_ctr=ctr;
44 
45 	weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
46 
47 	updateSubjectsComboBox();
48 	updateActivityTagsComboBox();
49 	updateRoomsComboBox();
50 }
51 
~ModifyConstraintSubjectActivityTagPreferredRoomForm()52 ModifyConstraintSubjectActivityTagPreferredRoomForm::~ModifyConstraintSubjectActivityTagPreferredRoomForm()
53 {
54 	saveFETDialogGeometry(this);
55 }
56 
updateSubjectsComboBox()57 void ModifyConstraintSubjectActivityTagPreferredRoomForm::updateSubjectsComboBox()
58 {
59 	int i=0, j=-1;
60 	subjectsComboBox->clear();
61 	for(int k=0; k<gt.rules.subjectsList.size(); k++){
62 		Subject* sb=gt.rules.subjectsList[k];
63 		subjectsComboBox->addItem(sb->name);
64 		if(sb->name==this->_ctr->subjectName)
65 			j=i;
66 		i++;
67 	}
68 	assert(j>=0);
69 	subjectsComboBox->setCurrentIndex(j);
70 }
71 
updateActivityTagsComboBox()72 void ModifyConstraintSubjectActivityTagPreferredRoomForm::updateActivityTagsComboBox()
73 {
74 	int i=0, j=-1;
75 	activityTagsComboBox->clear();
76 	for(int k=0; k<gt.rules.activityTagsList.size(); k++){
77 		ActivityTag* sb=gt.rules.activityTagsList[k];
78 		activityTagsComboBox->addItem(sb->name);
79 		if(sb->name==this->_ctr->activityTagName)
80 			j=i;
81 		i++;
82 	}
83 	assert(j>=0);
84 	activityTagsComboBox->setCurrentIndex(j);
85 }
86 
updateRoomsComboBox()87 void ModifyConstraintSubjectActivityTagPreferredRoomForm::updateRoomsComboBox()
88 {
89 	int i=0, j=-1;
90 	roomsComboBox->clear();
91 	for(int k=0; k<gt.rules.roomsList.size(); k++){
92 		Room* rm=gt.rules.roomsList[k];
93 		roomsComboBox->addItem(rm->name);
94 		if(rm->name==this->_ctr->roomName)
95 			j=i;
96 		i++;
97 	}
98 	assert(j>=0);
99 	roomsComboBox->setCurrentIndex(j);
100 }
101 
cancel()102 void ModifyConstraintSubjectActivityTagPreferredRoomForm::cancel()
103 {
104 	this->close();
105 }
106 
ok()107 void ModifyConstraintSubjectActivityTagPreferredRoomForm::ok()
108 {
109 	double weight;
110 	QString tmp=weightLineEdit->text();
111 	weight_sscanf(tmp, "%lf", &weight);
112 	if(weight<0.0 || weight>100){
113 		QMessageBox::warning(this, tr("FET information"),
114 			tr("Invalid weight"));
115 		return;
116 	}
117 
118 	int i=subjectsComboBox->currentIndex();
119 	if(i<0 || subjectsComboBox->count()<=0){
120 		QMessageBox::warning(this, tr("FET information"),
121 			tr("Invalid subject"));
122 		return;
123 	}
124 	QString subject=subjectsComboBox->currentText();
125 
126 	i=activityTagsComboBox->currentIndex();
127 	if(i<0 || activityTagsComboBox->count()<=0){
128 		QMessageBox::warning(this, tr("FET information"),
129 			tr("Invalid activity tag"));
130 		return;
131 	}
132 	QString activityTag=activityTagsComboBox->currentText();
133 
134 	i=roomsComboBox->currentIndex();
135 	if(i<0 || roomsComboBox->count()<=0){
136 		QMessageBox::warning(this, tr("FET information"),
137 			tr("Invalid room"));
138 		return;
139 	}
140 	QString room=roomsComboBox->currentText();
141 
142 	this->_ctr->weightPercentage=weight;
143 	this->_ctr->roomName=room;
144 	this->_ctr->subjectName=subject;
145 	this->_ctr->activityTagName=activityTag;
146 
147 	gt.rules.internalStructureComputed=false;
148 	setRulesModifiedAndOtherThings(&gt.rules);
149 
150 	this->close();
151 }
152