Since this is now in C++, we don't have to use our crazy
TABLE_* macros.
This contains a logic change: the dives associated to a
dive site are now unsorted.
The old code was subtly buggy: dives were added in a sorted
manner, but when the dive was edited the list was not
resorted. Very unlikely that this leads to a serious
problem, still not good.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
Use std::vector<> instead of fixed size array.
Doesn't do any logic change, even though the back-translation
logic is ominous.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Fix an issue introduced in #4148.
Essentially the refactoring missed the fact that in the imperial system
tank size is tracked as the free gas volume, but in the metric system
(which is the one used in most of Subsurface's calculations) tank size
is tracked as water capacity.
So when updating a tank template tracking imperial measurements, the
given (metric) volume in l has to be multiplied by the working pressure,
and vice versa.
This also combines all the logic dealing with `tank_info` data in one
place, hopefully making it less likely that this will be broken by
inconsistencies in the future.
Fixes#4239.
Signed-off-by: Michael Keller <github@ike.ch>
- show the correct gasmix in the profile;
- make gases available for gas switches in the profile after they have
been added;
- persist gas changes;
- add air as a default gas when adding a dive.
This still has problems when undoing a gas switch - instead of
completely removing the gas switch it is just moved to the next point in the
profile.
Signed-off-by: Michael Keller <github@ike.ch>
A long standing issue: the dives_to_add, etc. tables need to be
manually freed. This kind of problem wouldn't arise with proper
C++ data structures.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The old code was leaking memory. Use std::unique_ptr<> for
ownership management.
This is still very primitive and divetags are kept during
application lifetime. There should probably be some form
of reference counting. And the taglist should not be global,
but attached to the divelog.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
As far as I can see there are no translation strings for the
cylinder names, so there is no point in translating them back.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The combo-boxes (cylinder type, weightsystem, etc.) were controlled
by global models. Keeping these models up-to-date was very combersome
and buggy.
Create a new model everytime a combobox is opened. Ultimately it
might even be better to create a copy of the strings and switch
to simple QStringListModel. Set data in the core directly and
don't do this via the models.
The result is much simpler and easier to handle.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Mostly irrelevant std::move() stuff of copy-on-write Qt objects,
a few real bugs, a timestamp_t downconversion and some codingsyle
adaptation.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Unfortunately Coverity doesn't understand that most Qt data
structures are copy-on-write. It's a mis-feature of Qt, but
it is the way it is. Thus, passing by value is not an issue.
Out of ca. 25 warnings only two were legit. Let's silence
the others by either std::move()ing or passing by reference,
as would be idiomatic C++, which Qt is not.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The undo-code uses owning pointers based on std::unique_ptr to
manage lifetime of C-objects. Since these are generally useful,
move them from the undo-code to the core-code. In fact, this
eliminates one instance of code duplication.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The trip selection code was an awkward layering violation.
Whereas dive selections due to dive undo-commands trickled
down via DiveTripModel-->MultiFilterSortModel-->DiveListView,
for trip editing, the DiveListView directly intercepted the
TripEdited signal.
Instead, mimic the dive-selection code. This is a bit longer
but more consistent and logical. The undo/redo of trip changes
is now also a "programmatical" change of the selection.
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>
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
3629a87 changed the handling of cylinders in multi-dives edit.
Not only should the cylinders be the "same", but also at the
same position. The code did not check whether the edited dives
even had that many cylinders, leading to a null-pointer
dereference.
Check whether the cylinder exists before comparing it.
Fixes#3578.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This rarely gets seen / looked at, but it can help make it easier
to understand what a user was doing when trying to restore dives
that were inadvertantly deleted.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Also allow editing sensor on a cylinder with already attached sensor.
This will swap the sensor data with the cylinder that it is taking the
sensor data from, removing the need for adding an extra temporary
cylinder when swapping two sensors.
Signed-off-by: Michael Andreen <michael@andreen.dev>
The last caller of find_cylinder_index() was removed in
3629a87fcc. Also remove functions that where only called by
this function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of trying to find matching cylinders, trigger on the cylinder
number first and then only edit that n-th cylinder if it matches the one
in the current dive.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The undo stack is only relevant to the dives that were loaded at the
time the command was executed. If a file is closed, by specifically
closing it or opening another file, then the undo commands will
reference dives that aren't available anymore. Clearing the undo stack
ensures that we don't crash or accidentally do some undefined
modifications to the currently open file.
Signed-off-by: Michael Andreen <michael@andreen.dev>
Need to save the current dc as a member variable so we can apply redo
and undo to the correct dc later.
Signed-off-by: Michael Andreen <michael@andreen.dev>
Add a column to the equipment table that shows if a sensor is attached to a
tank, or which sensors would be available to attach to a tank that currently
doesn't have a pressure sensor associated with it.
Changing the sensor assignement can be undone.
This column is hidden by default as this is a somewhat unusual activity.
Signed-off-by: Michael Andreen <michael@andreen.dev>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Place undo commands for every change of the profile, not
only on "saving". Move the edit-mode from the mainwindow
and the maintab to the profile widget.
This is still very rough. For example, the only way to exit
the edit mode is changing the current dive.
The undo-commands are placed by the desktop-profile widget.
We might think about moving that down to the profile-view so
that this will be useable on mobile.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
It is confusing when undoing a command and nothing happens
in the UI. Therefore, switch to the corresponding dive when
undoing/redoing a replan or profile edit.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
These two actions were using the same command with a flag
controlling the name of the command, which is shown in
the undo menu.
However, the replanDive does much more (such as changing
the notes) and in the future we may want to be more
fine-grained with respect to profile editing. Therefore,
split these commands into two separate ones.
Moreover, make the editProfile command more flexible.
Pass an enum describing the action instead and also
a counter indicating how many points have been
moved or removed.
Finally, don't consume the input dive in the editProfile
command, because we will want to keep the original dive
while editing the profile.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In general, replace "dive master" by "dive guide".
However, do not change written dive logs for now. On reading,
accept both versions.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
User report: when switching focus between windows, the
cursor position gets lost. This is due to a note-edit
command being fired, which then overwrites the notes tab.
To prevent this, don't update the notes field when placing
a command. Moreover, generally don't update the dive
selection when placing a command as that also rewrites all
the values.
Should this be extended to other fields?
Fixes#3365
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In multiple places we have the problem that when an undo command
is executed, the corresponding value-changed signals are emitted,
which in turn updates the UI. This can have nasty UI effects, such
as the cursor position in the notes field being reset.
To avoid this, add a flag that indicates whether a newly placed
command is currently executed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
All data access is now directly via the plot_info structure
owned by the ProfileScene itself.
Also removes DivePercentageItem::hColumn, which was an
artifact from the DivePlotDataModel.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since there (currently) is no interactive widget on mobile, there
is no point in compiling it. This was a bit more complicated than
expected, since there were other source files (divehandler.cpp
and ruleritem.cpp) which reference ProfileWidget2 and therefore
need to be removed. Otherwise, the dreadful MOC produces unresolved
references.
We could now remove all the conditional compiles in
profilewidget2.cpp, but let's keep them for now. We might have
to readd a number of them later, when making the mobile-profile
interactive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
'constexpr' implies 'const' since it is a stronger guarantee,
so let's remove the redundant 'const'.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When adding a cylinder, it was added at the end of the list.
This would make hidden cylinders visible as the new rule is
to only hide unused cylinders at the end of the list.
Therefore, add the cylinder after the last used cylinder,
i.e. before the first hidden cylinder.
This means that the position where the cylinder is added has
to be hidden in the undo command.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The undo commands for depth and duration editing cleared
the samples of the dive computer. They relied on the profile
automatically creating a fake profile. However, at some point
that code got removed. Therefore, do it explicitly in the undo
command.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Only used in context of acquiring GPS locations with the mobile app, which
we no longer do.
Keep the DiveAndLocation structure around as that's needed by the
ApplyGpsFixes command.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Removal of a cylinder requires a renumbering of
cylinders in the core data structures (samples, etc.).
The renumbering was performed in the undo-action of
cylinder removal, but not during actual cylinder removal.
What a mess!
Add the missing call.
Attention: this makes the deletion of sensor-readings
on cylinder-deletion non-undoable!
Undo will have to be fixed in upcoming commits.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We no longer need the remove infrastructure, and the edit nickname function
becomes much more intuitive to use by passing in the dive computer for
which we want to create a nickname instead of the internal index into
the array of devices.
This also removes / simplifies the device list update signals in the
DiveListNotifier.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This is adding the capability to select 'Dive number' and 'Date / Time'
in the 'Copy dive components' dialog, and then copy them into the
clipboard.
When using 'Paste dive components, these values will then be pasted into
the selected dive(s).
This is intended to help with workflows that import dive information
from two different sources, like general information from another
logging program, and CCR ppO2 sensor readings from a unit log, and then
stitch them together into one cohesive entry with all data per dive.
Copied data is also output into formatted text when pasting the
clipboard outside of the application:
```
Dive number: 401
Date / time: Sun 2 May 2021 12:00 AM
```
No translations have been added as of now - I could not find any
information on how strings are translated for this project.
Signed-off-by: Michael Keller <github@ike.ch>
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>
The AddWeight, RemoveWeight, EditWeight and ReplanDive
commands were missing invalidate_dive_cache() calls.
Add them to ensure that the dives are written to git
logs on save.
Fixes#3150
Reported-by: Peter Zaal <peter.zaal@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Otherwise we end up showing the gasmix in a different form after editing
for the usual air percentages, because we haven't normalized the gasmix
values and store them back in the dive in the non-normalized format.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>