Zwrotomat/generatorwindow.cpp
/**
 * @brief GeneratorWindow::on_generateButton_clicked
 * Action on generate button clicked. Generating and saving the raport
 */
@brief GeneratorWindow::on_generateButton_clicked
Action on generate button clicked. Generating and saving the raport
@brief GeneratorWindow :: on_generateButton_clicked Action on generate button clicked . Generating and saving the raport
void GeneratorWindow::on_generateButton_clicked()
{
    QString mainPage = HtmlFormater::loadMainTemplate(
                ui->subjectTextEdit->toPlainText(),
                ui->topicTextEdit->toPlainText(),
                ui->checkerTextEdit->toPlainText(),
                QDateTime::currentDateTime().toString("dd-MM-yyyy"),
                ui->scoreTextEdit->toPlainText()
                );
    QString body = "";
    QHashIterator<QString, MultiFileComment*> i(*m_Comments);
    while (i.hasNext()) {
        i.next();
        QString comment = "";
        qDebug() << "::Comment Name::: " << i.key();
        comment += HtmlFormater::loadHeaderDisplayTemplate(i.key());
        MultiFileComment* multifileComment = i.value();
        qDebug() << "::Comment::: " << multifileComment->getComment();
        QHash<QString, QList<int>*>* filesIndexes = multifileComment->getData();
        QHashIterator<QString, QList<int>*> z(*filesIndexes);
        while (z.hasNext()) {
            z.next();
            QFileInfo fileInfo(z.key());
            qDebug() << "::File::: " << z.key();
            QString selectedLines = FileReadingUtils::readGivenLines(z.value(), z.key());
            if(!selectedLines.simplified().isEmpty()) {
                if(multifileComment->isPositive())
                    comment += HtmlFormater::loadPositiveCommentTemplate(fileInfo.fileName(), selectedLines);
                else
                    comment += HtmlFormater::loadNegativeCommentTemplate(fileInfo.fileName(), selectedLines);
            }
        }
        comment += HtmlFormater::loadTextDisplayTemplate(multifileComment->getComment());
        body += comment;
    }
    mainPage.replace("${body}", body);
    QString filename = ui->fileNameTextEdit->toPlainText();
    if(filename.isEmpty()){
       QMessageBox::information(0, "Error", "Missing file name");
       return;
    }
    if(!filename.endsWith(".html")){
        filename += ".html";
    }
    QString path = this->s_last_selectedDir.path() + filename;
    const QString qPath(path);
    QFile qFile(qPath);
    if (qFile.open(QIODevice::WriteOnly)) {
      QTextStream out(&qFile); out << mainPage;
      qFile.close();
    }
    this->close();
}
void GeneratorWindow :: on_generateButton_clicked ( ) { QString mainPage = HtmlFormater :: loadMainTemplate ( ui -> subjectTextEdit -> toPlainText ( ) , ui -> topicTextEdit -> toPlainText ( ) , ui -> checkerTextEdit -> toPlainText ( ) , QDateTime :: currentDateTime ( ) . toString ( " " ) , ui -> scoreTextEdit -> toPlainText ( ) ) ; QString body = " " ; QHashIterator < QString , MultiFileComment * > i ( * m_Comments ) ; while ( i . hasNext ( ) ) { i . next ( ) ; QString comment = " " ; qDebug ( ) << " " << i . key ( ) ; comment += HtmlFormater :: loadHeaderDisplayTemplate ( i . key ( ) ) ; MultiFileComment * multifileComment = i . value ( ) ; qDebug ( ) << " " << multifileComment -> getComment ( ) ; QHash < QString , QList < int > * > * filesIndexes = multifileComment -> getData ( ) ; QHashIterator < QString , QList < int > * > z ( * filesIndexes ) ; while ( z . hasNext ( ) ) { z . next ( ) ; QFileInfo fileInfo ( z . key ( ) ) ; qDebug ( ) << " " << z . key ( ) ; QString selectedLines = FileReadingUtils :: readGivenLines ( z . value ( ) , z . key ( ) ) ; if ( ! selectedLines . simplified ( ) . isEmpty ( ) ) { if ( multifileComment -> isPositive ( ) ) comment += HtmlFormater :: loadPositiveCommentTemplate ( fileInfo . fileName ( ) , selectedLines ) ; else comment += HtmlFormater :: loadNegativeCommentTemplate ( fileInfo . fileName ( ) , selectedLines ) ; } } comment += HtmlFormater :: loadTextDisplayTemplate ( multifileComment -> getComment ( ) ) ; body += comment ; } mainPage . replace ( " " , body ) ; QString filename = ui -> fileNameTextEdit -> toPlainText ( ) ; if ( filename . isEmpty ( ) ) { QMessageBox :: information ( 0 , " " , " " ) ; return ; } if ( ! filename . endsWith ( " " ) ) { filename += " " ; } QString path = this -> s_last_selectedDir . path ( ) + filename ; const QString qPath ( path ) ; QFile qFile ( qPath ) ; if ( qFile . open ( QIODevice :: WriteOnly ) ) { QTextStream out ( & qFile ) ; out << mainPage ; qFile . close ( ) ; } this -> close ( ) ; }
@brief GeneratorWindow::on_generateButton_clicked
 Action on generate button clicked.
@brief GeneratorWindow :: on_generateButton_clicked Action on generate button clicked .