1 | #include "mainwindow.H" |
---|
2 | #include "accountwidget.H" |
---|
3 | #include "stackvariablesexogenas.h" |
---|
4 | #include "formexportmatrix.h" |
---|
5 | #include <stackencadenamientos.h> |
---|
6 | #include <QDebug> |
---|
7 | |
---|
8 | #include <Eigen> |
---|
9 | |
---|
10 | using namespace Eigen; |
---|
11 | |
---|
12 | void MainWindow::slotLoadMatrix() |
---|
13 | { |
---|
14 | formLoadMatrix = new FormLoadMatrix(this); |
---|
15 | formLoadMatrix->show(); |
---|
16 | connect(formLoadMatrix, SIGNAL(formAccepted(QString,int,char)), |
---|
17 | this, SLOT(slotFormLoadMatrixAccepted(QString,int,char))); |
---|
18 | } |
---|
19 | |
---|
20 | void MainWindow::slotExportMatrix() |
---|
21 | { |
---|
22 | |
---|
23 | if(opcionExportarMatriz == 0) |
---|
24 | { |
---|
25 | formExportMatriz = new FormExportMatrix(this); |
---|
26 | QHBoxLayout * layoutLateralWidget = new QHBoxLayout; |
---|
27 | QVBoxLayout * layoutCentralWidget = new QVBoxLayout; |
---|
28 | |
---|
29 | QLabel *label = new QLabel; |
---|
30 | label->setText("Seleccione una de las matrices"); |
---|
31 | label->setStyleSheet("font-size:14;font-weight:bold;"); |
---|
32 | layoutLateralWidget->addWidget(label); |
---|
33 | |
---|
34 | formExportMatriz->Exportcb = new QComboBox; |
---|
35 | formExportMatriz->Exportcb->setFixedWidth(150); |
---|
36 | QVBoxLayout *cbLayout = new QVBoxLayout; |
---|
37 | cbLayout->addWidget(formExportMatriz->Exportcb); |
---|
38 | QWidget *cbWidget = new QWidget; |
---|
39 | cbWidget->setLayout(cbLayout); |
---|
40 | |
---|
41 | QStringList list; |
---|
42 | list << "valor1" << "valor2" << "valor3"; |
---|
43 | formExportMatriz->Exportcb->addItems(list); |
---|
44 | |
---|
45 | layoutLateralWidget->addWidget(cbWidget); |
---|
46 | |
---|
47 | QLabel *label2 = new QLabel; |
---|
48 | label2->setText("Archivo"); |
---|
49 | formExportMatriz->ExportLine = new QLineEdit; |
---|
50 | //line->setObjectName("lineaCarga"); |
---|
51 | formExportMatriz->ExportLine->setReadOnly(true); |
---|
52 | formExportMatriz->ExportLine->setFixedWidth(450); |
---|
53 | |
---|
54 | QPushButton * buttonExplorar = new QPushButton; |
---|
55 | buttonExplorar->setObjectName("Exportar-Explorar"); |
---|
56 | buttonExplorar->setFlat(true); |
---|
57 | buttonExplorar->setIcon(QIcon("./img/folder_blue.png")); |
---|
58 | |
---|
59 | QHBoxLayout *layoutMiddle = new QHBoxLayout; |
---|
60 | layoutMiddle->addWidget(label2); |
---|
61 | layoutMiddle->addWidget(formExportMatriz->ExportLine); |
---|
62 | layoutMiddle->addWidget(buttonExplorar); |
---|
63 | QWidget *middle = new QWidget; |
---|
64 | middle->setLayout(layoutMiddle); |
---|
65 | |
---|
66 | |
---|
67 | /*** Se crean y personalizan los bottones para agregar, finalizar, deshacer y cancelar ***/ |
---|
68 | QPushButton * buttonExportar = new QPushButton; |
---|
69 | buttonExportar->setObjectName("ExportarMatriz");//Se le asigna nombre al objeto |
---|
70 | buttonExportar->setText("Exportar"); |
---|
71 | buttonExportar->setFixedWidth(130); |
---|
72 | |
---|
73 | QPushButton * buttonCancelar = new QPushButton; |
---|
74 | buttonCancelar->setObjectName("CancelarMatriz");//Se le asigna nombre al objeto |
---|
75 | buttonCancelar->setText("Cancelar"); |
---|
76 | buttonCancelar->setFixedWidth(130); |
---|
77 | |
---|
78 | connect(buttonCancelar,SIGNAL(clicked()),this,SLOT(slotCloseExport())); |
---|
79 | connect(buttonExportar,SIGNAL(clicked()),this,SLOT(slotSaveExport())); |
---|
80 | connect(buttonExplorar,SIGNAL(clicked()),this,SLOT(slotSearchExport())); |
---|
81 | |
---|
82 | QHBoxLayout * layoutsButtons = new QHBoxLayout; |
---|
83 | layoutsButtons->addWidget(buttonExportar); |
---|
84 | layoutsButtons->addWidget(buttonCancelar); |
---|
85 | QWidget *buttonWidget = new QWidget; |
---|
86 | buttonWidget->setLayout(layoutsButtons); |
---|
87 | |
---|
88 | QWidget *widget = new QWidget; |
---|
89 | widget->setLayout(layoutLateralWidget); |
---|
90 | layoutCentralWidget->addWidget(widget); |
---|
91 | layoutCentralWidget->addWidget(middle); |
---|
92 | layoutCentralWidget->addWidget(buttonWidget); |
---|
93 | formExportMatriz->setLayout(layoutCentralWidget); |
---|
94 | formExportMatriz->show(); |
---|
95 | opcionExportarMatriz = 1; |
---|
96 | |
---|
97 | } |
---|
98 | else |
---|
99 | { |
---|
100 | formExportMatriz->show(); |
---|
101 | } |
---|
102 | |
---|
103 | } |
---|
104 | void MainWindow::closeEvent(QCloseEvent * event) |
---|
105 | { |
---|
106 | QMessageBox msBox(QMessageBox::Question,"Alerta","¿Desea Salir?", QMessageBox::Yes | QMessageBox::No,this); |
---|
107 | msBox.setButtonText(QMessageBox::Yes,"&Si"); |
---|
108 | if(msBox.exec()==QMessageBox::No) |
---|
109 | { |
---|
110 | event->ignore(); |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | void MainWindow::initGUI() |
---|
115 | { |
---|
116 | createMenuBar(); |
---|
117 | createCentralWidget(); |
---|
118 | } |
---|
119 | |
---|
120 | void MainWindow::createCentralWidget() |
---|
121 | { |
---|
122 | QVBoxLayout * layoutCentralWidget = new QVBoxLayout; |
---|
123 | |
---|
124 | QHBoxLayout * layoutTitle = new QHBoxLayout; |
---|
125 | QLabel * lblTitle = new QLabel("Estructura de la Matriz de " \ |
---|
126 | "Contabilidad Social"); |
---|
127 | lblTitle->setFont(QFont("Aero Matics", 25, 1)); |
---|
128 | lblTitle->setAlignment(Qt::AlignCenter | Qt::AlignBottom); |
---|
129 | layoutTitle->addWidget(lblTitle); |
---|
130 | layoutCentralWidget->addLayout(layoutTitle); |
---|
131 | |
---|
132 | QHBoxLayout * layoutMatrix = new QHBoxLayout; |
---|
133 | QLabel * lblMatrix = new QLabel; |
---|
134 | lblMatrix->setAlignment(Qt::AlignCenter); |
---|
135 | lblMatrix->setPixmap(QPixmap("./img/Imagen-matriz.png")); |
---|
136 | layoutMatrix->addWidget(lblMatrix); |
---|
137 | layoutCentralWidget->addLayout(layoutMatrix); |
---|
138 | |
---|
139 | QHBoxLayout * layoutFoot = new QHBoxLayout; |
---|
140 | QLabel * lblFoot = new QLabel("Fundación Centro Nacional de Desarrollo e" \ |
---|
141 | " Investigación en\nTecnologías Libres." \ |
---|
142 | " Nodo Mérida."); |
---|
143 | lblFoot->setFont(QFont("Aero Matics", 19, 1)); |
---|
144 | lblFoot->setAlignment(Qt::AlignRight | Qt::AlignBottom); |
---|
145 | QLabel * lblLogo = new QLabel; |
---|
146 | lblLogo->setPixmap(QPixmap("./img/logo_cenditel.jpg")); |
---|
147 | lblLogo->setFixedWidth(lblLogo->pixmap()->width()); |
---|
148 | lblLogo->setAlignment(Qt::AlignRight | Qt::AlignBottom); |
---|
149 | layoutFoot->addWidget(lblFoot); |
---|
150 | layoutFoot->addWidget(lblLogo); |
---|
151 | layoutCentralWidget->addLayout(layoutFoot); |
---|
152 | |
---|
153 | tabWidget->addTab(new QWidget,"Inicio"); |
---|
154 | setCentralWidget(tabWidget); |
---|
155 | QWidget *widget=tabWidget->widget(0); |
---|
156 | widget->setLayout(layoutCentralWidget); |
---|
157 | |
---|
158 | } |
---|
159 | |
---|
160 | |
---|
161 | void MainWindow::createMenuBar() |
---|
162 | { |
---|
163 | menuFile.setTitle("&Archivo"); |
---|
164 | |
---|
165 | actionLoadMatrix.setText("&Cargar Matriz"); |
---|
166 | menuFile.addAction(&actionLoadMatrix); |
---|
167 | |
---|
168 | actionExportMatrix.setText("&Exportar Matriz"); |
---|
169 | menuFile.addAction(&actionExportMatrix); |
---|
170 | actionExportMatrix.setDisabled(true); |
---|
171 | |
---|
172 | actionQuit.setText("&Salir"); |
---|
173 | menuFile.addAction(&actionQuit); |
---|
174 | |
---|
175 | |
---|
176 | menuBar()->addMenu(&menuFile); |
---|
177 | } |
---|
178 | |
---|
179 | void MainWindow::matricesMenuBar() |
---|
180 | { |
---|
181 | OpMatrices.setTitle("&Herramientas"); |
---|
182 | |
---|
183 | actionCH.setText("Coeficientes &Horizontales"); |
---|
184 | actionCH.setDisabled(true); |
---|
185 | OpMatrices.addAction(&actionCH); |
---|
186 | |
---|
187 | actionCV.setText("Coeficientes &Verticales"); |
---|
188 | actionCV.setDisabled(true); |
---|
189 | OpMatrices.addAction(&actionCV); |
---|
190 | |
---|
191 | EndoExo.setTitle("Variables &Exogenas"); |
---|
192 | |
---|
193 | actionVariableExogena.setText("Definir Variables &Exogenas"); |
---|
194 | actionVariableExogena.setDisabled(true); |
---|
195 | EndoExo.addAction(&actionVariableExogena); |
---|
196 | |
---|
197 | actionLa.setText("Multiplicadores de &Leontief"); |
---|
198 | actionLa.setDisabled(true); |
---|
199 | EndoExo.addAction(&actionLa); |
---|
200 | |
---|
201 | OpMatrices.addMenu(&EndoExo); |
---|
202 | |
---|
203 | actionEncadenamiento.setText("E&ncadenamientos"); |
---|
204 | actionEncadenamiento.setDisabled(true); |
---|
205 | OpMatrices.addAction(&actionEncadenamiento); |
---|
206 | |
---|
207 | |
---|
208 | menuBar()->addMenu(&OpMatrices); |
---|
209 | } |
---|
210 | |
---|
211 | MainWindow::MainWindow() |
---|
212 | : actionLoadMatrix(this), actionExportMatrix(this), actionQuit(this),actionCH(this), actionCV(this), |
---|
213 | actionVariableExogena(this),actionLa(this),actionEncadenamiento(this), formLoadMatrix(0) |
---|
214 | { |
---|
215 | tabWidget = new QTabWidget; |
---|
216 | |
---|
217 | /* Opcion de la cuenta exogena, 0 para decir que nos se selecciono ninguna, 1 que se seleccionaron algunas |
---|
218 | y 2 para decir que se seleccionaron todas*/ |
---|
219 | opcionCuentaExogena = 0; |
---|
220 | opcionVentanaExogena = 0; |
---|
221 | opcionExportarMatriz = 0; |
---|
222 | opcionEncadenamientos = 0; |
---|
223 | cantidadEncadenamientos = 1; |
---|
224 | |
---|
225 | initGUI(); |
---|
226 | |
---|
227 | connect(&actionLoadMatrix, SIGNAL(triggered()), this, |
---|
228 | SLOT(slotLoadMatrix())); |
---|
229 | connect(&actionExportMatrix, SIGNAL(triggered()), this, |
---|
230 | SLOT(slotExportMatrix())); |
---|
231 | connect(&actionQuit, SIGNAL(triggered()), this, SLOT(close())); |
---|
232 | |
---|
233 | showMaximized(); |
---|
234 | } |
---|
235 | |
---|
236 | void MainWindow::slotFormLoadMatrixAccepted(const QString & filePath, |
---|
237 | int accountNumber, char sep) |
---|
238 | { |
---|
239 | QString msg = "Archivo: " + filePath + "\nNúmero de cuentas: " + |
---|
240 | QString().setNum(accountNumber) + |
---|
241 | "\nSeparador: " + sep; |
---|
242 | |
---|
243 | csvFilePath = filePath; |
---|
244 | csvSeparator = sep; |
---|
245 | numAccounts = accountNumber; |
---|
246 | |
---|
247 | createMatrixCentralWidget(); |
---|
248 | } |
---|
249 | |
---|
250 | void MainWindow::slotFormLoadMatrixClosed() |
---|
251 | { |
---|
252 | disconnect(formLoadMatrix, SIGNAL(formAccepted(QString,int,char)), |
---|
253 | this, SLOT(slotFormLoadMatrixAccepted(QString,int,char))); |
---|
254 | formLoadMatrix = 0; |
---|
255 | } |
---|
256 | |
---|
257 | void MainWindow::slotVariableExogena() |
---|
258 | { |
---|
259 | if(opcionVentanaExogena==0) |
---|
260 | { |
---|
261 | formVariablesExogenas = new FormVariablesExogenas(this); |
---|
262 | QHBoxLayout * layoutLateralWidget = new QHBoxLayout; |
---|
263 | QVBoxLayout * layoutCentralWidget = new QVBoxLayout; |
---|
264 | QHBoxLayout * layoutAccounts = new QHBoxLayout; |
---|
265 | QHBoxLayout * labels = new QHBoxLayout; |
---|
266 | QLabel *label1 = new QLabel; |
---|
267 | QLabel *label2 = new QLabel; |
---|
268 | label1->setText("Cuentas"); |
---|
269 | label2->setText("Componentes"); |
---|
270 | labels->addWidget(label1); |
---|
271 | labels->addWidget(label2); |
---|
272 | QWidget *nw = new QWidget; |
---|
273 | nw->setLayout(labels); |
---|
274 | QGroupBox * groupBoxAccount = new QGroupBox; |
---|
275 | layoutCentralWidget->addWidget(nw); |
---|
276 | /*** Se obtiene la cantidad de cuentas ***/ |
---|
277 | StackWidget *sw = findChild<StackWidget *>(""); |
---|
278 | int cantidad=sw->comboAccount->count(); |
---|
279 | QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal"); |
---|
280 | /*** Se obtiene el nombre de las cuentas,sus componentes, su inicio y su fin en varias listas ***/ |
---|
281 | insertremoveRowCol(tw,0,false); |
---|
282 | QStringList Lista = ObtenerNombreCuenta(cantidad); |
---|
283 | QStringList Componentes = ObtenerComponentes(tw); |
---|
284 | QList <int> inicio = ObtenerLimitesCuenta(cantidad,0); |
---|
285 | QList <int> fin = ObtenerLimitesCuenta(cantidad,1); |
---|
286 | layoutAccounts->addWidget(stackVE=new stackVariablesExogenas(Lista,Componentes,inicio,fin,groupBoxAccount,cantidad)); |
---|
287 | insertremoveRowCol(tw,0,true); |
---|
288 | setAccountTitle(tw); |
---|
289 | |
---|
290 | groupBoxAccount->setObjectName("exogenasBoxAccount");//Se le asigna nombre al objeto |
---|
291 | groupBoxAccount->setLayout(layoutAccounts);; |
---|
292 | groupBoxAccount->setStyleSheet("QGroupBox {border: 1px solid gray; " |
---|
293 | "border-radius: 3px; margin-top: 0.5em;} " |
---|
294 | "QGroupBox::title { subcontrol-origin: margin; " |
---|
295 | "left: 10px; padding: 0 3px 0 3px; } "); |
---|
296 | |
---|
297 | |
---|
298 | layoutLateralWidget->addWidget(groupBoxAccount); |
---|
299 | |
---|
300 | /*** Se crean y personalizan los bottones para agregar, finalizar, deshacer y cancelar ***/ |
---|
301 | QPushButton * buttonAgregar = new QPushButton; |
---|
302 | buttonAgregar->setObjectName("AgregarExogena");//Se le asigna nombre al objeto |
---|
303 | buttonAgregar->setText("Agregar"); |
---|
304 | buttonAgregar->setFixedWidth(130); |
---|
305 | buttonAgregar->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
306 | "font-weight: bold; height: 30px; border: none;" |
---|
307 | "border-radius: 5px; margin-top: 40px;"); |
---|
308 | QPushButton * buttonCancelar = new QPushButton; |
---|
309 | buttonCancelar->setObjectName("CancelarExogena");//Se le asigna nombre al objeto |
---|
310 | buttonCancelar->setText("Cancelar"); |
---|
311 | buttonCancelar->setFixedWidth(130); |
---|
312 | buttonCancelar->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
313 | "font-weight: bold; height: 30px; border: none;" |
---|
314 | "border-radius: 5px; margin-top: 40px;"); |
---|
315 | QPushButton * buttonFinalizar = new QPushButton; |
---|
316 | buttonFinalizar->setObjectName("FinalizarExogena");//Se le asigna nombre al objeto |
---|
317 | buttonFinalizar->setText("Finalizar"); |
---|
318 | buttonFinalizar->setFixedWidth(130); |
---|
319 | buttonFinalizar->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
320 | "font-weight: bold; height: 30px; border: none;" |
---|
321 | "border-radius: 5px; margin-top: 40px;"); |
---|
322 | QPushButton * buttonDeshacer = new QPushButton; |
---|
323 | buttonDeshacer->setObjectName("DeshacerExogena");//Se le asigna nombre al objeto |
---|
324 | buttonDeshacer->setText("Deshacer"); |
---|
325 | buttonDeshacer->setFixedWidth(130); |
---|
326 | buttonDeshacer->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
327 | "font-weight: bold; height: 30px; border: none;" |
---|
328 | "border-radius: 5px; margin-top: 40px;"); |
---|
329 | |
---|
330 | connect(buttonCancelar,SIGNAL(clicked()),this,SLOT(slotCloseExogena())); |
---|
331 | connect(buttonAgregar,SIGNAL(clicked()),this,SLOT(slotAgregarExogena())); |
---|
332 | connect(buttonFinalizar,SIGNAL(clicked()),this,SLOT(slotFinalizarExogena())); |
---|
333 | connect(buttonDeshacer,SIGNAL(clicked()),this,SLOT(slotDeshacerExogena())); |
---|
334 | |
---|
335 | |
---|
336 | QHBoxLayout * layoutsButtons = new QHBoxLayout; |
---|
337 | layoutsButtons->addWidget(buttonFinalizar); |
---|
338 | layoutsButtons->addWidget(buttonAgregar); |
---|
339 | layoutsButtons->addWidget(buttonDeshacer); |
---|
340 | layoutsButtons->addWidget(buttonCancelar); |
---|
341 | QWidget *buttonWidget = new QWidget; |
---|
342 | buttonWidget->setLayout(layoutsButtons); |
---|
343 | |
---|
344 | QWidget *widget = new QWidget; |
---|
345 | widget->setLayout(layoutLateralWidget); |
---|
346 | layoutCentralWidget->addWidget(widget); |
---|
347 | layoutCentralWidget->addWidget(buttonWidget);//Se agregan los botones |
---|
348 | formVariablesExogenas->setLayout(layoutCentralWidget); |
---|
349 | formVariablesExogenas->show(); |
---|
350 | opcionVentanaExogena=1; |
---|
351 | } |
---|
352 | else |
---|
353 | { |
---|
354 | formVariablesExogenas->show(); |
---|
355 | } |
---|
356 | } |
---|
357 | |
---|
358 | |
---|
359 | void MainWindow::slotCoeficienteVertical() |
---|
360 | { |
---|
361 | actionCV.setDisabled(true); |
---|
362 | tabWidget->addTab(new QWidget,"CT_Vertical"); |
---|
363 | QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal"); |
---|
364 | |
---|
365 | QTableWidget *CT_VerticalTW = new QTableWidget; |
---|
366 | int count=tw->rowCount(); |
---|
367 | CrearTablaVacia(count,CT_VerticalTW);//Se crea una tabla vacia |
---|
368 | /* **** Se coloca como no editable la celda(0,0) ***** */ |
---|
369 | noEditColZero(CT_VerticalTW); |
---|
370 | /***** Se llena la tabla vacia con los valores de la tabla principal ****/ |
---|
371 | |
---|
372 | CalcularAn(tw,CT_VerticalTW,new QTableWidget,count,false);//Funcion para calcular el Coeficiente Tecnico Horizontal (An) |
---|
373 | |
---|
374 | |
---|
375 | insertremoveRowCol(CT_VerticalTW,0,true); |
---|
376 | insertremoveRowCol(CT_VerticalTW,0,false); |
---|
377 | setAccountTitle(CT_VerticalTW); |
---|
378 | int indice=ObtenerIndice("CT_Vertical");//Se obtiene el indice de la pestaña |
---|
379 | QHBoxLayout * layoutCentralWidget = new QHBoxLayout; |
---|
380 | layoutCentralWidget->addWidget(CT_VerticalTW); |
---|
381 | QWidget *widget = tabWidget->widget(indice); |
---|
382 | widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada |
---|
383 | |
---|
384 | } |
---|
385 | |
---|
386 | void MainWindow::slotCoeficienteHorizontal() |
---|
387 | { |
---|
388 | actionCH.setDisabled(true); |
---|
389 | tabWidget->addTab(new QWidget,"CT_Horizontal"); |
---|
390 | QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal"); |
---|
391 | |
---|
392 | /* Se eliminan la fila y columna (0,0) para los calculos*/ |
---|
393 | insertremoveRowCol(tw,0,false); |
---|
394 | |
---|
395 | int count=tw->rowCount(); |
---|
396 | QTableWidget *CT_HorizontalTW = new QTableWidget; |
---|
397 | CrearTablaVacia(count,CT_HorizontalTW); //Se Crea la tabla vacia |
---|
398 | /* **** Se coloca como no editable la celda(0,0) ***** */ |
---|
399 | noEditColZero(CT_HorizontalTW); |
---|
400 | /***** Se llena la tabla vacia con los valores de la tabla principal ****/ |
---|
401 | for(int i=0;i<count-1;i++) |
---|
402 | { |
---|
403 | QString STotal = Separador(tw->item(i,count-1),true); |
---|
404 | double total=STotal.toDouble();//Se obtiene el total de esa columna |
---|
405 | for(int j=0;j<count-1;j++) |
---|
406 | { |
---|
407 | if(i!=0 && j!=0) |
---|
408 | { |
---|
409 | QString value = Separador(tw->item(i,j),true); |
---|
410 | double valor=value.toDouble(); |
---|
411 | if(total==0)//Se comprueba en caso de que el total sea zero |
---|
412 | { |
---|
413 | valor=0; |
---|
414 | } |
---|
415 | else |
---|
416 | { |
---|
417 | valor/=total;//Se divide el valor de la celda entre el total correspondiente |
---|
418 | } |
---|
419 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(QString::number(valor,'f',2)); |
---|
420 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
421 | value = Separador(ValoraInsertar,false); |
---|
422 | ValoraInsertar->setText(value); |
---|
423 | CT_HorizontalTW->setItem(i,j,ValoraInsertar); |
---|
424 | } |
---|
425 | /**** En este else se llenan las celdas con fila y columna 0, es decir las que tienen nombre *****/ |
---|
426 | else if((i==0 && j>0)||(j==0 && i>0)) |
---|
427 | { |
---|
428 | QString value=tw->item(j,i)->text(); |
---|
429 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(value); |
---|
430 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
431 | CT_HorizontalTW->setItem(j,i,ValoraInsertar); |
---|
432 | } |
---|
433 | |
---|
434 | } |
---|
435 | } |
---|
436 | /* Se agrega la columna y fila (0,0) y se insertan los titulos de las cuentas */ |
---|
437 | insertremoveRowCol(tw,0,true); |
---|
438 | insertremoveRowCol(CT_HorizontalTW,0,true); |
---|
439 | setAccountTitle(tw); |
---|
440 | setAccountTitle(CT_HorizontalTW); |
---|
441 | |
---|
442 | int indice=ObtenerIndice("CT_Horizontal");//Se obtiene el indice de la pestaña |
---|
443 | QHBoxLayout * layoutCentralWidget = new QHBoxLayout; |
---|
444 | layoutCentralWidget->addWidget(CT_HorizontalTW); |
---|
445 | QWidget *widget = tabWidget->widget(indice); |
---|
446 | widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada |
---|
447 | } |
---|
448 | |
---|
449 | void MainWindow::slotCloseExogena() |
---|
450 | { |
---|
451 | formVariablesExogenas->close(); |
---|
452 | } |
---|
453 | |
---|
454 | void MainWindow::slotDeshacerExogena() |
---|
455 | { |
---|
456 | QMessageBox msBox(QMessageBox::Question,"Deshacer","¿Desea deshacer todos los cambios?", |
---|
457 | QMessageBox::Yes | QMessageBox::No,this); |
---|
458 | msBox.setButtonText(QMessageBox::Yes,"&Si"); |
---|
459 | msBox.setDefaultButton(QMessageBox::Yes); |
---|
460 | if(msBox.exec()==QMessageBox::Yes) |
---|
461 | { |
---|
462 | int cantidad=stackVE->comboAccount->count(); |
---|
463 | /* Se habilitan todas cuentas */ |
---|
464 | for(int i=0;i<cantidad;i++) |
---|
465 | { |
---|
466 | QListWidget *lw=new QListWidget; |
---|
467 | lw= stackVE->veWidget->accounListWidget; |
---|
468 | lw = findChild<QListWidget *>(QString("accountlist %1").arg(i + 1)); |
---|
469 | lw->setEnabled(true); |
---|
470 | } |
---|
471 | diccCuentasExogenas.clear();//Se limpia el diccionario |
---|
472 | } |
---|
473 | } |
---|
474 | |
---|
475 | void MainWindow::slotAgregarExogena() |
---|
476 | { |
---|
477 | actionVariableExogena.setDisabled(true);//Se deshabilita la opcion de agregar variables exogenas |
---|
478 | QString nombre_cuenta=stackVE->comboAccount->currentText();//Se obtiene el nombre de la cuenta seleccionado |
---|
479 | QListWidget *lw=new QListWidget; |
---|
480 | //lw=stackVE->veWidget->accounListWidget; |
---|
481 | int index=stackVE->comboAccount->currentIndex();//Se obtiene el indice selecionado |
---|
482 | lw = findChild<QListWidget *>(QString("accountlist %1").arg(index + 1));//Se obtiene la lista seleccionada |
---|
483 | QStringList componentes_cuenta; |
---|
484 | |
---|
485 | if(nombre_cuenta!="Todas las Cuentas") |
---|
486 | { |
---|
487 | if(!lw->isEnabled()) |
---|
488 | { |
---|
489 | QMessageBox::warning(this,"Alerta","La Cuenta Actual ya fue Agregada"); |
---|
490 | } |
---|
491 | else if(lw->selectedItems().count()==0) |
---|
492 | { |
---|
493 | QMessageBox::warning(this,"Alerta", |
---|
494 | "Para Agregar la Cuenta debe seleccionar \n al menos un valor"); |
---|
495 | } |
---|
496 | else |
---|
497 | { |
---|
498 | int contar=lw->selectedItems().count(); |
---|
499 | for(int i=0;i<contar;i++) |
---|
500 | { |
---|
501 | componentes_cuenta.append(lw->selectedItems().value(i)->text()); |
---|
502 | } |
---|
503 | lw->setDisabled(true); |
---|
504 | opcionCuentaExogena=1;//Se establece un valor para la variable de la opcion |
---|
505 | diccCuentasExogenas.insert(nombre_cuenta,componentes_cuenta); |
---|
506 | } |
---|
507 | } |
---|
508 | else |
---|
509 | { |
---|
510 | int cantidad=stackVE->comboAccount->count(); |
---|
511 | for(int i=0;i<cantidad;i++) |
---|
512 | { |
---|
513 | QListWidget *lw=new QListWidget; |
---|
514 | lw=stackVE->veWidget->accounListWidget; |
---|
515 | lw = findChild<QListWidget *>(QString("accountlist %1").arg(i + 1));//Se obtiene la lista seleccionada |
---|
516 | lw->setDisabled(true); |
---|
517 | opcionCuentaExogena=2;//Se establece un valor para la variable de la opcion |
---|
518 | } |
---|
519 | |
---|
520 | } |
---|
521 | |
---|
522 | } |
---|
523 | |
---|
524 | void MainWindow::slotFinalizarExogena() |
---|
525 | { |
---|
526 | QTableWidget *tablaEE = new QTableWidget; |
---|
527 | tablaEE->setObjectName("TablaExogenaEndogena"); |
---|
528 | QTableWidget *tablaPPAL = findChild<QTableWidget *>("TablaPrincipal");//Se carga la tabla principal |
---|
529 | int count=tablaPPAL->rowCount(); |
---|
530 | CrearTablaVacia(count,tablaEE);//Se crea la tabla vacia |
---|
531 | /* **** Se coloca como no editable la celda(0,0) ***** */ |
---|
532 | noEditColZero(tablaEE); |
---|
533 | if(opcionCuentaExogena==1)//Si seleccionaron componentes |
---|
534 | { |
---|
535 | |
---|
536 | int elementos = contarElementosMap(diccCuentasExogenas); |
---|
537 | |
---|
538 | /***** Se llena la tabla vacia con los valores de la tabla principal ****/ |
---|
539 | for(int i=0;i<count-1;i++) |
---|
540 | { |
---|
541 | for(int j=0;j<count-1;j++) |
---|
542 | { |
---|
543 | if(i>=2 && j>=2) |
---|
544 | { |
---|
545 | QString value = Separador(tablaPPAL->item(i,j),true); |
---|
546 | double valor=value.toDouble(); |
---|
547 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(QString::number(valor,'f',2)); |
---|
548 | value = Separador(ValoraInsertar,false); |
---|
549 | ValoraInsertar->setText(value); |
---|
550 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
551 | tablaEE->setItem(i,j,ValoraInsertar); |
---|
552 | } |
---|
553 | /**** En este else se llenan las celdas con fila y columna 0, es decir las que tienen nombre *****/ |
---|
554 | else if(((i==0 && j>1)||(j==0 && i>1))or((i==1 && j>1)||(j==1 && i>1))) |
---|
555 | { |
---|
556 | QString value=tablaPPAL->item(i,j)->text(); |
---|
557 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(value); |
---|
558 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
559 | tablaEE->setItem(i,j,ValoraInsertar); |
---|
560 | } |
---|
561 | else |
---|
562 | { |
---|
563 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem; |
---|
564 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
565 | tablaEE->setItem(i,j,ValoraInsertar); |
---|
566 | } |
---|
567 | |
---|
568 | } |
---|
569 | } |
---|
570 | |
---|
571 | /*** Se acomodan los componentes de las cuentas exogenas ***/ |
---|
572 | int cantidad =tablaEE->rowCount(); |
---|
573 | foreach(QString key,diccCuentasExogenas.keys()) |
---|
574 | { |
---|
575 | foreach(QString key2,diccCuentasExogenas[key]) |
---|
576 | { |
---|
577 | for(int i=2;i<cantidad;i++) |
---|
578 | { |
---|
579 | QString cuenta=tablaEE->item(1,i)->text(); |
---|
580 | QString componente =tablaEE->item(2,i)->text(); |
---|
581 | if(key==cuenta and key2==componente) |
---|
582 | { |
---|
583 | QList<QString> fila; |
---|
584 | fila=llenarLista(fila,tablaEE,i,1); |
---|
585 | tablaEE->removeRow(i-1); |
---|
586 | tablaEE->insertRow(tablaEE->rowCount()); |
---|
587 | insertRowExogena(fila,tablaEE,1); |
---|
588 | fila.clear(); |
---|
589 | |
---|
590 | QList<QString> columna; |
---|
591 | columna=llenarLista(columna,tablaEE,i,0); |
---|
592 | tablaEE->removeColumn(i-1); |
---|
593 | tablaEE->insertColumn(tablaEE->columnCount()); |
---|
594 | insertRowExogena(columna,tablaEE,0); |
---|
595 | columna.clear(); |
---|
596 | } |
---|
597 | } |
---|
598 | } |
---|
599 | } |
---|
600 | |
---|
601 | int inicioExogena=count-elementos; |
---|
602 | |
---|
603 | QTableWidget *matrizEndogena = new QTableWidget; |
---|
604 | matrizEndogena->setObjectName("MatrizEndogenaEndogena"); |
---|
605 | CrearTablaVacia(inicioExogena,matrizEndogena); |
---|
606 | noEditColZero(matrizEndogena); |
---|
607 | |
---|
608 | |
---|
609 | clonarTabla(tablaEE,matrizEndogena,inicioExogena); |
---|
610 | CalcularTotales(matrizEndogena,2); |
---|
611 | |
---|
612 | CalcularTotales(tablaEE,2); |
---|
613 | setEndogenaExogenaCell(tablaEE,inicioExogena,elementos,true); |
---|
614 | |
---|
615 | //Se crea la nueva pestaña |
---|
616 | tabWidget->addTab(new QWidget,"Tipo de Variable"); |
---|
617 | int indice=ObtenerIndice("Tipo de Variable");//Se obtiene el indice de la pestaña |
---|
618 | QHBoxLayout * layoutCentralWidget = new QHBoxLayout; |
---|
619 | layoutCentralWidget->addWidget(tablaEE); |
---|
620 | QWidget *widget = tabWidget->widget(indice); |
---|
621 | widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada |
---|
622 | formVariablesExogenas->close(); |
---|
623 | //Se activa la opcion de los multiplicadores de leontief |
---|
624 | connect(&actionLa,SIGNAL(triggered()),this,SLOT(slotLa())); |
---|
625 | actionLa.setEnabled(true); |
---|
626 | connect(&actionEncadenamiento,SIGNAL(triggered()),this,SLOT(slotEncadenamientos())); |
---|
627 | |
---|
628 | /* Se crea la pestaña endogena-endogena */ |
---|
629 | tabWidget->addTab(new QWidget,"Endogena-Endogena"); |
---|
630 | int indiceEndogeno=ObtenerIndice("Endogena-Endogena");//Se obtiene el indice de la pestaña |
---|
631 | QHBoxLayout * layoutEndogeno = new QHBoxLayout; |
---|
632 | layoutEndogeno->addWidget(matrizEndogena); |
---|
633 | QWidget *widgetEndogeno = tabWidget->widget(indiceEndogeno); |
---|
634 | widgetEndogeno->setLayout(layoutEndogeno);//Se añade el widget y layout a la pestaña creada |
---|
635 | |
---|
636 | crearDiccionario(tablaEE); |
---|
637 | crearDiccionario(tablaEE,false); |
---|
638 | //Se juntan y alinean las cuentas |
---|
639 | spanEndogenaCell(tablaEE,3,1); |
---|
640 | spanExogenaCell(tablaEE,1); |
---|
641 | spanEndogenaCell(matrizEndogena,2,0,false); |
---|
642 | |
---|
643 | obtenerCuentaComponentes();//Se guardan las cuentas/componentes |
---|
644 | |
---|
645 | } |
---|
646 | else if(opcionCuentaExogena==2)//Si se seleccionaron todas las cuentas |
---|
647 | { |
---|
648 | |
---|
649 | /***** Se llena la tabla vacia con los valores de la tabla principal ****/ |
---|
650 | for(int i=0;i<count-1;i++) |
---|
651 | { |
---|
652 | for(int j=0;j<count-1;j++) |
---|
653 | { |
---|
654 | if(i>=2 && j>=2) |
---|
655 | { |
---|
656 | QString value = Separador(tablaPPAL->item(i,j),true); |
---|
657 | double valor=value.toDouble(); |
---|
658 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(QString::number(valor,'f',2)); |
---|
659 | value = Separador(ValoraInsertar,false); |
---|
660 | ValoraInsertar->setText(value); |
---|
661 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
662 | tablaEE->setItem(i,j,ValoraInsertar); |
---|
663 | } |
---|
664 | /**** En este else se llenan las celdas con fila y columna 0, es decir las que tienen nombre *****/ |
---|
665 | else if(((i==0 && j>1)||(j==0 && i>1))or((i==1 && j>1)||(j==1 && i>1))) |
---|
666 | { |
---|
667 | QString value=tablaPPAL->item(i,j)->text(); |
---|
668 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(value); |
---|
669 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
670 | tablaEE->setItem(i,j,ValoraInsertar); |
---|
671 | } |
---|
672 | else |
---|
673 | { |
---|
674 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem; |
---|
675 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
676 | tablaEE->setItem(i,j,ValoraInsertar); |
---|
677 | } |
---|
678 | |
---|
679 | } |
---|
680 | } |
---|
681 | |
---|
682 | QTableWidget *matrizEndogena = new QTableWidget; |
---|
683 | matrizEndogena->setObjectName("MatrizEndogenaEndogena"); |
---|
684 | CrearTablaVacia(count,matrizEndogena); |
---|
685 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(""); |
---|
686 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
687 | matrizEndogena->setItem(0,0,ValoraInsertar); |
---|
688 | |
---|
689 | |
---|
690 | clonarTabla(tablaEE,matrizEndogena,count); |
---|
691 | CalcularTotales(matrizEndogena,2); |
---|
692 | |
---|
693 | setEndogenaExogenaCell(tablaEE,count,0,false); |
---|
694 | CalcularTotales(tablaEE,3); |
---|
695 | |
---|
696 | //Se agrega la nueva pestaña |
---|
697 | tabWidget->addTab(new QWidget,"Tipo de Variable"); |
---|
698 | int indice=ObtenerIndice("Tipo de Variable");//Se obtiene el indice de la pestaña |
---|
699 | QHBoxLayout * layoutCentralWidget = new QHBoxLayout; |
---|
700 | layoutCentralWidget->addWidget(tablaEE); |
---|
701 | QWidget *widget = tabWidget->widget(indice); |
---|
702 | widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada |
---|
703 | formVariablesExogenas->close(); |
---|
704 | |
---|
705 | /* Se crea la pestaña endogena-endogena */ |
---|
706 | tabWidget->addTab(new QWidget,"Endogena-Endogena"); |
---|
707 | int indiceEndogeno=ObtenerIndice("Endogena-Endogena");//Se obtiene el indice de la pestaña |
---|
708 | QHBoxLayout * layoutEndogeno = new QHBoxLayout; |
---|
709 | layoutEndogeno->addWidget(matrizEndogena); |
---|
710 | QWidget *widgetEndogeno = tabWidget->widget(indiceEndogeno); |
---|
711 | widgetEndogeno->setLayout(layoutEndogeno);//Se añade el widget y layout a la pestaña creada |
---|
712 | |
---|
713 | //Se juntan los espacios referentes a las cuentas |
---|
714 | crearDiccionario(tablaEE); |
---|
715 | spanEndogenaCell(tablaEE,3,1); |
---|
716 | spanEndogenaCell(matrizEndogena,2,0,false); |
---|
717 | |
---|
718 | //obtenerCuentaComponentes();//Se guardan las cuentas/componentes*/ |
---|
719 | |
---|
720 | } |
---|
721 | else |
---|
722 | { |
---|
723 | QMessageBox::warning(this,"Alerta","No Agregó ninguna cuenta"); |
---|
724 | } |
---|
725 | } |
---|
726 | |
---|
727 | /*** Slot para calcular el coeficiente tecnico vertical de la matriz endogena/exogena ***/ |
---|
728 | void MainWindow::EndogenaAn() |
---|
729 | { |
---|
730 | tabWidget->addTab(new QWidget,"An"); |
---|
731 | QTableWidget *tw = findChild<QTableWidget *>("MatrizEndogenaEndogena"); |
---|
732 | QTableWidget *to = findChild<QTableWidget *>("TablaExogenaEndogena"); |
---|
733 | QTableWidget *tablaAn = new QTableWidget; |
---|
734 | tablaAn->setObjectName("MatrizAn"); |
---|
735 | int count=tw->rowCount(); |
---|
736 | CrearTablaVacia(count,tablaAn);//Se crea una tabla vacia |
---|
737 | /* **** Se coloca como no editable la celda(0,0) ***** */ |
---|
738 | noEditColZero(tablaAn); |
---|
739 | |
---|
740 | insertremoveRowCol(to,0, false); |
---|
741 | if(opcionCuentaExogena==1) |
---|
742 | { |
---|
743 | CalcularAn(tw,tablaAn,to,count,true);//Funcion para calcular el Coeficiente Tecnico Horizontal (An) |
---|
744 | } |
---|
745 | else |
---|
746 | { |
---|
747 | CalcularAn(tw,tablaAn,to,count,false); |
---|
748 | } |
---|
749 | /* Se colocan los titulos de cuenta endoge/exogena en la tabla endogena-exogena(Tipo de Variable)*/ |
---|
750 | count=to->rowCount()-1; |
---|
751 | if(opcionCuentaExogena==1) |
---|
752 | { |
---|
753 | int elementos = contarElementosMap(diccCuentasExogenas); |
---|
754 | int inicioExogena=count-elementos; |
---|
755 | setEndogenaExogenaCell(to,inicioExogena+1,elementos,true); |
---|
756 | } |
---|
757 | else |
---|
758 | { |
---|
759 | count = tw->rowCount(); |
---|
760 | setEndogenaExogenaCell(to,count,0,false); |
---|
761 | } |
---|
762 | |
---|
763 | int indice=ObtenerIndice("An");//Se obtiene el indice de la pestaña |
---|
764 | QHBoxLayout * layoutCentralWidget = new QHBoxLayout; |
---|
765 | layoutCentralWidget->addWidget(tablaAn); |
---|
766 | QWidget *widget = tabWidget->widget(indice); |
---|
767 | widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada |
---|
768 | spanEndogenaCell(tablaAn,2,0,false);//Se juntan los espacios de las cuentas |
---|
769 | crearMatrizEndogena(tablaAn); |
---|
770 | } |
---|
771 | |
---|
772 | void MainWindow::slotLa() |
---|
773 | { |
---|
774 | EndogenaAn(); |
---|
775 | QTableWidget *tw = findChild<QTableWidget *>("MatrizAn"); |
---|
776 | restarIdentidadAn(tw); |
---|
777 | } |
---|
778 | |
---|
779 | int MainWindow::ObtenerIndice(QString text)//Funcion para obtener el indice de una pestaña buscada por un nombre dado |
---|
780 | { |
---|
781 | int cantidad=tabWidget->count(); |
---|
782 | int indice=0; |
---|
783 | for(int i=0;i<cantidad;i++) |
---|
784 | { |
---|
785 | if(tabWidget->tabText(i)==text) |
---|
786 | { |
---|
787 | indice=i; |
---|
788 | break; |
---|
789 | } |
---|
790 | } |
---|
791 | return indice; |
---|
792 | } |
---|
793 | |
---|
794 | |
---|
795 | void MainWindow::createMatrixCentralWidget() |
---|
796 | { |
---|
797 | QHBoxLayout * layoutCentralWidget = new QHBoxLayout; |
---|
798 | QVBoxLayout * layoutLateralWidget = new QVBoxLayout; |
---|
799 | |
---|
800 | QTableWidget * tableWidget = new QTableWidget(this); |
---|
801 | tableWidget->setObjectName("TablaPrincipal");//Se le asigna nombre al objeto |
---|
802 | QGroupBox * groupBoxAccount = new QGroupBox; |
---|
803 | QPushButton * buttonEnd = new QPushButton; |
---|
804 | buttonEnd->setObjectName("AgregarCuentas");//Se le asigna nombre al objeto |
---|
805 | QPushButton * buttonRestaurar = new QPushButton; |
---|
806 | buttonRestaurar->setObjectName("Restaurar");//Se le asigna nombre al objeto |
---|
807 | QPushButton * buttonFinalizar = new QPushButton; |
---|
808 | buttonFinalizar->setObjectName("Finalizar");//Se le asigna nombre al objeto |
---|
809 | QPushButton * buttonModificar = new QPushButton; |
---|
810 | buttonModificar->setObjectName("Modificar");//Se le asigna nombre al objeto |
---|
811 | |
---|
812 | populateTable(tableWidget); |
---|
813 | tableWidget->setMaximumHeight(700); |
---|
814 | |
---|
815 | /* **** Se coloca como no editable la celda(0,0) ***** */ |
---|
816 | noEditColZero(tableWidget); |
---|
817 | |
---|
818 | //tableWidget->setFixedSize(750,750); |
---|
819 | layoutCentralWidget->addWidget(tableWidget); |
---|
820 | //layoutCentralWidget->addStretch(); |
---|
821 | |
---|
822 | QVBoxLayout * layoutAccounts = new QVBoxLayout; |
---|
823 | |
---|
824 | layoutAccounts->addWidget(new StackWidget(numAccounts, groupBoxAccount)); |
---|
825 | |
---|
826 | groupBoxAccount->setFixedWidth(220); |
---|
827 | groupBoxAccount->setObjectName("GrupoCuentas");//Se le asigna nombre al objeto |
---|
828 | groupBoxAccount->setLayout(layoutAccounts);; |
---|
829 | groupBoxAccount->setTitle("Cuentas"); |
---|
830 | groupBoxAccount->setStyleSheet("QGroupBox {border: 1px solid gray; " |
---|
831 | "border-radius: 3px; margin-top: 0.5em;} " |
---|
832 | "QGroupBox::title { subcontrol-origin: margin; " |
---|
833 | "left: 10px; padding: 0 3px 0 3px; } "); |
---|
834 | |
---|
835 | |
---|
836 | |
---|
837 | layoutLateralWidget->addStretch(1); |
---|
838 | layoutLateralWidget->addWidget(groupBoxAccount); |
---|
839 | buttonEnd->setText("Agregar Cuenta"); |
---|
840 | buttonEnd->setFixedWidth(130); |
---|
841 | buttonEnd->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
842 | "font-weight: bold; height: 30px; border: none;" |
---|
843 | "border-radius: 5px; margin-top: 40px;"); |
---|
844 | layoutLateralWidget->addWidget(buttonEnd); |
---|
845 | |
---|
846 | |
---|
847 | /*********** Nuevo boton para restaurar la tabla *******/ |
---|
848 | buttonRestaurar->setText("Restaurar Titulos"); |
---|
849 | buttonRestaurar->setFixedWidth(150); |
---|
850 | buttonRestaurar->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
851 | "font-weight: bold; height: 30px; border: none;" |
---|
852 | "border-radius: 5px; margin-top: 40px;"); |
---|
853 | layoutLateralWidget->addWidget(buttonRestaurar); |
---|
854 | |
---|
855 | buttonModificar->setText("Editar Cuenta Actual"); |
---|
856 | buttonModificar->setFixedWidth(180); |
---|
857 | buttonModificar->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
858 | "font-weight: bold; height: 30px; border: none;" |
---|
859 | "border-radius: 5px; margin-top: 40px;"); |
---|
860 | layoutLateralWidget->addWidget(buttonModificar); |
---|
861 | |
---|
862 | |
---|
863 | buttonFinalizar->setText("Finalizar Carga"); |
---|
864 | buttonFinalizar->setFixedWidth(130); |
---|
865 | buttonFinalizar->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
866 | "font-weight: bold; height: 30px; border: none;" |
---|
867 | "border-radius: 5px; margin-top: 40px;"); |
---|
868 | layoutLateralWidget->addWidget(buttonFinalizar); |
---|
869 | layoutLateralWidget->addStretch(6); |
---|
870 | |
---|
871 | |
---|
872 | layoutCentralWidget->addLayout(layoutLateralWidget); |
---|
873 | |
---|
874 | connect(buttonEnd,SIGNAL(clicked()),this,SLOT(AgregarCuenta()));//**************Conexion del boton agregar********************** |
---|
875 | connect(buttonRestaurar,SIGNAL(clicked()),this,SLOT(RestaurarCeldas()));//Conexion del boton restaurar |
---|
876 | connect(buttonFinalizar,SIGNAL(clicked()),this,SLOT(FinalizarCuentas()));//Conexion del boton Finalizar |
---|
877 | connect(buttonModificar,SIGNAL(clicked()),this,SLOT(ModificarCuenta()));//Conexion del boton modificar |
---|
878 | |
---|
879 | |
---|
880 | layoutCentralWidget->sizeHint(); |
---|
881 | |
---|
882 | tabWidget->addTab(new QWidget,"MCS"); |
---|
883 | QWidget *widget= tabWidget->widget(1); |
---|
884 | widget->setLayout(layoutCentralWidget); |
---|
885 | |
---|
886 | |
---|
887 | /* *********** Se agrega la columna en la que se asignan los nombre ************** */ |
---|
888 | tableWidget->insertRow(0); |
---|
889 | tableWidget->insertColumn(0); |
---|
890 | noEditColZero(tableWidget); |
---|
891 | /* Se agregan elementos a la recien creada fila/columna */ |
---|
892 | int contador=tableWidget->rowCount(); |
---|
893 | for(int i=1;i<contador;i++) |
---|
894 | { |
---|
895 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem; |
---|
896 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
897 | tableWidget->setItem(0,i,ValoraInsertar); |
---|
898 | |
---|
899 | QTableWidgetItem *ValoraInsertar2 = new QTableWidgetItem; |
---|
900 | ValoraInsertar2->setFlags(ValoraInsertar2->flags() ^ Qt::ItemIsEditable); |
---|
901 | tableWidget->setItem(i,0,ValoraInsertar2); |
---|
902 | } |
---|
903 | |
---|
904 | matricesMenuBar();//Al terminar la carga de la tabla se ejecuta la accion para el menu de Operaciones |
---|
905 | tabWidget->setCurrentIndex(1);//Se seleciona la pestaña MCS |
---|
906 | |
---|
907 | actionLoadMatrix.setDisabled(true); |
---|
908 | |
---|
909 | actionExportMatrix.setEnabled(true); |
---|
910 | |
---|
911 | /**** Se conectan las acciones para coeficientes tecnicos horizontales y verticales ****/ |
---|
912 | connect(&actionCH, SIGNAL(triggered()), this,SLOT(slotCoeficienteHorizontal())); |
---|
913 | connect(&actionCV, SIGNAL(triggered()), this,SLOT(slotCoeficienteVertical())); |
---|
914 | //Se conecta la accion para la variables exogenas |
---|
915 | connect(&actionVariableExogena,SIGNAL(triggered()),this,SLOT(slotVariableExogena())); |
---|
916 | } |
---|
917 | |
---|
918 | void MainWindow::AgregarCuenta() |
---|
919 | { |
---|
920 | QMessageBox msBox(QMessageBox::Question,"Agregar cuenta","¿Está seguro que agregar la cuenta?", |
---|
921 | QMessageBox::Yes | QMessageBox::No,this); |
---|
922 | msBox.setButtonText(QMessageBox::Yes,"&Si"); |
---|
923 | msBox.setDefaultButton(QMessageBox::Yes); |
---|
924 | if(msBox.exec()==QMessageBox::Yes) |
---|
925 | { |
---|
926 | QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal");//Se busca la tabla que se creo |
---|
927 | StackWidget *sw = findChild<StackWidget *>();//Se buscan las cuentas creadas |
---|
928 | |
---|
929 | /* ****** Se leen los campos del widget izquierdo ******* */; |
---|
930 | |
---|
931 | int index=sw->comboAccount->currentIndex(); |
---|
932 | |
---|
933 | |
---|
934 | /***** Se cargan la linea y las spin box correpondientes a la cuenta seleccionada *****/ |
---|
935 | |
---|
936 | QLineEdit *le= findChild<QLineEdit *>(QString("linedit %1").arg(index + 1)); |
---|
937 | QSpinBox *SBStart = findChild<QSpinBox *>(QString("accountstart %1").arg(index+1)); |
---|
938 | QSpinBox *SBEnd = findChild<QSpinBox *>(QString("accountend %1").arg(index+1)); |
---|
939 | |
---|
940 | int inicio=SBStart->value(); |
---|
941 | int fin=SBEnd->value(); |
---|
942 | QString nombreCuenta=le->text(); |
---|
943 | |
---|
944 | if(nombreCuenta.isEmpty() or nombreCuenta.isNull()) |
---|
945 | { |
---|
946 | QMessageBox::warning(this,"Alerta","El nombre de la cuenta esta vacio"); |
---|
947 | } |
---|
948 | else |
---|
949 | { |
---|
950 | int cantidad_filas=tw->rowCount(); |
---|
951 | |
---|
952 | if(inicio>cantidad_filas or fin>cantidad_filas)//Se verifica que los valores no excedan el tamaño de la tabla |
---|
953 | { |
---|
954 | QMessageBox::warning(this,"Alerta","Valores mayores al tamaño\n de la tabla"); |
---|
955 | } |
---|
956 | else |
---|
957 | { |
---|
958 | /*** Se comprueba si la celda de la tabla esta ocupada por otra cuenta ***/ |
---|
959 | bool centinela=true; |
---|
960 | if(inicio>2 and fin>2){ |
---|
961 | for(int i=0;i<numAccounts;i++) |
---|
962 | { |
---|
963 | if(i!=index) |
---|
964 | { |
---|
965 | QSpinBox *otherEnd = findChild<QSpinBox *>(QString("accountend %1").arg(i+1)); |
---|
966 | int otroFin=otherEnd->text().toInt(); |
---|
967 | if(inicio<otroFin) |
---|
968 | { |
---|
969 | centinela=false; |
---|
970 | } |
---|
971 | } |
---|
972 | } |
---|
973 | } |
---|
974 | |
---|
975 | /* ***** Se asigna el nombre de la cuenta a las cabecereas de la tabla en el rango(inicio,fin) ***** */ |
---|
976 | if((inicio>2 && fin>2) and (centinela)) |
---|
977 | { |
---|
978 | for(int i=inicio-1;i<fin;i++) |
---|
979 | { |
---|
980 | QTableWidgetItem *ValoraInsertarFila = new QTableWidgetItem(nombreCuenta); |
---|
981 | ValoraInsertarFila->setTextAlignment(Qt::AlignCenter); |
---|
982 | ValoraInsertarFila->setFlags(ValoraInsertarFila->flags() ^ Qt::ItemIsEditable); |
---|
983 | tw->setItem(0,i,ValoraInsertarFila); |
---|
984 | QTableWidgetItem *ValoraInsertarColumna = new QTableWidgetItem(nombreCuenta); |
---|
985 | ValoraInsertarColumna->setTextAlignment(Qt::AlignCenter); |
---|
986 | ValoraInsertarColumna->setFlags(ValoraInsertarColumna->flags() ^ Qt::ItemIsEditable); |
---|
987 | tw->setItem(i,0,ValoraInsertarColumna); |
---|
988 | } |
---|
989 | int espacio=(fin-inicio)+1; |
---|
990 | if(espacio>1) |
---|
991 | { |
---|
992 | tw->setSpan(inicio-1,0,espacio,1); |
---|
993 | tw->setSpan(0,inicio-1,1,espacio); |
---|
994 | } |
---|
995 | /***** Se inhabilita el boton de la linea y los spinbox *******/ |
---|
996 | le->setEnabled(false); |
---|
997 | SBStart->setEnabled(false); |
---|
998 | SBEnd->setEnabled(false); |
---|
999 | } |
---|
1000 | else if(!centinela) |
---|
1001 | { |
---|
1002 | QMessageBox::warning(this,"Alerta","Valores en el espacio de otra cuenta"); |
---|
1003 | } |
---|
1004 | else |
---|
1005 | { |
---|
1006 | QMessageBox::warning(this,"Alerta","Valores invalidos"); |
---|
1007 | } |
---|
1008 | |
---|
1009 | } |
---|
1010 | } |
---|
1011 | } |
---|
1012 | |
---|
1013 | } |
---|
1014 | |
---|
1015 | void MainWindow::FinalizarCuentas() |
---|
1016 | { |
---|
1017 | QMessageBox msBox(QMessageBox::Question,"Finalizar Carga","¿Está seguro que desea finalizar?", |
---|
1018 | QMessageBox::Yes | QMessageBox::No,this); |
---|
1019 | msBox.setButtonText(QMessageBox::Yes,"&Si"); |
---|
1020 | msBox.setDefaultButton(QMessageBox::Yes); |
---|
1021 | if(msBox.exec()==QMessageBox::Yes) |
---|
1022 | { |
---|
1023 | bool Centinela=ComprobarCuentas();//Se llama a la funcion que comprueba si todos los campos de las cuentas estan llenos |
---|
1024 | if(Centinela) |
---|
1025 | { |
---|
1026 | QPushButton *Agregar = findChild<QPushButton *>("AgregarCuentas"); |
---|
1027 | QPushButton *Restaurar = findChild<QPushButton *>("Restaurar"); |
---|
1028 | Agregar->setStyleSheet("background-color: gray; color: #fff;" |
---|
1029 | "font-weight: bold; height: 30px; border: none;" |
---|
1030 | "border-radius: 5px; margin-top: 40px;"); |
---|
1031 | Agregar->setEnabled(false); |
---|
1032 | Agregar->setVisible(false); |
---|
1033 | Restaurar->setStyleSheet("background-color: gray; color: #fff;" |
---|
1034 | "font-weight: bold; height: 30px; border: none;" |
---|
1035 | "border-radius: 5px; margin-top: 40px;"); |
---|
1036 | Restaurar->setEnabled(false); |
---|
1037 | Restaurar->setVisible(false); |
---|
1038 | QPushButton *Modificar = findChild<QPushButton *>("Modificar"); |
---|
1039 | Modificar->setStyleSheet("background-color: gray; color: #fff;" |
---|
1040 | "font-weight: bold; height: 30px; border: none;" |
---|
1041 | "border-radius: 5px; margin-top: 40px;"); |
---|
1042 | Modificar->setEnabled(false); |
---|
1043 | Modificar->setVisible(false); |
---|
1044 | QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal"); |
---|
1045 | QPushButton *Finalizar = findChild<QPushButton *>("Finalizar"); |
---|
1046 | Finalizar->setStyleSheet("background-color: gray; color: #fff;" |
---|
1047 | "font-weight: bold; height: 30px; border: none;" |
---|
1048 | "border-radius: 5px; margin-top: 40px;"); |
---|
1049 | Finalizar->setEnabled(false); |
---|
1050 | Finalizar->setVisible(false); |
---|
1051 | |
---|
1052 | QGroupBox *groupbox = findChild<QGroupBox *>("GrupoCuentas"); |
---|
1053 | groupbox->setVisible(false); |
---|
1054 | |
---|
1055 | CalcularTotales(tw,2);//Se llama a la funcion que agregue una nueva fila y columna con los totales respectivos |
---|
1056 | setAccountTitle(tw); |
---|
1057 | |
---|
1058 | /* Luego de calcular los totales se habilitan las opciones del menu herramientas */ |
---|
1059 | actionCH.setEnabled(true); |
---|
1060 | actionCV.setEnabled(true); |
---|
1061 | actionVariableExogena.setEnabled(true); |
---|
1062 | } |
---|
1063 | else |
---|
1064 | { |
---|
1065 | QMessageBox::warning(this,"Alerta","Debe llenar correctamente y agregar todas las cuentas"); |
---|
1066 | } |
---|
1067 | } |
---|
1068 | } |
---|
1069 | |
---|
1070 | void MainWindow::CalcularTotales(QTableWidget *tableWidget,int inicio)//Se calculan los totales por fila/columna |
---|
1071 | { |
---|
1072 | int filas=tableWidget->rowCount(); |
---|
1073 | int columnas=tableWidget->columnCount(); |
---|
1074 | /******* Se inserta la nueva fila y columna para los totales, asi como es texto corespondiente *****/ |
---|
1075 | tableWidget->insertRow(filas); |
---|
1076 | tableWidget->insertColumn(columnas); |
---|
1077 | QTableWidgetItem *ColumnaTotal = new QTableWidgetItem; |
---|
1078 | ColumnaTotal->setText("Total en Columna"); |
---|
1079 | CellStyle(ColumnaTotal);//Estilo de la Celda |
---|
1080 | ColumnaTotal->setFlags(ColumnaTotal->flags() ^ Qt::ItemIsEditable); |
---|
1081 | QTableWidgetItem *FilaTotal = new QTableWidgetItem; |
---|
1082 | FilaTotal->setText("Total en Fila"); |
---|
1083 | CellStyle(FilaTotal);//Estilo de la Celda |
---|
1084 | FilaTotal->setFlags(FilaTotal->flags() ^ Qt::ItemIsEditable); |
---|
1085 | tableWidget->setItem(columnas,inicio-1,ColumnaTotal); |
---|
1086 | tableWidget->setItem(inicio-1,filas,FilaTotal); |
---|
1087 | for(int i=inicio;i<filas;i++) |
---|
1088 | { |
---|
1089 | double SumaFila=0; |
---|
1090 | double SumaColumna=0; |
---|
1091 | for(int j=inicio;j<filas;j++) |
---|
1092 | { |
---|
1093 | QString fila=Separador(tableWidget->item(j,i),true); |
---|
1094 | double thisFila=fila.toDouble(); |
---|
1095 | QString columna=Separador(tableWidget->item(i,j),true); |
---|
1096 | double thisColumna=columna.toDouble(); |
---|
1097 | SumaFila+=thisFila; |
---|
1098 | SumaColumna+=thisColumna; |
---|
1099 | } |
---|
1100 | QTableWidgetItem *Valor1 = new QTableWidgetItem; |
---|
1101 | Valor1->setText(QString::number(SumaFila,'f',2)); |
---|
1102 | QString value1 = Separador(Valor1,false); |
---|
1103 | Valor1->setText(value1); |
---|
1104 | Valor1->setFlags(Valor1->flags() ^ Qt::ItemIsEditable); |
---|
1105 | CellStyle(Valor1);//Estilo de la Celda |
---|
1106 | QTableWidgetItem *Valor2 = new QTableWidgetItem; |
---|
1107 | Valor2->setText(QString::number(SumaColumna,'f',2)); |
---|
1108 | QString value2 = Separador(Valor2,false); |
---|
1109 | Valor2->setText(value2); |
---|
1110 | Valor2->setFlags(Valor2->flags() ^ Qt::ItemIsEditable); |
---|
1111 | CellStyle(Valor2);//Estilo de la Celda |
---|
1112 | tableWidget->setItem(filas,i,Valor1);//Inserta en Filas |
---|
1113 | tableWidget->setItem(i,filas,Valor2);//Inserta en Columnas |
---|
1114 | } |
---|
1115 | /* Se coloca como no editable la última celda */ |
---|
1116 | QTableWidgetItem *Valor = new QTableWidgetItem; |
---|
1117 | Valor->setFlags(Valor->flags() ^ Qt::ItemIsEditable); |
---|
1118 | tableWidget->setItem(filas,columnas,Valor); |
---|
1119 | // |
---|
1120 | int cantidad = tableWidget->rowCount(); |
---|
1121 | ItemsNoEditable(tableWidget,0,inicio-1,cantidad-1); |
---|
1122 | |
---|
1123 | } |
---|
1124 | |
---|
1125 | void MainWindow::RestaurarCeldas()//Slot que permite restaurar el titulo de las cuentas en las celdas |
---|
1126 | { |
---|
1127 | QMessageBox msBox(QMessageBox::Question,"Restaurar Celdas","¿Desea Restaurar el titulo de todas las celdas?", |
---|
1128 | QMessageBox::Yes | QMessageBox::No,this); |
---|
1129 | msBox.setButtonText(QMessageBox::Yes,"&Si"); |
---|
1130 | msBox.setDefaultButton(QMessageBox::Yes); |
---|
1131 | if(msBox.exec()==QMessageBox::Yes) |
---|
1132 | { |
---|
1133 | QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal"); |
---|
1134 | insertremoveRowCol(tw,0,false); |
---|
1135 | insertremoveRowCol(tw,0,true); |
---|
1136 | } |
---|
1137 | } |
---|
1138 | |
---|
1139 | void MainWindow::ModificarCuenta()//Slot que permite habilitar la edicion de una cuenta una vez agregada |
---|
1140 | { |
---|
1141 | QMessageBox msBox(QMessageBox::Question,"Modificar Cuenta","¿Desea Modificar la Cuenta Actual?", |
---|
1142 | QMessageBox::Yes | QMessageBox::No,this); |
---|
1143 | msBox.setButtonText(QMessageBox::Yes,"&Si"); |
---|
1144 | msBox.setDefaultButton(QMessageBox::Yes); |
---|
1145 | if(msBox.exec()==QMessageBox::Yes) |
---|
1146 | { |
---|
1147 | StackWidget *sw = findChild<StackWidget *>();//Se buscan las cuentas creadas |
---|
1148 | int index=sw->comboAccount->currentIndex(); |
---|
1149 | QLineEdit *le= findChild<QLineEdit *>(QString("linedit %1").arg(index + 1)); |
---|
1150 | QSpinBox *SBStart = findChild<QSpinBox *>(QString("accountstart %1").arg(index+1)); |
---|
1151 | QSpinBox *SBEnd = findChild<QSpinBox *>(QString("accountend %1").arg(index+1)); |
---|
1152 | le->setEnabled(true); |
---|
1153 | SBStart->setEnabled(true); |
---|
1154 | SBEnd->setEnabled(true); |
---|
1155 | } |
---|
1156 | } |
---|
1157 | |
---|
1158 | void MainWindow::loadMatrizExogena() |
---|
1159 | { |
---|
1160 | |
---|
1161 | } |
---|
1162 | |
---|
1163 | void MainWindow::populateTable(QTableWidget * tableWidget) { |
---|
1164 | |
---|
1165 | QFile file(csvFilePath); |
---|
1166 | if (file.open(QIODevice::ReadOnly | QIODevice::Text)) |
---|
1167 | { |
---|
1168 | int row = 0; |
---|
1169 | QString lineHead = file.readLine(); |
---|
1170 | const std::vector<std::string> rowVH = |
---|
1171 | csv_read_row(lineHead.toStdString(), csvSeparator); |
---|
1172 | |
---|
1173 | |
---|
1174 | matrixSize = rowVH.size(); |
---|
1175 | tableWidget->setRowCount(matrixSize+1); |
---|
1176 | tableWidget->setColumnCount(matrixSize+1); |
---|
1177 | |
---|
1178 | for(int column=0; column<matrixSize; column++) { |
---|
1179 | QTableWidgetItem *newItem = new QTableWidgetItem( |
---|
1180 | QString::fromUtf8(rowVH[column].c_str()). |
---|
1181 | toLocal8Bit().constData()); |
---|
1182 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable);//Se coloca como no editable |
---|
1183 | tableWidget->setItem(row, column+1, newItem); |
---|
1184 | } |
---|
1185 | ++row; |
---|
1186 | |
---|
1187 | while (!file.atEnd() and row<=matrixSize) |
---|
1188 | { |
---|
1189 | QTableWidgetItem *newItem = new QTableWidgetItem( |
---|
1190 | QString::fromUtf8(rowVH[row-1].c_str()). |
---|
1191 | toLocal8Bit().constData()); |
---|
1192 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable);//Se coloca como no editable |
---|
1193 | tableWidget->setItem(row, 0, newItem); |
---|
1194 | |
---|
1195 | QString line = file.readLine(); |
---|
1196 | /*QStringList strings = line.split(csvSeparator); |
---|
1197 | for (int column = 0; column < strings.size(); ++column) { |
---|
1198 | QTableWidgetItem *newItem = new QTableWidgetItem( |
---|
1199 | strings.at(column).toLocal8Bit().constData()); |
---|
1200 | tableWidget->setItem(row, column, newItem); |
---|
1201 | |
---|
1202 | }*/ |
---|
1203 | |
---|
1204 | std::vector<std::string> rowV = |
---|
1205 | csv_read_row(line.toStdString(), csvSeparator); |
---|
1206 | for(int column=0, leng=rowV.size(); |
---|
1207 | column < leng and column<matrixSize; column++) { |
---|
1208 | |
---|
1209 | /* Aqui se incorporan los valores luego de la coma(,) */ |
---|
1210 | QString rowVal = QString::fromUtf8(rowV[column].c_str()); |
---|
1211 | double value = rowVal.toDouble(); |
---|
1212 | |
---|
1213 | |
---|
1214 | |
---|
1215 | QTableWidgetItem *newItem = new QTableWidgetItem( |
---|
1216 | numberFormat(value). |
---|
1217 | toLocal8Bit().constData()); |
---|
1218 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable);//Se coloca como no editable |
---|
1219 | tableWidget->setItem(row, column+1, newItem); |
---|
1220 | matrix[row-1][column] = atof(rowV[column].c_str()); |
---|
1221 | } |
---|
1222 | ++row; |
---|
1223 | } |
---|
1224 | file.close(); |
---|
1225 | } |
---|
1226 | } |
---|
1227 | |
---|
1228 | std::vector<std::string> MainWindow::csv_read_row(std::string line, |
---|
1229 | char delimiter) |
---|
1230 | { |
---|
1231 | std::stringstream ss(line); void msghere(); |
---|
1232 | return csv_read_row(ss, delimiter); |
---|
1233 | } |
---|
1234 | |
---|
1235 | std::vector<std::string> MainWindow::csv_read_row(std::istream &in, |
---|
1236 | char delimiter) |
---|
1237 | { |
---|
1238 | std::stringstream ss; |
---|
1239 | bool inquotes = false; |
---|
1240 | std::vector<std::string> row;//relying on RVO |
---|
1241 | while(in.good()) |
---|
1242 | { |
---|
1243 | char c = in.get(); |
---|
1244 | if (!inquotes && c=='"') //beginquotechar |
---|
1245 | { |
---|
1246 | inquotes=true; |
---|
1247 | } |
---|
1248 | else if (inquotes && c=='"') //quotechar |
---|
1249 | { |
---|
1250 | if ( in.peek() == '"')//2 consecutive quotes resolve to 1 |
---|
1251 | { |
---|
1252 | ss << (char)in.get(); |
---|
1253 | } |
---|
1254 | else //endquotechar |
---|
1255 | { |
---|
1256 | inquotes=false; |
---|
1257 | } |
---|
1258 | } |
---|
1259 | else if (!inquotes && c==delimiter) //end of field |
---|
1260 | { |
---|
1261 | row.push_back( ss.str() ); |
---|
1262 | ss.str(""); |
---|
1263 | } |
---|
1264 | else if (!inquotes && (c=='\r' || c=='\n') ) |
---|
1265 | { |
---|
1266 | if(in.peek()=='\n') { in.get(); } |
---|
1267 | row.push_back( ss.str() ); |
---|
1268 | return row; |
---|
1269 | } |
---|
1270 | else |
---|
1271 | { |
---|
1272 | ss << c; |
---|
1273 | } |
---|
1274 | } |
---|
1275 | } |
---|
1276 | |
---|
1277 | QString MainWindow::numberFormat(double & d) { |
---|
1278 | |
---|
1279 | int precision = 2; |
---|
1280 | bool controlador = false; |
---|
1281 | if(d<0) |
---|
1282 | { |
---|
1283 | controlador = true; |
---|
1284 | d *=-1; |
---|
1285 | } |
---|
1286 | |
---|
1287 | |
---|
1288 | QString stringNumber = QString::number(d, 'f', precision); |
---|
1289 | for(int point = 0, i = (stringNumber.lastIndexOf('.') == -1 ? stringNumber.length() : stringNumber.lastIndexOf('.')); i > 0; --i, ++point) |
---|
1290 | { |
---|
1291 | if(point != 0 && point % 3 == 0) |
---|
1292 | { |
---|
1293 | stringNumber.insert(i, '*'); |
---|
1294 | } |
---|
1295 | } |
---|
1296 | if(controlador) |
---|
1297 | { |
---|
1298 | double var = stringNumber.toDouble(); |
---|
1299 | var *=-1; |
---|
1300 | stringNumber = QString::number(var, 'f', precision); |
---|
1301 | } |
---|
1302 | stringNumber.replace(".", ","); |
---|
1303 | stringNumber.replace("*", "."); |
---|
1304 | return stringNumber; |
---|
1305 | } |
---|
1306 | |
---|
1307 | bool MainWindow::ComprobarCuentas()//Se verifica que las lineas de texto y spin box de todas las cuentas no esten vacios |
---|
1308 | { |
---|
1309 | bool centinela=true; |
---|
1310 | StackWidget *sw = findChild<StackWidget *>(); |
---|
1311 | int count=sw->comboAccount->count(); |
---|
1312 | for(int i=0;i<count;i++) |
---|
1313 | { |
---|
1314 | QLineEdit *le= findChild<QLineEdit *>(QString("linedit %1").arg(i + 1)); |
---|
1315 | QSpinBox *SBStart = findChild<QSpinBox *>(QString("accountstart %1").arg(i+1)); |
---|
1316 | QSpinBox *SBEnd = findChild<QSpinBox *>(QString("accountend %1").arg(i+1)); |
---|
1317 | if((le->text().isEmpty()) || (SBStart->text().toInt()==0) || (SBEnd->text().toInt()==0) || (le->isEnabled())) |
---|
1318 | { |
---|
1319 | centinela=false; |
---|
1320 | } |
---|
1321 | } |
---|
1322 | return centinela; |
---|
1323 | } |
---|
1324 | |
---|
1325 | /*** Funcion que obtiene el nombre las cuentas a traves de los lineeidt y los retorna en una lista de string ***/ |
---|
1326 | QStringList MainWindow::ObtenerNombreCuenta(int contador) |
---|
1327 | { |
---|
1328 | QStringList MiLista; |
---|
1329 | for(int i = 0;i<contador;i++) |
---|
1330 | { |
---|
1331 | QLineEdit *le= findChild<QLineEdit *>(QString("linedit %1").arg(i + 1)); |
---|
1332 | MiLista.append(le->text()); |
---|
1333 | } |
---|
1334 | return MiLista; |
---|
1335 | } |
---|
1336 | |
---|
1337 | /*** Funcion que obtiene los inicios/fin de las cuentas y las retorna como entero en una lista ***/ |
---|
1338 | QList<int> MainWindow::ObtenerLimitesCuenta(int contador,int opccion) |
---|
1339 | { |
---|
1340 | QList<int> Lista; |
---|
1341 | for(int i=0;i<contador;i++) |
---|
1342 | { |
---|
1343 | if(opccion==0) |
---|
1344 | { |
---|
1345 | QSpinBox *SBStart = findChild<QSpinBox *>(QString("accountstart %1").arg(i+1)); |
---|
1346 | Lista.append(SBStart->text().toInt()); |
---|
1347 | |
---|
1348 | } |
---|
1349 | else |
---|
1350 | { |
---|
1351 | QSpinBox *SBEnd = findChild<QSpinBox *>(QString("accountend %1").arg(i+1)); |
---|
1352 | Lista.append(SBEnd->text().toInt()); |
---|
1353 | } |
---|
1354 | } |
---|
1355 | return Lista; |
---|
1356 | } |
---|
1357 | |
---|
1358 | /*** Funcion para retornar todos los componentes en una lista ***/ |
---|
1359 | QStringList MainWindow::ObtenerComponentes(QTableWidget *tw) |
---|
1360 | { |
---|
1361 | QStringList MiLista; |
---|
1362 | int contador=tw->rowCount(); |
---|
1363 | for(int i=1;i<contador-1;i++) |
---|
1364 | { |
---|
1365 | MiLista.append(tw->item(0,i)->text()); |
---|
1366 | } |
---|
1367 | return MiLista; |
---|
1368 | } |
---|
1369 | |
---|
1370 | void MainWindow::CrearTablaVacia(int contador, QTableWidget *tw)//FUncion para crear una tabla vacia |
---|
1371 | { |
---|
1372 | for(int k=0;k<contador-1;k++) |
---|
1373 | { |
---|
1374 | tw->insertRow(k); |
---|
1375 | tw->insertColumn(k); |
---|
1376 | } |
---|
1377 | } |
---|
1378 | |
---|
1379 | int MainWindow::contarElementosMap(QMap<QString,QStringList> diccionario)//Funcion para contar los elementos en el map o diccionario |
---|
1380 | { |
---|
1381 | int contador=0; |
---|
1382 | foreach(QString key,diccionario.keys()) |
---|
1383 | { |
---|
1384 | contador+=diccionario[key].count(); |
---|
1385 | } |
---|
1386 | return contador; |
---|
1387 | } |
---|
1388 | |
---|
1389 | /*** Funcion, que dada un nombre de uan cuenta permite retornar su respectivo indice en la combobox ***/ |
---|
1390 | int MainWindow::retornarIndiceCuenta(QString nombre_cuenta) |
---|
1391 | { |
---|
1392 | for(int i=0;i<numAccounts;i++) |
---|
1393 | { |
---|
1394 | QLineEdit *newline= findChild<QLineEdit *>(QString("linedit %1").arg(i + 1)); |
---|
1395 | if(newline->text()==nombre_cuenta) |
---|
1396 | { |
---|
1397 | return i; |
---|
1398 | } |
---|
1399 | } |
---|
1400 | return 0; |
---|
1401 | } |
---|
1402 | |
---|
1403 | /*** Funcion que permite llenar una lista con los elementos en un intervalo dado(fila o columna) ***/ |
---|
1404 | QList<QString> MainWindow::llenarLista(QList<QString> lista,QTableWidget *tw,int valor,int opcion) |
---|
1405 | { |
---|
1406 | int cantidad = tw->rowCount(); |
---|
1407 | for(int i=0;i<cantidad;i++) |
---|
1408 | { |
---|
1409 | if(opcion==1) |
---|
1410 | { |
---|
1411 | lista.append(tw->item(valor,i)->text()); |
---|
1412 | } |
---|
1413 | else |
---|
1414 | { |
---|
1415 | lista.append(tw->item(i,valor)->text()); |
---|
1416 | } |
---|
1417 | } |
---|
1418 | return lista; |
---|
1419 | } |
---|
1420 | |
---|
1421 | /*** Funcion que escribe en una columna o fila con la lista dada ***/ |
---|
1422 | void MainWindow::insertRowExogena(QList<QString> lista,QTableWidget *tw,int opcion) |
---|
1423 | { |
---|
1424 | for(int i=0;i<tw->rowCount();i++) |
---|
1425 | { |
---|
1426 | QTableWidgetItem *twi =new QTableWidgetItem; |
---|
1427 | twi->setText(lista[i]); |
---|
1428 | twi->setFlags(twi->flags() ^ Qt::ItemIsEditable); |
---|
1429 | int fin=tw->rowCount(); |
---|
1430 | if(opcion==1) |
---|
1431 | { |
---|
1432 | tw->setItem(fin-1,i,twi); |
---|
1433 | } |
---|
1434 | else |
---|
1435 | { |
---|
1436 | tw->setItem(i,fin-1,twi); |
---|
1437 | } |
---|
1438 | } |
---|
1439 | } |
---|
1440 | |
---|
1441 | /*** Funcion que permite insertar, alinear y combinar las celdas con los titulos endogena/exogena ***/ |
---|
1442 | void MainWindow::setEndogenaExogenaCell(QTableWidget *tw,int inicioExogena,int elementos,bool condicion) |
---|
1443 | { |
---|
1444 | tw->insertRow(0); |
---|
1445 | tw->insertColumn(0); |
---|
1446 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem; |
---|
1447 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
1448 | tw->setItem(0,0,ValoraInsertar); |
---|
1449 | /* Titulos para las Cuentas endogenas */ |
---|
1450 | QTableWidgetItem *CuentaEndogenafila = new QTableWidgetItem("Cuentas Endógenas"); |
---|
1451 | CuentaEndogenafila->setFlags(CuentaEndogenafila->flags() ^ Qt::ItemIsEditable); |
---|
1452 | CuentaEndogenafila->setTextAlignment(Qt::AlignCenter); |
---|
1453 | tw->setItem(0,1,CuentaEndogenafila); |
---|
1454 | tw->setSpan(0,1,1,inicioExogena-1); |
---|
1455 | QTableWidgetItem *CuentaEndogenaColumna = new QTableWidgetItem; |
---|
1456 | if(elementos<12) |
---|
1457 | { |
---|
1458 | CuentaEndogenaColumna->setText("Cuentas \nEndógenas"); |
---|
1459 | } |
---|
1460 | else |
---|
1461 | { |
---|
1462 | CuentaEndogenaColumna->setText("C\nu\ne\nn\nt\na\ns\n\nE\nn\nd\nó\ng\ne\nn\na\ns"); |
---|
1463 | } |
---|
1464 | CuentaEndogenaColumna->setFlags(CuentaEndogenaColumna->flags() ^ Qt::ItemIsEditable); |
---|
1465 | tw->setItem(1,0,CuentaEndogenaColumna); |
---|
1466 | if((inicioExogena-1)>1) |
---|
1467 | { |
---|
1468 | tw->setSpan(1,0,inicioExogena-1,1); |
---|
1469 | } |
---|
1470 | if(condicion)//Si tiene cuentas exogenas |
---|
1471 | { |
---|
1472 | /* Titulos para las Cuentas exogenas */ |
---|
1473 | QTableWidgetItem *CuentaExogenafila = new QTableWidgetItem("Cuentas Exógenas"); |
---|
1474 | CuentaExogenafila->setFlags(CuentaExogenafila->flags() ^ Qt::ItemIsEditable); |
---|
1475 | CuentaExogenafila->setTextAlignment(Qt::AlignCenter); |
---|
1476 | tw->setItem(0,inicioExogena,CuentaExogenafila); |
---|
1477 | if(elementos>1) |
---|
1478 | { |
---|
1479 | tw->setSpan(0,inicioExogena,1,elementos); |
---|
1480 | } |
---|
1481 | QTableWidgetItem *CuentaExogenaColumna = new QTableWidgetItem; |
---|
1482 | if(elementos<12) |
---|
1483 | { |
---|
1484 | CuentaExogenaColumna->setText("Cuentas \nExógenas"); |
---|
1485 | } |
---|
1486 | else |
---|
1487 | { |
---|
1488 | CuentaExogenaColumna->setText("C\nu\ne\nn\nt\na\ns\n\nE\nx\nó\ng\ne\nn\na\ns"); |
---|
1489 | } |
---|
1490 | CuentaExogenaColumna->setFlags(CuentaExogenaColumna->flags() ^ Qt::ItemIsEditable); |
---|
1491 | tw->setItem(inicioExogena,0,CuentaExogenaColumna); |
---|
1492 | if(elementos>1) |
---|
1493 | { |
---|
1494 | tw->setSpan(inicioExogena,0,elementos,1); |
---|
1495 | } |
---|
1496 | int count = tw->rowCount(); |
---|
1497 | ItemsNoEditable(tw,count-1,count); |
---|
1498 | } |
---|
1499 | } |
---|
1500 | |
---|
1501 | void MainWindow::CalcularAn(QTableWidget *tw,QTableWidget *nuevaTabla,QTableWidget *tablaOriginal,int count,bool endogena)//Funcion para calcular el Coeficiente Tecnico Horizontal (An) |
---|
1502 | { |
---|
1503 | for(int i=0;i<count-1;i++) |
---|
1504 | { |
---|
1505 | double total; |
---|
1506 | QString value; |
---|
1507 | for(int j=0;j<count-1;j++) |
---|
1508 | { |
---|
1509 | if(i>=2 and j>=2) |
---|
1510 | { |
---|
1511 | if(endogena) |
---|
1512 | { |
---|
1513 | int contador = tablaOriginal->rowCount()-1; |
---|
1514 | value = Separador(tablaOriginal->item(contador,i),true); |
---|
1515 | value = QString::number(value.toDouble(),'f',2); |
---|
1516 | total=value.toDouble(); |
---|
1517 | } |
---|
1518 | else |
---|
1519 | { |
---|
1520 | value = Separador(tw->item(count-1,i),true); |
---|
1521 | value = QString::number(value.toDouble(),'f',2); |
---|
1522 | total=value.toDouble(); |
---|
1523 | } |
---|
1524 | QString values = Separador(tw->item(j,i),true); |
---|
1525 | values = QString::number(values.toDouble(),'f',2); |
---|
1526 | double valor=values.toDouble(); |
---|
1527 | if(total==0)//Se comprueba en caso de que el total sea zero |
---|
1528 | { |
---|
1529 | valor=0; |
---|
1530 | } |
---|
1531 | else |
---|
1532 | { |
---|
1533 | valor/=total;//Se divide el valor de la celda entre el total correspondiente |
---|
1534 | |
---|
1535 | } |
---|
1536 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(QString::number(valor,'f',2)); |
---|
1537 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
1538 | QString value = Separador(ValoraInsertar,false); |
---|
1539 | ValoraInsertar->setText(value); |
---|
1540 | nuevaTabla->setItem(j,i,ValoraInsertar); |
---|
1541 | } |
---|
1542 | /**** En este else se llenan las celdas con fila y columna 0, es decir las que tienen nombre *****/ |
---|
1543 | else if(((i==0 && j>1)||(j==0 && i>1))or((i==1 && j>1)||(j==1 && i>1))) |
---|
1544 | { |
---|
1545 | QString value=tw->item(i,j)->text(); |
---|
1546 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(value); |
---|
1547 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
1548 | nuevaTabla->setItem(i,j,ValoraInsertar); |
---|
1549 | } |
---|
1550 | /* Se colocan no editables algunas de las celdas que estan vacias*/ |
---|
1551 | else |
---|
1552 | { |
---|
1553 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem; |
---|
1554 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
1555 | nuevaTabla->setItem(i,j,ValoraInsertar); |
---|
1556 | } |
---|
1557 | } |
---|
1558 | |
---|
1559 | } |
---|
1560 | } |
---|
1561 | |
---|
1562 | void MainWindow::clonarTabla(QTableWidget *tw,QTableWidget *nuevaTabla,int cantidad) |
---|
1563 | { |
---|
1564 | for(int i=0;i<cantidad-1;i++) |
---|
1565 | { |
---|
1566 | for(int j=0;j<cantidad-1;j++) |
---|
1567 | { |
---|
1568 | if(i>=2 && j>=2) |
---|
1569 | { |
---|
1570 | QString value = Separador(tw->item(i,j),true); |
---|
1571 | double valor= value.toDouble(); |
---|
1572 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(QString::number(valor,'f',2)); |
---|
1573 | value = Separador(ValoraInsertar,false); |
---|
1574 | ValoraInsertar->setText(value); |
---|
1575 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
1576 | nuevaTabla->setItem(i,j,ValoraInsertar); |
---|
1577 | } |
---|
1578 | else if(((i==0 && j>1)||(j==0 && i>1)) or ((i==1 && j>1)||(j==1 && i>1))) |
---|
1579 | { |
---|
1580 | QString value=tw->item(i,j)->text(); |
---|
1581 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(value); |
---|
1582 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
1583 | nuevaTabla->setItem(i,j,ValoraInsertar); |
---|
1584 | } |
---|
1585 | else |
---|
1586 | { |
---|
1587 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem; |
---|
1588 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
1589 | nuevaTabla->setItem(i,j,ValoraInsertar); |
---|
1590 | } |
---|
1591 | |
---|
1592 | } |
---|
1593 | } |
---|
1594 | } |
---|
1595 | |
---|
1596 | void MainWindow::crearMatrizEndogena(QTableWidget *tw) |
---|
1597 | { |
---|
1598 | int cantidad=tw->rowCount(); |
---|
1599 | for(int i=0;i<cantidad;i++) |
---|
1600 | { |
---|
1601 | for(int j=0;j<cantidad;j++) |
---|
1602 | { |
---|
1603 | if(i>=2 && j>=2) |
---|
1604 | { |
---|
1605 | double valor=tw->item(i,j)->text().toDouble(); |
---|
1606 | MatrizEndogenaEndogena[i-2][j-2]=valor; |
---|
1607 | } |
---|
1608 | |
---|
1609 | } |
---|
1610 | } |
---|
1611 | } |
---|
1612 | |
---|
1613 | void MainWindow::restarIdentidadAn(QTableWidget *tw) |
---|
1614 | { |
---|
1615 | int cantidad=tw->rowCount()-1; |
---|
1616 | MatrixXd A(cantidad-1,cantidad-1); |
---|
1617 | MatrixXd b(cantidad-1,cantidad-1); |
---|
1618 | MatrixXd ident = MatrixXd::Identity(cantidad-1,cantidad-1); |
---|
1619 | for(int i=0;i<cantidad-1;i++) |
---|
1620 | { |
---|
1621 | for(int j=0;j<cantidad-1;j++) |
---|
1622 | { |
---|
1623 | A(i,j) = ident(i,j)-MatrizEndogenaEndogena[i][j]; |
---|
1624 | } |
---|
1625 | } |
---|
1626 | |
---|
1627 | double determinant = A.determinant(); |
---|
1628 | b = A.inverse(); |
---|
1629 | if(determinant==0) |
---|
1630 | { |
---|
1631 | QMessageBox::critical(this,"Alerta","El determinante es Nulo"); |
---|
1632 | actionLa.setDisabled(true); |
---|
1633 | int indice=ObtenerIndice("An");//Se obtiene el indice de la pestaña |
---|
1634 | tabWidget->widget(indice)->setDisabled(true); |
---|
1635 | |
---|
1636 | } |
---|
1637 | else |
---|
1638 | { |
---|
1639 | QTableWidget *tablaMa = new QTableWidget; |
---|
1640 | tablaMa->setObjectName("MatrizMa"); |
---|
1641 | CrearTablaVacia(cantidad,tablaMa); |
---|
1642 | for(int i=0;i<cantidad-1;i++) |
---|
1643 | { |
---|
1644 | for(int j=0;j<cantidad-1;j++) |
---|
1645 | { |
---|
1646 | double value = b(i,j); |
---|
1647 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(QString::number(value,'f',2)); |
---|
1648 | QString valor = Separador(ValoraInsertar,false); |
---|
1649 | ValoraInsertar->setText(valor); |
---|
1650 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
1651 | tablaMa->setItem(i,j,ValoraInsertar); |
---|
1652 | |
---|
1653 | } |
---|
1654 | } |
---|
1655 | titleEndogena(tablaMa); |
---|
1656 | spanEndogenaCell(tablaMa,2,0,false); |
---|
1657 | tabWidget->addTab(new QWidget,"Ma"); |
---|
1658 | int indice=ObtenerIndice("Ma");//Se obtiene el indice de la pestaña |
---|
1659 | QHBoxLayout * layoutCentralWidget = new QHBoxLayout; |
---|
1660 | layoutCentralWidget->addWidget(tablaMa); |
---|
1661 | QWidget *widget = tabWidget->widget(indice); |
---|
1662 | widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada |
---|
1663 | //Se activa la opcion para los encadenamientos |
---|
1664 | actionEncadenamiento.setEnabled(true); |
---|
1665 | actionLa.setDisabled(true); |
---|
1666 | } |
---|
1667 | } |
---|
1668 | |
---|
1669 | /*Funcion para agregar los componentes y cuentas a partir de la matriz endogena-endogena*/ |
---|
1670 | void MainWindow::titleEndogena(QTableWidget *tw) |
---|
1671 | { |
---|
1672 | QTableWidget *endogena = findChild<QTableWidget *>("MatrizEndogenaEndogena"); |
---|
1673 | int cantidad = endogena->columnCount()-1; |
---|
1674 | tw->insertRow(0); |
---|
1675 | tw->insertRow(0); |
---|
1676 | tw->insertColumn(0); |
---|
1677 | tw->insertColumn(0); |
---|
1678 | for(int i=0;i<2;i++) |
---|
1679 | { |
---|
1680 | for(int j=0;j<cantidad;j++) |
---|
1681 | { |
---|
1682 | if(j>1) |
---|
1683 | { |
---|
1684 | QString item=endogena->item(i,j)->text(); |
---|
1685 | QTableWidgetItem *fila = new QTableWidgetItem(item); |
---|
1686 | fila->setFlags(fila->flags() ^ Qt::ItemIsEditable); |
---|
1687 | tw->setItem(i,j,fila); |
---|
1688 | QTableWidgetItem *columna = new QTableWidgetItem(item); |
---|
1689 | columna->setFlags(columna->flags() ^ Qt::ItemIsEditable); |
---|
1690 | tw->setItem(j,i,columna); |
---|
1691 | } |
---|
1692 | else |
---|
1693 | { |
---|
1694 | QTableWidgetItem *item = new QTableWidgetItem; |
---|
1695 | item->setFlags(item->flags() ^ Qt::ItemIsEditable); |
---|
1696 | tw->setItem(i,j,item); |
---|
1697 | } |
---|
1698 | |
---|
1699 | } |
---|
1700 | } |
---|
1701 | } |
---|
1702 | |
---|
1703 | /* Funcion para volver la celda(0,0) no editable */ |
---|
1704 | void MainWindow::noEditColZero(QTableWidget *tw) |
---|
1705 | { |
---|
1706 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem; |
---|
1707 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
1708 | tw->setItem(0,0,ValoraInsertar); |
---|
1709 | } |
---|
1710 | |
---|
1711 | /* Funcion para colocar los titulos de las cuentas */ |
---|
1712 | void MainWindow::setAccountTitle(QTableWidget *tw) |
---|
1713 | { |
---|
1714 | int myinicio=999; |
---|
1715 | for(int i=0;i<numAccounts;i++) |
---|
1716 | { |
---|
1717 | QLineEdit *le= findChild<QLineEdit *>(QString("linedit %1").arg(i + 1)); |
---|
1718 | QSpinBox *SBStart = findChild<QSpinBox *>(QString("accountstart %1").arg(i+1)); |
---|
1719 | QSpinBox *SBEnd = findChild<QSpinBox *>(QString("accountend %1").arg(i+1)); |
---|
1720 | |
---|
1721 | int inicio=SBStart->value(); |
---|
1722 | int fin=SBEnd->value(); |
---|
1723 | QString nombreCuenta=le->text(); |
---|
1724 | |
---|
1725 | if(myinicio>inicio) |
---|
1726 | { |
---|
1727 | myinicio=inicio; |
---|
1728 | } |
---|
1729 | |
---|
1730 | for(int i=inicio-1;i<fin;i++) |
---|
1731 | { |
---|
1732 | QTableWidgetItem *ValoraInsertarFila = new QTableWidgetItem(nombreCuenta); |
---|
1733 | ValoraInsertarFila->setTextAlignment(Qt::AlignCenter); |
---|
1734 | ValoraInsertarFila->setFlags(ValoraInsertarFila->flags() ^ Qt::ItemIsEditable); |
---|
1735 | tw->setItem(0,i,ValoraInsertarFila); |
---|
1736 | QTableWidgetItem *ValoraInsertarColumna = new QTableWidgetItem(nombreCuenta); |
---|
1737 | ValoraInsertarColumna->setTextAlignment(Qt::AlignCenter); |
---|
1738 | ValoraInsertarColumna->setFlags(ValoraInsertarColumna->flags() ^ Qt::ItemIsEditable); |
---|
1739 | tw->setItem(i,0,ValoraInsertarColumna); |
---|
1740 | } |
---|
1741 | |
---|
1742 | int espacio=(fin-inicio)+1; |
---|
1743 | if(espacio>1) |
---|
1744 | { |
---|
1745 | tw->setSpan(inicio-1,0,espacio,1); |
---|
1746 | tw->setSpan(0,inicio-1,1,espacio); |
---|
1747 | } |
---|
1748 | } |
---|
1749 | ItemsNoEditable(tw,1,myinicio-1); |
---|
1750 | } |
---|
1751 | |
---|
1752 | /* Funcion para agregar/quitar columnas y filas */ |
---|
1753 | void MainWindow::insertremoveRowCol(QTableWidget *tw, int rowcol, bool opcion) |
---|
1754 | { |
---|
1755 | if(opcion)//Si la opcion es verdadero se agrega |
---|
1756 | { |
---|
1757 | tw->insertRow(rowcol); |
---|
1758 | tw->insertColumn(rowcol); |
---|
1759 | int count = tw->rowCount(); |
---|
1760 | ItemsNoEditable(tw,count-1,count); |
---|
1761 | } |
---|
1762 | else//de lo contrario se remueve |
---|
1763 | { |
---|
1764 | tw->removeColumn(rowcol); |
---|
1765 | tw->removeRow(rowcol); |
---|
1766 | } |
---|
1767 | } |
---|
1768 | |
---|
1769 | /* Funcion para agregar/quitar el separador de miles y la coma en las tablas */ |
---|
1770 | QString MainWindow::Separador(QTableWidgetItem *ti,bool quitar) |
---|
1771 | { |
---|
1772 | QString value=ti->text(); |
---|
1773 | if(quitar) |
---|
1774 | { |
---|
1775 | value.remove(QChar('.')); |
---|
1776 | value.replace(",","."); |
---|
1777 | } |
---|
1778 | else |
---|
1779 | { |
---|
1780 | double val =value.toDouble(); |
---|
1781 | value = numberFormat(val); |
---|
1782 | } |
---|
1783 | return value; |
---|
1784 | } |
---|
1785 | |
---|
1786 | void MainWindow::slotCloseExport() |
---|
1787 | { |
---|
1788 | formExportMatriz->ExportLine->setText(""); |
---|
1789 | formExportMatriz->close(); |
---|
1790 | } |
---|
1791 | |
---|
1792 | void MainWindow::slotSaveExport() |
---|
1793 | { |
---|
1794 | |
---|
1795 | if(formExportMatriz->ExportLine->text().isEmpty()) |
---|
1796 | { |
---|
1797 | QMessageBox::critical(this,"Nombre del Archivo","Debe Colocar un nombre"); |
---|
1798 | } |
---|
1799 | else |
---|
1800 | { |
---|
1801 | QString filename = formExportMatriz->ExportLine->text(); |
---|
1802 | QFile archivo(filename); |
---|
1803 | archivo.open(QFile::WriteOnly | QFile::Text); |
---|
1804 | QTextStream out(&archivo); |
---|
1805 | out << "hola " << "que hace" << "? \n"; |
---|
1806 | out << "otra linea de prueba"; |
---|
1807 | archivo.flush(); |
---|
1808 | archivo.close(); |
---|
1809 | formExportMatriz->ExportLine->setText(""); |
---|
1810 | formExportMatriz->close(); |
---|
1811 | } |
---|
1812 | } |
---|
1813 | |
---|
1814 | void MainWindow::slotSearchExport() |
---|
1815 | { |
---|
1816 | QString format = ".txt"; |
---|
1817 | |
---|
1818 | QString filename = QFileDialog::getSaveFileName(this, |
---|
1819 | "Elija el nombre", QDir::homePath(),"*.txt"); |
---|
1820 | |
---|
1821 | filename +=format; |
---|
1822 | |
---|
1823 | formExportMatriz->Exportcb->addItem(filename); |
---|
1824 | |
---|
1825 | formExportMatriz->ExportLine->setText(filename); |
---|
1826 | qDebug()<< formExportMatriz->ExportLine->text(); |
---|
1827 | |
---|
1828 | } |
---|
1829 | |
---|
1830 | /* Funcion estandar para hacer algunas celdas no editables debido a que son dificiles de manipular(por motivos de colocado y borrado dinamico)*/ |
---|
1831 | void MainWindow::ItemsNoEditable(QTableWidget *tw,int inicio,int fin,int col) |
---|
1832 | { |
---|
1833 | noEditColZero(tw); |
---|
1834 | for(int i=inicio;i<fin;i++) |
---|
1835 | { |
---|
1836 | QTableWidgetItem *ValoraInsertarFila = new QTableWidgetItem; |
---|
1837 | ValoraInsertarFila->setFlags(ValoraInsertarFila->flags() ^ Qt::ItemIsEditable); |
---|
1838 | tw->setItem(i,col,ValoraInsertarFila); |
---|
1839 | QTableWidgetItem *ValoraInsertarColumna = new QTableWidgetItem; |
---|
1840 | ValoraInsertarColumna->setFlags(ValoraInsertarColumna->flags() ^ Qt::ItemIsEditable); |
---|
1841 | tw->setItem(col,i,ValoraInsertarColumna); |
---|
1842 | |
---|
1843 | } |
---|
1844 | } |
---|
1845 | |
---|
1846 | /* Funcion para agregar el estilo de una celda en negrita con fondo de color azul */ |
---|
1847 | void MainWindow::CellStyle(QTableWidgetItem *ti) |
---|
1848 | { |
---|
1849 | ti->setBackgroundColor(QColor(53,140,203)); |
---|
1850 | ti->setTextColor(Qt::white); |
---|
1851 | QFont font; |
---|
1852 | font.setBold(true); |
---|
1853 | ti->setFont(font); |
---|
1854 | } |
---|
1855 | |
---|
1856 | /* Funcion para crear la ventana de los encadenamientos */ |
---|
1857 | void MainWindow::slotEncadenamientos() |
---|
1858 | { |
---|
1859 | if(opcionEncadenamientos == 0) |
---|
1860 | { |
---|
1861 | formEncadenamientos = new FormEncadenamientos(this); |
---|
1862 | QHBoxLayout * layoutLateralWidget = new QHBoxLayout; |
---|
1863 | QVBoxLayout * layoutCentralWidget = new QVBoxLayout; |
---|
1864 | QHBoxLayout * layoutAccounts = new QHBoxLayout; |
---|
1865 | QHBoxLayout * labels = new QHBoxLayout; |
---|
1866 | QLabel *label = new QLabel; |
---|
1867 | label->setText("Encadenamiento por: "); |
---|
1868 | labels->addWidget(label); |
---|
1869 | QWidget *nw = new QWidget; |
---|
1870 | nw->setLayout(labels); |
---|
1871 | QGroupBox * groupBoxAccount = new QGroupBox; |
---|
1872 | layoutCentralWidget->addWidget(nw); |
---|
1873 | /*** Se obtiene el nombre de las cuentas,sus componentes, su inicio y su fin en varias listas ***/ |
---|
1874 | layoutAccounts->addWidget(stackEncadenamiento=new stackEncadenamientos(diccCuentasComponentes,groupBoxAccount)); |
---|
1875 | |
---|
1876 | |
---|
1877 | groupBoxAccount->setObjectName("encadenamientoBoxAcc");//Se le asigna nombre al objeto |
---|
1878 | groupBoxAccount->setLayout(layoutAccounts);; |
---|
1879 | groupBoxAccount->setStyleSheet("QGroupBox {border: 1px solid gray; " |
---|
1880 | "border-radius: 3px; margin-top: 0.5em;} " |
---|
1881 | "QGroupBox::title { subcontrol-origin: margin; " |
---|
1882 | "left: 10px; padding: 0 3px 0 3px; } "); |
---|
1883 | |
---|
1884 | |
---|
1885 | layoutLateralWidget->addWidget(groupBoxAccount); |
---|
1886 | |
---|
1887 | /* Se crea el layout necesario para las etiqueta y radio button */ |
---|
1888 | |
---|
1889 | QVBoxLayout *labelBox = new QVBoxLayout; |
---|
1890 | //Etiqueta |
---|
1891 | QLabel *label2 = new QLabel; |
---|
1892 | label2->setText("Ver Encadenamiento por medio de: "); |
---|
1893 | labelBox->addWidget(label2); |
---|
1894 | QWidget *label2Widget = new QWidget; |
---|
1895 | label2Widget->setLayout(labelBox); |
---|
1896 | |
---|
1897 | QHBoxLayout *radioBox = new QHBoxLayout; |
---|
1898 | //Radio Button |
---|
1899 | QRadioButton *ct = new QRadioButton; |
---|
1900 | ct->setObjectName("CTButton"); |
---|
1901 | QRadioButton *ma = new QRadioButton; |
---|
1902 | ma->setObjectName("MaButton"); |
---|
1903 | ct->setText("Coeficientes Técnicos"); |
---|
1904 | ma->setText("Multiplicadores Leontief"); |
---|
1905 | radioBox->addWidget(ct); |
---|
1906 | radioBox->addWidget(ma); |
---|
1907 | QGroupBox * groupRadio = new QGroupBox; |
---|
1908 | groupRadio->setLayout(radioBox); |
---|
1909 | groupRadio->setStyleSheet("QGroupBox {border: 1px solid gray; " |
---|
1910 | "border-radius: 3px; margin-top: 0.5em;} " |
---|
1911 | "QGroupBox::title { subcontrol-origin: margin; " |
---|
1912 | "left: 10px; padding: 0 3px 0 3px; } "); |
---|
1913 | |
---|
1914 | /*** Se crean y personalizan los bottones para agregar, finalizar, deshacer y cancelar ***/ |
---|
1915 | QPushButton * buttonAgregar = new QPushButton; |
---|
1916 | buttonAgregar->setObjectName("AgregarEncadenamiento");//Se le asigna nombre al objeto |
---|
1917 | buttonAgregar->setText("Agregar"); |
---|
1918 | buttonAgregar->setFixedWidth(130); |
---|
1919 | buttonAgregar->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
1920 | "font-weight: bold; height: 30px; border: none;" |
---|
1921 | "border-radius: 5px; margin-top: 40px;"); |
---|
1922 | QPushButton * buttonCancelar = new QPushButton; |
---|
1923 | buttonCancelar->setObjectName("CancelarEncadenamiento");//Se le asigna nombre al objeto |
---|
1924 | buttonCancelar->setText("Cancelar"); |
---|
1925 | buttonCancelar->setFixedWidth(130); |
---|
1926 | buttonCancelar->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
1927 | "font-weight: bold; height: 30px; border: none;" |
---|
1928 | "border-radius: 5px; margin-top: 40px;"); |
---|
1929 | QPushButton * buttonVer = new QPushButton; |
---|
1930 | buttonVer->setObjectName("VerEncadenamiento");//Se le asigna nombre al objeto |
---|
1931 | buttonVer->setText("Ver"); |
---|
1932 | buttonVer->setFixedWidth(130); |
---|
1933 | buttonVer->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
1934 | "font-weight: bold; height: 30px; border: none;" |
---|
1935 | "border-radius: 5px; margin-top: 40px;"); |
---|
1936 | |
---|
1937 | connect(buttonCancelar,SIGNAL(clicked()),this,SLOT(slotCloseEncadenamiento())); |
---|
1938 | connect(buttonAgregar,SIGNAL(clicked()),this,SLOT(slotAgregarEncadenamiento())); |
---|
1939 | connect(buttonVer,SIGNAL(clicked()),this,SLOT(slotVerEncadenamiento())); |
---|
1940 | |
---|
1941 | QHBoxLayout * layoutsButtons = new QHBoxLayout; |
---|
1942 | layoutsButtons->addWidget(buttonVer); |
---|
1943 | layoutsButtons->addWidget(buttonAgregar); |
---|
1944 | layoutsButtons->addWidget(buttonCancelar); |
---|
1945 | QWidget *buttonWidget = new QWidget; |
---|
1946 | buttonWidget->setLayout(layoutsButtons); |
---|
1947 | |
---|
1948 | QWidget *widget = new QWidget; |
---|
1949 | widget->setLayout(layoutLateralWidget); |
---|
1950 | layoutCentralWidget->addWidget(widget); |
---|
1951 | layoutCentralWidget->addWidget(label2Widget); |
---|
1952 | layoutCentralWidget->addWidget(groupRadio); |
---|
1953 | layoutCentralWidget->addWidget(buttonWidget);//Se agregan los botones |
---|
1954 | formEncadenamientos->setLayout(layoutCentralWidget); |
---|
1955 | formEncadenamientos->show(); |
---|
1956 | opcionEncadenamientos = 1; |
---|
1957 | } |
---|
1958 | else |
---|
1959 | { |
---|
1960 | formEncadenamientos->show(); |
---|
1961 | } |
---|
1962 | } |
---|
1963 | |
---|
1964 | void MainWindow::slotCloseEncadenamiento() |
---|
1965 | { |
---|
1966 | formEncadenamientos->close(); |
---|
1967 | } |
---|
1968 | |
---|
1969 | /* Funcion que crea un diccionario con cuenta/cantidad de veces que se repiten para el espacio de las celdas */ |
---|
1970 | void MainWindow::crearDiccionario(QTableWidget *tw, bool endogena) |
---|
1971 | { |
---|
1972 | QStringList CuentasE; |
---|
1973 | if(endogena) |
---|
1974 | { |
---|
1975 | CuentasE=obtenerCuentasEndogenas(tw,CuentasE); |
---|
1976 | } |
---|
1977 | else |
---|
1978 | { |
---|
1979 | CuentasE=obtenerCuentasExogenas(tw,CuentasE); |
---|
1980 | } |
---|
1981 | QMap <int,QVector<QString> > map; |
---|
1982 | QVector <QString> vector; |
---|
1983 | int cantidad = CuentasE.count(); |
---|
1984 | for(int i=0;i<cantidad;i++) |
---|
1985 | { |
---|
1986 | if(!vector.contains(CuentasE[i])) |
---|
1987 | { |
---|
1988 | vector.append(CuentasE[i]); |
---|
1989 | int count = CuentasE.count(CuentasE[i]); |
---|
1990 | vector.append(QString::number(count)); |
---|
1991 | map.insert(i,vector); |
---|
1992 | } |
---|
1993 | } |
---|
1994 | int longVector = vector.count(); |
---|
1995 | for(int j=0;j<longVector;j+=2) |
---|
1996 | { |
---|
1997 | QVector <QString> vec; |
---|
1998 | vec.append(vector[j]); |
---|
1999 | vec.append(vector[j+1]); |
---|
2000 | if(endogena) |
---|
2001 | { |
---|
2002 | diccCuentasEndogenas.insert(j,vec); |
---|
2003 | } |
---|
2004 | else |
---|
2005 | { |
---|
2006 | espacioCuentasExogenas.insert(j,vec); |
---|
2007 | } |
---|
2008 | vec.clear(); |
---|
2009 | } |
---|
2010 | map.clear(); |
---|
2011 | } |
---|
2012 | |
---|
2013 | /* Crea una lista de las cuentas endogenas s*/ |
---|
2014 | QStringList MainWindow::obtenerCuentasEndogenas(QTableWidget *tw,QStringList list) |
---|
2015 | { |
---|
2016 | int elementos = contarElementosMap(diccCuentasExogenas); |
---|
2017 | int count=tw->rowCount()-2; |
---|
2018 | int inicioExogena; |
---|
2019 | if(opcionCuentaExogena==1) |
---|
2020 | { |
---|
2021 | inicioExogena=count-elementos; |
---|
2022 | } |
---|
2023 | else |
---|
2024 | { |
---|
2025 | inicioExogena=count; |
---|
2026 | } |
---|
2027 | for(int i=3;i<inicioExogena+1;i++) |
---|
2028 | { |
---|
2029 | list.append(tw->item(1,i)->text()); |
---|
2030 | } |
---|
2031 | return list; |
---|
2032 | } |
---|
2033 | |
---|
2034 | /* Crea una lista de las cuentas exogenas */ |
---|
2035 | QStringList MainWindow::obtenerCuentasExogenas(QTableWidget *tw,QStringList list) |
---|
2036 | { |
---|
2037 | int elementos = contarElementosMap(diccCuentasExogenas); |
---|
2038 | int count=tw->rowCount()-2; |
---|
2039 | int inicioExogena; |
---|
2040 | if(opcionCuentaExogena==1) |
---|
2041 | { |
---|
2042 | inicioExogena=count-elementos; |
---|
2043 | } |
---|
2044 | else |
---|
2045 | { |
---|
2046 | inicioExogena=3; |
---|
2047 | } |
---|
2048 | int cantidad = tw->rowCount(); |
---|
2049 | for(int i=inicioExogena+1;i<cantidad-1;i++) |
---|
2050 | { |
---|
2051 | list.append(tw->item(1,i)->text()); |
---|
2052 | } |
---|
2053 | return list; |
---|
2054 | } |
---|
2055 | |
---|
2056 | /* Permite crear los espacios en las celdas de las cuentas en la matriz endogena */ |
---|
2057 | void MainWindow::spanEndogenaCell(QTableWidget *tw,int inicio,int celda,bool endex) |
---|
2058 | { |
---|
2059 | int elementos = contarElementosMap(diccCuentasExogenas); |
---|
2060 | int count=tw->rowCount()-2; |
---|
2061 | int inicioExogena; |
---|
2062 | if(opcionCuentaExogena==1 and endex) |
---|
2063 | { |
---|
2064 | inicioExogena=(count-elementos)+1; |
---|
2065 | } |
---|
2066 | else if(opcionCuentaExogena==1 and !endex) |
---|
2067 | { |
---|
2068 | inicioExogena = tw->rowCount(); |
---|
2069 | } |
---|
2070 | else |
---|
2071 | { |
---|
2072 | inicioExogena=count; |
---|
2073 | } |
---|
2074 | foreach(int key,diccCuentasEndogenas.keys()) |
---|
2075 | { |
---|
2076 | for(int i=inicio;i<inicioExogena;i++) |
---|
2077 | { |
---|
2078 | QString item=tw->item(celda,i)->text(); |
---|
2079 | if(item==diccCuentasEndogenas[key][0]) |
---|
2080 | { |
---|
2081 | //Se centran los elementos |
---|
2082 | QTableWidgetItem *fila = tw->item(celda,i); |
---|
2083 | fila->setTextAlignment(Qt::AlignCenter); |
---|
2084 | QTableWidgetItem *columna = tw->item(i,celda); |
---|
2085 | columna->setTextAlignment(Qt::AlignCenter); |
---|
2086 | //Se obtiene el valor del espacio |
---|
2087 | int espacio = diccCuentasEndogenas[key][1].toInt(); |
---|
2088 | if(espacio>1) |
---|
2089 | { |
---|
2090 | //Se crea el espacio de las cuentas |
---|
2091 | tw->setSpan(celda,i,1,espacio);//Span fila |
---|
2092 | tw->setSpan(i,celda,espacio,1);//Span columna |
---|
2093 | } |
---|
2094 | break; |
---|
2095 | } |
---|
2096 | } |
---|
2097 | } |
---|
2098 | } |
---|
2099 | |
---|
2100 | void MainWindow::spanExogenaCell(QTableWidget *tw,int celda) |
---|
2101 | { |
---|
2102 | int elementos = contarElementosMap(diccCuentasExogenas); |
---|
2103 | int count=tw->rowCount()-1; |
---|
2104 | int inicioExogena; |
---|
2105 | if(opcionCuentaExogena==1) |
---|
2106 | { |
---|
2107 | inicioExogena=count-elementos; |
---|
2108 | } |
---|
2109 | else |
---|
2110 | { |
---|
2111 | inicioExogena=count; |
---|
2112 | } |
---|
2113 | foreach(int key,espacioCuentasExogenas.keys()) |
---|
2114 | { |
---|
2115 | for(int i=inicioExogena;i<count;i++) |
---|
2116 | { |
---|
2117 | QString item=tw->item(celda,i)->text(); |
---|
2118 | if(item==espacioCuentasExogenas[key][0]) |
---|
2119 | { |
---|
2120 | //Se centran los elementos |
---|
2121 | QTableWidgetItem *fila = tw->item(celda,i); |
---|
2122 | fila->setTextAlignment(Qt::AlignCenter); |
---|
2123 | QTableWidgetItem *columna = tw->item(i,celda); |
---|
2124 | columna->setTextAlignment(Qt::AlignCenter); |
---|
2125 | //Se obtiene el valor del espacio |
---|
2126 | int espacio = espacioCuentasExogenas[key][1].toInt(); |
---|
2127 | if(espacio>1) |
---|
2128 | { |
---|
2129 | //Se crea el espacio de las cuentas |
---|
2130 | tw->setSpan(celda,i,1,espacio);//Span fila |
---|
2131 | tw->setSpan(i,celda,espacio,1);//Span columna |
---|
2132 | } |
---|
2133 | break; |
---|
2134 | } |
---|
2135 | } |
---|
2136 | } |
---|
2137 | } |
---|
2138 | |
---|
2139 | /* obtiene un diccionario de cuentas/componentes de la matriz endogena/endogena */ |
---|
2140 | void MainWindow::obtenerCuentaComponentes() |
---|
2141 | { |
---|
2142 | foreach(int key,diccCuentasEndogenas.keys()) |
---|
2143 | { |
---|
2144 | QStringList list; |
---|
2145 | diccCuentasComponentes.insert(diccCuentasEndogenas[key][0],list); |
---|
2146 | } |
---|
2147 | QStringList lista; |
---|
2148 | QTableWidget *tw = findChild<QTableWidget *>("MatrizEndogenaEndogena"); |
---|
2149 | int count = tw->rowCount(); |
---|
2150 | foreach(QString key,diccCuentasComponentes.keys()) |
---|
2151 | { |
---|
2152 | for(int i=2;i<count-1;i++) |
---|
2153 | { |
---|
2154 | QString accTitle = tw->item(i,0)->text(); |
---|
2155 | if(accTitle==key) |
---|
2156 | { |
---|
2157 | lista.append(tw->item(i,1)->text()); |
---|
2158 | } |
---|
2159 | } |
---|
2160 | diccCuentasComponentes[key].append(lista); |
---|
2161 | lista.clear(); |
---|
2162 | } |
---|
2163 | } |
---|
2164 | |
---|
2165 | void MainWindow::slotAgregarEncadenamiento() |
---|
2166 | { |
---|
2167 | QString nombre_cuenta=stackEncadenamiento->comboAccount->currentText();//Se obtiene el nombre de la cuenta seleccionado |
---|
2168 | QListWidget *lw=new QListWidget; |
---|
2169 | int index=stackEncadenamiento->comboAccount->currentIndex();//Se obtiene el indice selecionado |
---|
2170 | lw = findChild<QListWidget *>(QString("encadenamientosAccList %1").arg(index + 1));//Se obtiene la lista seleccionada |
---|
2171 | QStringList componentes_cuenta; |
---|
2172 | |
---|
2173 | if(nombre_cuenta!="Sub-Matriz Endógena-Endógena") |
---|
2174 | { |
---|
2175 | if(!lw->isEnabled()) |
---|
2176 | { |
---|
2177 | QMessageBox::warning(this,"Alerta","La Cuenta Actual ya fue Agregada"); |
---|
2178 | } |
---|
2179 | else if(lw->selectedItems().count()==0) |
---|
2180 | { |
---|
2181 | QMessageBox::warning(this,"Alerta", |
---|
2182 | "Para Agregar la Cuenta debe seleccionar \n al menos un valor"); |
---|
2183 | } |
---|
2184 | else |
---|
2185 | { |
---|
2186 | int contar=lw->selectedItems().count(); |
---|
2187 | for(int i=0;i<contar;i++) |
---|
2188 | { |
---|
2189 | componentes_cuenta.append(lw->selectedItems().value(i)->text()); |
---|
2190 | } |
---|
2191 | lw->setDisabled(true); |
---|
2192 | opcionCuentaEncadenamientos=1;//Se establece un valor para la variable de la opcion |
---|
2193 | diccCuentasEncadenamientos.insert(nombre_cuenta,componentes_cuenta); |
---|
2194 | } |
---|
2195 | } |
---|
2196 | else |
---|
2197 | { |
---|
2198 | int cantidad=stackEncadenamiento->comboAccount->count(); |
---|
2199 | for(int i=0;i<cantidad;i++) |
---|
2200 | { |
---|
2201 | QListWidget *lw=new QListWidget; |
---|
2202 | lw = findChild<QListWidget *>(QString("encadenamientosAccList %1").arg(i + 1));//Se obtiene la lista seleccionada |
---|
2203 | lw->setDisabled(true); |
---|
2204 | opcionCuentaEncadenamientos=2;//Se establece un valor para la variable de la opcion |
---|
2205 | } |
---|
2206 | |
---|
2207 | } |
---|
2208 | |
---|
2209 | } |
---|
2210 | |
---|
2211 | void MainWindow::slotVerEncadenamiento() |
---|
2212 | { |
---|
2213 | QRadioButton *rbCT = findChild<QRadioButton *>("CTButton"); |
---|
2214 | QRadioButton *rbMa = findChild<QRadioButton *>("MaButton"); |
---|
2215 | if(rbCT->isChecked() or rbMa->isChecked()) |
---|
2216 | { |
---|
2217 | int opcion; |
---|
2218 | if(rbCT->isChecked()) |
---|
2219 | { |
---|
2220 | opcion=0; |
---|
2221 | } |
---|
2222 | else |
---|
2223 | { |
---|
2224 | opcion=1; |
---|
2225 | } |
---|
2226 | if(opcionCuentaEncadenamientos==1)//Opcion para encadenar por coeficientes tecnicos/multiplicadores de leontief |
---|
2227 | { |
---|
2228 | QTableWidget *tw; |
---|
2229 | if(opcion==0) |
---|
2230 | { |
---|
2231 | tw= findChild<QTableWidget *>("MatrizAn"); |
---|
2232 | } |
---|
2233 | else |
---|
2234 | { |
---|
2235 | tw = findChild<QTableWidget *>("MatrizMa"); |
---|
2236 | } |
---|
2237 | QTableWidget *enTable = new QTableWidget; |
---|
2238 | crearMatrizEncadenamiento(tw,enTable);//Se llama a la funcion que realiza todo el procedimiento |
---|
2239 | tabWidget->addTab(new QWidget,QString("Encadenamiento %1").arg(cantidadEncadenamientos)); |
---|
2240 | int indice=ObtenerIndice(QString("Encadenamiento %1").arg(cantidadEncadenamientos));//Se obtiene el indice de la pestaña |
---|
2241 | cantidadEncadenamientos++; |
---|
2242 | QHBoxLayout * layoutCentralWidget = new QHBoxLayout; |
---|
2243 | layoutCentralWidget->addWidget(enTable); |
---|
2244 | QWidget *widget = tabWidget->widget(indice); |
---|
2245 | widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada |
---|
2246 | formEncadenamientos->close(); |
---|
2247 | |
---|
2248 | } |
---|
2249 | else if (opcionCuentaEncadenamientos==2)//opcion para encadenar por la matriz endogena-endogena |
---|
2250 | { |
---|
2251 | QTableWidget *tw; |
---|
2252 | if(opcion==0) |
---|
2253 | { |
---|
2254 | tw= findChild<QTableWidget *>("MatrizAn"); |
---|
2255 | } |
---|
2256 | else |
---|
2257 | { |
---|
2258 | tw = findChild<QTableWidget *>("MatrizMa"); |
---|
2259 | } |
---|
2260 | QTableWidget *enTable = new QTableWidget; |
---|
2261 | crearMatrizEncadenamientoEndogena(tw,enTable);//Se llama a la funcion que realiza todo el procedimiento |
---|
2262 | tabWidget->addTab(new QWidget,QString("Encadenamiento %1").arg(cantidadEncadenamientos)); |
---|
2263 | int indice=ObtenerIndice(QString("Encadenamiento %1").arg(cantidadEncadenamientos));//Se obtiene el indice de la pestaña |
---|
2264 | cantidadEncadenamientos++; |
---|
2265 | QHBoxLayout * layoutCentralWidget = new QHBoxLayout; |
---|
2266 | layoutCentralWidget->addWidget(enTable); |
---|
2267 | QWidget *widget = tabWidget->widget(indice); |
---|
2268 | widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada |
---|
2269 | formEncadenamientos->close(); |
---|
2270 | |
---|
2271 | } |
---|
2272 | else |
---|
2273 | { |
---|
2274 | QMessageBox::warning(this,"Alerta","No Agregó ninguna cuenta"); |
---|
2275 | } |
---|
2276 | } |
---|
2277 | else |
---|
2278 | { |
---|
2279 | QMessageBox::warning(this,"Alerta","No seleccionó ninguna matriz \npara visualizar el encadenamiento"); |
---|
2280 | } |
---|
2281 | } |
---|
2282 | |
---|
2283 | /* Funcion para crear una tabla vacia, específicamente para los encadenamientos */ |
---|
2284 | void MainWindow::crearTablaVaciaEncadenamiento(int contador, QTableWidget *tw) |
---|
2285 | { |
---|
2286 | for(int j=0;j<3;j++) |
---|
2287 | { |
---|
2288 | tw->insertColumn(0); |
---|
2289 | } |
---|
2290 | for(int k=0;k<contador;k++) |
---|
2291 | { |
---|
2292 | tw->insertRow(k); |
---|
2293 | } |
---|
2294 | } |
---|
2295 | |
---|
2296 | /* Funcion para crear la tabla con los encadenamientos */ |
---|
2297 | void MainWindow::crearMatrizEncadenamiento(QTableWidget *tw,QTableWidget *enTable) |
---|
2298 | { |
---|
2299 | int countEndogena = tw->rowCount(); |
---|
2300 | int elementos = contarElementosMap(diccCuentasEncadenamientos); |
---|
2301 | crearTablaVaciaEncadenamiento(elementos,enTable); |
---|
2302 | int columna=0; |
---|
2303 | foreach(QString key,diccCuentasEncadenamientos.keys()) |
---|
2304 | { |
---|
2305 | for(int j=2;j<countEndogena;j++) |
---|
2306 | { |
---|
2307 | QString titulo =tw->item(0,j)->text(); |
---|
2308 | QString componente = tw->item(1,j)->text(); |
---|
2309 | double sumaColumna = 0; |
---|
2310 | double sumaFila = 0; |
---|
2311 | if(titulo==key) |
---|
2312 | { |
---|
2313 | foreach(QString valor,diccCuentasEncadenamientos[key]) |
---|
2314 | { |
---|
2315 | if(componente==valor) |
---|
2316 | { |
---|
2317 | for(int k=2;k<countEndogena;k++) |
---|
2318 | { |
---|
2319 | double EncadenamientoAtras = tw->item(k,j)->text().toDouble();//Suma Columna(Encadenamiento hacia atras) |
---|
2320 | sumaColumna+=EncadenamientoAtras; |
---|
2321 | double EncadenamientoAdelante = tw->item(j,k)->text().toDouble();//Suma Fila(Encadenamiento hacia adelante) |
---|
2322 | sumaFila+=EncadenamientoAdelante; |
---|
2323 | } |
---|
2324 | //Titulo basado en cuenta/componente |
---|
2325 | QTableWidgetItem *title = new QTableWidgetItem; |
---|
2326 | QFont font; |
---|
2327 | font.setBold(true); |
---|
2328 | title->setFont(font); |
---|
2329 | title->setText(QString("<b>Cuenta:</b> %1\n<b>Componente:</b> %2").arg(key,valor)); |
---|
2330 | title->setFlags(title->flags() ^ Qt::ItemIsEditable); |
---|
2331 | enTable->setItem(columna,0,title); |
---|
2332 | //Elementos del encadenamiento hacia atras |
---|
2333 | QTableWidgetItem *valorAtras = new QTableWidgetItem(QString::number(sumaColumna,'f',2)); |
---|
2334 | QString value = Separador(valorAtras,false); |
---|
2335 | valorAtras->setText(value); |
---|
2336 | valorAtras->setFlags(valorAtras->flags() ^ Qt::ItemIsEditable); |
---|
2337 | valorAtras->setTextAlignment(Qt::AlignCenter); |
---|
2338 | enTable->setItem(columna,1,valorAtras); |
---|
2339 | //Elementos del encadenamiento hacia adelante |
---|
2340 | QTableWidgetItem *valorAdelante = new QTableWidgetItem(QString::number(sumaFila,'f',2)); |
---|
2341 | value = Separador(valorAdelante,false); |
---|
2342 | valorAdelante->setText(value); |
---|
2343 | valorAdelante->setFlags(valorAdelante->flags() ^ Qt::ItemIsEditable); |
---|
2344 | valorAdelante->setTextAlignment(Qt::AlignCenter); |
---|
2345 | enTable->setItem(columna,2,valorAdelante); |
---|
2346 | columna++; |
---|
2347 | } |
---|
2348 | } |
---|
2349 | } |
---|
2350 | } |
---|
2351 | } |
---|
2352 | //Se agregan los titulos |
---|
2353 | enTable->insertRow(0); |
---|
2354 | QTableWidgetItem *encAtras = new QTableWidgetItem("Encadenamiento Parcial\nhacia atrás"); |
---|
2355 | encademientosStyle(encAtras); |
---|
2356 | QTableWidgetItem *encAdelante = new QTableWidgetItem("Encadenamiento Parcial\nhacia adelante"); |
---|
2357 | encademientosStyle(encAdelante); |
---|
2358 | enTable->setItem(0,1,encAtras); |
---|
2359 | enTable->setItem(0,2,encAdelante); |
---|
2360 | noEditColZero(enTable); |
---|
2361 | //Se agregan los totales |
---|
2362 | calcularTotalesEncadenamientos(enTable); |
---|
2363 | //Se auto ajustan las tablas al contenido |
---|
2364 | enTable->resizeRowsToContents(); |
---|
2365 | enTable->resizeColumnsToContents(); |
---|
2366 | //Se desbloquean las listas para proximos encadenamientos |
---|
2367 | int count = diccCuentasComponentes.count(); |
---|
2368 | for(int i=0;i<count;i++) |
---|
2369 | { |
---|
2370 | QListWidget *lw=new QListWidget; |
---|
2371 | lw = findChild<QListWidget *>(QString("encadenamientosAccList %1").arg(i + 1)); |
---|
2372 | lw->setEnabled(true); |
---|
2373 | } |
---|
2374 | } |
---|
2375 | |
---|
2376 | /* Funcion para crear los encadenamientos de toda la matrix endógena-endógena */ |
---|
2377 | void MainWindow::crearMatrizEncadenamientoEndogena(QTableWidget *tw,QTableWidget *enTable) |
---|
2378 | { |
---|
2379 | int countEndogena = tw->rowCount(); |
---|
2380 | crearTablaVaciaEncadenamiento(countEndogena-2,enTable); |
---|
2381 | int columna=0; |
---|
2382 | for(int i=2;i<countEndogena;i++) |
---|
2383 | { |
---|
2384 | double sumaColumna = 0; |
---|
2385 | double sumaFila = 0; |
---|
2386 | for(int j=2;j<countEndogena;j++) |
---|
2387 | { |
---|
2388 | double EncadenamientoAtras = tw->item(j,i)->text().toDouble();//Suma Columna(Encadenamiento hacia atras) |
---|
2389 | sumaColumna+=EncadenamientoAtras; |
---|
2390 | double EncadenamientoAdelante = tw->item(i,j)->text().toDouble();//Suma Fila(Encadenamiento hacia adelante) |
---|
2391 | sumaFila+=EncadenamientoAdelante; |
---|
2392 | } |
---|
2393 | //Titulo basado en cuenta/componente |
---|
2394 | QString cuenta = tw->item(0,i)->text(); |
---|
2395 | QString componente = tw->item(1,i)->text(); |
---|
2396 | QTableWidgetItem *title = new QTableWidgetItem; |
---|
2397 | QFont font; |
---|
2398 | font.setBold(true); |
---|
2399 | title->setFont(font); |
---|
2400 | title->setText(QString("Cuenta: %1\nComponente: %2").arg(cuenta,componente)); |
---|
2401 | title->setFlags(title->flags() ^ Qt::ItemIsEditable); |
---|
2402 | enTable->setItem(columna,0,title); |
---|
2403 | //Elementos del encadenamiento hacia atras |
---|
2404 | QTableWidgetItem *valorAtras = new QTableWidgetItem(QString::number(sumaColumna,'f',2)); |
---|
2405 | QString value = Separador(valorAtras,false); |
---|
2406 | valorAtras->setText(value); |
---|
2407 | valorAtras->setFlags(valorAtras->flags() ^ Qt::ItemIsEditable); |
---|
2408 | valorAtras->setTextAlignment(Qt::AlignCenter); |
---|
2409 | enTable->setItem(columna,1,valorAtras); |
---|
2410 | //Elementos del encadenamiento hacia adelante |
---|
2411 | QTableWidgetItem *valorAdelante = new QTableWidgetItem(QString::number(sumaFila,'f',2)); |
---|
2412 | value = Separador(valorAdelante,false); |
---|
2413 | valorAdelante->setText(value); |
---|
2414 | valorAdelante->setFlags(valorAdelante->flags() ^ Qt::ItemIsEditable); |
---|
2415 | valorAdelante->setTextAlignment(Qt::AlignCenter); |
---|
2416 | enTable->setItem(columna,2,valorAdelante); |
---|
2417 | columna++; |
---|
2418 | } |
---|
2419 | //Se agregan los titulos |
---|
2420 | enTable->insertRow(0); |
---|
2421 | QTableWidgetItem *encAtras = new QTableWidgetItem("Encadenamiento Parcial\nhacia atrás"); |
---|
2422 | encademientosStyle(encAtras); |
---|
2423 | QTableWidgetItem *encAdelante = new QTableWidgetItem("Encadenamiento Parcial\nhacia adelante"); |
---|
2424 | encademientosStyle(encAdelante); |
---|
2425 | enTable->setItem(0,1,encAtras); |
---|
2426 | enTable->setItem(0,2,encAdelante); |
---|
2427 | noEditColZero(enTable); |
---|
2428 | //Se agregan los totales |
---|
2429 | calcularTotalesEncadenamientos(enTable); |
---|
2430 | //Se auto ajustan las tablas al contenido |
---|
2431 | enTable->resizeRowsToContents(); |
---|
2432 | enTable->resizeColumnsToContents(); |
---|
2433 | int count = diccCuentasComponentes.count(); |
---|
2434 | for(int i=0;i<count;i++) |
---|
2435 | { |
---|
2436 | QListWidget *lw=new QListWidget; |
---|
2437 | lw = findChild<QListWidget *>(QString("encadenamientosAccList %1").arg(i + 1)); |
---|
2438 | lw->setEnabled(true); |
---|
2439 | } |
---|
2440 | } |
---|
2441 | |
---|
2442 | /* Funcion para agregar los estilos de la tabla de encadenamientos */ |
---|
2443 | void MainWindow::encademientosStyle(QTableWidgetItem *ti) |
---|
2444 | { |
---|
2445 | QFont font; |
---|
2446 | font.setBold(true); |
---|
2447 | ti->setFont(font); |
---|
2448 | ti->setFlags(ti->flags() ^ Qt::ItemIsEditable); |
---|
2449 | ti->setTextAlignment(Qt::AlignCenter); |
---|
2450 | } |
---|
2451 | |
---|
2452 | /* Funcion para agregar los totales en la matriz de encadenamientos */ |
---|
2453 | void MainWindow::calcularTotalesEncadenamientos(QTableWidget *tw) |
---|
2454 | { |
---|
2455 | int count = tw->rowCount(); |
---|
2456 | double sumaAdelante=0; |
---|
2457 | double sumaAtras=0; |
---|
2458 | //Se realizan los calculos |
---|
2459 | for(int i=1;i<count;i++) |
---|
2460 | { |
---|
2461 | QString stringAtras = Separador(tw->item(i,1),true); |
---|
2462 | double itemAtras = stringAtras.toDouble(); |
---|
2463 | sumaAtras+=itemAtras; |
---|
2464 | QString stringAdelante = Separador(tw->item(i,2),true); |
---|
2465 | double itemAdelante = stringAdelante.toDouble(); |
---|
2466 | sumaAdelante+=itemAdelante; |
---|
2467 | } |
---|
2468 | //Se inserta la fila donde iran los totales |
---|
2469 | tw->insertRow(count); |
---|
2470 | //Se insertan las celdas con los respectivos valores totales |
---|
2471 | QTableWidgetItem *titulo = new QTableWidgetItem("Encadenamiento Parcial, Total"); |
---|
2472 | encademientosStyle(titulo); |
---|
2473 | tw->setItem(count,0,titulo); |
---|
2474 | QTableWidgetItem *totalAtras = new QTableWidgetItem(QString::number(sumaAtras,'f',2)); |
---|
2475 | QString value = Separador(totalAtras,false); |
---|
2476 | totalAtras->setText(value); |
---|
2477 | encademientosStyle(totalAtras); |
---|
2478 | QTableWidgetItem *totalAdelante = new QTableWidgetItem(QString::number(sumaAdelante,'f',2)); |
---|
2479 | value = Separador(totalAdelante,false); |
---|
2480 | totalAdelante->setText(value); |
---|
2481 | encademientosStyle(totalAdelante); |
---|
2482 | tw->setItem(count,1,totalAtras); |
---|
2483 | tw->setItem(count,2,totalAdelante); |
---|
2484 | } |
---|