2017-04-27 18:18:03 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2011-09-05 19:12:58 +00:00
|
|
|
#ifndef DIVELIST_H
|
|
|
|
#define DIVELIST_H
|
|
|
|
|
2013-04-01 10:51:49 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
2013-04-24 23:52:18 +00:00
|
|
|
#endif
|
2013-04-24 23:33:29 +00:00
|
|
|
|
2015-06-20 13:45:12 +00:00
|
|
|
/* this is used for both git and xml format */
|
|
|
|
#define DATAFORMAT_VERSION 3
|
|
|
|
|
2011-09-19 23:41:56 +00:00
|
|
|
struct dive;
|
|
|
|
|
2011-11-13 17:29:07 +00:00
|
|
|
extern void update_cylinder_related_info(struct dive *);
|
2017-12-11 21:23:52 +00:00
|
|
|
extern void mark_divelist_changed(bool);
|
2011-09-21 04:29:09 +00:00
|
|
|
extern int unsaved_changes(void);
|
2012-09-03 04:48:30 +00:00
|
|
|
extern void remove_autogen_trips(void);
|
2017-11-22 19:42:33 +00:00
|
|
|
extern int init_decompression(struct deco_state *ds, struct dive *dive);
|
2013-04-07 03:49:06 +00:00
|
|
|
|
|
|
|
/* divelist core logic functions */
|
2018-09-23 10:53:35 +00:00
|
|
|
extern void process_loaded_dives();
|
2018-10-03 19:45:50 +00:00
|
|
|
extern void process_imported_dives(struct dive_table *import_table, bool prefer_imported, bool downloaded);
|
2014-07-20 13:07:57 +00:00
|
|
|
extern char *get_dive_gas_string(struct dive *dive);
|
2013-10-07 20:43:17 +00:00
|
|
|
|
2015-10-02 01:13:48 +00:00
|
|
|
struct dive **grow_dive_table(struct dive_table *table);
|
2013-04-07 03:49:06 +00:00
|
|
|
extern void get_dive_gas(struct dive *dive, int *o2_p, int *he_p, int *o2low_p);
|
2018-08-23 17:18:43 +00:00
|
|
|
extern int get_divenr(const struct dive *dive);
|
|
|
|
extern int get_divesite_idx(const struct dive_site *ds);
|
Undo: fix multi-level undo of delete-dive and remove-dive-from-trip
The original undo-code was fundamentally broken. Not only did it leak
resources (copied trips were never freed), it also kept references
to trips or dives that could be changed by other commands. Thus,
anything more than a single undo could lead to crashes.
Two ways of fixing this were considered
1) Don't store pointers, but unique dive-ids and trip-ids.
Whereas such unique ids exist for dives, they would have to be
implemented for trips.
2) Don't free objects in the backend.
Instead, take ownership of deleted objects in the undo-object.
Thus, all references in previous undo-objects are guaranteed to
still exist (unless the objects are deleted elsewhere).
After some contemplation, the second method was chosen, because
it is significantly less intrusive. While touching the undo-objects,
clearly separate backend from ui-code, such that they can ultimately
be reused for mobile.
Note that if other parts of the code delete dives, crashes can still
be provoked. Notable examples are split/merge dives. These will have
to be fixed later. Nevertheless, the new code is a significant
improvement over the old state.
While touching the code, implement proper translation string based
on Qt's plural-feature (using %n).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-19 12:44:27 +00:00
|
|
|
extern struct dive_trip *unregister_dive_from_trip(struct dive *dive, short was_autogen);
|
2013-12-12 23:03:25 +00:00
|
|
|
extern void remove_dive_from_trip(struct dive *dive, short was_autogen);
|
2018-09-23 19:22:48 +00:00
|
|
|
extern dive_trip_t *alloc_trip(void);
|
|
|
|
extern dive_trip_t *create_trip_from_dive(struct dive *dive);
|
2013-04-07 03:49:06 +00:00
|
|
|
extern dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive);
|
2018-09-23 19:22:48 +00:00
|
|
|
extern dive_trip_t *get_dives_to_autogroup(int start, int *from, int *to, bool *allocated);
|
2018-07-30 08:33:25 +00:00
|
|
|
extern dive_trip_t *get_trip_for_new_dive(struct dive *new_dive, bool *allocated);
|
2013-04-07 03:49:06 +00:00
|
|
|
extern void autogroup_dives(void);
|
2013-09-24 04:57:28 +00:00
|
|
|
extern struct dive *merge_two_dives(struct dive *a, struct dive *b);
|
2013-09-24 10:42:40 +00:00
|
|
|
extern bool consecutive_selected();
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
extern void select_dive(struct dive *dive);
|
|
|
|
extern void deselect_dive(struct dive *dive);
|
2014-05-24 20:19:05 +00:00
|
|
|
extern void select_dives_in_trip(struct dive_trip *trip);
|
|
|
|
extern void deselect_dives_in_trip(struct dive_trip *trip);
|
2014-11-12 06:59:04 +00:00
|
|
|
extern void filter_dive(struct dive *d, bool shown);
|
2014-05-24 21:02:08 +00:00
|
|
|
extern void combine_trips(struct dive_trip *trip_a, struct dive_trip *trip_b);
|
2018-09-23 19:22:48 +00:00
|
|
|
extern dive_trip_t *combine_trips_create(struct dive_trip *trip_a, struct dive_trip *trip_b);
|
2014-05-24 15:27:42 +00:00
|
|
|
extern void find_new_trip_start_time(dive_trip_t *trip);
|
|
|
|
extern struct dive *first_selected_dive();
|
|
|
|
extern struct dive *last_selected_dive();
|
2018-08-23 17:18:43 +00:00
|
|
|
extern bool is_trip_before_after(const struct dive *dive, bool before);
|
2018-07-19 20:35:25 +00:00
|
|
|
extern int get_dive_nr_at_idx(int idx);
|
2014-08-18 19:12:05 +00:00
|
|
|
extern void set_dive_nr_for_current_dive();
|
2018-10-06 07:21:27 +00:00
|
|
|
extern timestamp_t get_surface_interval(timestamp_t when);
|
2018-09-28 08:21:23 +00:00
|
|
|
extern void delete_dive_from_table(struct dive_table *table, int idx);
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
extern struct dive *find_next_visible_dive(timestamp_t when);
|
2013-04-07 03:49:06 +00:00
|
|
|
|
2015-06-20 13:45:12 +00:00
|
|
|
int get_min_datafile_version();
|
|
|
|
void reset_min_datafile_version();
|
|
|
|
void report_datafile_version(int version);
|
2016-04-14 12:34:19 +00:00
|
|
|
int get_dive_id_closest_to(timestamp_t when);
|
2015-07-24 20:18:30 +00:00
|
|
|
void clear_dive_file_data();
|
2015-06-20 13:45:12 +00:00
|
|
|
|
2013-04-07 03:49:06 +00:00
|
|
|
#ifdef DEBUG_TRIP
|
|
|
|
extern void dump_selection(void);
|
|
|
|
extern void dump_trip_list(void);
|
|
|
|
#endif
|
|
|
|
|
2013-04-01 10:51:49 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-11 18:14:46 +00:00
|
|
|
#endif // DIVELIST_H
|