1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 09:18:54 -05:00

Feature plugins: register feature instances outside of their GUI classes

This commit is contained in:
f4exb 2020-10-03 05:26:07 +02:00
parent 93de98c53c
commit efaba0fa67
8 changed files with 24 additions and 20 deletions

View File

@ -86,6 +86,7 @@ public:
virtual void destroy() { delete this; }
virtual bool handleMessage(const Message& cmd);
virtual const QString& getURI() const { return m_featureIdURI; }
virtual void getIdentifier(QString& id) const { id = m_featureId; }
virtual void getTitle(QString& title) const { title = m_settings.m_title; }

View File

@ -140,7 +140,6 @@ RigCtlServerGUI::RigCtlServerGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISe
m_rigCtlServer = reinterpret_cast<RigCtlServer*>(feature);
m_rigCtlServer->setMessageQueueToGUI(&m_inputMessageQueue);
m_featureUISet->registerFeatureInstance(RigCtlServer::m_featureIdURI, this, m_rigCtlServer);
m_featureUISet->addRollupWidget(this);
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &)));

View File

@ -104,6 +104,7 @@ public:
virtual void destroy() { delete this; }
virtual bool handleMessage(const Message& cmd);
virtual const QString& getURI() const { return m_featureIdURI; }
virtual void getIdentifier(QString& id) const { id = m_featureId; }
virtual void getTitle(QString& title) const { title = m_settings.m_title; }

View File

@ -147,7 +147,6 @@ SimplePTTGUI::SimplePTTGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Fea
m_simplePTT = reinterpret_cast<SimplePTT*>(feature);
m_simplePTT->setMessageQueueToGUI(&m_inputMessageQueue);
m_featureUISet->registerFeatureInstance(SimplePTT::m_featureIdURI, this, m_simplePTT);
m_featureUISet->addRollupWidget(this);
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &)));

View File

@ -53,6 +53,7 @@ public:
virtual void destroy() = 0;
virtual bool handleMessage(const Message& cmd) = 0; //!< Processing of a message. Returns true if message has actually been processed
virtual const QString& getURI() const = 0;
virtual void getIdentifier(QString& id) const = 0;
virtual void getTitle(QString& title) const = 0;
virtual void setName(const QString& name) { m_name = name; }

View File

@ -20,6 +20,7 @@
#include "plugin/pluginapi.h"
#include "settings/featuresetpreset.h"
#include "feature/featureutils.h"
#include "feature/feature.h"
#include "featureuiset.h"
@ -39,9 +40,9 @@ void FeatureUISet::addRollupWidget(QWidget *widget)
m_featureWindow->addRollupWidget(widget);
}
void FeatureUISet::registerFeatureInstance(const QString& featureName, PluginInstanceGUI* pluginGUI, Feature *feature)
void FeatureUISet::registerFeatureInstance(const QString& featureURI, PluginInstanceGUI* pluginGUI, Feature *feature)
{
m_featureInstanceRegistrations.append(FeatureInstanceRegistration(featureName, pluginGUI, feature));
m_featureInstanceRegistrations.append(FeatureInstanceRegistration(featureURI, pluginGUI, feature));
renameFeatureInstances();
}
@ -62,7 +63,7 @@ void FeatureUISet::removeFeatureInstance(PluginInstanceGUI* pluginGUI)
void FeatureUISet::renameFeatureInstances()
{
for (int i = 0; i < m_featureInstanceRegistrations.count(); i++) {
m_featureInstanceRegistrations[i].m_gui->setName(QString("%1:%2").arg(m_featureInstanceRegistrations[i].m_featureName).arg(i));
m_featureInstanceRegistrations[i].m_gui->setName(QString("%1:%2").arg(m_featureInstanceRegistrations[i].m_featureURI).arg(i));
}
}
@ -80,7 +81,7 @@ void FeatureUISet::freeFeatures()
{
for(int i = 0; i < m_featureInstanceRegistrations.count(); i++)
{
qDebug("FeatureUISet::freeFeatures: destroying feature [%s]", qPrintable(m_featureInstanceRegistrations[i].m_featureName));
qDebug("FeatureUISet::freeFeatures: destroying feature [%s]", qPrintable(m_featureInstanceRegistrations[i].m_featureURI));
m_featureInstanceRegistrations[i].m_gui->destroy();
}
}
@ -90,7 +91,7 @@ void FeatureUISet::deleteFeature(int featureIndex)
if ((featureIndex >= 0) && (featureIndex < m_featureInstanceRegistrations.count()))
{
qDebug("FeatureUISet::deleteFeature: delete feature [%s] at %d",
qPrintable(m_featureInstanceRegistrations[featureIndex].m_featureName),
qPrintable(m_featureInstanceRegistrations[featureIndex].m_featureURI),
featureIndex);
m_featureInstanceRegistrations[featureIndex].m_gui->destroy();
renameFeatureInstances();
@ -128,7 +129,7 @@ void FeatureUISet::loadFeatureSetSettings(const FeatureSetPreset *preset, Plugin
for (int i = 0; i < openFeatures.count(); i++)
{
qDebug("FeatureUISet::loadFeatureSetSettings: destroying old feature [%s]", qPrintable(openFeatures[i].m_featureName));
qDebug("FeatureUISet::loadFeatureSetSettings: destroying old feature [%s]", qPrintable(openFeatures[i].m_featureURI));
openFeatures[i].m_gui->destroy();
}
@ -137,7 +138,7 @@ void FeatureUISet::loadFeatureSetSettings(const FeatureSetPreset *preset, Plugin
for (int i = 0; i < preset->getFeatureCount(); i++)
{
const FeatureSetPreset::FeatureConfig& featureConfig = preset->getFeatureConfig(i);
FeatureInstanceRegistration reg;
PluginInstanceGUI *featureGUI = nullptr;
// create feature instance
@ -152,15 +153,15 @@ void FeatureUISet::loadFeatureSetSettings(const FeatureSetPreset *preset, Plugin
(*featureRegistrations)[i].m_plugin->createFeature(apiAdapter);
PluginInstanceGUI *featureGUI =
(*featureRegistrations)[i].m_plugin->createFeatureGUI(this, feature);
reg = FeatureInstanceRegistration(featureConfig.m_featureIdURI, featureGUI, feature);
registerFeatureInstance(feature->getURI(), featureGUI, feature);
break;
}
}
if (reg.m_gui)
if (featureGUI)
{
qDebug("FeatureUISet::loadFeatureSetSettings: deserializing feature [%s]", qPrintable(featureConfig.m_featureIdURI));
reg.m_gui->deserialize(featureConfig.m_config);
featureGUI->deserialize(featureConfig.m_config);
}
}
@ -173,7 +174,7 @@ void FeatureUISet::saveFeatureSetSettings(FeatureSetPreset *preset)
for (int i = 0; i < m_featureInstanceRegistrations.count(); i++)
{
qDebug("FeatureUISet::saveFeatureSetSettings: saving feature [%s]", qPrintable(m_featureInstanceRegistrations[i].m_featureName));
preset->addFeature(m_featureInstanceRegistrations[i].m_featureName, m_featureInstanceRegistrations[i].m_gui->serialize());
qDebug("FeatureUISet::saveFeatureSetSettings: saving feature [%s]", qPrintable(m_featureInstanceRegistrations[i].m_featureURI));
preset->addFeature(m_featureInstanceRegistrations[i].m_featureURI, m_featureInstanceRegistrations[i].m_gui->serialize());
}
}

View File

@ -39,7 +39,7 @@ public:
void addRollupWidget(QWidget *widget); //!< Add feature rollup widget to feature window
int getNumberOfFeatures() const { return m_featureInstanceRegistrations.size(); }
void registerFeatureInstance(const QString& featureName, PluginInstanceGUI* pluginGUI, Feature *feature);
void registerFeatureInstance(const QString& featureURI, PluginInstanceGUI* pluginGUI, Feature *feature);
void removeFeatureInstance(PluginInstanceGUI* pluginGUI);
void freeFeatures();
void deleteFeature(int featureIndex);
@ -53,18 +53,18 @@ public:
private:
struct FeatureInstanceRegistration
{
QString m_featureName;
QString m_featureURI;
PluginInstanceGUI* m_gui;
Feature* m_feature;
FeatureInstanceRegistration() :
m_featureName(),
m_featureURI(),
m_gui(nullptr),
m_feature(nullptr)
{ }
FeatureInstanceRegistration(const QString& featureName, PluginInstanceGUI* pluginGUI, Feature *feature) :
m_featureName(featureName),
FeatureInstanceRegistration(const QString& featureURI, PluginInstanceGUI* pluginGUI, Feature *feature) :
m_featureURI(featureURI),
m_gui(pluginGUI),
m_feature(feature)
{ }

View File

@ -37,6 +37,7 @@
#include "device/deviceenumerator.h"
#include "channel/channelapi.h"
#include "feature/featureuiset.h"
#include "feature/feature.h"
#include "gui/indicator.h"
#include "gui/presetitem.h"
#include "gui/commanditem.h"
@ -1983,7 +1984,8 @@ void MainWindow::featureAddClicked(int featureIndex)
PluginAPI::FeatureRegistrations *featureRegistrations = m_pluginManager->getFeatureRegistrations(); // Available feature plugins
PluginInterface *pluginInterface = (*featureRegistrations)[featureIndex].m_plugin;
Feature *feature = pluginInterface->createFeature(m_apiAdapter);
pluginInterface->createFeatureGUI(featureUISet, feature);
PluginInstanceGUI *gui = pluginInterface->createFeatureGUI(featureUISet, feature);
featureUISet->registerFeatureInstance(feature->getURI(), gui, feature);
}
}