aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--desktop-widgets/filterwidget2.cpp23
-rw-r--r--desktop-widgets/filterwidget2.h2
-rw-r--r--desktop-widgets/filterwidget2.ui14
3 files changed, 35 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();
diff --git a/desktop-widgets/filterwidget2.h b/desktop-widgets/filterwidget2.h
index 76d089b61..900cbdad7 100644
--- a/desktop-widgets/filterwidget2.h
+++ b/desktop-widgets/filterwidget2.h
@@ -50,6 +50,8 @@ private:
void selectPreset(int i);
void clearFilterData();
std::unique_ptr<QMenu> loadFilterPresetMenu;
+ int selectedPreset() const; // returns -1 of no preset is selected
+ void updatePresetLabel();
};
#endif
diff --git a/desktop-widgets/filterwidget2.ui b/desktop-widgets/filterwidget2.ui
index d49f21fc7..5fa0fc505 100644
--- a/desktop-widgets/filterwidget2.ui
+++ b/desktop-widgets/filterwidget2.ui
@@ -85,6 +85,20 @@
</spacer>
</item>
<item>
+ <widget class="QLabel" name="currentSetLabel">
+ <property name="text">
+ <string>Current set:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="currentSet">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QToolButton" name="addSetButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">