mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Selection: provide convenience function for single-dive selection
Currently, selecting a single dive or deselecting all dives was quite awkward: One had to pass in a single-dive vector and the dive itself (as current dive). Provide a convenience function that selects a single dive or deselects all dives if null is passed in. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
84394adb11
commit
f4f9ba9263
3 changed files with 12 additions and 6 deletions
|
@ -574,10 +574,7 @@ void DeleteDive::redoit()
|
||||||
timestamp_t when = divesToAdd.dives[0].dive->when;
|
timestamp_t when = divesToAdd.dives[0].dive->when;
|
||||||
newCurrent = find_next_visible_dive(when);
|
newCurrent = find_next_visible_dive(when);
|
||||||
}
|
}
|
||||||
if (newCurrent)
|
select_single_dive(newCurrent);
|
||||||
setSelection(std::vector<dive *>{ newCurrent }, newCurrent);
|
|
||||||
else
|
|
||||||
setSelection(std::vector<dive *>(), nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -195,6 +195,14 @@ void setSelection(const std::vector<dive *> &selection, dive *currentDive)
|
||||||
emit diveListNotifier.divesSelected(divesToSelect, current_dive);
|
emit diveListNotifier.divesSelected(divesToSelect, current_dive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" void select_single_dive(dive *d)
|
||||||
|
{
|
||||||
|
if (d)
|
||||||
|
setSelection(std::vector<dive *>{ d }, d);
|
||||||
|
else
|
||||||
|
setSelection(std::vector<dive *>(), nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
// Turn current selection into a vector.
|
// Turn current selection into a vector.
|
||||||
// TODO: This could be made much more efficient if we kept a sorted list of selected dives!
|
// TODO: This could be made much more efficient if we kept a sorted list of selected dives!
|
||||||
std::vector<dive *> getDiveSelection()
|
std::vector<dive *> getDiveSelection()
|
||||||
|
@ -217,9 +225,9 @@ extern "C" void select_newest_visible_dive()
|
||||||
for (int i = dive_table.nr - 1; i >= 0; --i) {
|
for (int i = dive_table.nr - 1; i >= 0; --i) {
|
||||||
dive *d = dive_table.dives[i];
|
dive *d = dive_table.dives[i];
|
||||||
if (!d->hidden_by_filter)
|
if (!d->hidden_by_filter)
|
||||||
return setSelection({ d }, d);
|
return select_single_dive(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
// No visible dive -> deselect all
|
// No visible dive -> deselect all
|
||||||
setSelection({}, nullptr);
|
select_single_dive(nullptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ extern struct dive *first_selected_dive(void);
|
||||||
extern struct dive *last_selected_dive(void);
|
extern struct dive *last_selected_dive(void);
|
||||||
extern bool consecutive_selected(void);
|
extern bool consecutive_selected(void);
|
||||||
extern void select_newest_visible_dive();
|
extern void select_newest_visible_dive();
|
||||||
|
extern void select_single_dive(struct dive *d); // wrapper for setSelection() with a single dive. NULL clears the selection.
|
||||||
|
|
||||||
#if DEBUG_SELECTION_TRACKING
|
#if DEBUG_SELECTION_TRACKING
|
||||||
extern void dump_selection(void);
|
extern void dump_selection(void);
|
||||||
|
|
Loading…
Reference in a new issue