1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-15 12:51:49 -05:00

GLSpectrum GUI optimization

This commit is contained in:
f4exb 2020-03-12 15:31:20 +01:00
parent 926f45d9fb
commit 47b8dc199b
2 changed files with 84 additions and 80 deletions

View File

@ -8,9 +8,9 @@
GLSpectrumGUI::GLSpectrumGUI(QWidget* parent) : GLSpectrumGUI::GLSpectrumGUI(QWidget* parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::GLSpectrumGUI), ui(new Ui::GLSpectrumGUI),
m_messageQueueToVis(0), m_messageQueueToVis(nullptr),
m_spectrumVis(0), m_spectrumVis(nullptr),
m_glSpectrum(0), m_glSpectrum(nullptr),
m_fftSize(1024), m_fftSize(1024),
m_fftOverlap(0), m_fftOverlap(0),
m_fftWindow(FFTWindow::Hanning), m_fftWindow(FFTWindow::Hanning),
@ -57,6 +57,7 @@ void GLSpectrumGUI::setBuddies(MessageQueue* messageQueue, SpectrumVis* spectrum
m_glSpectrum = glSpectrum; m_glSpectrum = glSpectrum;
m_glSpectrum->setMessageQueueToGUI(&m_messageQueue); m_glSpectrum->setMessageQueueToGUI(&m_messageQueue);
applySettings(); applySettings();
applySettingsVis();
} }
void GLSpectrumGUI::resetToDefaults() void GLSpectrumGUI::resetToDefaults()
@ -80,6 +81,7 @@ void GLSpectrumGUI::resetToDefaults()
m_averagingIndex = 0; m_averagingIndex = 0;
m_linear = false; m_linear = false;
applySettings(); applySettings();
applySettingsVis();
} }
QByteArray GLSpectrumGUI::serialize() const QByteArray GLSpectrumGUI::serialize() const
@ -152,6 +154,7 @@ bool GLSpectrumGUI::deserialize(const QByteArray& data)
m_glSpectrum->setWaterfallShare(waterfallShare); m_glSpectrum->setWaterfallShare(waterfallShare);
applySettings(); applySettings();
applySettingsVis();
return true; return true;
} }
else else
@ -163,18 +166,8 @@ bool GLSpectrumGUI::deserialize(const QByteArray& data)
void GLSpectrumGUI::applySettings() void GLSpectrumGUI::applySettings()
{ {
ui->fftWindow->setCurrentIndex(m_fftWindow);
for(int i = 0; i < 6; i++) {
if(m_fftSize == (1 << (i + 7))) {
ui->fftSize->setCurrentIndex(i);
break;
}
}
ui->refLevel->setCurrentIndex(-m_refLevel / 5); ui->refLevel->setCurrentIndex(-m_refLevel / 5);
ui->levelRange->setCurrentIndex((100 - m_powerRange) / 5); ui->levelRange->setCurrentIndex((100 - m_powerRange) / 5);
ui->averaging->setCurrentIndex(m_averagingIndex);
ui->averagingMode->setCurrentIndex((int) m_averagingMode);
ui->linscale->setChecked(m_linear);
ui->decay->setSliderPosition(m_decay); ui->decay->setSliderPosition(m_decay);
ui->decayDivisor->setSliderPosition(m_decayDivisor); ui->decayDivisor->setSliderPosition(m_decayDivisor);
ui->stroke->setSliderPosition(m_histogramStroke); ui->stroke->setSliderPosition(m_histogramStroke);
@ -203,52 +196,73 @@ void GLSpectrumGUI::applySettings()
m_glSpectrum->setInvertedWaterfall(m_invert); m_glSpectrum->setInvertedWaterfall(m_invert);
m_glSpectrum->setDisplayGrid(m_displayGrid); m_glSpectrum->setDisplayGrid(m_displayGrid);
m_glSpectrum->setDisplayGridIntensity(m_displayGridIntensity); m_glSpectrum->setDisplayGridIntensity(m_displayGridIntensity);
m_glSpectrum->setLinear(m_linear);
if (m_spectrumVis) { setAveragingToolitp();
}
void GLSpectrumGUI::applySettingsVis()
{
ui->fftWindow->blockSignals(true);
ui->averaging->blockSignals(true);
ui->averagingMode->blockSignals(true);
ui->linscale->blockSignals(true);
ui->fftWindow->setCurrentIndex(m_fftWindow);
for (int i = 0; i < 6; i++)
{
if (m_fftSize == (1 << (i + 7)))
{
ui->fftSize->setCurrentIndex(i);
break;
}
}
ui->averaging->setCurrentIndex(m_averagingIndex);
m_averagingNb = getAveragingValue(m_averagingIndex);
ui->averagingMode->setCurrentIndex((int) m_averagingMode);
ui->linscale->setChecked(m_linear);
if (m_glSpectrum) {
m_glSpectrum->setLinear(m_linear);
}
if (m_spectrumVis)
{
m_spectrumVis->configure(m_messageQueueToVis, m_spectrumVis->configure(m_messageQueueToVis,
m_fftSize, m_fftSize,
m_fftOverlap, m_fftOverlap,
m_averagingNb, m_averagingNb,
(SpectrumVis::AvgMode) m_averagingMode, (SpectrumVis::AvgMode) m_averagingMode,
(FFTWindow::Function)m_fftWindow, (FFTWindow::Function) m_fftWindow,
m_linear); m_linear
);
} }
setAveragingToolitp(); ui->fftWindow->blockSignals(false);
ui->averaging->blockSignals(false);
ui->averagingMode->blockSignals(false);
ui->linscale->blockSignals(false);
} }
void GLSpectrumGUI::on_fftWindow_currentIndexChanged(int index) void GLSpectrumGUI::on_fftWindow_currentIndexChanged(int index)
{ {
qDebug("GLSpectrumGUI::on_fftWindow_currentIndexChanged: %d", index);
m_fftWindow = index; m_fftWindow = index;
if(m_spectrumVis != 0) { applySettingsVis();
m_spectrumVis->configure(m_messageQueueToVis,
m_fftSize,
m_fftOverlap,
m_averagingNb,
(SpectrumVis::AvgMode) m_averagingMode,
(FFTWindow::Function)m_fftWindow,
m_linear);
}
} }
void GLSpectrumGUI::on_fftSize_currentIndexChanged(int index) void GLSpectrumGUI::on_fftSize_currentIndexChanged(int index)
{ {
qDebug("GLSpectrumGUI::on_fftSize_currentIndexChanged: %d", index);
m_fftSize = 1 << (7 + index); m_fftSize = 1 << (7 + index);
if(m_spectrumVis != 0) { applySettingsVis();
m_spectrumVis->configure(m_messageQueueToVis,
m_fftSize,
m_fftOverlap,
m_averagingNb,
(SpectrumVis::AvgMode) m_averagingMode,
(FFTWindow::Function)m_fftWindow,
m_linear);
}
setAveragingToolitp(); setAveragingToolitp();
} }
void GLSpectrumGUI::on_averagingMode_currentIndexChanged(int index) void GLSpectrumGUI::on_averagingMode_currentIndexChanged(int index)
{ {
qDebug("GLSpectrumGUI::on_averagingMode_currentIndexChanged: %d", index);
m_averagingMode = index < 0 ? AvgModeNone : index > 3 ? AvgModeMax : (AveragingMode) index; m_averagingMode = index < 0 ? AvgModeNone : index > 3 ? AvgModeMax : (AveragingMode) index;
if (m_averagingMode == AvgModeMoving) if (m_averagingMode == AvgModeMoving)
@ -263,17 +277,9 @@ void GLSpectrumGUI::on_averagingMode_currentIndexChanged(int index)
setAveragingCombo(); setAveragingCombo();
} }
if(m_spectrumVis != 0) { applySettingsVis();
m_spectrumVis->configure(m_messageQueueToVis,
m_fftSize,
m_fftOverlap,
m_averagingNb,
(SpectrumVis::AvgMode) m_averagingMode,
(FFTWindow::Function)m_fftWindow,
m_linear);
}
if (m_glSpectrum != 0) if (m_glSpectrum)
{ {
if ((m_averagingMode == AvgModeFixed) || (m_averagingMode == AvgModeMax)) { if ((m_averagingMode == AvgModeFixed) || (m_averagingMode == AvgModeMax)) {
m_glSpectrum->setTimingRate(m_averagingNb == 0 ? 1 : m_averagingNb); m_glSpectrum->setTimingRate(m_averagingNb == 0 ? 1 : m_averagingNb);
@ -285,20 +291,12 @@ void GLSpectrumGUI::on_averagingMode_currentIndexChanged(int index)
void GLSpectrumGUI::on_averaging_currentIndexChanged(int index) void GLSpectrumGUI::on_averaging_currentIndexChanged(int index)
{ {
qDebug("GLSpectrumGUI::on_averaging_currentIndexChanged: %d", index);
m_averagingIndex = index; m_averagingIndex = index;
m_averagingNb = getAveragingValue(index);
if(m_spectrumVis != 0) { applySettingsVis();
m_spectrumVis->configure(m_messageQueueToVis,
m_fftSize,
m_fftOverlap,
m_averagingNb,
(SpectrumVis::AvgMode) m_averagingMode,
(FFTWindow::Function)m_fftWindow,
m_linear);
}
if (m_glSpectrum != 0) if (m_glSpectrum)
{ {
if ((m_averagingMode == AvgModeFixed) || (m_averagingMode == AvgModeMax)) { if ((m_averagingMode == AvgModeFixed) || (m_averagingMode == AvgModeMax)) {
m_glSpectrum->setTimingRate(m_averagingNb == 0 ? 1 : m_averagingNb); m_glSpectrum->setTimingRate(m_averagingNb == 0 ? 1 : m_averagingNb);
@ -312,19 +310,12 @@ void GLSpectrumGUI::on_averaging_currentIndexChanged(int index)
void GLSpectrumGUI::on_linscale_toggled(bool checked) void GLSpectrumGUI::on_linscale_toggled(bool checked)
{ {
qDebug("GLSpectrumGUI::on_averaging_currentIndexChanged: %s", checked ? "lin" : "log");
m_linear = checked; m_linear = checked;
if(m_spectrumVis != 0) { applySettingsVis();
m_spectrumVis->configure(m_messageQueueToVis,
m_fftSize,
m_fftOverlap,
m_averagingNb,
(SpectrumVis::AvgMode) m_averagingMode,
(FFTWindow::Function)m_fftWindow,
m_linear);
}
if(m_glSpectrum != 0) if (m_glSpectrum)
{ {
Real refLevel = m_linear ? pow(10.0, m_refLevel/10.0) : m_refLevel; Real refLevel = m_linear ? pow(10.0, m_refLevel/10.0) : m_refLevel;
Real powerRange = m_linear ? pow(10.0, m_refLevel/10.0) : m_powerRange; Real powerRange = m_linear ? pow(10.0, m_refLevel/10.0) : m_powerRange;
@ -339,7 +330,7 @@ void GLSpectrumGUI::on_refLevel_currentIndexChanged(int index)
{ {
m_refLevel = 0 - index * 5; m_refLevel = 0 - index * 5;
if(m_glSpectrum != 0) if (m_glSpectrum)
{ {
Real refLevel = m_linear ? pow(10.0, m_refLevel/10.0) : m_refLevel; Real refLevel = m_linear ? pow(10.0, m_refLevel/10.0) : m_refLevel;
Real powerRange = m_linear ? pow(10.0, m_refLevel/10.0) : m_powerRange; Real powerRange = m_linear ? pow(10.0, m_refLevel/10.0) : m_powerRange;
@ -353,7 +344,7 @@ void GLSpectrumGUI::on_levelRange_currentIndexChanged(int index)
{ {
m_powerRange = 100 - index * 5; m_powerRange = 100 - index * 5;
if(m_glSpectrum != 0) if (m_glSpectrum)
{ {
Real refLevel = m_linear ? pow(10.0, m_refLevel/10.0) : m_refLevel; Real refLevel = m_linear ? pow(10.0, m_refLevel/10.0) : m_refLevel;
Real powerRange = m_linear ? pow(10.0, m_refLevel/10.0) : m_powerRange; Real powerRange = m_linear ? pow(10.0, m_refLevel/10.0) : m_powerRange;
@ -367,7 +358,8 @@ void GLSpectrumGUI::on_decay_valueChanged(int index)
{ {
m_decay = index; m_decay = index;
ui->decay->setToolTip(QString("Decay: %1").arg(m_decay)); ui->decay->setToolTip(QString("Decay: %1").arg(m_decay));
if(m_glSpectrum != 0) {
if (m_glSpectrum) {
m_glSpectrum->setDecay(m_decay); m_glSpectrum->setDecay(m_decay);
} }
} }
@ -385,7 +377,7 @@ void GLSpectrumGUI::on_stroke_valueChanged(int index)
{ {
m_histogramStroke = index; m_histogramStroke = index;
//ui->stroke->setToolTip(QString("Stroke: %1").arg(m_histogramStroke)); //ui->stroke->setToolTip(QString("Stroke: %1").arg(m_histogramStroke));
if(m_glSpectrum != 0) { if (m_glSpectrum) {
applySettings(); applySettings();
} }
} }
@ -393,7 +385,8 @@ void GLSpectrumGUI::on_stroke_valueChanged(int index)
void GLSpectrumGUI::on_waterfall_toggled(bool checked) void GLSpectrumGUI::on_waterfall_toggled(bool checked)
{ {
m_displayWaterfall = checked; m_displayWaterfall = checked;
if(m_glSpectrum != 0) {
if (m_glSpectrum) {
m_glSpectrum->setDisplayWaterfall(m_displayWaterfall); m_glSpectrum->setDisplayWaterfall(m_displayWaterfall);
} }
} }
@ -401,7 +394,8 @@ void GLSpectrumGUI::on_waterfall_toggled(bool checked)
void GLSpectrumGUI::on_histogram_toggled(bool checked) void GLSpectrumGUI::on_histogram_toggled(bool checked)
{ {
m_displayHistogram = checked; m_displayHistogram = checked;
if(m_glSpectrum != 0) {
if (m_glSpectrum) {
m_glSpectrum->setDisplayHistogram(m_displayHistogram); m_glSpectrum->setDisplayHistogram(m_displayHistogram);
} }
} }
@ -409,7 +403,8 @@ void GLSpectrumGUI::on_histogram_toggled(bool checked)
void GLSpectrumGUI::on_maxHold_toggled(bool checked) void GLSpectrumGUI::on_maxHold_toggled(bool checked)
{ {
m_displayMaxHold = checked; m_displayMaxHold = checked;
if(m_glSpectrum != 0) {
if (m_glSpectrum) {
m_glSpectrum->setDisplayMaxHold(m_displayMaxHold); m_glSpectrum->setDisplayMaxHold(m_displayMaxHold);
} }
} }
@ -417,7 +412,8 @@ void GLSpectrumGUI::on_maxHold_toggled(bool checked)
void GLSpectrumGUI::on_current_toggled(bool checked) void GLSpectrumGUI::on_current_toggled(bool checked)
{ {
m_displayCurrent = checked; m_displayCurrent = checked;
if(m_glSpectrum != 0) {
if (m_glSpectrum) {
m_glSpectrum->setDisplayCurrent(m_displayCurrent); m_glSpectrum->setDisplayCurrent(m_displayCurrent);
} }
} }
@ -425,7 +421,8 @@ void GLSpectrumGUI::on_current_toggled(bool checked)
void GLSpectrumGUI::on_invert_toggled(bool checked) void GLSpectrumGUI::on_invert_toggled(bool checked)
{ {
m_invert = checked; m_invert = checked;
if(m_glSpectrum != 0) {
if (m_glSpectrum) {
m_glSpectrum->setInvertedWaterfall(m_invert); m_glSpectrum->setInvertedWaterfall(m_invert);
} }
} }
@ -433,7 +430,8 @@ void GLSpectrumGUI::on_invert_toggled(bool checked)
void GLSpectrumGUI::on_grid_toggled(bool checked) void GLSpectrumGUI::on_grid_toggled(bool checked)
{ {
m_displayGrid = checked; m_displayGrid = checked;
if(m_glSpectrum != 0) {
if (m_glSpectrum) {
m_glSpectrum->setDisplayGrid(m_displayGrid); m_glSpectrum->setDisplayGrid(m_displayGrid);
} }
} }
@ -442,7 +440,8 @@ void GLSpectrumGUI::on_gridIntensity_valueChanged(int index)
{ {
m_displayGridIntensity = index; m_displayGridIntensity = index;
ui->gridIntensity->setToolTip(QString("Grid intensity: %1").arg(m_displayGridIntensity)); ui->gridIntensity->setToolTip(QString("Grid intensity: %1").arg(m_displayGridIntensity));
if(m_glSpectrum != 0) {
if (m_glSpectrum) {
m_glSpectrum->setDisplayGridIntensity(m_displayGridIntensity); m_glSpectrum->setDisplayGridIntensity(m_displayGridIntensity);
} }
} }
@ -451,7 +450,8 @@ void GLSpectrumGUI::on_traceIntensity_valueChanged(int index)
{ {
m_displayTraceIntensity = index; m_displayTraceIntensity = index;
ui->traceIntensity->setToolTip(QString("Trace intensity: %1").arg(m_displayTraceIntensity)); ui->traceIntensity->setToolTip(QString("Trace intensity: %1").arg(m_displayTraceIntensity));
if(m_glSpectrum != 0) {
if (m_glSpectrum) {
m_glSpectrum->setDisplayTraceIntensity(m_displayTraceIntensity); m_glSpectrum->setDisplayTraceIntensity(m_displayTraceIntensity);
} }
} }
@ -459,7 +459,8 @@ void GLSpectrumGUI::on_traceIntensity_valueChanged(int index)
void GLSpectrumGUI::on_clearSpectrum_clicked(bool checked) void GLSpectrumGUI::on_clearSpectrum_clicked(bool checked)
{ {
(void) checked; (void) checked;
if(m_glSpectrum != 0) {
if (m_glSpectrum) {
m_glSpectrum->clearSpectrumHistogram(); m_glSpectrum->clearSpectrumHistogram();
} }
} }
@ -520,6 +521,7 @@ int GLSpectrumGUI::getAveragingValue(int averagingIndex) const
void GLSpectrumGUI::setAveragingCombo() void GLSpectrumGUI::setAveragingCombo()
{ {
int index = ui->averaging->currentIndex(); int index = ui->averaging->currentIndex();
ui->averaging->blockSignals(true);
ui->averaging->clear(); ui->averaging->clear();
ui->averaging->addItem(QString("1")); ui->averaging->addItem(QString("1"));
@ -539,6 +541,7 @@ void GLSpectrumGUI::setAveragingCombo()
} }
ui->averaging->setCurrentIndex(index >= ui->averaging->count() ? ui->averaging->count() - 1 : index); ui->averaging->setCurrentIndex(index >= ui->averaging->count() ? ui->averaging->count() - 1 : index);
ui->averaging->blockSignals(false);
} }
void GLSpectrumGUI::setNumberStr(int n, QString& s) void GLSpectrumGUI::setNumberStr(int n, QString& s)

View File

@ -67,6 +67,7 @@ private:
bool m_linear; //!< linear else logarithmic scale bool m_linear; //!< linear else logarithmic scale
void applySettings(); void applySettings();
void applySettingsVis();
int getAveragingIndex(int averaging) const; int getAveragingIndex(int averaging) const;
int getAveragingValue(int averagingIndex) const; int getAveragingValue(int averagingIndex) const;
void setAveragingCombo(); void setAveragingCombo();