From eafeaa2a774c34eb735cafff5f57250e9d4393ec Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 6 Jan 2018 20:02:08 +0100 Subject: [PATCH] Commands: added run and delete group. Presets: added delete group. --- sdrbase/settings/mainsettings.cpp | 28 ++++++++ sdrbase/settings/mainsettings.h | 2 + sdrgui/mainwindow.cpp | 113 +++++++++++++++++++++++------- 3 files changed, 116 insertions(+), 27 deletions(-) diff --git a/sdrbase/settings/mainsettings.cpp b/sdrbase/settings/mainsettings.cpp index 735f1059d..675bf97e1 100644 --- a/sdrbase/settings/mainsettings.cpp +++ b/sdrbase/settings/mainsettings.cpp @@ -133,6 +133,20 @@ void MainSettings::deletePreset(const Preset* preset) delete (Preset*)preset; } +void MainSettings::deletePresetGroup(const QString& groupName) +{ + Presets::iterator it = m_presets.begin(); + + while (it != m_presets.end()) + { + if ((*it)->getGroup() == groupName) { + it = m_presets.erase(it); + } else { + ++it; + } + } +} + void MainSettings::sortPresets() { qSort(m_presets.begin(), m_presets.end(), Preset::presetCompare); @@ -180,6 +194,20 @@ void MainSettings::deleteCommand(const Command* command) delete (Command*)command; } +void MainSettings::deleteCommandGroup(const QString& groupName) +{ + Commands::iterator it = m_commands.begin(); + + while (it != m_commands.end()) + { + if ((*it)->getGroup() == groupName) { + it = m_commands.erase(it); + } else { + ++it; + } + } +} + void MainSettings::sortCommands() { qSort(m_commands.begin(), m_commands.end(), Command::commandCompare); diff --git a/sdrbase/settings/mainsettings.h b/sdrbase/settings/mainsettings.h index a579df8e6..d200b8865 100644 --- a/sdrbase/settings/mainsettings.h +++ b/sdrbase/settings/mainsettings.h @@ -25,6 +25,7 @@ public: const Preset* getPreset(const QString& groupName, quint64 centerFrequency, const QString& description) const; void sortPresets(); void renamePresetGroup(const QString& oldGroupName, const QString& newGroupName); + void deletePresetGroup(const QString& groupName); void addCommand(Command *command); void deleteCommand(const Command* command); @@ -33,6 +34,7 @@ public: const Command* getCommand(const QString& groupName, const QString& description) const; void sortCommands(); void renameCommandGroup(const QString& oldGroupName, const QString& newGroupName); + void deleteCommandGroup(const QString& groupName); Preset* getWorkingPreset() { return &m_workingPreset; } int getSourceIndex() const { return m_preferences.getSourceIndex(); } diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index 6ae3d926c..740be0f22 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -975,23 +975,40 @@ void MainWindow::on_commandDelete_clicked() { QTreeWidgetItem* item = ui->commandTree->currentItem(); - if(item == 0) { - return; - } - - const Command* command = qvariant_cast(item->data(0, Qt::UserRole)); - - if(command == 0) { - return; - } - - if (QMessageBox::question(this, - tr("Delete command"), - tr("Do you want to delete command '%1'?") - .arg(command->getDescription()), QMessageBox::No | QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) + if (item != 0) { - delete item; - m_settings.deleteCommand(command); + if (item->type() == PItem) // delete individual command + { + const Command* command = qvariant_cast(item->data(0, Qt::UserRole)); + + if(command) + { + if (QMessageBox::question(this, + tr("Delete command"), + tr("Do you want to delete command '%1'?") + .arg(command->getDescription()), QMessageBox::No | QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) + { + delete item; + m_settings.deleteCommand(command); + } + } + } + else if (item->type() == PGroup) // delete all commands in this group + { + if (QMessageBox::question(this, + tr("Delete command group"), + tr("Do you want to delete command group '%1'?") + .arg(item->text(0)), QMessageBox::No | QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) + { + m_settings.deleteCommandGroup(item->text(0)); + + ui->commandTree->clear(); + + for (int i = 0; i < m_settings.getCommandCount(); ++i) { + addCommandToTree(m_settings.getCommand(i)); + } + } + } } } @@ -999,12 +1016,29 @@ void MainWindow::on_commandRun_clicked() { QTreeWidgetItem* item = ui->commandTree->currentItem(); - if ((item != 0) && (item->type() == PItem)) + if (item != 0) { - const Command* command = qvariant_cast(item->data(0, Qt::UserRole)); - Command* command_mod = const_cast(command); int currentDeviceSetIndex = ui->tabInputsSelect->currentIndex(); - command_mod->run(m_apiServer->getHost(), m_apiServer->getPort(), currentDeviceSetIndex); + + if (item->type() == PItem) // run individual command + { + const Command* command = qvariant_cast(item->data(0, Qt::UserRole)); + Command* command_mod = const_cast(command); + command_mod->run(m_apiServer->getHost(), m_apiServer->getPort(), currentDeviceSetIndex); + } + else if (item->type() == PGroup) // run all commands in this group + { + QString group = item->text(0); + + for (int i = 0; i < m_settings.getCommandCount(); ++i) + { + Command *command_mod = const_cast(m_settings.getCommand(i)); + + if (command_mod->getGroup() == group) { + command_mod->run(m_apiServer->getHost(), m_apiServer->getPort(), currentDeviceSetIndex); + } + } + } } } @@ -1302,17 +1336,42 @@ void MainWindow::on_presetLoad_clicked() void MainWindow::on_presetDelete_clicked() { QTreeWidgetItem* item = ui->presetTree->currentItem(); - if(item == 0) { + + if (item == 0) + { updatePresetControls(); return; } - const Preset* preset = qvariant_cast(item->data(0, Qt::UserRole)); - if(preset == 0) - return; + else + { + if (item->type() == PItem) + { + const Preset* preset = qvariant_cast(item->data(0, Qt::UserRole)); - 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; - m_settings.deletePreset(preset); + 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; + 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) + { + m_settings.deletePresetGroup(item->text(0)); + + ui->commandTree->clear(); + + for (int i = 0; i < m_settings.getPresetCount(); ++i) { + addPresetToTree(m_settings.getPreset(i)); + } + } + } } }