void DlgSettingsExportFormat::updatePreview()
{
  // Save the scroll position for continuity before and after the preview update
  int scrollPosition = m_editPreview->verticalScrollBar()->value();

  QString exportedTextFunctions, exportedTextRelations, exportedHtml;
  QTextStream strFunctions (&exportedTextFunctions);
  QTextStream strRelations (&exportedTextRelations);

  if (mainWindow().transformation().transformIsDefined()) {

    unsigned int numWritesSoFar = 0;

    ExportFileFunctions exportStrategyFunctions;
    exportStrategyFunctions.exportToFile (*m_modelExportAfter,
                                          cmdMediator().document(),
                                          mainWindow().modelMainWindow(),
                                          mainWindow().transformation(),
                                          strFunctions,
                                          numWritesSoFar);

    ExportFileRelations exportStrategyRelations;
    exportStrategyRelations.exportToFile (*m_modelExportAfter,
                                          cmdMediator().document(),
                                          mainWindow().modelMainWindow(),
                                          mainWindow().transformation(),
                                          strRelations,
                                          numWritesSoFar);

    // Use html to set background color. A <div> fills the whole background, unlike a <span>.
    // Final carriage return is removed to prevent unwanted blank line. A requirement is that
    // if there are no functions then no empty <div> appears (too confusing), and likewise if
    // there are no relations
    QString exportedHtmlFunctions, exportedHtmlRelations;
    if (! exportedTextFunctions.isEmpty ()) {

      exportedHtmlFunctions = exportedTextToExportedHtml (exportedTextFunctions, COLOR_FUNCTIONS);
    }
    if (! exportedTextRelations.isEmpty ()) {

      exportedHtmlRelations = exportedTextToExportedHtml (exportedTextRelations, COLOR_RELATIONS);
    }

    exportedHtml = exportedHtmlFunctions + exportedHtmlRelations;

  } else {

    exportedHtml = tr ("Preview is unavailable until axis points are defined.");
  }

  m_editPreview->setHtml (exportedHtml);

  // Restore scroll position
  m_editPreview->verticalScrollBar()->setValue (scrollPosition);
}
void DlgSettingsExportFormat::updatePreview()
{
  // Save the scroll position for continuity before and after the preview update
  int scrollPosition = m_editPreview->verticalScrollBar()->value();

  QString exportedText;
  QTextStream str (&exportedText);

  if (mainWindow().transformation().transformIsDefined()) {

    // Transformaiton is defined so we can create a preview
    if (m_tabWidget->currentIndex() == TAB_WIDGET_INDEX_FUNCTIONS) {

      ExportFileFunctions exportStrategy;
      exportStrategy.exportToFile (*m_modelExportAfter,
                                   cmdMediator().document(),
                                   mainWindow().modelMainWindow(),
                                   mainWindow().transformation(),
                                   str);

    } else {

      ExportFileRelations exportStrategy;
      exportStrategy.exportToFile (*m_modelExportAfter,
                                   cmdMediator().document(),
                                   mainWindow().modelMainWindow(),
                                   mainWindow().transformation(),
                                   str);

    }
  } else {

    str << "Preview is unavailable until axis points are defined.";
  }

  m_editPreview->setText (exportedText);

  // Restore scroll position
  m_editPreview->verticalScrollBar()->setValue (scrollPosition);
}
void ExportToFile::exportToFile (const DocumentModelExportFormat &modelExport,
                                 const Document &document,
                                 const MainWindowModel &modelMainWindow,
                                 const Transformation &transformation,
                                 QTextStream &str) const
{
  LOG4CPP_INFO_S ((*mainCat)) << "ExportToFile::exportToFile";

  ExportFileFunctions exportFunctions;
  exportFunctions.exportToFile (modelExport,
                                document,
                                modelMainWindow,
                                transformation,
                                str);

  ExportFileRelations exportRelations;
  exportRelations.exportToFile (modelExport,
                                document,
                                modelMainWindow,
                                transformation,
                                str);
}