I'm not sure about this one, as we test name at the start of the
function and event->name shouldn't be NULL, but hey, we have the safe
compare function, so let's use it.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Header files should compile regardless of order of inclusion.
Since libdivecomputer.h uses FILE unconditional include of
stdio.h is the correct thing to do.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Enough gas was checking the currently displayed dive instead of the
dive to be planned. Not good in a multi-threaded context. Pass the
actual dive instead.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Pass the dive to be planned to track_ascent_gas and don't use
the displayed_dive. For convenience, pass the cylinder-id, since
the function can now access the cylinder of the dive by itself.
This makes the callers less verbose.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The function comment talks about overwriting displayed_dive, when
in reality the function overwrites a passed in dive.
Also fix a debug-call which dumped the displayed_dive, not the
actual dive to stdout.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The fill_default_cylinder() function calculated the MOD based
on the currently displayed dive. This does not seem to make sense:
- When importing dives, why would we care about the altitude and
salinity of the currently displayed dive, possibly from a different
trip.
- The planner is supposed to be thread-safe and should not touch
global variables.
Of course this means that the importing-functions have to fill
out altitude and salinity before creating the default cylinder,
but this is their problem. For a freshly created dive they will
get the default values, which still seems less random than the
values from the displayed dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of passing the global displayed_dive to
calc_crushing_pressure(), use the dive the planner is working on.
A small step in making the planner thread-safe.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The parser had global state in the form of a linear regression
and the "plot_depth" variable. Collect that in the deco_state struct and
pass it down the call-chain. Move out the code to update the
regression data to not bother other callers of tissue_tolerance_calc().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
A number of architecture-dependent functions were declared in
dive.h. Move them to file.h so that not all file-manipulating
translation units have to include dive.h. This is a small step
in avoiding mass-recompilation on every change to dive.h
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Move the declarations of the "report_error()" and "set_error_cb()"
functions and the "verbose" variable to errorhelper.h.
Thus, error-reporting translation units don't have to import the
big dive.h header file.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Replace a macro calculating a degree-three polynomial by an
inline function.
Moreover, calculate the powers 1, 2 and 3 of the pressure inside
the function. The compiler will be smart enough to optimize this
to the same code. The only important thing is to write "x*x*x*coeff"
instead of "coeff*x*x*x". The compiler can't optimize the latter
because ... wonderful floating point semantics.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The planner can produce negative cylinder pressures when
more gas is used than available. Let's color the pressure
graph in a highly visible color to alert the user of the
fact that current gas planning is insufficient.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
The curve fitting for our gas compressibility was only done in the sane
range of 0-500 bar, which is what a scuba cylinder can reasonably be
expected to perhaps have.
But the planner ends up happily using negative cylinder pressures when
you run out of gas, and then the compressibility gives nonsensical
results.
That's clearly a planner bug, but the nonsensical gas compressibility
values made it harder to see what could be wrong.
So we just clamp the inpot range to the range we have verified against
experimental data. If you try to get compressibility for negative
pressures, you get the compressibility for an ideal and imaginary gas.
And if you try to get compressibility for pressures over 500 bar, we'll
just assume that it's 500 bar.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
For better encapsulation, use clear_git_id() in clear_dive_file_data()
instead of setting saved_git_id directly.
Thus, memory management of the saved_git_id value is encapsulated
and can be modified more easily.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The git parser was using a number of global static variables. Remove
them by introducing a parser state, which is passed down to the
call hierarchy.
Advantages:
1) Removes global variables and makes the parser (mostly) reentrant.
2) More flexible - e.g. when parsing samples, the parser can now
access the dive to check if the cylinder number is valid.
3) Less weak typing through "void *".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The function get_divemode() and git_tree_entry_blob() were not used
outside of load-git.c. Make them of static linkage.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
copy_cylinders() copied the cylinders of one dive onto another dive
and then reset to the original gas values. Presumably, when copy and
pasting cylinders from one dive to another, only the types should
be copied, not the gases.
Moreover, the function could either copy all or only the used cylinders.
Firstly, the code was bogus: when restoring the pressures the indices
were mixed up: the old indices were used. Thus, when there where
uncopied cylinders, not all pressure values were restored.
Secondly, it is not clear that all callers actually want to restore
the pressure data. It rather appears the two (out of three) callers
actually just want to copy the cylinders.
Therefore, split the function in
1) copy_cylinders(): copy the cylinders with pressure data
2) copy_cylinder_types(): copy only the cylinder information
Since there is only one caller of copy_cylinder_types(), the "used_only"
argument can be removed. Since all cylinders are copied there is
no point in storing the pressure data. Don't overwrite it in
the first place.
The resulting two functions should be distinctly easier to understand.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The parsers / downloaders parse into a separate table and do
not directly change the divelist. Therefore, they shouldn't
call mark_divelist_changed().
Likewise split_dive_at() doesn't modify the dive list and
therefore shouldn't call this function.
Calling the function has the unwanted side-effect that undoing
the change will not clear the *-symbol in the title of the
main window.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This function was used to count the number of weightsystems
used in a dive. Since the weightsysems are now collected
in a dynamic table it became unused. Remove.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Replace the fixed-size weightsystem table by a dynamically
relocated table. Reuse the table-macros used in other parts
of the code.
The table stores weightsystem entries, not pointers to
weightsystems. Thus, ownership of the description string is
taken when adding a weightsystem. An extra function adds
a cloned weightsystem at the end of the table.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This will be used later when joining and editing dives.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Sadly, this doesn't give any type safety. But at least it documents
the function arguments.
Make the last item in the enum as a number-of-pressure-entries
sentinel. Use that to size the pressure-values array.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of assigning the the lvalue of the SENSOR_PRESSURE
macro, introduce a general function to set pressure values.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The comment to populate_pressure_information() was mentioning
gas pressures that didn't exist. Remove these parts.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Replace the INTERPOLATED_PRESSURE and SENSOR_PRESSURE macros by
inline functions. Generate a common inline function that reads
a pressure value for a dynamic sensor.
Not all SENSOR_PRESSURE macros can be replaced, because the
macro is also used to set the value and C sadly doesn't know
the concept of "return reference from a function".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There is absolutely no reason to use a macro here.
The only argument that can be made is consistency with
the other pressure-macros, but those too are questionable.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
DILUENT_PRESSURE and INTERPOLATED_DILUENT_PRESSURE do not exist
anymore. No point in trying to output them.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Another tiny step in making dive.h smaller: move function
declarations to deco.h if these functions are defined in deco.c
and don't directly concern dives.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The string_to_*() functions were declared in dive.h and qthelper.h.
Moreover in one file they were declared with C in the other with
C++ linkage. This only works because qthelper.h includes dive.h
first.
Fix this anomaly by declaring the functions only in qthelper.h,
but moving them from the C++ to the C part.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since this function doesn't act on a dive and is only related
to cylinders, move it to equipment.c and equipment.h.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
While testing the cylinder type saving fix, I noticed that the RBT
saving was broken. Instead of saving RBT whenever it changed, we'd save
it when it was non-zero. Which doesn't match the git save format, and
also doesn't match what we do when loading an xml file (where we default
to the previous RBT value, and a sample RBT will modify it).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Steve Williams reported a crash when saving a previously loaded dive as
xml, and gave a gdb backtrace.
It turns out that if we can't parse the cylinder use type (OC, diluent,
oxygen, unused) we initialize the cylinder use to an invalid type, and
then when we save it, we mess up.
Fix it up by doing proper limit checking before accessing the
"cylinderuse_text[]" array when saving.
Reported-by: Steve <stevewilliams@internode.on.net>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
In the error messages shown when failing to start ffmpeg, instruct
the user to set the correct executable in the preferences.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Currently, the git parser happily trashes memory if a git repository
contains too many weightsystems or cylinders. This should only happen
in testing, but nevertheless try to handle it gracefully and ignore
excess cylinders / weightsystems.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
All callers of create_plot_info_new() called calculate_max_limits_new()
a line before. Thus, simply call the latter in the former.
This allows us to automatically free the plot data in create_plot_info_new().
The old code overwrote the corresponding field with NULL.
As a side-effect, this removes a bogus static variable.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There was a global variable last_pi_entry_new, which stored the
recently allocated plot data. This was freed when new plot data
was generated.
A very scary proposition: You can never have two plot datas at
the same time! But exactly that happens when you export for
example subtitles.
The only reason why this didn't lead to very crazy behavior
is that at least on my Linux machine, the calloc() call would
just return the previously freed memory.
Fix this mess by removing the global variable and freeing the
data in the callers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Bailing out does not happen instantly. Rather wait for
the minimum stop switch duration before ascending.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
In "core/save-html.h", the "core/dive.h" header was included in the
extern "C" block. This is invalid, because "core/dive.h" included
from C++ code contains Qt macros that expand to C++ templates. These
in turn must not have extern "C" linkage, since a plain C-linker
cannot handle such things.
The only reason this worked is that in all cases "core/save-html.h"
was included after "core/dive.h". The include of the latter in the
former had therefore not effect.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When checking for trip-overlap on import, only really overlapping trips
have been considered, i.e. when dives had overlapping times.
Instead use the TRIP_THRESHOLD so that on download dives are added to
the same trip if in a two-days time frame.
Reported-by: Miika Turkia <miika.turkia@gmail.com>
Reported-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
For historic reasons, there where three distinct signals concerning
dive-selection from the undo-machinery:
1) divesSelected: sent newly selected dives
2) currentDiveChanged: sent if the current dive changed
3) selectionChanged: sent at the end of a command if either the selection
or the current dive changed
Since now the undo-commands do a full reset of the selection, merge these
three signals into a single signal.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Some commands tried to retain the current selection on undo/redo,
others set the selection to the modified dives.
The latter was introduced because it was easier in some cases, but
it is probably more user-friendly because the user gets feedback
on the change.
Therefore, unify to always select the affected dives on undo()/redo().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since the default view is batched by trips, signals were sent trip-wise.
This seemed like a good idea at first, but when more and more parts used
these signals, it became a burden. Therefore push the batching to the
part of the code where it is needed: the trip view.
The divesAdded and divesDeleted are not yet converted, because these
are combined with trip addition/deletion. This should also be detangled,
but not now.
Since the dive-lists were sorted in the processByTrip function, the
dive-list model now does its own sorting. This will have to be
audited.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In signals dives were sorted by date. This criterion is not be unique.
Therefore sort by the dive_less_than() function of the core to avoid
any inconsistencies between the Qt-models and the core data.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The last direct user of the used parameter was removed in
16276faa45, the last actual user in
e2bbd0ceec.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
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>
The function declarations of regressiona(), regressionb() and
reset_regression() were given in an independent translation unit.
Move them into the proper header file. To ensure consistent function
signatures is the whole point of header files, after all.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The lookup tables decostoplevels_metric and decostoplevels_imperial
in planner.c were not used outside the translation unit. Make them
static.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
gaspressure.h had definitions of non-exported structs, but did
not declare the only function exported by gaspressure.c.
Therefore, move the struct definitions into gaspressure.c and
the declarations of the populate_pressure_information() function
from profile.c to gaspressures.h.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
But only functions that operate only on gases. Functions concerning
cylinders or dives remain in dive.c or are moved to equipment.c
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
gas_density() was declared extern in the header and defined inline
in the translation unit. I didn't even realize that this oxymoron
is valid. Remove inline and an Java-style function definition.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
There is an equipment.c file, but no corresponding header. Move the
corresponding functions into a newly created header. This does not
improve compile time since, at least for now, equipment.h is included
in dive.h. But it makes things more consistent.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The comment said "Clear everything but the first element" but
actually the macro freed the whole list including the first element.
For dive computers it was explicitly called on the second element.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Make dive.h a bit slimmer. It's only a drop in the bucket - but at
least when modifying tag functions not the *whole* application is
rebuilt anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Headers should not have to be included in a certain order.
Therefore include stdarg.h and stdio.h in membuffer.h, since
the latter uses FILE and va_list.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There is a function for copying tag-lists, use that instead of the
raw STRUCTURED_LIST_COPY macro-invocation. This will help in moving
tag functions into their own translation unit.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was probably used for debugging but has no callers anymore.
Let's remove it. If needed, it can be trivially readded.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When a different field is edited, hide any old multi-dive-edit
warning message. The reason is that we might want to add an "undo"
button to the message. But this will undo the wrong command if
we don't hide the message.
Sadly, this means that we can't use animated show / hide, because
an animatedHide() followed immediately by an animatedShow() does
not necessarily show the message. In other words, and animatedShow()
does not interupt a started animatedHide()!?
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add display of the difference between pO2 in rebreather loop and the
equivalent OC pO2: this is the oxygen drop over the mouthpiece for
SCR dives. Obviously this is only displayed for SCR dives.
Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Note that we don't really have libdivecomputer support for it yet, only
newly added model numbers etc. But the name detection should make it
easier for people to at least download a memory dump.
In addition to the libdivecomputer model number updates, this also has a
merge of Jef's upstram libdivecomputer changes.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Currently, count_divecomputers only works on the current_dive.
Instead, let it take a pointer to an arbitrary dive. This is
in preparation for being smarter in the undo code concerning
which dive computer to show on deletion.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This function clones a dive and clear out the old dive. This
corresponds to move semantics. Name the function accordingly.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of the elegant solution that just modifies the dive,
keep two copies and add either the old or the new copy. This
is primitive, but it trivially keeps the dives in the right order.
The order might change on renumbering the dive computers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When splitting out dive computers, the dives were sorted in
an arbitrary way (according to an internal id), since all
data are identical.
Therefore, consider the dive-computer model names when sorting
dives. Equal dives are now sorted alphabetically by model.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The units.h file has two functions to convert atm pressure to mbar
and also to convert mbar to atm pressure. Implement these two
functions in the planner.
Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
This is just a trivial update to recognize the BT name, and a
libdivecomputer submodule update to get the updates to libdivecomputer
to recognize the new USB IDs etc.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
The Information tab shows the atmospheric pressure. Make this value editable
and also ensure that changes to it are undo-able.
Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
The application state was encoded in a QByteArray. Thus, there was
no compile-time checking. Typos would lead to silent failures.
Turn the application state into an enum. Use the enum-class construct,
so that the values don't polute the global namespace. Moreover,
this makes them strongly typed, i.e. they don't auto-convert to
integers.
A disadvantage is that the enums now have to be cast to int
explicitly when used to index an array.
Replace two hash-maps in MainWindow to arrays of fixed sizes.
Move the application-state details into their own files.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
A user reports a problem when dives have the same time but different
numbers. The dives appear sorted randomly (effectively they are sorted
by an internal unique-id).
Try to sort by number for dives at the same date in this case.
Fixes#2086
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
At some places we use UTF8 string literals. Therefore, we effectively
only support UTF8 build systems. We might just as well remove all
the other UTF_* macros and use direct string literals.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Some dive computers save GPS data. Currently, this is stored
by libdivecomputer in an "extra field". When generating a
new dive site for a dive try to use this data to place the
dive site.
To do so, create a "dive_get_gps_location()" function. This
function can be extended later to use e.g. event. When creating
a dive site, use the result of this function over a potential
pre-existing dive site.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The parse_location() function was used in three places. In two
of them, the declaration was in the translation unit. Instead,
move the declaration into a header file, to avoid duplication
and the possibility of inconsistencies.
The "units.h" header was chosen as this is where location_t
is defined.
Moreover, make the string argument to parse_location() "const
char *", so that it can be used on non-owned buffers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This has been a feature people have asked for quite frequently. It is
taking up some valuable screen real estate - so the question could
become if there should be a switch to enable / disable it.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>
Fixed bug in the Haversine function in get_distance() based on algorithm
at https://www.movable-type.co.uk/scripts/latlong.html and added bounds
to the 'a' term to avoid floating point errors for antipodal points.
Signed-off-by: Doug Junkins <junkins@foghead.com>
This didn't use to matter, because none of the BLE-using backends did
retry on timeout until recently.
But Jef started doing packet sending retry for the Mares Icon backend,
and now we should make sure to distinguish the "IO failed" from "IO
timed out" cases.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit adds an entry to the dive media context
menu which offers to write a subtitle file. This
creates an .ass file for the selected videos.
In an attempt to to clutter the screen too much, don't
show irrelevant entries (zero temperature or
NDL and show TTS only for dives with stops).
VLC is able to show these subtitles directly, they
can be integrated into the video file with ffmpeg.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Commit c69ca4df80 removed the roleNames
function, which is not needed according to the docs, as a default function
is provided. For unknown reasons this broke the QML combo box.
Reinstate the function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Skip gas use calculation for the gas that was used in
the surface segment added by the planner in the end.
Reported-by: philippe@philmassart.net
Signed-off-by: Robert C. Helling <helling@atdotde.de>
The dive splitting code returns an error code when splitting fails, but
it turns out that the C++ UI code doesn't actually look at the error
code, and instead expected the resulting dives to be NULL if an error
happened and the split didn't succeed for whatever reason.
Which is kind of lazy of it, but we might as well clear the resulting
dives and make the UI code happy. This should fix the problem that
Celia Marlowe reported on the Subsurface google groups forum.
Reported-by: Celia Marlowe
Acked-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Fixes: 145f70aab5 ("Undo: implement split-out of dive computer")
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
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>
Trips and dive sites were changed to use dive tables instead
of linked lists. But the memory used for the tables wasn't freed.
Do this.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Selecting "Selected dives" exports the dive sites for the selected
dives. Selecting "All dives" exports all dive sites.
XML format is the subsection of the divelog XML that describes the
sites headed with a <divesites> section like:
<divesites program='subsurface' version='3'>
</divesites>
Signed-off-by: Doug Junkins <junkins@foghead.com>
Instead of using a random UUID, use an SHA1 hash of name, description
and notes (if defined). This is necessary for testing.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The dive_site_has_gps_location() function already checks for the null
dive site. Remove redundant checks.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Properly implement the unsaved-changes flag(s). Since we currently have
two kinds of changes, there are two flags:
1) dive_list_changed in divelist.c marks non-undoable changes. This flag
is only cleared on save or load.
2) QUndoStack::isClean() is used to determine the state of undoable
changes. Every time the user returns to the state where they saved,
this flag is cleared.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is copying the dive editing code. It uses an OO design with
virtual functions for getting and setting the values. It doesn't
use templates though, as both fields of strig type. This feels
a bit over-engineered, but it is 1) consistent with the dive edit
code and 2) the number / types of dive trip fields might increase.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When pasting (or undoing paste) the cylinders or weights may change.
Send the appropriate signals and update the models accordingly.
Currently, this means copying from current dive to displayed dive,
but hopefully we can get rid of "displayed_dive" in the not so
distant future.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Remove a few cases of
void fun() {
...
}
While touching these functions, fix a few other whitespace
coding style violations.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Taglists were only copied in dive.c using the STRUCTURED_LIST_COPY
macro. Export that functionality in a function. This will be
needed for undo of dive-pasting.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The dive list was not updated automatically when an edit command was
executed. There was already a signal to do that, viz. divesChanged().
But that signal worked by-trip and didn't have a dive-field specifier.
The edit-commands used the divesEdited() signal that isn't by-trip
but has a dive-field specifier.
Unify these two signals to be by-trip and with dive-field specifier.
This needs common code to generate the by-trip list that is moved to
a command_private.h header.
Since there might now be multiple signals (one per trip) actually
check in the main-tab whether the current trip is affected to
avoid multiple update of fields. This has the positive(?) effect
of not doing any update if the current dive isn't changed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was a bit different from the other editing commands:
1) Only the current dive is edited not all selected dives.
Therefore, create a function that turns the current dive
into a one-element list.
2) The profile has to be replot. Here, likewise, create a
function to do that.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This one is a bit more tricky. There are two modes: set dive site
and set newly created dive site. This is realized using an OO model
with derived classed. Quite convoluted - but it seems to work.
Moreover, editing a dive site is not simply setting a value,
but the list of dives in a dive site has to be kept up to date.
Finally, we have to inform the dive site list of the changed
number of dives. Therefore add a new signal diveSiteDivesChanged.
To send only one signal per dive site, hook into the undo() and
redo() functions and call the functions of the base class there.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To keep the UI in a consistent state, update the notes field if
it is changed by an undo command. To that purpose, add a new
signal to diveListNotifier with a list of dives and a field-id
as payload.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This one was rather trivial, as there is no actual merging
done. Quite simply, a number of dive sites are removed and
their dive added to a different dive site.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Implement an undo command that edits the name of a dive site.
Connect it to the dive site table, so that names can be edited
directly in the table.
Send signals on undo / redo so that the dive site table and
the dive site edit widget can be updated.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
Turn the table functions of the dive site handling into macros
as was already used for dives and dive trips. This has the effect
that the table is kept sorted by UUID.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
dive- and trip-table functions are generated in dive.c by macros.
Move this macros to a new "core/table.h" header file.
Thus, these functions can be used for other tables (e.g. dive site)
and the trip function can be moved to a separate translation unit
(divelist.c being quite large already).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The other dive- and trip-table functions were already autogenerated.
Let's do the same for these two.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
Add a new signal to DiveListNotifier. Send signal if dives are
added or removed and therefore the dive count of a dive site
changes. The dive sites are collected and the signal is sent
at the end of the command.
Add code to update the table view.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
1) The second parameter (selected_only) was always false. Therefore,
remove it.
2) Simplify the function by simply returning the reference count.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of setting dive->dive_site directly, call the
add_dive_to_dive_site() and unregister_dive_from_dive_site()
functions. In the parser this turned out to be a bit tricky.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
The function is defined in qthelper.c and thus not all users
of dive.h have to suck in the xslt headers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Move the declaration of these functions to "file.h" and "parse.h"
according to the translation unit they are defined in. Thus, not
all users of "dive.h" have to suck in "sqlite3.h".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since the UUID will be overwritten on save and is only used on save
and load, set it only on save or load. For other created dive sites,
leave the UUID field uninitialized.
This means that the UUID will change between saves. Let's see how
the git saver handles that.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>