Commit graph

27 commits

Author SHA1 Message Date
Berthold Stoeger
22a1120b30 core: move gasname() to struct gasmix
Also, turn it to use std::string instead of writing into a
global(!) buffer. This was not reentrant.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
d36fd79527 core: move total_weight() into struct dive
Feels natural in a C++ code base.

Change the function to return a weight_t. Sadly, use of the
units.h types is very inconsistent and many parts of the code
use int or double instead. So let's try to make this consistent.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
1b593dc56c core: move cylinder related functions to struct dive
Seems natural in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
3aab33ba4c core: move get_dive_gas() to struct dive
It is unclear why this was declared in divelist.h.

Moreover, rename it to get_maximal_gas() to better reflect
what it does.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
ccdd92aeb7 preferences: use std::string in struct preferences
This is a messy commit, because the "qPref" system relies
heavily on QString, which means lots of conversions between
the two worlds. Ultimately, I plan to base the preferences
system on std::string and only convert to QString when
pushing through Qt's property system or when writing into
Qt's settings.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
7792f54a73 core: move functions into trip-structure
Not strictly necessary, but a "natural" thing to do in a classical
C++ code base.

Move the tiny trip-table into its own source file, since it also
has its own header.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
b95ac3f79c core: turn C dive-table into an owning table
This is a humongous commit, because it touches all parts of the
code. It removes the last user of our horrible TABLE macros, which
simulate std::vector<> in a very clumsy way.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
5c7cfb1057 core: replace list of dives in trip by std::vector<>
The dive_table will be converted into a table of owning pointers.
Since the trip has only non-owning pointers to dives, turn
its dive_table into an std::vector<dive *>.

Add a helper functions to add/remove items in a sorted list.
These could be used elsewhere.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
eacad89531 core: turn trip-table into our own sorted_owning_table
Since the sorted_owning_table depends on the fact that
different elements never compare as equal, make the
comparison function safer in that respect. If all failes,
compare the pointers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
3ee41328f9 core: turn dive-trip location and notes into std::string
Simpler memory management.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
3cb04d230b core: turn struct dive string data into std::string
Much easier memory management!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
640ecb345b core: convert weightsystem_t and weightsystem_table to C++
As for cylinders, this had to be done simultaneously,

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
28520da655 core: convert cylinder_t and cylinder_table to C++
This had to be done simultaneously, because the table macros
do not work properly with C++ objects.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
284582d2e8 core: turn divecomputer list into std::vector<>
Since struct divecomputer is now fully C++ (i.e. cleans up
after itself), we can simply turn the list of divecomputers
into an std::vector<>. This makes the code quite a bit simpler,
because the first divecomputer was actually a subobject.

Yes, this makes the common case of a single divecomputer a
little bit less efficient, but it really shouldn't matter.
If it does, we can still write a special std::vector<>-
like container that keeps the first element inline.

This change makes pointers-to-divecomputers not stable.
So always access the divecomputer via its index. As
far as I can tell, most of the code already does this.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
3f8b4604be core: convert taxonomy.c to C++
Since the taxonomy is now a real C++ struct with constructor
and destructor, dive_site has to be converted to C++ as well.

A bit hairy for now, but will ultimately be distinctly simpler.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
3c1401785b core: use C++ structures for tanksystem info
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Michael Keller
e65c7cedc8 Refactoring: Improve Naming of FRACTION and SIGNED_FRAC defines.
Make it more obvious that the FRACTION and SIGNED_FRAC defines return a
tuple / triplet of values.

Fixes https://github.com/subsurface/subsurface/pull/4171#discussion_r1585941133

Complained-about-by: @bstoeger
Signed-off-by: Michael Keller <github@ike.ch>
2024-05-02 20:36:26 +02:00
Berthold Stoeger
fac006148f profile: make event hiding persistent across change of dive
Currently, the "hide event" status is lost when switching dives.
Save it in the event struct instead to make it persistent.

In the future we might save this information to the log file.
Then this should be integrated in the undo-system.

This commit also makes the "unhide events" menu entry more
fine grained: It now differentiates between individual
events and event types.

Note this adds an additional field to the event structure.
There is a "deleted" field that is used internally for
book-keeping, but probably should be removed. Not touching
this at the moment as long as this is C-only code. When/if
switching to C++ we can make the event linked list a table,
which will make this much simpler.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-02-23 09:46:16 -08:00
Berthold Stoeger
31cf991afe cleanup: remove pointless idle comment in string-format.cpp
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-03-28 20:39:02 -07:00
Berthold Stoeger
264adacba1 cleanup: move formatting of gas type to string-format.cpp
Since the only caller was C++ code, this can be done in
C++ code, which removes memory-management headaches.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-03-28 20:39:02 -07:00
Berthold Stoeger
4a7ee872f3 cleanup: move minute formating to format-string.cpp
The get_minutes() function formats a time as m:ss
and returns a static C-string. Since all callers are
C++ anyway and transform directly into QString, let us
move this to the other string formatting function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-09-03 13:49:02 -07:00
Berthold Stoeger
d1b8f1ca3d formatting: move get_trip_title to string-format.h and split it
To enable grouping by trip in the statistics module, split
the get_trip_title() function in a version that appends
a "(n dive(s)" string an one that doesn't. The statistics
module doesn't want that added string, since it displays
the number of dives in a different way.

Also, move the functions to string-format.h, where these
are collected. And rename them to camelCase. Yes, it's
ugly, but consistent with most other C++ code in the code
base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 10:36:13 -08:00
Berthold Stoeger
e23d103c5d core: move formatting of day-of-week to string-format.cpp
This was only used by the filter, but will also be used
by the statistics module. To avoid duplicate translation
strings, move to a common place.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-01 21:10:10 +01:00
Berthold Stoeger
1037c15b98 mobile: remove DiveObjectHelper code
When editing a dive, a DiveObjectHelper of the unmodified dive
was created to compare the edited with the old values. Since
the DiveObjectHelper is used here only as a pointless wrapper
around the formatting functions, call these functions directly.

However, note that the code is in principle wrong since the
change to the mobile-models, which do not use the DiveObjectHelper.
The real fix would be to reload the data from the model to prevent
going out-of-sync with respect to the formatting routines!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 13:03:56 -08:00
Berthold Stoeger
ae182c386b printing: remove DiveObjectHelper from printing code
At this point (post grantlee), DiveObjectHelper is just pointless
glue code. Let's remove it from the printing code and call the
formatting functions directly. If necessary, move these functions
to core/string-format.cpp.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 13:03:56 -08:00
Berthold Stoeger
d9942269a9 printing: remove DiveObjectHelperGrantlee
This was a weird helper object, needed for grantlee. Instead
of storing this object, loop over cylinders and dives directly.

The actual accessor function is unchanged and now generates
a DiveObjectHelper or DiveCylinderHelper for every variable
access. Obviously, this is very inefficient. However, this
will be replaced in future commits by direct calls to formatting
functions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 13:03:56 -08:00
Berthold Stoeger
bf8261c001 core: create string-format.cpp source file
The mobile version of the list used string formatting functions
defined in DiveObjectHelper and declared in mobilelistmodels.h.
Very confusing. Move them to a separate source file where - in
the long run - all the string-formatting functions, which
are scattered all over the place, can be collected.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-12-17 13:03:56 -08:00