Permalink
Browse files

Use SI prefixes in labels

  • Loading branch information...
1 parent e8c1f1f commit 0565d83d27a0329d054c859a017d189b91d4a4ac @miek committed Aug 11, 2016
Showing with 10 additions and 4 deletions.
  1. +1 −0 CMakeLists.txt
  2. +5 −4 spectrogramcontrols.cpp
  3. +4 −0 util.h
View
@@ -46,6 +46,7 @@ list(APPEND inspectrum_sources
traceplot.cpp
tuner.cpp
tunertransform.cpp
+ util.cpp
)
INCLUDE(FindPkgConfig)
@@ -23,6 +23,7 @@
#include <QFileDialog>
#include <QLabel>
#include <cmath>
+#include "util.h"
SpectrogramControls::SpectrogramControls(const QString & title, QWidget * parent)
: QDockWidget::QDockWidget(title, parent)
@@ -139,12 +140,12 @@ void SpectrogramControls::fileOpenButtonClicked()
void SpectrogramControls::timeSelectionChanged(float time)
{
if (cursorsCheckBox->checkState() == Qt::Checked) {
- periodLabel->setText(QString::number(time) + "s");
- rateLabel->setText(QString::number(1 / time) + "Hz");
+ periodLabel->setText(QString::fromStdString(formatSIValue(time)) + "s");
+ rateLabel->setText(QString::fromStdString(formatSIValue(1 / time)) + "Hz");
int symbols = cursorSymbolsSpinBox->value();
- symbolPeriodLabel->setText(QString::number(time / symbols) + "s");
- symbolRateLabel->setText(QString::number(symbols / time) + "Hz");
+ symbolPeriodLabel->setText(QString::fromStdString(formatSIValue(time / symbols)) + "s");
+ symbolRateLabel->setText(QString::fromStdString(formatSIValue(symbols / time)) + "Hz");
}
}
View
@@ -20,7 +20,9 @@
#pragma once
#include <algorithm>
+#include <map>
#include <math.h>
+#include <sstream>
static const double Tau = M_PI * 2.0;
@@ -93,3 +95,5 @@ struct range_t {
return !contains(value);
}
};
+
+std::string formatSIValue(float value);

0 comments on commit 0565d83

Please sign in to comment.