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>
This commit is contained in:
Berthold Stoeger 2020-09-12 09:48:25 +02:00 committed by Dirk Hohndel
parent e1c44a0a4d
commit 1ed61aeabf
3 changed files with 35 additions and 4 deletions

View file

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

View file

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

View file

@ -84,6 +84,20 @@
</property>
</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">