Commit graph

24 commits

Author SHA1 Message Date
Berthold Stoeger
01705a6449 undo: exit early if no event in RemoveEvent()
To avoid dereferencing a null pointer.

Found by Coverity.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-18 16:26:31 +02:00
Berthold Stoeger
e305546046 undo: fix RemoveEvent if we can't find the event
We check for the event, but then access it anyway even if it
doesn't exist. Should not happen, but let's be safe.

Found by Coverity.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-17 23:37:00 +12:00
Berthold Stoeger
5c6ca2c1ce undo: don't use moved-from string
Found by Coverity.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-17 23:37:00 +12:00
Berthold Stoeger
f1f082d86a core: move get_dive_dc() to struct dive
Feels natural in a C++ code base.

This removes a nullptr-check so some care has to be taken.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
72bb38601d core: move invalidate_dive_cache() 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
a2903b31a7 core: move fixup_dive() to struct dive_table
This accesses the global dive_table, so make this explicit.

Since force_fixup_dive() and default_dive() use fixup_dive(),
also move them to struct dive_table.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
27dbdd35c6 core: turn event-list of divecomputer into std::vector<>
This is a rather long commit, because it refactors lots of the event
code from pointer to value semantics: pointers to entries in an
std::vector<> are not stable, so better use indexes.

To step through the event-list at diven time stamps, add *_loop classes,
which encapsulate state that had to be manually handled before by
the caller. I'm not happy about the interface, but it tries to
mirror the one we had before.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
5960fb7340 core: remove get_event_mutable()
We can now return mutable/imutable depending on const-ness of
the parameter, owing to parameter overloading.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
b8c7b173c6 core: make event name an std::string
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
408b31b6ce core: default initialize units-type objects to 0
Makes the code much nicer to read.

Default initialize cylinder_t to the empty cylinder.

This produces lots of warnings, because most structure are now
not PODs anymore and shouldn't be erased using memset().

These memset()s will be removed one-by-one and replaced by
proper constructors.

The whole ordeal made it necessary to add a constructor to
struct event. To simplify things the whole optimization of
the variable-size event names was removed. In upcoming commits
this will be replaced by std::string anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
9f455b1457 selection: move current dive and divecomputer to selection.cpp
This tries to encapsulate the management of the current dive and
divecomputer in the selection code. The current dive is alreay
set by setSelection(). Add a new parameter to also set the
current divecomputer. If -1 is passed, then the current
computer number is remained. This will allow us to audit the code.
Because for now, the whole "current dive computer" thing seems
to be ill-defined.

This fixes a bug: the dive-computer number wasn't validated
when making a new dive the current dive. The new code has some
drawbacks though: when selecting a whole trip, the validation
will be called for all dives in the trip and thus the dive computer
number will depend on the dive with the lowest amount of dive
computers in the trip. This will need to be fixed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-16 20:23:59 +02:00
Berthold Stoeger
1a0f6f53ed undo: set dive mode to CCR in undo command, not profile code
When setting a CCR setpoint, the profile code(!) would turn
the dive into a CCR dive. Not only should the display layer
not alter dives, this also means that the action is not
undoable.

Move that to the appropriate undo command, where it makes
more sense, but obviously also makes things more complicated.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-11 09:31:36 -08:00
Dirk Hohndel
8e3f7f9565 desktop: fix translation implementation
We need to always call the tr() function of the base class. This will have
consequences for our translations.

See: #3068

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-11-08 14:39:26 -08:00
Berthold Stoeger
8212acc992 cleanup: break out event-related code into event.[c|h]
In an effort to reduce the size of dive.h and dive.c, break out
the event related functions. Moreover event-names were handled
by the profile-code, collect that also in the new source files.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:52 -07:00
Berthold Stoeger
4ae87da58c undo: reload dive on removal of gas-switch
If a gas-switch is removed we have to perform the same action
as if a gas-switch is added: fixup the dive and signal the
changed cylinder and stats.

Adapt the RemoveEvent command accordingly. Copy the code of
the AddGasSwitch command and simplify for the fact that
only ony cylinder can be affected.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
e39063f6df undo: switch to affected dive on undo/redo of event-changes
Select and make current the affected dive. And also switch
to the divecomputer that was affected.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
0bd821183d undo: implement gas switch
This is a bit hairy as - in theory - one gas switch can remove
other gas switch(es) at the same timestamp. However, I did not
find a way to test it. Moreover, it is not clear whether the
dive-tabs are properly updated on undo/redo.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
3d511b069f undo: add event removal undo command
This was a trivial copy & past of the event-adding undo command
with a switch of the undo() and redo() actions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
ab8e317b28 undo: implement renaming of events
There is a slight complexity here owing to the fact that the profile
works on a copy of the current dive: We get a copy of the event and
have to search for the original event in the current dive. This
could be done in the undo command. Nevertheless, here we do it in
the profile so that when in the future the profile can work on a
non-copied dive we can simply remove this function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
f9fe6d759f undo: split out EventBase class
All event-based commands will work on a dive computer and
need to replot the profile, etc. Therefore, in analogy to
the dive-list commands create a base class with two virtual
functions undoit() and redoit() that must be defined in the
derived classes that do the actual work.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
1971cfad54 undo: implement set point change undo command
This is a simple copy of the other add-event commands. It could
be made more friendly by stating the pO2 value in the text.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
33fb6461fb undo: add undo command for dive-mode switch
This basically copies the bookmark code, with the addition that
the dive mode is recorded in the text of the undo command.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
7018783f64 undo: replot profile if event changed
Add a DiveListNotifer::eventsChanged signal, which is emitted when
the events changed. This is very coarse, at it doesn't differentiate
between signal addition / editing / deletion. We might want to
be finer in the future.

Catch the signal in the profile-widget to replot the dive if this
is the currently displayed dive. Reuse the cylindersChanged() slot,
but rename it to the now more appropriate profileChanged().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
30c7499a3c undo: implement addBookmark undo command
Create a new translation unit for event-related undo commands.
Create a base class of commands that add events and one subclass
that adds a bookmark event.
Use this command in the profile-widget.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00