]> Devoid-pointer.net GitWeb - anyanka.git/commitdiff
Unify raw data and peaks data exporting infrastructure.
authorMichal Malý <madcatxster@prifuk.cz>
Fri, 13 Dec 2013 16:36:42 +0000 (17:36 +0100)
committerMichal Malý <madcatxster@prifuk.cz>
Fri, 13 Dec 2013 16:36:42 +0000 (17:36 +0100)
datamanager.cpp
datamanager.h
gui/exportrawdatadialog.cpp
gui/exportrawdatadialog.h
signalcontroller.h
singlerundata.cpp
singlerundata.h

index a91f6f185e900eef167819697acec4c3007c1ebf..d00e0826facada194ba6e431d588836a73e87d50 100644 (file)
@@ -46,31 +46,53 @@ DataManager::DataManager(QObject* parent) :
 
 /* Private functions */
 
-void DataManager::generateRawDataWriteList(DataFileExporter::WriteList& writeList, std::shared_ptr<const QObject> data)
+void DataManager::generateIntegDataWriteList(DataFileExporter::WriteList& writeList, const std::shared_ptr<SingleRunData> sr, const std::vector<std::string> &keys)
 {
-  QVariantList header;
-  std::vector<QVariantList> lines;
-  std::pair<QVariantList, std::vector<QVariantList>> p;
-  std::string dname;
-  std::shared_ptr<const Signal> sig;
-
-  try {
-    sig = std::dynamic_pointer_cast<const Signal>(data);
-  } catch (std::bad_cast&) {
-    return;
+  for (const std::string& key : keys) {
+    QVariantList header;
+    std::vector<QVariantList> lines;
+    std::pair<QVariantList, std::vector<QVariantList>> p;
+    const std::shared_ptr<SignalController> ctrl = sr->controllerAt(key);
+    std::shared_ptr<const Integrator> 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<size_t, std::shared_ptr<IntegratedPeak>>::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<QVariantList, std::vector<QVariantList>>(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<QVariantList, std::vector<QVariantList>>(header, lines);
-   writeList[dname] = p;
+void DataManager::generateRawDataWriteList(DataFileExporter::WriteList& writeList, const std::shared_ptr<SingleRunData> sr, const std::vector<std::string>& keys)
+{
+  for (const std::string& key : keys) {
+    QVariantList header;
+    std::vector<QVariantList> lines;
+    std::pair<QVariantList, std::vector<QVariantList>> p;
+    const std::shared_ptr<Signal> 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<QVariantList, std::vector<QVariantList>>(header, lines);
+    writeList[key] = p;
+  }
 }
 
 std::shared_ptr<Sequence> DataManager::sequenceByKey(const QString& key)
@@ -107,32 +129,28 @@ Signal::Equipment DataManager::equipmentFromFiletype(AGRE_Filetype filetype)
   }
 }
 
-void DataManager::processDataExport(std::function<void (DataFileExporter::WriteList&, std::shared_ptr<const QObject>)> genfunc)
+void DataManager::processDataExport(GeneratorFunc genfunc)
 {
   DataFileExporter exporter(this);
   ExportRawDataDialog dlg(DataFileExporter::SUPPORTED_FORMATS);
   DataFileExporter::WriteList writeList;
   DataFileExporter::ReturnCode ret;
-  std::shared_ptr<SingleRunData> srd = m_activeSequence->selectedRun();
+  std::shared_ptr<SingleRunData> 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<std::string> 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<SignalController> ctrl)
 
 void DataManager::onExportPeaks()
 {
-  std::vector<std::shared_ptr<const SignalController>> ctrls;
-
   if (m_activeSequence == nullptr)
     return;
-  if (m_activeSequence->selectedRun() == nullptr)
-    return;
 
-
-
-  //std::function<void (DataFileExporter::WriteList&, std::shared_ptr<const QObject>)> 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<void (DataFileExporter::WriteList&, std::shared_ptr<const QObject>)> 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);
 }
 
index fa0baff34c35b1bf6bb540e390e3bd488b386f1b..93be0beac3acc2ae3f8228e4512196e1cdaea594 100644 (file)
@@ -36,6 +36,7 @@
 #include <QtCore/QTime>
 #include "metatypes.h"
 
+typedef std::function<void (DataFileExporter::WriteList&, const std::shared_ptr<SingleRunData>, std::vector<std::string>&)> 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<const QObject> data);
-  void generateRawDataWriteList(DataFileExporter::WriteList& writeList, std::shared_ptr<const QObject> data);
+  void generateIntegDataWriteList(DataFileExporter::WriteList& writeList, const std::shared_ptr<SingleRunData> sr, const std::vector<std::string>& keys);
+  void generateRawDataWriteList(DataFileExporter::WriteList& writeList, const std::shared_ptr<SingleRunData> sr, const std::vector<std::string>& keys);
   std::shared_ptr<Sequence> sequenceByKey(const QString& key);
   int sequenceIdxByKey(const QString& key);
   std::shared_ptr<SingleRunData> loadSingleRun(QDir& dir);
-  void processDataExport(std::function<void (DataFileExporter::WriteList&, std::shared_ptr<const QObject>)> 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<SignalController> ctrl);
index e4817c8cf404288da90c4eb399edc48e7a0e3cce..bde220e01b2b16bdf0277bdf0891bbbbfaf8fd87 100644 (file)
@@ -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<std::string> ExportRawDataDialog::selectedSignalKeys() const
 {
-  int cnt = 0;
+  std::vector<std::string> 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 */
index d8c8014f6aa8568e9676153bd0385c429dd4ab28..db1c0d5a0897fd4e8f5a419861647edb995f4199 100644 (file)
@@ -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<std::string> selectedSignalKeys() const;
   int signalsCount() const { return m_signalCheckboxes.size(); }
 
 private:
index 44c59c0a3033f0f5ca3aaf8f8addd834f0a07b9f..b11e7580c9bda4c790c3ae47dcfff23ad6b39370 100644 (file)
@@ -41,6 +41,7 @@ public:
   SignalDataTableModel* dataTableModel() { return m_dtblModel; }
   IntegrationTableModel* integrationTableModel() { return m_integTblModel;}
   const std::shared_ptr<Signal> signal() const { return m_signal; }
+  const std::shared_ptr<Integrator> cIntegrator() const { return m_integrator; }
 
 private:
   GraphViewContextMenu m_ctxMenu;
index 3b762c266c959d397c93d89229b6bdaf9bc8c641..4c70828f2f9766bda3c90b5e5ac7e559033c6f51 100644 (file)
@@ -47,3 +47,21 @@ std::vector<std::string> SingleRunData::allKeys() const
 
   return keys;
 }
+
+std::shared_ptr<SignalController> SingleRunData::controllerAt(const std::string& key)
+{
+  try {
+    return m_ctrls.at(key);
+  } catch (std::out_of_range&) {
+    return nullptr;
+  }
+}
+
+std::shared_ptr<Signal> SingleRunData::signalAt(const std::string& key)
+{
+  try {
+    return m_signals.at(key);
+  } catch (std::out_of_range&) {
+    return nullptr;
+  }
+}
index 27bbeaeb6aafc60aa2ad9b93a5bbc5adb6b394c0..c099fa96a52bb7e333512786a1b66fda64586b85 100644 (file)
@@ -38,13 +38,13 @@ public:
                          std::unordered_map<std::string, std::shared_ptr<Signal>>& sigs, std::unordered_map<std::string, std::shared_ptr<SignalController>>& ctrls,
                          const QString& dirname, QObject* parent = nullptr);
   std::vector<std::string> allKeys() const;
-  std::shared_ptr<SignalController> controllerAt(const std::string& key) { return m_ctrls.at(key); }
+  std::shared_ptr<SignalController> 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<Signal> signalAt(const std::string& key) { return m_signals.at(key); }
+  std::shared_ptr<Signal> signalAt(const std::string& key);
   const std::unordered_map<std::string, std::shared_ptr<Signal>>& allSignals() const { return m_signals; }
   size_t signalCount() const { return m_signals.size(); }
   QTime time() const { return m_time; }