Commit graph

14958 commits

Author SHA1 Message Date
Dirk Hohndel
2954bc5f22 Bluetooth: move declaration and make variable file scoped
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12 08:22:44 -07:00
Dirk Hohndel
a5416b9bea Bluetooth: remember all data during a scan on macOS
Since we trigger a scan even without the dialog to pick the right
device, we need to remember all devices that we find.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12 08:22:44 -07:00
Dirk Hohndel
38cda08819 Bluetooth: run a discovery agent for BT/BLE dive computers on macOS
This way the scan time will be shorter (which on macOS can be 25+ seconds).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12 08:22:44 -07:00
Dirk Hohndel
2ba3eab319 Bluetooth: discovery should always scan on macOS as well
Instead of only starting the scan when explicitly asked to do so in the BT
dialog, create the discovery agent when the download dialog opens, since on
macOS we cannot connect to a device without having scanned for it first.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12 08:22:44 -07:00
Dirk Hohndel
c6b62cbe5c tests: add test for the BT/BLE address recognition
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12 08:22:44 -07:00
Dirk Hohndel
0cfd76740b core: helper function to recognize BT/BLE addresses
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-12 08:22:44 -07:00
Jan Mulder
4263d1c3f5 QML, cleanup: remove stackView
There is no reason (any more?) to have a property defined
that basically renames the global pageStack into a local
pageView. Just cleanup.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-10-12 08:22:26 -07:00
Berthold Stoeger
5d1c30acbf Cleanup: remove unused function MainTab::showLocation()
The last caller was removed way back in 266e754d08.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-12 13:05:35 +02:00
Jan Mulder
1f76460dfa Whitespace only
Separated from the previous commit as I do not like big whitespace
changes in a small functional commit.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-10-12 13:03:54 +02:00
Jan Mulder
a47df05ce5 Edit: prevent not needed change marking
While trying to understand more of the big change from PR 1528,
I found that the divelist was marked changed while it was not
changed at all. Reason is simple. The MODIFY_DIVES code assumes
its called only for truly changed data. But in case of saving
tagged strings, it was not.

This fixes this. And I do not believe this has any visual effects.
Further, the now broken indentation is fixed seperately.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-10-12 13:03:54 +02:00
Berthold Stoeger
6137e0bc60 Cleanup: Remove SsrfFilterSortProxyModel
SsrfFilterSortProxyModel was a thin wrapper around QFilterSortProxyModel,
which was intended as a convenience class to avoid deriving from the
latter. The filter and sort functions were replaced by simple function
pointers.

Unfortunately, by using function-pointers, the whole thing was rather
weak as these functions do not have state. The last user was removed
in ac8dcd7f65b78958587ba025280ed4c529b0b519. Therefore, remove the
whole class.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:25:32 -07:00
Berthold Stoeger
f39596df06 Map: remove access to displayed_dive_site in GPS-filter model
The location information shows a list of dive sites at the
same location as the edited dive site. This was done by passing
a function to an "SsrfSortFilterProxyModel". Unfortunately,
the latter does only support function pointers without state
and therefore had to access the global "displayed_dive_site"
object.

Replace the SsrfSortFilterProxyModel by a proper subclass of
QSortFilterProxyModel that contains information on the position
and id of the currently edited dive site.

Update the filter model if the location of the dive site changes.
This introduces a behavioral change: editing the GPS location
will lead to an updated list.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:25:32 -07:00
Berthold Stoeger
ac02854a8a Map: don't access displayed_dive_site in reloadMapLocations()
MapWidgetHelper::reloadMapLocations() reloads all dive flags
of the non-hidden dives plus the one of the currently edited
dive. Use the current_dive macro to determine whether this
is the current dive site instead of the global displayed_dive_site
object.

This is part of a series of commits, which makes the map-code
independent of the global displayed_dive_site object.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:25:32 -07:00
Berthold Stoeger
dd44dc4ab8 Map: pass down dive site in prepareForGetDiveCoordinates()
Instead of reading out the global object "displayed_dive_site",
pass the dive site to be edited in arguments to
prepareForGetDiveCoordinates() and enter edit mode.

Simplify the code in LocationInformationWidget by not using
signals to call the prepareForGetDiveCoordinates() function.
While doing this, collect common code in accept() and reject()
in the already existing resetState() function.

This is another entry in a series of commits that makes
data-flow more clear by removing access to the global
"displayed_dive_site" object.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:25:32 -07:00
Berthold Stoeger
8091497745 Map: split void MapWidget::setEditMode()
The setEditMode(bool) function behaves very differently, when
entering and exiting edit mode. Therefore, split it in two
versions. This will allow to pass arguments that make sense
only when entering the edit mode.

Since setEditMode() doesn't exist anymore, turn the editMode
Q_PROPERTY line to the MEMBER version. Accordingly, remove
the reader function. If QML wants to enter edit mode, it
should invoke the appropriate function and not simply set
the flag.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:25:32 -07:00
Berthold Stoeger
754160d625 Map: pass changed coordinates via signal
The coordinates of a "dragged flag" were passed out-of-bound via
the global "displayed_dive_site" object and then a signal was sent
to notify of the changed coordinates.

Instead, pass the coordinates directly via the signal. This makes
the data- and control-flow more clear.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:25:32 -07:00
Berthold Stoeger
66c5c5f72b Map: remove LocationInformationWidget::coordinatesChanged signal
This was used by LocationInformationWidget to instruct the map
that the coordinates of the current dive site has changed.
There is no reason why this couldn't be a function call, as no
other object ever connect()s to this signal. In fact, such a
function already exists viz. updateLocationOnMap.

Therefore, replace the signal by a simple function call.

Moreover, the uuid and coordinates of the dive site were transported
via the global "displayed_dive_site" object. Instead, pass this
information in the parameters of the function. This makes it
easier to reason about data- and control-flow.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:25:32 -07:00
Berthold Stoeger
ad57871a2c Geo lookup: don't pass arguments / result via global object
The reverseGeoLookup() fetches dive-site data via GPS coordinates.
The coordinates and the result were passed via the global
"displayed_dive_site" object. To make data-flow more clear,
pass data as in and out parameters instead.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:25:02 -07:00
Berthold Stoeger
04ad9c885d Geo lookup: make the reply a managed-pointer
By making reply a std::unique_ptr<>, the function can be quit
from any point and the reply will be freed. This is valid according
to Qt's documentation as we're not deleting during signal processing.

This commit fixes a leak: reply was overwritten with the address of
a new object without freeing the old object.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:25:02 -07:00
Berthold Stoeger
cb2f09a8e3 Geo lookup: make the QNetworkAccessManager a static object
According to Qt's docs, the QNetworkAccessManager is supposed
to be a long-living object. Therefore, don't create one on
every geo-lookup, but a single object for all geo-lookups.

By making the object function-local it is only initiaized
on first use. Morover this limits the amount of concurrent
geo lookups.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:25:02 -07:00
Berthold Stoeger
ce8199cdfd Cleanup: remove ReverseGeoLookupThread
Fetching the taxonomy from GPS coordinates was implemented in
a QThread. But the only access to the main function was a
direct call to run(). Thus, the thread was *never* started.
The function call was always asynchronous [it was using an
event loop though, so the UI doesn't hang]. Notably this
means that the signals connected to the thread would never
fire. And the spinner would never be activated.

Thus:
1) Turn the thread into a simple function.
2) Remove the spinner.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:25:02 -07:00
Berthold Stoeger
76e5c5ac67 Dive site: remove access to displayed dive site from LocationFilterDelegate
When editing a dive, in the location box a list of dive sites is
shown containing the distance to the current dive site. This was
implemented via the global displayed_dive_site object, which is
set when switching between dives. This seems like an unnecessary
indirection. Instead, use the current_dive macro.

This is part of a series to refactor dive-site handling to use
pointers instead of UUIDs and a general push to reduce global state.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:25:02 -07:00
Berthold Stoeger
b426a7937e Update CHANGELOG.md
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
b19adecb9f Undo: make adding of planned dive undo-able
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-11 16:22:27 -07:00
Berthold Stoeger
e0fcf99d0a Filter: reload only when checkstate changed
Currently, the filter is recalculated if a filter-entry is changed.
This also happens if the counts of a filter-entry changes. This
is to be avoided, as it causes unnecessary churn.

Therefore, send the proper role with the dataChanged() signal
and add a new slot, which invalidates only if a field with the
Qt::CheckStateRole is changed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
7150d1c6f6 Filter: Make filters aware of added / removed dives
Instead of reloading all the filter, only increment / decrement the
count of the entries of added / removed dives.

Originally, this was planned to be done via the signals from the
divelist, but it turned out that this was suboptimal, because
if the filter decides that the new item is selected, this has to
be done *before* adding the dive. Otherwise, it wouldn't be shown.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
11e0b7ac0a Dive commands: set filter flag when adding dives
When adding dives to the list, set the filter flag accordingly.
Thus, dives that are hidden by the filter are not shown on
redo/undo.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
f836b9ae97 Dive list: unify sorting in core and Qt-model
Ultimately, we want to use a single dive-list and not replicate
it in the Qt-model code. To this goal, let's start with using
the same sort function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
0cca36377b Dive list: retain selection on moval of dives
The current code cheats when it comes to move dives inside
a trip or move dives between trips: Instead of using the
*MoveRows() functionality, the dives are removed from and
re-added to the respective trips. This loses the selection.

Therefore, remember which of the moved dives are selected
and select them manually after they are re-added.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
3c6cdfd8c0 Dive list: propagate current-item to frontend
The command-objects select a current item, but this selection
was not propagated to the front-end. The current item is the
base for keyboard-navigation through the dive-list and therefore
should be set correctly.

It took some experimentation to get the flags right:
 QItemSelectionModel::Current
Hopefully, these are the correct flags across all supported
Qt versions!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
b16be29595 Dive list: expand trips if dives are selected
If dives are deleted, the trip(s) containing the dives are expanded.
Thus, on undo it seems natural to re-expand the trip.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
2a61664ceb Undo: correctly fill dive-list vector
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
8c2383b495 Undo: don't modify source-dives on merge
For undo, it is crucial that commands don't modify existing dives.
Unfortunately, dive merging would write into the data-structures
of the to-be-merged dives. To prevent it from doing so, make the
input dives const-pointers.

This led to a whole cascade of functions that had to take const
and significant churn.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
1afd295c41 Undo: use vectors for MergeDives and SplitDive
The MergeDives and SplitDive commands used addDive() and removeDive()
calls to manage their dives. Unfortunately, these calls don't send
the proper signals and thus the dive-list was not updated. Instead,
use one- and two-element vectors, which are passed to addDives()
and removeDives() [note the plural].

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
7067e33596 Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.

The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
   transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
   DiveTripModel indexes to actual indexes via its QSortFilterProxy-
   model.

For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.

To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.

Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
23db0ba68d Dive list view: replace signal-magic by flag
In DiveListView, we have a very fundamental problem: When
On the one hand, we get informed of user-selection in the
DiveListView::selectionChanged() slot. This has to set the
correct flags in the C-backend.

On the other hand, sometimes we have to set the selection
programatically, e.g. when selecting a trip. This is done
by calling QItemSelectionModel::select().

But: this will *also* call into the above slot, in which
we can't tell whether it was a user interaction or an
internal call. This can lead to either infinite loops or
very inefficient behavior, because the current dive
is set numerous times.

The current code is aware of that and disconnects the
corresponding signal. This is scary, as these signals are
set internally by the model and view. Replace this
by a global "command executing" flag in DiveListNotifier.
The flag is set using a "marker" class, which resets the flag
once it goes out of scope (cf. RAII pattern).

In DiveListView, only process a selection if the flag is not
set. Otherwise simply call the QTreeView base class, to reflect
the new selection in the UI.

To have a common point for notifications of selection changes,
add such a signal to DiveListNotifier. This signal will be
used by the DiveListView as well as the Command-objects.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
0d98da5261 Dive list: remember selected dives
Don't delesect dives, when unregistering them from the backend.
If a previously selected dive is added, select it in the dive-list.
For this purpose introduce a SELECTED_ROLE to query the DiveTripModel
for selected dives.

Unfortunately, when adding multiple selected dives, current_dive_changed
is called for each of them, making this very slow. This will have
to be fixed in subsequent commits.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
96d8727399 Undo: use dive * instead of unique index in renumber-dives
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-11 16:22:27 -07:00
Berthold Stoeger
26901a8dbd Undo: disable undo- and redo-actions in edit mode
We have to avoid that undo/redo removes the currently edited
dive from under our feet. This code can be removed once proper
undo/redo (including editing) is implemented.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
63b65a7e20 Undo: implement autogrouping of trips in DiveAdd
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-11 16:22:27 -07:00
Berthold Stoeger
ec7d85835f Dive list: implement proper Qt-model semantics for DiveTripModel
Previously, each dive-list modifying function would lead to a
full model reset. Instead, implement proper Qt-model semantics
using beginInsertRows()/endInsertRows(), beginRemoveRows()/
endRemoveRows(), dataChange().

To do so, a DiveListNotifer singleton is generatated, which
broadcasts all changes to the dive-list. Signals are sent by
the commands and received by the DiveTripModel. Signals are
batched by dive-trip. This seems to be an adequate compromise
for the two kinds of list-views (tree and list). In the common
usecase mostly dives of a single trip are affected.

Thus, batching of dives is performed in two positions:
- At command-level to batch by trip
- In DiveTripModel to feed batches of contiguous elements
  to Qt's begin*/end*-functions.

This is conceptually simple, but rather complex code. To avoid
repetition of complex loops, the batching is implemented in
templated-functions, which are passed lambda-functions, which
are called for each batch.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
6ac4ddbeed Core: introduce insert_trip_dont_merge() function
insert_trip() adds a trip to the backend, but merges trips if
there exists a trip with the same date. This is a disaster
for the MergeTrips command, because this command adds a new
trip and removes the previous two. Of course if the added trip
is merged, this cannot work.

Therefore, add an insert_trip_dont_merge() function, which
adds the trip, but doesn't merge.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
43c3885249 Undo: isolate undo-commands
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>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
f427226b3b Undo: make diverse trip-related operations undo-able
AddDivesToTrip, CreateTrip, AutogroupDives, RemoveAutogenTrips
and MergeTrips basically all did the same thing as RemoveDivesFromTrip,
which was already implemented. Thus, factor our the common functionality
and hook it up to make all these functions undo-able.

Don't do the autogroup-call everytime the dive-list is rebuilt
(that would create innumberable undo-actions), but only on dive-load /
import or if expressly asked by the user [by switching the autogroup
flag].

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
4fbb8ef399 Dive list: hand-code the DiveTripModel
The dive list is fed data by means of a sorted "DiveTripModel".
There are two modes: list and tree. This was implemented rather
elegantly with a general "TreeModel", which can represent trees
of arbitrary depths.

Nevertheless, we have at most two levels and on the second level
only dives can reside. Implementing proper model-semantics
(insert, delete, move) will be quite a challenge and implementing
it under the umbrella of a very general model will not make it
easier.

Therefore, for now, hardcode the model:
At the top-level there are items which may either be a trip
(can contain multiple dives) or a dive (contains exactly one dive).

Thus, we can completely de-virutalize the DiveItem and TripItem
classes, which are now trivial wrappers around dive * and dive_trip *.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
c341bc53c3 Dive list: replace dive-id by dive pointer
The undo-system now guarantees that pointers to dives are stable
throughout their lifetime. Therefore, replace the unique index by
pointers. This is a small performance improvement, but much more
importantly, it will make it more natural to transport a pointer
to the dive inside QModelIndex's private pointer.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
dd9af8e72e Undo: make editing of dive-time an undoable operation
The whole undo system assumes that the indexes in the dive table
do not change under its feet. On desktop, there seems only one
exception left: editing of the dive time. To circumvent this,
hook editing of the dive-time to the already existing UndoShiftTime
command.

This introduces a temporary UI-inconsistency: this is the only
edit that is reflected in the undo-list. This will be fixed in
due course, when other edit actions are also made undoable.

UndoShiftTime is changed to take pointers to dives (which should
be stable by now) instead of uniq-ids.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
ba9c35215e Dive editing: don't repeatedly loop through whole dive list
On dive editing, for every changed field the code looped through
the whole dive-list and modified the selected dives. Instead,
get the list of selected dives once and use that.

Whereas this may look like a gratuitous optimization, it will
make things easier for subsequent commits. Notably, we can
pass the list of selected dives to an "UndoObject".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
c30efc95d4 Undo: clear undo history on load / import
Keeping undo-history across load makes little sense. The user was
expressly reminded that they have unsaved work.

For import (from other logs or the dive-computer) an undo-functionality
would be desirable. Nevertheless, this is rather complex since
new and old dives are merged. Implementation would require a finer
backend<->undocommand interface. Thus, leave this for now until more
experience with the undo system is acquired.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00
Berthold Stoeger
014c04f8bd Undo: implement rudimentary support for undo of dive-merging
For this, an output-parameter was added to the backend merge_dives()
function. When non-zero, instead of adding the merged dive to
the preferred trip, the preferred trip is returned to the caller.

Since the new UndoObject, just like the delete-dives UndoObject,
needs to remove/readd a set of dives, the corresponding functionality
was split-off in a helper function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-11 16:22:27 -07:00