From 1a92a23d2e7b7dffa2524449a102bf7bfaf79150 Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Sat, 30 May 2020 16:55:18 -0400 Subject: [PATCH] Add maximum filter spinbox, menu item in waterfall, and proper controls for handling editing --- widegraph.cpp | 55 +++++++++++++++++++++++++++++++++++++++------------ widegraph.h | 28 ++++++++++++++++++++++++++ widegraph.ui | 42 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 110 insertions(+), 15 deletions(-) diff --git a/widegraph.cpp b/widegraph.cpp index dbd982d..36f0e8b 100644 --- a/widegraph.cpp +++ b/widegraph.cpp @@ -46,6 +46,13 @@ WideGraph::WideGraph(QSettings * settings, QWidget *parent) : ui->splitter->setCollapsible(ui->splitter->indexOf(ui->controls_widget), false); ui->splitter->updateGeometry(); + auto focusEater = new FocusEater(this); + connect(focusEater, &FocusEater::blurred, this, [this](QObject * /*obj*/){ + setFilter(filterMinimum(), filterMaximum()); + }); + ui->filterMinSpinBox->installEventFilter(focusEater); + ui->filterMaxSpinBox->installEventFilter(focusEater); + auto filterEscapeEater = new KeyPressEater(); connect(filterEscapeEater, &KeyPressEater::keyPressed, this, [this](QObject */*obj*/, QKeyEvent *e, bool *pProcessed){ if(e->key() != Qt::Key_Escape){ @@ -55,6 +62,7 @@ WideGraph::WideGraph(QSettings * settings, QWidget *parent) : if(pProcessed) *pProcessed=true; }); ui->filterMinSpinBox->installEventFilter(filterEscapeEater); + ui->filterMaxSpinBox->installEventFilter(filterEscapeEater); ui->widePlot->setCursor(Qt::CrossCursor); ui->widePlot->setMaximumWidth(MAX_SCREENSIZE); @@ -104,6 +112,12 @@ WideGraph::WideGraph(QSettings * settings, QWidget *parent) : ui->filterCheckBox->setChecked(true); }); + auto maxAction = menu->addAction(QString("Set Filter Ma&ximum to %1 Hz").arg(f)); + connect(maxAction, &QAction::triggered, this, [this, f](){ + ui->filterMaxSpinBox->setValue(f); + ui->filterCheckBox->setChecked(true); + }); + menu->popup(ui->widePlot->mapToGlobal(pos)); }); @@ -117,6 +131,7 @@ WideGraph::WideGraph(QSettings * settings, QWidget *parent) : emit qsy(hzDelta); }); + { //Restore user's settings @@ -563,13 +578,13 @@ int WideGraph::Fmax() //Fmax } int WideGraph::filterMinimum() -{ - return std::max(0, m_filterMinimum); +{ + return std::max(0, std::min(m_filterMinimum, m_filterMaximum)); } int WideGraph::filterMaximum() { - return std::min(m_filterMaximum, 5000); + return std::min(std::max(m_filterMinimum, m_filterMaximum), 5000); } bool WideGraph::filterEnabled() @@ -579,7 +594,7 @@ bool WideGraph::filterEnabled() void WideGraph::setFilterCenter(int n){ int delta = n - m_filterCenter; - setFilter(m_filterMinimum + delta, m_filterMaximum + delta); + setFilter(filterMinimum() + delta, filterMaximum() + delta); } void WideGraph::setFilter(int a, int b){ @@ -587,26 +602,32 @@ void WideGraph::setFilter(int a, int b){ int high = std::max(a, b); // ensure minimum filter width - if(high-low < m_filterMinWidth){ - high = low + m_filterMinWidth; - } + // if(high-low < m_filterMinWidth){ + // high = low + m_filterMinWidth; + // } int width = high - low; int center = low + width / 2; // update the filter history - m_filterMinimum = low; - m_filterMaximum = high; + m_filterMinimum = a; + m_filterMaximum = b; m_filterCenter = center; // update the spinner UI bool blocked = false; blocked = ui->filterMinSpinBox->blockSignals(true); { - ui->filterMinSpinBox->setValue(low); + ui->filterMinSpinBox->setValue(a); } ui->filterMinSpinBox->blockSignals(blocked); + blocked = ui->filterMaxSpinBox->blockSignals(true); + { + ui->filterMaxSpinBox->setValue(b); + } + ui->filterMaxSpinBox->blockSignals(blocked); + blocked = ui->filterCenterSpinBox->blockSignals(true); { ui->filterCenterSpinBox->setValue(center); @@ -627,7 +648,11 @@ void WideGraph::setFilter(int a, int b){ void WideGraph::setFilterMinimumBandwidth(int width){ m_filterMinWidth = width; ui->filterWidthSpinBox->setMinimum(width); - setFilter(m_filterMinimum, std::max(m_filterMinimum+width, m_filterMaximum)); + + int low = filterMinimum(); + int high = filterMaximum(); + + setFilter(low, std::max(low + width, high)); } void WideGraph::setFilterEnabled(bool enabled){ @@ -638,6 +663,7 @@ void WideGraph::setFilterEnabled(bool enabled){ ui->filterCenterSyncButton->setEnabled(enabled); ui->filterWidthSpinBox->setEnabled(enabled); ui->filterMinSpinBox->setEnabled(enabled); + ui->filterMaxSpinBox->setEnabled(enabled); // update the checkbox ui bool blocked = ui->filterCheckBox->blockSignals(true); @@ -928,8 +954,11 @@ void WideGraph::on_sbPercent2dPlot_valueChanged(int n) } void WideGraph::on_filterMinSpinBox_valueChanged(int n){ - int delta = n - m_filterMinimum; - setFilter(m_filterMinimum + delta, m_filterMaximum + delta); + setFilter(n, m_filterMaximum); +} + +void WideGraph::on_filterMaxSpinBox_valueChanged(int n){ + setFilter(m_filterMinimum, n); } void WideGraph::on_filterCenterSpinBox_valueChanged(int n){ diff --git a/widegraph.h b/widegraph.h index 5dd823d..81adb00 100644 --- a/widegraph.h +++ b/widegraph.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -26,6 +27,32 @@ namespace Ui { class QSettings; class Configuration; +class FocusEater : public QObject +{ + Q_OBJECT +public: + explicit FocusEater(QObject* parent = nullptr) : QObject(parent) + { + } + + virtual bool eventFilter(QObject *obj, QEvent *event) override + { + Q_UNUSED(obj) + if (event->type() == QEvent::FocusIn){ + emit focused(obj); + } + else if (event->type() == QEvent::FocusOut){ + emit blurred(obj); + } + + return false; + } + +signals: + void focused(QObject *obj); + void blurred(QObject *obj); +}; + class WideGraph : public QDialog { Q_OBJECT @@ -121,6 +148,7 @@ private slots: void on_smoSpinBox_valueChanged(int n); void on_sbPercent2dPlot_valueChanged(int n); void on_filterMinSpinBox_valueChanged(int n); + void on_filterMaxSpinBox_valueChanged(int n); void on_filterCenterSpinBox_valueChanged(int n); void on_filterWidthSpinBox_valueChanged(int n); void on_filterCenterSyncButton_clicked(); diff --git a/widegraph.ui b/widegraph.ui index 0b4d2f5..21cc10d 100644 --- a/widegraph.ui +++ b/widegraph.ui @@ -285,6 +285,9 @@ false + + <html><head/><body><p>Set the software filter center in Hz. This filter prevents signals outside the filter range from being processed by the decoder.</p></body></html> + 2 @@ -337,6 +340,9 @@ Hz + + <html><head/><body><p>Set the software filter width in Hz. This filter prevents signals outside the filter range from being processed by the decoder.</p></body></html> + Width: @@ -354,7 +360,7 @@ false - <html><head/><body><p>Set the software filter width in Hz. This filter prevents signals outside the filter range from being processed by the decoder.</p></body></html> + <html><head/><body><p>Set the software filter minimum in Hz. This filter prevents signals outside the filter range from being processed by the decoder.</p></body></html> QAbstractSpinBox::PlusMinus @@ -379,7 +385,39 @@ - + + + + false + + + <html><head/><body><p>Set the software filter maximum in Hz. This filter prevents signals outside the filter range from being processed by the decoder.</p></body></html> + + + QAbstractSpinBox::PlusMinus + + + + + + Hz + + + Max: + + + 5000 + + + 1 + + + 500 + + + + +