aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets/command.cpp
AgeCommit message (Collapse)Author
2019-06-15Undo: only show warning message if dives were actually editedGravatar Berthold Stoeger
The multiple-dives-edited message was shown even if the value was not changed. Notably, when tab-flipping through the dive fields. Therefore, changed the execute_edit() function to return zero when no command was executed. For this, return a boolean from the execute() function indicating whether the command was really executed or trashed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-15Cleanup: unify comments in desktop-widgets/command.hGravatar Berthold Stoeger
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-05-20Undo: make "delete dive computer" undoableGravatar Berthold Stoeger
Simply reuse the code for "move dive computer" by creating a DiveComputerBase base class. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-20Undo: make "move dive computer to front" undoableGravatar Berthold Stoeger
Instead of the elegant solution that just modifies the dive, keep two copies and add either the old or the new copy. This is primitive, but it trivially keeps the dives in the right order. The order might change on renumbering the dive computers. 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-06Add undo/redo commands for importing dive sitesGravatar Doug Junkins
ImportDiveSites adds the provided dive sites to the core dive site table and stores the source data so it can be undone. Signed-off-by: Doug Junkins <junkins@foghead.com>
2019-04-12Undo: remove ADD mode from main tabGravatar Berthold Stoeger
Instead of letting the user edit the fields before adding a dive, simply add an empty dive. Thus, the ADD mode of the main tab can be removed. Constructing a new dive with default-depth and making sure that the dive is displayed correctly is very subtle. This all needs to be detangled in due course. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: implement undo of dive trip editingGravatar Berthold Stoeger
This is copying the dive editing code. It uses an OO design with virtual functions for getting and setting the values. It doesn't use templates though, as both fields of strig type. This feels a bit over-engineered, but it is 1) consistent with the dive edit code and 2) the number / types of dive trip fields might increase. 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: 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: 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: 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>
2019-04-12Dive site: implement purge of unused dive sitesGravatar Berthold Stoeger
Add a "purge unused dive sites" button to the dive site list. Connect it to a new PurgeUnusedDiveSites command. Implementation was trivial: simply copy the DeleteDiveSites command. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: make dive site merging undoableGravatar Berthold Stoeger
This one was rather trivial, as there is no actual merging done. Quite simply, a number of dive sites are removed and their dive added to a different dive site. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: implement undo of geo lookupGravatar Berthold Stoeger
Simply copy code of the other edit dive site functions. Here though introduce a destructor in the undo command to free the taxonomy data. Remove the taxonomy member of the LocationInformationWidget class, because it is not needed anymore. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Dive site: remove edit mode from dive location widgetGravatar Berthold Stoeger
Since no dive site field editing enters edit mode anymore, the whole edit mode state and code can be removed from the widget. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: implement undo of dive site location editingGravatar Berthold Stoeger
Simply copy the code of note editing. It's a bit more complex, since we have to parse the Gps coordinates. For consitency, rename the COORD field to LOCATION (the field in the dive_site struct is called LOCATION). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: implement undo of dive site country editingGravatar Berthold Stoeger
Simply copy the code of notes editing, but use the taxonomy_* functions to read and set the value. Moreover, replace the three TAXONOMY_n field ids by a single TAXONOMY id. We will probably never show one column per taxonomy field, but rather a single column with a string derived from all taxonomy fields. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: implement undo of dive site notes editingGravatar Berthold Stoeger
Simply copy the code of description editing. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: implement undo of dive site additionGravatar Berthold Stoeger
Implement a dive site addition undo command and connect it to the add dive site button. The added dive site has a default name ("new dive site"). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: implement undo of dive site description editingGravatar Berthold Stoeger
Simply duplicate the code of dive site name editing. Split out the common functionality that swaps a C and a Qt string. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: Implement undo of dive site name editingGravatar Berthold Stoeger
Implement an undo command that edits the name of a dive site. Connect it to the dive site table, so that names can be edited directly in the table. Send signals on undo / redo so that the dive site table and the dive site edit widget can be updated. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: make dive site removal undoableGravatar Berthold Stoeger
Create a new undo-command for deleting dive sites. If there are dives associated with that site, the dives will be removed. The frontend is not yet updated in such a case, as that infrastructure is in a different PR. Connect the trashcan icon of the dive site table to the undo command. Currently, this code is in the dive site model, which makes little sense, but is how the TableView class works. We might want to change that when cylinder and weight editing are made undoable. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: consider dive site in AddDive()Gravatar Berthold Stoeger
If a dive site was added for a new dive, remove it on undo. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: make undo-system dive site-awareGravatar Berthold Stoeger
As opposed to dive trips, dive sites were always directly added to the global table, even on import. Instead, parse the divesites into a distinct table and merge them on import. Currently, this does not do any merging of dive sites, i.e. dive sites are considered as either equal or different. Nevertheless, merging of data should be rather easy to implement and simply follow the code of the dive merging. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-04Undo: implement split-out of dive computerGravatar Berthold Stoeger
Allow splitting out a dive computer into a distinct dive. This is realized by generating a base class from SplitDive. This turned out to be more cumbersome than expected: we don't know a-priori which of the split dives will come first. Since the undo-command saves the indices where the dives will be insert, these have to be calculated. This is an premature optimization, which makes more pain than necessary. Let's remove it and simply determine the insertion index when executing the command. Original code by Linus Torvalds <torvalds@linux-foundation.org>. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-01-19Import: control process_imported_dives() by flagsGravatar Berthold Stoeger
process_imported_dives() takes four boolean parameters. Replace these by flags. This makes the function calls much more descriptive. Morover, it becomes easier to add or remove flags. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-19Import: add add_to_new_trip flag to process_imported_dives()Gravatar Berthold Stoeger
If this flag is set, dives that are not assigned to a trip will be assigned to a new trip. This flag is set if the user checked "add to new trip" in the download dialog of the desktop version. Currently this is a no-op as the dives will already have been added to a new trip by the downloading code. This will be removed in a subsequent commit. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Undo: make dive-import undoableGravatar Berthold Stoeger
On desktop, replace all add_imported_dives() calls by a new undo-command. This was rather straight forward, as all the preparation work was done in previous commits. By using an undo-command, a full UI-reset can be avoided, making the UI react smoother. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Undo: make adding of planned dive undo-ableGravatar Berthold Stoeger
Planned dives were still added by directly calling core code. This could confuse the undo-machinery, leading to crashes. Instead, use the proper undo-command. The problem is that as opposed to the other AddDive-commands, planned dives may belong to a trip. Thus, the interface to the AddDive command was changed to respect the divetrip field. Make sure that the other callers reset that field (actually, it should never be set). Add a comment describing the perhaps surprising interface (the passed-in dive, usually displayed dive, is reset). Moreover, a dive cloned in the planner is not assigned a new number. Thus, add an argument to the AddDive-command, which expresses whether a new number should be generated for the to-be-added dive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Undo: use dive * instead of unique index in renumber-divesGravatar Berthold Stoeger
Now, that pointers to dives are stable, we might just as well use dive * instead of the unique-id. This also affects the merge-dive command, as this uses the same renumbering machinery. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Undo: implement autogrouping of trips in DiveAddGravatar Berthold Stoeger
If the autogroup flag is set, search for appropriate trips in DiveAdd() and add the dive to this trip. If no trip exists, add a new trip. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11Undo: isolate undo-commandsGravatar Berthold Stoeger
This refactors the undo-commands (which are now only "commands"). - Move everything in namespace Command. This allows shortening of names without polluting the global namespace. Moreover, the prefix Command:: will immediately signal that the undo-machinery is invoked. This is more terse than UndoCommands::instance()->... - Remove the Undo in front of the class-names. Creating an "UndoX" object to do "X" is paradoxical. - Create a base class for all commands that defines the Qt-translation functions. Thus all translations end up in the "Command" context. - Add a workToBeDone() function, which signals whether this should be added to the UndoStack. Thus the caller doesn't have to check itself whether this any work will be done. Note: Qt5.9 introduces "setObsolete" which does the same. - Split into public and internal header files. In the public header file only export the function calls, thus hiding all implementation details from the caller. - Split in different translation units: One for the stubs, one for the base classes and one for groups of commands. Currently, there is only one class of commands: divelist-commands. - Move the undoStack from the MainWindow class into commands_base.cpp. If we want to implement MDI, this can easily be moved into an appropriate Document class. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>