From 111c8d4a9943a124c545abc111a5574ad8449e1a Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 3 Aug 2021 00:28:14 +0200 Subject: [PATCH] Spectrum markers: add dialog for waterfall markers --- sdrgui/gui/glspectrum.cpp | 5 + sdrgui/gui/glspectrum.h | 1 + sdrgui/gui/glspectrumgui.cpp | 1 + sdrgui/gui/spectrummarkersdialog.cpp | 191 ++++ sdrgui/gui/spectrummarkersdialog.h | 16 + sdrgui/gui/spectrummarkersdialog.ui | 1327 ++++++++++++++++++-------- 6 files changed, 1136 insertions(+), 405 deletions(-) diff --git a/sdrgui/gui/glspectrum.cpp b/sdrgui/gui/glspectrum.cpp index 553481529..621ef092f 100644 --- a/sdrgui/gui/glspectrum.cpp +++ b/sdrgui/gui/glspectrum.cpp @@ -443,6 +443,11 @@ float GLSpectrum::getPowerMax() const return m_linear ? m_powerScale.getRangeMax() : CalcDb::powerFromdB(m_powerScale.getRangeMax()); } +float GLSpectrum::getTimeMax() const +{ + return m_timeScale.getRangeMax(); +} + void GLSpectrum::newSpectrum(const Real *spectrum, int nbBins, int fftSize) { QMutexLocker mutexLocker(&m_mutex); diff --git a/sdrgui/gui/glspectrum.h b/sdrgui/gui/glspectrum.h index 807178b4f..5c8dce499 100644 --- a/sdrgui/gui/glspectrum.h +++ b/sdrgui/gui/glspectrum.h @@ -115,6 +115,7 @@ public: void setCenterFrequency(qint64 frequency); qint64 getCenterFrequency() const { return m_centerFrequency; } float getPowerMax() const; + float getTimeMax() const; void setSampleRate(qint32 sampleRate); void setTimingRate(qint32 timingRate); void setFFTOverlap(int overlap); diff --git a/sdrgui/gui/glspectrumgui.cpp b/sdrgui/gui/glspectrumgui.cpp index e3682b2fe..3fb5f9cf5 100644 --- a/sdrgui/gui/glspectrumgui.cpp +++ b/sdrgui/gui/glspectrumgui.cpp @@ -348,6 +348,7 @@ void GLSpectrumGUI::on_markers_clicked(bool checked) markersDialog.setCenterFrequency(m_glSpectrum->getCenterFrequency()); markersDialog.setPower(m_glSpectrum->getPowerMax() / 2.0f); + markersDialog.setTime(m_glSpectrum->getTimeMax() / 2.0f); connect(&markersDialog, SIGNAL(updateHistogram()), this, SLOT(updateHistogramMarkers())); connect(&markersDialog, SIGNAL(updateWaterfall()), this, SLOT(updateWaterfallMarkers())); diff --git a/sdrgui/gui/spectrummarkersdialog.cpp b/sdrgui/gui/spectrummarkersdialog.cpp index a20d483bf..a53b57255 100644 --- a/sdrgui/gui/spectrummarkersdialog.cpp +++ b/sdrgui/gui/spectrummarkersdialog.cpp @@ -33,6 +33,7 @@ SpectrumMarkersDialog::SpectrumMarkersDialog( m_histogramMarkers(histogramMarkers), m_waterfallMarkers(waterfallMarkers), m_histogramMarkerIndex(0), + m_waterfallMarkerIndex(0), m_centerFrequency(0), m_power(0.5f) { @@ -40,7 +41,11 @@ SpectrumMarkersDialog::SpectrumMarkersDialog( ui->markerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold)); ui->markerFrequency->setValueRange(false, 10, -9999999999L, 9999999999L); ui->marker->setMaximum(m_histogramMarkers.size() - 1); + ui->wMarkerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold)); + ui->wMarkerFrequency->setValueRange(false, 10, -9999999999L, 9999999999L); + ui->wMarker->setMaximum(m_waterfallMarkers.size() - 1); displayHistogramMarker(); + displayWaterfallMarker(); } SpectrumMarkersDialog::~SpectrumMarkersDialog() @@ -76,6 +81,59 @@ void SpectrumMarkersDialog::displayHistogramMarker() } } +void SpectrumMarkersDialog::displayWaterfallMarker() +{ + if (m_waterfallMarkers.size() == 0) + { + ui->wMarker->setEnabled(false); + ui->wMarkerFrequency->setEnabled(false); + ui->timeCoarse->setEnabled(false); + ui->timeFine->setEnabled(false); + ui->timeExp->setEnabled(false); + ui->wMarkerText->setText("-"); + ui->timeCoarse->setValue(0); + ui->timeFine->setValue(0); + ui->timeText->setText("0.000"); + ui->timeExp->setValue(0); + ui->timeExpText->setText("e+0"); + } + else + { + ui->wMarker->setEnabled(true); + ui->wMarkerFrequency->setEnabled(true); + ui->timeCoarse->setEnabled(true); + ui->timeFine->setEnabled(true); + ui->timeExp->setEnabled(true); + ui->wMarkerText->setText(tr("%1").arg(m_waterfallMarkerIndex)); + ui->wMarkerFrequency->setValue(m_waterfallMarkers[m_waterfallMarkerIndex].m_frequency); + int r,g,b,a; + m_waterfallMarkers[m_waterfallMarkerIndex].m_markerColor.getRgb(&r, &g, &b, &a); + ui->wMarkerColor->setStyleSheet(tr("QLabel { background-color : rgb(%1,%2,%3); }").arg(r).arg(g).arg(b)); + displayTime(m_waterfallMarkers[m_waterfallMarkerIndex].m_time); + } +} + +void SpectrumMarkersDialog::displayTime(float time) +{ + int timeExp; + double timeMant = CalcDb::frexp10(time, &timeExp) * 10.0; + int timeCoarse = (int) timeMant; + int timeFine = round((timeMant - timeCoarse) * 1000.0); + timeExp -= timeMant == 0 ? 0 : 1; + qDebug("SpectrumMarkersDialog::displayTime: time: %e fine: %d coarse: %d exp: %d", + time, timeFine, timeCoarse, timeExp); + ui->timeFine->setValue(timeFine); + ui->timeCoarse->setValue(timeCoarse); + ui->timeExp->setValue(timeExp); + ui->timeText->setText(tr("%1").arg(timeMant, 0, 'f', 3)); + ui->timeExpText->setText(tr("e%1%2").arg(timeExp < 0 ? "" : "+").arg(timeExp)); +} + +float SpectrumMarkersDialog::getTime() const +{ + return ((ui->timeFine->value() / 1000.0) + ui->timeCoarse->value()) * pow(10.0, ui->timeExp->value()); +} + void SpectrumMarkersDialog::on_markerFrequency_changed(qint64 value) { if (m_histogramMarkers.size() == 0) { @@ -191,3 +249,136 @@ void SpectrumMarkersDialog::on_powerMode_currentIndexChanged(int index) m_histogramMarkers[m_histogramMarkerIndex].m_markerType = (SpectrumHistogramMarkerType) index; } + +void SpectrumMarkersDialog::on_wMarkerFrequency_changed(qint64 value) +{ + if (m_waterfallMarkers.size() == 0) { + return; + } + + m_waterfallMarkers[m_waterfallMarkerIndex].m_frequency = value; + emit updateWaterfall(); +} + +void SpectrumMarkersDialog::on_timeCoarse_valueChanged(int value) +{ + double timeMant = value + (ui->timeFine->value() / 1000.0); + ui->timeText->setText(tr("%1").arg(timeMant, 0, 'f', 3)); + + if (m_waterfallMarkers.size() == 0) { + return; + } + + m_waterfallMarkers[m_waterfallMarkerIndex].m_time = getTime(); + emit updateWaterfall(); +} + +void SpectrumMarkersDialog::on_timeFine_valueChanged(int value) +{ + double timeMant = ui->timeCoarse->value() + (value / 1000.0); + ui->timeText->setText(tr("%1").arg(timeMant, 0, 'f', 3)); + + if (m_waterfallMarkers.size() == 0) { + return; + } + + m_waterfallMarkers[m_waterfallMarkerIndex].m_time = getTime(); + emit updateWaterfall(); +} + +void SpectrumMarkersDialog::on_timeExp_valueChanged(int value) +{ + ui->timeExpText->setText(tr("e%1%2").arg(value < 0 ? "" : "+").arg(value)); + + if (m_waterfallMarkers.size() == 0) { + return; + } + + m_waterfallMarkers[m_waterfallMarkerIndex].m_time = getTime(); + emit updateWaterfall(); +} + +void SpectrumMarkersDialog::on_wCenterFrequency_clicked() +{ + if (m_waterfallMarkers.size() == 0) { + return; + } + + m_waterfallMarkers[m_waterfallMarkerIndex].m_frequency = m_centerFrequency; + displayWaterfallMarker(); + emit updateWaterfall(); +} + +void SpectrumMarkersDialog::on_wMarkerColor_clicked() +{ + if (m_waterfallMarkers.size() == 0) { + return; + } + + QColor newColor = QColorDialog::getColor( + m_waterfallMarkers[m_waterfallMarkerIndex].m_markerColor, + this, + tr("Select Color for marker"), + QColorDialog::DontUseNativeDialog + ); + + if (newColor.isValid()) // user clicked OK and selected a color + { + m_waterfallMarkers[m_waterfallMarkerIndex].m_markerColor = newColor; + displayWaterfallMarker(); + } +} + +void SpectrumMarkersDialog::on_wMarker_valueChanged(int value) +{ + if (m_waterfallMarkers.size() == 0) { + return; + } + + m_waterfallMarkerIndex = value; + displayWaterfallMarker(); +} + +void SpectrumMarkersDialog::on_wSetReference_clicked() +{ + if ((m_waterfallMarkerIndex == 0) || (m_waterfallMarkers.size() < 2)) { + return; + } + + SpectrumWaterfallMarker marker0 = m_waterfallMarkers.at(0); + QColor color0 = marker0.m_markerColor; // do not exchange colors + QColor colorI = m_waterfallMarkers[m_waterfallMarkerIndex].m_markerColor; + m_waterfallMarkers[0] = m_waterfallMarkers[m_waterfallMarkerIndex]; + m_waterfallMarkers[0].m_markerColor = color0; + m_waterfallMarkers[m_waterfallMarkerIndex] = marker0; + m_waterfallMarkers[m_waterfallMarkerIndex].m_markerColor = colorI; + displayWaterfallMarker(); + emit updateWaterfall(); +} + +void SpectrumMarkersDialog::on_wMarkerAdd_clicked() +{ + if (m_waterfallMarkers.size() == SpectrumWaterfallMarker::m_maxNbOfMarkers) { + return; + } + + m_waterfallMarkers.append(SpectrumWaterfallMarker()); + m_waterfallMarkers.back().m_frequency = m_centerFrequency; + m_waterfallMarkers.back().m_time = m_time; + m_waterfallMarkerIndex = m_waterfallMarkers.size() - 1; + ui->wMarker->setMaximum(m_waterfallMarkers.size() - 1); + displayWaterfallMarker(); +} + +void SpectrumMarkersDialog::on_wMarkerDel_clicked() +{ + if (m_waterfallMarkers.size() == 0) { + return; + } + + m_waterfallMarkers.removeAt(m_waterfallMarkerIndex); + m_waterfallMarkerIndex = m_waterfallMarkerIndex < m_waterfallMarkers.size() ? + m_waterfallMarkerIndex : m_waterfallMarkerIndex - 1; + ui->wMarker->setMaximum(m_waterfallMarkers.size() - 1); + displayWaterfallMarker(); +} diff --git a/sdrgui/gui/spectrummarkersdialog.h b/sdrgui/gui/spectrummarkersdialog.h index 1ab6150aa..e6c48f53c 100644 --- a/sdrgui/gui/spectrummarkersdialog.h +++ b/sdrgui/gui/spectrummarkersdialog.h @@ -41,16 +41,22 @@ public: ~SpectrumMarkersDialog(); void setCenterFrequency(qint64 centerFrequency) { m_centerFrequency = centerFrequency; } void setPower(float power) { m_power = power; } + void setTime(float time) { m_time = time; } private: Ui::SpectrumMarkersDialog* ui; QList& m_histogramMarkers; QList& m_waterfallMarkers; int m_histogramMarkerIndex; + int m_waterfallMarkerIndex; qint64 m_centerFrequency; float m_power; + float m_time; void displayHistogramMarker(); + void displayWaterfallMarker(); + void displayTime(float time); + float getTime() const; private slots: void on_markerFrequency_changed(qint64 value); @@ -62,6 +68,16 @@ private slots: void on_markerAdd_clicked(); void on_markerDel_clicked(); void on_powerMode_currentIndexChanged(int index); + void on_wMarkerFrequency_changed(qint64 value); + void on_timeCoarse_valueChanged(int value); + void on_timeFine_valueChanged(int value); + void on_timeExp_valueChanged(int value); + void on_wCenterFrequency_clicked(); + void on_wMarkerColor_clicked(); + void on_wMarker_valueChanged(int value); + void on_wSetReference_clicked(); + void on_wMarkerAdd_clicked(); + void on_wMarkerDel_clicked(); signals: void updateHistogram(); diff --git a/sdrgui/gui/spectrummarkersdialog.ui b/sdrgui/gui/spectrummarkersdialog.ui index 2b1a4995e..3d35da8df 100644 --- a/sdrgui/gui/spectrummarkersdialog.ui +++ b/sdrgui/gui/spectrummarkersdialog.ui @@ -6,8 +6,8 @@ 0 0 - 364 - 125 + 390 + 201 @@ -21,409 +21,926 @@ - - - - - - - F - - - - - - - - 0 - 0 - - - - - 32 - 16 - - - - - DejaVu Sans Mono - 12 - - - - PointingHandCursor - - - Qt::StrongFocus - - - Transverter delta frequency (Hz) - - - - - - - - 0 - 0 - - - - - 32 - 16 - - - - PointingHandCursor - - - Qt::StrongFocus - - - Marker frequency (Hz) - - - Hz - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 24 - 24 - - - - Set marker as reference (index 0) - - - C - - - - - - - - 16 - 16 - - - - - 16 - 16 - - - - Current marker color (click to change) - - - - - - - - - - - - - - - 24 - 0 - - - - Mk - - - - - - - - 15 - 0 - - - - 0 - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - 24 - 24 - - - - Marker index (0 is reference) - - - 0 - - - 1 - - - - - - - - 24 - 24 - - - - Set marker as reference (index 0) - - - 0 - - - - - - - 0 - - - - - - 18 - 18 - - - - - - - - - 255 - 255 - 255 - - - - - - - - - 255 - 255 - 255 - - - - - - - - - 190 - 190 - 190 - - - - - - - - - Liberation Sans - 10 - - - - Add a new Y trace - - - + - - - - - - - - 18 - 18 - - - - - - - - - 255 - 255 - 255 - - - - - - - - - 255 - 255 - 255 - - - - - - - - - 190 - 190 - 190 - - - - - - - - - Liberation Sans - 10 - - - - Remove current Y trace - - - - - - - - - - - - - - 15 - 0 - - - - P - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - 60 - 16777215 - - - - - Man - - - - - Pow - - - - - - - - - 24 - 24 - - - - Fixed power (dB) - - - -1500 - - - 1500 - - - 1 - - - - - - - - 32 - 0 - - - - -100.0 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - + + + 0 + + + + Hist + + + + + 0 + 10 + 361 + 74 + + + + + + + + + F + + + + + + + + 0 + 0 + + + + + 32 + 16 + + + + + DejaVu Sans Mono + 12 + + + + PointingHandCursor + + + Qt::StrongFocus + + + Marker frequency (Hz) + + + + + + + + 0 + 0 + + + + + 32 + 16 + + + + PointingHandCursor + + + Qt::StrongFocus + + + Marker frequency (Hz) + + + Hz + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 24 + 24 + + + + Set marker as reference (index 0) + + + C + + + + + + + + 16 + 16 + + + + + 16 + 16 + + + + Current marker color (click to change) + + + + + + + + + + + + + + + 24 + 0 + + + + Mk + + + + + + + + 15 + 0 + + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 24 + 24 + + + + Marker index (0 is reference) + + + 0 + + + 1 + + + + + + + + 24 + 24 + + + + Set marker as reference (index 0) + + + 0 + + + + + + + 0 + + + + + + 18 + 18 + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 190 + 190 + 190 + + + + + + + + + Liberation Sans + 10 + + + + Add a new marker + + + + + + + + + + + + 18 + 18 + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 190 + 190 + 190 + + + + + + + + + Liberation Sans + 10 + + + + Remove current marker + + + - + + + + + + + + + + 15 + 0 + + + + P + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 60 + 16777215 + + + + + Man + + + + + Pow + + + + + + + + Fixed power (dB) + + + -1500 + + + 1500 + + + 1 + + + Qt::Horizontal + + + + + + + + 32 + 0 + + + + -100.0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Wat + + + + + 0 + 10 + 361 + 93 + + + + + + + + + F + + + + + + + + 0 + 0 + + + + + 32 + 16 + + + + + DejaVu Sans Mono + 12 + + + + PointingHandCursor + + + Qt::StrongFocus + + + Marker frequency (Hz) + + + + + + + + 0 + 0 + + + + + 32 + 16 + + + + PointingHandCursor + + + Qt::StrongFocus + + + Marker frequency (Hz) + + + Hz + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 24 + 24 + + + + Set marker as reference (index 0) + + + C + + + + + + + + 16 + 16 + + + + + 16 + 16 + + + + Current marker color (click to change) + + + + + + + + + + + + + + + 24 + 0 + + + + Mk + + + + + + + + 15 + 0 + + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 24 + 24 + + + + Marker index (0 is reference) + + + 0 + + + 1 + + + + + + + + 24 + 24 + + + + Set marker as reference (index 0) + + + 0 + + + + + + + 0 + + + + + + 18 + 18 + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 190 + 190 + 190 + + + + + + + + + Liberation Sans + 10 + + + + Add a new marker + + + + + + + + + + + + 18 + 18 + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 255 + 255 + 255 + + + + + + + + + 190 + 190 + 190 + + + + + + + + + Liberation Sans + 10 + + + + Remove current marker + + + - + + + + + + + + + + 20 + 0 + + + + t(s) + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + 2 + + + + + + + + 36 + 0 + + + + Time mantissa + + + 0.000 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 16777215 + 14 + + + + Time mantissa (fine) + + + 0 + + + 1000 + + + 1 + + + Qt::Horizontal + + + + + + + + 24 + 24 + + + + Time mantissa (coarse) + + + 0 + + + 9 + + + 1 + + + 0 + + + + + + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 36 + 0 + + + + Time exponent + + + e+0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 16777215 + 14 + + + + Time exponent + + + -10 + + + 10 + + + 1 + + + Qt::Horizontal + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + +