116 lines
3.4 KiB
C++
Executable File
116 lines
3.4 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* CodificationDataManagement - Export codification table csv data
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by hjl, SLSE, 2017-01-23
|
|
*/
|
|
|
|
#include "cod_csv_export.h"
|
|
#include "cod_numeral_code_model.h"
|
|
#include "cod_authentication_code_model.h"
|
|
#include "cod_logistical_terms_model.h"
|
|
#include "cod_phrase_table_model.h"
|
|
|
|
#include <LtsWidgets/lts_message_dialog.h>
|
|
|
|
#include <QFile>
|
|
#include <QFileDialog>
|
|
|
|
|
|
using namespace CodificationManagement;
|
|
|
|
CSVExport::CSVExport(const NumeralCodeModel *numCodeModel,
|
|
const AuthenticationCodeModel *authenticationCodeModel,
|
|
const LogisticalTermsModel *logisticalTermsModel,
|
|
const PhraseTableModel *phraseTableModel,
|
|
const QString ¬e,
|
|
QWidget *parent)
|
|
: QWidget(parent)
|
|
, m_numCodeModel(numCodeModel)
|
|
, m_authenticationCodeModel(authenticationCodeModel)
|
|
, m_logisticalTermsModel(logisticalTermsModel)
|
|
, m_phraseTableModel(phraseTableModel)
|
|
, m_note(note)
|
|
, m_logger(getLogger("CodificationCSVExport"))
|
|
{
|
|
} // end of ctor()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
QByteArray CSVExport::exportToByteArray() const
|
|
{
|
|
QByteArray byteArray;
|
|
|
|
// Numeral Code table
|
|
byteArray.append("<Numeral Code Horizontal Header>\n");
|
|
byteArray.append(m_numCodeModel->getHorizontalHeaderCSVString().toUtf8());
|
|
byteArray.append("\n");
|
|
byteArray.append("<Numeral Code Vertical Header>\n");
|
|
byteArray.append(m_numCodeModel->getVerticalHeaderCSVString().toUtf8());
|
|
byteArray.append("\n");
|
|
|
|
// Authentication table
|
|
byteArray.append("<Authentication Code Matrix>\n");
|
|
byteArray.append(m_authenticationCodeModel->getMatrixDataCSVString().toUtf8());
|
|
byteArray.append("\n");
|
|
|
|
// Logistical Terms table
|
|
byteArray.append("<Logistical Terms Table Horizontal Header>\n");
|
|
byteArray.append(m_logisticalTermsModel->getHorizontalHeaderCSVString().toUtf8());
|
|
byteArray.append("\n");
|
|
byteArray.append("<Logistical Terms Table Vertical Header>\n");
|
|
byteArray.append(m_logisticalTermsModel->getVerticalHeaderCSVString().toUtf8());
|
|
byteArray.append("\n");
|
|
byteArray.append("<Logistical Terms Table Matrix>\n");
|
|
byteArray.append(m_logisticalTermsModel->getMatrixDataCSVString().toUtf8());
|
|
byteArray.append("\n");
|
|
|
|
// Phrase table
|
|
byteArray.append("<Phrase Table Matrix>\n");
|
|
byteArray.append(m_phraseTableModel->getMatrixDataCSVString().toUtf8());
|
|
byteArray.append("\n");
|
|
|
|
// Note
|
|
byteArray.append("<Note>\n");
|
|
byteArray.append(m_note.toLocal8Bit());
|
|
|
|
return byteArray;
|
|
|
|
}
|
|
|
|
bool CSVExport::writeCSVData()
|
|
{
|
|
DEBUG_LOG(m_logger) << "writeCSVData()";
|
|
|
|
QFileDialog dialog;
|
|
dialog.setNameFilter(tr("CSV File (*.csv)"));
|
|
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
|
dialog.setDirectory(QLatin1String("../TMP"));
|
|
dialog.setDefaultSuffix(QLatin1String("csv"));
|
|
|
|
if (!dialog.exec())
|
|
return false;
|
|
const QStringList fileNames = dialog.selectedFiles();
|
|
if (fileNames.isEmpty())
|
|
return false;
|
|
|
|
QFile file;
|
|
file.setFileName(fileNames.first());
|
|
|
|
if (!file.open(QFile::ReadWrite))
|
|
{
|
|
LtsWidgets::LtsMessageDialog::showMessage(this, tr("File is not accessible!"), tr("CSV Export Error"));
|
|
return false;
|
|
}
|
|
|
|
QByteArray byteArray = exportToByteArray();
|
|
|
|
file.write(byteArray);
|
|
|
|
file.close();
|
|
return true;
|
|
|
|
} // end of writeCSVData()
|
|
//-----------------------------------------------------------------------------
|