along with Signals.
#include "datamanager.h"
#include "logger.h"
-#include "datafileexporter.h"
#include "gui/exportrawdatadialog.h"
#include <QtWidgets/QMessageBox>
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) {
}
}
+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) {
{
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);
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;
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."));
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 */
}
}
- 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;
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)));
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)
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) {
}
}
- /* 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();
/* 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");
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);
}
}
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)
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.");
#ifndef DATAMANAGER_H
#define DATAMANAGER_H
+#include "datafileexporter.h"
#include "datafilesloader.h"
#include "gui/signalview.h"
#include "sequence.h"
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);
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:
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);
}
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:
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()));
{
}
-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) {
idx++;
}
return -1;
-}
+}*/
#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:
#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) :
}
}
-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;
}
return m_values.at(idx);
}
-QString Signal::resourceToString() const {
+std::string Signal::resourceToString() const {
switch (m_resource) {
case Resource::CE_CCD:
return RES_CCD;
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
{
return m_values.at(idx).second;
}
-QString Signal::xunitToString() const
+std::string Signal::xunitToString() const
{
switch (m_xunit) {
case XUnit::MINUTE:
}
}
-QString Signal::yunitToString() const
+std::string Signal::yunitToString() const
{
switch (m_yunit) {
case YUnit::KILOVOLTS:
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(); }
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;
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:
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();
}
#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;
+}
#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>
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; }
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:
#include <QDebug>
SingleRunsSelectorModel::SingleRunsSelectorModel(QObject *parent) :
- QAbstractListModel(parent),
- m_singleRuns(nullptr)
+ QAbstractListModel(parent)
{
}
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();
}
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: