diff --git a/sdrbase/feature/featureset.cpp b/sdrbase/feature/featureset.cpp index 499e9e70a..e009df34e 100644 --- a/sdrbase/feature/featureset.cpp +++ b/sdrbase/feature/featureset.cpp @@ -174,3 +174,21 @@ void FeatureSet::saveFeatureSetSettings(FeatureSetPreset *preset) preset->addFeature(m_featureInstanceRegistrations[i].m_featureName, m_featureInstanceRegistrations[i].m_feature->serialize()); } } + +void FeatureSet::addFeatureInstance(const QString& featureURI, Feature *feature) +{ + qDebug("FeatureSet::addFeatureInstance"); + m_featureInstanceRegistrations.push_back(FeatureInstanceRegistration(featureURI, feature)); +} + +void FeatureSet::removeFeatureInstanceAt(int index) +{ + if (index < m_featureInstanceRegistrations.size()) { + m_featureInstanceRegistrations.removeAt(index); + } +} + +void FeatureSet::clearFeatures() +{ + m_featureInstanceRegistrations.clear(); +} diff --git a/sdrbase/feature/featureset.h b/sdrbase/feature/featureset.h index aa4d04e16..ad9390301 100644 --- a/sdrbase/feature/featureset.h +++ b/sdrbase/feature/featureset.h @@ -43,6 +43,10 @@ public: Feature *getFeatureAt(int featureIndex); void loadFeatureSetSettings(const FeatureSetPreset* preset, PluginAPI *pluginAPI, WebAPIAdapterInterface *apiAdapter); void saveFeatureSetSettings(FeatureSetPreset* preset); + // slave mode + void addFeatureInstance(const QString& featureURI, Feature *feature); + void removeFeatureInstanceAt(int index); + void clearFeatures(); private: struct FeatureInstanceRegistration diff --git a/sdrbase/maincore.cpp b/sdrbase/maincore.cpp index cbdc895e2..fabda447f 100644 --- a/sdrbase/maincore.cpp +++ b/sdrbase/maincore.cpp @@ -21,6 +21,7 @@ #include "loggerwithfile.h" #include "dsp/dsptypes.h" +#include "feature/featureset.h" #include "maincore.h" @@ -102,3 +103,23 @@ void MainCore::setLoggingOptions() m_logger->logToFile(QtInfoMsg, appInfoStr); } } + +void MainCore::appendFeatureSet() +{ + int newIndex = m_featureSets.size(); + m_featureSets.push_back(new FeatureSet(newIndex)); +} + +void MainCore::removeFeatureSet(int index) +{ + if (index < m_featureSets.size()) { + m_featureSets.erase(m_featureSets.begin() + index); + } +} + +void MainCore::removeLastFeatureSet() +{ + if (m_featureSets.size() != 0) { + m_featureSets.pop_back(); + } +} diff --git a/sdrbase/maincore.h b/sdrbase/maincore.h index 03d4b1744..2708aec7d 100644 --- a/sdrbase/maincore.h +++ b/sdrbase/maincore.h @@ -410,6 +410,10 @@ public: std::vector& getDeviceSets() { return m_deviceSets; } std::vector& getFeatureeSets() { return m_featureSets; } void setLoggingOptions(); + // slave mode + void appendFeatureSet(); + void removeFeatureSet(int index); + void removeLastFeatureSet(); friend class MainServer; friend class MainWindow; diff --git a/sdrgui/feature/featureuiset.cpp b/sdrgui/feature/featureuiset.cpp index 78b9f31e7..048375b1e 100644 --- a/sdrgui/feature/featureuiset.cpp +++ b/sdrgui/feature/featureuiset.cpp @@ -19,15 +19,17 @@ #include "plugin/pluginapi.h" #include "settings/featuresetpreset.h" #include "feature/featureutils.h" +#include "feature/featureset.h" #include "feature/feature.h" #include "feature/featuregui.h" #include "featureuiset.h" -FeatureUISet::FeatureUISet(int tabIndex) +FeatureUISet::FeatureUISet(int tabIndex, FeatureSet *featureSet) { m_featureWindow = new FeatureWindow; m_featureTabIndex = tabIndex; + m_featureSet = featureSet; } FeatureUISet::~FeatureUISet() @@ -44,6 +46,7 @@ void FeatureUISet::addRollupWidget(QWidget *widget) void FeatureUISet::registerFeatureInstance(const QString& featureURI, FeatureGUI* featureGUI, Feature *feature) { m_featureInstanceRegistrations.append(FeatureInstanceRegistration(featureURI, featureGUI, feature)); + m_featureSet->addFeatureInstance(featureURI, feature); QObject::connect( featureGUI, &FeatureGUI::closing, @@ -71,6 +74,8 @@ void FeatureUISet::freeFeatures() m_featureInstanceRegistrations[i].m_gui->destroy(); m_featureInstanceRegistrations[i].m_feature->destroy(); } + + m_featureSet->clearFeatures(); } void FeatureUISet::deleteFeature(int featureIndex) @@ -82,6 +87,7 @@ void FeatureUISet::deleteFeature(int featureIndex) featureIndex); m_featureInstanceRegistrations[featureIndex].m_gui->destroy(); m_featureInstanceRegistrations[featureIndex].m_feature->destroy(); + m_featureSet->removeFeatureInstanceAt(featureIndex); } } @@ -113,6 +119,7 @@ void FeatureUISet::loadFeatureSetSettings(const FeatureSetPreset *preset, Plugin // copy currently open features and clear list FeatureInstanceRegistrations openFeatures = m_featureInstanceRegistrations; m_featureInstanceRegistrations.clear(); + m_featureSet->clearFeatures(); for (int i = 0; i < openFeatures.count(); i++) { @@ -172,6 +179,7 @@ void FeatureUISet::handleClosingFeatureGUI(FeatureGUI *featureGUI) { if (it->m_gui == featureGUI) { + m_featureSet->removeFeatureInstance(it->m_feature); it->m_feature->destroy(); m_featureInstanceRegistrations.erase(it); break; diff --git a/sdrgui/feature/featureuiset.h b/sdrgui/feature/featureuiset.h index 049f405c1..96e92f672 100644 --- a/sdrgui/feature/featureuiset.h +++ b/sdrgui/feature/featureuiset.h @@ -28,6 +28,7 @@ class QWidget; class FeatureWindow; class FeatureGUI; class PluginAPI; +class FeatureSet; class Feature; class FeatureSetPreset; class WebAPIAdapterInterface; @@ -36,7 +37,7 @@ class SDRGUI_API FeatureUISet : public QObject { Q_OBJECT public: - FeatureUISet(int tabIndex); + FeatureUISet(int tabIndex, FeatureSet *featureSet); ~FeatureUISet(); void addRollupWidget(QWidget *widget); //!< Add feature rollup widget to feature window @@ -76,6 +77,7 @@ private: FeatureInstanceRegistrations m_featureInstanceRegistrations; int m_featureTabIndex; + FeatureSet *m_featureSet; void freeFeatures(); diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index 2ca5b64b5..df5abad48 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -36,6 +36,7 @@ #include "channel/channelapi.h" #include "channel/channelgui.h" #include "feature/featureuiset.h" +#include "feature/featureset.h" #include "feature/feature.h" #include "gui/commandkeyreceiver.h" #include "gui/indicator.h" @@ -555,7 +556,8 @@ void MainWindow::removeLastDevice() void MainWindow::addFeatureSet() { int tabIndex = m_featureUIs.size(); - m_featureUIs.push_back(new FeatureUISet(tabIndex)); + m_mainCore->appendFeatureSet(); + m_featureUIs.push_back(new FeatureUISet(tabIndex, m_mainCore->m_featureSets[tabIndex])); ui->tabFeatures->addTab(m_featureUIs.back()->m_featureWindow, QString("F%1").arg(tabIndex)); } @@ -565,6 +567,7 @@ void MainWindow::removeFeatureSet(int tabIndex) { delete m_featureUIs[tabIndex]; m_featureUIs.erase(m_featureUIs.begin() + tabIndex); + m_mainCore->removeFeatureSet(tabIndex); } } @@ -583,6 +586,7 @@ void MainWindow::deleteChannel(int deviceSetIndex, int channelIndex) { DeviceUISet *deviceSet = m_deviceUIs[deviceSetIndex]; deviceSet->deleteChannel(channelIndex); + m_mainCore->removeLastFeatureSet(); } } diff --git a/sdrgui/webapi/webapiadaptergui.cpp b/sdrgui/webapi/webapiadaptergui.cpp index 122637fd1..329b4af32 100644 --- a/sdrgui/webapi/webapiadaptergui.cpp +++ b/sdrgui/webapi/webapiadaptergui.cpp @@ -2921,7 +2921,7 @@ int WebAPIAdapterGUI::featuresetFeatureSettingsGet( { error.init(); - if ((featureSetIndex >= 0) && (featureSetIndex < (int) m_mainCore->m_deviceSets.size())) + if ((featureSetIndex >= 0) && (featureSetIndex < (int) m_mainCore->m_featureSets.size())) { FeatureSet *featureSet = m_mainCore->m_featureSets[featureSetIndex]; Feature *feature = featureSet->getFeatureAt(featureIndex);