Changeset b23848e in mmcs for mainwindow.C


Ignore:
Timestamp:
Sep 14, 2016, 11:22:49 AM (8 years ago)
Author:
rudmanmrrod <rudman22@…>
Branches:
master
Children:
b0c244f
Parents:
dfabbb4
Message:

Agregada la funcionalidad para exportar el gráfico de encadenamientos

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mainwindow.C

    rdfabbb4 rb23848e  
    878878void MainWindow::abrirManual()
    879879{
    880     //QDesktopServices::openUrl(QUrl("/usr/share/mmcs/Usuario/Entrada.html",QUrl::TolerantMode));
    881     // generate some data:
    882     /*QCustomPlot *customPlot = new QCustomPlot;
    883     QVector<double> x(101), y(101); // initialize with entries 0..100
    884     for (int i=0; i<10; ++i)
    885     {
    886       x[i] = i/5.0 - 1; // x goes from -1 to 1
    887       y[i] = x[i]*x[i]; // let's plot a quadratic function
    888     }
    889     // create graph and assign data to it:
    890     customPlot->addGraph();
    891     customPlot->graph(0)->setData(x, y);
    892     //customPlot->graph(0)->setLineStyle(QCPGraph::lsNone);
    893     customPlot->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCross, 4));
    894     // give the axes some labels:
    895     customPlot->xAxis->setLabel("-y");
    896     customPlot->yAxis->setLabel("-x");
    897     customPlot->xAxis2->setLabel("y");
    898     customPlot->yAxis2->setLabel("x");
    899     // set axes ranges, so we see all data:
    900     customPlot->xAxis->setRange(-5, 5);
    901     customPlot->yAxis->setRange(-5, 5);
    902     customPlot->xAxis2->setRange(-5, 5);
    903     customPlot->yAxis2->setRange(-5, 5);
    904     customPlot->xAxis2->setVisible(true);
    905     customPlot->yAxis2->setVisible(true);
    906     customPlot->replot();
    907     FormExportMatrix *form = new FormExportMatrix(this);
    908     QHBoxLayout *layoutHorizontal = new QHBoxLayout;
    909     layoutHorizontal->addWidget(customPlot);
    910     form->setLayout(layoutHorizontal);
    911     form->show();*/
     880    QDesktopServices::openUrl(QUrl("/usr/share/mmcs/Usuario/Entrada.html",QUrl::TolerantMode));
    912881}
    913882
     
    28702839        QPushButton * buttonAgregar = new QPushButton;
    28712840        buttonAgregar->setObjectName("AgregarEncadenamiento");//Se le asigna nombre al objeto
    2872         buttonAgregar->setText("Agregar");
     2841        buttonAgregar->setText("A&gregar");
    28732842        buttonAgregar->setFixedWidth(130);
    28742843        buttonAgregar->setStyleSheet("background-color: #358ccb; color: #fff;"
     
    28772846        QPushButton * buttonCancelar = new QPushButton;
    28782847        buttonCancelar->setObjectName("CancelarEncadenamiento");//Se le asigna nombre al objeto
    2879         buttonCancelar->setText("Cancelar");
     2848        buttonCancelar->setText("&Cancelar");
    28802849        buttonCancelar->setFixedWidth(130);
    28812850        buttonCancelar->setStyleSheet("background-color: #358ccb; color: #fff;"
     
    28842853        QPushButton * buttonVer = new QPushButton;
    28852854        buttonVer->setObjectName("VerEncadenamiento");//Se le asigna nombre al objeto
    2886         buttonVer->setText("Ver");
     2855        buttonVer->setText("V&er");
    28872856        buttonVer->setFixedWidth(130);
    28882857        buttonVer->setStyleSheet("background-color: #358ccb; color: #fff;"
     
    30302999                                     "font-weight: bold; height: 30px; border: none;"
    30313000                                     "border-radius: 5px; margin-top: 40px;");
     3001            //Se genera el boton de gráfico
     3002            QPushButton * buttonGraphic = new QPushButton;
     3003            buttonGraphic->setText("&Gráfico");
     3004            buttonGraphic->setObjectName("ReportButton");
     3005            buttonGraphic->setFixedWidth(100);
     3006            buttonGraphic->setStyleSheet("background-color: #358ccb; color: #fff;"
     3007                                     "font-weight: bold; height: 30px; border: none;"
     3008                                     "border-radius: 5px; margin-top: 40px;");
    30323009
    30333010            //Se genera la caja de grupo que contendrá el botón
     
    30423019            QHBoxLayout * layoutButtons = new QHBoxLayout;
    30433020            layoutButtons->addWidget(buttonReport);
     3021            layoutButtons->addWidget(buttonGraphic);
    30443022            groupBoxAccount->setLayout(layoutButtons);
    30453023            //Se conecta el boton de reporte
    30463024            connect(buttonReport,SIGNAL(clicked()),this,SLOT(slotEncadenamientoReport()));
     3025            connect(buttonGraphic,SIGNAL(clicked()),this,SLOT(slotEncadenamientoGraphic()));
    30473026
    30483027            layoutLateralWidget->addWidget(groupBoxAccount);
     
    30843063                                     "font-weight: bold; height: 30px; border: none;"
    30853064                                     "border-radius: 5px; margin-top: 40px;");
     3065            //Se genera el boton de gráfico
     3066            QPushButton * buttonGraphic = new QPushButton;
     3067            buttonGraphic->setText("&Gráfico");
     3068            buttonGraphic->setObjectName("ReportButton");
     3069            buttonGraphic->setFixedWidth(100);
     3070            buttonGraphic->setStyleSheet("background-color: #358ccb; color: #fff;"
     3071                                     "font-weight: bold; height: 30px; border: none;"
     3072                                     "border-radius: 5px; margin-top: 40px;");
    30863073
    30873074            //Se genera la caja de grupo que contendrá el botón
     
    30963083            QHBoxLayout * layoutButtons = new QHBoxLayout;
    30973084            layoutButtons->addWidget(buttonReport);
     3085            layoutButtons->addWidget(buttonGraphic);
    30983086            groupBoxAccount->setLayout(layoutButtons);
    30993087            //Se conecta el boton de reporte
    31003088            connect(buttonReport,SIGNAL(clicked()),this,SLOT(slotEncadenamientoReport()));
     3089            connect(buttonGraphic,SIGNAL(clicked()),this,SLOT(slotEncadenamientoGraphic()));
    31013090
    31023091            layoutLateralWidget->addWidget(groupBoxAccount);
     
    31403129    crearTablaVaciaEncadenamiento(elementos,enTable,7);
    31413130    int columna=0;
    3142     qDebug()<< diccCuentasEncadenamientos;
    31433131    foreach(int key,diccCuentasEncadenamientos.keys())
    31443132    {
     
    35273515
    35283516/**
    3529     @brief Función que permite agregar la primera celda en los clasificadores
    3530     @date 10/09/2015
    3531     @author Rodrigo Boet
    3532     @param <tw> Recibe el widget de la tabla de clasificadores
    3533 */
    3534 void MainWindow::agregarPrimeraCelda(QTableWidget *tw)
    3535 {
    3536     tw->insertRow(0);
    3537     //Se colocan no editables la celda 0 y 1
    3538     noEditColZero(tw);
    3539     QTableWidgetItem *one = new QTableWidgetItem;
    3540     one->setFlags(one->flags() ^ Qt::ItemIsEditable);
    3541     tw->setItem(0,1,one);
    3542     for(int i=0;i<3;i++)
    3543     {
    3544         QTableWidgetItem *cAn = new QTableWidgetItem("Clasificador por An");
    3545         cAn->setTextAlignment(Qt::AlignCenter);
    3546         cAn->setFlags(cAn->flags() ^ Qt::ItemIsEditable);
    3547         CellStyleExEn(cAn);
    3548         tw->setItem(0,i+2,cAn);
    3549         QTableWidgetItem *cMa = new QTableWidgetItem("Clasificador por Ma");
    3550         cMa->setTextAlignment(Qt::AlignCenter);
    3551         cMa->setFlags(cMa->flags() ^ Qt::ItemIsEditable);
    3552         CellStyleExEn(cMa);
    3553         tw->setItem(0,5+i,cMa);
    3554     }
    3555     tw->setSpan(0,2,1,3);
    3556     tw->setSpan(0,5,1,3);
    3557 }
    3558 
    3559 /**
    35603517    @brief Función que permite abir el formulario de creación del reporte de los encadenamientos
    35613518    @date 31/08/2015
     
    35653522{
    35663523    FormExportReport *formularioReporte = new FormExportReport(this);
    3567     connect(formularioReporte,SIGNAL(formAccepted(QString)),this,SLOT(slotGenerarEncadenamientoReport(QString)));
     3524    connect(formularioReporte,SIGNAL(formAccepted(QString,bool)),this,SLOT(slotGenerarEncadenamientoReport(QString,bool)));
     3525    formularioReporte->show();
     3526}
     3527
     3528/**
     3529    @brief Función que permite abir el formulario de creación de gráficos de los encadenamientos
     3530    @date 14/09/2016
     3531    @author Rodrigo Boet
     3532*/
     3533void MainWindow::slotEncadenamientoGraphic()
     3534{
     3535    FormExportReport *formularioReporte = new FormExportReport(this);
     3536    formularioReporte->setWindowTitle("Exportar Gráfico");
     3537    formularioReporte->ui->label->setText("Guardar Gráifco");
     3538    formularioReporte->ui->label_3->setText("Seleccione la ruta para guardar el gráfico");
     3539    disconnect(formularioReporte->ui->ButtonCargar,SIGNAL(clicked()),formularioReporte,SLOT(slotLoad()));
     3540    disconnect(formularioReporte->ui->ButtonGenerar,SIGNAL(clicked()),formularioReporte,SLOT(slotClicked()));
     3541    connect(formularioReporte->ui->ButtonCargar,SIGNAL(clicked()),formularioReporte,SLOT(slotLoadGraphic()));
     3542    connect(formularioReporte->ui->ButtonGenerar,SIGNAL(clicked()),formularioReporte,SLOT(slotClickedGraphic()));
     3543    connect(formularioReporte,SIGNAL(formAccepted(QString,bool)),this,SLOT(slotGenerarEncadenamientoReport(QString,bool)));
    35683544    formularioReporte->show();
    35693545}
     
    35733549    @date 31/08/2015
    35743550    @author Rodrigo Boet
    3575 */
    3576 void MainWindow::slotGenerarEncadenamientoReport(QString filename)
     3551    @param <filename> Recibe el nombre del archivo
     3552    @param <report> recibe un booleano (true si es reporte, falso en caso contrario)
     3553*/
     3554void MainWindow::slotGenerarEncadenamientoReport(QString filename, bool report)
    35773555{
    35783556    int indice = tabWidget->currentIndex();
     
    35813559    int row = tw->rowCount();
    35823560    int col = tw->columnCount();
     3561    QVector<double> x, y;
    35833562    QStringList myHtml;
    35843563    myHtml.append("<table>");
     
    35893568        {
    35903569            QString item = tw->item(i,j)->text();
    3591             myHtml.append("<td>"+item+"</td>");
     3570            //Comprende las filas superiores
     3571            if(i==0 and j>1)
     3572            {
     3573                myHtml.append("<td align='center' style='font-weight:bold;background-color:LightGrey;'>"+item+"</td>");
     3574            }
     3575            //Comprende las cuentas en la parte izquierda
     3576            else if((i>0 and i<row-1) and j==0)
     3577            {
     3578                myHtml.append("<td style='background-color:steelblue;color:white'>"+item+"</td>");
     3579            }
     3580            //Comprende las subcuentas en la parte izquierda
     3581            else if((i>0 and i<row-1)and j==1)
     3582            {
     3583                myHtml.append("<td align='center' style='background-color:LightGrey'>"+item+"</td>");
     3584            }
     3585            //Comprende la última fila
     3586            else if(i==row-1)
     3587            {
     3588                myHtml.append("<td align='center' style='font-weight:bold'>"+item+"</td>");
     3589            }
     3590            //Comprende el resto de los elementos
     3591            else
     3592            {
     3593                myHtml.append("<td align='center'>"+item+"</td>");
     3594            }
     3595            if((i>0 and i<row-1) and (j>3 and j<col-1))
     3596            {
     3597                QString titem = Separador(tw->item(i,j),true);
     3598                double valor = titem.toDouble();
     3599                if(j==4)
     3600                {
     3601                    x.append(valor);
     3602                }
     3603                else
     3604                {
     3605                    y.append(valor);
     3606                }
     3607            }
    35923608        }
    35933609        myHtml.append("</tr>");
    35943610    }
    35953611    myHtml.append("</table>");
     3612    //Máximos y Mínimos
     3613    double max = 3;
     3614    double min = -1;
     3615    //Gráfico
    35963616    QCustomPlot *customPlot = new QCustomPlot;
    3597     QVector<double> x(101), y(101); // initialize with entries 0..100
    3598     for (int i=0; i<10; ++i)
    3599     {
    3600       x[i] = i/5.0 - 1; // x goes from -1 to 1
    3601       y[i] = x[i]*x[i]; // let's plot a quadratic function
    3602     }
    36033617    // create graph and assign data to it:
    36043618    customPlot->addGraph();
    36053619    customPlot->graph(0)->setData(x, y);
    3606     //customPlot->graph(0)->setLineStyle(QCPGraph::lsNone);
     3620    customPlot->graph(0)->setLineStyle(QCPGraph::lsNone);
    36073621    customPlot->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCross, 4));
     3622    // set title of plot:
     3623    customPlot->plotLayout()->insertRow(0);
     3624    customPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(customPlot, "Clasificación de Cuentas"));
    36083625    // give the axes some labels:
    36093626    customPlot->xAxis->setLabel("-y");
     3627    customPlot->xAxis->setTickStep(1);
     3628    customPlot->xAxis->setAutoTickStep(false);
     3629    customPlot->xAxis->setSubTickCount(5);
    36103630    customPlot->yAxis->setLabel("-x");
     3631    customPlot->yAxis->setAutoTickStep(false);
     3632    customPlot->yAxis->setTickStep(1);
     3633    customPlot->yAxis->setSubTickCount(5);
    36113634    customPlot->xAxis2->setLabel("y");
     3635    customPlot->xAxis2->setAutoTickStep(false);
     3636    customPlot->xAxis2->setTickStep(1);
     3637    customPlot->xAxis2->setSubTickCount(5);
    36123638    customPlot->yAxis2->setLabel("x");
     3639    customPlot->yAxis2->setAutoTickStep(false);
     3640    customPlot->yAxis2->setTickStep(1);
     3641    customPlot->yAxis2->setSubTickCount(5);
    36133642    // set axes ranges, so we see all data:
    3614     customPlot->xAxis->setRange(-5, 5);
    3615     customPlot->yAxis->setRange(-5, 5);
    3616     customPlot->xAxis2->setRange(-5, 5);
    3617     customPlot->yAxis2->setRange(-5, 5);
     3643    customPlot->xAxis->setRange(min, max);
     3644    customPlot->yAxis->setRange(min, max);
     3645    customPlot->xAxis2->setRange(min, max);
     3646    customPlot->yAxis2->setRange(min, max);
    36183647    customPlot->xAxis2->setVisible(true);
    36193648    customPlot->yAxis2->setVisible(true);
     3649    // flecha
     3650    QCPItemStraightLine *newY = new QCPItemStraightLine(customPlot);
     3651    customPlot->addItem(newY);
     3652    newY->point1->setCoords(1,3);
     3653    QCPItemStraightLine *newX = new QCPItemStraightLine(customPlot);
     3654    customPlot->addItem(newX);
     3655    newX->point1->setCoords(3,1);
     3656    //Se crean los labels
     3657    QCPItemText *claveText = new QCPItemText(customPlot);
     3658    customPlot->addItem(claveText);
     3659    claveText->position->setCoords(max-0.5, max-0.5);
     3660    claveText->setPositionAlignment(Qt::AlignBottom|Qt::AlignHCenter);
     3661    claveText->setPen(QPen(Qt::black));
     3662    claveText->setText("Clave");
     3663    claveText->setFont(QFont(font().family(), 10));
     3664    QCPItemText *baseText = new QCPItemText(customPlot);
     3665    customPlot->addItem(baseText);
     3666    baseText->position->setCoords(min+0.5, max-0.5);
     3667    baseText->setPositionAlignment(Qt::AlignBottom|Qt::AlignHCenter);
     3668    baseText->setPen(QPen(Qt::black));
     3669    baseText->setText("Base");
     3670    baseText->setFont(QFont(font().family(), 10));
     3671    QCPItemText *indepentientesText = new QCPItemText(customPlot);
     3672    customPlot->addItem(indepentientesText);
     3673    indepentientesText->position->setCoords(min+0.8, min+0.5);
     3674    indepentientesText->setPositionAlignment(Qt::AlignBottom|Qt::AlignHCenter);
     3675    indepentientesText->setPen(QPen(Qt::black));
     3676    indepentientesText->setText("Independiente");
     3677    indepentientesText->setFont(QFont(font().family(), 10));
     3678    QCPItemText *fuertearrastreText = new QCPItemText(customPlot);
     3679    customPlot->addItem(fuertearrastreText);
     3680    fuertearrastreText->position->setCoords(max-0.8, min+0.5);
     3681    fuertearrastreText->setPositionAlignment(Qt::AlignBottom|Qt::AlignHCenter);
     3682    fuertearrastreText->setPen(QPen(Qt::black));
     3683    fuertearrastreText->setText("Impulsor");
     3684    fuertearrastreText->setFont(QFont(font().family(), 10));
     3685    //Se generan los cambios en el grafico
    36203686    customPlot->replot();
    36213687
    3622     QTextDocument report;
    3623     report.setHtml(myHtml.join(""));
    3624     QTextCursor cursor(&report);
    3625     QPixmap pm = customPlot->toPixmap();
    3626     QImage img = pm.toImage();
    3627     cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
    3628     cursor.insertImage(img);
    3629     QPrinter printer( QPrinter::HighResolution );
    3630     printer.setOutputFileName(filename);
    3631     printer.setOutputFormat(QPrinter::PdfFormat);
    3632     report.print(&printer);
     3688    QString reportText;
     3689    //Se evalua si es un reporte
     3690    if(report){
     3691        QTextDocument report;
     3692        report.setHtml(myHtml.join(""));
     3693        QTextCursor cursor(&report);
     3694        QPixmap pm = customPlot->toPixmap();
     3695        QImage img = pm.toImage();
     3696        cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
     3697        cursor.insertImage(img);
     3698        QPrinter printer( QPrinter::HighResolution );
     3699        printer.setOutputFileName(filename);
     3700        printer.setOutputFormat(QPrinter::PdfFormat);
     3701        report.print(&printer);
     3702        reportText = "Se generó con éxito el reporte\n en "+filename;
     3703    }
     3704    else
     3705    {
     3706        customPlot->savePng(filename);
     3707        reportText = "Se generó con éxito el gráfico en "+filename;
     3708    }
     3709    //Mensaje de confimación
     3710    QMessageBox::information(this,"Reporte",reportText);
    36333711
    36343712    /*QPainter painter( &printer );
Note: See TracChangeset for help on using the changeset viewer.