From 6eaf006d90c1e50ef5c74fae52b5eb9eb5327388 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Fri, 13 Dec 2013 17:36:42 +0100 Subject: [PATCH] Unify raw data and peaks data exporting infrastructure. --- datamanager.cpp | 98 ++++++++++++++++++++----------------- datamanager.h | 7 +-- gui/exportrawdatadialog.cpp | 21 ++++---- gui/exportrawdatadialog.h | 4 +- signalcontroller.h | 1 + singlerundata.cpp | 18 +++++++ singlerundata.h | 4 +- 7 files changed, 93 insertions(+), 60 deletions(-) diff --git a/datamanager.cpp b/datamanager.cpp index a91f6f1..d00e082 100644 --- a/datamanager.cpp +++ b/datamanager.cpp @@ -46,31 +46,53 @@ DataManager::DataManager(QObject* parent) : /* Private functions */ -void DataManager::generateRawDataWriteList(DataFileExporter::WriteList& writeList, std::shared_ptr data) +void DataManager::generateIntegDataWriteList(DataFileExporter::WriteList& writeList, const std::shared_ptr sr, const std::vector &keys) { - QVariantList header; - std::vector lines; - std::pair> p; - std::string dname; - std::shared_ptr sig; - - try { - sig = std::dynamic_pointer_cast(data); - } catch (std::bad_cast&) { - return; + for (const std::string& key : keys) { + QVariantList header; + std::vector lines; + std::pair> p; + const std::shared_ptr ctrl = sr->controllerAt(key); + std::shared_ptr integrator; + if (ctrl == nullptr) + continue; + + header << "time [" + QString::fromStdString(ctrl->signal()->xunitToString()) + "]" << "area [" + QString::fromStdString(ctrl->signal()->xunitToString()) + " " + + QString::fromStdString(ctrl->signal()->yunitToString()) + "]" << "width [" + QString::fromStdString(ctrl->signal()->xunitToString()) + "]" + << "height [" + QString::fromStdString(ctrl->signal()->yunitToString()) + "]"; + integrator = ctrl->cIntegrator(); + for (std::multimap>::const_iterator cit = integrator->peaksCBegin(); + cit != integrator->peaksCEnd(); cit++) { + QVariantList line; + line << cit->second->peakTime() << cit->second->auc() << cit->second->width() << cit->second->height(); + lines.push_back(line); + } + p = std::pair>(header, lines); + writeList[key] = p; } +} - dname = sig->descriptiveName(); - - /* Create header */ - header << QString("time [" + QString::fromStdString(sig->xunitToString()) + "]") << QString("value [" + QString::fromStdString(sig->yunitToString()) + "]"); - for (const Signal::TimeValuePair& tvp : sig->values()) { - QVariantList line; - line << tvp.first << tvp.second; - lines.push_back(line); - } - p = std::pair>(header, lines); - writeList[dname] = p; +void DataManager::generateRawDataWriteList(DataFileExporter::WriteList& writeList, const std::shared_ptr sr, const std::vector& keys) +{ + for (const std::string& key : keys) { + QVariantList header; + std::vector lines; + std::pair> p; + const std::shared_ptr sig = sr->signalAt(key); + if (sig == nullptr) + continue; + + /* Create header */ + header << QString("time [" + QString::fromStdString(sig->xunitToString()) + "]") << QString("value [" + QString::fromStdString(sig->yunitToString()) + "]"); + for (const Signal::TimeValuePair& tvp : sig->values()) { + QVariantList line; + line << tvp.first << tvp.second; + lines.push_back(line); + } + + p = std::pair>(header, lines); + writeList[key] = p; + } } std::shared_ptr DataManager::sequenceByKey(const QString& key) @@ -107,32 +129,28 @@ Signal::Equipment DataManager::equipmentFromFiletype(AGRE_Filetype filetype) } } -void DataManager::processDataExport(std::function)> genfunc) +void DataManager::processDataExport(GeneratorFunc genfunc) { DataFileExporter exporter(this); ExportRawDataDialog dlg(DataFileExporter::SUPPORTED_FORMATS); DataFileExporter::WriteList writeList; DataFileExporter::ReturnCode ret; - std::shared_ptr srd = m_activeSequence->selectedRun(); + std::shared_ptr sr = m_activeSequence->selectedRun(); - //for (uint idx = 0; idx < m_activeSequence->selectedRun()->signalCount(); idx++) - //dlg.addAvailableSignal(m_activeSequence->selectedRun()->signalAt(idx)->descriptiveName()); - for (const std::string& s : srd->allKeys()) + for (const std::string& s : sr->allKeys()) dlg.addAvailableSignal(QString::fromStdString(s)); do { int dret = dlg.exec(); if (dret == QDialog::Rejected) return; - else if (dret == QDialog::Accepted && dlg.selectedSignalsCount() < 1) { + else if (dret == QDialog::Accepted && !dlg.isSignalSelected()) { QMessageBox::information(nullptr, "Data export error", "No signals selected"); ret = DataFileExporter::ReturnCode::E_TRYAGAIN; - } else if (dret == QDialog::Accepted && dlg.selectedSignalsCount() >= 1) { + } else if (dret == QDialog::Accepted && dlg.isSignalSelected()) { + std::vector selKeys = dlg.selectedSignalKeys(); /* Generate data to export */ - for (int idx = 0; idx < dlg.signalsCount(); idx++) { - if (dlg.isSignalSelected(idx)); - //genfunc(writeList, m_activeSequence->selectedRun()->signalAt(idx)); - } + genfunc(writeList, sr, selKeys); ret = exporter.exportData(writeList, dlg.destination(), dlg.format()); } } while (ret == DataFileExporter::ReturnCode::E_TRYAGAIN); @@ -354,27 +372,19 @@ void DataManager::showOneSignal(std::shared_ptr ctrl) void DataManager::onExportPeaks() { - std::vector> ctrls; - if (m_activeSequence == nullptr) return; - if (m_activeSequence->selectedRun() == nullptr) - return; - - - //std::function)> f = std::bind(&DataManager::generateIntegDataWriteList, this, std::placeholders::_1, std::placeholders::_2); - //processDataExport(f); + GeneratorFunc f = std::bind(&DataManager::generateIntegDataWriteList, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); + processDataExport(f); } void DataManager::onExportRawData() { if (m_activeSequence == nullptr) return; - if (m_activeSequence->selectedRun() == nullptr) - return; - std::function)> f = std::bind(&DataManager::generateRawDataWriteList, this, std::placeholders::_1, std::placeholders::_2); + GeneratorFunc f = std::bind(&DataManager::generateRawDataWriteList, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); processDataExport(f); } diff --git a/datamanager.h b/datamanager.h index fa0baff..93be0be 100644 --- a/datamanager.h +++ b/datamanager.h @@ -36,6 +36,7 @@ #include #include "metatypes.h" +typedef std::function, std::vector&)> GeneratorFunc; class DataManager : public QObject { @@ -47,12 +48,12 @@ public: private: Signal::Equipment equipmentFromFiletype(AGRE_Filetype filetype); - void generateIntegDataWriteList(DataFileExporter::WriteList& writeList, std::shared_ptr data); - void generateRawDataWriteList(DataFileExporter::WriteList& writeList, std::shared_ptr data); + void generateIntegDataWriteList(DataFileExporter::WriteList& writeList, const std::shared_ptr sr, const std::vector& keys); + void generateRawDataWriteList(DataFileExporter::WriteList& writeList, const std::shared_ptr sr, const std::vector& keys); std::shared_ptr sequenceByKey(const QString& key); int sequenceIdxByKey(const QString& key); std::shared_ptr loadSingleRun(QDir& dir); - void processDataExport(std::function)> genfunc); + void processDataExport(GeneratorFunc genfunc); Signal::Resource resourceFromFiletype(AGRE_Filetype filetype); std::string signalControllerKey(const QString& main, const QString& resource) ; void showOneSignal(std::shared_ptr ctrl); diff --git a/gui/exportrawdatadialog.cpp b/gui/exportrawdatadialog.cpp index e4817c8..bde220e 100644 --- a/gui/exportrawdatadialog.cpp +++ b/gui/exportrawdatadialog.cpp @@ -57,22 +57,25 @@ int ExportRawDataDialog::format() const return ui->qcbox_formats->currentIndex(); } -bool ExportRawDataDialog::isSignalSelected(int idx) const +bool ExportRawDataDialog::isSignalSelected() const { - if (idx >= m_signalCheckboxes.size()) - return false; - else - return m_signalCheckboxes.at(idx)->isChecked(); + for (const QCheckBox* cbox : m_signalCheckboxes) + if (cbox->isChecked()) return true; + + return false; } -int ExportRawDataDialog::selectedSignalsCount() const +std::vector ExportRawDataDialog::selectedSignalKeys() const { - int cnt = 0; + std::vector kl; + kl.reserve(m_signalCheckboxes.size()); + for (const QCheckBox* cbox : m_signalCheckboxes) { if (cbox->isChecked()) - cnt++; + kl.push_back(cbox->text().toStdString()); } - return cnt; + + return kl; } /* Private slots */ diff --git a/gui/exportrawdatadialog.h b/gui/exportrawdatadialog.h index d8c8014..db1c0d5 100644 --- a/gui/exportrawdatadialog.h +++ b/gui/exportrawdatadialog.h @@ -41,8 +41,8 @@ public: void addAvailableSignal(const QString& name); QString destination() const; int format() const; - bool isSignalSelected(int idx) const; - int selectedSignalsCount() const; + bool isSignalSelected() const; + std::vector selectedSignalKeys() const; int signalsCount() const { return m_signalCheckboxes.size(); } private: diff --git a/signalcontroller.h b/signalcontroller.h index 44c59c0..b11e758 100644 --- a/signalcontroller.h +++ b/signalcontroller.h @@ -41,6 +41,7 @@ public: SignalDataTableModel* dataTableModel() { return m_dtblModel; } IntegrationTableModel* integrationTableModel() { return m_integTblModel;} const std::shared_ptr signal() const { return m_signal; } + const std::shared_ptr cIntegrator() const { return m_integrator; } private: GraphViewContextMenu m_ctxMenu; diff --git a/singlerundata.cpp b/singlerundata.cpp index 3b762c2..4c70828 100644 --- a/singlerundata.cpp +++ b/singlerundata.cpp @@ -47,3 +47,21 @@ std::vector SingleRunData::allKeys() const return keys; } + +std::shared_ptr SingleRunData::controllerAt(const std::string& key) +{ + try { + return m_ctrls.at(key); + } catch (std::out_of_range&) { + return nullptr; + } +} + +std::shared_ptr SingleRunData::signalAt(const std::string& key) +{ + try { + return m_signals.at(key); + } catch (std::out_of_range&) { + return nullptr; + } +} diff --git a/singlerundata.h b/singlerundata.h index 27bbeae..c099fa9 100644 --- a/singlerundata.h +++ b/singlerundata.h @@ -38,13 +38,13 @@ public: std::unordered_map>& sigs, std::unordered_map>& ctrls, const QString& dirname, QObject* parent = nullptr); std::vector allKeys() const; - std::shared_ptr controllerAt(const std::string& key) { return m_ctrls.at(key); } + std::shared_ptr controllerAt(const std::string& key); QDate date() const { return m_date; } QString dirName() const { return m_dirName; } QString methodName() const { return m_methodName; } QString operatorName() const { return m_operatorName; } QString sampleInfo() const { return m_sampleInfo; } - std::shared_ptr signalAt(const std::string& key) { return m_signals.at(key); } + std::shared_ptr signalAt(const std::string& key); const std::unordered_map>& allSignals() const { return m_signals; } size_t signalCount() const { return m_signals.size(); } QTime time() const { return m_time; } -- 2.43.5