Since all the other event-functions are also defined there.
Ultimately, we should probably move them to their own
event.c translation unit.
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>
Since pointers to divecomputers may not be stable, the undo
commands take a dive + a divecomputer number. Update the
SetpointDialog accordingly.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
While touching this dialog, might as well change away from the MOC
version of the connect() statements.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We have too many global objects. There is no reason why this dialog
should be a persistent global object.
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>
We have a remove_event() function that
1) frees the event
2) works on the current divecomputer
3) compares the events because the profile has copies of events
However, for undo commands
1) we want to keep the event so that we can readd it later
2) we have to work on arbitrary divecomputers
3) we don't work with copies of events
Therefore, create a new remove_event_from_dc() function that
does all that. Moreover, make the event argument to remove_event()
const to (slightly) point out the difference in the API.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
add_event() creates and adds an event from the given parameters.
For undo, we want to do these separately, therefore split this
function in two parts: create_event() and add_event_to_dc().
Keep the add_event() function for convenience. Moreover, keep
the remember_event() call in there, so that undo-commands can
call remember_event() once, not on every undo/redo action.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since we removed the setData() calls of the QActions in
ProfileWidget2::contextMenuEvent(), we don't have to manually
generate the QActions. We can simply use the convenience
overload of addAction() that takes a string and a functional.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The removeEvent(), hideEvents() and editName() actions need
the DiveEventItem they are applied to. This was transported
via QAction's user-data, which means casting to void and
back.
By using lambdas instead, this can be made perfectly type-safe:
First we are 100% sure that we have a DiveEventItem because
we check the result of a dynamic_cast<>. Then we can pass
it to the even using its proper type.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is not such a big gain as for addDivemodeSwitch(), but still
simpler. Therefore, let's do it for consistency.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The unhideEvents context menu action was fed with the click-position.
However, that was not used. Therefore, remove it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The data was transported via the action in a most complicated way:
The text was backtranslated. Simply use a lambda - perhaps hard to
read, but much simpler to follow and less brittle.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In two cases we were passing the magic value 8 instead of the
symbolic SAMPLE_EVENT_BOOKMARK. Use the symbolic version instead.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
That mode is not used anymore, since only the editing of
profiles of manually added dives enters editing mode. For
that case we have the MANUALLY_ADDED_DIVE edit mode.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
All remaining callers were passing MANUALLY_ADDED_DIVE as a new
mode, so we may just as well remove the parameter and thus
simplify the logic.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The only way to enter edit mode is to edit the profile. However,
that means that the profile is already visible, so there is no
need to change the mode. Simply remove the EDIT mode.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When entering the edit state, we don't want the user to be able
to undo/redo lest things become inconsistent. Since the only way
to enter edit state is to edit the profile, we can simply use
the disableShortcuts() function that is used by the profile
when it goes into edit state.
This has one desirable side-effect: Undo is now also disabled in
the planner. Undo during planning likewise can lead to inconsistent
state.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In the profile, catch cylinder-editing signals and redraw the
profile if the currently displayed dive has changed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
On desktop, we have two CylindersModel concurrently: One in the
planner and one on the equipment-tab. They act differently, because
the former modifies displayed_dive directly, the latter issues
undo commands.
To differentiate, we used the in_planner() function. However, that
appears extremely brittle, especially when combined with undo-commands.
Therefore when generating the model, pass in a parameter that says
whether this is for the planner or the equipment tab and use
that flag to decide how to act.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Call an undo command when editing cylinders, but only if on
the EquipmentTab.
To keep code changes small, make a copy of the cylinder first,
then edit the cylinder as before and then either call an undo
command (EquipmentTab) or overwrite the old cylinder (Planner).
The memory management here is a bit strange: Since the undo-command
itself makes a deep-copy of the passed in cylinder, we only do
a shallow copy. If we have to change the type, we allocate the
string with an std::string, so that the memory is automatically
freed at the end of the function. However, this means that in
the planner we have to make a deep copy first, swap old and
new cylinder and finally release the old cylinder. Certainly
not ideal, but for now the pragmatic thing to do.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This one is tricky, as when browsing through the types-combobox,
the user is presented with presets without actually changing the
dive. We do not want an undo-command for every change-event in
the combo-box.
Therefore, implement a scheme analoguous to the weight-editing:
A temporary row can be set / committed or reset. Sadly, the
code is more complex because we have to consider the planner,
which is not included in the undo system.
Firstly, the planner uses a different model, therefore all
interactions are channeled through setData() with special roles.
Secondly, in the planner we shouldn't place an undo command,
but simply overwrite the dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The profile can only be edited for manually added or planned
dives. No point in keeping code for other kinds of dives.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The edit state is now only used to edit the profile. There is no
reason to disable random tabs.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The editing of the dive site is controlled via an undo command.
No point in centering the map when cancelling a profile-edit.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This stored the old editMode. However, it was not read after
editMode was changed, so there is no point to it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The "dive is currently" edited is only shown when the profile is
edited. This affects only the current dive and therefore a
message saying that multiple dives are edited makes no sense.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When enableEdition() was called with mode == NONE and the dive
was a manually added dive, it would call into MainWindow::
editCurrentDive(), which would in turn call enableEdition(),
however with another mode. Since the only caller of
enableEdition() is now editCurrentDive() anyway, we can
remove that weird code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
add() and remove() are not used anymore since this is done using
undo commands. The planner uses CylindersModel instead.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The CHANGED macro was defined in the cleanerTableModel header.
Since it had only one user, expand it there. The macro was very
questionably anyway, as it would set the local "vString" variable.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
A small code consolidation:
With one exception, all targets of the switch statement would
test for CHANGED(). Instead do the test once and exit early.
This changes the behavior of the function: if not changed, there
will be no more dataChanged-signal. However, this appears to be
the correct thing to do anyway. And it is easily changed if
it matters after all.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Cylinder-editing is controlled by undo (either by saving a planned
dive or by using the equipment tab). There is no point in setting
the dive_list_changed flag.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since cylinders are now edited using the undo system, these
functions are not needed anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of connecting to the remove() function of the model,
call the removeCylinder undo command. Take care to translate
the index into the source index, should cylinders be hidden!
Apart from the map-to-source call, this copies the weightsystem
code.
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>
The CylinderModel always accessed the global "displayed_dive" and in
some special cases also "current_dive". To implement cylinder undo,
the model should work on an arbitrary dive. Therefore, in analogy
to the weight model, make the dive dynamic.
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>