1 | #include "mainwindow.H" |
---|
2 | #include "accountwidget.H" |
---|
3 | #include "stackvariablesexogenas.h" |
---|
4 | #include <QDebug> |
---|
5 | #include <armadillo> |
---|
6 | |
---|
7 | using namespace arma; |
---|
8 | |
---|
9 | void MainWindow::slotLoadMatrix() |
---|
10 | { |
---|
11 | formLoadMatrix = new FormLoadMatrix(this); |
---|
12 | formLoadMatrix->show(); |
---|
13 | connect(formLoadMatrix, SIGNAL(formAccepted(QString,int,char)), |
---|
14 | this, SLOT(slotFormLoadMatrixAccepted(QString,int,char))); |
---|
15 | } |
---|
16 | void MainWindow::slotExportMatrix() |
---|
17 | { |
---|
18 | QMessageBox::warning(this,"Warning", "Opcion en desarrollo", |
---|
19 | QMessageBox::Ok); |
---|
20 | } |
---|
21 | void MainWindow::closeEvent(QCloseEvent * event) |
---|
22 | { |
---|
23 | if(QMessageBox::question(this, "Warning", "Are you sure?", |
---|
24 | QMessageBox::Yes | QMessageBox::No) == |
---|
25 | QMessageBox::No) |
---|
26 | { |
---|
27 | event->ignore(); |
---|
28 | } |
---|
29 | } |
---|
30 | |
---|
31 | void MainWindow::initGUI() |
---|
32 | { |
---|
33 | createMenuBar(); |
---|
34 | createCentralWidget(); |
---|
35 | } |
---|
36 | |
---|
37 | void MainWindow::createCentralWidget() |
---|
38 | { |
---|
39 | QVBoxLayout * layoutCentralWidget = new QVBoxLayout; |
---|
40 | |
---|
41 | QHBoxLayout * layoutTitle = new QHBoxLayout; |
---|
42 | QLabel * lblTitle = new QLabel("Estructura de la Matriz de " \ |
---|
43 | "Contabilidad Social"); |
---|
44 | lblTitle->setFont(QFont("Aero Matics", 25, 1)); |
---|
45 | lblTitle->setAlignment(Qt::AlignCenter | Qt::AlignBottom); |
---|
46 | layoutTitle->addWidget(lblTitle); |
---|
47 | layoutCentralWidget->addLayout(layoutTitle); |
---|
48 | |
---|
49 | QHBoxLayout * layoutMatrix = new QHBoxLayout; |
---|
50 | QLabel * lblMatrix = new QLabel; |
---|
51 | lblMatrix->setAlignment(Qt::AlignCenter); |
---|
52 | lblMatrix->setPixmap(QPixmap("./img/Imagen-matriz.png")); |
---|
53 | layoutMatrix->addWidget(lblMatrix); |
---|
54 | layoutCentralWidget->addLayout(layoutMatrix); |
---|
55 | |
---|
56 | QHBoxLayout * layoutFoot = new QHBoxLayout; |
---|
57 | QLabel * lblFoot = new QLabel("Fundación Centro Nacional de Desarrollo e" \ |
---|
58 | " Investigación en\nTecnologías Libres." \ |
---|
59 | " Nodo Mérida."); |
---|
60 | lblFoot->setFont(QFont("Aero Matics", 19, 1)); |
---|
61 | lblFoot->setAlignment(Qt::AlignRight | Qt::AlignBottom); |
---|
62 | QLabel * lblLogo = new QLabel; |
---|
63 | lblLogo->setPixmap(QPixmap("./img/logo_cenditel.jpg")); |
---|
64 | lblLogo->setFixedWidth(lblLogo->pixmap()->width()); |
---|
65 | lblLogo->setAlignment(Qt::AlignRight | Qt::AlignBottom); |
---|
66 | layoutFoot->addWidget(lblFoot); |
---|
67 | layoutFoot->addWidget(lblLogo); |
---|
68 | layoutCentralWidget->addLayout(layoutFoot); |
---|
69 | |
---|
70 | tabWidget->addTab(new QWidget,"Inicio"); |
---|
71 | setCentralWidget(tabWidget); |
---|
72 | QWidget *widget=tabWidget->widget(0); |
---|
73 | widget->setLayout(layoutCentralWidget); |
---|
74 | |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | void MainWindow::createMenuBar() |
---|
79 | { |
---|
80 | menuFile.setTitle("&Archivo"); |
---|
81 | |
---|
82 | actionLoadMatrix.setText("&Cargar Matriz"); |
---|
83 | menuFile.addAction(&actionLoadMatrix); |
---|
84 | |
---|
85 | actionExportMatrix.setText("&Exportar Matriz"); |
---|
86 | menuFile.addAction(&actionExportMatrix); |
---|
87 | actionExportMatrix.setDisabled(true); |
---|
88 | |
---|
89 | actionQuit.setText("&Salir"); |
---|
90 | menuFile.addAction(&actionQuit); |
---|
91 | |
---|
92 | |
---|
93 | menuBar()->addMenu(&menuFile); |
---|
94 | } |
---|
95 | |
---|
96 | void MainWindow::matricesMenuBar() |
---|
97 | { |
---|
98 | OpMatrices.setTitle("&Herramientas"); |
---|
99 | |
---|
100 | actionCH.setText("Coeficientes &Horizontales"); |
---|
101 | actionCH.setDisabled(true); |
---|
102 | OpMatrices.addAction(&actionCH); |
---|
103 | |
---|
104 | actionCV.setText("Coeficientes &Verticales"); |
---|
105 | actionCV.setDisabled(true); |
---|
106 | OpMatrices.addAction(&actionCV); |
---|
107 | |
---|
108 | EndoExo.setTitle("Variables &Exogenas"); |
---|
109 | |
---|
110 | actionVariableExogena.setText("Definir Variables &Exogenas"); |
---|
111 | actionVariableExogena.setDisabled(true); |
---|
112 | EndoExo.addAction(&actionVariableExogena); |
---|
113 | |
---|
114 | actionAn.setText("Coeficientes &Horizontales"); |
---|
115 | actionAn.setDisabled(true); |
---|
116 | EndoExo.addAction(&actionAn); |
---|
117 | |
---|
118 | actionLa.setText("Multiplicadores de &Leontief"); |
---|
119 | actionLa.setDisabled(true); |
---|
120 | EndoExo.addAction(&actionLa); |
---|
121 | |
---|
122 | OpMatrices.addMenu(&EndoExo); |
---|
123 | |
---|
124 | actionEncadenamiento.setText("Encadenamientos"); |
---|
125 | actionEncadenamiento.setDisabled(true); |
---|
126 | OpMatrices.addAction(&actionEncadenamiento); |
---|
127 | |
---|
128 | |
---|
129 | menuBar()->addMenu(&OpMatrices); |
---|
130 | } |
---|
131 | |
---|
132 | MainWindow::MainWindow() |
---|
133 | : actionLoadMatrix(this), actionExportMatrix(this), actionQuit(this),actionCH(this), actionCV(this), |
---|
134 | actionVariableExogena(this),actionAn(this),actionLa(this),actionEncadenamiento(this), formLoadMatrix(0) |
---|
135 | { |
---|
136 | tabWidget = new QTabWidget; |
---|
137 | initGUI(); |
---|
138 | |
---|
139 | connect(&actionLoadMatrix, SIGNAL(triggered()), this, |
---|
140 | SLOT(slotLoadMatrix())); |
---|
141 | connect(&actionExportMatrix, SIGNAL(triggered()), this, |
---|
142 | SLOT(slotExportMatrix())); |
---|
143 | connect(&actionQuit, SIGNAL(triggered()), this, SLOT(close())); |
---|
144 | |
---|
145 | showMaximized(); |
---|
146 | } |
---|
147 | |
---|
148 | void MainWindow::slotFormLoadMatrixAccepted(const QString & filePath, |
---|
149 | int accountNumber, char sep) |
---|
150 | { |
---|
151 | QString msg = "Archivo: " + filePath + "\nNúmero de cuentas: " + |
---|
152 | QString().setNum(accountNumber) + |
---|
153 | "\nSeparador: " + sep; |
---|
154 | |
---|
155 | csvFilePath = filePath; |
---|
156 | csvSeparator = sep; |
---|
157 | numAccounts = accountNumber; |
---|
158 | |
---|
159 | createMatrixCentralWidget(); |
---|
160 | } |
---|
161 | |
---|
162 | void MainWindow::slotFormLoadMatrixClosed() |
---|
163 | { |
---|
164 | disconnect(formLoadMatrix, SIGNAL(formAccepted(QString,int,char)), |
---|
165 | this, SLOT(slotFormLoadMatrixAccepted(QString,int,char))); |
---|
166 | formLoadMatrix = 0; |
---|
167 | } |
---|
168 | |
---|
169 | void MainWindow::slotVariableExogena() |
---|
170 | { |
---|
171 | if(opcionVentanaExogena==0) |
---|
172 | { |
---|
173 | formVariablesExogenas = new FormVariablesExogenas(this); |
---|
174 | QHBoxLayout * layoutLateralWidget = new QHBoxLayout; |
---|
175 | QVBoxLayout * layoutCentralWidget = new QVBoxLayout; |
---|
176 | QHBoxLayout * layoutAccounts = new QHBoxLayout; |
---|
177 | QHBoxLayout * labels = new QHBoxLayout; |
---|
178 | QLabel *label1 = new QLabel; |
---|
179 | QLabel *label2 = new QLabel; |
---|
180 | label1->setText("Cuentas"); |
---|
181 | label2->setText("Componentes"); |
---|
182 | labels->addWidget(label1); |
---|
183 | labels->addWidget(label2); |
---|
184 | QWidget *nw = new QWidget; |
---|
185 | nw->setLayout(labels); |
---|
186 | QGroupBox * groupBoxAccount = new QGroupBox; |
---|
187 | layoutCentralWidget->addWidget(nw); |
---|
188 | /*** Se obtiene la cantidad de cuentas ***/ |
---|
189 | StackWidget *sw = findChild<StackWidget *>(""); |
---|
190 | int cantidad=sw->comboAccount->count(); |
---|
191 | QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal"); |
---|
192 | /*** Se obtiene el nombre de las cuentas,sus componentes, su inicio y su fin en varias listas ***/ |
---|
193 | insertremoveRowCol(tw,0,false); |
---|
194 | QStringList Lista = ObtenerNombreCuenta(cantidad); |
---|
195 | QStringList Componentes = ObtenerComponentes(tw); |
---|
196 | QList <int> inicio = ObtenerLimitesCuenta(cantidad,0); |
---|
197 | QList <int> fin = ObtenerLimitesCuenta(cantidad,1); |
---|
198 | layoutAccounts->addWidget(stackVE=new stackVariablesExogenas(Lista,Componentes,inicio,fin,groupBoxAccount,cantidad)); |
---|
199 | insertremoveRowCol(tw,0,true); |
---|
200 | setAccountTitle(tw); |
---|
201 | |
---|
202 | groupBoxAccount->setObjectName("exogenasBoxAccount");//Se le asigna nombre al objeto |
---|
203 | groupBoxAccount->setLayout(layoutAccounts);; |
---|
204 | groupBoxAccount->setStyleSheet("QGroupBox {border: 1px solid gray; " |
---|
205 | "border-radius: 3px; margin-top: 0.5em;} " |
---|
206 | "QGroupBox::title { subcontrol-origin: margin; " |
---|
207 | "left: 10px; padding: 0 3px 0 3px; } "); |
---|
208 | |
---|
209 | |
---|
210 | layoutLateralWidget->addWidget(groupBoxAccount); |
---|
211 | |
---|
212 | /*** Se crean y personalizan los bottones para agregar, finalizar, deshacer y cancelar ***/ |
---|
213 | QPushButton * buttonAgregar = new QPushButton; |
---|
214 | buttonAgregar->setObjectName("AgregarExogena");//Se le asigna nombre al objeto |
---|
215 | buttonAgregar->setText("Agregar"); |
---|
216 | buttonAgregar->setFixedWidth(130); |
---|
217 | buttonAgregar->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
218 | "font-weight: bold; height: 30px; border: none;" |
---|
219 | "border-radius: 5px; margin-top: 40px;"); |
---|
220 | QPushButton * buttonCancelar = new QPushButton; |
---|
221 | buttonCancelar->setObjectName("CancelarExogena");//Se le asigna nombre al objeto |
---|
222 | buttonCancelar->setText("Cancelar"); |
---|
223 | buttonCancelar->setFixedWidth(130); |
---|
224 | buttonCancelar->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
225 | "font-weight: bold; height: 30px; border: none;" |
---|
226 | "border-radius: 5px; margin-top: 40px;"); |
---|
227 | QPushButton * buttonFinalizar = new QPushButton; |
---|
228 | buttonFinalizar->setObjectName("FinalizarExogena");//Se le asigna nombre al objeto |
---|
229 | buttonFinalizar->setText("Finalizar"); |
---|
230 | buttonFinalizar->setFixedWidth(130); |
---|
231 | buttonFinalizar->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
232 | "font-weight: bold; height: 30px; border: none;" |
---|
233 | "border-radius: 5px; margin-top: 40px;"); |
---|
234 | QPushButton * buttonDeshacer = new QPushButton; |
---|
235 | buttonDeshacer->setObjectName("DeshacerExogena");//Se le asigna nombre al objeto |
---|
236 | buttonDeshacer->setText("Deshacer"); |
---|
237 | buttonDeshacer->setFixedWidth(130); |
---|
238 | buttonDeshacer->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
239 | "font-weight: bold; height: 30px; border: none;" |
---|
240 | "border-radius: 5px; margin-top: 40px;"); |
---|
241 | |
---|
242 | connect(buttonCancelar,SIGNAL(clicked()),this,SLOT(slotCloseExogena())); |
---|
243 | connect(buttonAgregar,SIGNAL(clicked()),this,SLOT(slotAgregarExogena())); |
---|
244 | connect(buttonFinalizar,SIGNAL(clicked()),this,SLOT(slotFinalizarExogena())); |
---|
245 | connect(buttonDeshacer,SIGNAL(clicked()),this,SLOT(slotDeshacerExogena())); |
---|
246 | |
---|
247 | |
---|
248 | QHBoxLayout * layoutsButtons = new QHBoxLayout; |
---|
249 | layoutsButtons->addWidget(buttonFinalizar); |
---|
250 | layoutsButtons->addWidget(buttonAgregar); |
---|
251 | layoutsButtons->addWidget(buttonDeshacer); |
---|
252 | layoutsButtons->addWidget(buttonCancelar); |
---|
253 | QWidget *buttonWidget = new QWidget; |
---|
254 | buttonWidget->setLayout(layoutsButtons); |
---|
255 | |
---|
256 | QWidget *widget = new QWidget; |
---|
257 | widget->setLayout(layoutLateralWidget); |
---|
258 | layoutCentralWidget->addWidget(widget); |
---|
259 | layoutCentralWidget->addWidget(buttonWidget);//Se agregan los botones |
---|
260 | formVariablesExogenas->setLayout(layoutCentralWidget); |
---|
261 | formVariablesExogenas->show(); |
---|
262 | opcionVentanaExogena=1; |
---|
263 | } |
---|
264 | else |
---|
265 | { |
---|
266 | formVariablesExogenas->show(); |
---|
267 | } |
---|
268 | } |
---|
269 | |
---|
270 | |
---|
271 | void MainWindow::slotCoeficienteHorizontal() |
---|
272 | { |
---|
273 | actionCH.setDisabled(true); |
---|
274 | tabWidget->addTab(new QWidget,"CT_Horizontal"); |
---|
275 | QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal"); |
---|
276 | |
---|
277 | /* Se eliminan la fila y columna (0,0) para los calculos*/ |
---|
278 | insertremoveRowCol(tw,0,false); |
---|
279 | |
---|
280 | QTableWidget *CT_HorizontalTW = new QTableWidget; |
---|
281 | int count=tw->rowCount(); |
---|
282 | CrearTablaVacia(count,CT_HorizontalTW);//Se crea una tabla vacia |
---|
283 | /* **** Se coloca como no editable la celda(0,0) ***** */ |
---|
284 | noEditColZero(CT_HorizontalTW); |
---|
285 | /***** Se llena la tabla vacia con los valores de la tabla principal ****/ |
---|
286 | |
---|
287 | CalcularAn(tw,CT_HorizontalTW,count,false);//Funcion para calcular el Coeficiente Tecnico Horizontal (An) |
---|
288 | |
---|
289 | /* Se agrega la columna y fila (0,0) y se insertan los titulos de las cuentas */ |
---|
290 | insertremoveRowCol(tw,0,true); |
---|
291 | insertremoveRowCol(CT_HorizontalTW,0,true); |
---|
292 | setAccountTitle(tw); |
---|
293 | setAccountTitle(CT_HorizontalTW); |
---|
294 | |
---|
295 | int indice=ObtenerIndice("CT_Horizontal");//Se obtiene el indice de la pestaña |
---|
296 | QHBoxLayout * layoutCentralWidget = new QHBoxLayout; |
---|
297 | layoutCentralWidget->addWidget(CT_HorizontalTW); |
---|
298 | QWidget *widget = tabWidget->widget(indice); |
---|
299 | widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada |
---|
300 | |
---|
301 | } |
---|
302 | |
---|
303 | void MainWindow::slotCoeficienteVertical() |
---|
304 | { |
---|
305 | actionCV.setDisabled(true); |
---|
306 | tabWidget->addTab(new QWidget,"CT_Vertical"); |
---|
307 | QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal"); |
---|
308 | |
---|
309 | /* Se eliminan la fila y columna (0,0) para los calculos*/ |
---|
310 | insertremoveRowCol(tw,0,false); |
---|
311 | |
---|
312 | int count=tw->rowCount(); |
---|
313 | QTableWidget *CT_VerticalTW = new QTableWidget; |
---|
314 | CrearTablaVacia(count,CT_VerticalTW); //Se Crea la tabla vacia |
---|
315 | /* **** Se coloca como no editable la celda(0,0) ***** */ |
---|
316 | noEditColZero(CT_VerticalTW); |
---|
317 | /***** Se llena la tabla vacia con los valores de la tabla principal ****/ |
---|
318 | for(int i=0;i<count-1;i++) |
---|
319 | { |
---|
320 | double total=tw->item(count-1,i)->text().toDouble();//Se obtiene el total de esa columna |
---|
321 | for(int j=0;j<count-1;j++) |
---|
322 | { |
---|
323 | if(i!=0 && j!=0) |
---|
324 | { |
---|
325 | double valor=tw->item(j,i)->text().toDouble(); |
---|
326 | if(total==0)//Se comprueba en caso de que el total sea zero |
---|
327 | { |
---|
328 | valor=0; |
---|
329 | } |
---|
330 | else |
---|
331 | { |
---|
332 | valor/=total;//Se divide el valor de la celda entre el total correspondiente |
---|
333 | } |
---|
334 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(QString::number(valor,'f',4)); |
---|
335 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
336 | CT_VerticalTW->setItem(j,i,ValoraInsertar); |
---|
337 | } |
---|
338 | /**** En este else se llenan las celdas con fila y columna 0, es decir las que tienen nombre *****/ |
---|
339 | else if((i==0 && j>0)||(j==0 && i>0)) |
---|
340 | { |
---|
341 | QString value=tw->item(j,i)->text(); |
---|
342 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(value); |
---|
343 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
344 | CT_VerticalTW->setItem(j,i,ValoraInsertar); |
---|
345 | } |
---|
346 | |
---|
347 | } |
---|
348 | } |
---|
349 | /* Se agrega la columna y fila (0,0) y se insertan los titulos de las cuentas */ |
---|
350 | insertremoveRowCol(tw,0,true); |
---|
351 | insertremoveRowCol(CT_VerticalTW,0,true); |
---|
352 | setAccountTitle(tw); |
---|
353 | setAccountTitle(CT_VerticalTW); |
---|
354 | |
---|
355 | int indice=ObtenerIndice("CT_Vertical");//Se obtiene el indice de la pestaña |
---|
356 | QHBoxLayout * layoutCentralWidget = new QHBoxLayout; |
---|
357 | layoutCentralWidget->addWidget(CT_VerticalTW); |
---|
358 | QWidget *widget = tabWidget->widget(indice); |
---|
359 | widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada |
---|
360 | } |
---|
361 | |
---|
362 | void MainWindow::slotCloseExogena() |
---|
363 | { |
---|
364 | formVariablesExogenas->close(); |
---|
365 | } |
---|
366 | |
---|
367 | void MainWindow::slotDeshacerExogena() |
---|
368 | { |
---|
369 | QMessageBox::StandardButton respuesta; |
---|
370 | respuesta=QMessageBox::question(this,"Deshacer","¿Desea deshacer todos los cambios?", |
---|
371 | QMessageBox::Yes|QMessageBox::Default, QMessageBox::No); |
---|
372 | |
---|
373 | if(respuesta==QMessageBox::Yes) |
---|
374 | { |
---|
375 | int cantidad=stackVE->comboAccount->count(); |
---|
376 | /* Se habilitan todas cuentas */ |
---|
377 | for(int i=0;i<cantidad;i++) |
---|
378 | { |
---|
379 | QListWidget *lw=new QListWidget; |
---|
380 | lw= stackVE->veWidget->accounListWidget; |
---|
381 | lw = findChild<QListWidget *>(QString("accountlist %1").arg(i + 1)); |
---|
382 | lw->setEnabled(true); |
---|
383 | } |
---|
384 | diccCuentasExogenas.clear();//Se limpia el diccionario |
---|
385 | } |
---|
386 | } |
---|
387 | |
---|
388 | void MainWindow::slotAgregarExogena() |
---|
389 | { |
---|
390 | actionVariableExogena.setDisabled(true);//Se deshabilita la oipcion de agregar variables exogenas |
---|
391 | QString nombre_cuenta=stackVE->comboAccount->currentText();//Se obtiene el nombre de la cuenta seleccionado |
---|
392 | QListWidget *lw=new QListWidget; |
---|
393 | lw=stackVE->veWidget->accounListWidget; |
---|
394 | int index=stackVE->comboAccount->currentIndex();//Se obtiene el indice selecionado |
---|
395 | lw = findChild<QListWidget *>(QString("accountlist %1").arg(index + 1));//Se obtiene la lista seleccionada |
---|
396 | QStringList componentes_cuenta; |
---|
397 | |
---|
398 | if(nombre_cuenta!="Todas las Cuentas") |
---|
399 | { |
---|
400 | if(!lw->isEnabled()) |
---|
401 | { |
---|
402 | QMessageBox::warning(this,"Alerta","La Cuenta Actual ya fue Agregada"); |
---|
403 | } |
---|
404 | else if(lw->selectedItems().count()==0) |
---|
405 | { |
---|
406 | QMessageBox::warning(this,"Alerta", |
---|
407 | "Para Agregar la Cuenta debe seleccionar \n al menos un valor"); |
---|
408 | } |
---|
409 | else |
---|
410 | { |
---|
411 | int contar=lw->selectedItems().count(); |
---|
412 | for(int i=0;i<contar;i++) |
---|
413 | { |
---|
414 | componentes_cuenta.append(lw->selectedItems().value(i)->text()); |
---|
415 | } |
---|
416 | lw->setDisabled(true); |
---|
417 | opcionCuentaExogena=1;//Se establece un valor para la variable de la opcion |
---|
418 | diccCuentasExogenas.insert(nombre_cuenta,componentes_cuenta); |
---|
419 | } |
---|
420 | } |
---|
421 | else |
---|
422 | { |
---|
423 | int cantidad=stackVE->comboAccount->count(); |
---|
424 | for(int i=0;i<cantidad;i++) |
---|
425 | { |
---|
426 | QListWidget *lw=new QListWidget; |
---|
427 | lw=stackVE->veWidget->accounListWidget; |
---|
428 | lw = findChild<QListWidget *>(QString("accountlist %1").arg(i + 1));//Se obtiene la lista seleccionada |
---|
429 | lw->setDisabled(true); |
---|
430 | opcionCuentaExogena=2;//Se establece un valor para la variable de la opcion |
---|
431 | } |
---|
432 | |
---|
433 | } |
---|
434 | |
---|
435 | } |
---|
436 | |
---|
437 | void MainWindow::slotFinalizarExogena() |
---|
438 | { |
---|
439 | QTableWidget *tablaEE = new QTableWidget; |
---|
440 | tablaEE->setObjectName("TablaExogenaEndogena"); |
---|
441 | QTableWidget *tablaPPAL = findChild<QTableWidget *>("TablaPrincipal");//Se carga la tabla principal |
---|
442 | insertremoveRowCol(tablaPPAL,0,false); |
---|
443 | int count=tablaPPAL->rowCount(); |
---|
444 | CrearTablaVacia(count,tablaEE);//Se crea la tabla vacia |
---|
445 | /* **** Se coloca como no editable la celda(0,0) ***** */ |
---|
446 | noEditColZero(tablaEE); |
---|
447 | if(opcionCuentaExogena==1)//Si seleccionaron componentes |
---|
448 | { |
---|
449 | |
---|
450 | int elementos = contarElementosMap(); |
---|
451 | |
---|
452 | /***** Se llena la tabla vacia con los valores de la tabla principal ****/ |
---|
453 | for(int i=0;i<count-1;i++) |
---|
454 | { |
---|
455 | for(int j=0;j<count-1;j++) |
---|
456 | { |
---|
457 | if(i!=0 && j!=0) |
---|
458 | { |
---|
459 | double valor=tablaPPAL->item(i,j)->text().toDouble(); |
---|
460 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(QString::number(valor,'f',4)); |
---|
461 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
462 | tablaEE->setItem(i,j,ValoraInsertar); |
---|
463 | } |
---|
464 | /**** En este else se llenan las celdas con fila y columna 0, es decir las que tienen nombre *****/ |
---|
465 | else if((i==0 && j>0)||(j==0 && i>0)) |
---|
466 | { |
---|
467 | QString value=tablaPPAL->item(i,j)->text(); |
---|
468 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(value); |
---|
469 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
470 | tablaEE->setItem(i,j,ValoraInsertar); |
---|
471 | } |
---|
472 | |
---|
473 | } |
---|
474 | } |
---|
475 | |
---|
476 | /*** Se acomodan los componentes de las cuentas exogenas ***/ |
---|
477 | |
---|
478 | foreach(QString key,diccCuentasExogenas.keys()) |
---|
479 | { |
---|
480 | int indiceCuenta=retornarIndiceCuenta(key); |
---|
481 | QSpinBox *SBinicio = findChild<QSpinBox *>(QString("accountstart %1").arg(indiceCuenta+1)); |
---|
482 | QSpinBox *SBFin = findChild<QSpinBox *>(QString("accountend %1").arg(indiceCuenta+1)); |
---|
483 | int inicio=SBinicio->text().toInt(); |
---|
484 | int fin=SBFin->text().toInt(); |
---|
485 | foreach(QString key2,diccCuentasExogenas[key]) |
---|
486 | { |
---|
487 | for(int i=inicio;i<fin+1;i++) |
---|
488 | { |
---|
489 | QString item=tablaEE->item(0,i)->text(); |
---|
490 | if(item==key2) |
---|
491 | { |
---|
492 | QList<QString> fila; |
---|
493 | fila=llenarLista(fila,tablaEE,i,1); |
---|
494 | tablaEE->removeRow(i); |
---|
495 | tablaEE->insertRow(tablaEE->rowCount()); |
---|
496 | insertRowExogena(fila,tablaEE,1); |
---|
497 | fila.clear(); |
---|
498 | |
---|
499 | QList<QString> columna; |
---|
500 | columna=llenarLista(columna,tablaEE,i,0); |
---|
501 | tablaEE->removeColumn(i); |
---|
502 | tablaEE->insertColumn(tablaEE->columnCount()); |
---|
503 | insertRowExogena(columna,tablaEE,0); |
---|
504 | columna.clear(); |
---|
505 | |
---|
506 | } |
---|
507 | } |
---|
508 | } |
---|
509 | } |
---|
510 | |
---|
511 | int inicioExogena=count-elementos; |
---|
512 | |
---|
513 | QTableWidget *matrizEndogena = new QTableWidget; |
---|
514 | matrizEndogena->setObjectName("MatrizEndogenaEndogena"); |
---|
515 | CrearTablaVacia(inicioExogena,matrizEndogena); |
---|
516 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(""); |
---|
517 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
518 | matrizEndogena->setItem(0,0,ValoraInsertar); |
---|
519 | |
---|
520 | |
---|
521 | clonarTabla(tablaEE,matrizEndogena,inicioExogena); |
---|
522 | CalcularTotales(matrizEndogena,1); |
---|
523 | |
---|
524 | setEndogenaExogenaCell(tablaEE,inicioExogena,elementos,true); |
---|
525 | CalcularTotales(tablaEE,2); |
---|
526 | |
---|
527 | //Se crea la nueva pestaña |
---|
528 | tabWidget->addTab(new QWidget,"Endogena-Exogena"); |
---|
529 | int indice=ObtenerIndice("Endogena-Exogena");//Se obtiene el indice de la pestaña |
---|
530 | QHBoxLayout * layoutCentralWidget = new QHBoxLayout; |
---|
531 | layoutCentralWidget->addWidget(tablaEE); |
---|
532 | QWidget *widget = tabWidget->widget(indice); |
---|
533 | widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada |
---|
534 | formVariablesExogenas->close(); |
---|
535 | connect(&actionAn,SIGNAL(triggered()),this,SLOT(slotAn())); |
---|
536 | actionAn.setEnabled(true); |
---|
537 | |
---|
538 | /* Se crea la pestaña endogena-endogena */ |
---|
539 | tabWidget->addTab(new QWidget,"Endogena-Endogena"); |
---|
540 | int indiceEndogeno=ObtenerIndice("Endogena-Endogena");//Se obtiene el indice de la pestaña |
---|
541 | QHBoxLayout * layoutEndogeno = new QHBoxLayout; |
---|
542 | layoutEndogeno->addWidget(matrizEndogena); |
---|
543 | QWidget *widgetEndogeno = tabWidget->widget(indiceEndogeno); |
---|
544 | widgetEndogeno->setLayout(layoutEndogeno);//Se añade el widget y layout a la pestaña creada |
---|
545 | |
---|
546 | } |
---|
547 | else if(opcionCuentaExogena==2)//Si se seleccionaron todas las cuentas |
---|
548 | { |
---|
549 | |
---|
550 | /***** Se llena la tabla vacia con los valores de la tabla principal ****/ |
---|
551 | for(int i=0;i<count-1;i++) |
---|
552 | { |
---|
553 | for(int j=0;j<count-1;j++) |
---|
554 | { |
---|
555 | if(i!=0 && j!=0) |
---|
556 | { |
---|
557 | double valor=tablaPPAL->item(i,j)->text().toDouble(); |
---|
558 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(QString::number(valor,'f',4)); |
---|
559 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
560 | tablaEE->setItem(i,j,ValoraInsertar); |
---|
561 | } |
---|
562 | /**** En este else se llenan las celdas con fila y columna 0, es decir las que tienen nombre *****/ |
---|
563 | else if((i==0 && j>0)||(j==0 && i>0)) |
---|
564 | { |
---|
565 | QString value=tablaPPAL->item(i,j)->text(); |
---|
566 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(value); |
---|
567 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
568 | tablaEE->setItem(i,j,ValoraInsertar); |
---|
569 | } |
---|
570 | |
---|
571 | } |
---|
572 | } |
---|
573 | |
---|
574 | QTableWidget *matrizEndogena = new QTableWidget; |
---|
575 | matrizEndogena->setObjectName("MatrizEndogenaEndogena"); |
---|
576 | CrearTablaVacia(count,matrizEndogena); |
---|
577 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(""); |
---|
578 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
579 | matrizEndogena->setItem(0,0,ValoraInsertar); |
---|
580 | |
---|
581 | |
---|
582 | clonarTabla(tablaEE,matrizEndogena,count); |
---|
583 | CalcularTotales(matrizEndogena,1); |
---|
584 | |
---|
585 | setEndogenaExogenaCell(tablaEE,count,0,false); |
---|
586 | CalcularTotales(tablaEE,2); |
---|
587 | |
---|
588 | //Se agrega la nueva pestaña |
---|
589 | tabWidget->addTab(new QWidget,"Endogena-Exogena"); |
---|
590 | int indice=ObtenerIndice("Endogena-Exogena");//Se obtiene el indice de la pestaña |
---|
591 | QHBoxLayout * layoutCentralWidget = new QHBoxLayout; |
---|
592 | layoutCentralWidget->addWidget(tablaEE); |
---|
593 | QWidget *widget = tabWidget->widget(indice); |
---|
594 | widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada |
---|
595 | formVariablesExogenas->close(); |
---|
596 | connect(&actionAn,SIGNAL(triggered()),this,SLOT(slotAn())); |
---|
597 | actionAn.setEnabled(true); |
---|
598 | |
---|
599 | /* Se crea la pestaña endogena-endogena */ |
---|
600 | tabWidget->addTab(new QWidget,"Endogena-Endogena"); |
---|
601 | int indiceEndogeno=ObtenerIndice("Endogena-Endogena");//Se obtiene el indice de la pestaña |
---|
602 | QHBoxLayout * layoutEndogeno = new QHBoxLayout; |
---|
603 | layoutEndogeno->addWidget(matrizEndogena); |
---|
604 | QWidget *widgetEndogeno = tabWidget->widget(indiceEndogeno); |
---|
605 | widgetEndogeno->setLayout(layoutEndogeno);//Se añade el widget y layout a la pestaña creada |
---|
606 | |
---|
607 | |
---|
608 | } |
---|
609 | else |
---|
610 | { |
---|
611 | QMessageBox::warning(this,"Alerta","No Selecciono alguna opción"); |
---|
612 | } |
---|
613 | insertremoveRowCol(tablaPPAL,0,true); |
---|
614 | setAccountTitle(tablaPPAL); |
---|
615 | } |
---|
616 | /*** Slot para calcular el coeficiente tecnico horizontal de la matriz endogena/exogena ***/ |
---|
617 | void MainWindow::slotAn() |
---|
618 | { |
---|
619 | actionAn.setDisabled(true); |
---|
620 | tabWidget->addTab(new QWidget,"An"); |
---|
621 | QTableWidget *tw = findChild<QTableWidget *>("MatrizEndogenaEndogena"); |
---|
622 | QTableWidget *tablaAn = new QTableWidget; |
---|
623 | int count=tw->rowCount(); |
---|
624 | CrearTablaVacia(count,tablaAn);//Se crea una tabla vacia |
---|
625 | /* **** Se coloca como no editable la celda(0,0) ***** */ |
---|
626 | noEditColZero(tablaAn); |
---|
627 | /***** Se llena la tabla vacia con los valores de la tabla principal ****/ |
---|
628 | |
---|
629 | CalcularAn(tw,tablaAn,count,false);//Funcion para calcular el Coeficiente Tecnico Horizontal (An) |
---|
630 | |
---|
631 | int indice=ObtenerIndice("An");//Se obtiene el indice de la pestaña |
---|
632 | QHBoxLayout * layoutCentralWidget = new QHBoxLayout; |
---|
633 | layoutCentralWidget->addWidget(tablaAn); |
---|
634 | QWidget *widget = tabWidget->widget(indice); |
---|
635 | widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada |
---|
636 | |
---|
637 | crearMatrizEndogena(tablaAn); |
---|
638 | connect(&actionLa,SIGNAL(triggered()),this,SLOT(slotLa())); |
---|
639 | actionLa.setEnabled(true); |
---|
640 | } |
---|
641 | |
---|
642 | void MainWindow::slotLa() |
---|
643 | { |
---|
644 | QTableWidget *tw = findChild<QTableWidget *>("MatrizEndogenaEndogena"); |
---|
645 | double matrizIdentidad[200][200]; |
---|
646 | double matrizResta[200][200]; |
---|
647 | crearMatrizIdentidad(tw,matrizIdentidad); |
---|
648 | restarIdentidadAn(tw,matrizIdentidad,matrizResta); |
---|
649 | } |
---|
650 | |
---|
651 | int MainWindow::ObtenerIndice(QString text)//Funcion para obtener el indice de una pestaña buscada por un nombre dado |
---|
652 | { |
---|
653 | int cantidad=tabWidget->count(); |
---|
654 | int indice=0; |
---|
655 | for(int i=0;i<cantidad;i++) |
---|
656 | { |
---|
657 | if(tabWidget->tabText(i)==text) |
---|
658 | { |
---|
659 | indice=i; |
---|
660 | break; |
---|
661 | } |
---|
662 | } |
---|
663 | return indice; |
---|
664 | } |
---|
665 | |
---|
666 | |
---|
667 | void MainWindow::createMatrixCentralWidget() |
---|
668 | { |
---|
669 | QHBoxLayout * layoutCentralWidget = new QHBoxLayout; |
---|
670 | QVBoxLayout * layoutLateralWidget = new QVBoxLayout; |
---|
671 | |
---|
672 | QTableWidget * tableWidget = new QTableWidget(this); |
---|
673 | tableWidget->setObjectName("TablaPrincipal");//Se le asigna nombre al objeto |
---|
674 | QGroupBox * groupBoxAccount = new QGroupBox; |
---|
675 | QPushButton * buttonEnd = new QPushButton; |
---|
676 | buttonEnd->setObjectName("AgregarCuentas");//Se le asigna nombre al objeto |
---|
677 | QPushButton * buttonRestaurar = new QPushButton; |
---|
678 | buttonRestaurar->setObjectName("Restaurar");//Se le asigna nombre al objeto |
---|
679 | QPushButton * buttonFinalizar = new QPushButton; |
---|
680 | buttonFinalizar->setObjectName("Finalizar");//Se le asigna nombre al objeto |
---|
681 | QPushButton * buttonModificar = new QPushButton; |
---|
682 | buttonModificar->setObjectName("Modificar");//Se le asigna nombre al objeto |
---|
683 | |
---|
684 | populateTable(tableWidget); |
---|
685 | tableWidget->setMaximumHeight(700); |
---|
686 | |
---|
687 | /* **** Se coloca como no editable la celda(0,0) ***** */ |
---|
688 | noEditColZero(tableWidget); |
---|
689 | |
---|
690 | //tableWidget->setFixedSize(750,750); |
---|
691 | layoutCentralWidget->addWidget(tableWidget); |
---|
692 | //layoutCentralWidget->addStretch(); |
---|
693 | |
---|
694 | QVBoxLayout * layoutAccounts = new QVBoxLayout; |
---|
695 | |
---|
696 | layoutAccounts->addWidget(new StackWidget(numAccounts, groupBoxAccount)); |
---|
697 | |
---|
698 | groupBoxAccount->setFixedWidth(220); |
---|
699 | groupBoxAccount->setObjectName("GrupoCuentas");//Se le asigna nombre al objeto |
---|
700 | groupBoxAccount->setLayout(layoutAccounts);; |
---|
701 | groupBoxAccount->setTitle("Cuentas"); |
---|
702 | groupBoxAccount->setStyleSheet("QGroupBox {border: 1px solid gray; " |
---|
703 | "border-radius: 3px; margin-top: 0.5em;} " |
---|
704 | "QGroupBox::title { subcontrol-origin: margin; " |
---|
705 | "left: 10px; padding: 0 3px 0 3px; } "); |
---|
706 | |
---|
707 | |
---|
708 | |
---|
709 | layoutLateralWidget->addStretch(1); |
---|
710 | layoutLateralWidget->addWidget(groupBoxAccount); |
---|
711 | buttonEnd->setText("Agregar Cuenta"); |
---|
712 | buttonEnd->setFixedWidth(130); |
---|
713 | buttonEnd->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
714 | "font-weight: bold; height: 30px; border: none;" |
---|
715 | "border-radius: 5px; margin-top: 40px;"); |
---|
716 | layoutLateralWidget->addWidget(buttonEnd); |
---|
717 | |
---|
718 | |
---|
719 | /*********** Nuevo boton para restaurar la tabla *******/ |
---|
720 | buttonRestaurar->setText("Restaurar Titulos"); |
---|
721 | buttonRestaurar->setFixedWidth(150); |
---|
722 | buttonRestaurar->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
723 | "font-weight: bold; height: 30px; border: none;" |
---|
724 | "border-radius: 5px; margin-top: 40px;"); |
---|
725 | layoutLateralWidget->addWidget(buttonRestaurar); |
---|
726 | |
---|
727 | buttonModificar->setText("Editar Cuenta Actual"); |
---|
728 | buttonModificar->setFixedWidth(180); |
---|
729 | buttonModificar->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
730 | "font-weight: bold; height: 30px; border: none;" |
---|
731 | "border-radius: 5px; margin-top: 40px;"); |
---|
732 | layoutLateralWidget->addWidget(buttonModificar); |
---|
733 | |
---|
734 | |
---|
735 | buttonFinalizar->setText("Finalizar Carga"); |
---|
736 | buttonFinalizar->setFixedWidth(130); |
---|
737 | buttonFinalizar->setStyleSheet("background-color: #358ccb; color: #fff;" |
---|
738 | "font-weight: bold; height: 30px; border: none;" |
---|
739 | "border-radius: 5px; margin-top: 40px;"); |
---|
740 | layoutLateralWidget->addWidget(buttonFinalizar); |
---|
741 | layoutLateralWidget->addStretch(6); |
---|
742 | |
---|
743 | |
---|
744 | layoutCentralWidget->addLayout(layoutLateralWidget); |
---|
745 | |
---|
746 | connect(buttonEnd,SIGNAL(clicked()),this,SLOT(AgregarCuenta()));//**************Conexion del boton agregar********************** |
---|
747 | connect(buttonRestaurar,SIGNAL(clicked()),this,SLOT(RestaurarCeldas()));//Conexion del boton restaurar |
---|
748 | connect(buttonFinalizar,SIGNAL(clicked()),this,SLOT(FinalizarCuentas()));//Conexion del boton Finalizar |
---|
749 | connect(buttonModificar,SIGNAL(clicked()),this,SLOT(ModificarCuenta()));//Conexion del boton modificar |
---|
750 | |
---|
751 | |
---|
752 | layoutCentralWidget->sizeHint(); |
---|
753 | |
---|
754 | tabWidget->addTab(new QWidget,"MCS"); |
---|
755 | QWidget *widget= tabWidget->widget(1); |
---|
756 | widget->setLayout(layoutCentralWidget); |
---|
757 | |
---|
758 | |
---|
759 | /* *********** Se agrega la columna en la que se asignan los nombre ************** */ |
---|
760 | tableWidget->insertRow(0); |
---|
761 | tableWidget->insertColumn(0); |
---|
762 | noEditColZero(tableWidget); |
---|
763 | /* Se agregan elementos a la recien creada fila/columna */ |
---|
764 | int contador=tableWidget->rowCount(); |
---|
765 | for(int i=1;i<contador;i++) |
---|
766 | { |
---|
767 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem; |
---|
768 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
769 | tableWidget->setItem(0,i,ValoraInsertar); |
---|
770 | |
---|
771 | QTableWidgetItem *ValoraInsertar2 = new QTableWidgetItem; |
---|
772 | ValoraInsertar2->setFlags(ValoraInsertar2->flags() ^ Qt::ItemIsEditable); |
---|
773 | tableWidget->setItem(i,0,ValoraInsertar2); |
---|
774 | } |
---|
775 | |
---|
776 | matricesMenuBar();//Al terminar la carga de la tabla se ejecuta la accion para el menu de Operaciones |
---|
777 | tabWidget->setCurrentIndex(1);//Se seleciona la pestaña MCS |
---|
778 | |
---|
779 | actionLoadMatrix.setDisabled(true); |
---|
780 | |
---|
781 | /**** Se conectan las acciones para coeficientes tecnicos horizontales y verticales ****/ |
---|
782 | connect(&actionCH, SIGNAL(triggered()), this,SLOT(slotCoeficienteHorizontal())); |
---|
783 | connect(&actionCV, SIGNAL(triggered()), this,SLOT(slotCoeficienteVertical())); |
---|
784 | //Se conecta la accion para la variables exogenas |
---|
785 | connect(&actionVariableExogena,SIGNAL(triggered()),this,SLOT(slotVariableExogena())); |
---|
786 | } |
---|
787 | |
---|
788 | void MainWindow::AgregarCuenta() |
---|
789 | { |
---|
790 | QMessageBox::StandardButton respuesta; |
---|
791 | respuesta=QMessageBox::question(this,"Agregar cuenta","¿Está seguro que agregar la cuenta?", |
---|
792 | QMessageBox::Yes|QMessageBox::Default, QMessageBox::No); |
---|
793 | |
---|
794 | if(respuesta==QMessageBox::Yes) |
---|
795 | { |
---|
796 | QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal");//Se busca la tabla que se creo |
---|
797 | StackWidget *sw = findChild<StackWidget *>();//Se buscan las cuentas creadas |
---|
798 | |
---|
799 | /* ****** Se leen los campos del widget izquierdo ******* */; |
---|
800 | |
---|
801 | int index=sw->comboAccount->currentIndex(); |
---|
802 | |
---|
803 | |
---|
804 | /***** Se cargan la linea y las spin box correpondientes a la cuenta seleccionada *****/ |
---|
805 | |
---|
806 | QLineEdit *le= findChild<QLineEdit *>(QString("linedit %1").arg(index + 1)); |
---|
807 | QSpinBox *SBStart = findChild<QSpinBox *>(QString("accountstart %1").arg(index+1)); |
---|
808 | QSpinBox *SBEnd = findChild<QSpinBox *>(QString("accountend %1").arg(index+1)); |
---|
809 | |
---|
810 | int inicio=SBStart->value(); |
---|
811 | int fin=SBEnd->value(); |
---|
812 | QString nombreCuenta=le->text(); |
---|
813 | |
---|
814 | if(nombreCuenta.isEmpty() or nombreCuenta.isNull()) |
---|
815 | { |
---|
816 | QMessageBox::warning(this,"Alerta","El nombre de la cuenta esta vacio"); |
---|
817 | } |
---|
818 | else |
---|
819 | { |
---|
820 | int cantidad_filas=tw->rowCount(); |
---|
821 | |
---|
822 | if(inicio>cantidad_filas or fin>cantidad_filas)//Se verifica que los valores no excedan el tamaño de la tabla |
---|
823 | { |
---|
824 | QMessageBox::warning(this,"Alerta","Valores mayores al tamaño\n de la tabla"); |
---|
825 | } |
---|
826 | else |
---|
827 | { |
---|
828 | /*** Se comprueba si la celda de la tabla esta ocupada por otra cuenta ***/ |
---|
829 | bool centinela=true; |
---|
830 | if(inicio>2 and fin>2){ |
---|
831 | for(int i=0;i<numAccounts;i++) |
---|
832 | { |
---|
833 | if(i!=index) |
---|
834 | { |
---|
835 | QSpinBox *otherEnd = findChild<QSpinBox *>(QString("accountend %1").arg(i+1)); |
---|
836 | int otroFin=otherEnd->text().toInt(); |
---|
837 | if(inicio<otroFin) |
---|
838 | { |
---|
839 | centinela=false; |
---|
840 | } |
---|
841 | } |
---|
842 | } |
---|
843 | } |
---|
844 | |
---|
845 | /* ***** Se asigna el nombre de la cuenta a las cabecereas de la tabla en el rango(inicio,fin) ***** */ |
---|
846 | if((inicio>2 && fin>2) and (centinela)) |
---|
847 | { |
---|
848 | |
---|
849 | QTableWidgetItem *ValoraInsertarFila = new QTableWidgetItem(nombreCuenta); |
---|
850 | ValoraInsertarFila->setTextAlignment(Qt::AlignCenter); |
---|
851 | ValoraInsertarFila->setFlags(ValoraInsertarFila->flags() ^ Qt::ItemIsEditable); |
---|
852 | tw->setItem(0,inicio-1,ValoraInsertarFila); |
---|
853 | QTableWidgetItem *ValoraInsertarColumna = new QTableWidgetItem(nombreCuenta); |
---|
854 | ValoraInsertarColumna->setTextAlignment(Qt::AlignCenter); |
---|
855 | ValoraInsertarColumna->setFlags(ValoraInsertarColumna->flags() ^ Qt::ItemIsEditable); |
---|
856 | tw->setItem(inicio-1,0,ValoraInsertarColumna); |
---|
857 | int espacio=(fin-inicio)+1; |
---|
858 | tw->setSpan(inicio-1,0,espacio,1); |
---|
859 | tw->setSpan(0,inicio-1,1,espacio); |
---|
860 | /***** Se inhabilita el boton de la linea y los spinbox *******/ |
---|
861 | le->setEnabled(false); |
---|
862 | SBStart->setEnabled(false); |
---|
863 | SBEnd->setEnabled(false); |
---|
864 | } |
---|
865 | else if(!centinela) |
---|
866 | { |
---|
867 | QMessageBox::warning(this,"Alerta","Valores en el espacio de otra cuenta"); |
---|
868 | } |
---|
869 | else |
---|
870 | { |
---|
871 | QMessageBox::warning(this,"Alerta","Valores invalidos"); |
---|
872 | } |
---|
873 | |
---|
874 | } |
---|
875 | } |
---|
876 | } |
---|
877 | |
---|
878 | } |
---|
879 | |
---|
880 | void MainWindow::FinalizarCuentas() |
---|
881 | { |
---|
882 | QMessageBox::StandardButton respuesta; |
---|
883 | respuesta=QMessageBox::question(this,"Finalizar Carga","¿Está seguro que desea finalizar?", |
---|
884 | QMessageBox::Yes|QMessageBox::Default, QMessageBox::No); |
---|
885 | if(respuesta==QMessageBox::Yes) |
---|
886 | { |
---|
887 | bool Centinela=ComprobarCuentas();//Se llama a la funcion que comprueba si todos los campos de las cuentas estan llenos |
---|
888 | if(Centinela) |
---|
889 | { |
---|
890 | QPushButton *Agregar = findChild<QPushButton *>("AgregarCuentas"); |
---|
891 | QPushButton *Restaurar = findChild<QPushButton *>("Restaurar"); |
---|
892 | Agregar->setStyleSheet("background-color: gray; color: #fff;" |
---|
893 | "font-weight: bold; height: 30px; border: none;" |
---|
894 | "border-radius: 5px; margin-top: 40px;"); |
---|
895 | Agregar->setEnabled(false); |
---|
896 | Agregar->setVisible(false); |
---|
897 | Restaurar->setStyleSheet("background-color: gray; color: #fff;" |
---|
898 | "font-weight: bold; height: 30px; border: none;" |
---|
899 | "border-radius: 5px; margin-top: 40px;"); |
---|
900 | Restaurar->setEnabled(false); |
---|
901 | Restaurar->setVisible(false); |
---|
902 | QPushButton *Modificar = findChild<QPushButton *>("Modificar"); |
---|
903 | Modificar->setStyleSheet("background-color: gray; color: #fff;" |
---|
904 | "font-weight: bold; height: 30px; border: none;" |
---|
905 | "border-radius: 5px; margin-top: 40px;"); |
---|
906 | Modificar->setEnabled(false); |
---|
907 | Modificar->setVisible(false); |
---|
908 | QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal"); |
---|
909 | QPushButton *Finalizar = findChild<QPushButton *>("Finalizar"); |
---|
910 | Finalizar->setStyleSheet("background-color: gray; color: #fff;" |
---|
911 | "font-weight: bold; height: 30px; border: none;" |
---|
912 | "border-radius: 5px; margin-top: 40px;"); |
---|
913 | Finalizar->setEnabled(false); |
---|
914 | Finalizar->setVisible(false); |
---|
915 | |
---|
916 | QGroupBox *groupbox = findChild<QGroupBox *>("GrupoCuentas"); |
---|
917 | groupbox->setVisible(false); |
---|
918 | |
---|
919 | insertremoveRowCol(tw,0,false); |
---|
920 | CalcularTotales(tw,1);//Se llama a la funcion que agregue una nueva fila y columna con los totales respectivos |
---|
921 | insertremoveRowCol(tw,0,true); |
---|
922 | setAccountTitle(tw); |
---|
923 | |
---|
924 | /* Luego de calcular los totales se habilitan las opciones del menu herramientas */ |
---|
925 | actionCH.setEnabled(true); |
---|
926 | actionCV.setEnabled(true); |
---|
927 | actionVariableExogena.setEnabled(true); |
---|
928 | } |
---|
929 | else |
---|
930 | { |
---|
931 | QMessageBox::warning(this,"Alerta","Debe llenar correctamente y agregar todas las cuentas"); |
---|
932 | } |
---|
933 | } |
---|
934 | } |
---|
935 | |
---|
936 | void MainWindow::CalcularTotales(QTableWidget *tableWidget,int inicio)//Se calculan los totales por fila/columna |
---|
937 | { |
---|
938 | int filas=tableWidget->rowCount(); |
---|
939 | int columnas=tableWidget->columnCount(); |
---|
940 | /******* Se inserta la nueva fila y columna para los totales, asi como es texto corespondiente *****/ |
---|
941 | tableWidget->insertRow(filas); |
---|
942 | tableWidget->insertColumn(columnas); |
---|
943 | QTableWidgetItem *FilaTotal = new QTableWidgetItem; |
---|
944 | FilaTotal->setText("Total en Fila"); |
---|
945 | FilaTotal->setFlags(FilaTotal->flags() ^ Qt::ItemIsEditable); |
---|
946 | QTableWidgetItem *ColumnaTotal = new QTableWidgetItem; |
---|
947 | ColumnaTotal->setText("Total en Columna"); |
---|
948 | ColumnaTotal->setFlags(ColumnaTotal->flags() ^ Qt::ItemIsEditable); |
---|
949 | tableWidget->setItem(columnas,inicio-1,FilaTotal); |
---|
950 | tableWidget->setItem(inicio-1,filas,ColumnaTotal); |
---|
951 | for(int i=inicio;i<filas;i++) |
---|
952 | { |
---|
953 | double SumaFila=0; |
---|
954 | double SumaColumna=0; |
---|
955 | for(int j=inicio;j<filas;j++) |
---|
956 | { |
---|
957 | double thisFila=tableWidget->item(j,i)->text().toDouble(); |
---|
958 | double thisColumna=tableWidget->item(i,j)->text().toDouble(); |
---|
959 | SumaFila+=thisFila; |
---|
960 | SumaColumna+=thisColumna; |
---|
961 | } |
---|
962 | QTableWidgetItem *Valor1 = new QTableWidgetItem; |
---|
963 | Valor1->setText(QString::number(SumaFila)); |
---|
964 | Valor1->setFlags(Valor1->flags() ^ Qt::ItemIsEditable); |
---|
965 | QTableWidgetItem *Valor2 = new QTableWidgetItem; |
---|
966 | Valor2->setText(QString::number(SumaColumna)); |
---|
967 | Valor2->setFlags(Valor2->flags() ^ Qt::ItemIsEditable); |
---|
968 | tableWidget->setItem(filas,i,Valor1);//Inserta en Filas |
---|
969 | tableWidget->setItem(i,filas,Valor2);//Inserta en Columnas |
---|
970 | } |
---|
971 | |
---|
972 | } |
---|
973 | |
---|
974 | void MainWindow::RestaurarCeldas()//Slot que permite restaurar el titulo de las cuentas en las celdas |
---|
975 | { |
---|
976 | QMessageBox::StandardButton respuesta; |
---|
977 | respuesta=QMessageBox::question(this,"Restaurar Celdas","¿Desea Restaurar el titulo de todas las celdas?", |
---|
978 | QMessageBox::Yes|QMessageBox::Default, QMessageBox::No); |
---|
979 | if(respuesta==QMessageBox::Yes) |
---|
980 | { |
---|
981 | QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal"); |
---|
982 | insertremoveRowCol(tw,0,false); |
---|
983 | insertremoveRowCol(tw,0,true); |
---|
984 | } |
---|
985 | } |
---|
986 | |
---|
987 | void MainWindow::ModificarCuenta()//Slot que permite habilitar la edicion de una cuenta una vez agregada |
---|
988 | { |
---|
989 | QMessageBox::StandardButton respuesta; |
---|
990 | respuesta=QMessageBox::question(this,"Modificar Cuenta","¿Desea Modificar la Cuenta Actual?", |
---|
991 | QMessageBox::Yes|QMessageBox::Default, QMessageBox::No); |
---|
992 | if(respuesta==QMessageBox::Yes) |
---|
993 | { |
---|
994 | StackWidget *sw = findChild<StackWidget *>();//Se buscan las cuentas creadas |
---|
995 | int index=sw->comboAccount->currentIndex(); |
---|
996 | QLineEdit *le= findChild<QLineEdit *>(QString("linedit %1").arg(index + 1)); |
---|
997 | QSpinBox *SBStart = findChild<QSpinBox *>(QString("accountstart %1").arg(index+1)); |
---|
998 | QSpinBox *SBEnd = findChild<QSpinBox *>(QString("accountend %1").arg(index+1)); |
---|
999 | le->setEnabled(true); |
---|
1000 | SBStart->setEnabled(true); |
---|
1001 | SBEnd->setEnabled(true); |
---|
1002 | } |
---|
1003 | } |
---|
1004 | |
---|
1005 | void MainWindow::loadMatrizExogena() |
---|
1006 | { |
---|
1007 | |
---|
1008 | } |
---|
1009 | |
---|
1010 | void MainWindow::populateTable(QTableWidget * tableWidget) { |
---|
1011 | |
---|
1012 | QFile file(csvFilePath); |
---|
1013 | if (file.open(QIODevice::ReadOnly | QIODevice::Text)) |
---|
1014 | { |
---|
1015 | int row = 0; |
---|
1016 | QString lineHead = file.readLine(); |
---|
1017 | std::vector<std::string> rowVH = |
---|
1018 | csv_read_row(lineHead.toStdString(), csvSeparator); |
---|
1019 | |
---|
1020 | matrixSize = rowVH.size(); |
---|
1021 | tableWidget->setRowCount(matrixSize+1); |
---|
1022 | tableWidget->setColumnCount(matrixSize+1); |
---|
1023 | |
---|
1024 | for(int column=0; column<matrixSize; column++) { |
---|
1025 | QTableWidgetItem *newItem = new QTableWidgetItem( |
---|
1026 | QString::fromUtf8(rowVH[column].c_str()). |
---|
1027 | toLocal8Bit().constData()); |
---|
1028 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable);//Se coloca como no editable |
---|
1029 | tableWidget->setItem(row, column+1, newItem); |
---|
1030 | } |
---|
1031 | ++row; |
---|
1032 | |
---|
1033 | while (!file.atEnd() and row<=matrixSize) |
---|
1034 | { |
---|
1035 | QTableWidgetItem *newItem = new QTableWidgetItem( |
---|
1036 | QString::fromUtf8(rowVH[row-1].c_str()). |
---|
1037 | toLocal8Bit().constData()); |
---|
1038 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable);//Se coloca como no editable |
---|
1039 | tableWidget->setItem(row, 0, newItem); |
---|
1040 | |
---|
1041 | QString line = file.readLine(); |
---|
1042 | /*QStringList strings = line.split(csvSeparator); |
---|
1043 | for (int column = 0; column < strings.size(); ++column) { |
---|
1044 | QTableWidgetItem *newItem = new QTableWidgetItem( |
---|
1045 | strings.at(column).toLocal8Bit().constData()); |
---|
1046 | tableWidget->setItem(row, column, newItem); |
---|
1047 | |
---|
1048 | }*/ |
---|
1049 | std::vector<std::string> rowV = |
---|
1050 | csv_read_row(line.toStdString(), csvSeparator); |
---|
1051 | |
---|
1052 | for(int column=0, leng=rowV.size(); |
---|
1053 | column < leng and column<matrixSize; column++) { |
---|
1054 | |
---|
1055 | double value = (double)atof(rowV[column].c_str()); |
---|
1056 | |
---|
1057 | QTableWidgetItem *newItem = new QTableWidgetItem( |
---|
1058 | numberFormat(value). |
---|
1059 | toLocal8Bit().constData()); |
---|
1060 | newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable);//Se coloca como no editable |
---|
1061 | tableWidget->setItem(row, column+1, newItem); |
---|
1062 | matrix[row-1][column] = atof(rowV[column].c_str()); |
---|
1063 | } |
---|
1064 | ++row; |
---|
1065 | } |
---|
1066 | file.close(); |
---|
1067 | } |
---|
1068 | //tableWidget->resizeColumnsToContents(); |
---|
1069 | } |
---|
1070 | |
---|
1071 | std::vector<std::string> MainWindow::csv_read_row(std::string line, |
---|
1072 | char delimiter) |
---|
1073 | { |
---|
1074 | std::stringstream ss(line); void msghere(); |
---|
1075 | return csv_read_row(ss, delimiter); |
---|
1076 | } |
---|
1077 | |
---|
1078 | std::vector<std::string> MainWindow::csv_read_row(std::istream &in, |
---|
1079 | char delimiter) |
---|
1080 | { |
---|
1081 | std::stringstream ss; |
---|
1082 | bool inquotes = false; |
---|
1083 | std::vector<std::string> row;//relying on RVO |
---|
1084 | while(in.good()) |
---|
1085 | { |
---|
1086 | char c = in.get(); |
---|
1087 | if (!inquotes && c=='"') //beginquotechar |
---|
1088 | { |
---|
1089 | inquotes=true; |
---|
1090 | } |
---|
1091 | else if (inquotes && c=='"') //quotechar |
---|
1092 | { |
---|
1093 | if ( in.peek() == '"')//2 consecutive quotes resolve to 1 |
---|
1094 | { |
---|
1095 | ss << (char)in.get(); |
---|
1096 | } |
---|
1097 | else //endquotechar |
---|
1098 | { |
---|
1099 | inquotes=false; |
---|
1100 | } |
---|
1101 | } |
---|
1102 | else if (!inquotes && c==delimiter) //end of field |
---|
1103 | { |
---|
1104 | row.push_back( ss.str() ); |
---|
1105 | ss.str(""); |
---|
1106 | } |
---|
1107 | else if (!inquotes && (c=='\r' || c=='\n') ) |
---|
1108 | { |
---|
1109 | if(in.peek()=='\n') { in.get(); } |
---|
1110 | row.push_back( ss.str() ); |
---|
1111 | return row; |
---|
1112 | } |
---|
1113 | else |
---|
1114 | { |
---|
1115 | ss << c; |
---|
1116 | } |
---|
1117 | } |
---|
1118 | } |
---|
1119 | |
---|
1120 | QString MainWindow::numberFormat(double & d) { |
---|
1121 | |
---|
1122 | int precision = 2; |
---|
1123 | |
---|
1124 | QString stringNumber = QString::number(d, 'f', precision); |
---|
1125 | for(int point = 0, i = (stringNumber.lastIndexOf('.') == -1 ? stringNumber.length() : stringNumber.lastIndexOf('.')); i > 0; --i, ++point) |
---|
1126 | { |
---|
1127 | if(point != 0 && point % 3 == 0) |
---|
1128 | { |
---|
1129 | stringNumber.insert(i, '*'); |
---|
1130 | } |
---|
1131 | } |
---|
1132 | stringNumber.replace(".", ","); |
---|
1133 | stringNumber.replace("*", "."); |
---|
1134 | return stringNumber; |
---|
1135 | } |
---|
1136 | |
---|
1137 | bool MainWindow::ComprobarCuentas()//Se verifica que las lineas de texto y spin box de todas las cuentas no esten vacios |
---|
1138 | { |
---|
1139 | bool centinela=true; |
---|
1140 | StackWidget *sw = findChild<StackWidget *>(); |
---|
1141 | int count=sw->comboAccount->count(); |
---|
1142 | for(int i=0;i<count;i++) |
---|
1143 | { |
---|
1144 | QLineEdit *le= findChild<QLineEdit *>(QString("linedit %1").arg(i + 1)); |
---|
1145 | QSpinBox *SBStart = findChild<QSpinBox *>(QString("accountstart %1").arg(i+1)); |
---|
1146 | QSpinBox *SBEnd = findChild<QSpinBox *>(QString("accountend %1").arg(i+1)); |
---|
1147 | if((le->text().isEmpty()) || (SBStart->text().toInt()==0) || (SBEnd->text().toInt()==0) || (le->isEnabled())) |
---|
1148 | { |
---|
1149 | centinela=false; |
---|
1150 | } |
---|
1151 | } |
---|
1152 | return centinela; |
---|
1153 | } |
---|
1154 | |
---|
1155 | /*** Funcion que obtiene el nombre las cuentas a traves de los lineeidt y los retorna en una lista de string ***/ |
---|
1156 | QStringList MainWindow::ObtenerNombreCuenta(int contador) |
---|
1157 | { |
---|
1158 | QStringList MiLista; |
---|
1159 | for(int i = 0;i<contador;i++) |
---|
1160 | { |
---|
1161 | QLineEdit *le= findChild<QLineEdit *>(QString("linedit %1").arg(i + 1)); |
---|
1162 | MiLista.append(le->text()); |
---|
1163 | } |
---|
1164 | return MiLista; |
---|
1165 | } |
---|
1166 | |
---|
1167 | /*** Funcion que obtiene los inicios/fin de las cuentas y las retorna como entero en una lista ***/ |
---|
1168 | QList<int> MainWindow::ObtenerLimitesCuenta(int contador,int opccion)//Funcion que |
---|
1169 | { |
---|
1170 | QList<int> Lista; |
---|
1171 | for(int i=0;i<contador;i++) |
---|
1172 | { |
---|
1173 | if(opccion==0) |
---|
1174 | { |
---|
1175 | QSpinBox *SBStart = findChild<QSpinBox *>(QString("accountstart %1").arg(i+1)); |
---|
1176 | Lista.append(SBStart->text().toInt()); |
---|
1177 | |
---|
1178 | } |
---|
1179 | else |
---|
1180 | { |
---|
1181 | QSpinBox *SBEnd = findChild<QSpinBox *>(QString("accountend %1").arg(i+1)); |
---|
1182 | Lista.append(SBEnd->text().toInt()); |
---|
1183 | } |
---|
1184 | } |
---|
1185 | return Lista; |
---|
1186 | } |
---|
1187 | |
---|
1188 | /*** Funcion para retornar todos los componentes en una lista ***/ |
---|
1189 | QStringList MainWindow::ObtenerComponentes(QTableWidget *tw) |
---|
1190 | { |
---|
1191 | QStringList MiLista; |
---|
1192 | int contador=tw->rowCount(); |
---|
1193 | for(int i=1;i<contador-1;i++) |
---|
1194 | { |
---|
1195 | MiLista.append(tw->item(0,i)->text()); |
---|
1196 | } |
---|
1197 | return MiLista; |
---|
1198 | } |
---|
1199 | |
---|
1200 | void MainWindow::CrearTablaVacia(int contador, QTableWidget *tw)//FUncion para crear una tabla vacia |
---|
1201 | { |
---|
1202 | for(int k=0;k<contador-1;k++) |
---|
1203 | { |
---|
1204 | tw->insertRow(k); |
---|
1205 | tw->insertColumn(k); |
---|
1206 | } |
---|
1207 | } |
---|
1208 | |
---|
1209 | int MainWindow::contarElementosMap()//Funcion para contar los elementos en el map o diccionario |
---|
1210 | { |
---|
1211 | int contador=0; |
---|
1212 | foreach(QString key,diccCuentasExogenas.keys()) |
---|
1213 | { |
---|
1214 | contador+=diccCuentasExogenas[key].count(); |
---|
1215 | } |
---|
1216 | return contador; |
---|
1217 | } |
---|
1218 | |
---|
1219 | /*** Funcion, que dada un nombre de uan cuenta permite retornar su respectivo indice en la combobox ***/ |
---|
1220 | int MainWindow::retornarIndiceCuenta(QString nombre_cuenta) |
---|
1221 | { |
---|
1222 | for(int i=0;i<numAccounts;i++) |
---|
1223 | { |
---|
1224 | QLineEdit *newline= findChild<QLineEdit *>(QString("linedit %1").arg(i + 1)); |
---|
1225 | if(newline->text()==nombre_cuenta) |
---|
1226 | { |
---|
1227 | return i; |
---|
1228 | } |
---|
1229 | } |
---|
1230 | } |
---|
1231 | |
---|
1232 | /*** Funcion que permite llenar una lista con los elementos en un intervalo dado(fila o columna) ***/ |
---|
1233 | QList<QString> MainWindow::llenarLista(QList<QString> lista,QTableWidget *tw,int valor,int opcion) |
---|
1234 | { |
---|
1235 | for(int i=0;i<tw->rowCount();i++) |
---|
1236 | { |
---|
1237 | if(opcion==1) |
---|
1238 | { |
---|
1239 | lista.append(tw->item(valor,i)->text()); |
---|
1240 | } |
---|
1241 | else |
---|
1242 | { |
---|
1243 | lista.append(tw->item(i,valor)->text()); |
---|
1244 | } |
---|
1245 | } |
---|
1246 | return lista; |
---|
1247 | } |
---|
1248 | |
---|
1249 | /*** Funcion que escribe en una columna o fila con la lista dada ***/ |
---|
1250 | void MainWindow::insertRowExogena(QList<QString> lista,QTableWidget *tw,int opcion) |
---|
1251 | { |
---|
1252 | for(int i=0;i<tw->rowCount();i++) |
---|
1253 | { |
---|
1254 | QTableWidgetItem *twi =new QTableWidgetItem; |
---|
1255 | twi->setText(lista[i]); |
---|
1256 | twi->setFlags(twi->flags() ^ Qt::ItemIsEditable); |
---|
1257 | int fin=tw->rowCount(); |
---|
1258 | if(opcion==1) |
---|
1259 | { |
---|
1260 | tw->setItem(fin-1,i,twi); |
---|
1261 | } |
---|
1262 | else |
---|
1263 | { |
---|
1264 | tw->setItem(i,fin-1,twi); |
---|
1265 | } |
---|
1266 | } |
---|
1267 | } |
---|
1268 | |
---|
1269 | /*** Funcion que permite insertar, alinear y combinar las celdas con los titulos endogena/exogena ***/ |
---|
1270 | void MainWindow::setEndogenaExogenaCell(QTableWidget *tw,int inicioExogena,int elementos,bool condicion) |
---|
1271 | { |
---|
1272 | tw->insertRow(0); |
---|
1273 | tw->insertColumn(0); |
---|
1274 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem; |
---|
1275 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
1276 | tw->setItem(0,0,ValoraInsertar); |
---|
1277 | /* Titulos para las Cuentas endogenas */ |
---|
1278 | QTableWidgetItem *CuentaEndogenafila = new QTableWidgetItem("Cuentas Endogenas"); |
---|
1279 | CuentaEndogenafila->setFlags(CuentaEndogenafila->flags() ^ Qt::ItemIsEditable); |
---|
1280 | CuentaEndogenafila->setTextAlignment(Qt::AlignCenter); |
---|
1281 | tw->setItem(0,1,CuentaEndogenafila); |
---|
1282 | tw->setSpan(0,1,1,inicioExogena-1); |
---|
1283 | QTableWidgetItem *CuentaEndogenaColumna = new QTableWidgetItem("C\nu\ne\nn\nt\na\ns\n\nE\nn\nd\no\ng\ne\nn\na\ns"); |
---|
1284 | CuentaEndogenaColumna->setFlags(CuentaEndogenaColumna->flags() ^ Qt::ItemIsEditable); |
---|
1285 | tw->setItem(1,0,CuentaEndogenaColumna); |
---|
1286 | tw->setSpan(1,0,inicioExogena-1,1); |
---|
1287 | if(condicion) |
---|
1288 | { |
---|
1289 | /* Titulos para las Cuentas exogenas */ |
---|
1290 | QTableWidgetItem *CuentaExogenafila = new QTableWidgetItem("Cuentas Exogenas"); |
---|
1291 | CuentaExogenafila->setFlags(CuentaExogenafila->flags() ^ Qt::ItemIsEditable); |
---|
1292 | CuentaExogenafila->setTextAlignment(Qt::AlignCenter); |
---|
1293 | tw->setItem(0,inicioExogena,CuentaExogenafila); |
---|
1294 | if(elementos>1) |
---|
1295 | { |
---|
1296 | tw->setSpan(0,inicioExogena,1,elementos); |
---|
1297 | } |
---|
1298 | QTableWidgetItem *CuentaExogenaColumna = new QTableWidgetItem; |
---|
1299 | if(elementos<12) |
---|
1300 | { |
---|
1301 | CuentaExogenaColumna->setText("Cuenta \nExogena"); |
---|
1302 | } |
---|
1303 | else |
---|
1304 | { |
---|
1305 | CuentaExogenaColumna->setText("C\nu\ne\nn\nt\na\ns\n\nE\nx\no\ng\ne\nn\na\ns"); |
---|
1306 | } |
---|
1307 | CuentaExogenaColumna->setFlags(CuentaExogenaColumna->flags() ^ Qt::ItemIsEditable); |
---|
1308 | tw->setItem(inicioExogena,0,CuentaExogenaColumna); |
---|
1309 | if(elementos>1) |
---|
1310 | { |
---|
1311 | tw->setSpan(inicioExogena,0,elementos,1); |
---|
1312 | } |
---|
1313 | } |
---|
1314 | } |
---|
1315 | |
---|
1316 | void MainWindow::CalcularAn(QTableWidget *tw,QTableWidget *nuevaTabla,int count,bool exogena)//Funcion para calcular el Coeficiente Tecnico Horizontal (An) |
---|
1317 | { |
---|
1318 | if(exogena) |
---|
1319 | { |
---|
1320 | tw->removeRow(0); |
---|
1321 | tw->removeColumn(0); |
---|
1322 | count=tw->rowCount(); |
---|
1323 | } |
---|
1324 | /***** Se llena la tabla vacia con los valores de la tabla principal ****/ |
---|
1325 | for(int i=0;i<count-1;i++) |
---|
1326 | { |
---|
1327 | double total=tw->item(i,count-1)->text().toDouble();//Se obtiene el total de esa columna |
---|
1328 | for(int j=0;j<count-1;j++) |
---|
1329 | { |
---|
1330 | if(i!=0 && j!=0) |
---|
1331 | { |
---|
1332 | double valor=tw->item(i,j)->text().toDouble(); |
---|
1333 | if(total==0)//Se comprueba en caso de que el total sea zero |
---|
1334 | { |
---|
1335 | valor=0; |
---|
1336 | } |
---|
1337 | else |
---|
1338 | { |
---|
1339 | valor/=total;//Se divide el valor de la celda entre el total correspondiente |
---|
1340 | } |
---|
1341 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(QString::number(valor,'f',4)); |
---|
1342 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
1343 | nuevaTabla->setItem(i,j,ValoraInsertar); |
---|
1344 | } |
---|
1345 | /**** En este else se llenan las celdas con fila y columna 0, es decir las que tienen nombre *****/ |
---|
1346 | else if((i==0 && j>0)||(j==0 && i>0)) |
---|
1347 | { |
---|
1348 | QString value=tw->item(i,j)->text(); |
---|
1349 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(value); |
---|
1350 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
1351 | nuevaTabla->setItem(i,j,ValoraInsertar); |
---|
1352 | } |
---|
1353 | } |
---|
1354 | |
---|
1355 | } |
---|
1356 | if(exogena) |
---|
1357 | { |
---|
1358 | if(opcionCuentaExogena==1) |
---|
1359 | { |
---|
1360 | int elementos = contarElementosMap(); |
---|
1361 | int inicioExogena=count-elementos; |
---|
1362 | //setEndogenaExogenaCell(nuevaTabla,inicioExogena,elementos,count-1,true); |
---|
1363 | setEndogenaExogenaCell(tw,inicioExogena,elementos,true); |
---|
1364 | } |
---|
1365 | else |
---|
1366 | { |
---|
1367 | //setEndogenaExogenaCell(nuevaTabla,count,0,count,false); |
---|
1368 | setEndogenaExogenaCell(tw,count,0,false); |
---|
1369 | } |
---|
1370 | } |
---|
1371 | } |
---|
1372 | |
---|
1373 | void MainWindow::clonarTabla(QTableWidget *tw,QTableWidget *nuevaTabla,int cantidad) |
---|
1374 | { |
---|
1375 | for(int i=0;i<cantidad-1;i++) |
---|
1376 | { |
---|
1377 | for(int j=0;j<cantidad-1;j++) |
---|
1378 | { |
---|
1379 | if(i!=0 && j!=0) |
---|
1380 | { |
---|
1381 | double valor=tw->item(i,j)->text().toDouble(); |
---|
1382 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(QString::number(valor,'f',4)); |
---|
1383 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
1384 | nuevaTabla->setItem(i,j,ValoraInsertar); |
---|
1385 | } |
---|
1386 | else if((i==0 && j>0)||(j==0 && i>0)) |
---|
1387 | { |
---|
1388 | QString value=tw->item(i,j)->text(); |
---|
1389 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(value); |
---|
1390 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
1391 | nuevaTabla->setItem(i,j,ValoraInsertar); |
---|
1392 | } |
---|
1393 | |
---|
1394 | } |
---|
1395 | } |
---|
1396 | } |
---|
1397 | |
---|
1398 | void MainWindow::crearMatrizEndogena(QTableWidget *tw) |
---|
1399 | { |
---|
1400 | int cantidad=tw->rowCount(); |
---|
1401 | for(int i=0;i<cantidad-1;i++) |
---|
1402 | { |
---|
1403 | for(int j=0;j<cantidad-1;j++) |
---|
1404 | { |
---|
1405 | if(i!=0 && j!=0) |
---|
1406 | { |
---|
1407 | double valor=tw->item(i,j)->text().toDouble(); |
---|
1408 | MatrizEndogenaEndogena[i-1][j-1]=valor; |
---|
1409 | } |
---|
1410 | |
---|
1411 | } |
---|
1412 | } |
---|
1413 | } |
---|
1414 | |
---|
1415 | void MainWindow::crearMatrizIdentidad(QTableWidget *tw,double identidad[200][200]) |
---|
1416 | { |
---|
1417 | int cantidad=tw->rowCount(); |
---|
1418 | for(int i=0;i<cantidad-1;i++) |
---|
1419 | { |
---|
1420 | for(int j=0;j<cantidad-1;j++) |
---|
1421 | { |
---|
1422 | if(i==j) |
---|
1423 | { |
---|
1424 | identidad[i][j]=1; |
---|
1425 | } |
---|
1426 | else |
---|
1427 | { |
---|
1428 | identidad[i][j]=0; |
---|
1429 | } |
---|
1430 | |
---|
1431 | } |
---|
1432 | } |
---|
1433 | } |
---|
1434 | |
---|
1435 | void MainWindow::restarIdentidadAn(QTableWidget *tw,double identidad[200][200],double resta[200][200]) |
---|
1436 | { |
---|
1437 | int cantidad=tw->rowCount(); |
---|
1438 | mat A(cantidad,cantidad); |
---|
1439 | for(int i=0;i<cantidad-1;i++) |
---|
1440 | { |
---|
1441 | for(int j=0;j<cantidad-1;j++) |
---|
1442 | { |
---|
1443 | resta[i][j] = identidad[i][j]-MatrizEndogenaEndogena[i][j]; |
---|
1444 | //qDebug()<<"A"<<resta[i][j]; |
---|
1445 | A.at(i,j) = resta[i][j]; |
---|
1446 | //qDebug()<<"resta"<<A.at(i,j); |
---|
1447 | |
---|
1448 | } |
---|
1449 | } |
---|
1450 | /* mat A; |
---|
1451 | A << 1 << 2.2222 << 3 << 4 << endr |
---|
1452 | << 2 << 1 << 5 << 6 << endr |
---|
1453 | << 3 << 5 << 1 << 7 <<endr |
---|
1454 | << 4 << 6 << 7 << 1<<endr;*/ |
---|
1455 | //qDebug()<<"here"<<A.at(0,8); |
---|
1456 | //qDebug()<<"resta"<<resta[0][8]; |
---|
1457 | double determinant = det(A); |
---|
1458 | qDebug() << isnan(determinant); |
---|
1459 | /* |
---|
1460 | mat inverse = inv(A); |
---|
1461 | for(int i=0;i<4-1;i++) |
---|
1462 | { |
---|
1463 | for(int j=0;j<4-1;j++) |
---|
1464 | { |
---|
1465 | qDebug()<<"inversa"<<inverse.at(i,j); |
---|
1466 | |
---|
1467 | } |
---|
1468 | }*/ |
---|
1469 | |
---|
1470 | qDebug()<<"determinant"<<determinant; |
---|
1471 | if(determinant < -std::numeric_limits<qreal>::max()) |
---|
1472 | { |
---|
1473 | qDebug()<<"-inf"; |
---|
1474 | } |
---|
1475 | else if(determinant > std::numeric_limits<qreal>::max()) |
---|
1476 | { |
---|
1477 | qDebug()<<"inf"; |
---|
1478 | } |
---|
1479 | else if(determinant != determinant) |
---|
1480 | { |
---|
1481 | qDebug()<< "nan"; |
---|
1482 | } |
---|
1483 | |
---|
1484 | |
---|
1485 | |
---|
1486 | } |
---|
1487 | |
---|
1488 | /* Funcion para volver la celda(0,0) no editable */ |
---|
1489 | void MainWindow::noEditColZero(QTableWidget *tw) |
---|
1490 | { |
---|
1491 | QTableWidgetItem *ValoraInsertar = new QTableWidgetItem; |
---|
1492 | ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable); |
---|
1493 | tw->setItem(0,0,ValoraInsertar); |
---|
1494 | } |
---|
1495 | |
---|
1496 | /* Funcion para colocar los titulos de las cuentas */ |
---|
1497 | void MainWindow::setAccountTitle(QTableWidget *tw) |
---|
1498 | { |
---|
1499 | for(int i=0;i<numAccounts;i++) |
---|
1500 | { |
---|
1501 | QLineEdit *le= findChild<QLineEdit *>(QString("linedit %1").arg(i + 1)); |
---|
1502 | QSpinBox *SBStart = findChild<QSpinBox *>(QString("accountstart %1").arg(i+1)); |
---|
1503 | QSpinBox *SBEnd = findChild<QSpinBox *>(QString("accountend %1").arg(i+1)); |
---|
1504 | |
---|
1505 | int inicio=SBStart->value(); |
---|
1506 | int fin=SBEnd->value(); |
---|
1507 | QString nombreCuenta=le->text(); |
---|
1508 | |
---|
1509 | |
---|
1510 | QTableWidgetItem *ValoraInsertarFila = new QTableWidgetItem(nombreCuenta); |
---|
1511 | ValoraInsertarFila->setTextAlignment(Qt::AlignCenter); |
---|
1512 | ValoraInsertarFila->setFlags(ValoraInsertarFila->flags() ^ Qt::ItemIsEditable); |
---|
1513 | tw->setItem(0,inicio-1,ValoraInsertarFila); |
---|
1514 | QTableWidgetItem *ValoraInsertarColumna = new QTableWidgetItem(nombreCuenta); |
---|
1515 | ValoraInsertarColumna->setTextAlignment(Qt::AlignCenter); |
---|
1516 | ValoraInsertarColumna->setFlags(ValoraInsertarColumna->flags() ^ Qt::ItemIsEditable); |
---|
1517 | tw->setItem(inicio-1,0,ValoraInsertarColumna); |
---|
1518 | int espacio=(fin-inicio)+1; |
---|
1519 | tw->setSpan(inicio-1,0,espacio,1); |
---|
1520 | tw->setSpan(0,inicio-1,1,espacio); |
---|
1521 | } |
---|
1522 | } |
---|
1523 | |
---|
1524 | void MainWindow::insertremoveRowCol(QTableWidget *tw, int rowcol, bool opcion) |
---|
1525 | { |
---|
1526 | if(opcion)//Si la opcion es verdadero se agrega |
---|
1527 | { |
---|
1528 | tw->insertRow(rowcol); |
---|
1529 | tw->insertColumn(rowcol); |
---|
1530 | } |
---|
1531 | else//de lo contrario se remueve |
---|
1532 | { |
---|
1533 | tw->removeColumn(rowcol); |
---|
1534 | tw->removeRow(rowcol); |
---|
1535 | } |
---|
1536 | } |
---|