mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-07-19 01:05:35 -04:00
GLSpectrum: factorized displayScaledF and displayScaledM
This commit is contained in:
parent
f540fa0536
commit
aea72786b6
@ -2314,7 +2314,11 @@ QString GLScope::displayScaled(float value, char type, int precision)
|
|||||||
{
|
{
|
||||||
float posValue = (value < 0) ? -value : value;
|
float posValue = (value < 0) ? -value : value;
|
||||||
|
|
||||||
if (posValue < 1)
|
if (posValue == 0)
|
||||||
|
{
|
||||||
|
return tr("%1").arg(QString::number(value, 'f', precision));
|
||||||
|
}
|
||||||
|
else if (posValue < 1)
|
||||||
{
|
{
|
||||||
if (posValue > 0.001) {
|
if (posValue > 0.001) {
|
||||||
return tr("%1m").arg(QString::number(value * 1000.0, type, precision));
|
return tr("%1m").arg(QString::number(value * 1000.0, type, precision));
|
||||||
|
@ -2094,7 +2094,7 @@ void GLSpectrum::mousePressEvent(QMouseEvent* event)
|
|||||||
getPrecision(m_centerFrequency/m_sampleRate),
|
getPrecision(m_centerFrequency/m_sampleRate),
|
||||||
false);
|
false);
|
||||||
m_waterfallMarkers.back().m_time = time;
|
m_waterfallMarkers.back().m_time = time;
|
||||||
m_waterfallMarkers.back().m_timeStr = displayScaledM(
|
m_waterfallMarkers.back().m_timeStr = displayScaledF(
|
||||||
time,
|
time,
|
||||||
'f',
|
'f',
|
||||||
3,
|
3,
|
||||||
@ -2108,7 +2108,7 @@ void GLSpectrum::mousePressEvent(QMouseEvent* event)
|
|||||||
'f',
|
'f',
|
||||||
getPrecision(deltaFrequency/m_sampleRate),
|
getPrecision(deltaFrequency/m_sampleRate),
|
||||||
true);
|
true);
|
||||||
m_waterfallMarkers.back().m_deltaTimeStr = displayScaledM(
|
m_waterfallMarkers.back().m_deltaTimeStr = displayScaledF(
|
||||||
time - m_waterfallMarkers.at(0).m_time,
|
time - m_waterfallMarkers.at(0).m_time,
|
||||||
'f',
|
'f',
|
||||||
3,
|
3,
|
||||||
@ -2312,24 +2312,13 @@ QString GLSpectrum::displayScaledF(float value, char type, int precision, bool s
|
|||||||
{
|
{
|
||||||
float posValue = (value < 0) ? -value : value;
|
float posValue = (value < 0) ? -value : value;
|
||||||
|
|
||||||
if (posValue < 1000) {
|
if (posValue == 0)
|
||||||
return tr("%1").arg(QString::number(value, type, precision));
|
|
||||||
} else if (posValue < 1000000) {
|
|
||||||
return tr("%1%2").arg(QString::number(value / 1000.0, type, precision)).arg(showMult ? "k" : "");
|
|
||||||
} else if (posValue < 1000000000) {
|
|
||||||
return tr("%1%2").arg(QString::number(value / 1000000.0, type, precision)).arg(showMult ? "M" : "");
|
|
||||||
} else if (posValue < 1000000000000) {
|
|
||||||
return tr("%1%2").arg(QString::number(value / 1000000000.0, type, precision)).arg(showMult ? "G" : "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString GLSpectrum::displayScaledM(float value, char type, int precision, bool showMult)
|
|
||||||
{
|
{
|
||||||
float posValue = (value < 0) ? -value : value;
|
return tr("%1").arg(QString::number(value, 'f', precision));
|
||||||
|
}
|
||||||
if (posValue > 1) {
|
else if (posValue < 1)
|
||||||
return tr("%1").arg(QString::number(value, type, precision));
|
{
|
||||||
} else if (posValue > 0.001) {
|
if (posValue > 0.001) {
|
||||||
return tr("%1%2").arg(QString::number(value * 1000.0, type, precision)).arg(showMult ? "m" : "");
|
return tr("%1%2").arg(QString::number(value * 1000.0, type, precision)).arg(showMult ? "m" : "");
|
||||||
} else if (posValue > 0.000001) {
|
} else if (posValue > 0.000001) {
|
||||||
return tr("%1%2").arg(QString::number(value * 1000000.0, type, precision)).arg(showMult ? "u" : "");
|
return tr("%1%2").arg(QString::number(value * 1000000.0, type, precision)).arg(showMult ? "u" : "");
|
||||||
@ -2341,6 +2330,21 @@ QString GLSpectrum::displayScaledM(float value, char type, int precision, bool s
|
|||||||
return tr("%1").arg(QString::number(value, 'e', precision));
|
return tr("%1").arg(QString::number(value, 'e', precision));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (posValue < 1000) {
|
||||||
|
return tr("%1").arg(QString::number(value, type, precision));
|
||||||
|
} else if (posValue < 1000000) {
|
||||||
|
return tr("%1%2").arg(QString::number(value / 1000.0, type, precision)).arg(showMult ? "k" : "");
|
||||||
|
} else if (posValue < 1000000000) {
|
||||||
|
return tr("%1%2").arg(QString::number(value / 1000000.0, type, precision)).arg(showMult ? "M" : "");
|
||||||
|
} else if (posValue < 1000000000000) {
|
||||||
|
return tr("%1%2").arg(QString::number(value / 1000000000.0, type, precision)).arg(showMult ? "G" : "");
|
||||||
|
} else {
|
||||||
|
return tr("%1").arg(QString::number(value, 'e', precision));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int GLSpectrum::getPrecision(int value)
|
int GLSpectrum::getPrecision(int value)
|
||||||
{
|
{
|
||||||
|
@ -334,7 +334,6 @@ private:
|
|||||||
|
|
||||||
QString displayScaled(int64_t value, char type, int precision, bool showMult);
|
QString displayScaled(int64_t value, char type, int precision, bool showMult);
|
||||||
QString displayScaledF(float value, char type, int precision, bool showMult);
|
QString displayScaledF(float value, char type, int precision, bool showMult);
|
||||||
QString displayScaledM(float value, char type, int precision, bool showMult);
|
|
||||||
int getPrecision(int value);
|
int getPrecision(int value);
|
||||||
void drawTextOverlay( //!< Draws a text overlay
|
void drawTextOverlay( //!< Draws a text overlay
|
||||||
const QString& text,
|
const QString& text,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user