42 changed files with 2242 additions and 26 deletions
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2019 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 "SWGFeatureSettings.h" |
||||
#include "simpleptt.h" |
||||
#include "simplepttwebapiadapter.h" |
||||
|
||||
SimplePTTWebAPIAdapter::SimplePTTWebAPIAdapter() |
||||
{} |
||||
|
||||
SimplePTTWebAPIAdapter::~SimplePTTWebAPIAdapter() |
||||
{} |
||||
|
||||
int SimplePTTWebAPIAdapter::webapiSettingsGet( |
||||
SWGSDRangel::SWGFeatureSettings& response, |
||||
QString& errorMessage) |
||||
{ |
||||
(void) errorMessage; |
||||
response.setSimplePttSettings(new SWGSDRangel::SWGSimplePTTSettings()); |
||||
response.getSimplePttSettings()->init(); |
||||
SimplePTT::webapiFormatFeatureSettings(response, m_settings); |
||||
|
||||
return 200; |
||||
} |
||||
|
||||
int SimplePTTWebAPIAdapter::webapiSettingsPutPatch( |
||||
bool force, |
||||
const QStringList& featureSettingsKeys, |
||||
SWGSDRangel::SWGFeatureSettings& response, |
||||
QString& errorMessage) |
||||
{ |
||||
(void) errorMessage; |
||||
SimplePTT::webapiUpdateFeatureSettings(m_settings, featureSettingsKeys, response); |
||||
|
||||
return 200; |
||||
} |
||||
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDE_SIMPLEPTT_WEBAPIADAPTER_H |
||||
#define INCLUDE_SIMPLEPTT_WEBAPIADAPTER_H |
||||
|
||||
#include "feature/featurewebapiadapter.h" |
||||
#include "simplepttsettings.h" |
||||
|
||||
/**
|
||||
* Standalone API adapter only for the settings |
||||
*/ |
||||
class SimplePTTWebAPIAdapter : public FeatureWebAPIAdapter { |
||||
public: |
||||
SimplePTTWebAPIAdapter(); |
||||
virtual ~SimplePTTWebAPIAdapter(); |
||||
|
||||
virtual QByteArray serialize() const { return m_settings.serialize(); } |
||||
virtual bool deserialize(const QByteArray& data) { return m_settings.deserialize(data); } |
||||
|
||||
virtual int webapiSettingsGet( |
||||
SWGSDRangel::SWGFeatureSettings& response, |
||||
QString& errorMessage); |
||||
|
||||
virtual int webapiSettingsPutPatch( |
||||
bool force, |
||||
const QStringList& featureSettingsKeys, |
||||
SWGSDRangel::SWGFeatureSettings& response, |
||||
QString& errorMessage); |
||||
|
||||
private: |
||||
SimplePTTSettings m_settings; |
||||
}; |
||||
|
||||
#endif // INCLUDE_SIMPLEPTT_WEBAPIADAPTER_H
|
||||
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 "featureutils.h" |
||||
|
||||
bool FeatureUtils::compareFeatureURIs(const QString& registeredFeatureURI, const QString& xFeatureURI) |
||||
{ |
||||
return registeredFeatureURI == getRegisteredFeatureURI(xFeatureURI); |
||||
} |
||||
|
||||
QString FeatureUtils::getRegisteredFeatureURI(const QString& xFeatureURI) |
||||
{ |
||||
return xFeatureURI; |
||||
} |
||||
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SDRBASE_FEATURE_FEATUREUTILS_H_ |
||||
#define SDRBASE_FEATURE_FEATUREUTILS_H_ |
||||
|
||||
#include <QString> |
||||
#include "export.h" |
||||
|
||||
class SDRBASE_API FeatureUtils |
||||
{ |
||||
public: |
||||
static bool compareFeatureURIs(const QString& registeredFeatureURI, const QString& xFeatureURI); |
||||
static QString getRegisteredFeatureURI(const QString& xFeatureURI); |
||||
}; |
||||
|
||||
#endif // SDRBASE_FEATURE_FEATUREUTILS_H_
|
||||
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2020 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// Interface for static web API adapters used for preset serialization and //
|
||||
// deserialization //
|
||||
// //
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SDRBASE_FEATURE_FEATUREWEBAPIADAPER_H_ |
||||
#define SDRBASE_FEATURE_FEATUREWEBAPIADAPER_H_ |
||||
|
||||
#include <QByteArray> |
||||
#include <QStringList> |
||||
|
||||
#include "export.h" |
||||
|
||||
namespace SWGSDRangel |
||||
{ |
||||
class SWGFeatureSettings; |
||||
} |
||||
|
||||
class SDRBASE_API FeatureWebAPIAdapter |
||||
{ |
||||
public: |
||||
FeatureWebAPIAdapter() {} |
||||
virtual ~FeatureWebAPIAdapter() {} |
||||
virtual QByteArray serialize() const = 0; |
||||
virtual bool deserialize(const QByteArray& data) = 0; |
||||
|
||||
/**
|
||||
* API adapter for the channel settings GET requests |
||||
*/ |
||||
virtual int webapiSettingsGet( |
||||
SWGSDRangel::SWGFeatureSettings& response, |
||||
QString& errorMessage) |
||||
{ |
||||
(void) response; |
||||
errorMessage = "Not implemented"; return 501; |
||||
} |
||||
|
||||
/**
|
||||
* API adapter for the channel settings PUT and PATCH requests |
||||
*/ |
||||
virtual int webapiSettingsPutPatch( |
||||
bool force, |
||||
const QStringList& featureSettingsKeys, |
||||
SWGSDRangel::SWGFeatureSettings& response, |
||||
QString& errorMessage) |
||||
{ |
||||
(void) force; |
||||
(void) featureSettingsKeys; |
||||
(void) response; |
||||
errorMessage = "Not implemented"; return 501; |
||||
} |
||||
}; |
||||
|
||||
#endif // SDRBASE_FEATURE_FEATUREWEBAPIADAPER_H_
|
||||
@ -0,0 +1,97 @@
@@ -0,0 +1,97 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 "util/simpleserializer.h" |
||||
|
||||
#include "featuresetpreset.h" |
||||
|
||||
FeatureSetPreset::FeatureSetPreset() |
||||
{ |
||||
resetToDefaults(); |
||||
} |
||||
|
||||
FeatureSetPreset::FeatureSetPreset(const FeatureSetPreset& other) : |
||||
m_group(other.m_group), |
||||
m_description(other.m_description), |
||||
m_featureConfigs(other.m_featureConfigs) |
||||
{} |
||||
|
||||
void FeatureSetPreset::resetToDefaults() |
||||
{ |
||||
m_group = "default"; |
||||
m_description = "no name"; |
||||
m_featureConfigs.clear(); |
||||
} |
||||
|
||||
QByteArray FeatureSetPreset::serialize() const |
||||
{ |
||||
SimpleSerializer s(1); |
||||
|
||||
s.writeString(1, m_group); |
||||
s.writeString(2, m_description); |
||||
s.writeS32(100, m_featureConfigs.size()); |
||||
|
||||
for(int i = 0; i < m_featureConfigs.size(); i++) |
||||
{ |
||||
s.writeString(101 + i * 2, m_featureConfigs[i].m_featureIdURI); |
||||
s.writeBlob(102 + i * 2, m_featureConfigs[i].m_config); |
||||
} |
||||
|
||||
return s.final(); |
||||
} |
||||
|
||||
bool FeatureSetPreset::deserialize(const QByteArray& data) |
||||
{ |
||||
SimpleDeserializer d(data); |
||||
|
||||
if (!d.isValid()) |
||||
{ |
||||
resetToDefaults(); |
||||
return false; |
||||
} |
||||
|
||||
if (d.getVersion() == 1) |
||||
{ |
||||
bool tmpBool; |
||||
int tmp; |
||||
|
||||
d.readString(1, &m_group, "default"); |
||||
d.readString(2, &m_description, "no name"); |
||||
|
||||
qint32 featureCount; |
||||
d.readS32(100, &featureCount, 0); |
||||
|
||||
m_featureConfigs.clear(); |
||||
|
||||
for (int i = 0; i < featureCount; i++) |
||||
{ |
||||
QString feature; |
||||
QByteArray config; |
||||
|
||||
d.readString(101 + i * 2, &feature, "unknown-feature"); |
||||
d.readBlob(102 + i * 2, &config); |
||||
m_featureConfigs.append(FeatureConfig(feature, config)); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
else |
||||
{ |
||||
resetToDefaults(); |
||||
return false; |
||||
} |
||||
} |
||||
@ -0,0 +1,81 @@
@@ -0,0 +1,81 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SDRBASE_SETTINGS_FEATURESETSETTINGS_H_ |
||||
#define SDRBASE_SETTINGS_FEATURESETSETTINGS_H_ |
||||
|
||||
#include <QString> |
||||
#include <QByteArray> |
||||
#include <QList> |
||||
#include <QMetaType> |
||||
|
||||
#include "export.h" |
||||
|
||||
class SDRBASE_API FeatureSetPreset { |
||||
public: |
||||
struct FeatureConfig { |
||||
QString m_featureIdURI; //!< Channel type ID in URI form
|
||||
QByteArray m_config; |
||||
|
||||
FeatureConfig(const QString& featureIdURI, const QByteArray& config) : |
||||
m_featureIdURI(featureIdURI), |
||||
m_config(config) |
||||
{ } |
||||
}; |
||||
typedef QList<FeatureConfig> FeatureConfigs; |
||||
|
||||
FeatureSetPreset(); |
||||
FeatureSetPreset(const FeatureSetPreset& other); |
||||
void resetToDefaults(); |
||||
|
||||
QByteArray serialize() const; |
||||
bool deserialize(const QByteArray& data); |
||||
|
||||
void setGroup(const QString& group) { m_group = group; } |
||||
const QString& getGroup() const { return m_group; } |
||||
void setDescription(const QString& description) { m_description = description; } |
||||
const QString& getDescription() const { return m_description; } |
||||
|
||||
void clearFeatures() { m_featureConfigs.clear(); } |
||||
void addFeature(const QString& feature, const QByteArray& config) { m_featureConfigs.append(FeatureConfig(feature, config)); } |
||||
int getFeatureCount() const { return m_featureConfigs.count(); } |
||||
const FeatureConfig& getFeatureConfig(int index) const { return m_featureConfigs.at(index); } |
||||
|
||||
static bool presetCompare(const FeatureSetPreset *p1, FeatureSetPreset *p2) |
||||
{ |
||||
if (p1->m_group != p2->m_group) |
||||
{ |
||||
return p1->m_group < p2->m_group; |
||||
} |
||||
else |
||||
{ |
||||
return p1->m_description < p2->m_description; |
||||
} |
||||
} |
||||
|
||||
private: |
||||
// group and preset description
|
||||
QString m_group; |
||||
QString m_description; |
||||
// features and configurations
|
||||
FeatureConfigs m_featureConfigs; |
||||
}; |
||||
|
||||
Q_DECLARE_METATYPE(const FeatureSetPreset*) |
||||
Q_DECLARE_METATYPE(FeatureSetPreset*) |
||||
|
||||
#endif // SDRBASE_SETTINGS_FEATURESETSETTINGS_H_
|
||||
@ -0,0 +1,413 @@
@@ -0,0 +1,413 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2020 F4EXB //
|
||||
// written by Edouard Griffiths //
|
||||
// //
|
||||
// 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 <QMessageBox> |
||||
#include <QDebug> |
||||
|
||||
#include "gui/addpresetdialog.h" |
||||
#include "feature/featureuiset.h" |
||||
#include "featurepresetsdialog.h" |
||||
#include "settings/featuresetpreset.h" |
||||
#include "ui_featurepresetsdialog.h" |
||||
|
||||
FeaturePresetsDialog::FeaturePresetsDialog(QWidget* parent) : |
||||
QDialog(parent), |
||||
ui(new Ui::FeaturePresetsDialog), |
||||
m_featureSetPresets(nullptr) |
||||
{ |
||||
ui->setupUi(this); |
||||
} |
||||
|
||||
FeaturePresetsDialog::~FeaturePresetsDialog() |
||||
{ |
||||
delete ui; |
||||
} |
||||
|
||||
void FeaturePresetsDialog::populateTree() |
||||
{ |
||||
if (!m_featureSetPresets) { |
||||
return; |
||||
} |
||||
|
||||
QList<FeatureSetPreset*>::const_iterator it = m_featureSetPresets->begin(); |
||||
int middleIndex = m_featureSetPresets->size() / 2; |
||||
QTreeWidgetItem *treeItem; |
||||
ui->presetsTree->clear(); |
||||
|
||||
for (int i = 0; it != m_featureSetPresets->end(); ++it, i++) |
||||
{ |
||||
treeItem = addPresetToTree(*it); |
||||
|
||||
if (i == middleIndex) { |
||||
ui->presetsTree->setCurrentItem(treeItem); |
||||
} |
||||
} |
||||
|
||||
updatePresetControls(); |
||||
} |
||||
|
||||
QTreeWidgetItem* FeaturePresetsDialog::addPresetToTree(const FeatureSetPreset* preset) |
||||
{ |
||||
QTreeWidgetItem* group = nullptr; |
||||
|
||||
for (int i = 0; i < ui->presetsTree->topLevelItemCount(); i++) |
||||
{ |
||||
if (ui->presetsTree->topLevelItem(i)->text(0) == preset->getGroup()) |
||||
{ |
||||
group = ui->presetsTree->topLevelItem(i); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
if (!group) |
||||
{ |
||||
QStringList sl; |
||||
sl.append(preset->getGroup()); |
||||
group = new QTreeWidgetItem(ui->presetsTree, sl, PGroup); |
||||
group->setFirstColumnSpanned(true); |
||||
group->setExpanded(true); |
||||
ui->presetsTree->sortByColumn(0, Qt::AscendingOrder); |
||||
} |
||||
|
||||
QStringList sl; |
||||
sl.append(preset->getDescription()); |
||||
QTreeWidgetItem* item = new QTreeWidgetItem(group, sl, PItem); // description column
|
||||
item->setTextAlignment(0, Qt::AlignLeft); |
||||
item->setData(0, Qt::UserRole, QVariant::fromValue(preset)); |
||||
|
||||
updatePresetControls(); |
||||
return item; |
||||
} |
||||
|
||||
void FeaturePresetsDialog::updatePresetControls() |
||||
{ |
||||
ui->presetsTree->resizeColumnToContents(0); |
||||
|
||||
if (ui->presetsTree->currentItem()) |
||||
{ |
||||
ui->presetDelete->setEnabled(true); |
||||
ui->presetLoad->setEnabled(true); |
||||
} |
||||
else |
||||
{ |
||||
ui->presetDelete->setEnabled(false); |
||||
ui->presetLoad->setEnabled(false); |
||||
} |
||||
} |
||||
|
||||
void FeaturePresetsDialog::on_presetSave_clicked() |
||||
{ |
||||
QStringList groups; |
||||
QString group; |
||||
QString description = ""; |
||||
|
||||
for (int i = 0; i < ui->presetsTree->topLevelItemCount(); i++) { |
||||
groups.append(ui->presetsTree->topLevelItem(i)->text(0)); |
||||
} |
||||
|
||||
QTreeWidgetItem* item = ui->presetsTree->currentItem(); |
||||
|
||||
if (item) |
||||
{ |
||||
if (item->type() == PGroup) |
||||
{ |
||||
group = item->text(0); |
||||
} |
||||
else if (item->type() == PItem) |
||||
{ |
||||
group = item->parent()->text(0); |
||||
description = item->text(0); |
||||
} |
||||
} |
||||
|
||||
AddPresetDialog dlg(groups, group, this); |
||||
|
||||
if (description.length() > 0) { |
||||
dlg.setDescription(description); |
||||
} |
||||
|
||||
if (dlg.exec() == QDialog::Accepted) |
||||
{ |
||||
FeatureSetPreset* preset = newFeatureSetPreset(dlg.group(), dlg.description()); |
||||
savePresetSettings(preset); |
||||
ui->presetsTree->setCurrentItem(addPresetToTree(preset)); |
||||
} |
||||
|
||||
sortFeatureSetPresets(); |
||||
} |
||||
|
||||
void FeaturePresetsDialog::on_presetUpdate_clicked() |
||||
{ |
||||
QTreeWidgetItem* item = ui->presetsTree->currentItem(); |
||||
const FeatureSetPreset* changedPreset = nullptr; |
||||
|
||||
if (item) |
||||
{ |
||||
if( item->type() == PItem) |
||||
{ |
||||
const FeatureSetPreset* preset = qvariant_cast<const FeatureSetPreset*>(item->data(0, Qt::UserRole)); |
||||
|
||||
if (preset) |
||||
{ |
||||
FeatureSetPreset* preset_mod = const_cast<FeatureSetPreset*>(preset); |
||||
savePresetSettings(preset_mod); |
||||
changedPreset = preset; |
||||
} |
||||
} |
||||
} |
||||
|
||||
sortFeatureSetPresets(); |
||||
ui->presetsTree->clear(); |
||||
|
||||
for (int i = 0; i < m_featureSetPresets->size(); ++i) |
||||
{ |
||||
QTreeWidgetItem *item_x = addPresetToTree(m_featureSetPresets->at(i)); |
||||
const FeatureSetPreset* preset_x = qvariant_cast<const FeatureSetPreset*>(item_x->data(0, Qt::UserRole)); |
||||
|
||||
if (changedPreset && (preset_x == changedPreset)) { // set cursor on changed preset
|
||||
ui->presetsTree->setCurrentItem(item_x); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void FeaturePresetsDialog::on_settingsSave_clicked() |
||||
{ |
||||
} |
||||
|
||||
void FeaturePresetsDialog::on_presetEdit_clicked() |
||||
{ |
||||
QTreeWidgetItem* item = ui->presetsTree->currentItem(); |
||||
QStringList groups; |
||||
bool change = false; |
||||
const FeatureSetPreset *changedPreset = nullptr; |
||||
QString newGroupName; |
||||
|
||||
for (int i = 0; i < ui->presetsTree->topLevelItemCount(); i++) { |
||||
groups.append(ui->presetsTree->topLevelItem(i)->text(0)); |
||||
} |
||||
|
||||
if (item) |
||||
{ |
||||
if (item->type() == PItem) |
||||
{ |
||||
const FeatureSetPreset* preset = qvariant_cast<const FeatureSetPreset*>(item->data(0, Qt::UserRole)); |
||||
AddPresetDialog dlg(groups, preset->getGroup(), this); |
||||
dlg.setDescription(preset->getDescription()); |
||||
|
||||
if (dlg.exec() == QDialog::Accepted) |
||||
{ |
||||
FeatureSetPreset* preset_mod = const_cast<FeatureSetPreset*>(preset); |
||||
preset_mod->setGroup(dlg.group()); |
||||
preset_mod->setDescription(dlg.description()); |
||||
change = true; |
||||
changedPreset = preset; |
||||
} |
||||
} |
||||
else if (item->type() == PGroup) |
||||
{ |
||||
AddPresetDialog dlg(groups, item->text(0), this); |
||||
dlg.showGroupOnly(); |
||||
dlg.setDialogTitle("Edit preset group"); |
||||
|
||||
if (dlg.exec() == QDialog::Accepted) |
||||
{ |
||||
renamePresetGroup(item->text(0), dlg.group()); |
||||
newGroupName = dlg.group(); |
||||
change = true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (change) |
||||
{ |
||||
sortFeatureSetPresets(); |
||||
ui->presetsTree->clear(); |
||||
|
||||
for (int i = 0; i < m_featureSetPresets->size(); ++i) |
||||
{ |
||||
QTreeWidgetItem *item_x = addPresetToTree(m_featureSetPresets->at(i)); |
||||
const FeatureSetPreset* preset_x = qvariant_cast<const FeatureSetPreset*>(item_x->data(0, Qt::UserRole)); |
||||
|
||||
if (changedPreset && (preset_x == changedPreset)) { // set cursor on changed preset
|
||||
ui->presetsTree->setCurrentItem(item_x); |
||||
} |
||||
} |
||||
|
||||
if (!changedPreset) // on group name change set cursor on the group that has been changed
|
||||
{ |
||||
for(int i = 0; i < ui->presetsTree->topLevelItemCount(); i++) |
||||
{ |
||||
QTreeWidgetItem* item = ui->presetsTree->topLevelItem(i); |
||||
|
||||
if (item->text(0) == newGroupName) { |
||||
ui->presetsTree->setCurrentItem(item); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
void FeaturePresetsDialog::on_presetDelete_clicked() |
||||
{ |
||||
QTreeWidgetItem* item = ui->presetsTree->currentItem(); |
||||
|
||||
if (item == 0) |
||||
{ |
||||
updatePresetControls(); |
||||
return; |
||||
} |
||||
else |
||||
{ |
||||
if (item->type() == PItem) |
||||
{ |
||||
const FeatureSetPreset* preset = qvariant_cast<const FeatureSetPreset*>(item->data(0, Qt::UserRole)); |
||||
|
||||
if (preset) |
||||
{ |
||||
if(QMessageBox::question(this, tr("Delete Preset"), tr("Do you want to delete preset '%1'?").arg(preset->getDescription()), QMessageBox::No | QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) { |
||||
delete item; |
||||
deletePreset(preset); |
||||
} |
||||
} |
||||
} |
||||
else if (item->type() == PGroup) |
||||
{ |
||||
if (QMessageBox::question(this, |
||||
tr("Delete preset group"), |
||||
tr("Do you want to delete preset group '%1'?") |
||||
.arg(item->text(0)), QMessageBox::No | QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) |
||||
{ |
||||
deletePresetGroup(item->text(0)); |
||||
|
||||
ui->presetsTree->clear(); |
||||
|
||||
for (int i = 0; i < m_featureSetPresets->size(); ++i) { |
||||
addPresetToTree(m_featureSetPresets->at(i)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
void FeaturePresetsDialog::on_presetLoad_clicked() |
||||
{ |
||||
qDebug() << "FeaturePresetsDialog::on_presetLoad_clicked"; |
||||
|
||||
QTreeWidgetItem* item = ui->presetsTree->currentItem(); |
||||
|
||||
if (!item) |
||||
{ |
||||
qDebug("FeaturePresetsDialog::on_presetLoad_clicked: item null"); |
||||
updatePresetControls(); |
||||
return; |
||||
} |
||||
|
||||
const FeatureSetPreset* preset = qvariant_cast<const FeatureSetPreset*>(item->data(0, Qt::UserRole)); |
||||
|
||||
if (!preset) |
||||
{ |
||||
qDebug("FeatureSetPreset::on_presetLoad_clicked: preset null"); |
||||
return; |
||||
} |
||||
|
||||
loadPresetSettings(preset); |
||||
} |
||||
|
||||
void FeaturePresetsDialog::on_presetTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) |
||||
{ |
||||
(void) current; |
||||
(void) previous; |
||||
updatePresetControls(); |
||||
} |
||||
|
||||
void FeaturePresetsDialog::on_presetTree_itemActivated(QTreeWidgetItem *item, int column) |
||||
{ |
||||
(void) item; |
||||
(void) column; |
||||
on_presetLoad_clicked(); |
||||
} |
||||
|
||||
FeatureSetPreset* FeaturePresetsDialog::newFeatureSetPreset(const QString& group, const QString& description) |
||||
{ |
||||
FeatureSetPreset* preset = new FeatureSetPreset(); |
||||
preset->setGroup(group); |
||||
preset->setDescription(description); |
||||
addFeatureSetPreset(preset); |
||||
return preset; |
||||
} |
||||
|
||||
void FeaturePresetsDialog::addFeatureSetPreset(FeatureSetPreset *preset) |
||||
{ |
||||
m_featureSetPresets->append(preset); |
||||
} |
||||
|
||||
void FeaturePresetsDialog::savePresetSettings(FeatureSetPreset* preset) |
||||
{ |
||||
qDebug("FeaturePresetsDialog::savePresetSettings: preset [%s | %s]", |
||||
qPrintable(preset->getGroup()), |
||||
qPrintable(preset->getDescription())); |
||||
|
||||
preset->clearFeatures(); |
||||
m_featureUISet->saveFeatureSetSettings(preset); |
||||
} |
||||
|
||||
void FeaturePresetsDialog::loadPresetSettings(const FeatureSetPreset* preset) |
||||
{ |
||||
qDebug("FeaturePresetsDialog::loadPresetSettings: preset [%s | %s]", |
||||
qPrintable(preset->getGroup()), |
||||
qPrintable(preset->getDescription())); |
||||
|
||||
m_featureUISet->loadFeatureSetSettings(preset, m_pluginAPI, m_apiAdapter); |
||||
} |
||||
|
||||
void FeaturePresetsDialog::sortFeatureSetPresets() |
||||
{ |
||||
std::sort(m_featureSetPresets->begin(), m_featureSetPresets->end(), FeatureSetPreset::presetCompare); |
||||
} |
||||
|
||||
void FeaturePresetsDialog::renamePresetGroup(const QString& oldGroupName, const QString& newGroupName) |
||||
{ |
||||
for (int i = 0; i < m_featureSetPresets->size(); i++) |
||||
{ |
||||
if (m_featureSetPresets->at(i)->getGroup() == oldGroupName) |
||||
{ |
||||
FeatureSetPreset *preset_mod = const_cast<FeatureSetPreset*>(m_featureSetPresets->at(i)); |
||||
preset_mod->setGroup(newGroupName); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void FeaturePresetsDialog::deletePreset(const FeatureSetPreset* preset) |
||||
{ |
||||
m_featureSetPresets->removeAll((FeatureSetPreset*) preset); |
||||
delete (FeatureSetPreset*) preset; |
||||
} |
||||
|
||||
void FeaturePresetsDialog::deletePresetGroup(const QString& groupName) |
||||
{ |
||||
QList<FeatureSetPreset*>::iterator it = m_featureSetPresets->begin(); |
||||
|
||||
while (it != m_featureSetPresets->end()) |
||||
{ |
||||
if ((*it)->getGroup() == groupName) { |
||||
it = m_featureSetPresets->erase(it); |
||||
} else { |
||||
++it; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,82 @@
@@ -0,0 +1,82 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2020 F4EXB //
|
||||
// written by Edouard Griffiths //
|
||||
// //
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SDRGUI_GUI_FEATUREPRESETDIALOG_H_ |
||||
#define SDRGUI_GUI_FEATUREPRESETDIALOG_H_ |
||||
|
||||
#include <QDialog> |
||||
#include <QList> |
||||
#include <QTreeWidgetItem> |
||||
|
||||
#include "export.h" |
||||
|
||||
class FeatureSetPreset; |
||||
class FeatureUISet; |
||||
class WebAPIAdapterInterface; |
||||
class PluginAPI; |
||||
|
||||
namespace Ui { |
||||
class FeaturePresetsDialog; |
||||
} |
||||
|
||||
class SDRGUI_API FeaturePresetsDialog : public QDialog { |
||||
Q_OBJECT |
||||
public: |
||||
explicit FeaturePresetsDialog(QWidget* parent = nullptr); |
||||
~FeaturePresetsDialog(); |
||||
void setPresets(QList<FeatureSetPreset*>* presets) { m_featureSetPresets = presets; } |
||||
void setFeatureUISet(FeatureUISet *featureUISet) { m_featureUISet = featureUISet; } |
||||
void setPluginAPI(PluginAPI *pluginAPI) { m_pluginAPI = pluginAPI; } |
||||
void setWebAPIAdapter(WebAPIAdapterInterface *apiAdapter) { m_apiAdapter = apiAdapter; } |
||||
void populateTree(); |
||||
|
||||
private: |
||||
enum { |
||||
PGroup, |
||||
PItem |
||||
}; |
||||
|
||||
Ui::FeaturePresetsDialog* ui; |
||||
QList<FeatureSetPreset*> *m_featureSetPresets; |
||||
FeatureUISet *m_featureUISet; |
||||
PluginAPI *m_pluginAPI; |
||||
WebAPIAdapterInterface *m_apiAdapter; |
||||
|
||||
QTreeWidgetItem* addPresetToTree(const FeatureSetPreset* preset); |
||||
void updatePresetControls(); |
||||
FeatureSetPreset* newFeatureSetPreset(const QString& group, const QString& description); |
||||
void addFeatureSetPreset(FeatureSetPreset *preset); |
||||
void savePresetSettings(FeatureSetPreset* preset); |
||||
void loadPresetSettings(const FeatureSetPreset* preset); |
||||
void sortFeatureSetPresets(); |
||||
void renamePresetGroup(const QString& oldGroupName, const QString& newGroupName); |
||||
void deletePreset(const FeatureSetPreset* preset); |
||||
void deletePresetGroup(const QString& groupName); |
||||
|
||||
private slots: |
||||
void on_presetSave_clicked(); |
||||
void on_presetUpdate_clicked(); |
||||
void on_settingsSave_clicked(); |
||||
void on_presetEdit_clicked(); |
||||
void on_presetDelete_clicked(); |
||||
void on_presetLoad_clicked(); |
||||
void on_presetTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); |
||||
void on_presetTree_itemActivated(QTreeWidgetItem *item, int column); |
||||
}; |
||||
|
||||
#endif // SDRGUI_GUI_FEATUREPRESETDIALOG_H_
|
||||
@ -0,0 +1,261 @@
@@ -0,0 +1,261 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>FeaturePresetsDialog</class> |
||||
<widget class="QDialog" name="FeaturePresetsDialog"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>392</width> |
||||
<height>414</height> |
||||
</rect> |
||||
</property> |
||||
<property name="font"> |
||||
<font> |
||||
<family>Liberation Sans</family> |
||||
<pointsize>9</pointsize> |
||||
</font> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>Feature presets</string> |
||||
</property> |
||||
<widget class="QDialogButtonBox" name="buttonBox"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>40</x> |
||||
<y>380</y> |
||||
<width>341</width> |
||||
<height>32</height> |
||||
</rect> |
||||
</property> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
<property name="standardButtons"> |
||||
<set>QDialogButtonBox::Close</set> |
||||
</property> |
||||
</widget> |
||||
<widget class="QWidget" name="widget" native="true"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>10</y> |
||||
<width>392</width> |
||||
<height>310</height> |
||||
</rect> |
||||
</property> |
||||
<layout class="QVBoxLayout" name="verticalLayout"> |
||||
<item> |
||||
<widget class="QTreeWidget" name="presetsTree"> |
||||
<property name="indentation"> |
||||
<number>5</number> |
||||
</property> |
||||
<property name="allColumnsShowFocus"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<property name="columnCount"> |
||||
<number>1</number> |
||||
</property> |
||||
<attribute name="headerMinimumSectionSize"> |
||||
<number>5</number> |
||||
</attribute> |
||||
<column> |
||||
<property name="text"> |
||||
<string>Description</string> |
||||
</property> |
||||
</column> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<widget class="QWidget" name="layoutWidget"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>330</y> |
||||
<width>392</width> |
||||
<height>34</height> |
||||
</rect> |
||||
</property> |
||||
<layout class="QHBoxLayout" name="presetsControl"> |
||||
<item> |
||||
<widget class="QToolButton" name="presetSave"> |
||||
<property name="toolTip"> |
||||
<string>Save current settings as new preset</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string>...</string> |
||||
</property> |
||||
<property name="icon"> |
||||
<iconset resource="../resources/res.qrc"> |
||||
<normaloff>:/create.png</normaloff>:/create.png</iconset> |
||||
</property> |
||||
<property name="iconSize"> |
||||
<size> |
||||
<width>16</width> |
||||
<height>16</height> |
||||
</size> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QToolButton" name="presetUpdate"> |
||||
<property name="toolTip"> |
||||
<string>Update selected preset with current settings</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string>...</string> |
||||
</property> |
||||
<property name="icon"> |
||||
<iconset resource="../resources/res.qrc"> |
||||
<normaloff>:/recycle.png</normaloff>:/recycle.png</iconset> |
||||
</property> |
||||
<property name="iconSize"> |
||||
<size> |
||||
<width>16</width> |
||||
<height>16</height> |
||||
</size> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QToolButton" name="settingsSave"> |
||||
<property name="toolTip"> |
||||
<string>Save the current settings (inc. presets)</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string>...</string> |
||||
</property> |
||||
<property name="icon"> |
||||
<iconset resource="../resources/res.qrc"> |
||||
<normaloff>:/save.png</normaloff>:/save.png</iconset> |
||||
</property> |
||||
<property name="iconSize"> |
||||
<size> |
||||
<width>16</width> |
||||
<height>16</height> |
||||
</size> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QToolButton" name="presetEdit"> |
||||
<property name="toolTip"> |
||||
<string>Edit preset details</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string/> |
||||
</property> |
||||
<property name="icon"> |
||||
<iconset resource="../resources/res.qrc"> |
||||
<normaloff>:/edit.png</normaloff>:/edit.png</iconset> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<spacer name="horizontalSpacer"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
<property name="sizeHint" stdset="0"> |
||||
<size> |
||||
<width>40</width> |
||||
<height>20</height> |
||||
</size> |
||||
</property> |
||||
</spacer> |
||||
</item> |
||||
<item> |
||||
<widget class="QToolButton" name="presetDelete"> |
||||
<property name="toolTip"> |
||||
<string>Delete selected preset</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string>...</string> |
||||
</property> |
||||
<property name="icon"> |
||||
<iconset resource="../resources/res.qrc"> |
||||
<normaloff>:/bin.png</normaloff>:/bin.png</iconset> |
||||
</property> |
||||
<property name="iconSize"> |
||||
<size> |
||||
<width>16</width> |
||||
<height>16</height> |
||||
</size> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<spacer name="horizontalSpacer_2"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
<property name="sizeHint" stdset="0"> |
||||
<size> |
||||
<width>40</width> |
||||
<height>20</height> |
||||
</size> |
||||
</property> |
||||
</spacer> |
||||
</item> |
||||
<item> |
||||
<widget class="QToolButton" name="presetLoad"> |
||||
<property name="toolTip"> |
||||
<string>Load selected preset</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string>...</string> |
||||
</property> |
||||
<property name="icon"> |
||||
<iconset resource="../resources/res.qrc"> |
||||
<normaloff>:/load.png</normaloff>:/load.png</iconset> |
||||
</property> |
||||
<property name="iconSize"> |
||||
<size> |
||||
<width>16</width> |
||||
<height>16</height> |
||||
</size> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
</widget> |
||||
<resources> |
||||
<include location="../resources/res.qrc"/> |
||||
</resources> |
||||
<connections> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>accepted()</signal> |
||||
<receiver>FeaturePresetsDialog</receiver> |
||||
<slot>accept()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>248</x> |
||||
<y>254</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>157</x> |
||||
<y>274</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>rejected()</signal> |
||||
<receiver>FeaturePresetsDialog</receiver> |
||||
<slot>reject()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>316</x> |
||||
<y>260</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>286</x> |
||||
<y>274</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
</connections> |
||||
</ui> |
||||
|
After Width: | Height: | Size: 1.0 KiB |
Loading…
Reference in new issue