2020-09-19 19:06:34 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2020 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 //
|
|
|
|
// (at your option) any later version. //
|
|
|
|
// //
|
|
|
|
// 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 <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "gui/featurewindow.h"
|
|
|
|
#include "plugin/plugininstancegui.h"
|
2020-09-23 23:38:05 -04:00
|
|
|
#include "plugin/pluginapi.h"
|
|
|
|
#include "settings/featuresetpreset.h"
|
|
|
|
#include "feature/featureutils.h"
|
2020-10-02 23:26:07 -04:00
|
|
|
#include "feature/feature.h"
|
2020-10-03 17:55:24 -04:00
|
|
|
#include "feature/featuregui.h"
|
2020-09-19 19:06:34 -04:00
|
|
|
|
|
|
|
#include "featureuiset.h"
|
|
|
|
|
|
|
|
FeatureUISet::FeatureUISet(int tabIndex)
|
|
|
|
{
|
|
|
|
m_featureWindow = new FeatureWindow;
|
|
|
|
m_featureTabIndex = tabIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
FeatureUISet::~FeatureUISet()
|
|
|
|
{
|
|
|
|
delete m_featureWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeatureUISet::addRollupWidget(QWidget *widget)
|
|
|
|
{
|
|
|
|
m_featureWindow->addRollupWidget(widget);
|
|
|
|
}
|
|
|
|
|
2020-10-03 17:55:24 -04:00
|
|
|
void FeatureUISet::registerFeatureInstance(const QString& featureURI, FeatureGUI* featureGUI, Feature *feature)
|
2020-09-19 19:06:34 -04:00
|
|
|
{
|
2020-10-03 17:55:24 -04:00
|
|
|
m_featureInstanceRegistrations.append(FeatureInstanceRegistration(featureURI, featureGUI, feature));
|
|
|
|
QObject::connect(
|
|
|
|
featureGUI,
|
|
|
|
&FeatureGUI::closing,
|
|
|
|
this,
|
|
|
|
[=](){ this->handleClosingFeatureGUI(featureGUI); },
|
|
|
|
Qt::QueuedConnection
|
|
|
|
);
|
2020-09-19 19:06:34 -04:00
|
|
|
}
|
|
|
|
|
2020-10-03 17:55:24 -04:00
|
|
|
void FeatureUISet::removeFeatureInstance(FeatureGUI* featureGUI)
|
2020-09-19 19:06:34 -04:00
|
|
|
{
|
|
|
|
for (FeatureInstanceRegistrations::iterator it = m_featureInstanceRegistrations.begin(); it != m_featureInstanceRegistrations.end(); ++it)
|
|
|
|
{
|
2020-10-03 17:55:24 -04:00
|
|
|
if (it->m_gui == featureGUI)
|
2020-09-19 19:06:34 -04:00
|
|
|
{
|
|
|
|
m_featureInstanceRegistrations.erase(it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-23 23:38:05 -04:00
|
|
|
// sort by name
|
|
|
|
bool FeatureUISet::FeatureInstanceRegistration::operator<(const FeatureInstanceRegistration& other) const
|
|
|
|
{
|
2020-10-03 05:43:14 -04:00
|
|
|
if (m_feature && other.m_feature) {
|
|
|
|
return m_feature->getName() < other.m_feature->getName();
|
2020-09-23 23:38:05 -04:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-19 19:06:34 -04:00
|
|
|
void FeatureUISet::freeFeatures()
|
|
|
|
{
|
|
|
|
for(int i = 0; i < m_featureInstanceRegistrations.count(); i++)
|
|
|
|
{
|
2020-10-02 23:26:07 -04:00
|
|
|
qDebug("FeatureUISet::freeFeatures: destroying feature [%s]", qPrintable(m_featureInstanceRegistrations[i].m_featureURI));
|
2020-09-19 19:06:34 -04:00
|
|
|
m_featureInstanceRegistrations[i].m_gui->destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeatureUISet::deleteFeature(int featureIndex)
|
|
|
|
{
|
|
|
|
if ((featureIndex >= 0) && (featureIndex < m_featureInstanceRegistrations.count()))
|
|
|
|
{
|
|
|
|
qDebug("FeatureUISet::deleteFeature: delete feature [%s] at %d",
|
2020-10-02 23:26:07 -04:00
|
|
|
qPrintable(m_featureInstanceRegistrations[featureIndex].m_featureURI),
|
2020-09-19 19:06:34 -04:00
|
|
|
featureIndex);
|
|
|
|
m_featureInstanceRegistrations[featureIndex].m_gui->destroy();
|
|
|
|
}
|
|
|
|
}
|
2020-09-20 21:13:36 -04:00
|
|
|
|
|
|
|
const Feature *FeatureUISet::getFeatureAt(int featureIndex) const
|
|
|
|
{
|
|
|
|
if ((featureIndex >= 0) && (featureIndex < m_featureInstanceRegistrations.count())) {
|
|
|
|
return m_featureInstanceRegistrations[featureIndex].m_feature;
|
|
|
|
} else{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Feature *FeatureUISet::getFeatureAt(int featureIndex)
|
|
|
|
{
|
|
|
|
if ((featureIndex >= 0) && (featureIndex < m_featureInstanceRegistrations.count())) {
|
|
|
|
return m_featureInstanceRegistrations[featureIndex].m_feature;
|
|
|
|
} else{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2020-09-23 23:38:05 -04:00
|
|
|
|
|
|
|
void FeatureUISet::loadFeatureSetSettings(const FeatureSetPreset *preset, PluginAPI *pluginAPI, WebAPIAdapterInterface *apiAdapter)
|
|
|
|
{
|
|
|
|
qDebug("FeatureUISet::loadFeatureSetSettings: Loading preset [%s | %s]", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
|
|
|
|
|
|
|
|
// Available feature plugins
|
|
|
|
PluginAPI::FeatureRegistrations *featureRegistrations = pluginAPI->getFeatureRegistrations();
|
|
|
|
|
|
|
|
// copy currently open features and clear list
|
|
|
|
FeatureInstanceRegistrations openFeatures = m_featureInstanceRegistrations;
|
|
|
|
m_featureInstanceRegistrations.clear();
|
|
|
|
|
|
|
|
for (int i = 0; i < openFeatures.count(); i++)
|
|
|
|
{
|
2020-10-02 23:26:07 -04:00
|
|
|
qDebug("FeatureUISet::loadFeatureSetSettings: destroying old feature [%s]", qPrintable(openFeatures[i].m_featureURI));
|
2020-09-23 23:38:05 -04:00
|
|
|
openFeatures[i].m_gui->destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug("FeatureUISet::loadFeatureSetSettings: %d feature(s) in preset", preset->getFeatureCount());
|
|
|
|
|
|
|
|
for (int i = 0; i < preset->getFeatureCount(); i++)
|
|
|
|
{
|
|
|
|
const FeatureSetPreset::FeatureConfig& featureConfig = preset->getFeatureConfig(i);
|
2020-10-02 23:26:07 -04:00
|
|
|
PluginInstanceGUI *featureGUI = nullptr;
|
2020-09-23 23:38:05 -04:00
|
|
|
|
|
|
|
// create feature instance
|
|
|
|
|
|
|
|
for(int i = 0; i < featureRegistrations->count(); i++)
|
|
|
|
{
|
|
|
|
if (FeatureUtils::compareFeatureURIs((*featureRegistrations)[i].m_featureIdURI, featureConfig.m_featureIdURI))
|
|
|
|
{
|
|
|
|
qDebug("FeatureUISet::loadFeatureSetSettings: creating new feature [%s] from config [%s]",
|
|
|
|
qPrintable((*featureRegistrations)[i].m_featureIdURI),
|
|
|
|
qPrintable(featureConfig.m_featureIdURI));
|
|
|
|
Feature *feature =
|
|
|
|
(*featureRegistrations)[i].m_plugin->createFeature(apiAdapter);
|
2020-10-03 17:55:24 -04:00
|
|
|
FeatureGUI *featureGUI =
|
2020-09-23 23:38:05 -04:00
|
|
|
(*featureRegistrations)[i].m_plugin->createFeatureGUI(this, feature);
|
2020-10-02 23:26:07 -04:00
|
|
|
registerFeatureInstance(feature->getURI(), featureGUI, feature);
|
2020-09-23 23:38:05 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-02 23:26:07 -04:00
|
|
|
if (featureGUI)
|
2020-09-23 23:38:05 -04:00
|
|
|
{
|
|
|
|
qDebug("FeatureUISet::loadFeatureSetSettings: deserializing feature [%s]", qPrintable(featureConfig.m_featureIdURI));
|
2020-10-02 23:26:07 -04:00
|
|
|
featureGUI->deserialize(featureConfig.m_config);
|
2020-09-23 23:38:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeatureUISet::saveFeatureSetSettings(FeatureSetPreset *preset)
|
|
|
|
{
|
|
|
|
std::sort(m_featureInstanceRegistrations.begin(), m_featureInstanceRegistrations.end()); // sort by increasing delta frequency and type
|
|
|
|
|
|
|
|
for (int i = 0; i < m_featureInstanceRegistrations.count(); i++)
|
|
|
|
{
|
2020-10-02 23:26:07 -04:00
|
|
|
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());
|
2020-09-23 23:38:05 -04:00
|
|
|
}
|
|
|
|
}
|
2020-10-03 17:55:24 -04:00
|
|
|
|
|
|
|
|
|
|
|
void FeatureUISet::handleClosingFeatureGUI(FeatureGUI *featureGUI)
|
|
|
|
{
|
|
|
|
qDebug("FeatureUISet::handleClosingFeatureGUI");
|
|
|
|
removeFeatureInstance(featureGUI);
|
|
|
|
}
|