Commit graph

311 commits

Author SHA1 Message Date
Berthold Stoeger
3b8b328639 desktop: use current_dive instead of displayed_dive on equipment tab
Since the displayed data is extracted from current_dive it makes no
sense to query displayed_dive for the dive mode.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-05-07 08:56:57 -07:00
Berthold Stoeger
532449644e desktop: update tab info only if current_dive is set
If current_dive was not set, the code would clear the tabs
right after updating the data. We might just as well set the
data only if current_dive is set.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-05-07 08:56:57 -07:00
Berthold Stoeger
326772cbdb statistics tab: use current_dive to decide whether user is freediving
This used the displayed_dive object. However, we now use current_dive
to designate the currently displayed dive. Thus, use this instead.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-05-07 08:56:56 -07:00
Berthold Stoeger
7a443423bc cleanup: generalize ExtraDataModel to display data of any dc
The goal here is to remove a dependency on displayed_dive.
While doing so, make the model more general and display any dc.
Pass in the dc of the current dive instead of displayed dive,
since all other tabs are already converted to show data of
the current dive. The QStrings are cached since we generate
them anyway, so we may just keep them. Thus, there is no
danger of the dc becoming invalid.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-07 08:46:15 -07:00
Berthold Stoeger
434644b381 undo: make picture (media) deletion undoable
The code is rather complex. Firstly, we have different representations
of pictures throughout the code. Secondly, this tries to do add the
pictures in batches to the divepicture model and that is always rather
tricky.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
418b160731 media: remove unused local variable
TabDivePhotos::saveSubtitles() had an unused local variable.
Clearly a copy&paste oversight.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
91e81879a5 media: put photo-view in row-selection mode
It makes no sense to have the view in item-selection mode, since
each picture represents a row. Thus we can remove a few lines
of code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
c50e58d761 desktop: avoid spurious undo commands for date/time editing
The date and time fields of the main tab posted undo events
for every date/timeChanged signal. Thus, when changing the
day of the month to e.g. 21, this would result in two date
change events: one to the 2nd and one to the 21st. This is
very irritating.

Instead listen to editingFinished() events, which thankfully
exist for these widgets.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:19:57 -07:00
Berthold Stoeger
9298466037 desktop: update statistics tab when cylinders changed
The cylinder-based statistics where not updated when an undo
command edited cylinder data. Do so.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 11:44:22 -07:00
Berthold Stoeger
16a35a8bbe desktop: update information tab when cylinders change
The SAC rate, etc were only updated when switching between dives.
They should always be updated when an undo command changes (adds,
edits, removes) the cylinders of a dive.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 11:44:22 -07:00
Monty Taylor
f37f428762 cleanup: capitalize use dc
It was suggested in a review of a previous patchset that we should
capitalize the use of "use dc" to "Use DC" - but if we were going
to do that we should do it everywhere, not just in the one place.

This is the followup to do that.

Signed-off-by: Monty Taylor <mordred@inaugust.com>
2020-05-05 10:23:18 -07:00
Monty Taylor
7a9214575e cleanup: Change Salty to Brackish
In the code, the difference between SALTYWATER and SALTWATER is hard
to see. More importantly, in the UI - Brackish is the word for water
that has more salt that freshwater but less salt that seawater. The
docs already use the word to clarify what is meant.
2020-05-05 08:25:21 -07:00
Monty Taylor
95e6792c4f Grantlee: Add salinity and water type to grantlee variables
These can be useful in a printed divelog, especially if the
log entry is also showing weight and exposure suit.

Signed-off-by: Monty Taylor <mordred@inaugust.com>
2020-05-05 17:31:47 +03:00
Berthold Stoeger
769915f3fe selection: create global single_selected_trip() function
The DiveListView had a singleSelectedTrip function that
returns the selected trip if exactly one trip is selected.
This could be very slow if numerous non-trip items were
selected, because all the selection indices were back-
translated by the proxy model.

This could make selection changes very slow, because the
MainTab used said function to determine whether it should
show trip or dive data.. Indeed, with a 3500 dive test log,
when selecting all dives in tree mode, the updating of the
TabWidgets is sped up from 130 ms to 5 ms this commit.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-03 15:02:21 -07:00
Berthold Stoeger
2829909376 profile: remove outside callers of ProfileWidget2::replot()
There was a mix of ProfileWidget2::replot() and
ProfileWidget2::plotDive(current_dive, true), which is equivalent.
Since there was more of the latter and it is more flexible, unify on
that.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-03 14:47:49 -07:00
Berthold Stoeger
a8130f0fa1 desktop: fix editing of trips
In 2021035cfc a bug was introduced:
currentTrip of MainTab was not set in trip mode. Thus, when editing
the trip notes, the notes of all selected dives were edited instead.

Set the member variable and not a local variable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-02 14:52:51 +02:00
Berthold Stoeger
60b00162a9 desktop: don't replot profile when populating dive information tab
When the dive mode is changed, the profile has to be replot. This
is by a function of the TabDiveInformation. However, that function
was also executed when populating the tab. Thus, when changing dive,
the profile was plot twice.

Move the profile plotting out of the function. Ultimately, the profile
should listen to the appropriate signals itself.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-30 14:14:13 -07:00
Berthold Stoeger
2021035cfc selection: replace selectedTrips() by singleSelectedTrip() function
To check wether the tab widgets should show the trip view, they called
the selectedTrips() function. The trip view was shown if that contained
only one trip. However, the selectedTrips() function was very slow,
because it has to query to core models.

Change the function to singleSelectedTrip(), which returns a trip
if there is exactly one trip selected. The function returns early
if there is more than one trip selected. This makes the select-all
case much faster.

There are two cases which are still very slow:
- List mode, because here all top-level items are queried.
- Dive log with many only top-level items.

Ultimately, we will have to cache the trip selection because
querying the model is too slow.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-26 13:54:59 -07:00
Berthold Stoeger
a8aa897117 desktop: don't access first data element if no cylinders
TabDiveInformation::updateProfile() does some statistics via the
per_cylinder_mean_depth function. It passes down arrays with one
entry per cylinder, which are allocated by means std::vector.

To pass the array, the expression "&vector[0]" is used. It seems
like some compilers through an assertion violation if vector
has no elements. They are technically correct in that this is
undefined, but still this appears like very unfriendly behavior.
After all, std::vector should behave just like a dynamic C-array
that is automatically freed, when going out of scope.

Replace the "&vector[0]" by "vector.data()" and don't do the
call if there aren't any cylinders for good measure.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-21 07:50:38 -07:00
Berthold Stoeger
a3238020ee desktop: rearrange widgets on the dive site tab
Move the more commonly used filter to the left and the less
commonly used "purge unused sites" button to the right. Add
a spacer so that the filter-textbox doesn't extend over the
whole free space.

With apologies to sinistroverse users (is there an option to
make the layout direction depend on the locale?).

Suggested-by: Hartley Horwitz <hhrwtz@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-20 09:46:24 -07:00
Berthold Stoeger
b4e0968ed5 desktop: remove special QGroupBox stylesheet for non-Windows systems
That style-sheet made things look really ugly on most Linux themes.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-13 10:14:00 -07:00
Berthold Stoeger
39bc6e3bdd cleanup: remove unneeded includes from TabDiveEquipment.cpp
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
63414fc823 undo: show multiple dive warning when editing equipment
When editing cylinders or weights directly in the table widgets,
no warning was shown if multiple dives were affected. To solve this,
emit signals from the respective models and catch them in dive
equipment tab. Not very nice, but it works for now.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
20e7064658 desktop/tabwidgets: replace editMode by boolean
There was only one editMode left (MANUALLY_ADDED_DIVE).
Therefore replace by a flag. This makes the code more consistent,
because the conditions "editMode != NONE" and "editMode ==
MANUALLY_ADDED_DIVE) actually meant the same thing.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
3b9913d828 desktop/tabwidgets: replace IGNORE_MODE by flag
The editMode was set to IGNORE_MODE when programatically setting
fields so that we can ignore changed-signals.

That seems to be orthogonal to whether we are in edit mode
and indeed when setting IGNORE_MODE the edit mode was
saved and restored.

Therefore, replace the IGNORE_MODE by an independent ignoreInput
flag.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
dcc1d3ed63 cleanup: remove DIVE EditMode in MainTab
That mode is not used anymore, since only the editing of
profiles of manually added dives enters editing mode. For
that case we have the MANUALLY_ADDED_DIVE edit mode.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
13d339451e cleanup: remove parameter to MainTab::enableEdition
All remaining callers were passing MANUALLY_ADDED_DIVE as a new
mode, so we may just as well remove the parameter and thus
simplify the logic.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
accf1fcc8f desktop: remove EDIT mode
The only way to enter edit mode is to edit the profile. However,
that means that the profile is already visible, so there is no
need to change the mode. Simply remove the EDIT mode.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
1aa25aad6d desktop: don't disable tabs in edit state
The edit state is now only used to edit the profile. There is no
reason to disable random tabs.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
42b423f02c cleanup: don't center map on rejecting edit
The editing of the dive site is controlled via an undo command.
No point in centering the map when cancelling a profile-edit.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
150bd9763e cleanup: remove lastMode variable in MainTab::rejectChanges()
This stored the old editMode. However, it was not read after
editMode was changed, so there is no point to it.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
5f858e137d edit: remove multi-dive version of edit information
The "dive is currently" edited is only shown when the profile is
edited. This affects only the current dive and therefore a
message saying that multiple dives are edited makes no sense.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
6288b2a619 cleanup: remove strange recursive code in MainTab::enableEdition
When enableEdition() was called with mode == NONE and the dive
was a manually added dive, it would call into MainWindow::
editCurrentDive(), which would in turn call enableEdition(),
however with another mode. Since the only caller of
enableEdition() is now editCurrentDive() anyway, we can
remove that weird code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
ee64a85d2e cleanup: remove cylinders_equal check in MainTab::rejectChanges()
This check make no more sense since cylinder editing is now
treated by undo commands.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
ff38c03e00 undo: add cylinders via undo
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
0732bb2302 undo: remove TabDiveWidget::acceptChanges and rejectChanges
Since cylinders are now edited using the undo system, these
functions are not needed anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
1f8a45db44 undo: call removeCylinder undo command in equipment tab
Instead of connecting to the remove() function of the model,
call the removeCylinder undo command. Take care to translate
the index into the source index, should cylinders be hidden!

Apart from the map-to-source call, this copies the weightsystem
code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:35 +02:00
Berthold Stoeger
30d289e4a8 CylinderModel: make dive dynamic
The CylinderModel always accessed the global "displayed_dive" and in
some special cases also "current_dive". To implement cylinder undo,
the model should work on an arbitrary dive. Therefore, in analogy
to the weight model, make the dive dynamic.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07 00:13:34 +02:00
Berthold Stoeger
9310d72943 models: update divesite-model when clearing/updating dive model
When the dive list is cleared or updated, the entries in the
divesite-model become stale and therefore the divesite-model
(with the actual name LocationInformationModel) also must be
updated. This was done manually in some parts of the code and
forgotten in others. Therefore, do it directly in the clear()
and reset() function of the dive list-model.

This might be a bit of a layering violation: why should one
model call into another if they are not in parent/child
relationship? However, this seems easier than introducing
a global "reset dives" function that coordinates the models.

Moreover, it does not appear 100% safe: if the clearing of
the divesite model causes accesses to the divelist-model,
they happen in the midst of a model reset and we had horrible
bugs with that kind of things. However, I don't think that
should happen.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-18 13:27:16 -07:00
Robert C. Helling
285fa8acbc Grammar: replaces 'indexes' by 'indices'
Grammar-nazi ran

git grep -l 'indexes' | xargs sed -i '' -e 's/indexes/indices/g'

to prevent future wincing when reading the source code.

Unfortunatly, Qt itself is infected as in
QModelIndexList QItemSelection::indexes() const

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-03-11 08:26:30 -07:00
Berthold Stoeger
2a97934db4 Cleanup: Move stringToList to core/qthelper.cpp
The same code was used in desktop and undo commands. Let's unify.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-06 10:00:13 +01:00
Berthold Stoeger
c495a49b1b Cleanup: use getDiveSelection() for shifting time
There are two cases where dive-times are shifted: in an explicit
dialog and when editing the date/time of a dive.

In each of these cases, the selected dives were collected manually.
Instead use the getDiveSelection() function. Since this returns
a std::vector, change the argument of Command::ShiftTime() to
such a std::vector.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-06 10:00:13 +01:00
Berthold Stoeger
3e9b661c22 cleanup: remove setTabIcon() calls in MainTab
These were used to remove warning-icons to mark tabs with user
changes. However these icons haven't been set since commit
a86aca0378.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-28 08:16:41 -08:00
Berthold Stoeger
fb18bc0803 cleanup: don't update tabs twice in MainTab::rejectChanges
The updateDiveInfo() call updates all tabs. No need to do
it right afterwards.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-27 14:49:01 -08:00
Berthold Stoeger
e3950df864 cleanup: remove weightsystems_equal function
This was used to test whether the "really discard changes?"
message should be shown. However, we now edit weightsystems
directly with undo commands. Therefore, the check is unnecessary
and the whole function can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-27 14:49:01 -08:00
Berthold Stoeger
0306109e95 cleanup: remove MainTab::modified
This field was not set to true since introducing undo of
dive fields.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-27 14:49:01 -08:00
Berthold Stoeger
6622f42aab Cylinders: Add CylindersModelFiltered
When the show_unused_cylinders flag is not set, the cylinder tables
in the equipment tab and the planner should not show unused cylinders.
However, the code in CylindersModel is fundamentally broken if the
unused cylinders are not at the end of the list: The correct number
of cylinders is shown, but not the correct cylinders.

Therefore, add a higher-level CylindersModelFiltered model on top
of CylindersModel that does the actual filtering. Some calls are
routed through to the base model (notably those that take indexes,
as these have to be mapped), for some calls the caller has to get
access to the source model first. We might want to adjust this.

For filtering, reuse the already existing show_cylinder function
and export it via CylindersModel.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-11 20:37:09 -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
2feb7077f8 code cleanup: add missing initialization
While technically the initial value of this variable makes no difference as
it is set when the first dive is displayed, technically Coverity is correct.

Fixes CID 353273

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-10 02:37:03 +09:00
Dirk Hohndel
254f42e396 desktop UI: only show salinity warning when DC salinity is different
There were two cases that were handled incorrectly:
- if the user hasn't entered a salinity, obviously there shouldn't be a warning
- if this is a manually entered dive, there is no salinity downloaded from a
  dive computer, so equally, no warning

Suggested-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-06 07:00:34 +09:00