]> Devoid-pointer.net GitWeb - anyanka.git/commitdiff
Rewrite SingleRunData to std::unordered_map and store SignalControllers
authorMichal Malý <madcatxster@prifuk.cz>
Fri, 13 Dec 2013 09:59:50 +0000 (10:59 +0100)
committerMichal Malý <madcatxster@prifuk.cz>
Fri, 13 Dec 2013 09:59:50 +0000 (10:59 +0100)
along with Signals.

14 files changed:
datamanager.cpp
datamanager.h
gui/mainwindow.cpp
gui/mainwindow.h
main.cpp
sequence.cpp
sequence.h
signal.cpp
signal.h
signaldatatablemodel.cpp
singlerundata.cpp
singlerundata.h
singlerunsselectormodel.cpp
singlerunsselectormodel.h

index b2440c358f1d29e03c23659415e5cba316fdee96..a91f6f185e900eef167819697acec4c3007c1ebf 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "datamanager.h"
 #include "logger.h"
-#include "datafileexporter.h"
 #include "gui/exportrawdatadialog.h"
 #include <QtWidgets/QMessageBox>
 
@@ -45,6 +44,35 @@ DataManager::DataManager(QObject* parent) :
   m_sigNameCodec = QTextCodec::codecForName("ISO-8859-1");
 }
 
+/* Private functions */
+
+void DataManager::generateRawDataWriteList(DataFileExporter::WriteList& writeList, std::shared_ptr<const QObject> data)
+{
+  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;
+  }
+
+  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;
+}
+
 std::shared_ptr<Sequence> DataManager::sequenceByKey(const QString& key)
 {
   for (NameSequencePair p : m_sequences) {
@@ -79,6 +107,37 @@ Signal::Equipment DataManager::equipmentFromFiletype(AGRE_Filetype filetype)
   }
 }
 
+void DataManager::processDataExport(std::function<void (DataFileExporter::WriteList&, std::shared_ptr<const QObject>)> genfunc)
+{
+  DataFileExporter exporter(this);
+  ExportRawDataDialog dlg(DataFileExporter::SUPPORTED_FORMATS);
+  DataFileExporter::WriteList writeList;
+  DataFileExporter::ReturnCode ret;
+  std::shared_ptr<SingleRunData> srd = 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())
+    dlg.addAvailableSignal(QString::fromStdString(s));
+
+  do {
+    int dret = dlg.exec();
+    if (dret == QDialog::Rejected)
+      return;
+    else if (dret == QDialog::Accepted && dlg.selectedSignalsCount() < 1) {
+      QMessageBox::information(nullptr, "Data export error", "No signals selected");
+      ret = DataFileExporter::ReturnCode::E_TRYAGAIN;
+    } else if (dret == QDialog::Accepted && dlg.selectedSignalsCount() >= 1) {
+      /* Generate data to export */
+      for (int idx = 0; idx < dlg.signalsCount(); idx++) {
+        if (dlg.isSignalSelected(idx));
+          //genfunc(writeList, m_activeSequence->selectedRun()->signalAt(idx));
+      }
+      ret = exporter.exportData(writeList, dlg.destination(), dlg.format());
+    }
+   } while (ret == DataFileExporter::ReturnCode::E_TRYAGAIN);
+}
+
 Signal::Resource DataManager::resourceFromFiletype(AGRE_Filetype filetype)
 {
   switch (filetype) {
@@ -129,7 +188,8 @@ std::shared_ptr<SingleRunData> DataManager::loadSingleRun(QDir& dir)
 {
   std::vector<std::shared_ptr<AGRE_MeasurementInfo>> dataFiles;
   std::shared_ptr<SingleRunData> singleRun;
-  std::vector<std::shared_ptr<Signal>> sigs;
+  std::unordered_map<std::string, std::shared_ptr<Signal>> sigs;
+  std::unordered_map<std::string, std::shared_ptr<SignalController>> ctrls;
   DataFilesLoader::ReturnCode ret;
   LocalLoggerPtr llog = Logger::createLocalLog();
   llog->setPrintLevel(Logger::Level::WARNING);
@@ -149,6 +209,8 @@ std::shared_ptr<SingleRunData> DataManager::loadSingleRun(QDir& dir)
   QList<QDate> dates;
   QList<QTime> times;
   for (std::shared_ptr<AGRE_MeasurementInfo> mi : dataFiles) {
+    std::shared_ptr<Signal> _s;
+    std::shared_ptr<SignalController> _c;
     Signal::Equipment eqp;
     Signal::Resource res;
     double samplingRate;
@@ -189,8 +251,8 @@ std::shared_ptr<SingleRunData> DataManager::loadSingleRun(QDir& dir)
       Signal::TimeValuePair stvp(tvp.first, tvp.second);
       values.push_back(stvp);
     }
-    std::shared_ptr<Signal> _s(new Signal(eqp, res, samplingRate, yu, mi->dad_wavelength_abs, mi->dad_wavelength_ref, values));
-    sigs.push_back(_s);
+
+    _s = std::shared_ptr<Signal>(new Signal(eqp, res, samplingRate, yu, mi->dad_wavelength_abs, mi->dad_wavelength_ref, values));
 
     if (!date.isValid()) {
       llog->log(Logger::WARNING, ME_SENDER_STR, QString("Date ") + date.toString() + QString("is invalid."));
@@ -204,6 +266,11 @@ std::shared_ptr<SingleRunData> DataManager::loadSingleRun(QDir& dir)
     operatorNames.append(operatorName);
     methodNames.append(methodName);
     sampleInfos.append(sampleInfo);
+
+    _c = std::shared_ptr<SignalController>(new SignalController(_s));
+
+    sigs[_s->descriptiveName()] = _s;
+    ctrls[_s->descriptiveName()] = _c;
   }
 
   /* Check that all common run informaton are the same */
@@ -243,9 +310,10 @@ std::shared_ptr<SingleRunData> DataManager::loadSingleRun(QDir& dir)
     }
   }
 
-  singleRun = std::shared_ptr<SingleRunData>(new SingleRunData(methodNames.at(0), operatorNames.at(0), sampleInfos.at(0), dates.at(0), times.at(0), sigs,
+  singleRun = std::shared_ptr<SingleRunData>(new SingleRunData(methodNames.at(0), operatorNames.at(0), sampleInfos.at(0), dates.at(0), times.at(0), sigs, ctrls,
                                                                dir.dirName(), this));
 
+
   Logger::log(Logger::DEBUG, ME_SENDER_STR, "Single run successfully parsed");
 
   return singleRun;
@@ -258,12 +326,12 @@ void DataManager::showOneSignal(std::shared_ptr<SignalController> ctrl)
   swp->setDataTableModel(ctrl->dataTableModel());
   swp->setIntegrationTableModel(ctrl->integrationTableModel());
   if (ctrl->signal()->resource() == Signal::Resource::CE_DAD)
-    swp->setTypeText(ctrl->signal()->resourceToString() + QString(" Sig: ") + QString::number(ctrl->signal()->wavelengthAbsorbed()) + " nm, Ref: " +
+    swp->setTypeText(QString::fromStdString(ctrl->signal()->resourceToString()) + QString(" Sig: ") + QString::number(ctrl->signal()->wavelengthAbsorbed()) + " nm, Ref: " +
                      QString::number(ctrl->signal()->wavelengthReference()) + " nm");
   else
-    swp->setTypeText(ctrl->signal()->resourceToString());
-  swp->setXUnits(ctrl->signal()->xunitToString());
-  swp->setYUnits(ctrl->signal()->yunitToString());
+    swp->setTypeText(QString::fromStdString(ctrl->signal()->resourceToString()));
+  swp->setXUnits(QString::fromStdString(ctrl->signal()->xunitToString()));
+  swp->setYUnits(QString::fromStdString(ctrl->signal()->yunitToString()));
   connect(swp->m_graphView, SIGNAL(crosshairErased()), ctrl.get(), SLOT(onViewCrosshairErased()));
   connect(swp->m_graphView, SIGNAL(crosshairMoved(int,int)), ctrl.get(), SLOT(onViewCrosshairMoved(int,int)));
   connect(swp->m_graphView, SIGNAL(integrated(int,int,int,int)), ctrl.get(), SLOT(onViewIntegrated(int,int,int,int)));
@@ -292,57 +360,22 @@ void DataManager::onExportPeaks()
     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);
 }
 
 void DataManager::onExportRawData()
 {
-  DataFileExporter exporter(this);
-  ExportRawDataDialog dlg(DataFileExporter::SUPPORTED_FORMATS);
-  DataFileExporter::WriteList writeList;
-  DataFileExporter::ReturnCode ret;
-
   if (m_activeSequence == nullptr)
     return;
   if (m_activeSequence->selectedRun() == nullptr)
     return;
 
-  for (uint idx = 0; idx < m_activeSequence->selectedRun()->signalCount(); idx++)
-    dlg.addAvailableSignal(m_activeSequence->selectedRun()->signalAt(idx)->descriptiveName());
-
-  do {
-    int dret = dlg.exec();
-    if (dret == QDialog::Rejected)
-      return;
-    else if (dret == QDialog::Accepted && dlg.selectedSignalsCount() < 1) {
-      QMessageBox::information(nullptr, "Data export error", "No signals selected");
-      ret = DataFileExporter::ReturnCode::E_TRYAGAIN;
-    } else if (dret == QDialog::Accepted && dlg.selectedSignalsCount() >= 1) {
-      /* Generate data to export */
-      for (int idx = 0; idx < dlg.signalsCount(); idx++) {
-        QVariantList header;
-        std::vector<QVariantList> lines;
-        std::pair<QVariantList, std::vector<QVariantList>> p;
-        std::shared_ptr<const Signal> sig;
-        std::string dname;
-        if (!dlg.isSignalSelected(idx))
-          continue;
-
-        sig = m_activeSequence->selectedRun()->signalAt(idx);
-        dname = m_activeSequence->selectedRun()->signalAt(idx)->descriptiveName().toStdString();
-
-        /* Create header */
-        header << QString("time [" + sig->xunitToString() + "]") << QString("value [" + 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;
-      }
-      ret = exporter.exportData(writeList, dlg.destination(), dlg.format());
-    }
-   } while (ret == DataFileExporter::ReturnCode::E_TRYAGAIN);
+  std::function<void (DataFileExporter::WriteList&, std::shared_ptr<const QObject>)> f = std::bind(&DataManager::generateRawDataWriteList, this, std::placeholders::_1, std::placeholders::_2);
+  processDataExport(f);
 }
 
 void DataManager::onLoadSequence(const QString& dir)
@@ -359,7 +392,7 @@ void DataManager::onLoadSequence(const QString& dir)
     if (srdata == nullptr)
       continue;
 
-    nSeq->add(subPath, srdata);
+    nSeq->add(subPath.toStdString(), srdata);
   }
   Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, "Single runs loaded, count: " + QString::number(nSeq->count()));
   if (nSeq->count() < 1) {
@@ -382,15 +415,6 @@ void DataManager::onLoadSequence(const QString& dir)
     }
   }
 
-  /* Create signal controllers */
-  for (const SingleRunPair& srp : *nSeq) {
-    std::shared_ptr<SingleRunData> srdata = srp.second;
-    for (size_t idx = 0; idx < srdata->signalCount(); idx++) {
-      std::shared_ptr<SignalController> controller(new SignalController(srdata->signalAt(idx)));
-      nSeq->addController(signalControllerKey(srdata->dirName(), srdata->signalAt(idx)->uidString()), controller);
-    }
-  }
-
   m_sequences.push_back(NameSequencePair(uniqueName, nSeq));
   m_seqSelModel.seqenceAdded();
 
@@ -409,7 +433,7 @@ void DataManager::onLoadSingleRun(const QString& str)
 
   /* Generate unique name for the single run data */
   uniqueName = dir.dirName();
-  while (srseq->find(uniqueName) != srseq->end()) {
+  while (srseq->at(uniqueName.toStdString()) != nullptr) {
     Logger::log(Logger::Level::INFO, ME_SENDER_STR, "[" + uniqueName + "]: Already there, adjusting.");
     if (nameSuffix == 1) {
       uniqueName += QString("_1");
@@ -419,14 +443,10 @@ void DataManager::onLoadSingleRun(const QString& str)
     nameSuffix++;
   }
 
-  /* Create signal controllers */
-  for (size_t idx = 0; idx < srdata->signalCount(); idx++) {
-    std::shared_ptr<SignalController> controller(new SignalController(srdata->signalAt(idx)));
-    srseq->addController(signalControllerKey(srdata->dirName(), srdata->signalAt(idx)->uidString()), controller);
-  }
+  //TODO: Rewrite to std::string completely
 
-  srseq->add(uniqueName, srdata);
-  srseq->setSelectedRunKey(uniqueName);
+  srseq->add(uniqueName.toStdString(), srdata);
+  srseq->setSelectedRun(uniqueName.toStdString());
   emit setActiveSequenceIndex(0);
 }
 
@@ -457,8 +477,8 @@ void DataManager::onSequenceSelected(const QString& key)
   }
 
   m_prevSequenceKey = key;
-  m_singleSelModel.setSingleRuns(m_activeSequence->allRuns());
-  emit setActiveSingleRunIndex(m_activeSequence->selectedRunIdx());
+  m_singleSelModel.setSingleRuns(m_activeSequence->allRunKeys());
+  emit setActiveSingleRunKey(m_activeSequence->selectedRunKey());
 }
 
 void DataManager::onSingleRunSelected(const QString& key)
@@ -466,24 +486,15 @@ void DataManager::onSingleRunSelected(const QString& key)
   if (m_activeSequence == nullptr)
     return;
 
-  std::vector<SingleRunPair>::iterator it = m_activeSequence->find(key);
-  if (it == m_activeSequence->end()) {
+  if (!m_activeSequence->setSelectedRun(key.toStdString())) {
     Logger::log(Logger::Level::ERROR, ME_SENDER_STR, "[" + key + "]: No such single run.");
     return;
   }
 
-  m_activeSequence->setSelectedRunKey(key);
-
-  std::shared_ptr<SingleRunData> srdata = it->second;
+  std::shared_ptr<SingleRunData> srdata = m_activeSequence->selectedRun();
   emit cleanDashboard();
-  for (size_t idx = 0; idx < srdata->signalCount(); idx++) {
-    std::shared_ptr<SignalController> controller = m_activeSequence->controller(signalControllerKey(srdata->dirName(), srdata->signalAt(idx)->uidString()));
-    if (controller == nullptr) {
-      Logger::log(Logger::Level::ERROR, ME_SENDER_STR, "[" + srdata->dirName() + srdata->signalAt(idx)->uidString() + "]: No such controller.");
-      continue;
-    }
-    showOneSignal(controller);
-  }
+  for (const std::string& s : srdata->allKeys())
+    showOneSignal(srdata->controllerAt(s));
 
   emit setSingleRunInfo(srdata->methodName(), srdata->operatorName(), srdata->sampleInfo(), srdata->date().toString() +" "+ srdata->time().toString());
   Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, "Single run changed.");
index def182ccc8a719049554be4259c21884926ab9ee..fa0baff34c35b1bf6bb540e390e3bd488b386f1b 100644 (file)
@@ -23,6 +23,7 @@
 #ifndef DATAMANAGER_H
 #define DATAMANAGER_H
 
+#include "datafileexporter.h"
 #include "datafilesloader.h"
 #include "gui/signalview.h"
 #include "sequence.h"
@@ -46,9 +47,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);
   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);
   Signal::Resource resourceFromFiletype(AGRE_Filetype filetype);
   std::string signalControllerKey(const QString& main, const QString& resource) ;
   void showOneSignal(std::shared_ptr<SignalController> ctrl);
@@ -77,7 +81,7 @@ signals:
   void addToDashboard(SignalView* sw);
   void cleanDashboard();
   void setActiveSequenceIndex(const int idx);
-  void setActiveSingleRunIndex(const int idx);
+  void setActiveSingleRunKey(const std::string& key);
   void setSingleRunInfo(const QString& method, const QString& operatorname, const QString& sample, const QString& datetime);
 
 public slots:
index 49bf37161ede548524c953f6915aca352cb5c091..53210bba39b6cf7d2ac70b5273329b95ef8ab0b0 100644 (file)
@@ -120,8 +120,10 @@ void MainWindow::onSetActiveSequenceIndex(const int idx)
     ui->qcbox_sequence->setCurrentIndex(idx);
 }
 
-void MainWindow::onSetActiveSingleRunIndex(const int idx)
+void MainWindow::onSetActiveSingleRunKey(const std::string& key)
 {
+  const SingleRunsSelectorModel* model = static_cast<const SingleRunsSelectorModel*>(ui->qcbox_singleRun->model());
+  int idx = model->idxFromKey(key);
   ui->qcbox_singleRun->setCurrentIndex(idx);
 }
 
index a83bb79ba2b5c310aa23e3251f6933d3591910b1..e3c42a471e19a1f34586f6f465071efcba3e16dd 100644 (file)
@@ -64,7 +64,7 @@ public slots:
   void onAddToDashboard(SignalView* sw);
   void onCleanDashboard();
   void onSetActiveSequenceIndex(const int idx);
-  void onSetActiveSingleRunIndex(const int idx);
+  void onSetActiveSingleRunKey(const std::string& key);
   void onSetSingleRunInfo(const QString& method, const QString& operatorname, const QString& sample, const QString& datetime);
 
 private slots:
index 847418d1bb7237602edabd2db5c58e1090224d04..446ddf59690eda2a48a3f5f7149b0261fd306723 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -67,7 +67,7 @@ int main(int argc, char *argv[])
   QObject::connect(dMgr.get(), SIGNAL(addToDashboard(SignalView*)), mWin.get(), SLOT(onAddToDashboard(SignalView*)));
   QObject::connect(dMgr.get(), SIGNAL(cleanDashboard()), mWin.get(), SLOT(onCleanDashboard()));
   QObject::connect(dMgr.get(), SIGNAL(setActiveSequenceIndex(int)), mWin.get(), SLOT(onSetActiveSequenceIndex(int)));
-  QObject::connect(dMgr.get(), SIGNAL(setActiveSingleRunIndex(int)), mWin.get(), SLOT(onSetActiveSingleRunIndex(int)));
+  QObject::connect(dMgr.get(), SIGNAL(setActiveSingleRunKey(std::string)), mWin.get(), SLOT(onSetActiveSingleRunKey(std::string)));
   QObject::connect(dMgr.get(), SIGNAL(setSingleRunInfo(QString,QString,QString,QString)), mWin.get(), SLOT(onSetSingleRunInfo(QString,QString,QString,QString)));
   QObject::connect(mWin.get(), SIGNAL(exportPeaks()), dMgr.get(), SLOT(onExportPeaks()));
   QObject::connect(mWin.get(), SIGNAL(exportRawData()), dMgr.get(), SLOT(onExportRawData()));
index 2c4e582920c554ae871f33900c4d5173c47ba7ca..a5fc15f4f8f1815832160b9ec164e96b4719474a 100644 (file)
@@ -27,87 +27,66 @@ Sequence::Sequence(QObject* parent) :
 {
 }
 
-Sequence::Sequence(std::vector<SingleRunPair>& singleRuns, QObject* parent) :
+Sequence::Sequence(std::unordered_map<std::string, std::shared_ptr<SingleRunData>>& singleRuns, QObject* parent) :
   QObject(parent),
-  m_selectedRunKey(""),
-  m_selectedRunIdx(-1),
-  m_singleRuns(singleRuns)
+  m_selectedRunKey("")
 {
+  m_singleRuns = singleRuns;
 }
 
-int Sequence::add(QString name, std::shared_ptr<SingleRunData> value)
+int Sequence::add(const std::string name, std::shared_ptr<SingleRunData> value)
 {
-  m_singleRuns.push_back(SingleRunPair(name, value));
+  m_singleRuns[name] = value;
   m_selectedRunKey = name;
   return m_singleRuns.size()-1;
 }
 
-void Sequence::addController(const std::string& uid, std::shared_ptr<SignalController> controller)
+std::shared_ptr<SingleRunData> Sequence::at(const std::string& key)
 {
-  m_signalCtrls[uid] = controller;
-}
-
-SingleRunPair Sequence::at(const size_t idx)
-{
-  return m_singleRuns.at(idx);
-}
-
-std::shared_ptr<SignalController> Sequence::controller(const std::string& uid)
-{
-  std::unordered_map<std::string, std::shared_ptr<SignalController>>::iterator it;
-  it = m_signalCtrls.find(uid);
-  if (it == m_signalCtrls.end())
+  std::unordered_map<std::string, std::shared_ptr<SingleRunData>>::iterator it = m_singleRuns.find(key);
+  if (it == m_singleRuns.end())
     return nullptr;
   else
     return it->second;
-}
 
-std::vector<SingleRunPair>::iterator Sequence::find(const QString& key)
-{
-  std::vector<SingleRunPair>::iterator it = m_singleRuns.begin();
-  while (it != m_singleRuns.end()) {
-    if (it->first == key)
-      return it;
-    it++;
-  }
-  return m_singleRuns.end();
+  return m_singleRuns.at(key);
 }
 
-void Sequence::remove(const QString& key)
+std::vector<std::string> Sequence::allRunKeys() const
 {
-  std::vector<SingleRunPair>::iterator it = m_singleRuns.begin();
-  while (it++ != m_singleRuns.end()) {
-    if (it->first == key)
-      m_singleRuns.erase(it);
-  }
+  std::vector<std::string> keys;
+  keys.reserve(m_singleRuns.size());
+
+  for (const std::pair<std::string, std::shared_ptr<SingleRunData>>& p : m_singleRuns)
+    keys.push_back(p.first);
+
+  return keys;
 }
 
-void Sequence::removeAt(const size_t idx)
+void Sequence::remove(const std::string& key)
 {
-  if (m_singleRuns.size() > idx)
-    m_singleRuns.erase(m_singleRuns.begin()+idx);
+  m_singleRuns.erase(m_singleRuns.find(key));
 }
 
 std::shared_ptr<SingleRunData> Sequence::selectedRun()
 {
-  if (m_selectedRunKey.compare("") == 0 || m_selectedRunIdx == -1)
+  if (m_selectedRunKey.compare("") == 0)
     return nullptr;
 
-  return m_singleRuns.at(m_selectedRunIdx).second;
+  return m_singleRuns.at(m_selectedRunKey);
 }
 
-int Sequence::selectedRunIdx() const
+bool Sequence::setSelectedRun(const std::string& key)
 {
-  int idx = 0;
-  for (const SingleRunPair& p : m_singleRuns) {
-    if (p.first.compare(m_selectedRunKey) == 0)
-      return idx;
-    idx++;
-  }
-  return -1;
+  std::unordered_map<std::string, std::shared_ptr<SingleRunData>>::iterator sr = m_singleRuns.find(key);
+  if (sr == m_singleRuns.end())
+    return false;
+
+  m_selectedRunKey = key;
+  return true;
 }
 
-int Sequence::singleRunToIdx(const QString& key) const
+/*int Sequence::singleRunToIdx(const QString& key) const
 {
   int idx = 0;
   for (const SingleRunPair& p : m_singleRuns) {
@@ -116,4 +95,4 @@ int Sequence::singleRunToIdx(const QString& key) const
     idx++;
   }
   return -1;
-}
+}*/
index 1f3f85fc988d4a0a73071bb07f97ba815b6a377a..abd710bf08094a6c15c8bc301b89bba8a32b023f 100644 (file)
 #include <vector>
 #include <QtCore/QObject>
 
-typedef std::pair<QString, std::shared_ptr<SingleRunData>> SingleRunPair;
-
 class Sequence : public QObject
 {
   Q_OBJECT
 public:
   explicit Sequence(QObject* parent = nullptr);
-  explicit Sequence(std::vector<SingleRunPair>& singleRuns, QObject* parent = nullptr);
-  int add(QString name, std::shared_ptr<SingleRunData> value);
-  void addController(const std::string& uid, std::shared_ptr<SignalController> controller);
-  const std::vector<SingleRunPair>* allRuns() const { return &m_singleRuns; }
-  SingleRunPair at(size_t idx);
-  std::vector<SingleRunPair>::iterator begin() { return m_singleRuns.begin(); }
-  std::vector<SingleRunPair>::const_iterator cbegin() const { return m_singleRuns.cbegin(); }
-  std::vector<SingleRunPair>::const_iterator cend() const { return m_singleRuns.cend(); }
+  explicit Sequence(std::unordered_map<std::string, std::shared_ptr<SingleRunData>>& singleRuns, QObject* parent = nullptr);
+  int add(const std::string name, std::shared_ptr<SingleRunData> value);
+  std::vector<std::string> allRunKeys() const;
+  std::shared_ptr<SingleRunData> at(const std::string& key);
+  std::unordered_map<std::string, std::shared_ptr<SingleRunData>>::iterator begin() { return m_singleRuns.begin(); }
+  std::unordered_map<std::string, std::shared_ptr<SingleRunData>>::const_iterator cbegin() const { return m_singleRuns.cbegin(); }
+  std::unordered_map<std::string, std::shared_ptr<SingleRunData>>::const_iterator cend() const { return m_singleRuns.cend(); }
   std::shared_ptr<SignalController> controller(const std::string& uid);
   size_t count() const { return m_singleRuns.size(); }
-  std::vector<SingleRunPair>::iterator end() { return m_singleRuns.end(); }
-  std::vector<SingleRunPair>::iterator find(const QString& key);
-  void remove(const QString& key);
-  void removeAt(const size_t idx);
-  const QString& selectedRunKey() const { return m_selectedRunKey; }
+  std::unordered_map<std::string, std::shared_ptr<SingleRunData>>::iterator end() { return m_singleRuns.end(); }
+  void remove(const std::string& key);
+  std::string selectedRunKey() const { return m_selectedRunKey; }
   std::shared_ptr<SingleRunData> selectedRun();
-  int selectedRunIdx() const;
-  int singleRunToIdx(const QString& key) const;
-  void setSelectedRunKey(const QString& key) { m_selectedRunKey = key; m_selectedRunIdx = singleRunToIdx(key); }
+  //int selectedRunIdx() const;
+  //int singleRunToIdx(const QString& key) const;
+  bool setSelectedRun(const std::string& key);
 
 private:
-  QString m_selectedRunKey;
-  int m_selectedRunIdx;
-  std::unordered_map<std::string, std::shared_ptr<SignalController>> m_signalCtrls;
-  std::vector<SingleRunPair> m_singleRuns;
+  std::string m_selectedRunKey;
+  std::unordered_map<std::string, std::shared_ptr<SingleRunData>> m_singleRuns;
 
 signals:
 
index e8e4d0c6a669e7ebd90b219fb9758459e2e7203e..3ef5e0fe239225311ab8890217057c9c3f80732b 100644 (file)
 #include "signal.h"
 #include <cfloat>
 
-const QString Signal::RES_CCD("CCD");
-const QString Signal::RES_CURRENT("Current");
-const QString Signal::RES_DAD("Absorbance");
-const QString Signal::RES_POWER("Power");
-const QString Signal::RES_VOLTAGE("Voltage");
-const QString Signal::KILOVOTLS_SI("KV");
-const QString Signal::MICROAMPERES_SI("\u03BCA");
-const QString Signal::MILLIAU_SI("mAU");
-const QString Signal::MILLIVOLTS_SI("mV");
-const QString Signal::WATTS_SI("W");
+const std::string Signal::RES_CCD("CCD");
+const std::string Signal::RES_CURRENT("Current");
+const std::string Signal::RES_DAD("Absorbance");
+const std::string Signal::RES_POWER("Power");
+const std::string Signal::RES_VOLTAGE("Voltage");
+const std::string Signal::KILOVOTLS_SI("KV");
+const std::string Signal::MICROAMPERES_SI("\u03BCA");
+const std::string Signal::MILLIAU_SI("mAU");
+const std::string Signal::MILLIVOLTS_SI("mV");
+const std::string Signal::WATTS_SI("W");
 
 Signal::Signal(const Equipment equipment, const Resource resource, const double samplingRate, const YUnit yunit, uint16_t wavelengthAbs, uint16_t wavelengthRef,
                const std::vector<TimeValuePair>& values, QObject* parent) :
@@ -54,11 +54,11 @@ Signal::Signal(const Equipment equipment, const Resource resource, const double
   }
 }
 
-QString Signal::descriptiveName() const
+std::string Signal::descriptiveName() const
 {
-  QString name = resourceToString();
+  std::string name = resourceToString();
   if (m_resource == Resource::CE_DAD)
-    name += "_SIG" + QString::number(m_wavelengthAbs) + "_REF" + QString::number(m_wavelengthRef);
+    name += "_SIG" + std::to_string(m_wavelengthAbs) + "_REF" + std::to_string(m_wavelengthRef);
   return name;
 }
 
@@ -75,7 +75,7 @@ Signal::TimeValuePair Signal::pairAt(const size_t idx) const
     return m_values.at(idx);
 }
 
-QString Signal::resourceToString() const {
+std::string Signal::resourceToString() const {
   switch (m_resource) {
     case Resource::CE_CCD:
       return RES_CCD;
@@ -100,10 +100,10 @@ double Signal::timeAt(const size_t idx) const
     return m_values.at(idx).first;
 }
 
-QString Signal::uidString() const
+/*QString Signal::uidString() const
 {
   return resourceToString() + QString::number(m_wavelengthAbs) + QString::number(m_wavelengthRef);
-}
+}*/
 
 double Signal::valueAt(const size_t idx) const
 {
@@ -113,7 +113,7 @@ double Signal::valueAt(const size_t idx) const
     return m_values.at(idx).second;
 }
 
-QString Signal::xunitToString() const
+std::string Signal::xunitToString() const
 {
   switch (m_xunit) {
     case XUnit::MINUTE:
@@ -123,7 +123,7 @@ QString Signal::xunitToString() const
   }
 }
 
-QString Signal::yunitToString() const
+std::string Signal::yunitToString() const
 {
   switch (m_yunit) {
     case YUnit::KILOVOLTS:
index 3423094b5be0770d69776c610929d3a27868a194..09a8d4fb060e53869e9fd7e1e3c88d319087d62b 100644 (file)
--- a/signal.h
+++ b/signal.h
@@ -55,17 +55,17 @@ public:
 
   explicit Signal(const Equipment equipment, const Resource resource, const double samplingRate, const YUnit yunit, const uint16_t wavelengthAbs,
                   const uint16_t wavelengthRef, const std::vector<TimeValuePair>& values, QObject* parent = nullptr);
-  QString descriptiveName() const;
+  std::string descriptiveName() const;
   Equipment equipment() const { return m_equipment; }
   std::vector<TimeValuePair>::const_iterator iteratorFrom(const size_t idx) const;
   double maximum() const { return m_max; }
   double minimum() const { return m_min; }
   TimeValuePair pairAt(const size_t idx) const;
   Resource resource() const { return m_resource; }
-  QString resourceToString() const;
+  std::string resourceToString() const;
   double timeAt(const size_t idx) const;
   double samplingRate() const { return m_samplingRate; }
-  QString uidString() const;
+  //QString uidString() const;
   double valueAt(const size_t idx) const;
   const std::vector<TimeValuePair>& values() const { return m_values; }
   std::vector<TimeValuePair>::const_iterator valuesBegin() const { return m_values.begin(); }
@@ -74,9 +74,9 @@ public:
   uint16_t wavelengthAbsorbed() const { return m_wavelengthAbs; }
   uint16_t wavelengthReference() const { return m_wavelengthRef; }
   XUnit xunit() const { return m_xunit; }
-  QString xunitToString() const;
+  std::string xunitToString() const;
   YUnit yunit() const { return m_yunit; }
-  QString yunitToString() const;
+  std::string yunitToString() const;
 
 private:
   const Equipment m_equipment;
@@ -90,17 +90,17 @@ private:
   const XUnit m_xunit;
   const YUnit m_yunit;
 
-  static const QString RES_ABSORBANCE;
-  static const QString RES_CCD;
-  static const QString RES_CURRENT;
-  static const QString RES_DAD;
-  static const QString RES_POWER;
-  static const QString RES_VOLTAGE;
-  static const QString KILOVOTLS_SI;
-  static const QString MICROAMPERES_SI;
-  static const QString MILLIAU_SI;
-  static const QString MILLIVOLTS_SI;
-  static const QString WATTS_SI;
+  static const std::string RES_ABSORBANCE;
+  static const std::string RES_CCD;
+  static const std::string RES_CURRENT;
+  static const std::string RES_DAD;
+  static const std::string RES_POWER;
+  static const std::string RES_VOLTAGE;
+  static const std::string KILOVOTLS_SI;
+  static const std::string MICROAMPERES_SI;
+  static const std::string MILLIAU_SI;
+  static const std::string MILLIVOLTS_SI;
+  static const std::string WATTS_SI;
 
 signals:
 
index 760a64bcac567df6886c537db54e7126caa35a3f..46863e3d1ae11daf446d99c324e232300f1666dd 100644 (file)
@@ -57,9 +57,9 @@ QVariant SignalDataTableModel::headerData(int section, Qt::Orientation orientati
   if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
     switch (section) {
       case 0:
-        return QString("Time [") + m_signal->xunitToString() + QString("]");
+        return QString("Time [") + QString::fromStdString(m_signal->xunitToString()) + QString("]");
       case 1:
-        return QString("Value [") + m_signal->yunitToString() + QString("]");
+        return QString("Value [") + QString::fromStdString(m_signal->yunitToString()) + QString("]");
       default:
       return QVariant();
     }
index fd5ef764ac44b22340f4361147cecd44811342e9..3b762c266c959d397c93d89229b6bdaf9bc8c641 100644 (file)
 #include "singlerundata.h"
 
 SingleRunData::SingleRunData(const QString& methodName, const QString& operatorName, const QString& sampleInfo, const QDate date, const QTime time,
-                             std::vector<std::shared_ptr<Signal>>& sigs, const QString& dirname, QObject *parent) :
+                             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) :
   QObject(parent),
   m_date(date),
   m_dirName(dirname),
   m_methodName(methodName),
   m_operatorName(operatorName),
   m_sampleInfo(sampleInfo),
+  m_ctrls(ctrls),
   m_signals(sigs),
   m_time(time)
 {
 }
+
+std::vector<std::string> SingleRunData::allKeys() const
+{
+  std::vector<std::string> keys;
+  keys.reserve(m_signals.size());
+
+  for (std::pair<std::string, std::shared_ptr<Signal>> p : m_signals)
+    keys.push_back(p.first);
+
+  return keys;
+}
index 2fdd88c41bf89f7041a94fd91ecc35d9c9fc834f..27bbeaeb6aafc60aa2ad9b93a5bbc5adb6b394c0 100644 (file)
@@ -23,8 +23,9 @@
 #ifndef SINGLERUNDATA_H
 #define SINGLERUNDATA_H
 
-#include "signal.h"
+#include "signalcontroller.h"
 #include <memory>
+#include <unordered_map>
 #include <QtCore/QDate>
 #include <QtCore/QObject>
 #include <QtCore/QTime>
@@ -34,13 +35,17 @@ class SingleRunData : public QObject
   Q_OBJECT
 public:
   explicit SingleRunData(const QString& methodName, const QString& operatorName, const QString& sampleInfo, const QDate date, const QTime time,
-                         std::vector<std::shared_ptr<Signal>>& sigs, const QString& dirname, QObject *parent = 0);
+                         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); }
   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(size_t idx) { return m_signals.at(idx); }
+  std::shared_ptr<Signal> signalAt(const std::string& key) { return m_signals.at(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; }
 
@@ -50,7 +55,8 @@ private:
   const QString m_methodName;
   const QString m_operatorName;
   const QString m_sampleInfo;
-  std::vector<std::shared_ptr<Signal>> m_signals;
+  std::unordered_map<std::string, std::shared_ptr<SignalController>> m_ctrls;
+  std::unordered_map<std::string, std::shared_ptr<Signal>> m_signals;
   const QTime m_time;
 
 signals:
index 4ee0293baff3c7d0ac86d669f67414d10ea9166e..bf11ec29b972800892d720cecee7cc37b656119e 100644 (file)
@@ -25,8 +25,7 @@
 #include <QDebug>
 
 SingleRunsSelectorModel::SingleRunsSelectorModel(QObject *parent) :
-  QAbstractListModel(parent),
-  m_singleRuns(nullptr)
+  QAbstractListModel(parent)
 {
 }
 
@@ -35,31 +34,45 @@ QVariant SingleRunsSelectorModel::data(const QModelIndex& index, int role) const
   int runIdx = 0;
   if (role != Qt::DisplayRole)
     return QVariant();
-  if (m_singleRuns == nullptr)
+  if (m_singleRunKeys.size() == 0)
     return QVariant();
 
-  std::vector<SingleRunPair>::const_iterator cit = m_singleRuns->cbegin();
-  while (cit != m_singleRuns->cend()) {
+  /*std::vector<std::string>::const_iterator cit = m_singleRunKeys->cbegin();
+  while (cit != m_singleRunKeys->cend()) {
     if (runIdx == index.row())
       return cit->first;
     runIdx++; cit++;
+  }*/
+  for (const std::string& s : m_singleRunKeys) {
+    if (runIdx == index.row())
+      return QString::fromStdString(s);
+    runIdx++;
   }
   return QVariant();
 }
 
+int SingleRunsSelectorModel::idxFromKey(const std::string& key) const
+{
+  int idx = 0;
+  for (const std::string& s : m_singleRunKeys) {
+    if (s.compare(key) == 0) return idx;
+    else idx++;
+  }
+
+  if (idx == m_singleRunKeys.size())
+    return -1;
+}
+
 int SingleRunsSelectorModel::rowCount(const QModelIndex& parent) const
 {
   Q_UNUSED(parent);
 
-  if (m_singleRuns == nullptr)
-    return 0;
-  else
-    return m_singleRuns->size();
+  return m_singleRunKeys.size();
 }
 
-void SingleRunsSelectorModel::setSingleRuns(const std::vector<SingleRunPair>* singleRuns)
+void SingleRunsSelectorModel::setSingleRuns(std::vector<std::string> singleRunKeys)
 {
   beginResetModel();
-  m_singleRuns = singleRuns;
+  m_singleRunKeys = singleRunKeys;
   endResetModel();
 }
index a343ab3558f7a0cb6b8eafda6f89b04ebb454f96..91ad99e0e38c3570eaeb8594af0c17be2c630cb3 100644 (file)
@@ -32,11 +32,12 @@ class SingleRunsSelectorModel : public QAbstractListModel
 public:
   explicit SingleRunsSelectorModel(QObject* parent = nullptr);
   QVariant data(const QModelIndex& index, int role) const;
+  int idxFromKey(const std::string& key) const;
   int rowCount(const QModelIndex& parent) const;
-  void setSingleRuns(const std::vector<SingleRunPair>* singleRuns);
+  void setSingleRuns(std::vector<std::string> singleRunKeys);
 
 private:
-  const std::vector<SingleRunPair>* m_singleRuns;
+  std::vector<std::string> m_singleRunKeys;
 
 signals: