From c797060a7dc09d17eedfc44122d8bf7b53e1361b Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 13 Apr 2022 18:43:37 +0200 Subject: [PATCH] Massive UI revamping (v7): device set presets --- sdrbase/maincore.h | 1 + sdrbase/settings/mainsettings.h | 1 + sdrgui/CMakeLists.txt | 3 + sdrgui/device/devicegui.cpp | 7 + sdrgui/device/devicegui.h | 2 + sdrgui/device/deviceuiset.h | 1 + sdrgui/gui/devicesetpresetsdialog.cpp | 468 ++++++++++++++++++++++++++ sdrgui/gui/devicesetpresetsdialog.h | 80 +++++ sdrgui/gui/devicesetpresetsdialog.ui | 264 +++++++++++++++ sdrgui/gui/featurepresetsdialog.ui | 358 ++++++++++---------- sdrgui/mainwindow.cpp | 103 +++--- sdrgui/mainwindow.h | 2 +- 12 files changed, 1066 insertions(+), 224 deletions(-) create mode 100644 sdrgui/gui/devicesetpresetsdialog.cpp create mode 100644 sdrgui/gui/devicesetpresetsdialog.h create mode 100644 sdrgui/gui/devicesetpresetsdialog.ui diff --git a/sdrbase/maincore.h b/sdrbase/maincore.h index 0c1222dd0..77a5ab322 100644 --- a/sdrbase/maincore.h +++ b/sdrbase/maincore.h @@ -744,6 +744,7 @@ public: friend class MainWindow; friend class WebAPIAdapter; friend class CommandsDialog; + friend class DeviceSetPresetsDialog; signals: void deviceSetAdded(int index, DeviceAPI *device); diff --git a/sdrbase/settings/mainsettings.h b/sdrbase/settings/mainsettings.h index cf9a7fa85..9c94b0392 100644 --- a/sdrbase/settings/mainsettings.h +++ b/sdrbase/settings/mainsettings.h @@ -46,6 +46,7 @@ public: void clearPresets(); const Preset& getWorkingPresetConst() const { return m_workingPreset; } Preset* getWorkingPreset() { return &m_workingPreset; } + QList *getPresets() { return &m_presets; } void addCommand(Command *command); void deleteCommand(const Command* command); diff --git a/sdrgui/CMakeLists.txt b/sdrgui/CMakeLists.txt index 57a90f961..f42591168 100644 --- a/sdrgui/CMakeLists.txt +++ b/sdrgui/CMakeLists.txt @@ -29,6 +29,7 @@ set(sdrgui_SOURCES gui/cwkeyergui.cpp gui/datetimedelegate.cpp gui/decimaldelegate.cpp + gui/devicesetpresetsdialog.cpp gui/devicestreamselectiondialog.cpp gui/deviceuserargsdialog.cpp gui/dmsspinbox.cpp @@ -130,6 +131,7 @@ set(sdrgui_HEADERS gui/cwkeyergui.h gui/datetimedelegate.h gui/decimaldelegate.h + gui/devicesetpresetsdialog.h gui/devicestreamselectiondialog.h gui/deviceuserargsdialog.h gui/dmsspinbox.h @@ -220,6 +222,7 @@ set(sdrgui_FORMS gui/commandoutputdialog.ui gui/configurationsdialog.ui gui/cwkeyergui.ui + gui/devicesetpresetsdialog.ui gui/devicestreamselectiondialog.ui gui/deviceuserargsdialog.ui gui/editcommanddialog.ui diff --git a/sdrgui/device/devicegui.cpp b/sdrgui/device/devicegui.cpp index 6778c168c..c4c68a84e 100644 --- a/sdrgui/device/devicegui.cpp +++ b/sdrgui/device/devicegui.cpp @@ -169,6 +169,7 @@ DeviceGUI::DeviceGUI(QWidget *parent) : connect(m_changeDeviceButton, SIGNAL(clicked()), this, SLOT(openChangeDeviceDialog())); connect(m_reloadDeviceButton, SIGNAL(clicked()), this, SLOT(deviceReload())); connect(m_addChannelsButton, SIGNAL(clicked()), this, SLOT(openAddChannelsDialog())); + connect(m_deviceSetPresetsButton, SIGNAL(clicked()), this, SLOT(deviceSetPresetsDialog())); connect(m_helpButton, SIGNAL(clicked()), this, SLOT(showHelp())); connect(m_moveButton, SIGNAL(clicked()), this, SLOT(openMoveToWorkspaceDialog())); connect(m_shrinkButton, SIGNAL(clicked()), this, SLOT(shrinkWindow())); @@ -305,6 +306,12 @@ void DeviceGUI::shrinkWindow() adjustSize(); } +void DeviceGUI::deviceSetPresetsDialog() +{ + QPoint p = mapFromGlobal(QCursor::pos()); + emit deviceSetPresetsDialogRequested(p, this); +} + void DeviceGUI::setTitle(const QString& title) { m_titleLabel->setText(title); diff --git a/sdrgui/device/devicegui.h b/sdrgui/device/devicegui.h index 61c36f8d9..f8e99e894 100644 --- a/sdrgui/device/devicegui.h +++ b/sdrgui/device/devicegui.h @@ -131,6 +131,7 @@ private slots: void openMoveToWorkspaceDialog(); void showSpectrumHandler(); void showAllChannelsHandler(); + void deviceSetPresetsDialog(); signals: void forceClose(); @@ -142,6 +143,7 @@ signals: void showSpectrum(int deviceSetIndex); void showAllChannels(int deviceSetIndex); void addChannelEmitted(int channelIndex); + void deviceSetPresetsDialogRequested(QPoint, DeviceGUI*); }; #endif // INCLUDE_DEVICEGUI_H diff --git a/sdrgui/device/deviceuiset.h b/sdrgui/device/deviceuiset.h index 3daf59524..f0e940fda 100644 --- a/sdrgui/device/deviceuiset.h +++ b/sdrgui/device/deviceuiset.h @@ -72,6 +72,7 @@ public: ~DeviceUISet(); void setIndex(int deviceSetIndex); + int getIndex() const { return m_deviceSetIndex; } GLSpectrum *getSpectrum() { return m_spectrum; } //!< Direct spectrum getter void setSpectrumScalingFactor(float scalef); void addChannelMarker(ChannelMarker* channelMarker); //!< Add channel marker to spectrum diff --git a/sdrgui/gui/devicesetpresetsdialog.cpp b/sdrgui/gui/devicesetpresetsdialog.cpp new file mode 100644 index 000000000..3bbd2077d --- /dev/null +++ b/sdrgui/gui/devicesetpresetsdialog.cpp @@ -0,0 +1,468 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2022 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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include + +#include "settings/preset.h" +#include "gui/presetitem.h" +#include "gui/addpresetdialog.h" +#include "device/deviceuiset.h" +#include "maincore.h" + +#include "devicesetpresetsdialog.h" +#include "ui_devicesetpresetsdialog.h" + +DeviceSetPresetsDialog::DeviceSetPresetsDialog(QWidget* parent) : + QDialog(parent), + ui(new Ui::DeviceSetPresetsDialog), + m_deviceSetPresets(nullptr), + m_deviceUISet(nullptr), + m_pluginAPI(nullptr), + m_currentWorkspace(nullptr), + m_workspaces(nullptr), + m_presetLoaded(false) +{ + ui->setupUi(this); +} + +DeviceSetPresetsDialog::~DeviceSetPresetsDialog() +{ + delete ui; +} + +void DeviceSetPresetsDialog::populateTree(int deviceType) +{ + if (!m_deviceSetPresets) { + return; + } + + QList::const_iterator it = m_deviceSetPresets->begin(); + QList treeItems; + ui->presetTree->clear(); + + for (int i = 0; it != m_deviceSetPresets->end(); ++it, i++) + { + if (((*it)->isSourcePreset() && (deviceType == 0)) || + ((*it)->isSinkPreset() && (deviceType == 1)) || + ((*it)->isMIMOPreset() && (deviceType == 2))) + { + QTreeWidgetItem *treeItem = addPresetToTree(*it); + treeItems.push_back(treeItem); + } + } + + if (treeItems.size() > 0) { + ui->presetTree->setCurrentItem(treeItems.at(treeItems.size()/2)); + } + + updatePresetControls(); +} + +QTreeWidgetItem* DeviceSetPresetsDialog::addPresetToTree(const Preset* preset) +{ + QTreeWidgetItem* group = 0; + + for(int i = 0; i < ui->presetTree->topLevelItemCount(); i++) + { + if(ui->presetTree->topLevelItem(i)->text(0) == preset->getGroup()) + { + group = ui->presetTree->topLevelItem(i); + break; + } + } + + if(group == 0) + { + QStringList sl; + sl.append(preset->getGroup()); + group = new QTreeWidgetItem(ui->presetTree, sl, PGroup); + group->setFirstColumnSpanned(true); + group->setExpanded(true); + ui->presetTree->sortByColumn(0, Qt::AscendingOrder); + } + + QStringList sl; + sl.append(QString("%1").arg(preset->getCenterFrequency() / 1e6f, 0, 'f', 3)); // frequency column + sl.append(QString("%1").arg(preset->isSourcePreset() ? 'R' : preset->isSinkPreset() ? 'T' : preset->isMIMOPreset() ? 'M' : 'X')); // mode column + sl.append(preset->getDescription()); // description column + PresetItem* item = new PresetItem(group, sl, preset->getCenterFrequency(), PItem); + item->setTextAlignment(0, Qt::AlignRight); + item->setData(0, Qt::UserRole, QVariant::fromValue(preset)); + ui->presetTree->resizeColumnToContents(0); // Resize frequency column to minimum + ui->presetTree->resizeColumnToContents(1); // Resize mode column to minimum + + updatePresetControls(); + return item; +} + +void DeviceSetPresetsDialog::updatePresetControls() +{ + ui->presetTree->resizeColumnToContents(0); + + if (ui->presetTree->currentItem() != 0) + { + ui->presetDelete->setEnabled(true); + ui->presetLoad->setEnabled(true); + } + else + { + ui->presetDelete->setEnabled(false); + ui->presetLoad->setEnabled(false); + } +} + +void DeviceSetPresetsDialog::on_presetSave_clicked() +{ + QStringList groups; + QString group; + QString description = ""; + + for(int i = 0; i < ui->presetTree->topLevelItemCount(); i++) { + groups.append(ui->presetTree->topLevelItem(i)->text(0)); + } + + QTreeWidgetItem* item = ui->presetTree->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) + { + Preset* preset = MainCore::instance()->m_settings.newPreset(dlg.group(), dlg.description()); + m_deviceUISet->saveDeviceSetSettings(preset); + ui->presetTree->setCurrentItem(addPresetToTree(preset)); + } + + MainCore::instance()->m_settings.sortPresets(); +} + +void DeviceSetPresetsDialog::on_presetUpdate_clicked() +{ + QTreeWidgetItem* item = ui->presetTree->currentItem(); + const Preset* changedPreset = 0; + + if(item != 0) + { + if(item->type() == PItem) + { + const Preset* preset = qvariant_cast(item->data(0, Qt::UserRole)); + + if (preset != 0) + { + Preset* preset_mod = const_cast(preset); + m_deviceUISet->saveDeviceSetSettings(preset_mod); + changedPreset = preset; + } + } + } + + MainCore::instance()->m_settings.sortPresets(); + ui->presetTree->clear(); + + for (int i = 0; i < MainCore::instance()->m_settings.getPresetCount(); ++i) + { + QTreeWidgetItem *item_x = addPresetToTree(MainCore::instance()->m_settings.getPreset(i)); + const Preset* preset_x = qvariant_cast(item_x->data(0, Qt::UserRole)); + + if (changedPreset && (preset_x == changedPreset)) { // set cursor on changed preset + ui->presetTree->setCurrentItem(item_x); + } + } +} + +void DeviceSetPresetsDialog::on_presetEdit_clicked() +{ + QTreeWidgetItem* item = ui->presetTree->currentItem(); + QStringList groups; + bool change = false; + const Preset *changedPreset = 0; + QString newGroupName; + + for(int i = 0; i < ui->presetTree->topLevelItemCount(); i++) { + groups.append(ui->presetTree->topLevelItem(i)->text(0)); + } + + if (item) + { + if (item->type() == PItem) + { + const Preset* preset = qvariant_cast(item->data(0, Qt::UserRole)); + AddPresetDialog dlg(groups, preset->getGroup(), this); + dlg.setDescription(preset->getDescription()); + + if (dlg.exec() == QDialog::Accepted) + { + Preset* preset_mod = const_cast(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) + { + MainCore::instance()->m_settings.renamePresetGroup(item->text(0), dlg.group()); + newGroupName = dlg.group(); + change = true; + } + } + } + + if (change) + { + MainCore::instance()->m_settings.sortPresets(); + ui->presetTree->clear(); + + for (int i = 0; i < MainCore::instance()->m_settings.getPresetCount(); ++i) + { + QTreeWidgetItem *item_x = addPresetToTree(MainCore::instance()->m_settings.getPreset(i)); + const Preset* preset_x = qvariant_cast(item_x->data(0, Qt::UserRole)); + + if (changedPreset && (preset_x == changedPreset)) { // set cursor on changed preset + ui->presetTree->setCurrentItem(item_x); + } + } + + if (!changedPreset) // on group name change set cursor on the group that has been changed + { + for(int i = 0; i < ui->presetTree->topLevelItemCount(); i++) + { + QTreeWidgetItem* item = ui->presetTree->topLevelItem(i); + + if (item->text(0) == newGroupName) { + ui->presetTree->setCurrentItem(item); + } + } + } + } +} + +void DeviceSetPresetsDialog::on_presetExport_clicked() +{ + QTreeWidgetItem* item = ui->presetTree->currentItem(); + + if (item) + { + if (item->type() == PItem) + { + const Preset* preset = qvariant_cast(item->data(0, Qt::UserRole)); + QString base64Str = preset->serialize().toBase64(); + QString fileName = QFileDialog::getSaveFileName( + this, + tr("Open preset export file"), + ".", + tr("Preset export files (*.prex)"), + 0, + QFileDialog::DontUseNativeDialog + ); + + if (fileName != "") + { + QFileInfo fileInfo(fileName); + + if (fileInfo.suffix() != "prex") { + fileName += ".prex"; + } + + QFile exportFile(fileName); + + if (exportFile.open(QIODevice::WriteOnly | QIODevice::Text)) + { + QTextStream outstream(&exportFile); + outstream << base64Str; + exportFile.close(); + } + else + { + QMessageBox::information(this, tr("Message"), tr("Cannot open file for writing")); + } + } + } + } +} + +void DeviceSetPresetsDialog::on_presetImport_clicked() +{ + QTreeWidgetItem* item = ui->presetTree->currentItem(); + + if (item) + { + QString group; + + if (item->type() == PGroup) { + group = item->text(0); + } else if (item->type() == PItem) { + group = item->parent()->text(0); + } else { + return; + } + + QString fileName = QFileDialog::getOpenFileName( + this, + tr("Open preset export file"), + ".", + tr("Preset export files (*.prex)"), + 0, + QFileDialog::DontUseNativeDialog + ); + + if (fileName != "") + { + QFile exportFile(fileName); + + if (exportFile.open(QIODevice::ReadOnly | QIODevice::Text)) + { + QByteArray base64Str; + QTextStream instream(&exportFile); + instream >> base64Str; + exportFile.close(); + + Preset* preset = MainCore::instance()->m_settings.newPreset("", ""); + preset->deserialize(QByteArray::fromBase64(base64Str)); + preset->setGroup(group); // override with current group + + ui->presetTree->setCurrentItem(addPresetToTree(preset)); + } + else + { + QMessageBox::information(this, tr("Message"), tr("Cannot open file for reading")); + } + } + } +} + +void DeviceSetPresetsDialog::on_presetLoad_clicked() +{ + qDebug() << "DeviceSetPresetsDialog::on_presetLoad_clicked"; + + QTreeWidgetItem* item = ui->presetTree->currentItem(); + + if (!item) + { + qDebug("DeviceSetPresetsDialog::on_presetLoad_clicked: item null"); + updatePresetControls(); + return; + } + + const Preset* preset = qvariant_cast(item->data(0, Qt::UserRole)); + + if (!preset) + { + qDebug("DeviceSetPresetsDialog::on_presetLoad_clicked: preset null"); + return; + } + + loadDeviceSetPresetSettings(preset); +} + +void DeviceSetPresetsDialog::on_presetDelete_clicked() +{ + QTreeWidgetItem* item = ui->presetTree->currentItem(); + + if (!item) + { + updatePresetControls(); + return; + } + else + { + if (item->type() == PItem) + { + const Preset* preset = qvariant_cast(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; + MainCore::instance()->m_settings.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 + ) + { + MainCore::instance()->m_settings.deletePresetGroup(item->text(0)); + + ui->presetTree->clear(); + + for (int i = 0; i < MainCore::instance()->m_settings.getPresetCount(); ++i) { + addPresetToTree(MainCore::instance()->m_settings.getPreset(i)); + } + } + } + } +} + +void DeviceSetPresetsDialog::on_presetTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) +{ + (void) current; + (void) previous; + updatePresetControls(); +} + +void DeviceSetPresetsDialog::on_presetTree_itemActivated(QTreeWidgetItem *item, int column) +{ + (void) item; + (void) column; + on_presetLoad_clicked(); +} + +void DeviceSetPresetsDialog::loadDeviceSetPresetSettings(const Preset* preset) +{ + qDebug("DeviceSetPresetsDialog::loadPresetSettings: preset [%s | %s]", + qPrintable(preset->getGroup()), + qPrintable(preset->getDescription())); + + m_deviceUISet->loadDeviceSetSettings(preset, m_pluginAPI, m_workspaces, m_currentWorkspace); + m_presetLoaded = true; +} diff --git a/sdrgui/gui/devicesetpresetsdialog.h b/sdrgui/gui/devicesetpresetsdialog.h new file mode 100644 index 000000000..c61ff1ba8 --- /dev/null +++ b/sdrgui/gui/devicesetpresetsdialog.h @@ -0,0 +1,80 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2022 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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef SDRGUI_GUI_DEVICESETPRESETDIALOG_H_ +#define SDRGUI_GUI_DEVICESETPRESETDIALOG_H_ + +#include +#include + +#include "export.h" + +class Preset; +class DeviceUISet; +class PluginAPI; +class Workspace; + +namespace Ui { + class DeviceSetPresetsDialog; +} + +class SDRGUI_API DeviceSetPresetsDialog : public QDialog { + Q_OBJECT +public: + explicit DeviceSetPresetsDialog(QWidget* parent = nullptr); + ~DeviceSetPresetsDialog(); + + void setPresets(QList* presets) { m_deviceSetPresets = presets; } + void setDeviceUISet(DeviceUISet *deviceUISet) { m_deviceUISet = deviceUISet; } + void setPluginAPI(PluginAPI *pluginAPI) { m_pluginAPI = pluginAPI; } + void setCurrentWorkspace(Workspace *workspace) { m_currentWorkspace = workspace; } + void setWorkspaces(QList *workspaces) { m_workspaces = workspaces; } + void populateTree(int deviceType); + bool wasPresetLoaded() const { return m_presetLoaded; } + +private: + enum { + PGroup, + PItem + }; + + Ui::DeviceSetPresetsDialog* ui; + QList *m_deviceSetPresets; + DeviceUISet *m_deviceUISet; + PluginAPI *m_pluginAPI; + Workspace *m_currentWorkspace; + QList *m_workspaces; + bool m_presetLoaded; + + QTreeWidgetItem* addPresetToTree(const Preset* preset); + void updatePresetControls(); + void loadDeviceSetPresetSettings(const Preset* preset); + +private slots: + void on_presetSave_clicked(); + void on_presetUpdate_clicked(); + void on_presetEdit_clicked(); + void on_presetExport_clicked(); + void on_presetImport_clicked(); + void on_presetLoad_clicked(); + void on_presetDelete_clicked(); + void on_presetTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); + void on_presetTree_itemActivated(QTreeWidgetItem *item, int column); +}; + +#endif // SDRGUI_GUI_DEVICESETPRESETDIALOG_H_ diff --git a/sdrgui/gui/devicesetpresetsdialog.ui b/sdrgui/gui/devicesetpresetsdialog.ui new file mode 100644 index 000000000..4a28cea13 --- /dev/null +++ b/sdrgui/gui/devicesetpresetsdialog.ui @@ -0,0 +1,264 @@ + + + DeviceSetPresetsDialog + + + + 0 + 0 + 396 + 396 + + + + + Liberation Sans + 9 + + + + Device Set Presets + + + + + + 10 + + + true + + + 5 + + + + Freq (MHz) + + + Center frequency in MHz + + + + + M + + + Mode: R: Rx or source, T: Tx or sink + + + + + Description + + + + + + + + + + Save current settings as new preset + + + ... + + + + :/create.png:/create.png + + + + 16 + 16 + + + + + + + + Update selected preset with current settings + + + ... + + + + :/recycle.png:/recycle.png + + + + 16 + 16 + + + + + + + + Edit preset details + + + + + + + :/edit.png:/edit.png + + + + + + + Export current preset to file + + + + + + + :/export.png:/export.png + + + + + + + Import preset from file into current group + + + + + + + :/import.png:/import.png + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Delete selected preset + + + ... + + + + :/bin.png:/bin.png + + + + 16 + 16 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Load selected preset + + + ... + + + + :/load.png:/load.png + + + + 16 + 16 + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + + + + buttonBox + accepted() + DeviceSetPresetsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DeviceSetPresetsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/sdrgui/gui/featurepresetsdialog.ui b/sdrgui/gui/featurepresetsdialog.ui index 1ee9c22f2..12d5c8f42 100644 --- a/sdrgui/gui/featurepresetsdialog.ui +++ b/sdrgui/gui/featurepresetsdialog.ui @@ -6,10 +6,16 @@ 0 0 - 392 - 414 + 376 + 399 + + + 0 + 0 + + Liberation Sans @@ -19,187 +25,175 @@ Feature presets - - - - 40 - 380 - 341 - 32 - - - - Qt::Horizontal - - - QDialogButtonBox::Close - - - - - - 0 - 10 - 392 - 310 - - - - - - - 5 - - - true - - - 1 - - - 5 - - - - Description + + + + + + 0 + 0 + + + + + + + 5 + + + true + + + 1 + + + 5 + + + + Description + + + + + + + + + + + + + Save current settings as new preset - - - - - - - - - 0 - 330 - 392 - 34 - - - - - - - Save current settings as new preset - - - ... - - - - :/create.png:/create.png - - - - 16 - 16 - - - - - - - - Update selected preset with current settings - - - ... - - - - :/recycle.png:/recycle.png - - - - 16 - 16 - - - - - - - - Edit preset details - - - - - - - :/edit.png:/edit.png - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Delete selected preset - - - ... - - - - :/bin.png:/bin.png - - - - 16 - 16 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Load selected preset - - - ... - - - - :/load.png:/load.png - - - - 16 - 16 - - - - - - + + ... + + + + :/create.png:/create.png + + + + 16 + 16 + + + + + + + + Update selected preset with current settings + + + ... + + + + :/recycle.png:/recycle.png + + + + 16 + 16 + + + + + + + + Edit preset details + + + + + + + :/edit.png:/edit.png + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Delete selected preset + + + ... + + + + :/bin.png:/bin.png + + + + 16 + 16 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Load selected preset + + + ... + + + + :/load.png:/load.png + + + + 16 + 16 + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index 5570df766..467590ca7 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -66,6 +66,7 @@ #include "gui/ambedevicesdialog.h" #include "gui/workspace.h" #include "gui/featurepresetsdialog.h" +#include "gui/devicesetpresetsdialog.h" #include "gui/commandsdialog.h" #include "gui/configurationsdialog.h" #include "dsp/dspengine.h" @@ -542,6 +543,12 @@ void MainWindow::sampleSourceCreate( this, [=](){ this->removeDeviceSet(deviceGUI->getIndex()); } ); + QObject::connect( + deviceGUI, + &DeviceGUI::deviceSetPresetsDialogRequested, + this, + &MainWindow::openDeviceSetPresetsDialog + ); deviceAPI->getSampleSource()->setMessageQueueToGUI(deviceGUI->getInputMessageQueue()); deviceUISet->m_deviceGUI = deviceGUI; @@ -753,6 +760,13 @@ void MainWindow::sampleSinkCreate( this, [=](){ this->removeDeviceSet(deviceGUI->getIndex()); } ); + QObject::connect( + deviceGUI, + &DeviceGUI::deviceSetPresetsDialogRequested, + this, + &MainWindow::openDeviceSetPresetsDialog + ); + deviceAPI->getSampleSink()->setMessageQueueToGUI(deviceGUI->getInputMessageQueue()); deviceUISet->m_deviceGUI = deviceGUI; const PluginInterface::SamplingDevice *selectedDevice = DeviceEnumerator::instance()->getRxSamplingDevice(selectedDeviceIndex); @@ -937,6 +951,13 @@ void MainWindow::sampleMIMOCreate( this, [=](){ this->removeDeviceSet(deviceGUI->getIndex()); } ); + QObject::connect( + deviceGUI, + &DeviceGUI::deviceSetPresetsDialogRequested, + this, + &MainWindow::openDeviceSetPresetsDialog + ); + deviceAPI->getSampleMIMO()->setMessageQueueToGUI(deviceGUI->getInputMessageQueue()); deviceUISet->m_deviceGUI = deviceGUI; const PluginInterface::SamplingDevice *selectedDevice = DeviceEnumerator::instance()->getRxSamplingDevice(selectedDeviceIndex); @@ -1591,44 +1612,6 @@ void MainWindow::updatePresetControls() // } } -QTreeWidgetItem* MainWindow::addPresetToTree(const Preset* preset) -{ - // QTreeWidgetItem* group = 0; - - // for(int i = 0; i < ui->presetTree->topLevelItemCount(); i++) - // { - // if(ui->presetTree->topLevelItem(i)->text(0) == preset->getGroup()) - // { - // group = ui->presetTree->topLevelItem(i); - // break; - // } - // } - - // if(group == 0) - // { - // QStringList sl; - // sl.append(preset->getGroup()); - // group = new QTreeWidgetItem(ui->presetTree, sl, PGroup); - // group->setFirstColumnSpanned(true); - // group->setExpanded(true); - // ui->presetTree->sortByColumn(0, Qt::AscendingOrder); - // } - - // QStringList sl; - // sl.append(QString("%1").arg(preset->getCenterFrequency() / 1e6f, 0, 'f', 3)); // frequency column - // sl.append(QString("%1").arg(preset->isSourcePreset() ? 'R' : preset->isSinkPreset() ? 'T' : preset->isMIMOPreset() ? 'M' : 'X')); // mode column - // sl.append(preset->getDescription()); // description column - // PresetItem* item = new PresetItem(group, sl, preset->getCenterFrequency(), PItem); - // item->setTextAlignment(0, Qt::AlignRight); - // item->setData(0, Qt::UserRole, QVariant::fromValue(preset)); - // ui->presetTree->resizeColumnToContents(0); // Resize frequency column to minimum - // ui->presetTree->resizeColumnToContents(1); // Resize mode column to minimum - - // updatePresetControls(); - // return item; - return nullptr; -} - void MainWindow::applySettings() { // loadDeviceSetPresetSettings(m_mainCore->m_settings.getWorkingPreset(), 0); @@ -1664,7 +1647,15 @@ bool MainWindow::handleMessage(const Message& cmd) if (MainCore::MsgLoadPreset::match(cmd)) { MainCore::MsgLoadPreset& notif = (MainCore::MsgLoadPreset&) cmd; - loadDeviceSetPresetSettings(notif.getPreset(), notif.getDeviceSetIndex()); + int deviceSetIndex = notif.getDeviceSetIndex(); + const Preset *preset = notif.getPreset(); + + if (deviceSetIndex < (int) m_deviceUIs.size()) + { + DeviceUISet *deviceUISet = m_deviceUIs[deviceSetIndex]; + deviceUISet->loadDeviceSetSettings(preset, m_pluginManager->getPluginAPI(), &m_workspaces, nullptr); + } + return true; } else if (MainCore::MsgSavePreset::match(cmd)) @@ -2303,14 +2294,14 @@ void MainWindow::on_presetTree_currentItemChanged(QTreeWidgetItem *current, QTre { (void) current; (void) previous; - updatePresetControls(); + // updatePresetControls(); } void MainWindow::on_presetTree_itemActivated(QTreeWidgetItem *item, int column) { (void) item; (void) column; - on_presetLoad_clicked(); + // on_presetLoad_clicked(); } void MainWindow::on_action_Quick_Start_triggered() @@ -2787,6 +2778,36 @@ void MainWindow::openFeaturePresetsDialog(QPoint p, Workspace *workspace) } } +void MainWindow::openDeviceSetPresetsDialog(QPoint p, DeviceGUI *deviceGUI) +{ + Workspace *workspace = m_workspaces[deviceGUI->getWorkspaceIndex()]; + DeviceUISet *deviceUISet = m_deviceUIs[deviceGUI->getIndex()]; + + DeviceSetPresetsDialog dialog; + dialog.setDeviceUISet(deviceUISet); + dialog.setPresets(m_mainCore->m_settings.getPresets()); + dialog.setPluginAPI(m_pluginManager->getPluginAPI()); + dialog.setCurrentWorkspace(workspace); + dialog.setWorkspaces(&m_workspaces); + dialog.populateTree((int) deviceGUI->getDeviceType()); + dialog.move(p); + dialog.exec(); + + // if (dialog.wasPresetLoaded()) + // { + // for (int i = 0; i < m_featureUIs[0]->getNumberOfFeatures(); i++) + // { + // FeatureGUI *gui = m_featureUIs[0]->getFeatureGuiAt(i); + // QObject::connect( + // gui, + // &FeatureGUI::moveToWorkspace, + // this, + // [=](int wsIndexDest){ this->featureMove(gui, wsIndexDest); } + // ); + // } + // } +} + void MainWindow::deleteFeature(int featureSetIndex, int featureIndex) { if ((featureSetIndex >= 0) && (featureSetIndex < (int) m_featureUIs.size())) diff --git a/sdrgui/mainwindow.h b/sdrgui/mainwindow.h index 174d5f366..3cff9ce7c 100644 --- a/sdrgui/mainwindow.h +++ b/sdrgui/mainwindow.h @@ -138,7 +138,6 @@ private: void createStatusBar(); void closeEvent(QCloseEvent*); void updatePresetControls(); - QTreeWidgetItem* addPresetToTree(const Preset* preset); void applySettings(); void removeDeviceSet(int deviceSetIndex); @@ -215,6 +214,7 @@ private slots: void mainSpectrumMove(MainSpectrumGUI *gui, int wsIndexDestnation); void mainSpectrumShow(MainSpectrumGUI *gui); void showAllChannels(int deviceSetIndex); + void openDeviceSetPresetsDialog(QPoint p, DeviceGUI *deviceGUI); void on_action_Quick_Start_triggered(); void on_action_Main_Window_triggered(); void on_action_Loaded_Plugins_triggered();