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