diff --git a/plugins/samplesource/soapysdrinput/CMakeLists.txt b/plugins/samplesource/soapysdrinput/CMakeLists.txt index 70e4553c9..e63f1525b 100644 --- a/plugins/samplesource/soapysdrinput/CMakeLists.txt +++ b/plugins/samplesource/soapysdrinput/CMakeLists.txt @@ -8,6 +8,7 @@ set(soapysdrinput_SOURCES soapysdrinputplugin.cpp soapysdrinputsettings.cpp soapysdrinputthread.cpp + itemsettinggui.cpp discreterangegui.cpp intervalrangegui.cpp ) @@ -18,6 +19,7 @@ set(soapysdrinput_HEADERS soapysdrinputplugin.h soapysdrinputsettings.h soapysdrinputthread.h + itemsettinggui.h discreterangegui.h intervalrangegui.h ) diff --git a/plugins/samplesource/soapysdrinput/discreterangegui.cpp b/plugins/samplesource/soapysdrinput/discreterangegui.cpp index 654b3aea0..8a74bdd0a 100644 --- a/plugins/samplesource/soapysdrinput/discreterangegui.cpp +++ b/plugins/samplesource/soapysdrinput/discreterangegui.cpp @@ -18,7 +18,7 @@ #include "discreterangegui.h" DiscreteRangeGUI::DiscreteRangeGUI(QWidget* parent) : - QWidget(parent), + ItemSettingGUI(parent), ui(new Ui::DiscreteRangeGUI) { ui->setupUi(this); @@ -52,8 +52,26 @@ double DiscreteRangeGUI::getCurrentValue() return itemValues[ui->rangeCombo->currentIndex()]; } +void DiscreteRangeGUI::setValue(double value) +{ + int index = 0; + + for (const auto &it : itemValues) + { + if (it >= value) + { + ui->rangeCombo->blockSignals(true); + ui->rangeCombo->setCurrentIndex(index); + ui->rangeCombo->blockSignals(false); + break; + } + + index++; + } +} + void DiscreteRangeGUI::on_rangeCombo_currentIndexChanged(int index) { double newRange = itemValues[index]; - emit rangeChanged(newRange); + emit ItemSettingGUI::valueChanged(newRange); } diff --git a/plugins/samplesource/soapysdrinput/discreterangegui.h b/plugins/samplesource/soapysdrinput/discreterangegui.h index 291d195d4..76d5e42a1 100644 --- a/plugins/samplesource/soapysdrinput/discreterangegui.h +++ b/plugins/samplesource/soapysdrinput/discreterangegui.h @@ -20,24 +20,24 @@ #include #include +#include "itemsettinggui.h" + namespace Ui { class DiscreteRangeGUI; } -class DiscreteRangeGUI : public QWidget +class DiscreteRangeGUI : public ItemSettingGUI { Q_OBJECT public: explicit DiscreteRangeGUI(QWidget* parent = 0); - ~DiscreteRangeGUI(); + virtual ~DiscreteRangeGUI(); void setLabel(const QString& text); void setUnits(const QString& units); void addItem(const QString& itemStr, double itemValue); - double getCurrentValue(); - -signals: - void rangeChanged(double value); + virtual double getCurrentValue(); + virtual void setValue(double value); private slots: void on_rangeCombo_currentIndexChanged(int index); diff --git a/plugins/samplesource/soapysdrinput/intervalrangegui.cpp b/plugins/samplesource/soapysdrinput/intervalrangegui.cpp index 9e31b85ea..10a3df81e 100644 --- a/plugins/samplesource/soapysdrinput/intervalrangegui.cpp +++ b/plugins/samplesource/soapysdrinput/intervalrangegui.cpp @@ -20,7 +20,7 @@ #include "intervalrangegui.h" IntervalRangeGUI::IntervalRangeGUI(QWidget* parent) : - QWidget(parent), + ItemSettingGUI(parent), ui(new Ui::IntervalRangeGUI), m_nbDigits(7) { @@ -83,9 +83,14 @@ double IntervalRangeGUI::getCurrentValue() return ui->value->getValue(); } +void IntervalRangeGUI::setValue(double value) +{ + ui->value->setValue(value); +} + void IntervalRangeGUI::on_value_changed(quint64 value) { - emit valueChanged(value); + emit ItemSettingGUI::valueChanged(value); } void IntervalRangeGUI::on_rangeInterval_currentIndexChanged(int index) diff --git a/plugins/samplesource/soapysdrinput/intervalrangegui.h b/plugins/samplesource/soapysdrinput/intervalrangegui.h index f858b7b1a..999452124 100644 --- a/plugins/samplesource/soapysdrinput/intervalrangegui.h +++ b/plugins/samplesource/soapysdrinput/intervalrangegui.h @@ -21,25 +21,25 @@ #include #include +#include "itemsettinggui.h" + namespace Ui { class IntervalRangeGUI; } -class IntervalRangeGUI : public QWidget +class IntervalRangeGUI : public ItemSettingGUI { Q_OBJECT public: explicit IntervalRangeGUI(QWidget* parent = 0); - ~IntervalRangeGUI(); + virtual ~IntervalRangeGUI(); void setLabel(const QString& text); void setUnits(const QString& units); void addInterval(double minimum, double maximum); void reset(); - double getCurrentValue(); - -signals: - void valueChanged(double value); + virtual double getCurrentValue(); + virtual void setValue(double value); private slots: void on_value_changed(quint64 value); diff --git a/plugins/samplesource/soapysdrinput/itemsettinggui.cpp b/plugins/samplesource/soapysdrinput/itemsettinggui.cpp new file mode 100644 index 000000000..a85dedc37 --- /dev/null +++ b/plugins/samplesource/soapysdrinput/itemsettinggui.cpp @@ -0,0 +1,11 @@ +/* + * itemsettinggui.cpp + * + * Created on: Nov 1, 2018 + * Author: f4exb + */ + +#include "itemsettinggui.h" + +ItemSettingGUI::ItemSettingGUI(QWidget *parent) : QWidget(parent) {} + diff --git a/plugins/samplesource/soapysdrinput/itemsettinggui.h b/plugins/samplesource/soapysdrinput/itemsettinggui.h new file mode 100644 index 000000000..e84621cd3 --- /dev/null +++ b/plugins/samplesource/soapysdrinput/itemsettinggui.h @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2018 Edouard Griffiths, F4EXB // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +// This is an interface to an elementary GUI item used to get/set setting from the GUI + +#ifndef PLUGINS_SAMPLESOURCE_SOAPYSDRINPUT_ITEMSETTINGGUI_H_ +#define PLUGINS_SAMPLESOURCE_SOAPYSDRINPUT_ITEMSETTINGGUI_H_ + +#include + +class ItemSettingGUI : public QWidget +{ + Q_OBJECT +public: + explicit ItemSettingGUI(QWidget *parent = 0); + virtual ~ItemSettingGUI() {} + virtual double getCurrentValue() = 0; + virtual void setValue(double value) = 0; + +signals: + void valueChanged(double value); +}; + + + +#endif /* PLUGINS_SAMPLESOURCE_SOAPYSDRINPUT_ITEMSETTINGGUI_H_ */ diff --git a/plugins/samplesource/soapysdrinput/soapysdrinputgui.cpp b/plugins/samplesource/soapysdrinput/soapysdrinputgui.cpp index ae218754e..1cc18b2b7 100644 --- a/plugins/samplesource/soapysdrinput/soapysdrinputgui.cpp +++ b/plugins/samplesource/soapysdrinput/soapysdrinputgui.cpp @@ -34,7 +34,8 @@ SoapySDRInputGui::SoapySDRInputGui(DeviceUISet *deviceUISet, QWidget* parent) : m_sampleSource(0), m_sampleRate(0), m_deviceCenterFrequency(0), - m_lastEngineState(DSPDeviceSourceEngine::StNotStarted) + m_lastEngineState(DSPDeviceSourceEngine::StNotStarted), + m_sampleRateGUI(0) { m_sampleSource = (SoapySDRInput*) m_deviceUISet->m_deviceSourceAPI->getSampleSource(); ui->setupUi(this); @@ -85,6 +86,8 @@ void SoapySDRInputGui::createRangesControl(const SoapySDR::RangeList& rangeList, rangeGUI->addItem(QString("%1").arg(QString::number(it.minimum()/1000.0, 'f', 0)), it.minimum()); } + m_sampleRateGUI = rangeGUI; + connect(m_sampleRateGUI, SIGNAL(valueChanged(double)), this, SLOT(sampleRateChanged(double))); // QHBoxLayout *layout = new QHBoxLayout(); // QLabel *rangeLabel = new QLabel(); // rangeLabel->setText(text); @@ -121,6 +124,9 @@ void SoapySDRInputGui::createRangesControl(const SoapySDR::RangeList& rangeList, } rangeGUI->reset(); + + m_sampleRateGUI = rangeGUI; + connect(m_sampleRateGUI, SIGNAL(valueChanged(double)), this, SLOT(sampleRateChanged(double))); } } @@ -164,4 +170,7 @@ bool SoapySDRInputGui::handleMessage(const Message& message __attribute__((unuse return false; } - +void SoapySDRInputGui::sampleRateChanged(double sampleRate) +{ + qDebug("SoapySDRInputGui::sampleRateChanged: %lf", sampleRate); +} diff --git a/plugins/samplesource/soapysdrinput/soapysdrinputgui.h b/plugins/samplesource/soapysdrinput/soapysdrinputgui.h index 0210c5c49..7517e610d 100644 --- a/plugins/samplesource/soapysdrinput/soapysdrinputgui.h +++ b/plugins/samplesource/soapysdrinput/soapysdrinputgui.h @@ -28,6 +28,7 @@ #include "soapysdrinput.h" class DeviceUISet; +class ItemSettingGUI; namespace Ui { class SoapySDRInputGui; @@ -66,6 +67,11 @@ private: quint64 m_deviceCenterFrequency; //!< Center frequency in device int m_lastEngineState; MessageQueue m_inputMessageQueue; + + ItemSettingGUI *m_sampleRateGUI; + +private slots: + void sampleRateChanged(double sampleRate); };