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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
This struct is used to store the completers during construction
of the object. But it is never accessed afterwards. Therefore,
remove it from the object and remove the structure definition
from the header file.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Most tabs in the dive-information widget have there own translation
units and ui-files. Only the equipment tab was married with the
main tab. Move it out to get more reasonably sized translation units
and some isolation.
Currently, this needs ugly hacks when entering / checking for edit
mode: Access to MainTab is via the MainWindow. And vice/versa, when
accessing the DiveEquipmentTab from the MainTab, the former is
hardcoded as the first item of an array.
These hacks will soon be removed though, when making equipment
editing undoable. The tabs will then be independent.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The only caller of said function used to check whether MainTab is
in edit mode. For this case there is already a function - use that
instead.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When adding dives in an undo command, the index is saved in the
command. This seemed logical at first, because why calculate the
index more than once? But actually it made the code rather subtle
and brittle when multiple dives were added.
Moreover, this is a pointless optimization, as it doesn't optimize
the common case (only one execution).
Remove this for now and calculate the index on every execution. If
it ever turns out to be a bottle neck, it will be much more effective
to turn the linear search of the index into a binary search. A
further sensible optimization would be inserting in batches.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The tag-widget was only showing the completer if we were in edit mode.
The edit mode does not exist anymore - therefore remove the check.
Hopefully this has no unintended consequences, like the completer
not disappearing when it should.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Selecting "Selected dives" exports the dive sites for the selected
dives. Selecting "All dives" exports all dive sites.
XML format is the subsection of the divelog XML that describes the
sites headed with a <divesites> section like:
<divesites program='subsurface' version='3'>
</divesites>
Signed-off-by: Doug Junkins <junkins@foghead.com>
Apparently, in some Qt-versions the destructor of the base class
calls hide on child-objects (according to Qt's object hierarchy).
This is obviously called after the derived class has been destructed.
In a concrete case, the base class of the destructed MainWindow
would hide the TabDiveSite object. That would reset the filtering
if a dive site was selected, which would indirectly access the
MainWindow, which is already partially destroyed.
Therefore, destroy the MainTab before destroying the MainWindow.
Do this by keeping it as a std::unique_ptr subobject. Thus, it
will be destroyed before the MainWindow and remove itself from
Qt's object hierarchy.
Reported-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This feels more natural than selecting a single cell. Still,
the "delete" cell is not visibly selected, which give a
strange impression.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The model was not reset on file close, leading to weird effects.
New dive sites would be added at the end of a table full of empty
entries.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The dive tabs are disabled, when no dive is shown. The dive site tab
is implemented as a dive tab, which is of course conceptually wrong.
Moreover it has the nasty side effect that when adding an empty dive
site, no dives are shown and the tab is disabled, leading to a
UI dead lock.
Therefore, disable all tabs but the dive site tab. The proper fix
will be a refactoring of the UI.
Reported-by: Doug Junkins <junkins@foghead.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When in dive site tab and some dive sites are selected, show only
dives at those sites. Simply read the selection and pass it to the
filter.
Start and stop filtering when switching to and from the tab,
respectively.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
Instead of sending a signal when counts change, catching them
in the filter widget and update the window title there,
directly update the window title in the model. This removes a
signal/slot pair.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Editing the dive site of a dive may make a dive site appear
(first dive of that site) or disappear (the last dive of that
site was removed). Therefore, we have to reload the dive site
markers on editing the site of a dive.
This should be made smarter by only reloading the markers if
the dive site status actually changed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The editing of a dive field is only performed when focus
is removed from the field. On pressing CTRL-s, the changes
in the currently active field were therefore not saved.
Remove the focus from all fields to trigger an edit command
yand thus ensure that all changes are saved.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>