From d064f786088ff2aeb44a5b82b3d9743d0d978fc0 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 6 Sep 2020 23:53:31 +0200 Subject: filter: when a filter preset is selected, suggest its name on save The goal here is to let the user edit already existing sets and save them using their old name. This is a stop-gap measure until we get a proper filter-set editing interface. Signed-off-by: Berthold Stoeger --- desktop-widgets/filterwidget2.cpp | 10 +++++++++- desktop-widgets/simplewidgets.cpp | 3 ++- desktop-widgets/simplewidgets.h | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/desktop-widgets/filterwidget2.cpp b/desktop-widgets/filterwidget2.cpp index 26cb05c2a..29a024d14 100644 --- a/desktop-widgets/filterwidget2.cpp +++ b/desktop-widgets/filterwidget2.cpp @@ -198,7 +198,15 @@ void FilterWidget2::updateFilter() void FilterWidget2::on_addSetButton_clicked() { - AddFilterPresetDialog dialog(this); + // If there is a selected item, suggest that to the user. + // Thus, if the user selects an item and modify the filter, + // they can simply overwrite the preset. + QString selectedPreset; + QModelIndexList selection = ui.presetTable->selectionModel()->selectedRows(); + if (selection.size() == 1) + selectedPreset = filter_preset_name_qstring(selection[0].row()); + + AddFilterPresetDialog dialog(selectedPreset, this); QString name = dialog.doit(); if (name.isEmpty()) return; diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp index bbce159b6..6eaab2eef 100644 --- a/desktop-widgets/simplewidgets.cpp +++ b/desktop-widgets/simplewidgets.cpp @@ -480,9 +480,10 @@ void DiveComponentSelection::buttonClicked(QAbstractButton *button) } } -AddFilterPresetDialog::AddFilterPresetDialog(QWidget *parent) +AddFilterPresetDialog::AddFilterPresetDialog(const QString &defaultName, QWidget *parent) { ui.setupUi(this); + ui.name->setText(defaultName); connect(ui.name, &QLineEdit::textChanged, this, &AddFilterPresetDialog::nameChanged); connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &AddFilterPresetDialog::accept); connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &AddFilterPresetDialog::reject); diff --git a/desktop-widgets/simplewidgets.h b/desktop-widgets/simplewidgets.h index d68c14bd4..c88ddd5f4 100644 --- a/desktop-widgets/simplewidgets.h +++ b/desktop-widgets/simplewidgets.h @@ -142,7 +142,7 @@ private: class AddFilterPresetDialog : public QDialog { Q_OBJECT public: - explicit AddFilterPresetDialog(QWidget *parent); + explicit AddFilterPresetDialog(const QString &defaultName, QWidget *parent); QString doit(); // returns name of filter preset or empty string if user cancelled the dialog private slots: -- cgit v1.2.3-70-g09d2