Commit graph

48 commits

Author SHA1 Message Date
Berthold Stoeger
cfa0c9c735 desktop: make DiveLocationModel entries "editable"
If the entries in the DiveLocationModel don't have their entries
set as editable, the auto-completion popup turns of composition
if such an item is highlighted (see Qt code in
/src/widgets/itemviews/qabstractitemview.cpp), thus disabling
composition of multi-key characters.

Therefore, set this flag. Seems weird, but what should we do!?

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-08-22 09:20:45 -07:00
Robert C. Helling
6ad55cd63b cleanup: fix compiler warning
... at least for llvm.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-08-24 08:31:38 -07: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
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
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
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
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
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
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
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
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
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
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
Berthold Stoeger
59f1191d0c Coding style: add tab before Q_OBJECT
In virtually all cases we use a tab before Q_OBJECT. Fix the four
exceptions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
7538546c89 Cleanup: rename locationInformation.ui -> locationinformation.ui
The .cpp and .h files are all lower-case, the .ui file is camel-case.
Unify to lower-case (which is much more common in the code base).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-02-02 19:36:11 +02:00
Berthold Stoeger
acd44467c1 Dive site: remove [start|stop]FilterDiveSite signals
This is another case of a weird pattern where an object would
connect it's own signal to the slot of a different object.
There seems to be no reason why the former couldn't simply
call the latter.

Remove the [start|stop]FilterDiveSite signals of LocationInformationWidget
and call the corresponding functions of MultiFilterSortModel directly.
While doing so, replace the UUID argument by a pointer-to-divesite.
It will be converted anyway right at the beginning of the function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29 00:09:31 +00:00
Berthold Stoeger
b9b1b3146b Dive site: remove UUIDs from LocationInformationModel
Replace UUIDs from LocationInformationModel and fix the fallout.
Notably, replace the UUID "column" by a DIVESITE "column".
Getting pointers through Qt's QVariant is horrible, we'll have
to think about a better solution.

RECENTLY_ADDED_DIVESITE now defines to a special pointer to
struct dive_site (defined as ~0).

This fixes an interesting logic bug:
The old code checked the uuid of the LocationInformationModel (currUuid)
for the value "1", which corresponded to RECENTLY_ADDED_DIVESITE.
If equal, currType would be set to NEW_DIVE_SITE. Later, _currType_
was compared against _RECENTLY_ADDED_DIVESITE_. This would only work
because NEW_DIVE_SITE and RECENTLY_ADDED_DIVESITE both were defined
as 1.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29 00:09:31 +00:00
Berthold Stoeger
6f98dca26e Dive site: remove argument from diveSiteSelected signal
The diveSiteSelected signal of DiveLocationLineEdit had the dive-site
UUID as argument. But the receiving slot would not use that argument.
Remove this as a tiny step to remove the UUIDs alltogether.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29 00:09:31 +00:00
Berthold Stoeger
d9588ec5df Cleanup: remove declaration of unused signal
The last use of the LocationInformation::startEditDiveSite()
signal was removed in ff26ffe0d0.
Remove its declaration.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-26 18:48:27 +01:00
Linus Torvalds
28e3413ff6 Add 'location_t' data structure
Instead of having people treat latitude and longitude as separate
things, just add a 'location_t' data structure that contains both.

Almost all cases want to always act on them together.

This is really just prep-work for adding a few more locations that we
track: I want to add a entry/exit location to each dive (independent of
the dive site) because of how the Garmin Descent gives us the
information (and hopefully, some day, other dive computers too).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-21 19:55:09 +03:00
Berthold Stoeger
11a211fb02 Dive site: replace displayed_dive_site by pointer
In the dive-site-edit widget, a copy of the current dive site was
used to store the old (pre-edit) data. This is not necessary, since
we can simply access the data in the original dive site. Thus,
replace the subobject by a simple pointer.

This is part of a series to replace dive-site uuids by pointers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-13 21:41:41 -04:00
Berthold Stoeger
8815f77ea0 Dive site: use own copy of taxonomy in dive-site-edit widget
The dive-site-edit widget uses a copy of the to-be-edited site
to compare with old values. Generally, this seems overkill
(the original dive-site can be used for such a comparison).
But one place where it can't simply be removed is the taxonomy,
because the widget needs a place to store the unsaved data.

Change the code to use an explicit taxonomy structure instead
of the one provided in the copy. This should ultimately allow
removal of the latter.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-13 21:41:41 -04:00
Berthold Stoeger
5d3967ce84 Dive site: un-globalize displayed_dive_site
The global object displayed_dive_site is used a a backing-store
by the dive-site-edit widget. All external accesses were removed,
therefore make the object local to the widget.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-13 21:41:41 -04:00
Berthold Stoeger
954820aa81 Dive site: explicitly init displayed_dive_site on show widget
The global object "displayed_dive_site" is used to store the
old dive site data for the edit-dive-site widget. The fields
of the widget were initialized from this object in the show
event. Therefore the object was updated in numerous parts of
the code to make sure that it was up-to-date. Instead, move
the initialization of the object to the function that also
initiatlizes the fields. Call this function explicitly before
showing the widget.

This makes the data-fow distinctly easier to understand.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-13 21:41:41 -04: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
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
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
d6010b5155 Dive locations: factor out common code of models
For increased maintainability, use the same columns, roles and
the same accessor function for both dive-site models.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-09 21:00:44 -07:00
Berthold Stoeger
574065b314 Cleanup: reinstate override modifiers
This reverts commit 1c4a859c8d,
where the override modifiers were removed owing to the noisy
"inconsistent override modifiers" which is default-on in clang.

This warning was disabled in 77577f717f,
so we can reinstate the overrides.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-29 15:23:25 -07:00
Berthold Stoeger
1c4a859c8d Cleanup: remove all override modifiers
Commit df156a56c0 replaced "virtual"
by "override" where appropriate. Unfortunately, this had the
unintended consequence of producing numerous clang warnings. If
clang finds a override-modified function in a class definition,
it warns for *all* overriden virtual functions without the override
modifier.

To solve this, go the easy route and remove all overrides. At least
it is consistent.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-01 06:30:00 -07:00
Berthold Stoeger
df156a56c0 Cleanup: replace virtual by override where appropriate
The keyword "virtual" signalizes that the function is virtual,
i.e. the function of the derived class is called, even if the
call is on the parent class.

It is not necessary to repeat the "virtual" keyword in derived
classes. To highlight derived virtual functions, the keyword
"override" should be used instead. It results in a hard compile-
error, if no function is overridden, thus avoiding subtle bugs.

Replace "virtual" by "override" where appropriate. Moreover,
replace Q_DECL_OVERRIDE by override, since we require reasonably
recent compilers anyway. Likewise, replace /* reimp */ by
"override" for consistency and compiler support.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-31 11:02:34 +02:00
Lubomir I. Ivanov
a084ea5b26 locationinformation: don't update map location on typing
Currently when the user is typing new coordinates the
marker on the map changes location right away. Disable that and
add a 'flag' button that should be pressed instead. Also make the
coordinates update when pressing Enter or when the text
field loses focus.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-11-27 22:59:22 +01:00
Berthold Stoeger
f4bcdf46aa Inform LocationFilterModel of changed dive site name
Since commit 01d961086c, the location filter
list is updated if a dive site is edited. The problem is that if the
name of a selected dive site is changed, the selection is lost.

Therefore, before repopulating, inform the location filter that a dive
site changed its name. The location filter then internally changes the
name and can properly transfer the old selection on repopulate. This is
performed via the new LocationInformationWidget::nameChanged signal,
which is connected to the new LocationFilterModel::changeName slot.

A special case to be handled is the following:
 [ ] Site 1
 [x] Site 2
and "Site 2" being renamed to "Site 1", i.e. both sites being merged.
Here, the merging is detected and "Site 1" will likewise be checked:
 [x] Site 1
 [x] Site 1
No merging is performed, as the list will be repopulated anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-26 18:50:40 -08:00
Dirk Hohndel
53b1b17f4f LocationInformationWidget: make sure to clean out fields
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-07 08:16:53 -07:00
Tomaz Canabrava
516527e1bd [Divesite] Hook location information interface for country
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-02 09:52:54 -07:00
Dirk Hohndel
9021a44ccc Add SPDX header to desktop widgets
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29 13:32:55 -07:00
Tomaz Canabrava
e49d6213ad Move qt-ui to desktop-widgets
Since we have now destkop and mobile versions, 'qt-ui' was a very
poor name choice for a folder that contains only destkop-enabled
widgets.

Also, move the graphicsview-common.h/cpp to subsurface-core because
it doesn't depend on qgraphicsview, it merely implements all the
colors that we use throughout Subsurface, and we will use colors on both
desktop and mobile versions

Same thing applies for metrics.h/cpp

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-30 10:36:49 -07:00
Renamed from qt-ui/locationinformation.h (Browse further)