Commit graph

118 commits

Author SHA1 Message Date
Michael Andreen
be2bdb8650 undo: Clear undo stack on file close
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>
2022-04-03 08:34:39 -07:00
Berthold Stoeger
16aa761e86 core: make the QUndoStack a "global object"
Thus, it will be freed before application exit.

Freeing it later led to crashes.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-03-16 13:06:06 -07:00
Michael Andreen
451be04400 Fix merge problem in EditSensors
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>
2022-03-14 09:34:16 -07:00
Dirk Hohndel
6354f97321 fix merge problem
I guess I get what I deserve.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2022-03-13 16:59:32 -07:00
Michael Andreen
9b4263aa87 Allow editing sensors through equipment tab
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>
2022-03-12 11:24:50 -08:00
Berthold Stoeger
fce48367cd undo: more fine-grained undo of profile editing
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>
2022-03-12 18:32:22 +01:00
Berthold Stoeger
c5c8bfec65 undo: switch to dive after replan / profile edit
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>
2022-03-12 18:32:22 +01:00
Berthold Stoeger
ea0c030770 undo: split replanDive and editProfile commands
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>
2022-03-12 18:32:22 +01:00
Berthold Stoeger
9e0712d5dc core: replace dive master by dive guide
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>
2022-02-15 09:35:43 -08:00
Berthold Stoeger
889827aadb desktop: don't update notes field when executing command
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>
2022-02-15 09:34:23 -08:00
Berthold Stoeger
1b8f3a06ec undo: add flag that indicates whether a command has been placed
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>
2022-02-15 09:33:59 -08:00
Berthold Stoeger
7aacde3169 profile: remove ProfileScene::dataModel
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>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
d28f4d5347 profile: don't compile ProfileWidget2 on mobile
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>
2021-12-17 11:54:23 -08:00
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