Desktop: Fix 'planned' and 'logged' Filters.

Fix the filters for planned (i.e. has at least one dive plan attached)
and logged (i.e. has at least one dive computer log attached) dives.
Also refactor the respective functions for improved readability.

Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
Michael Keller 2024-04-25 12:10:59 +12:00
parent bb00a9728f
commit f3c7dcf9c9
3 changed files with 19 additions and 9 deletions

View file

@ -969,7 +969,7 @@ static void fixup_dc_depths(struct dive *dive, struct divecomputer *dc)
}
update_depth(&dc->maxdepth, maxdepth);
if (!has_planned(dive, false) || !is_dc_planner(dc))
if (!is_logged(dive) || !is_dc_planner(dc))
if (maxdepth > dive->maxdepth.mm)
dive->maxdepth.mm = maxdepth;
}
@ -2550,19 +2550,29 @@ static void join_dive_computers(struct dive *d, struct divecomputer *res,
remove_redundant_dc(res, prefer_downloaded);
}
// Does this dive have a dive computer for which is_dc_planner has value planned
extern "C" bool has_planned(const struct dive *dive, bool planned)
static bool has_dc_type(const struct dive *dive, bool dc_is_planner)
{
const struct divecomputer *dc = &dive->dc;
while (dc) {
if (is_dc_planner(&dive->dc) == planned)
if (is_dc_planner(dc) == dc_is_planner)
return true;
dc = dc->next;
}
return false;
}
// Does this dive have a dive computer for which is_dc_planner has value planned
extern "C" bool is_planned(const struct dive *dive)
{
return has_dc_type(dive, true);
}
extern "C" bool is_logged(const struct dive *dive)
{
return has_dc_type(dive, false);
}
/*
* Merging two dives can be subtle, because there's two different ways
* of merging: