c1 = connect(&m_exportRawDataDialog, SIGNAL(fileNameChanged(QString)), &exporter, SLOT(guessFormatFromSuffix(QString)));
c2 = connect(&exporter, SIGNAL(formatChanged(int)), &m_exportRawDataDialog, SLOT(onFormatChanged(int)));
for (const std::string& s : sr->allKeys())
- m_exportRawDataDialog.addAvailableSignal(QString::fromStdString(s));
+ m_exportRawDataDialog.addAvailableSignal(Helpers::signalTagToHumanReadable(s), s);
do {
int dret = m_exportRawDataDialog.exec();
if (dret == QDialog::Rejected)
ret = 0;
- else if (dret == QDialog::Accepted && !m_exportRawDataDialog.isSignalSelected()) {
- QMessageBox::information(nullptr, S_RES_DATAEXPORT, "No signals selected");
- } else if (dret == QDialog::Accepted && m_exportRawDataDialog.isSignalSelected()) {
- std::vector<std::string> selKeys = m_exportRawDataDialog.selectedSignalKeys();
+ if (dret == QDialog::Accepted) {
DataFileExporter::ReturnCode exRet;
+ std::vector<std::string> selKeys = m_exportRawDataDialog.selectedSignalKeys();
+
+ if (selKeys.size() < 1) {
+ QMessageBox::information(nullptr, S_RES_DATAEXPORT, "No signals selected");
+ continue;
+ }
+
/* Generate data to export */
genfunc(writeList, sr, selKeys);
#include "exportrawdatadialog.h"
#include "ui_exportrawdatadialog.h"
+#include <QStandardItem>
#include <QtWidgets/QFileDialog>
+const int ExportRawDataDialog::SIGNAL_TAG_ROLE = Qt::UserRole + 1;
+
ExportRawDataDialog::ExportRawDataDialog(const QStringList& supportedFormats, QWidget* parent) :
QDialog(parent),
m_lastPath(""),
ui->setupUi(this);
ui->qcbox_formats->addItems(supportedFormats);
+ ui->qlv_availableSignals->setModel(&m_availableSignals);
connect(ui->qpb_browse, SIGNAL(clicked()), this, SLOT(onBrowseClicked()));
connect(ui->qpb_ok, SIGNAL(clicked()), this, SLOT(accept()));
/* Public functions */
-void ExportRawDataDialog::addAvailableSignal(const QString& name)
+void ExportRawDataDialog::addAvailableSignal(const QString& readable_name, const std::string& tag)
{
- QCheckBox* cbox = new QCheckBox(name, this);
- m_signalCheckboxes.push_back(cbox);
- ui->form_availSigs->addRow(cbox);
+ QStandardItem* item = new QStandardItem();
+ item->setCheckable(true);
+ item->setCheckState(Qt::Unchecked);
+ item->setData(readable_name, Qt::DisplayRole);
+ item->setData(QString(tag.c_str()), SIGNAL_TAG_ROLE);
+ m_availableSignals.appendRow(item);
}
QString ExportRawDataDialog::destination() const
return ui->qcbox_formats->currentIndex();
}
-bool ExportRawDataDialog::isSignalSelected() const
-{
- for (const QCheckBox* cbox : m_signalCheckboxes)
- if (cbox->isChecked()) return true;
-
- return false;
-}
-
void ExportRawDataDialog::removeAllSignals()
{
- QLayoutItem* item;
- while ((item = ui->form_availSigs->takeAt(0)) != nullptr) {
- delete item->widget();
- delete item;
- }
- m_signalCheckboxes.clear();
+ m_availableSignals.clear();
}
std::vector<std::string> ExportRawDataDialog::selectedSignalKeys() const
{
std::vector<std::string> kl;
- kl.reserve(m_signalCheckboxes.size());
+ kl.reserve(m_availableSignals.rowCount());
- for (const QCheckBox* cbox : m_signalCheckboxes) {
- if (cbox->isChecked())
- kl.push_back(cbox->text().toStdString());
+ for (int idx = 0; idx < m_availableSignals.rowCount(); idx++) {
+ const QStandardItem* item = m_availableSignals.item(idx);
+ if (item->checkState() == Qt::Checked)
+ kl.push_back(item->data(SIGNAL_TAG_ROLE).toString().toStdString());
}
return kl;
#ifndef EXPORTRAWDATADIALOG_H
#define EXPORTRAWDATADIALOG_H
+#include <QStandardItemModel>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QDialog>
#include <QtWidgets/QLabel>
public:
explicit ExportRawDataDialog(const QStringList& supportedFormats, QWidget* parent = nullptr);
~ExportRawDataDialog();
- void addAvailableSignal(const QString& name);
+ void addAvailableSignal(const QString& readable_name, const std::string& tag);
QString destination() const;
int format() const;
- bool isSignalSelected() const;
void removeAllSignals();
std::vector<std::string> selectedSignalKeys() const;
- int signalsCount() const { return m_signalCheckboxes.size(); }
private:
QString m_lastPath;
- std::vector<QCheckBox*> m_signalCheckboxes;
QStringList m_supportedFormats;
+ QStandardItemModel m_availableSignals;
Ui::ExportRawDataDialog* ui;
+ static const int SIGNAL_TAG_ROLE;
+
public slots:
void onFormatChanged(const int idx);
<x>0</x>
<y>0</y>
<width>400</width>
- <height>300</height>
+ <height>344</height>
</rect>
</property>
<property name="sizePolicy">
</widget>
</item>
<item>
- <layout class="QFormLayout" name="form_availSigs"/>
+ <widget class="QListView" name="qlv_availableSignals"/>
</item>
</layout>
</widget>
return name.mid(dotIdx+1).toLower();
}
+
+QString Helpers::signalTagToHumanReadable(const std::string& tag)
+{
+ QString hr = QString::fromStdString(tag);
+
+ hr.replace("_", " ");
+
+ return hr;
+}
static int dpiY();
static double firstTick(const double from, const double step);
static QString getFileNameSuffix(const QString& name);
+ static QString signalTagToHumanReadable(const std::string& tag);
template <typename T> static T average(T* vals, size_t len)
{