mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
e1c44a0a4d
commit
1ed61aeabf
3 changed files with 35 additions and 4 deletions
|
@ -128,6 +128,7 @@ void FilterWidget2::presetClicked(const QModelIndex &index)
|
||||||
|
|
||||||
void FilterWidget2::presetSelected(const QItemSelection &selected, const QItemSelection &)
|
void FilterWidget2::presetSelected(const QItemSelection &selected, const QItemSelection &)
|
||||||
{
|
{
|
||||||
|
updatePresetLabel();
|
||||||
if (selected.indexes().isEmpty())
|
if (selected.indexes().isEmpty())
|
||||||
return clearFilter();
|
return clearFilter();
|
||||||
const QModelIndex index = selected.indexes()[0];
|
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)
|
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.
|
ui.presetTable->selectionModel()->reset(); // Note: we use reset(), because that doesn't emit signals.
|
||||||
|
updatePresetLabel();
|
||||||
ui.fulltextStringMode->setCurrentIndex((int)StringFilterMode::STARTSWITH);
|
ui.fulltextStringMode->setCurrentIndex((int)StringFilterMode::STARTSWITH);
|
||||||
ui.fullText->clear();
|
ui.fullText->clear();
|
||||||
ui.presetTable->clearSelection();
|
ui.presetTable->clearSelection();
|
||||||
|
@ -197,15 +199,28 @@ void FilterWidget2::updateFilter()
|
||||||
DiveFilter::instance()->setFilter(filterData);
|
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()
|
void FilterWidget2::on_addSetButton_clicked()
|
||||||
{
|
{
|
||||||
// If there is a selected item, suggest that to the user.
|
// If there is a selected item, suggest that to the user.
|
||||||
// Thus, if the user selects an item and modify the filter,
|
// Thus, if the user selects an item and modify the filter,
|
||||||
// they can simply overwrite the preset.
|
// they can simply overwrite the preset.
|
||||||
QString selectedPreset;
|
int presetId = selectedPreset();
|
||||||
QModelIndexList selection = ui.presetTable->selectionModel()->selectedRows();
|
QString selectedPreset = presetId >= 0 ? filter_preset_name_qstring(presetId) : QString();
|
||||||
if (selection.size() == 1)
|
|
||||||
selectedPreset = filter_preset_name_qstring(selection[0].row());
|
|
||||||
|
|
||||||
AddFilterPresetDialog dialog(selectedPreset, this);
|
AddFilterPresetDialog dialog(selectedPreset, this);
|
||||||
QString name = dialog.doit();
|
QString name = dialog.doit();
|
||||||
|
|
|
@ -50,6 +50,8 @@ private:
|
||||||
void selectPreset(int i);
|
void selectPreset(int i);
|
||||||
void clearFilterData();
|
void clearFilterData();
|
||||||
std::unique_ptr<QMenu> loadFilterPresetMenu;
|
std::unique_ptr<QMenu> loadFilterPresetMenu;
|
||||||
|
int selectedPreset() const; // returns -1 of no preset is selected
|
||||||
|
void updatePresetLabel();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -84,6 +84,20 @@
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</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>
|
<item>
|
||||||
<widget class="QToolButton" name="addSetButton">
|
<widget class="QToolButton" name="addSetButton">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
|
Loading…
Add table
Reference in a new issue