summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/filterwidget2.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-09-12 09:48:25 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-09-29 16:13:03 -0700
commit1ed61aeabfd2e28dc60d60f5af2253dd8b8e235a (patch)
tree1d6a9bfe94b190371a50f2821709061fde0f14d0 /desktop-widgets/filterwidget2.cpp
parente1c44a0a4db12ec9fa36c84b7b457d3957059b60 (diff)
downloadsubsurface-1ed61aeabfd2e28dc60d60f5af2253dd8b8e235a.tar.gz
filter: show currently selected preset in a text field
This provides some visual feedback on the currently selected preset. Update when changing selection or clearing the filter. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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();