Commit graph

1227 commits

Author SHA1 Message Date
Robert C. Helling
b614a04330 Check if dive_site exists before accessing its name
... in copy dive to clipboad.

Fixes #2109

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-05-29 12:47:22 +02:00
Berthold Stoeger
a124198275 Undo: be smarter about dive computer shown after deletion
When deleting a dive computer, don't just show the first
dive computer, but the next one in the list (if it exists).

Moreover, on undo jump to the previously shown dive computer.

Do this by keeping track of the before and after dive computer
number in the undo command.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-20 21:23:16 -07:00
Berthold Stoeger
ac590235c9 Cleanup: rename clone_dive() to move_dive()
This function clones a dive and clear out the old dive. This
corresponds to move semantics. Name the function accordingly.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-20 21:23:16 -07:00
Berthold Stoeger
879f52180c Cleanup: fix a few comments and debug messages
This is just minor fixes that are not user-visible:
Fix a few erroneous comments and a debug message. These are
copy & paste mistakes and mistakes introduced during code-
refactoring.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-20 21:23:16 -07:00
Berthold Stoeger
0bc96905bf Undo: make "delete dive computer" undoable
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-20 21:23:16 -07:00
Berthold Stoeger
eba6e76b96 Undo: make "move dive computer to front" undoable
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-20 21:23:16 -07:00
Berthold Stoeger
3debd92734 Undo: properly reference-count dive sites
Recently, the undo code was changed to consider dive sites.
The undo code uses a DiveToAdd structure, which was extended
by the dive site to which the dive should be added.

The split and merge commands were not adapted and therefore
the dive counts of the dive sites were wrong after split
and merge.

Fix this by properly setting the dive site field and removing
the reference in the dive structure (in the split case, the merge
case already cleared the reference).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-17 10:36:23 -07:00
Berthold Stoeger
9bb5833848 Undo: sort list of dives to add and delete
In 5729f93e1f, the dive addition /
deletion code was simplified in that indexes were calculated on
the fly. This made it, in principle, possible to pass in dives
in any order.

But there was a small oversight: the recipients of the dives-added
and dives-deleted signals expect the dives to be sorted as in
the core list. Only then will the lists be consistent.

Therefore, sort the lists before adding / deleting dives.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-17 07:55:34 -07:00
willemferguson
a969d1dd45 Implement height-to-pressure functions in planner
The units.h file has two functions to convert atm pressure to mbar
and also to convert mbar to atm pressure. Implement these two
functions in the planner.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2019-05-17 09:46:05 +02:00
Dirk Hohndel
2feedf46fa Cleanup: small coding style fixes
And addressing a cut and paste error in a comment.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-05-15 07:42:14 -07:00
willemferguson
1bdf00b2b4 Convert the atmospheric pressure in the Information Tab to an editable field
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-15 07:37:14 -07:00
Berthold Stoeger
ca6aa38139 Mainwindow: simplify application-state code
The way the application state would enable/disable widgets was very
"dynamic". A property-list would be generated and put in a set
of arrays. Very hard to figure out what is going on.

Replace these property-list by flags and explicit old-fashioned boolean
expressions.

Join the two arrays (widget- and property-lists) into an array of
a unified data structure.

Replace the macro that sets the widgets by a simple static function.

Factor out the four loops that added widgets to the quadrants into
a simple static function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-12 12:33:55 -07: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
bab7033ccb Dive site: create new dive site at location from GPS data
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-05-11 12:35:11 -07:00
Berthold Stoeger
44c65fec88 Map: automatically update names on the map
Currently, dive site names are only updated on full reload.
Instead hook directly into the corresponding signal in the
MapLocationModel to set the name. Also to the coordinates
directly there instead of going via the MapWidgetHelper.

In the MapWidgetHelper, just center on the changed dive site.
Hook into the signal directly there and remove the slot
from the MapWidget. This makes the whole call-chain at least
one call shorter.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11 12:06:19 -07:00
Berthold Stoeger
0c38754916 Map: construct list of dive sites from dive site table
Instead of looping over the dive table and extract dive sites,
loop over the dive site table.

This makes it possible to show dive sites that have no dive
associated with them.

But we have to create to functions that check whether a dive
site has any shown dives or has any selected dives.

Moreover, change the code to add near dive sites of the same
name if in edit mode. Other wise (erroneously added?) dive
sites with the same name cannot be moved on the map.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11 12:06:19 -07:00
Berthold Stoeger
4e81edcf1e Map: remove skipReload logic in mapwidget.cpp
There used to be a flag to avoid reloading of the map. Since this
is not used anymore, remove it.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11 12:06:19 -07:00
Berthold Stoeger
065423896d Filter: add reference counting for dive-site mode
The dive-site-edit and dive-site-table tabs both put the filter
into a special dive-site mode. When switching between both, it
could happen that the one got its show befor the other got
its hide event.

Thus, the first would start dive-site filtering and the second
stop it. Now the app was not in filter mode even though it should.

To solve this problem, add reference counting for the filter's
dive-site mode. In both tabs call the enter/exit functions
on show/hide. In the dive-site-table tab, when the selection
changes, use a set function that doesn't modify the reference count.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11 12:06:19 -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
403206ca06 Selection: automatically unselect old selection in selectDives()
DiveListView::selectDives() would only select new dives but not clear
the old selection. Thus, callers would have to clear the selection
first. That would lead to two selection-changed signals.

Move the unselectDives() call into DiveListView::selectDives().
The DiveListView has an internal flag to prevent double signals.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11 12:06:19 -07:00
Berthold Stoeger
8eb586d1d4 Map: remove MapWidget::centerOnSelectedDiveSite
This was only used locally and only a stub for calling
MapWidgetHelper::centerOnSelectedDiveSite. Call the latter directly
instead.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11 12:06:19 -07:00
Berthold Stoeger
d4a91a52fa Map: reload on selection change directly
When changing the dive selection, we have to reload the map to show
the correctly highlighted flags. Do this directly by hooking into
the DiveListNotifier::divesChanged signal instead of indirectly
via the MainTab.

Moreover, on reload center on the highlighted dive sites.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11 12:06:19 -07:00
Berthold Stoeger
48b8129137 Cleanup: remove MapWidgetHelper::m_selectedDiveIds member
This member variable was only used locally in functions.
Accordingly, make it a function-local variable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11 12:06:19 -07:00
Berthold Stoeger
23cf85e89c Map: don't reload map when in edit mode
During edit mode, we could get spurious reload() requests owing
to tabs being hidden. This led to undefined behavior:
In some cases entering dive site edit mode would show all dive
sites, in some only the dive site of the currently edited dive.

Therefore, refuse to reload the map while in edit mode. The
corresponding flag already exists.

Partially fixes #2076

Reported-by: Doug Junkins <junkins@foghead.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11 12:06:19 -07:00
Berthold Stoeger
743f217620 Map: don't call exitEditMode() in MapWidget::reload()
On reload of the map, the map exits edit mode. Sounds logical
at first, but the whole map-mode code is very unpredictable.

What happened was that when switching from the dive site table
to dive site edit mode, the code would enter map edit mode first.
Then, the dive site tab got its hide-signal, which would reset the
filter. This would reload the map and thus exit mode. Hence the user
can't drag the flag on the map.

Partially fixes #2076

Reported-by: Doug Junkins <junkins@foghead.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-11 12:06:19 -07:00
Miika Turkia
a4ecfb7522 CSV Import: add heartrate support
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2019-05-11 11:23:41 -07:00
Doug Junkins
00ec824129 Create DivesiteImportDialog to select sites to import
Creates the dialog box to select which sites to import from the file
selected in mainwindow.cpp. The DivesiteImportModel is created as a
table to display and select which sites are to be imported. Once the
sites are selected, the Command::importDiveSites command is called to
add the sites to the core dive site table with undo/redo functions.

Signed-off-by: Doug Junkins <junkins@foghead.com>
2019-05-06 10:48:44 +02:00
Doug Junkins
98b3a326bd Add "Import dive sites" menu to mainwindow
Adds "Import->Import dive sites" menu to mainwindow.cpp and adds the
on_actionImportDiveSites_triggered() method to prompt for the filename
to import from. The files are parsed and then any dive and trip data is
cleared before opening a dialog box to select which sites are to be
imported.

Signed-off-by: Doug Junkins <junkins@foghead.com>
2019-05-06 10:48:44 +02:00
Doug Junkins
704ff9f82e Add undo/redo commands for importing dive sites
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-05-06 10:48:44 +02:00
Berthold Stoeger
ce140f2925 Desktop: fix crash on dive site tab
An interesting crash:

1) On the dive site tab select a dive site such that only one
   trip is shown.
2) Unselect all dives.
3) Press CTRL-A while the dive list has focus.
4) This will select a trip.
5) In MainTab::updateDiveInfo() this will switch to the previous
   tab active when in trip mode.
6) This will reset the filter.
7) This will reset the currentTrip field which we just set.
8) Since we just set the currentTrip field, we don't expect
   it to change and reference a null pointer.

To fix, don't switch tabs when on the dive site tab. This also
improves user experience as there seems to be no reason to switch
away from the dive site tab.

Currently the index of the dive site tab is hard-coded - this
should be changed!

Fixes #2077

Reported-by: Doug Junkins <junkins@foghead.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-05 08:53:19 -07:00
Berthold Stoeger
154792ffd1 Cleanup: make objects in desktop-widgets/modeldelegates.cpp
A number of objects in this file were global. Yet they weren't
used anywhere else. Don't export these symbols by making them of
static linkage.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 13:06:39 -07:00
Berthold Stoeger
7b83eeadff Cleanup: fix leak in delegates
A copy of a C-string was assigned to a QString. The copy was never
freed. Instead, assign the C-string directly. This does the right
thing.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 13:06:39 -07:00
Berthold Stoeger
cab0147093 Cleanup: implement proper Qt-model semantics in WeightInfoModel
- Use a beginResetModel()/endResetModel() pair instead of distinct
addRows / removeRows pairs.

- Reuse the update function in the constructor().

- Let "rows" be the number of rows, not the number of rows minus one.

- Remove updateInfo() function as it does the same as update().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 13:06:39 -07:00
Berthold Stoeger
ef76905590 Cleanup: simplify YearInfo class
YearInfo is a trivial wrapper around "stats_t *". All the
constructor / destructor rigmarole seems completely unnecessary.
Remove it. Probably the whole class could be removed, but for
that I'd need more insight into Grantlee, which is low on my
list of priorities for now.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 13:03:31 -07:00
Berthold Stoeger
8165abf2e7 Cleanup: remove stale include in desktop-widgets/templatelayout.cpp
Including <string> is not necessary in this file.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 13:03:31 -07:00
Berthold Stoeger
d498fcad61 Printing: fix memory leak
For printing, DiveObjectHelpers are allocated and pointers to these
are stored in a QVariantList. The objects are never freed. To fix
this leak, keep the objects in a std::list<>.

std::list<> was chosen because
1) Pointers to elements stay valid during its lifetime.
2) Objects can be constructed directly in the list with emplace_back()

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 13:03:31 -07:00
Berthold Stoeger
af00361929 Cleanup: rename variable PrintOptions to printOptions
We're quite inconsistent when it comes to variable naming.
The general usage is camelCase for Qt parts and snake_case
for core code. Virtually nowhere do we start variable names
with a capital letter. Therefore, turn this one weird case
into camelCase.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 13:03:31 -07:00
Berthold Stoeger
449dec8269 Cleanup: remove TemplateLayout::m_engine member variable
TemplateLayout::m_engine is a Grantlee::Engine that is reallocated
for every function call. Instead of the archaic memory-management,
remove the member variable and make it a local variable of the
two functions that need it. There seems to be no point in keeping
the object alive beyond the function's scope.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 13:03:31 -07:00
Berthold Stoeger
b2b328fd7e Cleanup: remove redundant string clearing
The default QString constructor generates an empty string. No point
in assigning the empty string to such a thing.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 12:58:49 -07:00
Berthold Stoeger
26edea7f71 Desktop: automatically update dive information tab
Currently, the dive information tab was not updated when the user
edited fields. The fields were only updated when switching between
dives.

Therefore, hook into the "divesChanged" signal and update the fields
accordingly.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 12:58:49 -07:00
Berthold Stoeger
98a3eb414b Desktop: use current_dive in information tab
The information tab used displayed_dive to fill out its field.
For consistency with the main tab and in a bigger effort to remove
displayed_dive, use current_dive instead.

Only clear the fields if no current_dive is set. The code used to
clear the fields and overwrite them later.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 12:58:49 -07:00
Berthold Stoeger
88fbcefd4f Desktop: set dive fields only when not in trip mode
On the main-tab, when looking at a trip, the fields were filled
out with dive-data and then either hidden or overwritten with
trip data. Move the update of the fields into the corresponding
if-branch that is only active if on dive-mode.

This means removing the UPDATE_* macros, which updated or cleared
dive-fields depending on whether a current dive was set. These
operations are now performed explicitly in the corresponding
if-branches.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 12:58:49 -07:00
Robert C. Helling
52105e5217 Write dive data as video subtitles
This commit adds an entry to the dive media context
menu which offers to write a subtitle file. This
creates an .ass file for the selected videos.

In an attempt to to clutter the screen too much, don't
show irrelevant entries (zero temperature or
NDL and show TTS only for dives with stops).

VLC is able to show these subtitles directly, they
can be integrated into the video file with ffmpeg.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-04-16 20:38:19 +02: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