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
|
|
|
|
|
2020-05-01 11:43:52 +00:00
|
|
|
#include "units.h"
|
2024-05-31 05:08:54 +00:00
|
|
|
#include <vector>
|
2019-03-04 22:20:29 +00:00
|
|
|
|
2020-05-01 11:43:52 +00:00
|
|
|
struct dive;
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
struct divelog;
|
2020-05-01 11:43:52 +00:00
|
|
|
struct trip_table;
|
2024-05-11 09:47:45 +00:00
|
|
|
class dive_site_table;
|
2024-05-31 05:08:54 +00:00
|
|
|
struct device;
|
2019-08-05 18:43:06 +00:00
|
|
|
struct deco_state;
|
|
|
|
|
2020-05-01 11:43:52 +00:00
|
|
|
struct dive_table {
|
|
|
|
int nr, allocated;
|
|
|
|
struct dive **dives;
|
|
|
|
};
|
|
|
|
static const struct dive_table empty_dive_table = { 0, 0, (struct dive **)0 };
|
|
|
|
|
2015-06-20 13:45:12 +00:00
|
|
|
/* this is used for both git and xml format */
|
|
|
|
#define DATAFORMAT_VERSION 3
|
|
|
|
|
2020-10-25 17:29:15 +00:00
|
|
|
extern void sort_dive_table(struct dive_table *table);
|
2011-11-13 17:29:07 +00:00
|
|
|
extern void update_cylinder_related_info(struct dive *);
|
2021-02-12 16:39:46 +00:00
|
|
|
extern int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_planner);
|
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();
|
2019-01-13 20:53:57 +00:00
|
|
|
/* flags for process_imported_dives() */
|
|
|
|
#define IMPORT_PREFER_IMPORTED (1 << 0)
|
|
|
|
#define IMPORT_IS_DOWNLOADED (1 << 1)
|
|
|
|
#define IMPORT_MERGE_ALL_TRIPS (1 << 2)
|
|
|
|
#define IMPORT_ADD_TO_NEW_TRIP (1 << 3)
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
extern void add_imported_dives(struct divelog *log, int flags);
|
2022-11-12 07:40:04 +00:00
|
|
|
extern void process_imported_dives(struct divelog *import_log, int flags,
|
2018-12-23 21:08:00 +00:00
|
|
|
struct dive_table *dives_to_add, struct dive_table *dives_to_remove,
|
2024-06-01 20:05:57 +00:00
|
|
|
struct trip_table &trips_to_add, dive_site_table &sites_to_add,
|
2024-05-31 05:08:54 +00:00
|
|
|
std::vector<device> &devices_to_add);
|
2013-10-07 20:43:17 +00:00
|
|
|
|
2018-11-24 09:11:07 +00:00
|
|
|
extern int dive_table_get_insertion_index(struct dive_table *table, struct dive *dive);
|
2019-03-04 22:20:29 +00:00
|
|
|
extern void add_to_dive_table(struct dive_table *table, int idx, struct dive *dive);
|
2019-05-31 14:09:14 +00:00
|
|
|
extern void insert_dive(struct dive_table *table, struct dive *d);
|
2018-10-13 20:32:53 +00:00
|
|
|
extern void get_dive_gas(const 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);
|
2019-03-11 23:25:31 +00:00
|
|
|
extern int remove_dive(const struct dive *dive, struct dive_table *table);
|
2018-07-19 20:35:25 +00:00
|
|
|
extern int get_dive_nr_at_idx(int idx);
|
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);
|
2019-05-31 14:09:14 +00:00
|
|
|
|
|
|
|
extern int comp_dives(const struct dive *a, const struct dive *b);
|
2013-04-07 03:49:06 +00:00
|
|
|
|
2015-06-20 13:45:12 +00:00
|
|
|
int get_min_datafile_version();
|
|
|
|
void report_datafile_version(int version);
|
2015-07-24 20:18:30 +00:00
|
|
|
void clear_dive_file_data();
|
2019-06-04 18:59:08 +00:00
|
|
|
void clear_dive_table(struct dive_table *table);
|
2020-10-25 12:32:51 +00:00
|
|
|
struct dive *unregister_dive(int idx);
|
2021-10-30 19:39:36 +00:00
|
|
|
extern bool has_dive(unsigned int deviceid, unsigned int diveid);
|
2015-06-20 13:45:12 +00:00
|
|
|
|
2014-02-11 18:14:46 +00:00
|
|
|
#endif // DIVELIST_H
|