aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets/filterwidget2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'desktop-widgets/filterwidget2.cpp')
-rw-r--r--desktop-widgets/filterwidget2.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/desktop-widgets/filterwidget2.cpp b/desktop-widgets/filterwidget2.cpp
index 7b06a42b1..80718c64e 100644
--- a/desktop-widgets/filterwidget2.cpp
+++ b/desktop-widgets/filterwidget2.cpp
@@ -128,6 +128,7 @@ void FilterWidget2::presetClicked(const QModelIndex &index)
void FilterWidget2::presetSelected(const QItemSelection &selected, const QItemSelection &)
{
+ updatePresetLabel();
if (selected.indexes().isEmpty())
return clearFilter();
const QModelIndex index = selected.indexes()[0];
@@ -160,6 +161,7 @@ void FilterWidget2::clearFilter()
{
ignoreSignal = true; // Prevent signals to force filter recalculation (TODO: check if necessary)
ui.presetTable->selectionModel()->reset(); // Note: we use reset(), because that doesn't emit signals.
+ updatePresetLabel();
ui.fulltextStringMode->setCurrentIndex((int)StringFilterMode::STARTSWITH);
ui.fullText->clear();
ui.presetTable->clearSelection();
@@ -197,15 +199,28 @@ void FilterWidget2::updateFilter()
DiveFilter::instance()->setFilter(filterData);
}
+int FilterWidget2::selectedPreset() const
+{
+ QModelIndexList selection = ui.presetTable->selectionModel()->selectedRows();
+ return selection.size() >= 1 ? selection[0].row() : -1;
+}
+
+void FilterWidget2::updatePresetLabel()
+{
+ int presetId = selectedPreset();
+ QString text;
+ if (presetId >= 0)
+ text = filter_preset_name_qstring(presetId);
+ ui.currentSet->setText(text);
+}
+
void FilterWidget2::on_addSetButton_clicked()
{
// 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());
+ int presetId = selectedPreset();
+ QString selectedPreset = presetId >= 0 ? filter_preset_name_qstring(presetId) : QString();
AddFilterPresetDialog dialog(selectedPreset, this);
QString name = dialog.doit();