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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>