From 8477641bec8c95053eee9f7663839796133cae4e Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 12 Mar 2022 05:45:24 +0100 Subject: [PATCH] MainCore: signals to notify changes in devices channels and features. Part of #1139 --- sdrbase/maincore.cpp | 43 +++++++++++++++++++++++++++++++++++++++---- sdrbase/maincore.h | 17 ++++++++++++++++- sdrgui/mainwindow.cpp | 2 ++ sdrsrv/mainserver.cpp | 3 +++ 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/sdrbase/maincore.cpp b/sdrbase/maincore.cpp index efe6b4f54..96eb24b89 100644 --- a/sdrbase/maincore.cpp +++ b/sdrbase/maincore.cpp @@ -122,6 +122,20 @@ void MainCore::setLoggingOptions() } } +DeviceAPI *MainCore::getDevice(unsigned int deviceSetIndex) +{ + if (deviceSetIndex < m_deviceSets.size()) { + return m_deviceSets[deviceSetIndex]->m_deviceAPI; + } else { + return nullptr; + } +} + +void MainCore::sendDeviceChanged(int deviceSetIndex) +{ + emit deviceChanged(deviceSetIndex); +} + ChannelAPI *MainCore::getChannel(unsigned int deviceSetIndex, int channelIndex) { if (deviceSetIndex < m_deviceSets.size()) { @@ -146,6 +160,7 @@ void MainCore::appendFeatureSet() FeatureSet *featureSet = new FeatureSet(newIndex); m_featureSets.push_back(featureSet); m_featureSetsMap.insert(featureSet, newIndex); + emit featureSetAdded(newIndex); } void MainCore::removeFeatureSet(unsigned int index) @@ -155,6 +170,7 @@ void MainCore::removeFeatureSet(unsigned int index) FeatureSet *featureSet = m_featureSets[index]; m_featureSetsMap.remove(featureSet); m_featureSets.erase(m_featureSets.begin() + index); + emit featureSetRemoved(index); } } @@ -162,9 +178,11 @@ void MainCore::removeLastFeatureSet() { if (m_featureSets.size() != 0) { + int size = m_featureSets.size(); FeatureSet *featureSet = m_featureSets.back(); m_featureSetsMap.remove(featureSet); m_featureSets.pop_back(); + emit featureSetRemoved(size - 1); } } @@ -174,21 +192,25 @@ void MainCore::appendDeviceSet(int deviceType) DeviceSet *deviceSet = new DeviceSet(newIndex, deviceType); m_deviceSets.push_back(deviceSet); m_deviceSetsMap.insert(deviceSet, newIndex); + emit deviceSetAdded(newIndex, deviceSet->m_deviceAPI); } void MainCore::removeLastDeviceSet() { if (m_deviceSets.size() != 0) { + int size = m_deviceSets.size(); DeviceSet *deviceSet = m_deviceSets.back(); m_deviceSetsMap.remove(deviceSet); m_deviceSets.pop_back(); + emit deviceSetRemoved(size - 1); } } void MainCore::addChannelInstance(DeviceSet *deviceSet, ChannelAPI *channelAPI) { m_channelsMap.insert(channelAPI, deviceSet); + emit channelAdded(m_deviceSetsMap[deviceSet], channelAPI); // debugMaps(); } @@ -197,15 +219,20 @@ void MainCore::removeChannelInstanceAt(DeviceSet *deviceSet, int channelIndex) int deviceSetIndex = m_deviceSetsMap[deviceSet]; ChannelAPI *channelAPI = m_deviceSets[deviceSetIndex]->getChannelAt(channelIndex); - if (channelAPI) { + if (channelAPI) + { m_channelsMap.remove(channelAPI); + emit channelRemoved(deviceSetIndex, channelAPI); } } void MainCore::removeChannelInstance(ChannelAPI *channelAPI) { - if (channelAPI) { + if (channelAPI) + { + int deviceSetIndex = m_deviceSetsMap[m_channelsMap[channelAPI]]; m_channelsMap.remove(channelAPI); + emit channelRemoved(deviceSetIndex, channelAPI); } } @@ -215,12 +242,14 @@ void MainCore::clearChannels(DeviceSet *deviceSet) { ChannelAPI *channelAPI = deviceSet->getChannelAt(i); m_channelsMap.remove(channelAPI); + emit channelRemoved(m_deviceSetsMap[deviceSet], channelAPI); } } void MainCore::addFeatureInstance(FeatureSet *featureSet, Feature *feature) { m_featuresMap.insert(feature, featureSet); + emit featureAdded(m_featureSetsMap[featureSet], feature); // debugMaps(); } @@ -229,15 +258,20 @@ void MainCore::removeFeatureInstanceAt(FeatureSet *featureSet, int featureIndex) int featureSetIndex = m_featureSetsMap[featureSet]; Feature *feature = m_featureSets[featureSetIndex]->getFeatureAt(featureIndex); - if (feature) { + if (feature) + { m_featuresMap.remove(feature); + emit featureRemoved(featureSetIndex, feature); } } void MainCore::removeFeatureInstance(Feature *feature) { - if (feature) { + if (feature) + { + int featureSetIndex = m_featureSetsMap[m_featuresMap[feature]]; m_featuresMap.remove(feature); + emit featureRemoved(featureSetIndex, feature); } } @@ -247,6 +281,7 @@ void MainCore::clearFeatures(FeatureSet *featureSet) { Feature *feature = featureSet->getFeatureAt(i); m_featuresMap.remove(feature); + emit featureRemoved(m_featureSetsMap[featureSet], feature); } } diff --git a/sdrbase/maincore.h b/sdrbase/maincore.h index 5f13f85c3..b3e1cfdf0 100644 --- a/sdrbase/maincore.h +++ b/sdrbase/maincore.h @@ -23,6 +23,7 @@ #include #include #include +#include #include "export.h" #include "settings/mainsettings.h" @@ -53,8 +54,9 @@ namespace SWGSDRangel class SWGStarTrackerDisplayLoSSettings; } -class SDRBASE_API MainCore +class SDRBASE_API MainCore : public QObject { + Q_OBJECT public: class SDRBASE_API MsgDeviceSetFocus : public Message { MESSAGE_CLASS_DECLARATION @@ -710,6 +712,8 @@ public: std::vector& getDeviceSets() { return m_deviceSets; } std::vector& getFeatureeSets() { return m_featureSets; } void setLoggingOptions(); + DeviceAPI *getDevice(unsigned int deviceSetIndex); + void sendDeviceChanged(int deviceSetIndex); ChannelAPI *getChannel(unsigned int deviceSetIndex, int channelIndex); Feature *getFeature(unsigned int featureSetIndex, int featureIndex); bool existsChannel(const ChannelAPI *channel) const { return m_channelsMap.contains(const_cast(channel)); } @@ -739,6 +743,17 @@ public: friend class MainWindow; friend class WebAPIAdapter; +signals: + void deviceSetAdded(int index, DeviceAPI *device); + void deviceChanged(int index); + void deviceSetRemoved(int index); + void channelAdded(int deviceSetIndex, ChannelAPI *channel); + void channelRemoved(int deviceSetIndex, ChannelAPI *oldChannel); + void featureSetAdded(int index); + void featureSetRemoved(int index); + void featureAdded(int featureSetIndex, Feature *feature); + void featureRemoved(int featureSetIndex, Feature *oldFeature); + private: MainSettings m_settings; qtwebapp::LoggerWithFile *m_logger; diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index e15235382..4517a2b55 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -1963,6 +1963,8 @@ void MainWindow::samplingDeviceChanged(int deviceType, int tabIndex, int newDevi } else if (deviceType == 2) { sampleMIMOChanged(tabIndex, newDeviceIndex); } + + MainCore::instance()->sendDeviceChanged(tabIndex); } void MainWindow::sampleSourceChanged(int tabIndex, int newDeviceIndex) diff --git a/sdrsrv/mainserver.cpp b/sdrsrv/mainserver.cpp index 023b8994d..3da57fb5d 100644 --- a/sdrsrv/mainserver.cpp +++ b/sdrsrv/mainserver.cpp @@ -529,6 +529,9 @@ void MainServer::changeSampleSource(int deviceSetIndex, int selectedDeviceIndex) deviceSet->m_deviceAPI->setSampleSource(source); deviceSet->m_deviceAPI->loadSamplingDeviceSettings(m_mainCore->m_settings.getWorkingPreset()); // load new API settings + + // Notify + m_mainCore->sendDeviceChanged(deviceSetIndex); } }