mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
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:
parent
bb00a9728f
commit
f3c7dcf9c9
3 changed files with 19 additions and 9 deletions
|
@ -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:
|
||||
|
|
|
@ -141,8 +141,7 @@ void split_divecomputer(const struct dive *src, int num, struct dive **out1, str
|
|||
for (_dc = &_dive->dc; _dc; _dc = _dc->next)
|
||||
|
||||
#define for_each_relevant_dc(_dive, _dc) \
|
||||
bool _all_planned = !has_planned(_dive, false); \
|
||||
for (_dc = &_dive->dc; _dc; _dc = _dc->next) if (_all_planned || !is_dc_planner(_dc))
|
||||
for (_dc = &_dive->dc; _dc; _dc = _dc->next) if (!is_logged(_dive) || !is_dc_planner(_dc))
|
||||
|
||||
extern struct dive *get_dive_by_uniq_id(int id);
|
||||
extern int get_idx_by_uniq_id(int id);
|
||||
|
@ -207,7 +206,8 @@ extern void invalidate_dive_cache(struct dive *dc);
|
|||
|
||||
extern int total_weight(const struct dive *);
|
||||
|
||||
extern bool has_planned(const struct dive *dive, bool planned);
|
||||
extern bool is_planned(const struct dive *dive);
|
||||
extern bool is_logged(const struct dive *dive);
|
||||
|
||||
/* Get gasmixes at increasing timestamps.
|
||||
* In "evp", pass a pointer to a "struct event *" which is NULL-initialized on first invocation.
|
||||
|
|
|
@ -1074,9 +1074,9 @@ bool filter_constraint_match_dive(const filter_constraint &c, const struct dive
|
|||
case FILTER_CONSTRAINT_SAC:
|
||||
return check_numerical_range_non_zero(c, d->sac);
|
||||
case FILTER_CONSTRAINT_LOGGED:
|
||||
return has_planned(d, false) != c.negate;
|
||||
return is_logged(d) != c.negate;
|
||||
case FILTER_CONSTRAINT_PLANNED:
|
||||
return has_planned(d, true) != c.negate;
|
||||
return is_planned(d) != c.negate;
|
||||
case FILTER_CONSTRAINT_DIVE_MODE:
|
||||
return check_multiple_choice(c, (int)d->dc.divemode); // should we be smarter and check all DCs?
|
||||
case FILTER_CONSTRAINT_TAGS:
|
||||
|
|
Loading…
Reference in a new issue