mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 21:23:24 +00:00
core: make find_next_visible_dive() member of dive_table
This function implicitely accessed the global divelog. To make that explicit make it a member of dive_table, such that the caller must access it via the global variable. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
4afefb1b9b
commit
e9a57ac5f5
4 changed files with 8 additions and 10 deletions
|
@ -600,7 +600,7 @@ void DeleteDive::redoit()
|
|||
dive *newCurrent = nullptr;
|
||||
if (!divesToAdd.dives.empty()) {
|
||||
timestamp_t when = divesToAdd.dives[0].dive->when;
|
||||
newCurrent = find_next_visible_dive(when);
|
||||
newCurrent = divelog.dives.find_next_visible_dive(when);
|
||||
}
|
||||
select_single_dive(newCurrent);
|
||||
}
|
||||
|
|
|
@ -1288,21 +1288,18 @@ timestamp_t get_surface_interval(timestamp_t when)
|
|||
|
||||
/* Find visible dive close to given date. First search towards older,
|
||||
* then newer dives. */
|
||||
struct dive *find_next_visible_dive(timestamp_t when)
|
||||
struct dive *dive_table::find_next_visible_dive(timestamp_t when)
|
||||
{
|
||||
if (divelog.dives.empty())
|
||||
return nullptr;
|
||||
|
||||
/* we might want to use binary search here */
|
||||
auto it = std::find_if(divelog.dives.begin(), divelog.dives.end(),
|
||||
auto it = std::find_if(begin(), end(),
|
||||
[when] (auto &d) { return d->when <= when; });
|
||||
|
||||
for (auto it2 = it; it2 != divelog.dives.begin(); --it2) {
|
||||
for (auto it2 = it; it2 != begin(); --it2) {
|
||||
if (!(*std::prev(it2))->hidden_by_filter)
|
||||
return it2->get();
|
||||
}
|
||||
|
||||
for (auto it2 = it; it2 != divelog.dives.end(); ++it2) {
|
||||
for (auto it2 = it; it2 != end(); ++it2) {
|
||||
if (!(*it2)->hidden_by_filter)
|
||||
return it2->get();
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ struct dive_table : public sorted_owning_table<dive, &comp_dives> {
|
|||
dive *get_by_uniq_id(int id) const;
|
||||
void record_dive(std::unique_ptr<dive> d); // call fixup_dive() before adding dive to table.
|
||||
std::unique_ptr<dive> unregister_dive(int idx);
|
||||
|
||||
struct dive *find_next_visible_dive(timestamp_t when);
|
||||
};
|
||||
|
||||
/* this is used for both git and xml format */
|
||||
|
@ -50,7 +52,6 @@ extern process_imported_dives_result process_imported_dives(struct divelog &impo
|
|||
extern void get_dive_gas(const struct dive *dive, int *o2_p, int *he_p, int *o2low_p);
|
||||
extern int get_dive_nr_at_idx(int idx);
|
||||
extern timestamp_t get_surface_interval(timestamp_t when);
|
||||
extern struct dive *find_next_visible_dive(timestamp_t when);
|
||||
|
||||
int get_min_datafile_version();
|
||||
void report_datafile_version(int version);
|
||||
|
|
|
@ -101,7 +101,7 @@ static void setClosestCurrentDive(timestamp_t when, const std::vector<dive *> &s
|
|||
// No selected dive is visible! Take the closest dive. Note, this might
|
||||
// return null, but that just means unsetting the current dive (as no
|
||||
// dive is visible anyway).
|
||||
current_dive = find_next_visible_dive(when);
|
||||
current_dive = divelog.dives.find_next_visible_dive(when);
|
||||
if (current_dive) {
|
||||
current_dive->selected = true;
|
||||
amount_selected++;
|
||||
|
|
Loading…
Add table
Reference in a new issue