mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
core: make get_surface_interval() 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
e9a57ac5f5
commit
cce5f5950c
3 changed files with 6 additions and 8 deletions
|
@ -1270,17 +1270,15 @@ bool dive_or_trip_less_than(struct dive_or_trip a, struct dive_or_trip b)
|
|||
* that happened inside other dives. The interval will always be calculated
|
||||
* with respect to the dive that started previously.
|
||||
*/
|
||||
timestamp_t get_surface_interval(timestamp_t when)
|
||||
timestamp_t dive_table::get_surface_interval(timestamp_t when) const
|
||||
{
|
||||
timestamp_t prev_end;
|
||||
|
||||
/* find previous dive. might want to use a binary search. */
|
||||
auto it = std::find_if(divelog.dives.rbegin(), divelog.dives.rend(),
|
||||
auto it = std::find_if(rbegin(), rend(),
|
||||
[when] (auto &d) { return d->when < when; });
|
||||
if (it == divelog.dives.rend())
|
||||
if (it == rend())
|
||||
return -1;
|
||||
|
||||
prev_end = (*it)->endtime();
|
||||
timestamp_t prev_end = (*it)->endtime();
|
||||
if (prev_end > when)
|
||||
return 0;
|
||||
return when - prev_end;
|
||||
|
|
|
@ -21,6 +21,7 @@ struct dive_table : public sorted_owning_table<dive, &comp_dives> {
|
|||
void record_dive(std::unique_ptr<dive> d); // call fixup_dive() before adding dive to table.
|
||||
std::unique_ptr<dive> unregister_dive(int idx);
|
||||
|
||||
timestamp_t get_surface_interval(timestamp_t when) const;
|
||||
struct dive *find_next_visible_dive(timestamp_t when);
|
||||
};
|
||||
|
||||
|
@ -51,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);
|
||||
|
||||
int get_min_datafile_version();
|
||||
void report_datafile_version(int version);
|
||||
|
|
|
@ -167,7 +167,7 @@ void TabDiveInformation::updateProfile()
|
|||
// Update fields that depend on start of dive
|
||||
void TabDiveInformation::updateWhen()
|
||||
{
|
||||
timestamp_t surface_interval = get_surface_interval(parent.currentDive->when);
|
||||
timestamp_t surface_interval = divelog.dives.get_surface_interval(parent.currentDive->when);
|
||||
if (surface_interval >= 0)
|
||||
ui->surfaceIntervalText->setText(get_dive_surfint_string(surface_interval, tr("d"), tr("h"), tr("min")));
|
||||
else
|
||||
|
|
Loading…
Add table
Reference in a new issue