From da5f8aa6f9cc5edd3e0efea5b2c18a61c0e53e8b Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 31 Oct 2017 00:07:55 +0100 Subject: [PATCH] Hack to try ChannelAnalyzer channel plugin handled via DeviceUISet --- .../channelrx/chanalyzer/chanalyzergui.cpp | 20 ++++++++++-------- plugins/channelrx/chanalyzer/chanalyzergui.h | 9 ++++---- .../channelrx/chanalyzer/chanalyzerplugin.cpp | 8 +++---- .../channelrx/chanalyzer/chanalyzerplugin.h | 6 +++--- sdrgui/device/deviceuiset.cpp | 13 ++++++++++-- sdrgui/mainwindow.cpp | 7 ++++++- sdrgui/plugin/plugininterface.h | 10 ++++++++- sdrgui/plugin/pluginmanager.cpp | 21 +++++++++++++++++++ sdrgui/plugin/pluginmanager.h | 2 ++ 9 files changed, 72 insertions(+), 24 deletions(-) diff --git a/plugins/channelrx/chanalyzer/chanalyzergui.cpp b/plugins/channelrx/chanalyzer/chanalyzergui.cpp index 35b299576..424295cf8 100644 --- a/plugins/channelrx/chanalyzer/chanalyzergui.cpp +++ b/plugins/channelrx/chanalyzer/chanalyzergui.cpp @@ -17,6 +17,7 @@ #include "chanalyzergui.h" #include +#include "device/deviceuiset.h" #include #include #include @@ -39,9 +40,9 @@ const QString ChannelAnalyzerGUI::m_channelID = "org.f4exb.sdrangelove.channel.chanalyzer"; -ChannelAnalyzerGUI* ChannelAnalyzerGUI::create(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI) +ChannelAnalyzerGUI* ChannelAnalyzerGUI::create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet) { - ChannelAnalyzerGUI* gui = new ChannelAnalyzerGUI(pluginAPI, deviceAPI); + ChannelAnalyzerGUI* gui = new ChannelAnalyzerGUI(pluginAPI, deviceUISet); return gui; } @@ -322,11 +323,12 @@ void ChannelAnalyzerGUI::onMenuDoubleClicked() } } -ChannelAnalyzerGUI::ChannelAnalyzerGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidget* parent) : +ChannelAnalyzerGUI::ChannelAnalyzerGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, QWidget* parent) : RollupWidget(parent), ui(new Ui::ChannelAnalyzerGUI), m_pluginAPI(pluginAPI), - m_deviceAPI(deviceAPI), +// m_deviceAPI(deviceAPI), + m_deviceUISet(deviceUISet), m_channelMarker(this), m_basicSettingsShown(false), m_doApplySettings(true), @@ -342,7 +344,7 @@ ChannelAnalyzerGUI::ChannelAnalyzerGUI(PluginAPI* pluginAPI, DeviceSourceAPI *de m_spectrumVis = new SpectrumVis(ui->glSpectrum); m_scopeVis = new ScopeVis(ui->glScope); m_spectrumScopeComboVis = new SpectrumScopeComboVis(m_spectrumVis, m_scopeVis); - m_channelAnalyzer = new ChannelAnalyzer(m_deviceAPI); + m_channelAnalyzer = new ChannelAnalyzer(m_deviceUISet->m_deviceSourceAPI); m_channelAnalyzer->setSampleSink(m_spectrumScopeComboVis); m_channelAnalyzer->setMessageQueueToGUI(getInputMessageQueue()); @@ -368,9 +370,9 @@ ChannelAnalyzerGUI::ChannelAnalyzerGUI(PluginAPI* pluginAPI, DeviceSourceAPI *de connect(&m_channelMarker, SIGNAL(changed()), this, SLOT(viewChanged())); - m_deviceAPI->registerChannelInstance(m_channelID, this); - m_deviceAPI->addChannelMarker(&m_channelMarker); - m_deviceAPI->addRollupWidget(this); + m_deviceUISet->registerChannelInstance(m_channelID, this); + m_deviceUISet->addChannelMarker(&m_channelMarker); + m_deviceUISet->addRollupWidget(this); ui->spectrumGUI->setBuddies(m_spectrumVis->getInputMessageQueue(), m_spectrumVis, ui->glSpectrum); ui->scopeGUI->setBuddies(m_scopeVis->getInputMessageQueue(), m_scopeVis, ui->glScope); @@ -383,7 +385,7 @@ ChannelAnalyzerGUI::ChannelAnalyzerGUI(PluginAPI* pluginAPI, DeviceSourceAPI *de ChannelAnalyzerGUI::~ChannelAnalyzerGUI() { - m_deviceAPI->removeChannelInstance(this); + m_deviceUISet->removeChannelInstance(this); delete m_channelAnalyzer; delete m_spectrumVis; delete m_scopeVis; diff --git a/plugins/channelrx/chanalyzer/chanalyzergui.h b/plugins/channelrx/chanalyzer/chanalyzergui.h index c13238f40..a56f91a2d 100644 --- a/plugins/channelrx/chanalyzer/chanalyzergui.h +++ b/plugins/channelrx/chanalyzer/chanalyzergui.h @@ -24,7 +24,7 @@ #include "util/messagequeue.h" class PluginAPI; -class DeviceSourceAPI; +class DeviceUISet; class ThreadedBasebandSampleSink; class DownChannelizer; @@ -41,7 +41,7 @@ class ChannelAnalyzerGUI : public RollupWidget, public PluginInstanceGUI { Q_OBJECT public: - static ChannelAnalyzerGUI* create(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI); + static ChannelAnalyzerGUI* create(PluginAPI* pluginAPI, DeviceUISet *deviceUIset); virtual void destroy(); void setName(const QString& name); @@ -73,7 +73,8 @@ private slots: private: Ui::ChannelAnalyzerGUI* ui; PluginAPI* m_pluginAPI; - DeviceSourceAPI* m_deviceAPI; +// DeviceSourceAPI* m_deviceAPI; + DeviceUISet* m_deviceUISet; ChannelMarker m_channelMarker; bool m_basicSettingsShown; bool m_doApplySettings; @@ -89,7 +90,7 @@ private: ScopeVis* m_scopeVis; MessageQueue m_inputMessageQueue; - explicit ChannelAnalyzerGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidget* parent = NULL); + explicit ChannelAnalyzerGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, QWidget* parent = 0); virtual ~ChannelAnalyzerGUI(); int getEffectiveLowCutoff(int lowCutoff); diff --git a/plugins/channelrx/chanalyzer/chanalyzerplugin.cpp b/plugins/channelrx/chanalyzer/chanalyzerplugin.cpp index 428ccd78c..5c8d6c175 100644 --- a/plugins/channelrx/chanalyzer/chanalyzerplugin.cpp +++ b/plugins/channelrx/chanalyzer/chanalyzerplugin.cpp @@ -33,18 +33,18 @@ void ChannelAnalyzerPlugin::initPlugin(PluginAPI* pluginAPI) m_pluginAPI->registerRxChannel(ChannelAnalyzerGUI::m_channelID, this); } -PluginInstanceGUI* ChannelAnalyzerPlugin::createRxChannel(const QString& channelName, DeviceSourceAPI *deviceAPI) +PluginInstanceGUI* ChannelAnalyzerPlugin::createRxChannel(const QString& channelName, DeviceUISet *deviceUISet) { if(channelName == ChannelAnalyzerGUI::m_channelID) { - ChannelAnalyzerGUI* gui = ChannelAnalyzerGUI::create(m_pluginAPI, deviceAPI); + ChannelAnalyzerGUI* gui = ChannelAnalyzerGUI::create(m_pluginAPI, deviceUISet); return gui; } else { return NULL; } } -void ChannelAnalyzerPlugin::createInstanceChannelAnalyzer(DeviceSourceAPI *deviceAPI) +void ChannelAnalyzerPlugin::createInstanceChannelAnalyzer(DeviceUISet *deviceUISet) { - ChannelAnalyzerGUI::create(m_pluginAPI, deviceAPI); + ChannelAnalyzerGUI::create(m_pluginAPI, deviceUISet); } diff --git a/plugins/channelrx/chanalyzer/chanalyzerplugin.h b/plugins/channelrx/chanalyzer/chanalyzerplugin.h index aa42c8edb..eaa7530f9 100644 --- a/plugins/channelrx/chanalyzer/chanalyzerplugin.h +++ b/plugins/channelrx/chanalyzer/chanalyzerplugin.h @@ -4,7 +4,7 @@ #include #include "plugin/plugininterface.h" -class DeviceSourceAPI; +class DeviceUISet; class ChannelAnalyzerPlugin : public QObject, PluginInterface { Q_OBJECT @@ -17,7 +17,7 @@ public: const PluginDescriptor& getPluginDescriptor() const; void initPlugin(PluginAPI* pluginAPI); - PluginInstanceGUI* createRxChannel(const QString& channelName, DeviceSourceAPI *deviceAPI); + PluginInstanceGUI* createRxChannel(const QString& channelName, DeviceUISet *deviceUISet); private: static const PluginDescriptor m_pluginDescriptor; @@ -25,7 +25,7 @@ private: PluginAPI* m_pluginAPI; private slots: - void createInstanceChannelAnalyzer(DeviceSourceAPI *deviceAPI); + void createInstanceChannelAnalyzer(DeviceUISet *deviceUISet); }; #endif // INCLUDE_CHANALYZERPLUGIN_H diff --git a/sdrgui/device/deviceuiset.cpp b/sdrgui/device/deviceuiset.cpp index 4998a3387..3a53f4909 100644 --- a/sdrgui/device/deviceuiset.cpp +++ b/sdrgui/device/deviceuiset.cpp @@ -63,6 +63,16 @@ DeviceUISet::~DeviceUISet() delete m_spectrum; } +void DeviceUISet::addChannelMarker(ChannelMarker* channelMarker) +{ + m_spectrum->addChannelMarker(channelMarker); +} + +void DeviceUISet::addRollupWidget(QWidget *widget) +{ + m_channelWindow->addRollupWidget(widget); +} + void DeviceUISet::registerChannelInstance(const QString& channelName, PluginInstanceGUI* pluginGUI) { m_channelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, pluginGUI)); @@ -136,11 +146,10 @@ void DeviceUISet::loadChannelSettings(const Preset *preset, PluginAPI *pluginAPI if((*channelRegistrations)[i].m_channelName == channelConfig.m_channel) { qDebug("DeviceUISet::loadChannelSettings: creating new channel [%s]", qPrintable(channelConfig.m_channel)); - // TOOO: replace m_deviceSourceAPI by this reg = ChannelInstanceRegistration( channelConfig.m_channel, (*channelRegistrations)[i]. - m_plugin->createRxChannel(channelConfig.m_channel, m_deviceSourceAPI) + m_plugin->createRxChannel(channelConfig.m_channel, this) ); break; } diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index ac62be906..a3d52d2e5 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -1024,7 +1024,12 @@ void MainWindow::on_channel_addClicked(bool checked __attribute__((unused))) if (deviceUI->m_deviceSourceEngine) // source device => Rx channels { - m_pluginManager->createRxChannelInstance(deviceUI->m_samplingDeviceControl->getChannelSelector()->currentIndex(), deviceUI->m_deviceSourceAPI); + qDebug("MainWindow::on_channel_addClicked: channel name: %s", qPrintable(m_pluginManager->getRxChannelInstanceName(deviceUI->m_samplingDeviceControl->getChannelSelector()->currentIndex()))); + if (m_pluginManager->getRxChannelInstanceName(deviceUI->m_samplingDeviceControl->getChannelSelector()->currentIndex()) == "org.f4exb.sdrangelove.channel.chanalyzer") { + m_pluginManager->createRxChannelInstance(deviceUI->m_samplingDeviceControl->getChannelSelector()->currentIndex(), deviceUI); + } else { + m_pluginManager->createRxChannelInstance(deviceUI->m_samplingDeviceControl->getChannelSelector()->currentIndex(), deviceUI->m_deviceSourceAPI); + } } else if (deviceUI->m_deviceSinkEngine) // sink device => Tx channels { diff --git a/sdrgui/plugin/plugininterface.h b/sdrgui/plugin/plugininterface.h index 584fc80f2..8abb4dd58 100644 --- a/sdrgui/plugin/plugininterface.h +++ b/sdrgui/plugin/plugininterface.h @@ -54,7 +54,15 @@ public: // channel Rx plugins - virtual PluginInstanceGUI* createRxChannel(const QString& channelName __attribute__((unused)), DeviceSourceAPI *deviceAPI __attribute__((unused)) ) { return 0; } + // TODO: remove this one when migration is complete + virtual PluginInstanceGUI* createRxChannel( + const QString& channelName __attribute__((unused)), + DeviceSourceAPI *deviceAPI __attribute__((unused)) ) + { return 0; } + virtual PluginInstanceGUI* createRxChannel( + const QString& channelName __attribute__((unused)), + DeviceUISet *deviceAPI __attribute__((unused)) ) + { return 0; } // channel Tx plugins diff --git a/sdrgui/plugin/pluginmanager.cpp b/sdrgui/plugin/pluginmanager.cpp index 1f1836dcf..fa37b408a 100644 --- a/sdrgui/plugin/pluginmanager.cpp +++ b/sdrgui/plugin/pluginmanager.cpp @@ -627,6 +627,27 @@ void PluginManager::createRxChannelInstance(int channelPluginIndex, DeviceSource } } +void PluginManager::createRxChannelInstance(int channelPluginIndex, DeviceUISet *deviceUISet) +{ + if (channelPluginIndex < m_rxChannelRegistrations.size()) + { + PluginInterface *pluginInterface = m_rxChannelRegistrations[channelPluginIndex].m_plugin; + pluginInterface->createRxChannel(m_rxChannelRegistrations[channelPluginIndex].m_channelName, deviceUISet); + } +} + +QString PluginManager::getRxChannelInstanceName(int channelPluginIndex) +{ + if (channelPluginIndex < m_rxChannelRegistrations.size()) + { + return m_rxChannelRegistrations[channelPluginIndex].m_channelName; + } + else + { + return ""; + } +} + void PluginManager::createTxChannelInstance(int channelPluginIndex, DeviceSinkAPI *deviceAPI) { if (channelPluginIndex < m_txChannelRegistrations.size()) diff --git a/sdrgui/plugin/pluginmanager.h b/sdrgui/plugin/pluginmanager.h index 801468cc8..13425a676 100644 --- a/sdrgui/plugin/pluginmanager.h +++ b/sdrgui/plugin/pluginmanager.h @@ -72,6 +72,8 @@ public: void populateRxChannelComboBox(QComboBox *channels); void createRxChannelInstance(int channelPluginIndex, DeviceSourceAPI *deviceAPI); + void createRxChannelInstance(int channelPluginIndex, DeviceUISet *deviceUISet); + QString getRxChannelInstanceName(int channelPluginIndex); void populateTxChannelComboBox(QComboBox *channels); void createTxChannelInstance(int channelPluginIndex, DeviceSinkAPI *deviceAPI);