aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets/command_edit.cpp
AgeCommit message (Collapse)Author
2019-10-26Undo: turn dive- and trip-fields into flagsGravatar Berthold Stoeger
The divesEdited signal sends the changed field as a parameter. Since some undo-commands change multiple fields, this led to numerous signals for a single command. This in turn would lead to multiple profile-reloads and statistic recalculations. Therefore, turn the enum into a bitfield. For simplicity, provide a constructor that takes classical flags and turns them into the bitfield. This is necessary because C-style named initialization is only supported on C++20 onward! Is this somewhat overengineered? Yes, maybe. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-26Undo: implement ReplanDive commandGravatar Berthold Stoeger
Implement an undo command that overwrites the dive-computers and cylinders of the current dive with a given dive. This will be used when replanning a dive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-24Desktop: fix crash on copy & pasteGravatar Berthold Stoeger
The constructor of PasteState was clearing an uninitialized weightsystem-table. Very silly. Initialize it instead. Fixes #2253 Reported-by: Stefan Fuchs <sfuchs@gmx.de> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-19Undo: make editing of dive number undoableGravatar Berthold Stoeger
When pressing F2 in the dive list, the number can be edited. Make this action undoable by implementing a EditNumber command. This command is differs from the other undo commands, as not the currently selected dives are changed. This means that the EditCommand needs an alternative constructor taking a single dive. This constructor was implemented in the base class so that all edit commands can now be called with a single dive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18Core: dynamically resize weight tableGravatar Berthold Stoeger
Replace the fixed-size weightsystem table by a dynamically relocated table. Reuse the table-macros used in other parts of the code. The table stores weightsystem entries, not pointers to weightsystems. Thus, ownership of the description string is taken when adding a weightsystem. An extra function adds a cloned weightsystem at the end of the table. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-23Cleanup: remove selectionChanged logic from dive-list commandsGravatar Berthold Stoeger
Since all commands now fully reset the selection, there is no point in keeping track of whether the selection changed on addition or removal of dives. This can be done in the function that sets the selection. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-23Undo: don't send signals batched by tripGravatar Berthold Stoeger
Since the default view is batched by trips, signals were sent trip-wise. This seemed like a good idea at first, but when more and more parts used these signals, it became a burden. Therefore push the batching to the part of the code where it is needed: the trip view. The divesAdded and divesDeleted are not yet converted, because these are combined with trip addition/deletion. This should also be detangled, but not now. Since the dive-lists were sorted in the processByTrip function, the dive-list model now does its own sorting. This will have to be audited. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19Cleanup: move tag functions into own translation unitGravatar Berthold Stoeger
Make dive.h a bit slimmer. It's only a drop in the bucket - but at least when modifying tag functions not the *whole* application is rebuilt anymore. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-15Undo: return number of changed dives from undo commandsGravatar Berthold Stoeger
To enable a "multiple dives edited" message, return the number of edited dives from dive edit undo commands. Since there are two kinds of these commands, viz. normal fields and tag fields, and the former use templates, create a common base class that can return the number of dives. Yes, the class hierarchy is getting scarily deep! At least, this gives a tiny bit of code-reuse. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-15Cleanup: remove silly typo in translation commentsGravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-15Convert the atmospheric pressure in the Information Tab to an editable fieldGravatar willemferguson
The Information tab shows the atmospheric pressure. Make this value editable and also ensure that changes to it are undo-able. Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2019-05-11Dive site: create new dive site at location from GPS dataGravatar Berthold Stoeger
Some dive computers save GPS data. Currently, this is stored by libdivecomputer in an "extra field". When generating a new dive site for a dive try to use this data to place the dive site. To do so, create a "dive_get_gps_location()" function. This function can be extended later to use e.g. event. When creating a dive site, use the result of this function over a potential pre-existing dive site. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: use QUndoStack::isClean() to determine unsaved changesGravatar Berthold Stoeger
Properly implement the unsaved-changes flag(s). Since we currently have two kinds of changes, there are two flags: 1) dive_list_changed in divelist.c marks non-undoable changes. This flag is only cleared on save or load. 2) QUndoStack::isClean() is used to determine the state of undoable changes. Every time the user returns to the state where they saved, this flag is cleared. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: move temperature update from MainTab to EditWaterTempGravatar Berthold Stoeger
The code in maintab is not called anymore (unless cylinders or weightsystems are changed). Move the code to the command that edits water temperature. This should be audited as it is unclear weather this is necessary. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: update cylinder and weight models on pasteGravatar Berthold Stoeger
When pasting (or undoing paste) the cylinders or weights may change. Send the appropriate signals and update the models accordingly. Currently, this means copying from current dive to displayed dive, but hopefully we can get rid of "displayed_dive" in the not so distant future. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Cleanup: remove EDIT_TEXT and EDIT_VALUE macros in maintab.cppGravatar Berthold Stoeger
These functions are now performed by the edit commands and the macros have no users. Remove them. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: select dives on undo of editing commandsGravatar Berthold Stoeger
Save selected dives when generating an edit-command. Restore the selection and current dive in undo()/redo(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: move dive-list logic into edit commandsGravatar Berthold Stoeger
The edit-commands were called with a list of selected dives and the original value. Move the creation of the list and extraction of the original value into the edit-commmands. This removes the "current is last" rule and allows for more flexibility. Since the depth- and duration editing applies only to the current dive and not all selected dives, add a parameter to the edit-commands controlling whether only the current or all selected dives are edited. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: update dive list after edit commandGravatar Berthold Stoeger
The dive list was not updated automatically when an edit command was executed. There was already a signal to do that, viz. divesChanged(). But that signal worked by-trip and didn't have a dive-field specifier. The edit-commands used the divesEdited() signal that isn't by-trip but has a dive-field specifier. Unify these two signals to be by-trip and with dive-field specifier. This needs common code to generate the by-trip list that is moved to a command_private.h header. Since there might now be multiple signals (one per trip) actually check in the main-tab whether the current trip is affected to avoid multiple update of fields. This has the positive(?) effect of not doing any update if the current dive isn't changed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: implement undo of depth and duration editingGravatar Berthold Stoeger
This was a bit different from the other editing commands: 1) Only the current dive is edited not all selected dives. Therefore, create a function that turns the current dive into a one-element list. 2) The profile has to be replot. Here, likewise, create a function to do that. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: implement undo of divemaster editingGravatar Berthold Stoeger
This is mostly a trivial copy of the buddies code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: implement undo of buddy editingGravatar Berthold Stoeger
This was mostly trivial by reusing the code for tag-editing. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: implement undo of tag editingGravatar Berthold Stoeger
The code follows the other edit-commands, but uses its own base class, because it is distinctly different. Editing the tag field does not simply mean setting the tag for all dives, but rather adding and removing individual tags. This class will be reused for editing of dive buddies and masters. Modify the tag widget thus that it sends an editingFinished() signal when it goes out of focus. The editingFinished() signal was prevented by hooking into the return, enter and tab key-events. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: implement undo of dive site editingGravatar Berthold Stoeger
This one is a bit more tricky. There are two modes: set dive site and set newly created dive site. This is realized using an OO model with derived classed. Quite convoluted - but it seems to work. Moreover, editing a dive site is not simply setting a value, but the list of dives in a dive site has to be kept up to date. Finally, we have to inform the dive site list of the changed number of dives. Therefore add a new signal diveSiteDivesChanged. To send only one signal per dive site, hook into the undo() and redo() functions and call the functions of the base class there. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: implement undo of air and water temperature editingGravatar Berthold Stoeger
Mostly trivial. Since now on editing the field is re-set, the validation function becomes unnecessary. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: implement undo of rating and visibility ratingGravatar Berthold Stoeger
This was rather trivial and modeled after the previous edit UndoCommands. Since this is the first time we're editing integers a new constructor instantiation had to be added. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: implement undo of suit editingGravatar Berthold Stoeger
This one was trivially modelled after notes editing. Only difference: the textChanged() signal was replaced by the editingFinished() signal so that we're not generating undo-commands on every key-press. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: implement undo of dive mode editingGravatar Berthold Stoeger
Add a new UndoCommand for dive mode editing. This one is a bit special, as the mode is associated with a dive computer (DC), not a dive. Thus the edit command has an additional parameter, viz. the index of the DC. This does not fit properly to the EditBase class, as this class isn't aware of additional parameters and therefore this parameter is not sent via signals. At the moment this doesn't matter. In any case, the semantics of editing are weird and therefore let's do the simple thing (derive from EditBase) and let's see what the future brings. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: update notes field if changed by undo commandsGravatar Berthold Stoeger
To keep the UI in a consistent state, update the notes field if it is changed by an undo command. To that purpose, add a new signal to diveListNotifier with a list of dives and a field-id as payload. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: implement rudimentary undo of dive-notes editingGravatar Berthold Stoeger
Implement a first rudimentary dive-editing command. The main code resides in a base class Command::Edit, which calls virtual functions to read / set the fields and extract the field name. Implement an example: editing of dive notes. This dose not yet update the UI on undo / redo. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>