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>
The undo-code must take care not to remove used cylinders.
To do so, extend the constructor of EditCylinderBase,
which collects the cylinders and dives to edit, by the
"nonProtectedOnly" boolean argument. If true, only those
cylinders for wich "is_cylinder_prot" returns false
will be added.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The cylinders in the events must be reordered if we remove
a cylinder. To avoid duplication of code, move the reordering
function into qthelper.cpp, though it might not be ideal
there.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Do a simple copy & paste followed by a simple search & replace
to generate cylinder undo commands from weight undo commands.
Obviously, this is still missing the necessary code to keep
the dive-data consistent after cylinder editing.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When editing the dive site of a dive, the dive-table of the
corresponding dive site was not properly updated by the undo
commands. Try to get this right.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Do this in analogy to other types. However, here we have to convert
from / to QString. We could do this in an even more general way
by using two templat parameters: one for the Qt type, one for the
core type and define conversion functions. However, let's not do
this for now.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Some dive-editing undo commands have trivial setter and getter
functions: they simply read and write a struct dive member.
Autogenerate these in a template to which we pass a pointer
to member as template argument.
For the invalid-flag we have to turn the edit command from int
to bool, since that is how the flag is store in the dive struct.
Sadly, quite a number of the setters do funky things and we
cannot autogenerate them.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Most edit commands derive from a common base class EditBase,
which declares a fieldId() virtual function that has to be
defined by the child classes. This is tedious. For some reason
the C++ makers refuse to allow "virtual member constants".
To make the code somewhat less verbose, create these functions
by a template. Of course, we could introduce the template
parameter directly in the EditBase class. However, that would
mean that the code in this base class is generated for every
single undo command. I'm not sure we want that.
This should als make it somewhat less tedious to create new
edit commands by copy & paste.
We could do the same for the fieldName. However, that is more
complicated for two reasons:
1) For historic reasons(?) C++ doesn't allow for string literals
as template parameters. Therefore, arrays-of-string would have
to be defined, which is not very nice.
2) We would have to make sure that these strings are recognized
by Qt's translation machinery and use the QT_TRANSLATE_NOOP
macro, which makes the whole thing even less attractive.
Maybe later.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In the mobile version of the dive-editing command, the fulltext
filter was not updated. Thus, when editing a dive while the filter
was active, the dive would disappear.
Unregister the old and register the new version.
Reported-by: Chirana Gheorghita Eugeniu Theodor <office@adaptcom.ro>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When editing dives, the undo-command sends a filte changed signal.
The models catch the signal and check whether the filter status
changed.
The mobile-version of the dive-edit command simply exchanged the
dives. This could lead to inconsistencies when the filter flag
was overwritten. Therefore, make sure that the filter flag
is not overwritten by the dive-exchange.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The way inheritance is implemented for the undo commands confuses the Qt
translation tooling - with the result that the context assumed by the
tools used to extract the strings doesn't match the context calculated
at runtime - so all the translations for the strings in undo commands
fail (including creating proper numerus forms).
This change forces a consistant context tag, at the price of creating a
significant delta for the source strings (the strings themselves stay
the same, but the context for a lot of them changes). I am hoping that
Transifex is smart enough to automagically add the correct translations
for these, but I guess I won't know until I try.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
In edit commands, the fulltext might have changed and therefore
we have to update the fulltext index.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Grammar-nazi ran
git grep -l 'indexes' | xargs sed -i '' -e 's/indexes/indices/g'
to prevent future wincing when reading the source code.
Unfortunatly, Qt itself is infected as in
QModelIndexList QItemSelection::indexes() const
Signed-off-by: Robert C. Helling <helling@atdotde.de>
For many of the commands it is fairly easy to add information that makes
it easier to figure out what actually happened. That's especially true
for commands operating on dives. Trip and dive site edits haven't been
given these more elaborate undo texts (yet).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Create a C string (which the caller needs to free) with the executed commands
in this session.
The detour via the callback allows us to not make the corelib depend on the
commands, which is nice for tests, export-html, and smtk2ssrf.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Command that just swaps two dives. This is rather complex,
as for example a dive site might be created.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This gets a list of dives with GPS fixes and
1) Adds new dive sites if the dive hasn't a dive site set
2) Edits the location of the dive site
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
At least in those cases where we are sending a divesChanged signal we can
easily check if the cache was properly invalidated. Of course this won't help
in cases where we don't notify the dive list about changes, either.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
There are two cases where dive-times are shifted: in an explicit
dialog and when editing the date/time of a dive.
In each of these cases, the selected dives were collected manually.
Instead use the getDiveSelection() function. Since this returns
a std::vector, change the argument of Command::ShiftTime() to
such a std::vector.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The DiveFilter class defined the showDive() function to test
whether a dive should be filtered or not. This was used in
DiveTripModel to loop over all dives or all dives affected by
an editing action.
This restricts us in how we do filtering: We can't use indexes
that give us directly the result. To make the filtering more
flexible, move the actual loops that do the filtering to
the DiveFilter class.
The undo-commands likewise called directly the showDive()
function to check whether newly added dives are shown.
Use the new interface here as well.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In moveDiveToTrip(), the dive was first removed from its old trip
and then added to the new trip. This function is also used to
remove the dive from its trip (by moving it to the "null-trip"
if you whish). Even in that case add_dive_to_trip() was called.
The only reason why this didn't crash is that add_dive_to_trip()
checks whether old and new trip are the same. This is the case
when adding to the "null-trip", since the dive was removed from
the trip just before.
To cut a long story short, to trust on add_dive_to_trip() not
crashing if moving from the null-trip to the null-trip is
way to subtly. If we remove a dive from its trip, don't call
add_dive_to_trip() in the first place.
Reported-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
These just make no sense. Since the value is copied, it
has no meaning to the caller whether the function can
change the value (and vice versa for return types).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We tend to use lower-case filenames. Let's do it for these files
as well. Simple search & replace.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In a total abundance of caution, make sure we don't exit the constructor
leaving fields uninitialized.
Fixes CID 351437
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Currently, selecting a single dive or deselecting all dives was
quite awkward: One had to pass in a single-dive vector and the
dive itself (as current dive). Provide a convenience function
that selects a single dive or deselects all dives if null is
passed in.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We relied upon the translators to remove the parenthesis in cases
like "Edited notes (%n dives)" for n = 1 dives. Dirk doesn't want
that. Therefore, do it in the C++-code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Implement the EditWeight undo command. Since there is common code
(storage of the old weight), this creates a common base class for
RemoveWeight and EditWeight. The model calls directly into the undo
command, which is somewhat unfortunate as it feels like a layering
violation. It's the easy thing to do for now.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of freeing internal data of the weightsystem structure,
call the free_weightsystem function (which has to be made extern
at first). This makes things more future-proof, should the
weightsystem struct ever be extended.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>