Commit graph

105 commits

Author SHA1 Message Date
Berthold Stoeger
5d1f12438b cleanup: remove 'const constexpr' pairs
'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>
2021-12-17 10:36:13 -08:00
Berthold Stoeger
1af67512a1 cylinders: add cylinder before hidden cylinders
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>
2021-12-13 11:54:24 -08:00
Berthold Stoeger
cbe6d89767 profile: fix editing depth / duration
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>
2021-12-04 09:40:08 -08:00
Dirk Hohndel
6f813b9f8e mobile: remove GpsLocation
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>
2021-09-13 11:21:34 -07:00
Berthold Stoeger
64faa23448 undo: renumber cylinders when deleting a cylinder
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>
2021-09-03 13:35:28 -07:00
Dirk Hohndel
e7a5ec46f5 undo/device: adjust device management infrastructure
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>
2021-08-18 13:22:02 -07:00
mikeller
2d734c529b desktop: Add the capability to copy / paste dive number and date / time.
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>
2021-05-19 15:15:34 -07: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
Berthold Stoeger
5692f0d68a undo: add missing invalidate_dive_cache() calls
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>
2021-01-11 08:42:17 -08:00
Linus Torvalds
1808804bab Make sure to sanitize the gasmix after editing it
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>
2021-01-10 13:44:43 -08:00
Berthold Stoeger
c53bab8965 filter: internalize shown_dives in DiveFilter class
one piece of global state removed!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-29 08:34:09 -08:00
Berthold Stoeger
9e84fd935b filter: keep track on shown_dive on dive removal in DiveFilter
When removing dives, the UndoCommands would keep track of the
shown dives. When adding, they were calling into the filter
instead. Let's remove this asymmetry.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-29 08:34:09 -08:00
Berthold Stoeger
3c786e35c3 undo: fix annoying warning message when deleting pictures
The RemovePictures command filters the pictures provided by the
UI: only actually existing pictures are removed. The code was
buggy: the original list was copied and then the filtered list
was added. Thus, every picture was listed twice leading to
annoying warning messages. Remove the copy.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-19 20:19:51 +01:00
Berthold Stoeger
77566fe285 undo: add \n to console warning error messages
To make the output more readable.

Moreover, fix a comment-typo.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-19 20:19:51 +01:00
Berthold Stoeger
50b11024d6 core: keep tank infos in a dynamic table
The list of known tank types were kept in a fixed size table.
Instead, use a dynamic table with our horrendous table macros.
This is more flexible and sensible.

While doing this, clean up the TankInfoModel, which was leaking
memory.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-13 11:49:59 -08:00
Berthold Stoeger
16f86f2f65 desktop: use getDiveSelection to access selected dives
In the list view two functions were still manually collecting
the selected dives. Use getDiveSelection() there as well.

Careful: that means that the check for dives that are already
outside of a trip now has to be done in the RemoveDivesFromTrip
command.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-12 15:52:40 -08:00
Berthold Stoeger
52d5125926 undo: add a general dives-imported signal
Add a general dives-imported signal for those cases where we
want to fully rebuild models, notably, the completion models.
The divesAdded signals are too fine, because they are sent
per trip and we don't want to reload these models multiple
times per import.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-11-14 10:01:50 -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
Dirk Hohndel
f193c2ef08 cleanup: fix deprecated QVector constructor
Annoyingly, the replacement has only been available since Qt 5.14.
To make the code less messy, implement our own stdToQt conversion helper.

Suggested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-26 19:27:03 -07:00
Berthold Stoeger
b984839836 cleanup: remove pref.h include in dive.h
If source files want to access preferences functions, they should
include pref.h themselves.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:52 -07: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
faebb53909 undo: add device related undo commands
Add commands for deleting devices and editing device nicknames
to include the device-handling in the undo system.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:04 -07:00
Berthold Stoeger
39a4090c0a devices: add devices in Command::importTable()
Add a device_table parameters to Command::importTable() and
add_imported_dives(). The content of this table will be added
to the global device list (respectively removed on undo).

This is currently a no-op, as the parser doesn't yet fill
out the device table, but adds devices directly to the global
device table.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24 09:51:37 -07:00
Berthold Stoeger
a7bbb6c1cc filter: remove filter_preset_table_t
We used a typedef "filter_preset_table_t" for the filter preset table,
because it is a "std::vector<filter_preset>". However, that is in
contrast to all the other global tables (dives, trips, sites) that we
have.

Therefore, turn this into a standard struct, which simply inherits
from "std::vector<filter_preset>". Note that while inheriting from
std::vector<> is generally not recommended, it is not a problem
here, because we don't modify it in any shape or form.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-17 09:04:20 -07:00
Berthold Stoeger
f9721fce4b filter: implement importing of filter presets
When importing a divelog, import filter presets. If there are
equal names, import only if the presets differ. In that case,
disambiguate the name. This made things a bit more complicated,
as comparison of filter presets had to be implemented.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
2f5223035a filter: add filter preset undo commands
Add undo commands to add / edit / delete filter presets.
These are styled after the other undo commands: On changes,
the UI is informed by DiveListNotifier signals. Editing is
a simple std::swap of values.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Berthold Stoeger
048cdcaa31 cleanup: remove count_divecomputers() function
There is a number_of_computers() function which does
the same thing with two exceptions:
1) checks for null-dive
2) returns an unsigned int

Replace calls to count_divecomputers() by calls to number_of_computers().
In one case, the return type makes a different - add a cast to int there.
Ultimately, we should probably change the dc_number to signed int
throughout the code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-08 17:20:09 -07:00
Berthold Stoeger
55e4237306 cleanup: copy string in taxonomy_set_[country|category]
These functions were taking a const char *, yet taking ownership
of the value. Moreover, taking ownership of strings is rather
unusual in C-style APIs. Let's copy the string instead.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06 12:59:54 -07:00
Berthold Stoeger
fe3021b88a cleanup: consistently use get_cylinder() accessor
get_cylinder(d, i) is more readable than d->cylinders.cylinders[i].
Moreover, it does bound checking and is more flexible with respect to
changing the core data structures. Most places already used this accessor,
but some still accessed the cylinders directly.

This patch unifies the accesses by consistently switching to get_cylinder().
The affected code is in C++ and accesses the cylinder as reference or
object, whereas the get_cylinder() function is C and returns a pointer.
This results in funky looking "*get_cylinder(d, i)" expressions.
Arguably still better than the original.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-08-21 08:48:22 -07:00
Berthold Stoeger
ab6cac9799 media: give newly created dive sites a name
When adding a picture with GPS information, a dive site was added
if the dive didn't have any. The dive site had the empty string as
name, leading to a confusing UI experience.

We could catch the empty string at numerous places and replace it
by some dummy string. This commit goes the distinctly less invasive
route and adds the dive site with the "unnamed dive site" string
(translated to the user language) as name.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-08 08:51:37 -07:00
Berthold Stoeger
4374605c12 undo: make adding of pictures undoable
This one is a bit hairy, because two things might happen if the
picture has a geo location:
- A dive gets a newly generated dive site set.
- The dive site of a dive is edited.
Therefore the undo command has to store keep track of that.
Oh my.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
434644b381 undo: make picture (media) deletion undoable
The code is rather complex. Firstly, we have different representations
of pictures throughout the code. Secondly, this tries to do add the
pictures in batches to the divepicture model and that is always rather
tricky.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
e61641c79c undo: implement undo of setting a picture time by drag&drop
Even though the functionality is seemingly trivial, this is a bit
invasive, as the code has to be split into two distinct parts:
1) Post undo command
2) React to changes to the divelist

Don't compile that code on mobile.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
beef8096f7 undo: update cylinder related info when editing cylinder data
We have to call update_cylinder_related_info() when adding /
editing / removing cylinders. This could be done in a common
base class of the commands. For simplicity, let's call
the function in the respective undo()/redo() functions.

Partially fixes #2814.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 11:44:22 -07:00
Berthold Stoeger
09b7fcbcf4 selection: add selection flag for trips
In analogy to dives add a selection flag for trips. The reason
being that search for a selected trip can be painfully slow when
we do it through Qt's proxy model.

Make sure to deselect trips when they are removed from the core.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-03 15:02:21 -07:00
Berthold Stoeger
e535ac90f9 cleanup: remove unnecessary include in command_divelist.cpp
"code/display.h" needs not be included anymore for selection
things.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-02 14:52:51 +02:00
Berthold Stoeger
95284c026e cleanup: move dive_table from dive.h to divelist.h
This allows us to decouple dive.h and divelist.h, a small step in
include disentangling.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 09:42:31 -07:00
Berthold Stoeger
b949bad026 core: always keep an empty cylinder at the end of the cylinder array
This will be temporarilly used by the planner to mark consumption of
air at the surface. Do this by creating a new function add_cylinder,
which replaces add_to_cylinder_table() and takes care of always adding
a dummy cylinder at the end of the table. Make the original
add_to_cylinder_table() local, so that it cannot be accessed anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 12:36:28 +02:00
Berthold Stoeger
f43b3f56b2 cleanup: remove Command::inCommand()
This was used by the divelist to check wether a selection change is
programmatical or user-initiated. However, since there is only one
entry point for programmatical selection changes, this is not needed
anymore. Remove it - this removes an inter-module dependency.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-26 13:54:59 -07:00
Berthold Stoeger
103951bc78 divelist: when removing/adding a dive unregister/register fulltext
This fixes a crash: when the undo commands removed a dive from
the list, the fulltext cache was not cleared. If now the divelist
is reset and then the undo-command deleted, deletion of the owned
dive tries to remove it's fulltext cache, which doesn't exist
anymore.

For reasons of symmetry, when readding the dive, its fulltext
has to be registered.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-13 08:52:48 -07:00
Dirk Hohndel
6d187b5f4a
Merge pull request #2643 from bstoeger/cylinder4
First steps of cylinder-editing undo
2020-04-11 11:03:05 -07:00
Berthold Stoeger
4489389a01 undo: refine pasting of cylinders
When pasting cylinders, the destination dive got a verbatim copy
of the cylinders of the source dive. This is not what users want:
for example, the start and stop pressures from the dive computer
as well as the gas mix may be overwritten.

There seems to be no perfect solution, since some times users may
want to paste the gas-mix.

Therefore, let's choose a heuristic approach for now (in the future
we might implement a UI-flag):

When copying over existing cylinders, only copy type and maximum
pressure.

When adding new cylinders (i.e. from-dive has more cylinders than
to-dive), copy everything, but reset start- and top-pressure to 0,
which represents unkown.

Moroever, in the latter case, set "manually added" to true, since
obviously this wasn't added by a dive computer.

Fixes #2676

Reported-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-10 09:43:32 -07:00
Berthold Stoeger
e2f77f9238 undo: call invalidate_dive_cache() when editing cylinders
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
2eeb5f4fc2 undo: more fine-grained editing of cylinder
Don't overwrite the full cylinder when editing a single field.
Implement three "modes": editing of type, pressure and gasmix.

Don't consider individual fields, because some of them are
related. E.g. you can change the gasmix by setting the MOD.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
4e8a838f74 undo: store all cylinders in EditCylinderBase
We stored only one cylinder in EditCylinderBase, which is the
base class of RemoveCylinder and EditCylinder. This turns out
to be too crude: when removing the "same" cylinder from
multiple dives, there are some "hidden variables" such as
bestmix_o2 or manually_added, which might actually be different.
We don't want to overwrite those on undo of delete.
Moreover, the cylinder edit is way too crude at the moment,
as it overwrites the whole cylinder even when the user edited
only a single field. To enable a more refined edit, we have
to store each changed cylinder.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
79d117b5bc undo: be more flexible about which cylinders to edit
Currently we use the same_cylinder() function to determine
which cylinders should be edited in a multi-dive edit. Make
this more flexible by introducing a flag-set, such that
the undo-command can select which cylinders are considered
as equal:
	- same type
	- same pressure
	- same gas mix
	- same size

Currently both undo commands use same type, pressure and
gas so that the behavior stays unchanged.

The future goal is to split the cylinder-edit undo command
into different commands so that when, for example, editing
the type only the type is considered by not the gas mix.

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