Skip to content

Commit

Permalink
Use SI prefixes in labels
Browse files Browse the repository at this point in the history
  • Loading branch information
miek committed Aug 11, 2016
1 parent e8c1f1f commit 0565d83
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -46,6 +46,7 @@ list(APPEND inspectrum_sources
traceplot.cpp
tuner.cpp
tunertransform.cpp
util.cpp
)

INCLUDE(FindPkgConfig)
Expand Down
9 changes: 5 additions & 4 deletions spectrogramcontrols.cpp
Expand Up @@ -23,6 +23,7 @@
#include <QFileDialog>
#include <QLabel>
#include <cmath>
#include "util.h"

SpectrogramControls::SpectrogramControls(const QString & title, QWidget * parent)
: QDockWidget::QDockWidget(title, parent)
Expand Down Expand Up @@ -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");
}
}

Expand Down
4 changes: 4 additions & 0 deletions util.h
Expand Up @@ -20,7 +20,9 @@

#pragma once
#include <algorithm>
#include <map>
#include <math.h>
#include <sstream>

static const double Tau = M_PI * 2.0;

Expand Down Expand Up @@ -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.