summaryrefslogtreecommitdiffstats
AgeCommit message (Collapse)Author
2020-04-07cleanup: remove conditional compilation in cylindermodel.cppGravatar Berthold Stoeger
Parts of the code were not compiled on mobile, because they used the undo-command infrastructure. However, since mobile now also compiles that, we might as well remove the conditional compilation. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: call invalidate_dive_cache() when editing cylindersGravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: make static fields local to ComboBoxDelegateGravatar Berthold Stoeger
All combobox-delegates shared a number of static status fields. In a quest to make the code more reentrant, move that to the actual object. The fields have to be defined as mutable, since they are set in const member functions. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: remove TankInfoDelegate::reenableReplotGravatar Berthold Stoeger
Update of the profile is now done by the undo-commands. If the planner needs this, it is probably better to connect directly to the model, not the delegate. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: remove unneeded includes from TabDiveEquipment.cppGravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: show multiple dive warning when editing equipmentGravatar Berthold Stoeger
When editing cylinders or weights directly in the table widgets, no warning was shown if multiple dives were affected. To solve this, emit signals from the respective models and catch them in dive equipment tab. Not very nice, but it works for now. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: more fine-grained editing of cylinderGravatar Berthold Stoeger
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-07undo: store all cylinders in EditCylinderBaseGravatar Berthold Stoeger
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-07cleanup: remove same_cylinderGravatar Berthold Stoeger
The last user was uses a more general function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: be more flexible about which cylinders to editGravatar Berthold Stoeger
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-07desktop/tabwidgets: replace editMode by booleanGravatar Berthold Stoeger
There was only one editMode left (MANUALLY_ADDED_DIVE). Therefore replace by a flag. This makes the code more consistent, because the conditions "editMode != NONE" and "editMode == MANUALLY_ADDED_DIVE) actually meant the same thing. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07desktop/tabwidgets: replace IGNORE_MODE by flagGravatar Berthold Stoeger
The editMode was set to IGNORE_MODE when programatically setting fields so that we can ignore changed-signals. That seems to be orthogonal to whether we are in edit mode and indeed when setting IGNORE_MODE the edit mode was saved and restored. Therefore, replace the IGNORE_MODE by an independent ignoreInput flag. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07desktop: properly initialize activeText of model-delegatesGravatar Berthold Stoeger
For reasons that I don't understand, we keep track of the current combo-box text for our model-delegates. However, that text was not initialized when the editor was generated, leading to a UI bug in the cylinder and weight widgets: Activate a field, click somewhere else -> either the empty string or the previous string was set. Reported-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cylinders: use preferences modpO2 preferences valueGravatar Berthold Stoeger
Use the user-editable MOD-pO2 preferences value when creating a default cylinder. It is not clear to me, when that even has a consequence, but it looks like the right thing to do. Reported-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: reload dive on removal of gas-switchGravatar Berthold Stoeger
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-07undo: switch to affected dive on undo/redo of event-changesGravatar Berthold Stoeger
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-07cleanup: remove commented-out evn_foreach() functionGravatar Berthold Stoeger
Apparently this was used to hide events in pre-Qt times. However, that has already been reimplemented in different ways. Let's remove that commented-out code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: remove remove_event() functionGravatar Berthold Stoeger
No user left. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: implement gas switchGravatar Berthold Stoeger
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-07cleanup: remove vintage report_error() function declarationGravatar Berthold Stoeger
Remove an old commented-out declaration. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07core: split out create_gas_change_event() from add_gas_change_event()Gravatar Berthold Stoeger
For undo, we want to create gas change events without adding them immediately to the dive computer. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: move add_gas_switch_event to dive.cGravatar Berthold Stoeger
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>
2020-04-07undo: add event removal undo commandGravatar Berthold Stoeger
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-07undo: implement renaming of eventsGravatar Berthold Stoeger
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>
2020-04-07undo: split out EventBase classGravatar Berthold Stoeger
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>
2020-04-07undo: implement set point change undo commandGravatar Berthold Stoeger
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>
2020-04-07undo: switch SetpointDialog from divecomputer to dive + dc-numberGravatar Berthold Stoeger
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>
2020-04-07cleanup: use pointer-to-member version of connect in SetpointDialogGravatar Berthold Stoeger
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>
2020-04-07cleanup: un-singletonify SetpointDialogGravatar Berthold Stoeger
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>
2020-04-07undo: add undo command for dive-mode switchGravatar Berthold Stoeger
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>
2020-04-07undo: replot profile if event changedGravatar Berthold Stoeger
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>
2020-04-07undo: implement addBookmark undo commandGravatar Berthold Stoeger
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>
2020-04-07core: add remove_event_from_dc() functionGravatar Berthold Stoeger
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>
2020-04-07core: split add_event() in two partsGravatar Berthold Stoeger
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>
2020-04-07cleanup: demote slots in ProfileWidget2 to private functionsGravatar Berthold Stoeger
Since we call these with lambdas, they don't need to be slots anymore. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: use QMenu::addAction() convenience overloadGravatar Berthold Stoeger
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>
2020-04-07cleanup: use lambdas to transport DiveEventItem to actionsGravatar Berthold Stoeger
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>
2020-04-07cleanup: use lambda to transport event-time to context menu actionsGravatar Berthold Stoeger
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>
2020-04-07cleanup: don't set unnecessary action userdata for unhideEventsGravatar Berthold Stoeger
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>
2020-04-07profile: use lambda for addDivemodeSwitch callsGravatar Berthold Stoeger
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>
2020-04-07cleanup: use SAMPLE_EVENT_BOOKMARK in add_event() callsGravatar Berthold Stoeger
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>
2020-04-07cleanup: remove DIVE EditMode in MainTabGravatar Berthold Stoeger
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>
2020-04-07cleanup: remove parameter to MainTab::enableEditionGravatar Berthold Stoeger
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>
2020-04-07desktop: remove EDIT modeGravatar Berthold Stoeger
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>
2020-04-07desktop: move undo-disabling from enterEditState to disableShortcutsGravatar Berthold Stoeger
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>
2020-04-07undo: update profile on cylinder editingGravatar Berthold Stoeger
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>
2020-04-07CylindersModel: use flag to decide whether we are in plannerGravatar Berthold Stoeger
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>
2020-04-07undo/cylinder: call undo command to edit cylinder fieldsGravatar Berthold Stoeger
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>
2020-04-07undo/cylinders: Implement editing of the typeGravatar Berthold Stoeger
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>
2020-04-07cleanup: remove default-code for editCurrentDiveGravatar Berthold Stoeger
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>