Commands and presets: added possibility to rename group or merge groups. In addition for presets: added possibility to edit description

pull/127/head
f4exb 2018-01-05 11:45:20 +01:00
rodzic 5c3938753c
commit aa8e01f8ce
8 zmienionych plików z 209 dodań i 26 usunięć

Wyświetl plik

@ -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<Preset*>(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<Command*>(getCommand(i));
command_mod->setGroup(newGroupName);
}
}
}
const Command* MainSettings::getCommand(const QString& groupName, const QString& description) const
{
int nbCommands = getCommandCount();

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

@ -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 {

Wyświetl plik

@ -17,17 +17,17 @@
</font>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>Preset details</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<widget class="QGroupBox" name="descriptionBox">
<property name="title">
<string>Preset Description</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<widget class="QLabel" name="groupLabel">
<property name="text">
<string>&amp;Group</string>
</property>
@ -44,7 +44,7 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="descriptionLabel">
<property name="text">
<string>&amp;Description</string>
</property>

Wyświetl plik

@ -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<const Command*>(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*>(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<const Command*>(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<const Command*>(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<const Command*>(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<const Preset*>(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);
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<const Preset*>(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();

Wyświetl plik

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

Wyświetl plik

@ -415,7 +415,7 @@
</property>
<property name="icon">
<iconset resource="resources/res.qrc">
<normaloff>:/edit.png</normaloff>:/edit.png</iconset>
<normaloff>:/recycle.png</normaloff>:/recycle.png</iconset>
</property>
<property name="iconSize">
<size>
@ -506,6 +506,20 @@
</property>
</spacer>
</item>
<item row="5" column="4">
<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>
</layout>
</widget>
</widget>