From 411a57a153d94a00c6e63f73b21f808c36a2340f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Fri, 17 Apr 2015 20:27:17 +0200 Subject: [PATCH] - Generate human readable signal name from the signal - Add an option to return descriptive name as std::string --- datamanager.cpp | 8 ++++---- helpers.cpp | 9 --------- helpers.h | 1 - signal.cpp | 20 +++++++++++++++++--- signal.h | 2 ++ 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/datamanager.cpp b/datamanager.cpp index 2f9f69d..8757f13 100644 --- a/datamanager.cpp +++ b/datamanager.cpp @@ -196,8 +196,8 @@ void DataManager::processDataExport(GeneratorFunc genfunc) m_exportRawDataDialog.removeAllSignals(); 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(Helpers::signalTagToHumanReadable(s), s); + for (const auto& sm : sr->allSignals()) + m_exportRawDataDialog.addAvailableSignal(sm.second->readableName(), sm.second->rawDescriptiveName()); do { int dret = m_exportRawDataDialog.exec(); @@ -390,8 +390,8 @@ std::shared_ptr DataManager::loadSingleRun(QDir& dir) _c = std::shared_ptr(new SignalController(_s)); - sigs[_s->descriptiveName().toStdString()] = _s; - ctrls[_s->descriptiveName().toStdString()] = _c; + sigs[_s->rawDescriptiveName()] = _s; + ctrls[_s->rawDescriptiveName()] = _c; hpcs_free_mdata(md); } diff --git a/helpers.cpp b/helpers.cpp index 8b915ea..5a39c5d 100644 --- a/helpers.cpp +++ b/helpers.cpp @@ -60,12 +60,3 @@ QString Helpers::getFileNameSuffix(const QString& name) return name.mid(dotIdx+1).toLower(); } - -QString Helpers::signalTagToHumanReadable(const std::string& tag) -{ - QString hr = QString::fromStdString(tag); - - hr.replace("_", " "); - - return hr; -} diff --git a/helpers.h b/helpers.h index 21da5ad..20d978a 100644 --- a/helpers.h +++ b/helpers.h @@ -36,7 +36,6 @@ public: 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 static T average(T* vals, size_t len) { diff --git a/signal.cpp b/signal.cpp index 6d8aadf..0b64ef4 100644 --- a/signal.cpp +++ b/signal.cpp @@ -72,10 +72,15 @@ Signal::Signal(const Equipment equipment, const Resource resource, const double QString Signal::descriptiveName() const { - QString name = resourceAsString(); + return QString(rawDescriptiveName().c_str()); +} + +std::string Signal::rawDescriptiveName() const +{ + std::string name = resourceAsString().toStdString(); if (m_resource == Resource::CE_DAD) - name += "_SIG" + QString::number(m_wavelengthMeasured) + "-" + QString::number(m_wavelengthMeasuredInterval) + "_REF" + - QString::number(m_wavelengthReference) + "-" + QString::number(m_wavelengthReferenceInterval); + name += "_SIG" + std::to_string(m_wavelengthMeasured) + "-" + std::to_string(m_wavelengthMeasuredInterval) + "_REF" + + std::to_string(m_wavelengthReference) + "-" + std::to_string(m_wavelengthReferenceInterval); return name; } @@ -92,6 +97,15 @@ Signal::TimeValuePair Signal::pairAt(const size_t idx) const return m_values.at(idx); } +QString Signal::readableName() const +{ + QString name = resourceAsString(); + if (m_resource == Resource::CE_DAD) { + return name + QString(" (Measured: %1/%2 nm, Reference %3/%4 nm)").arg(m_wavelengthMeasured).arg(m_wavelengthMeasuredInterval).arg(m_wavelengthReference).arg(m_wavelengthReferenceInterval); + } + return name; +} + QString Signal::resourceAsString() const { switch (m_resource) { case Resource::CE_CCD: diff --git a/signal.h b/signal.h index 9c285c9..2e13de9 100644 --- a/signal.h +++ b/signal.h @@ -73,6 +73,8 @@ public: double maximum() const { return m_max; } double minimum() const { return m_min; } TimeValuePair pairAt(const size_t idx) const; + std::string rawDescriptiveName() const; + QString readableName() const; Resource resource() const { return m_resource; } QString resourceAsString() const; double timeAt(const size_t idx) const; -- 2.43.5