From aa8e01f8ced499962c96444e6ffa242c6111e528 Mon Sep 17 00:00:00 2001 From: f4exb Date: Fri, 5 Jan 2018 11:45:20 +0100 Subject: [PATCH] Commands and presets: added possibility to rename group or merge groups. In addition for presets: added possibility to edit description --- sdrbase/settings/mainsettings.cpp | 28 ++++++ sdrbase/settings/mainsettings.h | 2 + sdrgui/gui/addpresetdialog.cpp | 20 +++- sdrgui/gui/addpresetdialog.h | 7 +- sdrgui/gui/addpresetdialog.ui | 8 +- sdrgui/mainwindow.cpp | 153 ++++++++++++++++++++++++++---- sdrgui/mainwindow.h | 1 + sdrgui/mainwindow.ui | 16 +++- 8 files changed, 209 insertions(+), 26 deletions(-) diff --git a/sdrbase/settings/mainsettings.cpp b/sdrbase/settings/mainsettings.cpp index 7e4a15a37..735f1059d 100644 --- a/sdrbase/settings/mainsettings.cpp +++ b/sdrbase/settings/mainsettings.cpp @@ -138,6 +138,20 @@ void MainSettings::sortPresets() qSort(m_presets.begin(), m_presets.end(), Preset::presetCompare); } +void MainSettings::renamePresetGroup(const QString& oldGroupName, const QString& newGroupName) +{ + int nbPresets = getPresetCount(); + + for (int i = 0; i < nbPresets; i++) + { + if (getPreset(i)->getGroup() == oldGroupName) + { + Preset *preset_mod = const_cast(getPreset(i)); + preset_mod->setGroup(newGroupName); + } + } +} + const Preset* MainSettings::getPreset(const QString& groupName, quint64 centerFrequency, const QString& description) const { int nbPresets = getPresetCount(); @@ -171,6 +185,20 @@ void MainSettings::sortCommands() qSort(m_commands.begin(), m_commands.end(), Command::commandCompare); } +void MainSettings::renameCommandGroup(const QString& oldGroupName, const QString& newGroupName) +{ + int nbCommands = getCommandCount(); + + for (int i = 0; i < nbCommands; i++) + { + if (getCommand(i)->getGroup() == oldGroupName) + { + Command *command_mod = const_cast(getCommand(i)); + command_mod->setGroup(newGroupName); + } + } +} + const Command* MainSettings::getCommand(const QString& groupName, const QString& description) const { int nbCommands = getCommandCount(); diff --git a/sdrbase/settings/mainsettings.h b/sdrbase/settings/mainsettings.h index 6edb0c98a..a579df8e6 100644 --- a/sdrbase/settings/mainsettings.h +++ b/sdrbase/settings/mainsettings.h @@ -24,6 +24,7 @@ public: const Preset* getPreset(int index) const { return m_presets[index]; } const Preset* getPreset(const QString& groupName, quint64 centerFrequency, const QString& description) const; void sortPresets(); + void renamePresetGroup(const QString& oldGroupName, const QString& newGroupName); void addCommand(Command *command); void deleteCommand(const Command* command); @@ -31,6 +32,7 @@ public: const Command* getCommand(int index) const { return m_commands[index]; } const Command* getCommand(const QString& groupName, const QString& description) const; void sortCommands(); + void renameCommandGroup(const QString& oldGroupName, const QString& newGroupName); Preset* getWorkingPreset() { return &m_workingPreset; } int getSourceIndex() const { return m_preferences.getSourceIndex(); } diff --git a/sdrgui/gui/addpresetdialog.cpp b/sdrgui/gui/addpresetdialog.cpp index 390fae2f6..87bf1ad73 100644 --- a/sdrgui/gui/addpresetdialog.cpp +++ b/sdrgui/gui/addpresetdialog.cpp @@ -25,12 +25,28 @@ QString AddPresetDialog::description() const return ui->description->text(); } -void AddPresetDialog::setGroup(QString& group) +void AddPresetDialog::setGroup(const QString& group) { ui->group->lineEdit()->setText(group); } -void AddPresetDialog::setDescription(QString& description) +void AddPresetDialog::setDescription(const QString& description) { ui->description->setText(description); } + +void AddPresetDialog::showGroupOnly() +{ + ui->description->hide(); + ui->descriptionLabel->hide(); +} + +void AddPresetDialog::setDialogTitle(const QString& title) +{ + setWindowTitle(title); +} + +void AddPresetDialog::setDescriptionBoxTitle(const QString& title) +{ + ui->descriptionBox->setTitle(title); +} diff --git a/sdrgui/gui/addpresetdialog.h b/sdrgui/gui/addpresetdialog.h index 0273544ce..dea9f7bd1 100644 --- a/sdrgui/gui/addpresetdialog.h +++ b/sdrgui/gui/addpresetdialog.h @@ -16,8 +16,11 @@ public: QString group() const; QString description() const; - void setGroup(QString& group); - void setDescription(QString& description); + void setGroup(const QString& group); + void setDescription(const QString& description); + void showGroupOnly(); + void setDialogTitle(const QString& title); + void setDescriptionBoxTitle(const QString& title); private: enum Audio { diff --git a/sdrgui/gui/addpresetdialog.ui b/sdrgui/gui/addpresetdialog.ui index 66a3d765d..e53bafc8a 100644 --- a/sdrgui/gui/addpresetdialog.ui +++ b/sdrgui/gui/addpresetdialog.ui @@ -17,17 +17,17 @@ - Dialog + Preset details - + Preset Description - + &Group @@ -44,7 +44,7 @@ - + &Description diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index 9159a527b..2d781bd0f 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -882,21 +882,24 @@ void MainWindow::on_commandDuplicate_clicked() void MainWindow::on_commandEdit_clicked() { QTreeWidgetItem* item = ui->commandTree->currentItem(); + bool change = false; + const Command *changedCommand = 0; + QString newGroupName; + + QStringList groups; + + for(int i = 0; i < ui->commandTree->topLevelItemCount(); i++) { + groups.append(ui->commandTree->topLevelItem(i)->text(0)); + } if(item != 0) { - if(item->type() == PItem) + if (item->type() == PItem) { const Command* command = qvariant_cast(item->data(0, Qt::UserRole)); if (command != 0) { - QStringList groups; - - for(int i = 0; i < ui->commandTree->topLevelItemCount(); i++) { - groups.append(ui->commandTree->topLevelItem(i)->text(0)); - } - EditCommandDialog editCommandDialog(groups, command->getGroup(), this); editCommandDialog.fromCommand(*command); @@ -904,18 +907,62 @@ void MainWindow::on_commandEdit_clicked() { Command* command_mod = const_cast(command); editCommandDialog.toCommand(*command_mod); - m_settings.sortCommands(); + change = true; + changedCommand = command; +// +// m_settings.sortCommands(); +// +// ui->commandTree->clear(); +// +// for (int i = 0; i < m_settings.getCommandCount(); ++i) +// { +// QTreeWidgetItem *item_x = addCommandToTree(m_settings.getCommand(i)); +// const Command* command_x = qvariant_cast(item_x->data(0, Qt::UserRole)); +// if (command_x == command_mod) { +// ui->commandTree->setCurrentItem(item_x); +// } +// } + } + } + } + else if (item->type() == PGroup) + { + AddPresetDialog dlg(groups, item->text(0), this); + dlg.showGroupOnly(); + dlg.setDialogTitle("Edit command group"); + dlg.setDescriptionBoxTitle("Command details"); - ui->commandTree->clear(); + if (dlg.exec() == QDialog::Accepted) + { + m_settings.renameCommandGroup(item->text(0), dlg.group()); + newGroupName = dlg.group(); + change = true; + } + } + } - for (int i = 0; i < m_settings.getCommandCount(); ++i) - { - QTreeWidgetItem *item_x = addCommandToTree(m_settings.getCommand(i)); - const Command* command_x = qvariant_cast(item_x->data(0, Qt::UserRole)); - if (command_x == command_mod) { - ui->commandTree->setCurrentItem(item_x); - } - } + if (change) + { + m_settings.sortCommands(); + ui->commandTree->clear(); + + for (int i = 0; i < m_settings.getCommandCount(); ++i) + { + QTreeWidgetItem *item_x = addCommandToTree(m_settings.getCommand(i)); + const Command* command_x = qvariant_cast(item_x->data(0, Qt::UserRole)); + if (changedCommand && (command_x == changedCommand)) { // set cursor on changed command + ui->commandTree->setCurrentItem(item_x); + } + } + + if (!changedCommand) // on group name change set cursor on the group that has been changed + { + for(int i = 0; i < ui->commandTree->topLevelItemCount(); i++) + { + QTreeWidgetItem* item = ui->commandTree->topLevelItem(i); + + if (item->text(0) == newGroupName) { + ui->commandTree->setCurrentItem(item); } } } @@ -1048,6 +1095,78 @@ void MainWindow::on_presetUpdate_clicked() m_settings.sortPresets(); } +void MainWindow::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 != 0) + { + 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) + { + m_settings.renamePresetGroup(item->text(0), dlg.group()); + newGroupName = dlg.group(); + change = true; + } + } + } + + if (change) + { + m_settings.sortPresets(); + ui->presetTree->clear(); + + for (int i = 0; i < m_settings.getPresetCount(); ++i) + { + QTreeWidgetItem *item_x = addPresetToTree(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 MainWindow::on_presetExport_clicked() { QTreeWidgetItem* item = ui->presetTree->currentItem(); diff --git a/sdrgui/mainwindow.h b/sdrgui/mainwindow.h index b40b6ad39..0d18a8073 100644 --- a/sdrgui/mainwindow.h +++ b/sdrgui/mainwindow.h @@ -340,6 +340,7 @@ private slots: void on_action_View_Fullscreen_toggled(bool checked); void on_presetSave_clicked(); void on_presetUpdate_clicked(); + void on_presetEdit_clicked(); void on_presetExport_clicked(); void on_presetImport_clicked(); void on_settingsSave_clicked(); diff --git a/sdrgui/mainwindow.ui b/sdrgui/mainwindow.ui index 0ea1e1c7a..e3c57a155 100644 --- a/sdrgui/mainwindow.ui +++ b/sdrgui/mainwindow.ui @@ -415,7 +415,7 @@ - :/edit.png:/edit.png + :/recycle.png:/recycle.png @@ -506,6 +506,20 @@ + + + + Edit preset details + + + + + + + :/edit.png:/edit.png + + +