From 47b8dc199bbe7657047447822dd51195f3d2b586 Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 12 Mar 2020 15:31:20 +0100 Subject: [PATCH] GLSpectrum GUI optimization --- sdrgui/gui/glspectrumgui.cpp | 163 ++++++++++++++++++----------------- sdrgui/gui/glspectrumgui.h | 1 + 2 files changed, 84 insertions(+), 80 deletions(-) diff --git a/sdrgui/gui/glspectrumgui.cpp b/sdrgui/gui/glspectrumgui.cpp index 2f60909d4..2158094ae 100644 --- a/sdrgui/gui/glspectrumgui.cpp +++ b/sdrgui/gui/glspectrumgui.cpp @@ -8,9 +8,9 @@ GLSpectrumGUI::GLSpectrumGUI(QWidget* parent) : QWidget(parent), ui(new Ui::GLSpectrumGUI), - m_messageQueueToVis(0), - m_spectrumVis(0), - m_glSpectrum(0), + m_messageQueueToVis(nullptr), + m_spectrumVis(nullptr), + m_glSpectrum(nullptr), m_fftSize(1024), m_fftOverlap(0), m_fftWindow(FFTWindow::Hanning), @@ -57,6 +57,7 @@ void GLSpectrumGUI::setBuddies(MessageQueue* messageQueue, SpectrumVis* spectrum m_glSpectrum = glSpectrum; m_glSpectrum->setMessageQueueToGUI(&m_messageQueue); applySettings(); + applySettingsVis(); } void GLSpectrumGUI::resetToDefaults() @@ -80,6 +81,7 @@ void GLSpectrumGUI::resetToDefaults() m_averagingIndex = 0; m_linear = false; applySettings(); + applySettingsVis(); } QByteArray GLSpectrumGUI::serialize() const @@ -152,6 +154,7 @@ bool GLSpectrumGUI::deserialize(const QByteArray& data) m_glSpectrum->setWaterfallShare(waterfallShare); applySettings(); + applySettingsVis(); return true; } else @@ -163,18 +166,8 @@ bool GLSpectrumGUI::deserialize(const QByteArray& data) 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->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->decayDivisor->setSliderPosition(m_decayDivisor); ui->stroke->setSliderPosition(m_histogramStroke); @@ -203,52 +196,73 @@ void GLSpectrumGUI::applySettings() m_glSpectrum->setInvertedWaterfall(m_invert); m_glSpectrum->setDisplayGrid(m_displayGrid); 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_fftSize, m_fftOverlap, m_averagingNb, (SpectrumVis::AvgMode) m_averagingMode, - (FFTWindow::Function)m_fftWindow, - m_linear); + (FFTWindow::Function) m_fftWindow, + 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) { + qDebug("GLSpectrumGUI::on_fftWindow_currentIndexChanged: %d", index); m_fftWindow = index; - if(m_spectrumVis != 0) { - m_spectrumVis->configure(m_messageQueueToVis, - m_fftSize, - m_fftOverlap, - m_averagingNb, - (SpectrumVis::AvgMode) m_averagingMode, - (FFTWindow::Function)m_fftWindow, - m_linear); - } + applySettingsVis(); } void GLSpectrumGUI::on_fftSize_currentIndexChanged(int index) { + qDebug("GLSpectrumGUI::on_fftSize_currentIndexChanged: %d", index); m_fftSize = 1 << (7 + index); - if(m_spectrumVis != 0) { - m_spectrumVis->configure(m_messageQueueToVis, - m_fftSize, - m_fftOverlap, - m_averagingNb, - (SpectrumVis::AvgMode) m_averagingMode, - (FFTWindow::Function)m_fftWindow, - m_linear); - } + applySettingsVis(); setAveragingToolitp(); } void GLSpectrumGUI::on_averagingMode_currentIndexChanged(int index) { + qDebug("GLSpectrumGUI::on_averagingMode_currentIndexChanged: %d", index); m_averagingMode = index < 0 ? AvgModeNone : index > 3 ? AvgModeMax : (AveragingMode) index; if (m_averagingMode == AvgModeMoving) @@ -263,17 +277,9 @@ void GLSpectrumGUI::on_averagingMode_currentIndexChanged(int index) setAveragingCombo(); } - if(m_spectrumVis != 0) { - m_spectrumVis->configure(m_messageQueueToVis, - m_fftSize, - m_fftOverlap, - m_averagingNb, - (SpectrumVis::AvgMode) m_averagingMode, - (FFTWindow::Function)m_fftWindow, - m_linear); - } + applySettingsVis(); - if (m_glSpectrum != 0) + if (m_glSpectrum) { if ((m_averagingMode == AvgModeFixed) || (m_averagingMode == AvgModeMax)) { 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) { + qDebug("GLSpectrumGUI::on_averaging_currentIndexChanged: %d", index); m_averagingIndex = index; - m_averagingNb = getAveragingValue(index); - if(m_spectrumVis != 0) { - m_spectrumVis->configure(m_messageQueueToVis, - m_fftSize, - m_fftOverlap, - m_averagingNb, - (SpectrumVis::AvgMode) m_averagingMode, - (FFTWindow::Function)m_fftWindow, - m_linear); - } + applySettingsVis(); - if (m_glSpectrum != 0) + if (m_glSpectrum) { if ((m_averagingMode == AvgModeFixed) || (m_averagingMode == AvgModeMax)) { 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) { + qDebug("GLSpectrumGUI::on_averaging_currentIndexChanged: %s", checked ? "lin" : "log"); m_linear = checked; - if(m_spectrumVis != 0) { - m_spectrumVis->configure(m_messageQueueToVis, - m_fftSize, - m_fftOverlap, - m_averagingNb, - (SpectrumVis::AvgMode) m_averagingMode, - (FFTWindow::Function)m_fftWindow, - m_linear); - } + applySettingsVis(); - if(m_glSpectrum != 0) + if (m_glSpectrum) { 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; @@ -339,7 +330,7 @@ void GLSpectrumGUI::on_refLevel_currentIndexChanged(int index) { 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 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; - if(m_glSpectrum != 0) + if (m_glSpectrum) { 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; @@ -367,7 +358,8 @@ void GLSpectrumGUI::on_decay_valueChanged(int index) { m_decay = index; ui->decay->setToolTip(QString("Decay: %1").arg(m_decay)); - if(m_glSpectrum != 0) { + + if (m_glSpectrum) { m_glSpectrum->setDecay(m_decay); } } @@ -385,7 +377,7 @@ void GLSpectrumGUI::on_stroke_valueChanged(int index) { m_histogramStroke = index; //ui->stroke->setToolTip(QString("Stroke: %1").arg(m_histogramStroke)); - if(m_glSpectrum != 0) { + if (m_glSpectrum) { applySettings(); } } @@ -393,7 +385,8 @@ void GLSpectrumGUI::on_stroke_valueChanged(int index) void GLSpectrumGUI::on_waterfall_toggled(bool checked) { m_displayWaterfall = checked; - if(m_glSpectrum != 0) { + + if (m_glSpectrum) { m_glSpectrum->setDisplayWaterfall(m_displayWaterfall); } } @@ -401,7 +394,8 @@ void GLSpectrumGUI::on_waterfall_toggled(bool checked) void GLSpectrumGUI::on_histogram_toggled(bool checked) { m_displayHistogram = checked; - if(m_glSpectrum != 0) { + + if (m_glSpectrum) { m_glSpectrum->setDisplayHistogram(m_displayHistogram); } } @@ -409,7 +403,8 @@ void GLSpectrumGUI::on_histogram_toggled(bool checked) void GLSpectrumGUI::on_maxHold_toggled(bool checked) { m_displayMaxHold = checked; - if(m_glSpectrum != 0) { + + if (m_glSpectrum) { m_glSpectrum->setDisplayMaxHold(m_displayMaxHold); } } @@ -417,7 +412,8 @@ void GLSpectrumGUI::on_maxHold_toggled(bool checked) void GLSpectrumGUI::on_current_toggled(bool checked) { m_displayCurrent = checked; - if(m_glSpectrum != 0) { + + if (m_glSpectrum) { m_glSpectrum->setDisplayCurrent(m_displayCurrent); } } @@ -425,7 +421,8 @@ void GLSpectrumGUI::on_current_toggled(bool checked) void GLSpectrumGUI::on_invert_toggled(bool checked) { m_invert = checked; - if(m_glSpectrum != 0) { + + if (m_glSpectrum) { m_glSpectrum->setInvertedWaterfall(m_invert); } } @@ -433,7 +430,8 @@ void GLSpectrumGUI::on_invert_toggled(bool checked) void GLSpectrumGUI::on_grid_toggled(bool checked) { m_displayGrid = checked; - if(m_glSpectrum != 0) { + + if (m_glSpectrum) { m_glSpectrum->setDisplayGrid(m_displayGrid); } } @@ -442,7 +440,8 @@ void GLSpectrumGUI::on_gridIntensity_valueChanged(int index) { m_displayGridIntensity = index; ui->gridIntensity->setToolTip(QString("Grid intensity: %1").arg(m_displayGridIntensity)); - if(m_glSpectrum != 0) { + + if (m_glSpectrum) { m_glSpectrum->setDisplayGridIntensity(m_displayGridIntensity); } } @@ -451,7 +450,8 @@ void GLSpectrumGUI::on_traceIntensity_valueChanged(int index) { m_displayTraceIntensity = index; ui->traceIntensity->setToolTip(QString("Trace intensity: %1").arg(m_displayTraceIntensity)); - if(m_glSpectrum != 0) { + + if (m_glSpectrum) { m_glSpectrum->setDisplayTraceIntensity(m_displayTraceIntensity); } } @@ -459,7 +459,8 @@ void GLSpectrumGUI::on_traceIntensity_valueChanged(int index) void GLSpectrumGUI::on_clearSpectrum_clicked(bool checked) { (void) checked; - if(m_glSpectrum != 0) { + + if (m_glSpectrum) { m_glSpectrum->clearSpectrumHistogram(); } } @@ -520,6 +521,7 @@ int GLSpectrumGUI::getAveragingValue(int averagingIndex) const void GLSpectrumGUI::setAveragingCombo() { int index = ui->averaging->currentIndex(); + ui->averaging->blockSignals(true); ui->averaging->clear(); 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->blockSignals(false); } void GLSpectrumGUI::setNumberStr(int n, QString& s) diff --git a/sdrgui/gui/glspectrumgui.h b/sdrgui/gui/glspectrumgui.h index 8d1840004..47fddf909 100644 --- a/sdrgui/gui/glspectrumgui.h +++ b/sdrgui/gui/glspectrumgui.h @@ -67,6 +67,7 @@ private: bool m_linear; //!< linear else logarithmic scale void applySettings(); + void applySettingsVis(); int getAveragingIndex(int averaging) const; int getAveragingValue(int averagingIndex) const; void setAveragingCombo();