source: mmcs/mainwindow.C @ bd5e45b

matrices
Last change on this file since bd5e45b was bd5e45b, checked in by rboet <rboet@…>, 9 years ago

Traducción de los botones de diálogo, primer prototipo de matriz La

  • Property mode set to 100644
File size: 66.5 KB
Line 
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
11using namespace arma;
12
13void 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
21void 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}
105void 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
115void MainWindow::initGUI()
116{
117    createMenuBar();
118    createCentralWidget();
119}
120
121void 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
162void 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
180void 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    actionAn.setText("Coeficientes &Horizontales");
199    actionAn.setDisabled(true);
200    EndoExo.addAction(&actionAn);
201
202    actionLa.setText("Multiplicadores de &Leontief");
203    actionLa.setDisabled(true);
204    EndoExo.addAction(&actionLa);
205
206    OpMatrices.addMenu(&EndoExo);
207
208    actionEncadenamiento.setText("Encadenamientos");
209    actionEncadenamiento.setDisabled(true);
210    OpMatrices.addAction(&actionEncadenamiento);
211
212
213    menuBar()->addMenu(&OpMatrices);
214}
215
216MainWindow::MainWindow()
217    : actionLoadMatrix(this), actionExportMatrix(this), actionQuit(this),actionCH(this), actionCV(this),
218      actionVariableExogena(this),actionAn(this),actionLa(this),actionEncadenamiento(this), formLoadMatrix(0)
219{
220    tabWidget = new QTabWidget;
221
222    /*    Opcion de la cuenta exogena, 0 para decir que nos se selecciono ninguna, 1 que se seleccionaron algunas
223                                    y 2 para decir que se seleccionaron todas*/
224    opcionCuentaExogena = 0;
225    opcionVentanaExogena = 0;
226    opcionExportarMatriz = 0;
227
228    initGUI();
229
230    connect(&actionLoadMatrix, SIGNAL(triggered()), this,
231            SLOT(slotLoadMatrix()));
232    connect(&actionExportMatrix, SIGNAL(triggered()), this,
233            SLOT(slotExportMatrix()));
234    connect(&actionQuit, SIGNAL(triggered()), this, SLOT(close()));
235   
236    showMaximized();
237}
238
239void MainWindow::slotFormLoadMatrixAccepted(const QString & filePath,
240                                            int accountNumber, char sep)
241{
242    QString msg = "Archivo: " + filePath + "\nNúmero de cuentas: " +
243                   QString().setNum(accountNumber) +
244                   "\nSeparador: " + sep;
245
246    csvFilePath = filePath;
247    csvSeparator = sep;
248    numAccounts = accountNumber;
249
250    createMatrixCentralWidget();
251}
252
253void MainWindow::slotFormLoadMatrixClosed()
254{
255    disconnect(formLoadMatrix, SIGNAL(formAccepted(QString,int,char)),
256               this, SLOT(slotFormLoadMatrixAccepted(QString,int,char)));
257    formLoadMatrix = 0;
258}
259
260void MainWindow::slotVariableExogena()
261{
262    if(opcionVentanaExogena==0)
263    {
264        formVariablesExogenas = new FormVariablesExogenas(this);
265        QHBoxLayout * layoutLateralWidget = new QHBoxLayout;
266        QVBoxLayout * layoutCentralWidget = new QVBoxLayout;
267        QHBoxLayout * layoutAccounts = new QHBoxLayout;
268        QHBoxLayout * labels = new QHBoxLayout;
269        QLabel *label1 = new QLabel;
270        QLabel *label2 = new QLabel;
271        label1->setText("Cuentas");
272        label2->setText("Componentes");
273        labels->addWidget(label1);
274        labels->addWidget(label2);
275        QWidget *nw = new QWidget;
276        nw->setLayout(labels);
277        QGroupBox * groupBoxAccount = new QGroupBox;
278        layoutCentralWidget->addWidget(nw);
279        /***        Se obtiene la cantidad de cuentas       ***/
280        StackWidget *sw = findChild<StackWidget *>("");
281        int cantidad=sw->comboAccount->count();
282        QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal");
283        /***        Se obtiene el nombre de las cuentas,sus componentes, su inicio y su fin en varias listas        ***/
284        insertremoveRowCol(tw,0,false);
285        QStringList Lista = ObtenerNombreCuenta(cantidad);
286        QStringList Componentes = ObtenerComponentes(tw);
287        QList <int> inicio = ObtenerLimitesCuenta(cantidad,0);
288        QList <int> fin = ObtenerLimitesCuenta(cantidad,1);
289        layoutAccounts->addWidget(stackVE=new stackVariablesExogenas(Lista,Componentes,inicio,fin,groupBoxAccount,cantidad));
290        insertremoveRowCol(tw,0,true);
291        setAccountTitle(tw);
292
293        groupBoxAccount->setObjectName("exogenasBoxAccount");//Se le asigna nombre al objeto
294        groupBoxAccount->setLayout(layoutAccounts);;
295        groupBoxAccount->setStyleSheet("QGroupBox {border: 1px solid gray; "
296                         "border-radius: 3px; margin-top: 0.5em;} "
297                         "QGroupBox::title { subcontrol-origin: margin; "
298                         "left: 10px; padding: 0 3px 0 3px; } ");
299
300
301        layoutLateralWidget->addWidget(groupBoxAccount);
302
303        /***        Se crean y personalizan los bottones para agregar, finalizar, deshacer y cancelar    ***/
304        QPushButton * buttonAgregar = new QPushButton;
305        buttonAgregar->setObjectName("AgregarExogena");//Se le asigna nombre al objeto
306        buttonAgregar->setText("Agregar");
307        buttonAgregar->setFixedWidth(130);
308        buttonAgregar->setStyleSheet("background-color: #358ccb; color: #fff;"
309                                 "font-weight: bold; height: 30px; border: none;"
310                                 "border-radius: 5px; margin-top: 40px;");
311        QPushButton * buttonCancelar = new QPushButton;
312        buttonCancelar->setObjectName("CancelarExogena");//Se le asigna nombre al objeto
313        buttonCancelar->setText("Cancelar");
314        buttonCancelar->setFixedWidth(130);
315        buttonCancelar->setStyleSheet("background-color: #358ccb; color: #fff;"
316                                 "font-weight: bold; height: 30px; border: none;"
317                                 "border-radius: 5px; margin-top: 40px;");
318        QPushButton * buttonFinalizar = new QPushButton;
319        buttonFinalizar->setObjectName("FinalizarExogena");//Se le asigna nombre al objeto
320        buttonFinalizar->setText("Finalizar");
321        buttonFinalizar->setFixedWidth(130);
322        buttonFinalizar->setStyleSheet("background-color: #358ccb; color: #fff;"
323                                 "font-weight: bold; height: 30px; border: none;"
324                                 "border-radius: 5px; margin-top: 40px;");
325        QPushButton * buttonDeshacer = new QPushButton;
326        buttonDeshacer->setObjectName("DeshacerExogena");//Se le asigna nombre al objeto
327        buttonDeshacer->setText("Deshacer");
328        buttonDeshacer->setFixedWidth(130);
329        buttonDeshacer->setStyleSheet("background-color: #358ccb; color: #fff;"
330                                 "font-weight: bold; height: 30px; border: none;"
331                                 "border-radius: 5px; margin-top: 40px;");
332
333        connect(buttonCancelar,SIGNAL(clicked()),this,SLOT(slotCloseExogena()));
334        connect(buttonAgregar,SIGNAL(clicked()),this,SLOT(slotAgregarExogena()));
335        connect(buttonFinalizar,SIGNAL(clicked()),this,SLOT(slotFinalizarExogena()));
336        connect(buttonDeshacer,SIGNAL(clicked()),this,SLOT(slotDeshacerExogena()));
337
338
339        QHBoxLayout * layoutsButtons = new QHBoxLayout;
340        layoutsButtons->addWidget(buttonFinalizar);
341        layoutsButtons->addWidget(buttonAgregar);
342        layoutsButtons->addWidget(buttonDeshacer);
343        layoutsButtons->addWidget(buttonCancelar);
344        QWidget *buttonWidget = new QWidget;
345        buttonWidget->setLayout(layoutsButtons);
346
347        QWidget *widget = new QWidget;
348        widget->setLayout(layoutLateralWidget);
349        layoutCentralWidget->addWidget(widget);
350        layoutCentralWidget->addWidget(buttonWidget);//Se agregan los botones
351        formVariablesExogenas->setLayout(layoutCentralWidget);
352        formVariablesExogenas->show();
353        opcionVentanaExogena=1;
354    }
355    else
356    {
357        formVariablesExogenas->show();
358    }
359}
360
361
362void MainWindow::slotCoeficienteHorizontal()
363{
364    actionCH.setDisabled(true);
365    tabWidget->addTab(new QWidget,"CT_Horizontal");
366    QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal");
367
368    /*      Se eliminan la fila y columna (0,0) para los calculos*/
369    insertremoveRowCol(tw,0,false);
370
371    QTableWidget *CT_HorizontalTW = new QTableWidget;
372    int count=tw->rowCount();
373    CrearTablaVacia(count,CT_HorizontalTW);//Se crea una tabla vacia
374    /* ****     Se coloca como no editable la celda(0,0)    ***** */
375    noEditColZero(CT_HorizontalTW);
376    /*****      Se llena la tabla vacia con los valores de la tabla principal ****/
377
378    CalcularAn(tw,CT_HorizontalTW,new QTableWidget,count,false);//Funcion para calcular el Coeficiente Tecnico Horizontal (An)
379
380    /*      Se agrega la columna y fila (0,0) y se insertan los titulos de las cuentas      */
381    insertremoveRowCol(tw,0,true);
382    insertremoveRowCol(CT_HorizontalTW,0,true);
383    setAccountTitle(tw);
384    setAccountTitle(CT_HorizontalTW);
385
386    int indice=ObtenerIndice("CT_Horizontal");//Se obtiene el indice de la pestaña
387    QHBoxLayout * layoutCentralWidget = new QHBoxLayout;
388    layoutCentralWidget->addWidget(CT_HorizontalTW);
389    QWidget *widget = tabWidget->widget(indice);
390    widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada
391
392}
393
394void MainWindow::slotCoeficienteVertical()
395{
396    actionCV.setDisabled(true);
397    tabWidget->addTab(new QWidget,"CT_Vertical");
398    QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal");
399
400    /*      Se eliminan la fila y columna (0,0) para los calculos*/
401    insertremoveRowCol(tw,0,false);
402
403    int count=tw->rowCount();
404    QTableWidget *CT_VerticalTW = new QTableWidget;
405    CrearTablaVacia(count,CT_VerticalTW); //Se Crea la tabla vacia
406    /* ****     Se coloca como no editable la celda(0,0)    ***** */
407    noEditColZero(CT_VerticalTW);
408    /*****      Se llena la tabla vacia con los valores de la tabla principal ****/
409    for(int i=0;i<count-1;i++)
410    {
411        QString STotal = Separador(tw->item(i,count-1),true);
412        double total=STotal.toDouble();//Se obtiene el total de esa columna
413        for(int j=0;j<count-1;j++)
414        {
415            if(i!=0 && j!=0)
416            {
417                QString value = Separador(tw->item(i,j),true);
418                double valor=value.toDouble();
419                if(total==0)//Se comprueba en caso de que el total sea zero
420                {
421                    valor=0;
422                }
423                else
424                {
425                    valor/=total;//Se divide el valor de la celda entre el total correspondiente
426                }
427                QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(QString::number(valor,'f',2));
428                ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable);
429                value = Separador(ValoraInsertar,false);
430                ValoraInsertar->setText(value);
431                CT_VerticalTW->setItem(i,j,ValoraInsertar);
432            }
433            /****           En este else se llenan las celdas con fila y columna 0, es decir las que tienen nombre *****/
434            else if((i==0 && j>0)||(j==0 && i>0))
435            {
436                QString value=tw->item(j,i)->text();
437                QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(value);
438                ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable);
439                CT_VerticalTW->setItem(j,i,ValoraInsertar);
440            }
441
442         }
443    }
444    /*      Se agrega la columna y fila (0,0) y se insertan los titulos de las cuentas      */
445    insertremoveRowCol(tw,0,true);
446    insertremoveRowCol(CT_VerticalTW,0,true);
447    setAccountTitle(tw);
448    setAccountTitle(CT_VerticalTW);
449
450    int indice=ObtenerIndice("CT_Vertical");//Se obtiene el indice de la pestaña
451    QHBoxLayout * layoutCentralWidget = new QHBoxLayout;
452    layoutCentralWidget->addWidget(CT_VerticalTW);
453    QWidget *widget = tabWidget->widget(indice);
454    widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada
455}
456
457void MainWindow::slotCloseExogena()
458{
459    formVariablesExogenas->close();
460}
461
462void MainWindow::slotDeshacerExogena()
463{
464    QMessageBox msBox(QMessageBox::Question,"Deshacer","¿Desea deshacer todos los cambios?",
465                      QMessageBox::Yes | QMessageBox::No,this);
466    msBox.setButtonText(QMessageBox::Yes,"Si");
467    msBox.setDefaultButton(QMessageBox::Yes);
468    if(msBox.exec()==QMessageBox::Yes)
469    {
470        int cantidad=stackVE->comboAccount->count();
471        /*   Se habilitan todas cuentas   */
472        for(int i=0;i<cantidad;i++)
473        {
474            QListWidget *lw=new QListWidget;
475            lw= stackVE->veWidget->accounListWidget;
476            lw = findChild<QListWidget *>(QString("accountlist %1").arg(i + 1));
477            lw->setEnabled(true);
478        }
479        diccCuentasExogenas.clear();//Se limpia el diccionario
480    }
481}
482
483void MainWindow::slotAgregarExogena()
484{
485    actionVariableExogena.setDisabled(true);//Se deshabilita la oipcion de agregar variables exogenas
486    QString nombre_cuenta=stackVE->comboAccount->currentText();//Se obtiene el nombre de la cuenta seleccionado
487    QListWidget *lw=new QListWidget;
488    lw=stackVE->veWidget->accounListWidget;
489    int index=stackVE->comboAccount->currentIndex();//Se obtiene el indice selecionado
490    lw = findChild<QListWidget *>(QString("accountlist %1").arg(index + 1));//Se obtiene la lista seleccionada
491    QStringList componentes_cuenta;
492
493    if(nombre_cuenta!="Todas las Cuentas")
494    {
495        if(!lw->isEnabled())
496        {
497            QMessageBox::warning(this,"Alerta","La Cuenta Actual ya fue Agregada");
498        }
499        else if(lw->selectedItems().count()==0)
500        {
501            QMessageBox::warning(this,"Alerta",
502                                 "Para Agregar la Cuenta debe seleccionar \n al menos un valor");
503        }
504        else
505        {
506            int contar=lw->selectedItems().count();
507            for(int i=0;i<contar;i++)
508            {
509                componentes_cuenta.append(lw->selectedItems().value(i)->text());
510            }
511            lw->setDisabled(true);
512            opcionCuentaExogena=1;//Se establece un valor para la variable de la opcion
513            diccCuentasExogenas.insert(nombre_cuenta,componentes_cuenta);
514        }
515    }
516    else
517    {
518        int cantidad=stackVE->comboAccount->count();
519        for(int i=0;i<cantidad;i++)
520        {
521            QListWidget *lw=new QListWidget;
522            lw=stackVE->veWidget->accounListWidget;
523            lw = findChild<QListWidget *>(QString("accountlist %1").arg(i + 1));//Se obtiene la lista seleccionada
524            lw->setDisabled(true);
525            opcionCuentaExogena=2;//Se establece un valor para la variable de la opcion
526        }
527
528    }
529
530}
531
532void MainWindow::slotFinalizarExogena()
533{
534    QTableWidget *tablaEE = new QTableWidget;
535    tablaEE->setObjectName("TablaExogenaEndogena");
536    QTableWidget *tablaPPAL = findChild<QTableWidget *>("TablaPrincipal");//Se carga la tabla principal
537    insertremoveRowCol(tablaPPAL,0,false);
538    int count=tablaPPAL->rowCount();
539    CrearTablaVacia(count,tablaEE);//Se crea la tabla vacia
540    /* ****     Se coloca como no editable la celda(0,0)    ***** */
541    noEditColZero(tablaEE);
542    if(opcionCuentaExogena==1)//Si seleccionaron componentes
543    {
544
545        int elementos = contarElementosMap();
546
547        /*****      Se llena la tabla vacia con los valores de la tabla principal ****/
548        for(int i=0;i<count-1;i++)
549        {
550            for(int j=0;j<count-1;j++)
551            {
552                if(i!=0 && j!=0)
553                {
554                    QString value = Separador(tablaPPAL->item(i,j),true);
555                    double valor=value.toDouble();
556                    QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(QString::number(valor,'f',2));
557                    value = Separador(ValoraInsertar,false);
558                    ValoraInsertar->setText(value);
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        /***                    Se acomodan los componentes de las cuentas exogenas                 ***/
575
576        foreach(QString key,diccCuentasExogenas.keys())
577        {
578            int indiceCuenta=retornarIndiceCuenta(key);
579            QSpinBox *SBinicio = findChild<QSpinBox *>(QString("accountstart %1").arg(indiceCuenta+1));
580            QSpinBox *SBFin = findChild<QSpinBox *>(QString("accountend %1").arg(indiceCuenta+1));
581            int inicio=SBinicio->text().toInt();
582            int fin=SBFin->text().toInt();
583            foreach(QString key2,diccCuentasExogenas[key])
584            {
585                for(int i=inicio;i<fin+1;i++)
586                {
587                    QString item=tablaEE->item(0,i)->text();
588                    if(item==key2)
589                    {
590                        QList<QString> fila;
591                        fila=llenarLista(fila,tablaEE,i,1);
592                        tablaEE->removeRow(i);
593                        tablaEE->insertRow(tablaEE->rowCount());
594                        insertRowExogena(fila,tablaEE,1);
595                        fila.clear();
596
597                        QList<QString> columna;
598                        columna=llenarLista(columna,tablaEE,i,0);
599                        tablaEE->removeColumn(i);
600                        tablaEE->insertColumn(tablaEE->columnCount());
601                        insertRowExogena(columna,tablaEE,0);
602                        columna.clear();
603
604                    }
605                }
606            }
607        }
608
609        int inicioExogena=count-elementos;
610
611        QTableWidget *matrizEndogena = new QTableWidget;
612        matrizEndogena->setObjectName("MatrizEndogenaEndogena");
613        CrearTablaVacia(inicioExogena,matrizEndogena);
614        QTableWidgetItem *ValoraInsertar = new QTableWidgetItem("");
615        ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable);
616        matrizEndogena->setItem(0,0,ValoraInsertar);
617
618
619        clonarTabla(tablaEE,matrizEndogena,inicioExogena);
620        CalcularTotales(matrizEndogena,1);
621
622        setEndogenaExogenaCell(tablaEE,inicioExogena,elementos,true);
623        CalcularTotales(tablaEE,2);
624
625        //Se crea la nueva pestaña
626        tabWidget->addTab(new QWidget,"Endogena-Exogena");
627        int indice=ObtenerIndice("Endogena-Exogena");//Se obtiene el indice de la pestaña
628        QHBoxLayout * layoutCentralWidget = new QHBoxLayout;
629        layoutCentralWidget->addWidget(tablaEE);
630        QWidget *widget = tabWidget->widget(indice);
631        widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada
632        formVariablesExogenas->close();
633        connect(&actionAn,SIGNAL(triggered()),this,SLOT(slotAn()));
634        actionAn.setEnabled(true);
635
636        /*                  Se crea la pestaña endogena-endogena            */
637        tabWidget->addTab(new QWidget,"Endogena-Endogena");
638        int indiceEndogeno=ObtenerIndice("Endogena-Endogena");//Se obtiene el indice de la pestaña
639        QHBoxLayout * layoutEndogeno = new QHBoxLayout;
640        layoutEndogeno->addWidget(matrizEndogena);
641        QWidget *widgetEndogeno = tabWidget->widget(indiceEndogeno);
642        widgetEndogeno->setLayout(layoutEndogeno);//Se añade el widget y layout a la pestaña creada
643
644    }
645    else if(opcionCuentaExogena==2)//Si se seleccionaron todas las cuentas
646    {
647
648        /*****      Se llena la tabla vacia con los valores de la tabla principal ****/
649        for(int i=0;i<count-1;i++)
650        {
651            for(int j=0;j<count-1;j++)
652            {
653                if(i!=0 && j!=0)
654                {
655                    QString value = Separador(tablaPPAL->item(i,j),true);
656                    double valor=value.toDouble();
657                    QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(QString::number(valor,'f',2));
658                    value = Separador(ValoraInsertar,false);
659                    ValoraInsertar->setText(value);
660                    ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable);
661                    tablaEE->setItem(i,j,ValoraInsertar);
662                }
663                /****           En este else se llenan las celdas con fila y columna 0, es decir las que tienen nombre *****/
664                else if((i==0 && j>0)||(j==0 && i>0))
665                {
666                    QString value=tablaPPAL->item(i,j)->text();
667                    QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(value);
668                    ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable);
669                    tablaEE->setItem(i,j,ValoraInsertar);
670                }
671
672             }
673        }
674
675        QTableWidget *matrizEndogena = new QTableWidget;
676        matrizEndogena->setObjectName("MatrizEndogenaEndogena");
677        CrearTablaVacia(count,matrizEndogena);
678        QTableWidgetItem *ValoraInsertar = new QTableWidgetItem("");
679        ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable);
680        matrizEndogena->setItem(0,0,ValoraInsertar);
681
682
683        clonarTabla(tablaEE,matrizEndogena,count);
684        CalcularTotales(matrizEndogena,1);
685
686        setEndogenaExogenaCell(tablaEE,count,0,false);
687        CalcularTotales(tablaEE,2);
688
689        //Se agrega la nueva pestaña
690        tabWidget->addTab(new QWidget,"Endogena-Exogena");
691        int indice=ObtenerIndice("Endogena-Exogena");//Se obtiene el indice de la pestaña
692        QHBoxLayout * layoutCentralWidget = new QHBoxLayout;
693        layoutCentralWidget->addWidget(tablaEE);
694        QWidget *widget = tabWidget->widget(indice);
695        widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada
696        formVariablesExogenas->close();
697        connect(&actionAn,SIGNAL(triggered()),this,SLOT(slotAn()));
698        actionAn.setEnabled(true);
699
700        /*                  Se crea la pestaña endogena-endogena            */
701        tabWidget->addTab(new QWidget,"Endogena-Endogena");
702        int indiceEndogeno=ObtenerIndice("Endogena-Endogena");//Se obtiene el indice de la pestaña
703        QHBoxLayout * layoutEndogeno = new QHBoxLayout;
704        layoutEndogeno->addWidget(matrizEndogena);
705        QWidget *widgetEndogeno = tabWidget->widget(indiceEndogeno);
706        widgetEndogeno->setLayout(layoutEndogeno);//Se añade el widget y layout a la pestaña creada
707
708
709    }
710    else
711    {
712        QMessageBox::warning(this,"Alerta","No Selecciono alguna opción");
713    }
714    insertremoveRowCol(tablaPPAL,0,true);
715    setAccountTitle(tablaPPAL);
716}
717
718/***        Slot para calcular el coeficiente tecnico horizontal de la matriz endogena/exogena      ***/
719void MainWindow::slotAn()
720{
721    actionAn.setDisabled(true);
722    tabWidget->addTab(new QWidget,"An");
723    QTableWidget *tw = findChild<QTableWidget *>("MatrizEndogenaEndogena");
724    QTableWidget *to = findChild<QTableWidget *>("TablaExogenaEndogena");
725    QTableWidget *tablaAn = new QTableWidget;
726    tablaAn->setObjectName("MatrizAn");
727    int count=tw->rowCount();
728    CrearTablaVacia(count,tablaAn);//Se crea una tabla vacia
729    /* ****     Se coloca como no editable la celda(0,0)    ***** */
730    noEditColZero(tablaAn);
731    /*****      Se llena la tabla vacia con los valores de la tabla principal ****/
732
733    insertremoveRowCol(to,0, false);
734    CalcularAn(tw,tablaAn,to,count,true);//Funcion para calcular el Coeficiente Tecnico Horizontal (An)
735    /***            Procedimiento para obtener la matriz con los totales originales para luegos ser usados en An ***/
736    int elementos = contarElementosMap();
737    count=to->rowCount()-1;
738    if(opcionCuentaExogena==1)
739    {
740        int inicioExogena=count-elementos;
741        setEndogenaExogenaCell(to,inicioExogena+1,elementos,true);
742    }
743    else
744    {
745        setEndogenaExogenaCell(to,count,0,false);
746    }
747
748    int indice=ObtenerIndice("An");//Se obtiene el indice de la pestaña
749    QHBoxLayout * layoutCentralWidget = new QHBoxLayout;
750    layoutCentralWidget->addWidget(tablaAn);
751    QWidget *widget = tabWidget->widget(indice);
752    widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada
753
754    crearMatrizEndogena(tablaAn);
755    connect(&actionLa,SIGNAL(triggered()),this,SLOT(slotLa()));
756    actionLa.setEnabled(true);
757}
758
759void MainWindow::slotLa()
760{
761    QTableWidget *tw = findChild<QTableWidget *>("MatrizAn");
762    double matrizIdentidad[200][200];
763    double matrizResta[200][200];
764    crearMatrizIdentidad(tw,matrizIdentidad);
765    restarIdentidadAn(tw,matrizIdentidad,matrizResta);
766}
767
768int MainWindow::ObtenerIndice(QString text)//Funcion para obtener el indice de una pestaña buscada por un nombre dado
769{
770    int cantidad=tabWidget->count();
771    int indice=0;
772    for(int i=0;i<cantidad;i++)
773    {
774        if(tabWidget->tabText(i)==text)
775        {
776            indice=i;
777            break;
778        }
779    }
780    return indice;
781}
782
783
784void MainWindow::createMatrixCentralWidget()
785{
786    QHBoxLayout * layoutCentralWidget = new QHBoxLayout;
787    QVBoxLayout * layoutLateralWidget = new QVBoxLayout;
788
789    QTableWidget * tableWidget = new QTableWidget(this);
790    tableWidget->setObjectName("TablaPrincipal");//Se le asigna nombre al objeto
791    QGroupBox * groupBoxAccount = new QGroupBox;
792    QPushButton * buttonEnd = new QPushButton;
793    buttonEnd->setObjectName("AgregarCuentas");//Se le asigna nombre al objeto
794    QPushButton * buttonRestaurar = new QPushButton;
795    buttonRestaurar->setObjectName("Restaurar");//Se le asigna nombre al objeto
796    QPushButton * buttonFinalizar = new QPushButton;
797    buttonFinalizar->setObjectName("Finalizar");//Se le asigna nombre al objeto
798    QPushButton * buttonModificar = new QPushButton;
799    buttonModificar->setObjectName("Modificar");//Se le asigna nombre al objeto
800
801    populateTable(tableWidget);
802    tableWidget->setMaximumHeight(700);
803
804    /* ****     Se coloca como no editable la celda(0,0)    ***** */
805    noEditColZero(tableWidget);
806
807    //tableWidget->setFixedSize(750,750);
808    layoutCentralWidget->addWidget(tableWidget);
809    //layoutCentralWidget->addStretch();
810
811    QVBoxLayout * layoutAccounts = new QVBoxLayout;
812
813    layoutAccounts->addWidget(new StackWidget(numAccounts, groupBoxAccount));
814
815    groupBoxAccount->setFixedWidth(220);
816    groupBoxAccount->setObjectName("GrupoCuentas");//Se le asigna nombre al objeto
817    groupBoxAccount->setLayout(layoutAccounts);;
818    groupBoxAccount->setTitle("Cuentas");
819    groupBoxAccount->setStyleSheet("QGroupBox {border: 1px solid gray; "
820                     "border-radius: 3px; margin-top: 0.5em;} "
821                     "QGroupBox::title { subcontrol-origin: margin; "
822                     "left: 10px; padding: 0 3px 0 3px; } ");
823
824
825
826    layoutLateralWidget->addStretch(1);
827    layoutLateralWidget->addWidget(groupBoxAccount);
828    buttonEnd->setText("Agregar Cuenta");
829    buttonEnd->setFixedWidth(130);
830    buttonEnd->setStyleSheet("background-color: #358ccb; color: #fff;"
831                             "font-weight: bold; height: 30px; border: none;"
832                             "border-radius: 5px; margin-top: 40px;");
833    layoutLateralWidget->addWidget(buttonEnd);
834
835
836    /***********          Nuevo boton para restaurar la tabla             *******/
837    buttonRestaurar->setText("Restaurar Titulos");
838    buttonRestaurar->setFixedWidth(150);
839    buttonRestaurar->setStyleSheet("background-color: #358ccb; color: #fff;"
840                             "font-weight: bold; height: 30px; border: none;"
841                             "border-radius: 5px; margin-top: 40px;");
842    layoutLateralWidget->addWidget(buttonRestaurar);
843
844    buttonModificar->setText("Editar Cuenta Actual");
845    buttonModificar->setFixedWidth(180);
846    buttonModificar->setStyleSheet("background-color: #358ccb; color: #fff;"
847                             "font-weight: bold; height: 30px; border: none;"
848                             "border-radius: 5px; margin-top: 40px;");
849    layoutLateralWidget->addWidget(buttonModificar);
850
851
852    buttonFinalizar->setText("Finalizar Carga");
853    buttonFinalizar->setFixedWidth(130);
854    buttonFinalizar->setStyleSheet("background-color: #358ccb; color: #fff;"
855                             "font-weight: bold; height: 30px; border: none;"
856                             "border-radius: 5px; margin-top: 40px;");
857    layoutLateralWidget->addWidget(buttonFinalizar);
858    layoutLateralWidget->addStretch(6);
859
860
861    layoutCentralWidget->addLayout(layoutLateralWidget);
862
863    connect(buttonEnd,SIGNAL(clicked()),this,SLOT(AgregarCuenta()));//**************Conexion del boton agregar**********************
864    connect(buttonRestaurar,SIGNAL(clicked()),this,SLOT(RestaurarCeldas()));//Conexion del boton restaurar
865    connect(buttonFinalizar,SIGNAL(clicked()),this,SLOT(FinalizarCuentas()));//Conexion del boton Finalizar
866    connect(buttonModificar,SIGNAL(clicked()),this,SLOT(ModificarCuenta()));//Conexion del boton modificar
867
868
869    layoutCentralWidget->sizeHint();
870
871    tabWidget->addTab(new QWidget,"MCS");
872    QWidget *widget= tabWidget->widget(1);
873    widget->setLayout(layoutCentralWidget);
874
875
876    /*  ***********         Se agrega la columna en la que se asignan los nombre            **************           */
877    tableWidget->insertRow(0);
878    tableWidget->insertColumn(0);
879    noEditColZero(tableWidget);
880    /*              Se agregan elementos a la recien creada fila/columna        */
881    int contador=tableWidget->rowCount();
882    for(int i=1;i<contador;i++)
883    {
884        QTableWidgetItem *ValoraInsertar = new QTableWidgetItem;
885        ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable);
886        tableWidget->setItem(0,i,ValoraInsertar);
887
888        QTableWidgetItem *ValoraInsertar2 = new QTableWidgetItem;
889        ValoraInsertar2->setFlags(ValoraInsertar2->flags() ^ Qt::ItemIsEditable);
890        tableWidget->setItem(i,0,ValoraInsertar2);
891    }
892
893    matricesMenuBar();//Al terminar la carga de la tabla se ejecuta la accion para el menu de Operaciones
894    tabWidget->setCurrentIndex(1);//Se seleciona la pestaña MCS
895
896    actionLoadMatrix.setDisabled(true);
897
898    actionExportMatrix.setEnabled(true);
899
900    /****          Se conectan las acciones para coeficientes tecnicos horizontales y verticales      ****/
901    connect(&actionCH, SIGNAL(triggered()), this,SLOT(slotCoeficienteHorizontal()));
902    connect(&actionCV, SIGNAL(triggered()), this,SLOT(slotCoeficienteVertical()));
903    //Se conecta la accion para la variables exogenas
904    connect(&actionVariableExogena,SIGNAL(triggered()),this,SLOT(slotVariableExogena()));
905}
906
907void MainWindow::AgregarCuenta()
908{
909    QMessageBox msBox(QMessageBox::Question,"Agregar cuenta","¿Está seguro que agregar la cuenta?",
910                      QMessageBox::Yes | QMessageBox::No,this);
911    msBox.setButtonText(QMessageBox::Yes,"Si");
912    msBox.setDefaultButton(QMessageBox::Yes);
913    if(msBox.exec()==QMessageBox::Yes)
914    {
915        QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal");//Se busca la tabla que se creo
916        StackWidget *sw = findChild<StackWidget *>();//Se buscan las cuentas creadas
917
918        /* ******   Se leen los campos del widget izquierdo   ******* */;
919
920        int index=sw->comboAccount->currentIndex();
921
922
923        /*****       Se cargan la linea y las spin box correpondientes a la cuenta seleccionada       *****/
924
925        QLineEdit *le= findChild<QLineEdit *>(QString("linedit %1").arg(index + 1));
926        QSpinBox *SBStart = findChild<QSpinBox *>(QString("accountstart %1").arg(index+1));
927        QSpinBox *SBEnd = findChild<QSpinBox *>(QString("accountend %1").arg(index+1));
928
929        int inicio=SBStart->value();
930        int fin=SBEnd->value();
931        QString nombreCuenta=le->text();
932
933        if(nombreCuenta.isEmpty() or nombreCuenta.isNull())
934        {
935            QMessageBox::warning(this,"Alerta","El nombre de la cuenta esta vacio");
936        }
937        else
938        {
939            int cantidad_filas=tw->rowCount();
940
941            if(inicio>cantidad_filas or fin>cantidad_filas)//Se verifica que los valores no excedan el tamaño de la tabla
942            {
943                QMessageBox::warning(this,"Alerta","Valores mayores al tamaño\n de la tabla");
944            }
945            else
946            {
947                /***  Se comprueba si la celda de la tabla esta ocupada por otra cuenta  ***/
948                bool centinela=true;
949                if(inicio>2 and fin>2){
950                    for(int i=0;i<numAccounts;i++)
951                    {
952                        if(i!=index)
953                        {
954                            QSpinBox *otherEnd = findChild<QSpinBox *>(QString("accountend %1").arg(i+1));
955                            int otroFin=otherEnd->text().toInt();
956                            if(inicio<otroFin)
957                            {
958                                centinela=false;
959                            }
960                        }
961                    }
962                }
963
964                /*  *****    Se asigna el nombre de la cuenta a las cabecereas de la tabla en el rango(inicio,fin)     *****    */
965                if((inicio>2 && fin>2) and (centinela))
966                {
967
968                    QTableWidgetItem *ValoraInsertarFila = new QTableWidgetItem(nombreCuenta);
969                    ValoraInsertarFila->setTextAlignment(Qt::AlignCenter);
970                    ValoraInsertarFila->setFlags(ValoraInsertarFila->flags() ^ Qt::ItemIsEditable);
971                    tw->setItem(0,inicio-1,ValoraInsertarFila);
972                    QTableWidgetItem *ValoraInsertarColumna = new QTableWidgetItem(nombreCuenta);
973                    ValoraInsertarColumna->setTextAlignment(Qt::AlignCenter);
974                    ValoraInsertarColumna->setFlags(ValoraInsertarColumna->flags() ^ Qt::ItemIsEditable);
975                    tw->setItem(inicio-1,0,ValoraInsertarColumna);
976                    int espacio=(fin-inicio)+1;
977                    tw->setSpan(inicio-1,0,espacio,1);
978                    tw->setSpan(0,inicio-1,1,espacio);
979                    /*****              Se inhabilita el boton de la linea  y los spinbox  *******/
980                    le->setEnabled(false);
981                    SBStart->setEnabled(false);
982                    SBEnd->setEnabled(false);
983                }
984                else if(!centinela)
985                {
986                    QMessageBox::warning(this,"Alerta","Valores en el espacio de otra cuenta");
987                }
988                else
989                {
990                    QMessageBox::warning(this,"Alerta","Valores invalidos");
991                }
992
993            }
994        }
995    }
996
997}
998
999void MainWindow::FinalizarCuentas()
1000{
1001    QMessageBox msBox(QMessageBox::Question,"Finalizar Carga","¿Está seguro que desea finalizar?",
1002                      QMessageBox::Yes | QMessageBox::No,this);
1003    msBox.setButtonText(QMessageBox::Yes,"Si");
1004    msBox.setDefaultButton(QMessageBox::Yes);
1005    if(msBox.exec()==QMessageBox::Yes)
1006    {
1007        bool Centinela=ComprobarCuentas();//Se llama a la funcion que comprueba si todos los campos de las cuentas estan llenos
1008        if(Centinela)
1009        {
1010            QPushButton *Agregar = findChild<QPushButton *>("AgregarCuentas");
1011            QPushButton *Restaurar = findChild<QPushButton *>("Restaurar");
1012            Agregar->setStyleSheet("background-color: gray; color: #fff;"
1013                                     "font-weight: bold; height: 30px; border: none;"
1014                                     "border-radius: 5px; margin-top: 40px;");
1015            Agregar->setEnabled(false);
1016            Agregar->setVisible(false);
1017            Restaurar->setStyleSheet("background-color: gray; color: #fff;"
1018                                     "font-weight: bold; height: 30px; border: none;"
1019                                     "border-radius: 5px; margin-top: 40px;");
1020            Restaurar->setEnabled(false);
1021            Restaurar->setVisible(false);
1022            QPushButton *Modificar = findChild<QPushButton *>("Modificar");
1023            Modificar->setStyleSheet("background-color: gray; color: #fff;"
1024                                     "font-weight: bold; height: 30px; border: none;"
1025                                     "border-radius: 5px; margin-top: 40px;");
1026            Modificar->setEnabled(false);
1027            Modificar->setVisible(false);
1028            QTableWidget *tw = findChild<QTableWidget *>("TablaPrincipal");
1029            QPushButton *Finalizar = findChild<QPushButton *>("Finalizar");
1030            Finalizar->setStyleSheet("background-color: gray; color: #fff;"
1031                                     "font-weight: bold; height: 30px; border: none;"
1032                                     "border-radius: 5px; margin-top: 40px;");
1033            Finalizar->setEnabled(false);
1034            Finalizar->setVisible(false);
1035
1036            QGroupBox *groupbox = findChild<QGroupBox *>("GrupoCuentas");
1037            groupbox->setVisible(false);
1038
1039            insertremoveRowCol(tw,0,false);
1040            CalcularTotales(tw,1);//Se llama a la funcion que agregue una nueva fila y columna con los totales respectivos
1041            insertremoveRowCol(tw,0,true);
1042            setAccountTitle(tw);
1043
1044            /*       Luego de calcular los totales se habilitan las opciones del menu herramientas       */
1045            actionCH.setEnabled(true);
1046            actionCV.setEnabled(true);
1047            actionVariableExogena.setEnabled(true);
1048         }
1049        else
1050        {
1051            QMessageBox::warning(this,"Alerta","Debe llenar correctamente y agregar todas las cuentas");
1052        }
1053    }
1054}
1055
1056void MainWindow::CalcularTotales(QTableWidget *tableWidget,int inicio)//Se calculan los totales por fila/columna
1057{
1058    int filas=tableWidget->rowCount();
1059    int columnas=tableWidget->columnCount();
1060    /*******       Se inserta la nueva fila y columna para los totales, asi como es texto corespondiente             *****/
1061    tableWidget->insertRow(filas);
1062    tableWidget->insertColumn(columnas);
1063    QTableWidgetItem *FilaTotal = new QTableWidgetItem;
1064    FilaTotal->setText("Total en Fila");
1065    FilaTotal->setFlags(FilaTotal->flags() ^ Qt::ItemIsEditable);
1066    QTableWidgetItem *ColumnaTotal = new QTableWidgetItem;
1067    ColumnaTotal->setText("Total en Columna");
1068    ColumnaTotal->setFlags(ColumnaTotal->flags() ^ Qt::ItemIsEditable);
1069    tableWidget->setItem(columnas,inicio-1,FilaTotal);
1070    tableWidget->setItem(inicio-1,filas,ColumnaTotal);
1071    for(int i=inicio;i<filas;i++)
1072    {
1073        double SumaFila=0;
1074        double SumaColumna=0;
1075        for(int j=inicio;j<filas;j++)
1076        {
1077            QString fila=Separador(tableWidget->item(j,i),true);
1078            double thisFila=fila.toDouble();
1079            QString columna=Separador(tableWidget->item(i,j),true);
1080            double thisColumna=columna.toDouble();
1081            SumaFila+=thisFila;
1082            SumaColumna+=thisColumna;
1083        }
1084        QTableWidgetItem *Valor1 = new QTableWidgetItem;
1085        Valor1->setText(QString::number(SumaFila,'f',2));
1086        QString value1 = Separador(Valor1,false);
1087        Valor1->setText(value1);
1088        Valor1->setFlags(Valor1->flags() ^ Qt::ItemIsEditable);
1089        QTableWidgetItem *Valor2 = new QTableWidgetItem;
1090        Valor2->setText(QString::number(SumaColumna,'f',2));
1091        QString value2 = Separador(Valor2,false);
1092        Valor2->setText(value2);
1093        Valor2->setFlags(Valor2->flags() ^ Qt::ItemIsEditable);
1094        tableWidget->setItem(filas,i,Valor1);//Inserta en Filas
1095        tableWidget->setItem(i,filas,Valor2);//Inserta en Columnas
1096    }
1097
1098}
1099
1100void 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
1114void 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
1133void MainWindow::loadMatrizExogena()
1134{
1135
1136}
1137
1138void 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
1206std::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
1213std::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
1255QString 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
1285bool 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     ***/
1304QStringList 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 ***/
1316QList<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     ***/
1337QStringList 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
1348void 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
1357int 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 ***/
1368int 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)         ***/
1382QList<QString> MainWindow::llenarLista(QList<QString> lista,QTableWidget *tw,int valor,int opcion)
1383{
1384    for(int i=0;i<tw->rowCount();i++)
1385    {
1386        if(opcion==1)
1387        {
1388            lista.append(tw->item(valor,i)->text());
1389        }
1390        else
1391        {
1392            lista.append(tw->item(i,valor)->text());
1393        }
1394    }
1395    return lista;
1396}
1397
1398/***        Funcion que escribe en una columna o fila con la lista dada              ***/
1399void MainWindow::insertRowExogena(QList<QString> lista,QTableWidget *tw,int opcion)
1400{
1401    for(int i=0;i<tw->rowCount();i++)
1402    {
1403        QTableWidgetItem *twi =new QTableWidgetItem;
1404        twi->setText(lista[i]);
1405        twi->setFlags(twi->flags() ^ Qt::ItemIsEditable);
1406        int fin=tw->rowCount();
1407        if(opcion==1)
1408        {
1409            tw->setItem(fin-1,i,twi);
1410        }
1411        else
1412        {
1413            tw->setItem(i,fin-1,twi);
1414        }
1415    }
1416}
1417
1418/***        Funcion que permite insertar, alinear y combinar las celdas con los titulos endogena/exogena        ***/
1419void MainWindow::setEndogenaExogenaCell(QTableWidget *tw,int inicioExogena,int elementos,bool condicion)
1420{
1421    tw->insertRow(0);
1422    tw->insertColumn(0);
1423    QTableWidgetItem *ValoraInsertar = new QTableWidgetItem;
1424    ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable);
1425    tw->setItem(0,0,ValoraInsertar);
1426    /*      Titulos para las Cuentas endogenas   */
1427    QTableWidgetItem *CuentaEndogenafila = new QTableWidgetItem("Cuentas Endogenas");
1428    CuentaEndogenafila->setFlags(CuentaEndogenafila->flags() ^ Qt::ItemIsEditable);
1429    CuentaEndogenafila->setTextAlignment(Qt::AlignCenter);
1430    tw->setItem(0,1,CuentaEndogenafila);
1431    tw->setSpan(0,1,1,inicioExogena-1);
1432    QTableWidgetItem *CuentaEndogenaColumna = new QTableWidgetItem;
1433    if(elementos<12)
1434    {
1435        CuentaEndogenaColumna->setText("Cuentas \nExogenas");
1436    }
1437    else
1438    {
1439        CuentaEndogenaColumna->setText("C\nu\ne\nn\nt\na\ns\n\nE\nn\nd\no\ng\ne\nn\na\ns");
1440    }
1441    CuentaEndogenaColumna->setFlags(CuentaEndogenaColumna->flags() ^ Qt::ItemIsEditable);
1442    tw->setItem(1,0,CuentaEndogenaColumna);
1443    tw->setSpan(1,0,inicioExogena-1,1);
1444    if(condicion)//Si tiene cuentas exogenas
1445    {
1446        /*      Titulos para las Cuentas exogenas   */
1447        QTableWidgetItem *CuentaExogenafila = new QTableWidgetItem("Cuentas Exogenas");
1448        CuentaExogenafila->setFlags(CuentaExogenafila->flags() ^ Qt::ItemIsEditable);
1449        CuentaExogenafila->setTextAlignment(Qt::AlignCenter);
1450        tw->setItem(0,inicioExogena,CuentaExogenafila);
1451        if(elementos>1)
1452        {
1453            tw->setSpan(0,inicioExogena,1,elementos);
1454        }
1455        QTableWidgetItem *CuentaExogenaColumna = new QTableWidgetItem;
1456        if(elementos<12)
1457        {
1458            CuentaExogenaColumna->setText("Cuenta \nExogena");
1459        }
1460        else
1461        {
1462            CuentaExogenaColumna->setText("C\nu\ne\nn\nt\na\ns\n\nE\nx\no\ng\ne\nn\na\ns");
1463        }
1464        CuentaExogenaColumna->setFlags(CuentaExogenaColumna->flags() ^ Qt::ItemIsEditable);
1465        tw->setItem(inicioExogena,0,CuentaExogenaColumna);
1466        if(elementos>1)
1467        {
1468            tw->setSpan(inicioExogena,0,elementos,1);
1469        }
1470    }
1471}
1472
1473void MainWindow::CalcularAn(QTableWidget *tw,QTableWidget *nuevaTabla,QTableWidget *tablaOriginal,int count,bool endogena)//Funcion para calcular el Coeficiente Tecnico Horizontal (An)
1474{
1475    for(int i=0;i<count-1;i++)
1476    {
1477        double total;
1478        if(endogena)
1479        {
1480            QString value = Separador(tablaOriginal->item(count,i),true);
1481            value = QString::number(value.toDouble(),'f',2);
1482            total=value.toDouble();
1483        }
1484        else
1485        {
1486            QString value = Separador(tw->item(count-1,i),true);
1487            value = QString::number(value.toDouble(),'f',2);
1488            total=value.toDouble();
1489        }
1490        for(int j=0;j<count-1;j++)
1491        {
1492            if(i!=0 && j!=0)
1493            {
1494                QString values = Separador(tw->item(j,i),true);
1495                values = QString::number(values.toDouble(),'f',2);
1496                double valor=values.toDouble();
1497
1498                if(total==0)//Se comprueba en caso de que el total sea zero
1499                {
1500                    valor=0;
1501                }
1502                else
1503                {
1504                    valor/=total;//Se divide el valor de la celda entre el total correspondiente
1505
1506                }
1507                QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(QString::number(valor,'f',2));
1508                ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable);
1509                QString value = Separador(ValoraInsertar,false);
1510                ValoraInsertar->setText(value);
1511                nuevaTabla->setItem(j,i,ValoraInsertar);
1512            }
1513            /****           En este else se llenan las celdas con fila y columna 0, es decir las que tienen nombre *****/
1514            else if((i==0 && j>0)||(j==0 && i>0))
1515            {
1516                QString value=tw->item(i,j)->text();
1517                QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(value);
1518                ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable);
1519                nuevaTabla->setItem(i,j,ValoraInsertar);
1520            }
1521       }
1522
1523    }
1524}
1525
1526void MainWindow::clonarTabla(QTableWidget *tw,QTableWidget *nuevaTabla,int cantidad)
1527{
1528    for(int i=0;i<cantidad-1;i++)
1529    {
1530        for(int j=0;j<cantidad-1;j++)
1531        {
1532            if(i!=0 && j!=0)
1533            {
1534                QString value = Separador(tw->item(i,j),true);
1535                double valor= value.toDouble();
1536                QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(QString::number(valor,'f',2));
1537                value = Separador(ValoraInsertar,false);
1538                ValoraInsertar->setText(value);
1539                ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable);
1540                nuevaTabla->setItem(i,j,ValoraInsertar);
1541            }
1542            else if((i==0 && j>0)||(j==0 && i>0))
1543            {
1544                QString value=tw->item(i,j)->text();
1545                QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(value);
1546                ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable);
1547                nuevaTabla->setItem(i,j,ValoraInsertar);
1548            }
1549
1550         }
1551    }
1552}
1553
1554void MainWindow::crearMatrizEndogena(QTableWidget *tw)
1555{
1556    int cantidad=tw->rowCount();
1557    for(int i=0;i<cantidad;i++)
1558    {
1559        for(int j=0;j<cantidad;j++)
1560        {
1561            if(i!=0 && j!=0)
1562            {
1563                double valor=tw->item(i,j)->text().toDouble();
1564                MatrizEndogenaEndogena[i-1][j-1]=valor;
1565            }
1566
1567         }
1568    }
1569}
1570
1571void MainWindow::crearMatrizIdentidad(QTableWidget *tw,double identidad[200][200])
1572{
1573    int cantidad=tw->rowCount();
1574    for(int i=0;i<cantidad-1;i++)
1575    {
1576        for(int j=0;j<cantidad-1;j++)
1577        {
1578            if(i==j)
1579            {
1580                identidad[i][j]=1;
1581            }
1582            else
1583            {
1584                identidad[i][j]=0;
1585            }
1586
1587         }
1588    }
1589}
1590
1591void MainWindow::restarIdentidadAn(QTableWidget *tw,double identidad[200][200],double resta[200][200])
1592{
1593    int cantidad=tw->rowCount();
1594    mat A(cantidad,cantidad);
1595    for(int i=0;i<cantidad-1;i++)
1596    {
1597        for(int j=0;j<cantidad-1;j++)
1598        {
1599            //qDebug()<<MatrizEndogenaEndogena[i][j]<<" "<<identidad[i][j];
1600            resta[i][j] = identidad[i][j]-MatrizEndogenaEndogena[i][j];
1601            //qDebug()<<"A"<<resta[i][j];
1602            A.at(i,j) = resta[i][j];
1603            //qDebug()<<"resta"<<A.at(i,j);
1604
1605         }
1606    }
1607
1608    mat inverse = inv(A);
1609
1610    QTableWidget *tablaLa = new QTableWidget;
1611    tablaLa->setObjectName("MatrizLa");
1612    CrearTablaVacia(cantidad,tablaLa);
1613    for(int i=0;i<cantidad-1;i++)
1614    {
1615        for(int j=0;j<cantidad-1;j++)
1616        {
1617            double value = inverse.at(i,j);
1618            qDebug()<<"double "<<value;
1619            QTableWidgetItem *ValoraInsertar = new QTableWidgetItem(QString::number(value,'f',2));
1620            ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable);
1621            tablaLa->setItem(i,j,ValoraInsertar);
1622
1623         }
1624    }
1625    tabWidget->addTab(new QWidget,"La");
1626    int indice=ObtenerIndice("La");//Se obtiene el indice de la pestaña
1627    QHBoxLayout * layoutCentralWidget = new QHBoxLayout;
1628    layoutCentralWidget->addWidget(tablaLa);
1629    QWidget *widget = tabWidget->widget(indice);
1630    widget->setLayout(layoutCentralWidget);//Se añade el widget y layout a la pestaña creada
1631
1632
1633    /*mat A;
1634    A << 1 << 2.2222 << 3 << 4 << endr
1635     << 2 << 1 << 5 << 6 << endr
1636     << 3 << 5 << 1 << 7 <<endr
1637     << 4 << 6 << 7 << 1<<endr;
1638    //qDebug()<<"here"<<A.at(0,8);
1639    //qDebug()<<"resta"<<resta[0][8];
1640
1641    double determinant = det(A);*/
1642    //qDebug() << isnan(determinant);
1643
1644   /*mat inverse = inv(A);
1645    for(int i=0;i<4;i++)
1646    {
1647        for(int j=0;j<4;j++)
1648        {
1649            qDebug()<<"inversa"<<inverse.at(i,j);
1650
1651         }
1652    }*/
1653
1654
1655
1656
1657    //qDebug()<<"determinant"<<determinant;
1658    /*if(determinant < -std::numeric_limits<qreal>::max())
1659    {
1660        qDebug()<<"-inf";
1661    }
1662    else if(determinant > std::numeric_limits<qreal>::max())
1663    {
1664        qDebug()<<"inf";
1665    }
1666    else if(determinant != determinant)
1667    {
1668        qDebug()<< "nan";
1669    }*/
1670
1671
1672}
1673
1674/*       Funcion para volver la celda(0,0) no editable     */
1675void MainWindow::noEditColZero(QTableWidget *tw)
1676{
1677    QTableWidgetItem *ValoraInsertar = new QTableWidgetItem;
1678    ValoraInsertar->setFlags(ValoraInsertar->flags() ^ Qt::ItemIsEditable);
1679    tw->setItem(0,0,ValoraInsertar);
1680}
1681
1682/*          Funcion para colocar los titulos de las cuentas         */
1683void MainWindow::setAccountTitle(QTableWidget *tw)
1684{
1685    for(int i=0;i<numAccounts;i++)
1686    {
1687        QLineEdit *le= findChild<QLineEdit *>(QString("linedit %1").arg(i + 1));
1688        QSpinBox *SBStart = findChild<QSpinBox *>(QString("accountstart %1").arg(i+1));
1689        QSpinBox *SBEnd = findChild<QSpinBox *>(QString("accountend %1").arg(i+1));
1690
1691        int inicio=SBStart->value();
1692        int fin=SBEnd->value();
1693        QString nombreCuenta=le->text();
1694
1695
1696        QTableWidgetItem *ValoraInsertarFila = new QTableWidgetItem(nombreCuenta);
1697        ValoraInsertarFila->setTextAlignment(Qt::AlignCenter);
1698        ValoraInsertarFila->setFlags(ValoraInsertarFila->flags() ^ Qt::ItemIsEditable);
1699        tw->setItem(0,inicio-1,ValoraInsertarFila);
1700        QTableWidgetItem *ValoraInsertarColumna = new QTableWidgetItem(nombreCuenta);
1701        ValoraInsertarColumna->setTextAlignment(Qt::AlignCenter);
1702        ValoraInsertarColumna->setFlags(ValoraInsertarColumna->flags() ^ Qt::ItemIsEditable);
1703        tw->setItem(inicio-1,0,ValoraInsertarColumna);
1704        int espacio=(fin-inicio)+1;
1705        tw->setSpan(inicio-1,0,espacio,1);
1706        tw->setSpan(0,inicio-1,1,espacio);
1707    }
1708}
1709
1710/*                  Funcion para agregar/quitar columnas y filas                    */
1711void MainWindow::insertremoveRowCol(QTableWidget *tw, int rowcol, bool opcion)
1712{
1713    if(opcion)//Si la opcion es verdadero se agrega
1714    {
1715        tw->insertRow(rowcol);
1716        tw->insertColumn(rowcol);
1717    }
1718    else//de lo contrario se remueve
1719    {
1720        tw->removeColumn(rowcol);
1721        tw->removeRow(rowcol);
1722    }
1723}
1724
1725/*                      Funcion para agregar/quitar el separador de miles y la coma en las tablas           */
1726QString MainWindow::Separador(QTableWidgetItem *ti,bool quitar)
1727{
1728    QString value=ti->text();
1729    if(quitar)
1730    {
1731        value.remove(QChar('.'));
1732        value.replace(",",".");
1733    }
1734    else
1735    {
1736        double val =value.toDouble();
1737        value = numberFormat(val);
1738    }
1739    return value;
1740}
1741
1742void MainWindow::slotCloseExport()
1743{
1744    formExportMatriz->ExportLine->setText("");
1745    formExportMatriz->close();
1746}
1747
1748void MainWindow::slotSaveExport()
1749{
1750
1751    if(formExportMatriz->ExportLine->text().isEmpty())
1752    {
1753        QMessageBox::critical(this,"Nombre del Archivo","Debe Colocar un nombre");
1754    }
1755    else
1756    {
1757        QString filename = formExportMatriz->ExportLine->text();
1758        QFile archivo(filename);
1759        archivo.open(QFile::WriteOnly | QFile::Text);
1760        QTextStream out(&archivo);
1761        out << "hola " << "que hace" << "? \n";
1762        out << "otra linea de prueba";
1763        archivo.flush();
1764        archivo.close();
1765        formExportMatriz->ExportLine->setText("");
1766        formExportMatriz->close();
1767    }
1768}
1769
1770void MainWindow::slotSearchExport()
1771{
1772    QString format = ".txt";
1773
1774    QString filename = QFileDialog::getSaveFileName(this,
1775            "Elija el nombre", QDir::homePath(),"*.txt");
1776
1777    filename +=format;
1778
1779    formExportMatriz->Exportcb->addItem(filename);
1780
1781    formExportMatriz->ExportLine->setText(filename);
1782    qDebug()<< formExportMatriz->ExportLine->text();
1783
1784}
Note: See TracBrowser for help on using the repository browser.