Commit graph

118 commits

Author SHA1 Message Date
Michael Werle
d404aa767f [Bug #2934] Geo Lookup - support for remote dive sites
Some remote dive sites have no populated places (towns, cities)
nearby. For such sites, we now fall back to looking up
unpopulated place names, such as the reef or island name.

Also some code refactorisation:
the actual network access is now encapsulated in its own
function removing some duplicated code handling in the
reverseGeoLookup function and making it more readable.

Furthermore, reverseGeoLookup() was completely refactored as
most of its functionality was due to legacy requirements; the
current code-base only calls this function from a single
location and only with an empty taxonomy_data object. This
makes the function more focussed and much simpler and more
readable.

Finally, a resource leak in reverseGeocde introduced in
4f3b26f9b6 was fixed.

Signed-off-by: Michael Werle <micha@michaelwerle.com>
2020-09-05 17:34:15 +02:00
Michael Werle
37ae5a7d83 [Bug #2930] Fix crash bug in LocationInformationWidget
If a user exits the LocationInformationWidget (Edit  Dive Site)
while a reverseGeocode lookup is in progress, the object's
diveSite variable is set to null.

When the reverseGeocode lookup completes, this variable is
dereferenced causing an application crash.

Signed-off-by: Michael Werle <micha@michaelwerle.com>
2020-09-03 08:59:08 +02:00
Berthold Stoeger
50b195142b cleanup: remove includes from desktop-widgets/locationinformation.h
Notably, there was a circular include

locationinformation.h <-> importgps.h

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 09:42:31 -07:00
Berthold Stoeger
96a03b4b26 Dive site: don't save invalid GPS coordinates
On the dive site screen, when entering invalid GPS coordinates,
we cleared the location of the dive site. Don't do this. To
clear the location, the user now has to enter the empty string.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-06 08:50:22 -08:00
Berthold Stoeger
cabaaa69db Dive site: give visual clue for invalid coordinates
On the dive site edit screen, when the user enters invalid
coordinates and saves, we treat this as "no location". This
is rather unfriendly, therefore warn the user with a visual
clue. This is performed by setting the background color of
the widget to red.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-06 08:50:22 -08:00
Berthold Stoeger
9ed886e4be Cleanup: lower-case filenames in core/subsurface-qt/
We tend to use lower-case filenames. Let's do it for these files
as well. Simple search & replace.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-04 02:16:46 +01:00
Dirk Hohndel
ee5a156498 core: move GPX parsing into core
This shouldn't be part of the desktop UI code; there's still the issue that we
really shouldn't hand code XML parsing, but I'll leave that for later.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-24 09:51:02 -08:00
Willem Ferguson
1ecd5065a0 Desktop: Import dive coordinates directly from GPS
This allows Subsurface to obtain the coordinates of a dive directly
from a GPS track. It parses a GPX file (GPX V1.0 or V1.1) from
a GPS to locate the trackpoint immediatedly after the start of a
dive. There is an additional "Use GPS file" button in the Edit Dive
Site panel that is selected from the Notes tab. Image:

This allows one to select a GPX file, bringing up the Import GPS
dialog.

There is extensive provision for cross-checking that the dive track
synchronises with the dive start and end. If the Save button in the
dialog is pressed the dive coordinates are copied into the Dive
Coordinates text box in the Edit Dive Site panel. The map moves
to indicate the location of the dive site.

The bulk of the work is done in importgps.cpp. The code is
pretty intergrated: I tried to break it up in smaller commits but that
was not feasible.

The code includes responses to the comments by @neolit123 and
@bstoeger. The C-based file input was replaced with Qt-based
code using QChar, QString and QFile.

[Dirk Hohndel: fixed several small issues in the .ui file, removed
               various headers includes that weren't needed and
               fixed printing of minutes as zero padded]

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-24 09:51:02 -08:00
Dirk Hohndel
70cabb968c code cleanup: use explicit zero_location
Again, several different ways to achieve the same thing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-10 02:37:03 +09:00
Dirk Hohndel
46441689b9 code cleanup: mark unused argument
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-10 02:37:03 +09:00
Dirk Hohndel
e6210aafc5 code cleanup: initialize all elements in structure
This seems silly. I don't like that warning and would rather disable the warning.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-10 02:37:03 +09:00
Berthold Stoeger
b76f207158 Filter: split out filter from model
Split out the actual filtering from the MultiFilterSortModel.
Create a DiveFilter class that does the actual filtering.
Currently, mobile and desktop have their own version of this
class, though ultimately we may want to merge them.

The idea here is that the trip-model and undo-commands have
direct access to the filter-function and thus can take care
of keeping track of the number of shown dives, etc.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-19 21:13:40 -08:00
Berthold Stoeger
5e29245e68 Refactoring: move undo commands to top level
In the future we might want to use undo-commands for mobile as
well (even if not implementing undo).

Therefore, move the undo-command source from desktop-widgets
to their own commands top-level folder.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-14 21:02:07 +01:00
Dirk Hohndel
130534aedf Cleanup: better handling of NULL dive in setCurrentDiveSite
We test for d being NULL so that's clearly an option we worried about, yet
we already called get_dive_site_for_dive(d) which dereferences d.

Found by Coverity. Fixes CID 350118

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-28 05:44:33 -07:00
Berthold Stoeger
81ea47a498 Desktop: fix dive site editing
When clicking "done" on the dive site edit screen, the diveSite
member variable was reset to nullptr in acceptChanges() at the
beginning of the function. This prevented posting an undo-command
as a consequence of the active widget losing focus.

Reset the diveSite variable after exiting dive-site mode, which
causes the active widget to lose focus.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-28 04:40:26 -07:00
Berthold Stoeger
fdfcbd0315 Cleanup: use pointer-to-member-function in addAction() calls
Since requiring Qt >= 5.9.1, we can use the pointer-to-member-function
overloads of addAction (introduced in Qt 5.6). This has the advantage
of compile-time checking of the signal/slot parameters.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-20 03:51:11 -04:00
Berthold Stoeger
e3cd0891d3 Dive site: close dive site edit widget when dive site is deleted
The application could be crashed by
1) Create dive site
2) Edit dive site
3) Undo until dive site is removed
4) Continue editing now non-existing dive site

Therefore, hook into the dive-site-deleted signal and if the
currently edited dive site is deleted, close the widget.

When closing the widget, make sure that the potentially
dangling pointer is reset to zero so that there is no
other potential use-after-free bug.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-07 08:28:29 -07:00
Berthold Stoeger
ca484c5029 Map: remove MapWidget::repopulateLabels() call
For historic reasons MapWidget::repopulateLabels() was called
in LocationInformationWidget::acceptChanges(). This should not
be necessary anymore, as this is done when entering/exiting
dive-site-mode.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06 11:48:47 -07:00
Berthold Stoeger
856fc357bc Map: remove unnecessary MapLocationModel::repopulateLabels() calls
The LocationInformationWidget repopulated the map labels if the name
or location of a site changed. This is unnecessary because the
MapLocationModel catches these signals itself. Remove these calls.

As an added bonus, calling repopulateLabels() in QML context leads
to crashes later on. Therefore this should fix at least one
crash condition when dragging a flag on the map while the
dive-site-edit-tab is shown.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06 11:48:47 -07:00
Berthold Stoeger
09163c1ee7 Cleanup: remove DiveLocationLineEdit::currType
Apparently this field was never used...?

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-04 10:41:09 +09:00
Berthold Stoeger
02e94de062 Desktop: enable clearing of dive site
Clearing dive site did not work for two reasons:
1) We didn't get a signal when editing was finished.
2) When clearing the dive site, the "add new dive site" site was set.

Thus, connect to the editingFinished signal and in
DiveLocationLineEdit::currDiveSite() return a null pointer if
the string is empty.

This means that it is not possible to have a dive site with an
empty string, but that shouldn't be a problem, right?

Fixes #2148

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-04 10:41:09 +09:00
Dirk Hohndel
e599d58531 Desktop: update flags on the map when dive sites change
Now when we change dive site location or name through a redo, the flags and
associated name are always reflected correctly.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-06-24 13:01:25 +02:00
Dirk Hohndel
ae6ce93775 Cleanup: simple consistency
Same pattern as the other functions in this group.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-06-24 13:01:25 +02:00
Berthold Stoeger
75767c456a Turn application state into enum
The application state was encoded in a QByteArray. Thus, there was
no compile-time checking. Typos would lead to silent failures.

Turn the application state into an enum. Use the enum-class construct,
so that the values don't polute the global namespace. Moreover,
this makes them strongly typed, i.e. they don't auto-convert to
integers.

A disadvantage is that the enums now have to be cast to int
explicitly when used to index an array.

Replace two hash-maps in MainWindow to arrays of fixed sizes.

Move the application-state details into their own files.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-12 12:33:55 -07:00
Berthold Stoeger
32720a7c18 Dive site: Add button to display all dive sites
On the main dive tab, add a button that opens the dive-site selection
widget showing all dive sites. This is done by setting the "temporary
dive site name" to the empty string. Thus no dive sites are filtered
and the "add new dive site" entries are not shown. Moreover, the
text is selected. The user can therefore immediately start typing to
activate the filter or enter the name of a new dive site.

The idea is that after downloading dives with GPS information the
user can select one of the close dive sites.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11 12:35:11 -07:00
Berthold Stoeger
4a61f155d3 Cleanup: simplify DiveLocationLineEdit::showPopup()
DiveLocationLineEdit::showPopup() called the functions
	- fixPopupPosition()
	- proxy->invalidate()
	- proxy->sort(LocationInformationModel::NAME)
	- view->show()
All these calls are redundant, as they are already performed by
setTemporaryDiveSiteName(). Remove them.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11 12:35:11 -07:00
Berthold Stoeger
e76298a8a7 Dive site: show distance to current dive using extra data
Currently, in the dive-site selection widget the distance to
the dive site of the current dive is shown. Instead, use the
recently introduced dive_get_gps_location() function. Thus,
the actual GPS coordinates extracted by libdivecomputer are
used.

The function is only called when the current dive changes
and the location is stored in the item delegate.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11 12:35:11 -07:00
Berthold Stoeger
c7e1c40b0e Dive site: sort by distance to current dive
When presenting the list of dive sites on the dive-info tab, sort
the dive sites by distance to the current dive. The idea is that
when the user wants to select a dive site, close dive sites should
be prioritized.

The location of the dive is determined with the dive_get_gps_location()
function introduced in the previous commit. This actual GPS data get
precedence over the currently set dive site for that dive.

On change of dive, the current location is updated in the
DiveLocationFilterProxyModel so that a potentially expensive search
for GPS data is not repeated for every comparison.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11 12:35:11 -07:00
Berthold Stoeger
d29f82c52d Map: make edit mode depend on dive-site-filtering
Since the dive-site-filter is active either on the dive-site-edit
page or the dive-site-list page, use that as the flag for dive-site-edit
mode. Moreover, when the filter is reset, the
MapWidgetHelper::reloadMapLocations() function is called, so we
can use that place to enter/exit edit mode.

This makes it easier to keep everything consistent.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11 12:06:19 -07:00
Berthold Stoeger
ee19b067a7 Desktop: don't show special dive site entries if there is no filter
In the dive site selection widget there are two special entries
(add dive site with given name). Don't show this if the user didn't
enter a string.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-16 23:46:19 +12:00
Berthold Stoeger
09c0d7a6f5 Desktop: enable sorting in dive site selection widget
The dive site selection widget implements a lessThan() function, but
that was never called. Apparently in a QListView one has to start
sorting by hand? Do just that.

In any case, the lessThan function was erroneous as it would happily
sort away the first two special entries. Fix it with a special case
for these to.

Finally use case insensitive string comparison.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-16 23:46:19 +12:00
Berthold Stoeger
5b270dd895 Cleanup: access filter-model directly without cast
To reset the filter-model, LocationInformationWidget would extract
the model from the diveSiteListView and then downcasts it. Instead,
it can access it directly, because the filter-model is a subobject
of LocationInformationWidget.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-16 23:46:19 +12:00
Berthold Stoeger
f09177e872 Cleanup: remove global DiveLocationLineEdit variable
DiveLocationLineEdit stored a pointer to itself in a global variable
so that the DiveLocationModel can access it to access the filter text.

Instead, on change simply pass the filter text down from DiveLocationLineEdit
to DiveLocationModel.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-16 23:46:19 +12:00
Berthold Stoeger
826cc97921 Dive site: display proper text for the two special options
The dive-site line edit box features two special entries for adding
new dive sites. These should display different texts depending on
whether the current dive has a dive site or not.

The current check is wrong, because it used displayed_dive, but
since the last set of undo-changes, this might not be filled out
correctly anymore. Instead the code should check the actual current
dive.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-15 11:23:11 +12:00
Berthold Stoeger
afde4dce0d Filter: allow filtering multiple dive sites
In the edit-dive-site tab the filter is switched to a particular
mode where only dives at that site are shown.

If we want to reuse this for the dive-site tab the mode has to
be extended to allow for multiple dive sites. This is trivially
done by replacing a pointer by a vector of pointers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
8287d86d2b Dive site: add proximity field to dive site list
Merging dive sites is currently only possible if dive sites are at
the exact same position.

Introduce a field where the user can enter a distance up to which all
dive sites should be listed. These can then be merged.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
434990dcd4 Desktop: Dive site editing: give up focus on ESC
As long as a text field is active, CTRL-Z only affects this field.
Thus it is suprisingly hard to undo edits. There seems to be a
fundamental problem with CTRL-Z handling.

To make it somewhat easier, catch any ESC-key event and move the
focus to the MainWindow. This effectively removes the focus from
any text field.

This all appears very wrong, but so far I wasn't able to find the
root cause of the problem.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
3a3089770a Cleanup: remove LocationInformationWidget::endEditDiveSite signal
The signal was caught by the MainWindow to:
1) call setDefaultState()
2) call refreshDisplay()
3) call refreshDisplayedDiveSite()

1) Let's call that directly from the widget. The reason is that in
   the future there might be multiple way to get into the widget and
   therefore the widget needs finer control.
2) Remove this call as it produces an unsteady UI.
3) This should be done by undo commands, not only when finishing
   dive site editing.

Thus, the signal becomes unnecessary and can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
59239cec02 Undo: make dive site merging undoable
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-12 18:19:07 +03:00
Berthold Stoeger
7c63956ee4 Undo: implement undo of geo lookup
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-12 18:19:07 +03:00
Berthold Stoeger
b5d4d88fe5 Dive site: remove edit mode from dive location widget
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-12 18:19:07 +03:00
Berthold Stoeger
0b851d723e Undo: update map when dive site location is changed by undo command
Simply hook into the appropriate signal. Thus, the "update dive site
location" button can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
fa4fedbb48 Undo: implement undo of dive site location editing
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-12 18:19:07 +03:00
Berthold Stoeger
021aa4bd57 Undo: implement undo of dive site country editing
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-12 18:19:07 +03:00
Berthold Stoeger
4d183e0d75 Undo: implement undo of dive site notes editing
Simply copy the code of description editing.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
0882ca64b0 Undo: use undo commands for name and description editing in widget
In the dive site widget, use the undo commands instead of editing
only on accept. This introduces an inconsistency betwee the
name and description and the other fields. This will be fixed
in follow-up commits.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
08d789b933 Dive site: remove LocationInformation::nameChanged signal
This signal was used by the old filter and the last user
was removed in e0f473fcb4.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
2dcc0a7d1e Undo: implement undo of dive site description editing
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-12 18:19:07 +03:00
Berthold Stoeger
0fd85832b7 Dive site: remove implicit deletion of empty dive sites
There was a way of deleting dive sites by clearing all fields.
This is not necessary anymore, as now the user can delete a
dive site in the dive site list.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
0e1b0cf1da Undo: Implement undo of dive site name editing
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-12 18:19:07 +03:00