1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 17:28:50 -05:00

Commands: added run and delete group. Presets: added delete group.

This commit is contained in:
f4exb 2018-01-06 20:02:08 +01:00
parent 9256e6b0ed
commit eafeaa2a77
3 changed files with 116 additions and 27 deletions

View File

@ -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);

View File

@ -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(); }

View File

@ -975,23 +975,40 @@ void MainWindow::on_commandDelete_clicked()
{
QTreeWidgetItem* item = ui->commandTree->currentItem();
if(item == 0) {
return;
}
const Command* command = qvariant_cast<const Command*>(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<const Command*>(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<const Command*>(item->data(0, Qt::UserRole));
Command* command_mod = const_cast<Command*>(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<const Command*>(item->data(0, Qt::UserRole));
Command* command_mod = const_cast<Command*>(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<Command*>(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<const Preset*>(item->data(0, Qt::UserRole));
if(preset == 0)
return;
else
{
if (item->type() == PItem)
{
const Preset* preset = qvariant_cast<const Preset*>(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));
}
}
}
}
}