1 | /* |
---|
2 | Copyright (C) 2012 |
---|
3 | Alejandro Mujica (amujica@cenditel.gob.ve) |
---|
4 | Erwin Paredes (eparedes@cenditel.gob.ve) |
---|
5 | José Ruiz (jruiz@cenditel.gob.ve) |
---|
6 | Rodolfo Rangel (rrangel@cenditel.gob.ve) |
---|
7 | Julie Vera (jvera@cenditel.gob.ve) |
---|
8 | |
---|
9 | CENDITEL Fundación Centro Nacional de Desarrollo e Investigación en |
---|
10 | Tecnologías Libres |
---|
11 | |
---|
12 | Este programa es software libre; Usted puede usarlo bajo los términos de la |
---|
13 | licencia de software GPL versión 2.0 de la Free Software Foundation. |
---|
14 | |
---|
15 | Este programa se distribuye con la esperanza de que sea útil, pero SIN |
---|
16 | NINGUNA GARANTÍA; tampoco las implícitas garantías de MERCANTILIDAD o |
---|
17 | ADECUACIÓN A UN PROPÓSITO PARTICULAR. |
---|
18 | Consulte la licencia GPL para más detalles. Usted debe recibir una copia |
---|
19 | de la GPL junto con este programa; si no, escriba a la Free Software |
---|
20 | Foundation Inc. 51 Franklin Street,5 Piso, Boston, MA 02110-1301, USA. |
---|
21 | */ |
---|
22 | |
---|
23 | /* |
---|
24 | Este archivo contiene la implementación de la clase TempFilterForm, la cual |
---|
25 | repesenta el formulario utilizado para filtrar los productos que serán las |
---|
26 | raíces de la red que se va a construir para estudiar. |
---|
27 | |
---|
28 | Autor: Alejandro J. Mujica |
---|
29 | Fecha: 04/12/2013 |
---|
30 | */ |
---|
31 | |
---|
32 | # include <tempFilterForm.H> |
---|
33 | |
---|
34 | # include <QMessageBox> |
---|
35 | |
---|
36 | # include <ioManager.H> |
---|
37 | # include <dbProperties.H> |
---|
38 | |
---|
39 | # include <configuration.H> |
---|
40 | # include <simType.H> |
---|
41 | |
---|
42 | TempFilterForm::TempFilterForm(QWidget *parent) |
---|
43 | : QWidget(parent, Qt::Tool) |
---|
44 | { |
---|
45 | ui.setupUi(this); |
---|
46 | |
---|
47 | selectedItem = NULL; |
---|
48 | |
---|
49 | QPoint halfForm(int(width() / 2), int(height() / 2)); |
---|
50 | |
---|
51 | QPoint halfParent(int(parent->width() / 2), int(parent->height() / 2)); |
---|
52 | |
---|
53 | QPoint position = parent->pos() + halfParent - halfForm; |
---|
54 | |
---|
55 | move(position); |
---|
56 | |
---|
57 | ui.btnAddProductToSelectedList->setEnabled(false); |
---|
58 | |
---|
59 | ui.btnRemoveProductFromSelectedList->setEnabled(false); |
---|
60 | |
---|
61 | ui.edtCompanyName->setFocus(); |
---|
62 | |
---|
63 | ui.layoutWaitingPanel->addWidget(&waitingPanel, Qt::AlignCenter); |
---|
64 | |
---|
65 | connect(ui.btnAccept, SIGNAL(clicked()), |
---|
66 | this, SLOT(slotBtnAcceptClicked())); |
---|
67 | |
---|
68 | connect(ui.edtCompanyName, SIGNAL(textChanged(QString)), |
---|
69 | this, SLOT(slotTextChanged())); |
---|
70 | |
---|
71 | connect(ui.companyList, SIGNAL(itemClicked(QListWidgetItem*)), |
---|
72 | this, SLOT(slotCompanySelected(QListWidgetItem*))); |
---|
73 | |
---|
74 | connect(ui.productList, SIGNAL(itemClicked(QListWidgetItem*)), |
---|
75 | this, SLOT(slotProductSelected(QListWidgetItem*))); |
---|
76 | |
---|
77 | connect(ui.selectedProductList, SIGNAL(itemClicked(QListWidgetItem*)), |
---|
78 | this, SLOT(slotSelectedProductSelected(QListWidgetItem*))); |
---|
79 | |
---|
80 | connect(ui.btnAddProductToSelectedList, SIGNAL(clicked()), |
---|
81 | this, SLOT(slotBtnAddProductToSelectedListClicked())); |
---|
82 | |
---|
83 | connect(ui.btnRemoveProductFromSelectedList, SIGNAL(clicked()), |
---|
84 | this, SLOT(slotBtnRemoveProductFromSelectedList())); |
---|
85 | |
---|
86 | connect(&process, SIGNAL(finished(int)), |
---|
87 | this, SLOT(slotGraphBuilderExecuted())); |
---|
88 | |
---|
89 | ui.edtCompanyName->setFocus(); |
---|
90 | } |
---|
91 | |
---|
92 | void TempFilterForm::slotBtnAcceptClicked() { |
---|
93 | |
---|
94 | if (ui.selectedProductList->count() == 0) { |
---|
95 | QMessageBox::critical(this, "Error", |
---|
96 | "No se ha seleccionado ningún producto"); |
---|
97 | |
---|
98 | ui.edtCompanyName->setFocus(); |
---|
99 | |
---|
100 | return; |
---|
101 | } |
---|
102 | |
---|
103 | if (ui.comboStudyType->currentIndex() == 0) { |
---|
104 | QMessageBox::critical(this, "Error", |
---|
105 | "Debe seleccionar un tipo de estudio"); |
---|
106 | |
---|
107 | ui.comboStudyType->setFocus(); |
---|
108 | |
---|
109 | return; |
---|
110 | } |
---|
111 | |
---|
112 | if (ui.comboYear->currentIndex() == 0) { |
---|
113 | QMessageBox::critical(this, "Error", |
---|
114 | "Debe seleccionar un año de estudio"); |
---|
115 | |
---|
116 | ui.comboYear->setFocus(); |
---|
117 | |
---|
118 | return; |
---|
119 | } |
---|
120 | |
---|
121 | Configuration & conf = Configuration::getInstance(); |
---|
122 | |
---|
123 | std::string rootsFileName = FILE_PATH(conf, Xml, Roots, xml).c_str(); |
---|
124 | |
---|
125 | IOManager ioManager; |
---|
126 | |
---|
127 | DynDlist <long> productIdList; |
---|
128 | |
---|
129 | for (size_t i = 0; i < ui.selectedProductList->count(); ++i) { |
---|
130 | |
---|
131 | QListWidgetItem * item = ui.selectedProductList->item(i); |
---|
132 | |
---|
133 | productIdList.append(item->data(1).toString().toLong()); |
---|
134 | } |
---|
135 | |
---|
136 | ioManager.createXmlRootsFile(ui.comboYear->currentText().toStdString(), |
---|
137 | productIdList, ui.spinUpstreamLevels->value(), |
---|
138 | ui.spinDownstreamLevels->value(), |
---|
139 | rootsFileName); |
---|
140 | |
---|
141 | conf.createDbFile(); |
---|
142 | |
---|
143 | std::string graphXmlFileName = FILE_PATH(conf, Xml, Graph, xml).c_str(); |
---|
144 | |
---|
145 | QStringList args; |
---|
146 | |
---|
147 | args.append(QString("-i") + rootsFileName.c_str()); |
---|
148 | args.append(QString("-o") + graphXmlFileName.c_str()); |
---|
149 | args.append(QString("-b") + conf.getDbFileName().c_str()); |
---|
150 | |
---|
151 | process.start(conf.getGraphBuilderCommand().c_str(), args); |
---|
152 | |
---|
153 | waitingPanel.start(); |
---|
154 | |
---|
155 | ui.btnAccept->setEnabled(false); |
---|
156 | ui.btnCancel->setEnabled(false); |
---|
157 | ui.btnAddProductToSelectedList->setEnabled(false); |
---|
158 | ui.btnRemoveProductFromSelectedList->setEnabled(false); |
---|
159 | ui.companyList->setEnabled(false); |
---|
160 | ui.productList->setEnabled(false); |
---|
161 | ui.selectedProductList->setEnabled(false); |
---|
162 | ui.comboStudyType->setEnabled(false); |
---|
163 | ui.comboYear->setEnabled(false); |
---|
164 | ui.spinDownstreamLevels->setEnabled(false); |
---|
165 | ui.spinUpstreamLevels->setEnabled(false); |
---|
166 | } |
---|
167 | |
---|
168 | void TempFilterForm::slotTextChanged() { |
---|
169 | |
---|
170 | if (selectedItem != NULL) { |
---|
171 | selectedItem->setSelected(false); |
---|
172 | selectedItem = NULL; |
---|
173 | } |
---|
174 | |
---|
175 | ui.btnAddProductToSelectedList->setEnabled(false); |
---|
176 | ui.btnRemoveProductFromSelectedList->setEnabled(false); |
---|
177 | ui.companyList->clear(); |
---|
178 | ui.productList->clear(); |
---|
179 | |
---|
180 | if (ui.edtCompanyName->text().size() < 3) |
---|
181 | return; |
---|
182 | |
---|
183 | List <CompanyRifName> companyList; |
---|
184 | |
---|
185 | try { |
---|
186 | |
---|
187 | listCompaniesLike(ui.edtCompanyName->text().toStdString(), companyList); |
---|
188 | |
---|
189 | for (List <CompanyRifName>::Iterator it(companyList); it.has_current(); |
---|
190 | it.next()) { |
---|
191 | |
---|
192 | CompanyRifName & company = it.get_current(); |
---|
193 | |
---|
194 | QString text; |
---|
195 | |
---|
196 | text.append(company.rif.c_str()); |
---|
197 | text.append(" -- "); |
---|
198 | text.append(company.name.c_str()); |
---|
199 | |
---|
200 | QListWidgetItem * item = new QListWidgetItem(text); |
---|
201 | item->setData(1, QVariant(company.rif.c_str())); |
---|
202 | |
---|
203 | ui.companyList->addItem(item); |
---|
204 | } |
---|
205 | } catch (const std::exception & e) { |
---|
206 | |
---|
207 | QString msg = "Se ha capturado la siguiente excepción: "; |
---|
208 | |
---|
209 | msg.append(e.what()); |
---|
210 | |
---|
211 | QMessageBox::critical(this, "Error", msg); |
---|
212 | } |
---|
213 | } |
---|
214 | |
---|
215 | void TempFilterForm::slotCompanySelected(QListWidgetItem * item) { |
---|
216 | |
---|
217 | if (selectedItem != NULL) { |
---|
218 | selectedItem->setSelected(false); |
---|
219 | selectedItem = NULL; |
---|
220 | } |
---|
221 | |
---|
222 | ui.btnAddProductToSelectedList->setEnabled(false); |
---|
223 | ui.btnRemoveProductFromSelectedList->setEnabled(false); |
---|
224 | ui.productList->clear(); |
---|
225 | |
---|
226 | List <ProductIdName> productList; |
---|
227 | |
---|
228 | I(item != NULL); |
---|
229 | |
---|
230 | try { |
---|
231 | |
---|
232 | listProductsByCompany(item->data(1).toString().toStdString(), |
---|
233 | productList); |
---|
234 | |
---|
235 | for (List <ProductIdName>::Iterator it(productList); it.has_current(); |
---|
236 | it.next()) { |
---|
237 | |
---|
238 | ProductIdName & product= it.get_current(); |
---|
239 | |
---|
240 | QString text; |
---|
241 | |
---|
242 | text.append(product.name.c_str()); |
---|
243 | text.append(" -- "); |
---|
244 | text.append(product.technicalSpecifications.c_str()); |
---|
245 | |
---|
246 | QListWidgetItem * item = new QListWidgetItem(text); |
---|
247 | item->setData(1, QVariant(QString().setNum(product.id))); |
---|
248 | |
---|
249 | ui.productList->addItem(item); |
---|
250 | } |
---|
251 | } catch (const std::exception & e) { |
---|
252 | |
---|
253 | QString msg = "Se ha capturado la siguiente excepción: "; |
---|
254 | |
---|
255 | msg.append(e.what()); |
---|
256 | |
---|
257 | QMessageBox::critical(this, "Error", msg); |
---|
258 | } |
---|
259 | } |
---|
260 | |
---|
261 | void TempFilterForm::slotProductSelected(QListWidgetItem * item) { |
---|
262 | |
---|
263 | if (selectedItem == item) |
---|
264 | return; |
---|
265 | |
---|
266 | ui.btnAddProductToSelectedList->setEnabled(true); |
---|
267 | ui.btnRemoveProductFromSelectedList->setEnabled(false); |
---|
268 | |
---|
269 | if (selectedItem != NULL) |
---|
270 | selectedItem->setSelected(false); |
---|
271 | |
---|
272 | selectedItem = item; |
---|
273 | } |
---|
274 | |
---|
275 | void TempFilterForm::slotSelectedProductSelected(QListWidgetItem * item) { |
---|
276 | |
---|
277 | if (selectedItem == item) |
---|
278 | return; |
---|
279 | |
---|
280 | ui.btnRemoveProductFromSelectedList->setEnabled(true); |
---|
281 | ui.btnAddProductToSelectedList->setEnabled(false); |
---|
282 | |
---|
283 | if (selectedItem != NULL) |
---|
284 | selectedItem->setSelected(false); |
---|
285 | |
---|
286 | selectedItem = item; |
---|
287 | } |
---|
288 | |
---|
289 | void TempFilterForm::slotBtnAddProductToSelectedListClicked() { |
---|
290 | |
---|
291 | long id = selectedItem->data(1).toString().toLong(); |
---|
292 | |
---|
293 | if (productIdSet.insert(id) == NULL) |
---|
294 | return; |
---|
295 | |
---|
296 | ui.btnRemoveProductFromSelectedList->setEnabled(true); |
---|
297 | ui.btnAddProductToSelectedList->setEnabled(false); |
---|
298 | |
---|
299 | QListWidgetItem * newItem = new QListWidgetItem(*selectedItem); |
---|
300 | |
---|
301 | ui.selectedProductList->addItem(newItem); |
---|
302 | |
---|
303 | selectedItem = newItem; |
---|
304 | newItem->setSelected(true); |
---|
305 | |
---|
306 | if (not ui.productList->selectedItems().isEmpty()) |
---|
307 | ui.productList->selectedItems().at(0)->setSelected(false); |
---|
308 | } |
---|
309 | |
---|
310 | void TempFilterForm::slotBtnRemoveProductFromSelectedList() { |
---|
311 | |
---|
312 | long id = selectedItem->data(1).toString().toLong(); |
---|
313 | |
---|
314 | productIdSet.remove(id); |
---|
315 | |
---|
316 | delete selectedItem; |
---|
317 | selectedItem = NULL; |
---|
318 | |
---|
319 | if (ui.selectedProductList->selectedItems().isEmpty()) |
---|
320 | ui.btnRemoveProductFromSelectedList->setEnabled(false); |
---|
321 | else |
---|
322 | selectedItem = ui.selectedProductList->selectedItems().at(0); |
---|
323 | } |
---|
324 | |
---|
325 | void TempFilterForm::slotGraphBuilderExecuted() { |
---|
326 | |
---|
327 | ui.btnAccept->setEnabled(true); |
---|
328 | ui.btnCancel->setEnabled(true); |
---|
329 | ui.btnAddProductToSelectedList->setEnabled(true); |
---|
330 | ui.btnRemoveProductFromSelectedList->setEnabled(true); |
---|
331 | ui.companyList->setEnabled(true); |
---|
332 | ui.productList->setEnabled(true); |
---|
333 | ui.selectedProductList->setEnabled(true); |
---|
334 | ui.comboStudyType->setEnabled(true); |
---|
335 | ui.comboYear->setEnabled(true); |
---|
336 | ui.spinDownstreamLevels->setEnabled(true); |
---|
337 | ui.spinUpstreamLevels->setEnabled(true); |
---|
338 | |
---|
339 | waitingPanel.stop(); |
---|
340 | |
---|
341 | Configuration::getInstance().removeDbFile(); |
---|
342 | |
---|
343 | if (process.exitStatus() == QProcess::CrashExit) { |
---|
344 | QMessageBox::critical( |
---|
345 | this, "Error", |
---|
346 | "El programa de construcción de red se estrelló"); |
---|
347 | return; |
---|
348 | } |
---|
349 | |
---|
350 | SimType::getInstance().setType( |
---|
351 | StudyType(ui.comboStudyType->currentIndex() - 1)); |
---|
352 | |
---|
353 | SimType::getInstance().setYear(ui.comboYear->currentText().toStdString()); |
---|
354 | |
---|
355 | emit signalFormAccepted(); |
---|
356 | |
---|
357 | close(); |
---|
358 | |
---|
359 | } |
---|
360 | |
---|
361 | void TempFilterForm::closeEvent(QCloseEvent *) { |
---|
362 | emit signalClosing(); |
---|
363 | } |
---|