#include <QtWidgets/QMessageBox>
-const std::vector<DataFileExporter::OutputFormat> DataFileExporter::SUPPORTED_FORMATS({DataFileExporter::OutputFormat("Comma separated values", "csv")});
+const std::unordered_map<std::string, QString> DataFileExporter::SUPPORTED_FORMATS({{"csv", "Comma separated values"}});
/* Static methods */
-QStringList DataFileExporter::supportedFormats()
+const std::unordered_map<std::string, QString>& DataFileExporter::supportedFormats()
{
- QStringList list;
-
- for (const OutputFormat& of : SUPPORTED_FORMATS) {
- list << of.description;
- }
-
- return list;
+ return SUPPORTED_FORMATS;
}
DataFileExporter::DataFileExporter(QObject* parent) :
/* Public methods */
DataFileExporter::ReturnCode DataFileExporter::
-exportData(const WriteList& list, const QString& path, const int formatIdx)
+exportData(const WriteList& list, const QString& path, const std::string& formatTag)
{
QDir dir(path);
QFile file(path);
DataFileExporter::ReturnCode ret;
DataWriterBackend* backend;
- if (formatIdx < 0 || formatIdx >= SUPPORTED_FORMATS.size()) {
- return ReturnCode::E_INVAL_FORMAT;
- }
-
if (path.compare("") == 0) {
return ReturnCode::E_NO_OUTPUT;
}
file.remove();
}
- format = formatIdxToFormat(formatIdx);
+ format = formatTagToFormat(formatTag);
switch (format) {
case OutputFormats::CSV:
backend = new CSVDataWriterBackend(this);
/* Private methods */
-DataFileExporter::OutputFormats DataFileExporter::formatIdxToFormat(const int idx)
+DataFileExporter::OutputFormats DataFileExporter::formatTagToFormat(const std::string& tag)
{
- switch (idx) {
- case 0:
- return OutputFormats::CSV;
- default:
- return OutputFormats::INVALID;
- }
+ if (tag.compare("csv") == 0)
+ return OutputFormats::CSV;
+
+ return OutputFormats::INVALID;
}
DataFileExporter::ReturnCode DataFileExporter::writeToFile(QFile& file, const DataWriterBackend* backend, const std::pair<QVariantList, std::vector<QVariantList>>& data)
void DataFileExporter::guessFormatFromSuffix(const QString& name)
{
- QString suffix = Helpers::getFileNameSuffix(name);
+ std::string suffix = Helpers::getFileNameSuffix(name).toStdString();
if (suffix.length() == 0)
return;
- for (int idx = 0; idx < SUPPORTED_FORMATS.size(); idx++) {
- if (suffix.compare(SUPPORTED_FORMATS[idx].suffix) == 0) {
- emit formatChanged(idx);
+ for (const auto& format : SUPPORTED_FORMATS) {
+ if (suffix.compare(format.first) == 0) {
+ emit formatChanged(QString(format.first.c_str()));
return;
}
}
typedef std::unordered_map<std::string, std::pair<QVariantList, std::vector<QVariantList>>> WriteList;
explicit DataFileExporter(QObject* parent = nullptr);
- ReturnCode exportData(const WriteList& header, const QString& path, const int formatIdx);
+ ReturnCode exportData(const WriteList& header, const QString& path, const std::string& formatTag);
- static QStringList supportedFormats();
+ static const std::unordered_map<std::string, QString>& supportedFormats();
private:
enum class OutputFormats {
CSV,
INVALID
};
- struct OutputFormat {
- OutputFormat(const QString& description, const QString& suffix) :
- description(description), suffix(suffix) {}
- const QString description;
- const QString suffix;
- };
-
- OutputFormats formatIdxToFormat(const int idx);
- QString toCSVLine(double time, double value);
+ OutputFormats formatTagToFormat(const std::string& tag);
ReturnCode writeToFile(QFile& file, const DataWriterBackend* writer, const std::pair<QVariantList, std::vector<QVariantList>>& data);
- static const std::vector<OutputFormat> SUPPORTED_FORMATS;
+ static const std::unordered_map<std::string, QString> SUPPORTED_FORMATS;
signals:
- void formatChanged(const int idx);
+ void formatChanged(const QString& suffix);
public slots:
void guessFormatFromSuffix(const QString& name);
DataManager::DataManager(QObject* parent) :
QObject(parent),
m_prevSequenceKey(""),
- m_exportRawDataDialog(DataFileExporter::supportedFormats()),
+ m_exportRawDataDialog(),
m_graphToImageExportDialog(ImageDrawer::supportedImageFormats())
{
+ for (auto it = DataFileExporter::supportedFormats().cbegin(); it != DataFileExporter::supportedFormats().cend(); it++)
+ m_exportRawDataDialog.addSupportedFormat(it->second, it->first);
+
m_sequences[S_SEQ_KEY_SINGLE_RUNS] = std::shared_ptr<Sequence>(new Sequence());
m_seqSelModel.setSequences(allSequenceKeys());
m_sigNameCodec = QTextCodec::codecForName("UTF-8");
m_exportRawDataDialog.removeAllSignals();
c1 = connect(&m_exportRawDataDialog, SIGNAL(fileNameChanged(QString)), &exporter, SLOT(guessFormatFromSuffix(QString)));
- c2 = connect(&exporter, SIGNAL(formatChanged(int)), &m_exportRawDataDialog, SLOT(onFormatChanged(int)));
+ c2 = connect(&exporter, SIGNAL(formatChanged(const QString&)), &m_exportRawDataDialog, SLOT(onFormatChanged(const QString&)));
for (const auto& sm : sr->allSignals())
m_exportRawDataDialog.addAvailableSignal(sm.second->readableName(), sm.second->rawDescriptiveName());
#include <QStandardItem>
#include <QtWidgets/QFileDialog>
+const int ExportRawDataDialog::FORMAT_TAG_ROLE = Qt::UserRole + 1;
const int ExportRawDataDialog::SIGNAL_TAG_ROLE = Qt::UserRole + 1;
-ExportRawDataDialog::ExportRawDataDialog(const QStringList& supportedFormats, QWidget* parent) :
+ExportRawDataDialog::ExportRawDataDialog(QWidget* parent) :
QDialog(parent),
m_lastPath(""),
- m_supportedFormats(supportedFormats),
ui(new Ui::ExportRawDataDialog)
{
ui->setupUi(this);
- ui->qcbox_formats->addItems(supportedFormats);
+ ui->qcbox_formats->setModel(&m_supportedFormats);
ui->qlv_availableSignals->setModel(&m_availableSignals);
ui->qcbox_formats->setSizeAdjustPolicy(QComboBox::AdjustToContents);
ui->qlv_availableSignals->setSizeAdjustPolicy(QListView::AdjustToContents);
m_availableSignals.appendRow(item);
}
+void ExportRawDataDialog::addSupportedFormat(const QString& format_desc, const std::string& tag)
+{
+ QStandardItem* item = new QStandardItem(format_desc);
+ item->setData(QString(tag.c_str()), FORMAT_TAG_ROLE);
+ m_supportedFormats.appendRow(item);
+}
+
QString ExportRawDataDialog::destination() const
{
return ui->qle_destPath->text();
}
-int ExportRawDataDialog::format() const
+std::string ExportRawDataDialog::format() const
{
- return ui->qcbox_formats->currentIndex();
+ return ui->qcbox_formats->currentData(FORMAT_TAG_ROLE).toString().toStdString();
}
void ExportRawDataDialog::removeAllSignals()
}
/* Public slots */
-void ExportRawDataDialog::onFormatChanged(const int idx)
+void ExportRawDataDialog::onFormatChanged(const QString& suffix)
{
- ui->qcbox_formats->setCurrentIndex(idx);
+ for (int idx = 0; idx < m_supportedFormats.rowCount(); idx++) {
+ QString s = m_supportedFormats.item(idx)->data(FORMAT_TAG_ROLE).toString();
+ if (s.compare(suffix) == 0)
+ ui->qcbox_formats->setCurrentIndex(idx);
+ }
}
/* Private slots */
Q_OBJECT
public:
- explicit ExportRawDataDialog(const QStringList& supportedFormats, QWidget* parent = nullptr);
+ explicit ExportRawDataDialog(QWidget* parent = nullptr);
~ExportRawDataDialog();
void addAvailableSignal(const QString& readable_name, const std::string& tag);
+ void addSupportedFormat(const QString& format_desc, const std::string& tag);
QString destination() const;
- int format() const;
+ std::string format() const;
void removeAllSignals();
std::vector<std::string> selectedSignalKeys() const;
private:
QString m_lastPath;
- QStringList m_supportedFormats;
+ QStandardItemModel m_supportedFormats;
QStandardItemModel m_availableSignals;
Ui::ExportRawDataDialog* ui;
+ static const int FORMAT_TAG_ROLE;
static const int SIGNAL_TAG_ROLE;
public slots:
- void onFormatChanged(const int idx);
+ void onFormatChanged(const QString& suffix);
private slots:
void onBrowseClicked();