aboutsummaryrefslogtreecommitdiffstats
path: root/core/divelist.h
AgeCommit message (Collapse)Author
2020-10-25cleanup: move sort_dive_table declaration to divetable.hGravatar Berthold Stoeger
Apparently this was forgotten in a previous include-reshuffling. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: move function declarations to divelist.hGravatar Berthold Stoeger
unregister_dive() and delete_single_dive are defined in divelist.c, as they take an "index" argument into the global divelist. Therefore, move their declarations to divelist.h. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: move mark_divelist_changed() to qmlmanager.cppGravatar Berthold Stoeger
Desktop does not use mark_divelist_changed() anymore - all is done via the undo machinery. Therefore move this function (and its counterpart unsaved_changes()) to qmlmanager.cpp. Ultimately, it probably should be removed from there as well, but currently I don't dare to touch all the cloud-logic! Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24devices: add devices in Command::importTable()Gravatar Berthold Stoeger
Add a device_table parameters to Command::importTable() and add_imported_dives(). The content of this table will be added to the global device list (respectively removed on undo). This is currently a no-op, as the parser doesn't yet fill out the device table, but adds devices directly to the global device table. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-02cleanup: remove unused function append_dive()Gravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01cleanup: move dive_table from dive.h to divelist.hGravatar Berthold Stoeger
This allows us to decouple dive.h and divelist.h, a small step in include disentangling. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04Selection: move selection functions from divelist.c to selection.cGravatar Berthold Stoeger
Since we now have a selection.c translation unit, put the selection- related functions there. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-19Filter: move num_shown logic from model to coreGravatar Berthold Stoeger
Since the number of shown dives is stored in the core, let's also keep it updated there. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-19Filter: move number of shown dives to coreGravatar Berthold Stoeger
We mark hidden/shown dives in the core but store the number of shown dives in the MultiFilterSortModel. Move this datum to the core for improved locality. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02Core: implement move functions for dive and dive_site tableGravatar Berthold Stoeger
To allow efficient moving of downloaded dives from the download thread to the model, implement a general move function that moves table data. Instantiate that function for the dive and dive_site tables. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08Cleanup: move planner/deco related declarations planner/deco.hGravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19Cleanup: use add_to_dive_table() in record_dive_to_table()Gravatar Berthold Stoeger
This was reimplementing functionality that was already there. Simply call the already existing function. Thus, we don't have to export the grow_dive_table function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19Cleanup: generate clear_*_table() functions by macroGravatar Berthold Stoeger
In analogy to the other table functions, generate these by a macro as well. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19Cleanup: localize enum and table in divelist.cGravatar Berthold Stoeger
The cns_table was only used in divelist.c. Make it of static linkage accordingly. The cns_table_headers enum is likewise only used in divelist.c. Therefore move it from the header to the .c file. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19Cleanup: move trip-related functions into own translation unitGravatar Berthold Stoeger
These functions were spread out over dive.c and divelist.c. Move them into their own file to make all this a bit less monolithic. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-06Add "Import dive sites" menu to mainwindowGravatar Doug Junkins
Adds "Import->Import dive sites" menu to mainwindow.cpp and adds the on_actionImportDiveSites_triggered() method to prompt for the filename to import from. The files are parsed and then any dive and trip data is cleared before opening a dialog box to select which sites are to be imported. Signed-off-by: Doug Junkins <junkins@foghead.com>
2019-04-15Core: turn add_single_dive() to append_dive()Gravatar Berthold Stoeger
The only external caller of add_single_dive() used it to append a dive to the global dive list. Rename the function accordingly and remove the index parameter. The internal caller can use the local insert_dive() function, which doesn't consider selection. That shouldn't be a problem, as the caller is doing import. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Dive site: inform model of dive site addition / deletionGravatar Berthold Stoeger
Introduce two DiveListNotifier signals which are sent by the undo commands if dives are added to / removed from the core. The signal has the dive site and the index in the global dive site table as payload. Thus, the model has only to remove the appropriate rows. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Cleanup: rename unregister_trip() to remove_trip()Gravatar Berthold Stoeger
For consistency with remove_dive(). Moreover, swap parameter order in remove_dive() so that both functions use the same parameter order. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Dive sites: prepare for dive site ref-countingGravatar Berthold Stoeger
Add a dive site table to each dive site to keep track of dives that have been added to a dive site. Add two functions to add dives to / remove dives from dive sites. Since dive sites now contain a dive table, the order of includes had to be changed: "divesite.h" now includes "dive.h" and not vice-versa. This caused some include churn. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: make undo-system dive site-awareGravatar Berthold Stoeger
As opposed to dive trips, dive sites were always directly added to the global table, even on import. Instead, parse the divesites into a distinct table and merge them on import. Currently, this does not do any merging of dive sites, i.e. dive sites are considered as either equal or different. Nevertheless, merging of data should be rather easy to implement and simply follow the code of the dive merging. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-03-17Core: remove variable name conflictGravatar Dirk Hohndel
Having a parameter with the same name as a global variable is potentially confusing. Found via LGTM.com Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-02-28Cleanup: move get_divesite_idx() to divesite.cGravatar Berthold Stoeger
This function was defined in divelist.c, whereas it's better located in divesite.c. Move it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-19Import: control process_imported_dives() by flagsGravatar Berthold Stoeger
process_imported_dives() takes four boolean parameters. Replace these by flags. This makes the function calls much more descriptive. Morover, it becomes easier to add or remove flags. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-19Import: add add_to_new_trip flag to process_imported_dives()Gravatar Berthold Stoeger
If this flag is set, dives that are not assigned to a trip will be assigned to a new trip. This flag is set if the user checked "add to new trip" in the download dialog of the desktop version. Currently this is a no-op as the dives will already have been added to a new trip by the downloading code. This will be removed in a subsequent commit. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Import: split process_imported_dives() functionGravatar Berthold Stoeger
Split the process_imported_dives() function in two: 1) process_imported_dives() processes the dives and generates a list of dives and trips to be added and removed. 2) add_imported_dives() calls process_imported_dives() and does the actual removal / addition of dives and trips. The goal is to split preparation and actual work, to make dive import undo-able. The code adds extra checks to never merge into the same dive twice, as this would lead to a double-free() bug. This should in principle never happen, as dives that compare equal according to is_same_dive() are merged in the imported-dives list, but perhaps in some pathologival corner-cases is_same_dive() turns out to be non-transitive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Import: add merge_all_trips parameter to process_imported_dives()Gravatar Berthold Stoeger
When importing log-files we generally want to merge trips. But when downloading and the user chose "generate new trip", that new trip should not be merged into existing trips. Therefore, add a "merge_all_trips" parameter to process_imported_dives(). If false only autogenerated trips [via autogroup] will be merged. In the future we might want to let the user choose if trips should be merged when importing log-files. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Import: merge dives trip-wiseGravatar Berthold Stoeger
The old way of merging log-files was not well defined: Trips were recognized as the same if and only if the first dives started at the same instant. Later dives did not matter. Change this to merge dives if they are overlapping. Moreover, on parsing and download generate trips in a separate trip-table. This will be fundamental for undo of dive-import: Firstly, we don't want to mix trips of imported and not-yet imported dives. Secondly, by merging trip-wise, we can autogroup the dives in the import-data to trips and merge these at once. This will simplify the code to decide to which trip dives should be autogrouped. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Core: add trip_table parameter to trip-functionsGravatar Berthold Stoeger
Currently trips are added to the global trip table. If we want to make dive-import undoable, we should be able to parse trips of a log-file into a distinct table. Therefore, add a trip_table parameter to - insert_trip() - create_and_hookup_trip_from_dive() - autogroup_dives() - unregister_trip() - remove_dive_from_trip() Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Core: Rename functions to more generic namesGravatar Berthold Stoeger
Rename - dive_get_insertion_index() -> dive_table_get_insertion_index() - unregister_dive_from_table() -> remove_from_dive_table() - get_idx_in_table() -> get_idx_in_dive_table() - sort_table() -> sort_dive_table() This will make it more straight-forward to generate these functions from macros. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Cleanup: Make add_dive_to_table local to divelist.cGravatar Berthold Stoeger
This function was not used outside of divelist.c, therefore make it local. Moreover rename it to add_to_divetable so that the name is generic and can be generated by a macro. Moreover, remove the special case idx = -1, which would determine the insertion index. Instead let the single caller who used this feature do this. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Dive list: add table parameter to autogroup_dives()Gravatar Berthold Stoeger
Currently autogroup_dives() groups all dives in the global dive list. Add a table parameter so that dives in any table can be grouped. Thus it will be possible to pre-group dives on import, which will be used for undo of import. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Core: move autogroup() into divelist.cGravatar Berthold Stoeger
After loading or importing, the caller usually called autogroup() to autogroup dives if so wished by the user. This has already led to bugs, when autogroup() was forgotten. Instead, call autogroup() directly in the process_loaded_dives() and process_imported_dives() functions. Not only does this prevent forgetting the call - it also means that autogrouping can be changed without changing every caller. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-23Cleanup: remove unused parameter was_autogenGravatar Berthold Stoeger
In commit 6bf4120dbbf7be1b9267e0e86f3948b77870ea71 the trip-flags were replaced by a simple boolean. This made the was_autogen parameter to the remove_dive_from_trip() and unregister_dive_from_trip() functions unused. Remove these parameters. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-14Cleanup: remove merge_two_dives() functionGravatar Berthold Stoeger
In 014c04f8bd30740e7711f3b3a01619fd27b5b613 merging dives was included in the undo-system. This made the merge_two_dives() function caller-less. Remove it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-14Cleanup: remove remove_autogen_trips() functionGravatar Berthold Stoeger
In f427226b3b605523bc8285dbdaaa7f6993af6e6a autogrouping / removal of autogrouping was moved into the undo-machinery. This made the remove_autogen_trips() function caller-less. Remove it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-14Cleanup: remove combine_trips() functionGravatar Berthold Stoeger
In f427226b3b605523bc8285dbdaaa7f6993af6e6a a combine_trips_create() function was introduced that combined trips without deleting the old trips. This was necessary for making combine-trips function undo-able. The old combine_trips() function is not used anymore. Therefore remove it. Rename the combine_trips_create() function to combine_trips() as no differentiation is needed anymore. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-23Core: move is-single-day-trip and count-shown functions into coreGravatar Berthold Stoeger
These functionality was used by the desktop filter. To unify desktop and mobile, move it into two new functions in divelist.c Since one of them is the only caller of is_same_day() move that likewise into divelist.c and make it of static linkage. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-18Core: remove "when" field of struct dive_tripGravatar Berthold Stoeger
The when field gives the time of the first dive. Instead of keeping this field in sync, replace it by a function that determines the time of the first dive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-18Core: add add_dive_to_table() functionGravatar Berthold Stoeger
Up to now, dives were added to the global dive table with add_single_dive(). Split out the funtionality to add a dive to an arbitrary dive in the add_dive_to_table_function(). The difference compared to record_dive_to_table is that dives are added at a specific position or the sort-criterion given by dive_less_than(). This will allow to use a dive tabe for trips instead of a linked list. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-16More accurate CNS calculations (following comments on github)Gravatar willemferguson
Update table of maximum oxygen exposure durations, used in CNS calulations. This table shows the official NOAA maximum O2 exposure limits (in seconds) for different PO2 values. It also gives slope values for linear interpolation for intermediate PO2 values between the tabulated PO2 values in the 1st column. Top & bottom rows are inserted that are not in the NOAA table: (1) For PO2 > 1.6 the same slope value as between 1.5 & 1.6 is used. This exptrapolation for PO2 > 1.6 likely gives an underestimate above 1.6 but is better than the value for PO2=1.6 (45 min). (2) The NOAA table only tabulates values for PO2 >= 0.6. Since O2-uptake occurs down to PO2=0.5, the same slope is used as for 0.7 > PO2 > 0.6. This gives a conservative estimate for 0.6 > PO2 > 0.5. To preserve the integer structure of the table, all slopes are given as slope*10: divide by 10 to get the valid slope. The columns below are: po2 (mbar), Maximum Single Exposure (seconds), single_slope, Maximum 24 hour Exposure (seconds), 24h_slope */ Then update Calculations of the CNS for a single dive - this only takes the first divecomputer into account. The previous version of the code did a table lookup and used the max O2 exposure for the next-higher PO2 category. This gave a shorter max O2 exposure time and a higher CNS contribution for a specific dive segment, resulting in a slightly conservative value of CNS, often some 2 - 3 % too high. This code does an interpolation for PO2 values inbetween PO2 entries in the lookup table and therefore results in a more accurate maximum O2 exposure time for that PO2. The maximum O2 exposure duration for each segment is also calculated based on the mean depth of the two samples (start & end) that define each segment. The CNS contribution of each segment is found by dividing the time duration of the segment by its maximum exposure duration. The contributions of all segments of the dive are summed to get the total CNS% value. This is a partial implementation of the proposals in Erik Baker's document "Oxygen Toxicity Calculations" */ Overall, this PR does not radically alter the existing CNS calculation, it only makes it more accurate and more consistent by doing interpolation and by using mean segment depth to find PO2. Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2018-10-14Cleanup: constify get_dive_gas() and get_dive_gas_string()Gravatar Berthold Stoeger
There's no reason for the dive input-parameter being non-const. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-14Cleanup: move clear_table() to divesite.cGravatar Berthold Stoeger
There were two declaration of clear_table(), one in dive.h and one in parse.h. The definition was in parse.c. Since the parser doesn't even use the function, move the function and its declaration to divelist.[ch] and remove the redundant declaration in dive.h. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Undo: select dives after add, remove, merge, split dive commandsGravatar Berthold Stoeger
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-10-11Undo: implement autogrouping of trips in DiveAddGravatar Berthold Stoeger
If the autogroup flag is set, search for appropriate trips in DiveAdd() and add the dive to this trip. If no trip exists, add a new trip. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Undo: make diverse trip-related operations undo-ableGravatar Berthold Stoeger
AddDivesToTrip, CreateTrip, AutogroupDives, RemoveAutogenTrips and MergeTrips basically all did the same thing as RemoveDivesFromTrip, which was already implemented. Thus, factor our the common functionality and hook it up to make all these functions undo-able. Don't do the autogroup-call everytime the dive-list is rebuilt (that would create innumberable undo-actions), but only on dive-load / import or if expressly asked by the user [by switching the autogroup flag]. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Undo: implement undo of manual dive-creationGravatar Berthold Stoeger
Play manual addition of dives via an UndoCommand. Since this does in large parts the same thing as undo/redo of dive deletion (just the other way round and only a single instead of multiple dive), factor out the functions that add/delete dives and take care of trips. The UI-interaction is just mindless copy&paste and will have to be adapted. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Undo: fix multi-level undo of delete-dive and remove-dive-from-tripGravatar Berthold Stoeger
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-10-06Import: pass "downloaded" parameter to process_imported_dives()Gravatar Berthold Stoeger
process_imported_dives() is more efficient for downloaded than for imported (from a file) dives, because it checks only the divecomputer of the first dive. This condition is checked via the "downloaded" flag of the first dive. Instead, pass an argument to process_imported_dives(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-06Import: pass a dive table to process_imported_dives()Gravatar Berthold Stoeger
Dives were directly imported into the global dive table and then merged in process_imported_dives(). Make this interface more flexible, by passing an independent dive table. The dive table of the to-be-imported dives will be sorted and merged. Then each dive is inserted in a one-by-one manner to into the global dive table. This actually introduces (at least) two functional changes: 1) If a new dive spans two old dives, it will only be merged to the first dive. But this seems like a pathological case, which is of dubious value anyway. 2) Dives unrelated to the import will not be merged. The old code would happily merge dives that were not even close to the newly imported dives. A surprising behavior. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>