Commit graph

1643 commits

Author SHA1 Message Date
jan Iversen
712f7ef7f6 desktop-widgets: correct type
correct SLOT was sec_bottomsac(double), which
is not reported as an error.

correct to set_bottomsac(double)

Signed-off-by: Jan Iversen <jan@casacondor.com>
2020-01-06 10:34:42 +09:00
jan Iversen
c89a357e84 desktop-widgets: correct set_min_switch_duration connect.
correct SLOT was set_min_swich_duration()(int), which
is not reported as an error.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2020-01-06 10:34:42 +09:00
jan Iversen
dacb331347 desktop-widgets: set_bailout -> set_dobailout
correct name mistake in connect()

Signed-off-by: Jan Iversen <jan@casacondor.com>
2020-01-06 10:34:42 +09:00
jan Iversen
2492b62ad4 desktop-widgets: set_verbatim_plan should go through plannerShared.
Adjust connect() to use plannerShared, avoiding parameter convert
problem.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2020-01-06 10:34:42 +09:00
jan Iversen
fa72288ca2 desktop-widgets: remove use of QSignalMapper.
QSignalMapper gives a warning that it is depreciated, and the
doc. states that using a lambda function is more efficient.

Replace use of QSignalMapper.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2020-01-06 10:34:42 +09:00
jan Iversen
e2d568acc1 desktop-widgets: replace QSignalMapper for set_deco_mode
QSignalMapper had a parameter convert problem, when mapping to
set_deco_mode in plannerShared.

Use lambda function in connect to avoid parameter convert problem.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2020-01-06 10:34:42 +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
Dirk Hohndel
c03731b220 desktop UI: use salinity of current DC, not first DC
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-06 07:00:34 +09:00
Dirk Hohndel
eac87f6481 desktop UI: correctly show the salinity data overwritten warning
We need to show this whenever the value in the dive (which could have been
entered by the user some other time) doesn't correspond to the value in the DC.
This, btw, will point out to the user if different DCs have different values.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-06 07:00:34 +09:00
Dirk Hohndel
1e4cc49f83 desktop UI: treat an unknown salinity as that
We were royally confused when we didn't know the salinity value (e.g., if the
dive computer didn't provide that information). We somehow treated this as the
same as wanting to use the salinity information in the dive computer. Which
makes no sense.

While cleaning this up, this also adds the textual representations of the water
types as a string list that corresponds to the enum values that we use - this
way it's easier to stay consistent.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-06 07:00:34 +09:00
Dirk Hohndel
c0bb04994b code cleanup: avoid unused argument warnings
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-06 07:00:34 +09:00
Dirk Hohndel
4e7adcf96a desktop UI: remove strange sprintf calls
I'm rather upset that I never noticed this in a review. That's just not how you
print numbers.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-06 07:00:34 +09:00
willemferguson
b12d0b1840 desktop UI: small cleanups of salinity code
Added code for string translation.
Added code to improve UI on Windows.
Added some comments to make the code more understandable.
Enable salinity combobox for manually entered dives

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-06 07:00:34 +09:00
willemferguson
d2cf58e07e core: read and write the user-specified salinity
Both XML and git storage are added.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-06 07:00:34 +09:00
willemferguson
ebabbfb457 desktop UI: create the UI components for editing the salinity.
The user may modify the salinity by selecting a water type from the combobox.
The new datum does not replace the existing salinity value but is stored in a
separate variable within the dive structure. If the dc-based salinity is
overwritten, there is an exclamation mark next to the modified salinity value
to indicate that the salinity has been overwritten. The dc-derived salinity can
always be recovered by selecting the "use dc" option in the combobox.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-06 07:00:34 +09:00
willemferguson
732d5a9fbd desktop UI: add preference for making salinity editable
Create a checkbox in the Preferences: General screen that enables or disables
editing of the salinity data. This preference is saved with all the other
preferences.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-06 07:00:34 +09:00
willemferguson
88cbcf5c6e Cosmetic updates to .UI files for Preferences
This is a cosmetic update to remove some warning messages
while building a fresh subsurface. These warnings were due to
duplicate label names in the .UI files.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2019-12-27 05:42:23 +09:00
jan Iversen
d4a2c5cdee plannerShared: replace notes variables to plannerShared
Replace
    display_runtime
    display_duration
    display_transitions
    verbatim_plan
    display_variations

Signed-off-by: Jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-26 09:59:26 -08:00
jan Iversen
c976385aed desktop-widgets: replace variables to plannerShared
Use plannerShared setter to update the variables in qPref.
This will also signal the cylindermodel to calculate a new bestmix.

variables:
   bottompo2
   decopo2
   bestmixend

Signed-off-by: Jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-26 09:58:47 -08:00
jan Iversen
738ee360ba desktop-widgets: replace o2narcotic from plannerModel to plannerShared
Use plannerShared setter to update o2narcotic. This will also signal
the cylindermodel to calculate a new bestmix.

Signed-off-by: Jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-26 09:58:21 -08:00
jan Iversen
413501bc61 desktop-widgets: replace variables from plannerModel to plannerShared
variables
bottomsac
decosac
problemsolvingtime
sacfactor
are not set in diveplanner.cpp, but instead
signals a slot in plannerModel.

change signals to slots in plannerShared

Signed-off-by: Jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-26 08:45:40 -08:00
jan Iversen
53958a50c6 desktop-widgets: replace var plannerModel -> plannerShared converted
variables
min_switch_duration
are not set in diveplanner.cpp, but instead
signals a slot in plannerModel.
and are read from plannerShared which includes a conversion

change signals to slots in plannerShared
change read from prefs. to plannerShared

Signed-off-by: Jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-26 08:40:08 -08:00
jan Iversen
316e56f4f7 desktop-widgets: replace vars. qPrefDivePlanner -> plannerShared
change local doo2breaks to plannerShared and update connect.

change signals to slots in plannerShared

Signed-off-by: Jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-26 08:39:49 -08:00
jan Iversen
5063431263 desktop-widgets: replace variables from plannerModel to plannerShared
variables
drop_stone_mode,
last_stop,
switch_at_req_stop
are not set in diveplanner.cpp, but instead
signals a slot in plannerModel.

change signals to slots in plannerShared

Signed-off-by: Jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-26 08:39:30 -08:00
jan Iversen
df6f01a6f6 desktop-widgets: replace vars. qPrefDivePlanner -> plannerShared
change local setBailout to plannerShared and update connect.

change signals to slots in plannerShared

Signed-off-by: Jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-26 08:39:05 -08:00
jan Iversen
87f680f5e7 desktop-widgets: replace variables from plannerModel to plannerShared
planner_deco_mode is not set in diveplanner.cpp, but instead
signals a slot in plannerModel.

reserve_gas is not set in diveplanner.cpp, but instead
signals a slot in plannerModel.

change signals to slots in plannerShared

Signed-off-by: Jan Iversen <jan@casacondor.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-26 08:38:51 -08:00
willemferguson
6212bb6721 Preferences UI: final cleanup
This commit does some final cleaning up to the code, mostly deleting
white space and comments.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-25 02:57:42 +09:00
willemferguson
75b5be8f40 Preferences UI: add reset tab
Add a separate preferences tab for resetting all preferences to their default values.
One or two very small alterations to other sections of the preferences UI code.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-25 02:57:42 +09:00
willemferguson
b6c3cdb20c Preferences UI: add dive log tab
This adds a tab for dive log - related preferences.
A suitable test programs is still required.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-25 02:57:42 +09:00
willemferguson
b24caa4e2d Preferenced UI: add dive download tab
Add a preferences tab for dive download, allowing resetting the
buttons representing download connections in the Download panel.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-25 02:57:42 +09:00
willemferguson
2ac279d129 Pereferences UI: add media tab
Remove the preference settings dealing with thumbnails (currently under
General preferences and Profile preferences) and put them in a newly-created
Media preference tab.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-25 02:57:42 +09:00
willemferguson
3e853e37a5 Preferences UI: create new equipment tab
Remove the "Show unused cylinders" checkbox (Profile tab) and the
"Set default cylinder" qTextEdit box (General tab) and put them in a
separate and new Equipment tab. This sounds like a simple task but,
as can be seen from the files changed, was actually a complex matter.
Adapt the existing test programs (General and TechDetails) for creating
a test program that tests parts of the Equipment tab.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-25 02:57:42 +09:00
willemferguson
c121afc96c Preferences UI: split network preferences
Split the Network Preferences page into two screens:
1) Network preferences
2) Cloud storage preferences
Enable storing these preferences locally.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-25 02:57:42 +09:00
jan Iversen
7751ec1c78 build-system: move plannerShared to backend-shared
WARNING: multi directory commit, needed to secure it builds.

move the core/plannerShared.* to backend-shared.

update CMakeLists.txt to include backend-shared lib in link process.

update ios project to reflect new directory

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-24 08:44:23 +09:00
jan Iversen
9c52aaf043 build-system: move exportfuncs to backend-shared
WARNING: multi directory commit, needed to secure it builds.

move the core/exportfuncs.* to backend-shared.

update backend-shared/CMakeLists.txt to generate backend-shared lib

update CMakeLists.txt to include backend-shared lib in link process.

update ios project to reflect new directory

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-24 08:44:23 +09:00
jan Iversen
080def7729 diveplanner: desktop, remove no longer used slots
Remove PlannerSettingsWidget slots, that are directed to plannerShared

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-24 06:30:57 +09:00
jan Iversen
fb5a67e16a diveplanner: desktop, connect signals direct to plannerShared
Connect the signals for ascent/descent directly to plannerShared

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-24 06:30:57 +09:00
jan Iversen
dc713000ff desktop-widgets: use share meter/feet funcs. in diveplanner
change the settings variables using UNIT_FACTOR to use
plannerShared instead.

There are no changed functionality, it is simply removing calculations
from the UI.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-24 06:30:57 +09:00
jan Iversen
a17cb6b681 build-system: clean desktop-widgets CMakeLists.txt
The CMakeLists.txt referenced mapwidget which is in another root
directory (and also a seperate library)

Remove mapwidget reference from CMakeLists.txt

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-24 06:18:36 +09:00
jan Iversen
6ccea3c39d desktop-widgets: divelogsDE: integrate shared backend
Use doUpload() from uploadDiveLogsDE

Connect signals from uploadDiveLogsDE to do UI part.

Clean slots to only contain UI.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 12:36:43 -05:00
jan Iversen
9fd95c18bd desktop-widgets: divelogsDE: delay handling until user select upload
Do not prepare zip file, just because user selected the divelogs.de
radiobutton

Move prepareDives to startUpload (slot handling user clicking on
upload button).

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 12:36:43 -05:00
jan Iversen
8becc29ca8 desktop-widgets: split UI and network in DivelogsDeWebServices (prepare)
Clean prepareDivesForUpload() and uploadDives() so that
uploadDives() only contain network handling no UI.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 12:36:43 -05:00
jan Iversen
2f680c1f76 desktop-widgets: use qPrefCloudStorage instead of QSettings
Use qPrefCloudStorage for divelogde_user/password to secure same
handling as other settings, as well as same handling as used in
shared uploadDiveLogsDE class

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 12:36:43 -05:00
jan Iversen
fba3e5115a desktop-widgets: remove code under RM_OBSOLETE_CODE ifdef
history, and it is disturbing in "diff".

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 12:36:43 -05:00
jan Iversen
4ee7cb7d1d desktop-widgets: use uploadDiveLogsDE::prepareDives
Remove local implementation (prepare_dives_for_divelog) and call
uploadDiveLogsDE::prepareDives, which are shared between
mobile and desktop

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 12:36:43 -05:00
jan Iversen
91e0ee9d9b desktop-widgets: diveDiveShareExportDialog add signal handling
connect signals from uploadDiveShare and remove reply variable

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 11:08:51 -05:00
jan Iversen
e5f3e927a7 desktop-widgets: use shared uploadDiveShare for diveshare.
Remove shared code from DiveShareExportDialog::doUpload()
and add call to uploadDiveShare::doUpload()

Remark signal handling is not implemented.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 11:08:51 -05:00
jan Iversen
bba9385d76 desktop-widgets: use qPrefCloudStorage for diveshare.
Diveshare upload in mobile is using qPrefCloudStorage, so change
diveshareexportdialog as well, to keep consistency.

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-11 11:08:51 -05:00
Berthold Stoeger
0f417a3bc1 Dive list: access header via filter-model
The dive list accesses the filter model, therefore it makes sense
to also get the header data from there, even if they are only
forwarded from the source model.

This makes control flow more logical and will allow us to remove
the global DiveTripModel instance.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-10 18:45:30 -08:00
Berthold Stoeger
e7dafe36aa Dive list: clear dive data via the filter model
The UI talks to the filter model. Therefore route clearing of
data through that model instead of accessing the source model
directly.

This will allow us to remove the DiveTripModel::instance()
function and makes control flow less "jumpy".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-10 18:45:30 -08:00
Berthold Stoeger
71307bce42 Dive list: don't handle selection changes on filter-change in view
The selection changes upon completing the filter are handled by
the core. Don't do this explicitly in the DiveListView.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-10 18:45:30 -08:00
Berthold Stoeger
a4c95fd8e8 Cleanup: remove WeightModel::changed
Since changes to the weight model are not modal anymore, nobody
queries the changed-flag. Remove it.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-05 10:14:25 -08:00
Berthold Stoeger
72c6b83866 Undo: make weight editing undoable
Implement the EditWeight undo command. Since there is common code
(storage of the old weight), this creates a common base class for
RemoveWeight and EditWeight. The model calls directly into the undo
command, which is somewhat unfortunate as it feels like a layering
violation. It's the easy thing to do for now.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-05 10:14:25 -08:00
Berthold Stoeger
029c9ccf02 Desktop: refactor WSInfoDelegate logic
The WSInfoDelegate (weight-system-info delegate) is used to display
a combo box of known weightsystem-types and auto-fills the weight if
the weightsystem-type is changed.

This would overwrite the weight data of the displayed dive when the
user hovers over the different entries. Moreover, it saves the original
weight in case the user cancels the editing action.

This is not viable when implementing undo of weightsystem changes,
because hovering over entries should not produce individual undo
commands. Instead, implement a special "temporary" row in the
weightsystem model. On canceling of the edit actions, simply reload
the weightsystem from the unmodified dive.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-05 10:14:25 -08:00
Berthold Stoeger
2cfb35b6d7 Cleanup: return value type from WeightModel::weightSystemAt()
There is only one caller of WeightModel::weightSystemAt() and that
certainly does not need a pointer into the weightsystem-table of
the current dive. Return a value type instead of a pointer.

This allows us to mark WeightModel::weightSystemAt() as const and
use it from WeightModel::data(). Slightly cleaner code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-05 10:14:25 -08:00
Berthold Stoeger
b3f530bfb9 Undo: make weight-deletion an undoable action
This one is a bit more complicated than weight adding, because the
multiple-dive case is not well defined. If multiple dives are selected,
this implementation will search for weights that are identical to the
weight deleted in the currently shown dive. The position of the weight
in the list is ignored.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-05 10:14:25 -08:00
Berthold Stoeger
b3253304a5 Desktop: don't connect to remove() slot of model from TableModel
When connecting a model to the TableModel class, it would connect
clicking on an item to the remove() slot of the model.

This breaks the program flow implied by the undo code:
Ui --> Undo-Command --> Model --> UI

Moreover, the naming of the remove() slot is illogical, because
clicks can also have different effects, as for example in the
cylinder-table.

Therefore, move the connect() call from TableModel to the
callers. In the case of TabDiveSite, move the remove() function
from the model to the TabWidget, where it makes more sense.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-05 10:14:25 -08:00
Berthold Stoeger
147a36647c Undo: make adding of weights an undoable action
Introduce an AddWeight undo command. This is modelled after the
numerous dive-edit undo commands. The redo and undo actions are
connected to the WeightModel via two new signals, weightAdded
and weightRemoved.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-05 10:14:25 -08:00
Berthold Stoeger
76a5a38f5e Cleanup: remove displayed_dive from WeightModel
The WeightModel always acted on the displayed dive. To support undo
of weightsystem changes, operate on an arbitrary dive. This is
in line with other models, where the updateDive() function resets
the model to represent a certain dive.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-05 10:14:25 -08:00
Berthold Stoeger
fb0bb33d82 Cleanup: remove DiveListView::dontEmitDiveChangedSignal member
Should have been removed in 4928c4ae04.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
28e97e7555 Cleanup: remove DiveListView::expandedRows member variable
The QList served as backing store for backupExpandedRows()
and restoreExpandedRows(). However, these always came in
pairs in the same scope. There is no reason to store the
expanded rows over a longer time.

Therefore, return the expanded rows from backupExpandedRows()
and take them as argument in restoreExpandedRows(). Morover
replace the QList<int> by the much lighter std::vector<int>.
We certainly don't need copy-on-write, reference-counting and
immutability of iterators in this case.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
be26b0bd9a Cleanup: remove DiveListView::mouseClickSelection member variable
That hasn't been used since 2013 (9cc04c1ca6).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
75dac8906e Cleanup: remove toggle parameter from DiveListView::selectDive()
This defaulted to false and no caller used anything different.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
364a8270d1 Cleanup: remove DiveListView::remember/restoreSelection()
Calls of these functions were removed in the previous commits.
Now, remove the functions themselves.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
a83bc5ecdb Selection: don't reset selection when resorting
The old code saved, cleared and restored the selection. This
is not necessary anymore, because on model reset the selection,
which is stored in the core, is reset. Remove the unnecessary
selection handling.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
55ffd5d1b5 Cleanup: remove unnecessary remember/restoreSelection() pair
When accepting changes, the main tab refreshes the display in
a remember/restoreSelection() pair. Since the display refresh
doesn't lose selection, these calls can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
bddca1ecc9 Cleanup: remove unpaired rememberSelection() call
The old renumbering-dives code had to remember and restore the
selection. This became unnecessary with the undo-code. The
restore-call was removed, the remember-call left in. Remove it
as well.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
e46b1e88d9 Selection: move translation of indexes to filter model
The DiveListView caught signals from the DiveTripModel
with the corresponding indexes. However, the DiveListView
is actually connected to the MultiFilterSortModel and
thus has to translate the indexes.

Instead, catch the signals in the MultiFilterSortModel,
transform them and resend. Let the DiveListView get
its signal from the MultiFilterSortModel.

Yes, this makes things less efficient because there is
an extra signal. On the upside, the makes data-flow much
more logical. Selection will have to be fixed anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
a431840075 Selection: move initialization of selection from view to model
The goal here is to unify desktop and mobile by moving
selection code from the desktop-only view.
Currently, initialization of the selection still has to be
called from the view after connecting the appropriate signals.
This is due to the weird way in which create completely new
models when resetting them.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
755f185cfc Selection: move selection of "first" dive to core
The DiveListView has a function to select the first dive. Move
this to the core to be able to call it from all parts (not only
desktop) of the code.

Currently, this has a (small?) UI regression: when filtering dives
and no selected dive is visible anymore, the old code would select
the first dive in the list. The new code selects the newest dive,
which might not be the first if some sort-criterion is active.

To revert to the old behavior, it will be necessary to move the
sorting function likewise to the core.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
86f384f932 Cleanup: rename newCurrentDive signal to currentDiveChanged
This is more consistent with the rest of the signals.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
88c7de65fa Cleanup: use quotation marks for non-system includes
That's the idiomatic way of doing things.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
4b1a3a1a6e Selection: move selection functions from divelist.c to selection.c
Since we now have a selection.c translation unit, put the selection-
related functions there.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 13:00:23 +01:00
Berthold Stoeger
569e532f5c Cleanup: Fix order of initialization in MainTab::MainTab()
For deterministic construction/destruction (i.e. objects are
destructed in reverse order of construction) it is crucial that
constructor initializer lists follow the order of the class
definition.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-04 08:37:14 +01:00
jan Iversen
f9a36733c6 desktop-widgets: move export functions to shared class
Remove export functions from desktop-widgets and move to core
in order to share with mobile version

Signed-off-by: Jan Iversen <jan@casacondor.com>
2019-12-03 21:30:39 -08:00
Berthold Stoeger
a6fa6cdb41 Undo: make profile-editing undoable
Recently, undo of dive-replanning was introduced. Therefore,
it appears logical to do the same thing for editing of the
profile of manually added dives.

For now, use the same undo-command, just change the displayed
text from "replan dive" to "edit profile". Move the fixup dive
call into the undo-command.

Eventually, every action on the profile should be made undoable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-03 20:55:58 -08:00
willemferguson
6d7f26f4bf Desktop: add additional star widgets to Information tab
Connect the UI to the underlying dive structure. Enable proper initialisation
and management of star widgets while Information tab is active. Enable undo for
the addtional star widgets.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-03 20:37:57 -08:00
willemferguson
4e86dd3a52 Desktop: enable additional environmental star widgets
Implement the UI features related to the additonal star widgets.
Create the additonal star widgets and connect them to the preferences settings.
By default only the current and visibility widgets are shown. In this case the
current widget is on the left hand side of the tab. If the additional widgets
are enabled the horizontal order of the widegts are changed to reflect
attributes roughly from the start of the dive on the left to those towards the
end of the dive on the right.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-03 20:37:57 -08:00
willemferguson
7dc8a9850d Desktop: handle environmental states in Information tab
Create a preference setting on the General Settings page. The setting is saved
with the other preferences.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-03 20:37:57 -08:00
Berthold Stoeger
4928c4ae04 Desktop: Improve speed of selecting multiple (or all) dives
When selecting all dives via CTRL-A or manually and the trips
were not expanded, the QSelectionModel sends a single
selectionChanged signal per trip. We are reloading the map
in every call, making this very slow.

I couldn't figure out how to make QSelectionModel behave more
nicely, therefore I chose the nuclear option: Remove the map
reloading from selectionChanged() and hook into all functions
that do selection changes. In these functions, first call the
original code and then do the selection-changed operations.

This will certainly need some tuning.

Reported-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-28 12:15:24 -08:00
willemferguson
2048c7f73d Bugfix: inconsistent groupbox sizes in Iformation tab
This is a bugfix for an error that slipped through.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2019-11-27 08:47:24 -08:00
Berthold Stoeger
a9da44b402 Cleanup: remove MainWindow::recreateDiveList() function
The function had only one line and had only one caller.
We might just as well fold that line into the caller.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-19 21:13:40 -08:00
Berthold Stoeger
958032b21c Desktop: don't reload dive list model after clearing the model
By clearing the model, its contents are removed. There is no
point in reloading the model.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-19 21:13:40 -08:00
Berthold Stoeger
ecb517d496 Cleanup: remove ProfileWidget2::refreshDisplay signal
It was not used anywhere.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-19 21:13:40 -08:00
Berthold Stoeger
78d4a4ce36 Filter: don't reload filter after reloading dive list
The hidden_by_filter items are set on reload of the dive list.
No point in reloading the filter again.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-19 21:13:40 -08:00
Berthold Stoeger
3003c6e1ee Filter: move recalculation of filter from FilterModel to TripModel
The way this was accessed via Qt's model semantics was horrible.
This gives arguably more readable code, since we don't have to
shoehorn things through QVariants.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-19 21:13:40 -08: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
6d6d10f03a Filter: move calculation of shown dives to undo command
The filter-model was catching dives-added / dives-deleted signals
from the models to keep track of the number of shown dives.

To simplify the data flow, do this directly in the undo-command.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-19 21:13:40 -08:00
Berthold Stoeger
2d09819ddf Filter: move number of shown dives to core
We mark hidden/shown dives in the core but store the number
of shown dives in the MultiFilterSortModel. Move this datum
to the core for improved locality.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-19 21:13:40 -08:00
Robert C. Helling
08cb521cf2 Initialize modified member
Fixes CID 350111

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-11-16 12:34:30 -08:00
Stefan Fuchs
1a2c42cebc Remove setStyleSheet for "Dive mode" box
Remove modification of style sheet for "Dive mode" box in info tab.
This fixes a broken UI layout under Windows.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2019-11-16 08:32:07 -08:00
Stefan Fuchs
e70cf24950 Fixes in tab widget UI layout
Three minor changes in tab widget UI layout and txt:
- Remove leading space in string "Gas name"
- Remove duplicate <item> entry
- Correct "leftMargin" and "rightMargin" to 0 everywhere

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2019-11-16 08:32:07 -08:00
Berthold Stoeger
8a33c04894 Cleanup: use DiveTripModelBase::clear() to reset the log
Introduce a DiveTripModelBase::clear() function that cleanly
clears all dive data inside a beginResetModel()/endResetModel()
pair. Thus, the UI will be cleanly reset and we can remove
explicit calls to
 - graphics->setEmptyState()
 - mainTab->clearTabs()
 - mainTab->clearTabs()
 - diveList->reload()
from MainWindow::closeCurrentFile().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-16 08:29:53 -08:00
Berthold Stoeger
12c7c5ea96 Cleanup: move clearing of current_dive into clear_dive_file_data()
It makes no sense to have a non-NULL current_dive once all dives
have been deleted. Therefore, clear current_dive implicitly in
clear_dive_file_data() and don't depend on the caller performing
this.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-16 08:29:53 -08:00
Berthold Stoeger
808316f434 Cleanup: fold cleanUpEmpty() into closeCurrentFile()
The latter was the only caller of the former and there seems
to be no clear separation between the two. By making a single
function out of this the code is easier to follow and duplicate
code can be more easily detected. Matter of fact, the profile
was cleared twice.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-16 08:29:53 -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
Berthold Stoeger
b43ecdad4e Undo: don't delete dive sites when pasting dives
We used to only keep sites with dives around. This changed when
implementing the dive site tab. The paste-dive code was written
using the old semantics and thus, when overwriting dive sites,
it deleted unused dive sites.

To make things consistent, remove that code. It would be very
weird when dive sites are deleted by pasting, but not by setting
a different dive site manually.

Bonus: no more dependencies on desktop-includes in the undo code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-14 09:37:27 +01:00
Berthold Stoeger
8db3e5cd59 Undo: remove unrelated include in command_divelist.cpp
This file included "desktop-widgets/divelistview.h" without needing
it. If we want to use the undo commands on mobile we shouldn't
include desktop headers. Therefore, remove the include.

This has the unintended side-effect that the Qt debug headers are
not included indirectly anymore. Thus, change a few
"qWarning() << ..." instances to "qWarning(...)".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-14 09:37:27 +01:00
Berthold Stoeger
1163fd18c4 Undo: remove superfluous dive replot in DiveComputerBase::redoit()
Removing / moving a dive computer needs a profile replot. This
was done explicitly in DiveComputerBase::redoit(). This is
unnecessary, as a profile replot is performed implicitly by the
setSelection() call.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-14 09:37:27 +01:00
Berthold Stoeger
ef2f682c67 Undo: remove superfluous refreshDisplay() in AddDive::(un)doit()
Dives used to be added from a special dive-edit screen. Thus, the
undo command had to close that screen. This is no longer the case.
Remove the calls.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-14 09:37:27 +01:00
Berthold Stoeger
f6d3efc6f8 Cleanup: don't std::move() temporaries
clang correctly warns about std::move()ing objects returned from
functions. This is a pessimization, because the compiler can't
copy elide the object. Remove.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-14 09:36:39 +01:00
willemferguson
ebaac21ef5 Show altitude corresponding to surface pressure
In the information tab, presenting atmospheric pressure is a bit
unintuitive because the diver cannot easily relate that to altitude.

For the Atm. Pressure widget in the Information tab this code does:
If the atmospheric pressure for a dive exists and the user selects
the 'm' or 'ft' option from the combobox, then the estimated altitude
is shown in the text box.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2019-11-11 22:57:48 +01:00
Berthold Stoeger
e434b5aa40 Cleanup: introduce DiveTripModelBase::IS_TRIP_ROLE
To test whether an entry is a trip, we passed a pointer to the
trip through a QVariant and tested that for null-ity.

Passing pointers through QVariants has given us myriads of
problems in QML, therefore introduce a bool IS_TRIP_ROLE

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-11 22:44:58 +01:00
willemferguson
08db77333b Notes tab: Use top RH for depth and duretion fields
Currently the top righthand part of the notes tab is used for
    showing and editing air teperature and water temperature. But
    these fields were moved over to the Information tab and are not
    required in the Notes tab any more. Rather use this space for the
    depth and duration data for manually-entered dives. Currently
    extra vertical space is created in the Notes tab for showing this
    field, resulting in inefficient use of screen space and
    inelegant layout. This code moves the Duration and Depth fields
    into the top righthand of the Notes tab.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2019-11-11 20:19:22 +01:00
willemferguson
2fe1121b1c Information tab: Make air and water tempertatures editable
The undo stack is preserved.
This is in preparation of removing temperatures from the Notes tab.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2019-11-11 20:18:41 +01:00
Willem Ferguson
7a4abd7477 Reorganise the Information tab of the Info panel
1)  Reorganise the existing widgets in the Information tab
2)  Move divemode widget and visibility widget from Notes tab to
    Information tab
3)  Translate water density to a word indicating water type
4)  Reorganise the Notes tab to compensate for the moving the
    divemode and visibility widgets to the Information tab
5)  Remove the problems in showing a QGroupBox in Qt Windows. I do
    this by removing the CSS specifying border characteristics

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-11-10 13:10:03 -08:00
Berthold Stoeger
794066b236 Cylinders: access cylinders with get_cylinder()
Instead of accessing the cylinder table directly, use the get_cylinder()
function. This gives less unwieldy expressions. But more importantly,
the function does bound checking. This is crucial for now as the code
hasn't be properly audited since the change to arbitrarily sized
cylinder tables. Accesses of invalid cylinder indexes may lead to
silent data-corruption that is sometimes not even noticed by
valgrind. Returning NULL instead of an invalid pointer will make
debugging much easier.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
6a1e2cd8c2 Desktop: support no-cylinders in dive information tab
The tab was crashing if there were no cylinders because
1) per_cylinder_mean_depth() would access non-existing cylinders.
2) TabDiveInformation::updateProfile() would access a non-existing
   mean.

Fix both of these crash conditions by checking whether the dive
actually has cylinders.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
7c9f46acd2 Core: remove MAX_CYLINDERS restriction
Instead of using fixed size arrays, use a new cylinder_table structure.
The code copies the weightsystem code, but is significantly more complex
because cylinders are such an integral part of the core.

Two functions to access the cylinders were added:
get_cylinder() and get_or_create_cylinder()
The former does a simple array access and supposes that the cylinder
exists. The latter is used by the parser(s) and if a cylinder with
the given id does not exist, cylinders up to that id are generated.

One point will make C programmers cringe: the cylinder structure is
passed by value. This is due to the way the table-macros work. A
refactoring of the table macros is planned. It has to be noted that
the size of a cylinder_t is 64 bytes, i.e. 8 long words on a 64-bit
architecture, so passing on the stack is probably not even significantly
slower than passing as reference.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
77e5dbac73 Undo: Make PasteState cylinders list dynamically allocated
Instead of using a sub-array, use a std::vector<>. This is
a necessary step in removing the MAX_CYLINDERS restriction.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
ff653f721c Cylinders: dynamically allocate cylinder arrays
When keeping track of cylinder related data, the code was using
static arrays of MAX_CYLINDERS length. If we want to use dynamically
sized cylinder arrays, these have to be dynamically allocated.
In C++ code, this is trivial: simply replace the C-style arrays
by std::vector<>. Don't use QVector, as no reference counting or
COW semantics are needed here. These are purely local and unshared
arrays.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
11467fa326 Core: dynamically allocate the result of get_gas_used()
get_gas_used() returns the volume of used gases. Currently,
an array with MAX_CYLINDERS is passed in. If we want to make the
number of cylinders dynamic, the function must use an arbitrarilly
sized array.

Therefore, return a dynamically allocated array and free it
in the caller.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
ec8e109a1a Profile: remove ProfileWidget2::recalcCeiling()
The ProfileWidget2::recalcCeiling() function is used in one place,
namely when an undo-command changes the mode. It recalculates
decompression data and repaints the ceilings and thus avoids a
full profile-redraw.

This is smart, but it becomes problematic when the dive is changed
and the ceiling is recalculated before the profile is redrawn.
The DivePlotDataModel then still has data from the previous dive
but cylinders of the new dive are accessed.

This kind of situation may arise if multiple dive fields are
updated, as for example when replanning a dive.

Currently, this only causes a temporary mis-calculation. When
removing MAX_CYLINDERS this will lead to crashes.

One might attempt to fix the whole data-dependency mess. This
commit goes the cheap route and simply redraws the profile when
the mode is changed. Yes, it is in a way ineffective, but we
do worse things. The ProfileWidget2::recalcCeiling() thus becomes
unused and is removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-08 20:42:06 +01:00
Robert C. Helling
9c8fbe494d Planner: Add option to treat O2 as narcotic
When computing the best mix for a target depth, for helium, one
can either require that the partial pressure of N2 is the same
as at the target depth or the partial pressure of N2 plus O2.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-10-31 00:30:38 -07: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
Linus Torvalds
a9b1fbdcc5 Don't expose 'detach_buffer()' to membuffer users
The native buffer of a membuffer is not NUL-terminated, so when you want
to detach it and use it as a C string, you had to first do
'mb_cstring()' that adds the proper termination/

This was all documented in the header files, and all but two users did
it correctly.

But there were those two users, and the exported interface was
unnecessarily hard to use.  We do want the "just detach the raw buffer"
internally in the membuffer code, but let's not make the exported
interface be that hard to use.

So this switches the exported interface to be 'detach_cstring()', which
does that 'mb_cstring()' for you, and avoids the possibility that you'd
use a non-terminated memory buffer as a C string.

The old 'detach_buffer()' is now purely the internal membuffer
implementation, and not used by others.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-10-27 12:42:54 -07:00
Dirk Hohndel
33137c62b0 Cleanup: NULL check pointer before dereferencing
Found by Coverity. CID 350081, 350087, 350095

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-27 07:35:46 -07:00
Dirk Hohndel
80f76773c1 Cleanup: prevent uninitialized pointer
This should never matter as we should never call undoit before redoit.
Extra ensurance that we don't access random data.

Found by Coverity. Fixes CID 350076

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-27 07:35:46 -07:00
Dirk Hohndel
d6ec20c541 Cleanup: avoid out of bounds access
This one is a bit complicated as it depends on a specific flow, but it
seems like setup_cvs_parms might indeed write NULL to the element at
index 49 of parm. I'm not 100% sure that the sequence of events required
for this can happen, but adding one more pointer to the array seems like
cheap insurance.

Found by Coverity. Fixes CID 350120

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-27 07:35:46 -07:00
Berthold Stoeger
a4ca3c520c Undo: simplify profile repainting code
The profile repainting code that was called when a dive changed was
located in a separate function. Not only did it take a redundant
parameter, it also performed very weird stuff like entering and
exiting plan state. That did not work at all. Replace by a simple
call to plotDive() and things work much better.

There was a comment about DivePlannerPointsModel and profile
getting out of sync. So let's keep an eye out for that.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-26 11:36:23 -07:00
Berthold Stoeger
8dea2ada3b Undo: turn dive- and trip-fields into flags
The divesEdited signal sends the changed field as a parameter.
Since some undo-commands change multiple fields, this led to
numerous signals for a single command. This in turn would lead
to multiple profile-reloads and statistic recalculations.

Therefore, turn the enum into a bitfield. For simplicity,
provide a constructor that takes classical flags and turns
them into the bitfield. This is necessary because C-style
named initialization is only supported on C++20 onward!

Is this somewhat overengineered? Yes, maybe.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-26 11:36:23 -07:00
Berthold Stoeger
5c4d163a41 Undo: update statistics if dive changed
On undo/redo, the dive statistics tab was not updated even
if a selected dive was changed. Fix that.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-26 11:36:23 -07:00
Berthold Stoeger
7b730602c6 Undo: implement ReplanDive command
Implement an undo command that overwrites the dive-computers and
cylinders of the current dive with a given dive. This will be used
when replanning a dive.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-26 11:36:23 -07:00
Berthold Stoeger
6a6b992a77 Desktop: make salinity a field known to the undo system
The undo system sets updates individual dive fields on
redo respectively undo. Make salinity such a field, since
it is changed on replanning a dive.

To do this, break out the "update salinity" functionality
into its own function, add an entry to the DiveField enum
and add the corresponding switch-case.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-26 11:36:23 -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
81268adfd3 Import: extract number of dives from model not from thread
The plan is to make the model the authoritative source of
the imported dives. Therefore, access the number of
downloaded dives from there.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02 08:04:49 -07:00
Berthold Stoeger
36676120ab Import: clear table via model not via thread
Clearing the table in the thread leaves the model in an inconsistent
state. Don't do that.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02 08:04:49 -07:00
Berthold Stoeger
8f3c85f58d Import: get tables from DiveImportedModel not DownloadThread
When importing dives, consume the tables from DiveImportedModel
and not the DownloadThread. This appears more logical and avoids
an inconsistent state of the DiveImportedModel: On import the
tables would be reset, but the DiveImportedModel wasn't
informed of that.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02 08:04:49 -07:00
Berthold Stoeger
10d4ba82a2 Documentation: add comment to Command::importDives
Add a comment that the passed-in dives are consumed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02 08:04:49 -07:00
Berthold Stoeger
a24b1a4027 Desktop: Use DiveImportedModel::deleteDeselected()
In DownloadFromDCWidget::on_ok_clicked() deselected dives were
directly deleted from the dive table, leaving DiveImportedModel
in an inconsistent state. Use the function in DiveImportedModel
instead. This also removes code duplication.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02 08:04:49 -07:00
Berthold Stoeger
ad7ffa0af0 Import: Make DownloadThread a subobject of DiveImportedModel
Currently, desktop and mobile are accessing the DownloadThread
and the DiveImportedModel concurrently. This makes a big data
flow mess. To achieve a more hierarchical data flow, start
by making the DownloadThread a subobject of DiveImportedModel.

Start the download by calling a function in DiveImportedModel.

Route the finished signal through DiveImportedModel. Thus,
the model can reload itself with the new data.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-02 08:04:49 -07:00
Dirk Hohndel
9ae7040a91 Revert the singleton PR
It turns out that this isn't working the way it was intended to.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-09-27 16:26:58 -07:00
Berthold Stoeger
05200f9266 Cleanup: unify idiosyncratic singletons
The way we handle singletons in QML, QML insists on allocating the
objects. This leads to a very idiosyncratic way of handling
singletons: The global instance pointer is set in the constructor.

Unify all these by implementing a "SillySingleton" template. All
of the weird singleton-classes can derive from this template and
don't have to bother with reimplementing the instance() function
with all the safety-checks, etc.

This serves firstly as documentation but also improves debugging
as we will now see wanted and unwanted creation and destruction
of these weird singletons.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-25 13:35:30 -07:00
Fabio Rueda
356293da7d If only one dive selected, only one temperature in stats tab
In stats tab, when only one dive is selected, on one stat, only average is
shown, except temperature which 3 same temps for max, min and avg are shown.

[Dirk Hohndel: fixed whitespace]

Signed-off-by: Fabio Rueda <avances123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-09-21 16:10:25 -07:00
Berthold Stoeger
4f0582ea0b Export: special case dive site mode when exporting dive sites
In dive site mode, export selected dive sites, not dive sites
of selected dives.

Fixes #2275.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-21 16:07:24 -07:00
Berthold Stoeger
4b401eb2de Cleanup: return each dive site only once in selectedDiveSites()
In TabDiveSite::selectedDiveSites(), the QItemSelectionModel::
selectedIndexes() function was used. Thus for every selected
dive site 8 entries were added to the return-vector!

Instead, use the QItemSelectionModel::selectedRows() function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-21 16:07:24 -07:00
Berthold Stoeger
44a291a09f Export: move dive site selection logic to C++
When exporting dive sites, the dive sites to be selected were collected
in the C-core. But that doesn't have access to the selected dive sites
if in dive site mode. Therefore, collect the dive sites in C++ and
pass down to the core. Use a std::vector to avoid memory management
woes.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-21 16:07:24 -07:00
Fabio Rueda
8c82a1cb98 if only one dive, max depth show in average field
Signed-off-by: Fabio Rueda <avances123@gmail.com>
2019-09-15 20:55:55 +02:00
Berthold Stoeger
718c07c1a8 Grantlee: split out grantlee-only property from DiveObjectHelper
The cylindersObject list was only used by grantlee but not by
the mobile code. Since it is quite heavy, split it out and thus
don't generate it for every dive on mobile.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-14 13:20:59 +02:00
Berthold Stoeger
6a9df3bba3 Mobile: transform DiveObjectHelper into value-type
Instead of handing a reference-to-dive to QML, prerender all the needed
properties and store them as values in DiveObjectHelper. Exception:
 - date(): generated from timestamp
 - time(): generated from timestamp
 - cylinderList(): does not depend on dive anyway and should be made
   static.

This hopefully avoids the random mobile crashes that we are seeing.
Clearly, this code needs to be optimized, but it is a start.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-14 13:20:59 +02:00
Berthold Stoeger
be763452ad DiveObjectHelper: Turn DiveObjectHelper into Q_GADGET based object
DiveObjectHelper is a tiny wrapper around dive * to allow access
to dive data from QML and grantlee. It doesn't have to be a
full-fledged QObject with support for signals, etc. Therefore,
turn it into a Q_GADGET based object. This allows us passing the
object around as object, not as pointer to DiveObjectHelper.
This makes memory-management distinctly easier.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-14 13:20:59 +02:00
Anton Lundin
fcf5333bf2 Add the ability to export print template as html
This way we can view the html generated from a print template, for
debugging, validation or printing via your favorite browser.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2019-09-11 17:21:50 +01:00
Robert C. Helling
00c902d66c Show correct notes entry when switching on stops
When gas switching only on stops is selected, the notes
showed an extra line at the not realized stop depth. This
eliminates it. It also makes sure there are no 0 second
spurious entries. And gas switching takes more than zero
time (otherwise we would have to print a line of zero
duration for at the gas switch depth).

Reported-by: tormento <turment@gmail.com>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-09-11 14:55:33 +01:00
Berthold Stoeger
ee365b7341 Plan: introduce function that returns disclaimer
The setting of the disclaimer variable was removed inadvertently
some time ago, which removed the disclaimer from the printed plan.
Instead, introduce a function that returns the disclaimer with
the current deco mode. Use that function to generate the dive
notes and for printing.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-10 21:31:21 +02: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
4479ccf8f3 Cleanup: remove unused MapWidget::repopulateLabels() function
There is the alternative MapWidget::reload() function, which
centers on the selected dive-site.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06 11:48:47 -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
f27d440bb3 Dive site: don't emit divesChanged signals when editing dive site
When editing the dive site, for certain fields a divesChanged signal
was emitted so that the dive-list can be updated.

Arguably it is wrong to decide which fields are relevant to the
dive list in the undo-command code. Therefore, let the list
catch the dive-site-edited signal and decide itself.

But the actual reason for this commit is that if the dive-site
field of a dive changes, we might have to reload the dive-location-model
because suddenly a new dive site appears. Now if this is done
in QML context on some Qt version (notably 5.9) we get crashes
later on. But that can happen if the user moves a flag. So in that
case only send a diveSiteChanged signal.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06 11:48:47 -07:00
Berthold Stoeger
093adf1ea8 Map: highlight correct dive sites in dive site mode
Since changing the highlighting to use the selected dive, dive
sites with no dive were never highlighted in dive site mode.
Obviously, because there was no dive to be selected.

Therefore special-case all dive-site selection code to recognize
when we are in dive site mode.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06 11:48:47 -07:00
Berthold Stoeger
4713611ea8 Cleanup: remove TabDiveSite::updateFilter() function
This one-liner was called in only one place from the same class.
Just fold it into the caller.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06 11:48:47 -07:00
Berthold Stoeger
b766525183 Selection: properly update selection flag of map location
Owing to the recent changes, when the selection flag in the
MapLocationModel was not updated correctly when the user
manually selected the dive. Do that before raising the
divesSelected signal in DiveListView::selectionChanged()
because that will cause the MainWindow to repaint the flags.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06 11:48:47 -07:00
Berthold Stoeger
488eb15423 Desktop: show all selected dive sites on click
When clicking a dive site on the map, the QML code would set
the selected dive site, but then all dives of dive sites in
the vicinity were set. But still only the clicked-on dive site
was shown.

Therefore, don't set the list of selected dive sites in QML,
but later in DiveListView::selectDives(), where we know all
the dives that were selected.

This, again, gives nasty entanglement of diverse widgets and
models.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06 11:48:47 -07:00
Berthold Stoeger
b39f2406c6 Map: don't fully reset model on selection change
When changing the selection the MapLocationModel was reset.
This lead to crashes on Qt-5.9 which are due to QML accessing
data that was freed during model reset. This putative Qt bug
doesn't happen on newer Qt versions. At least Qt-5.12 is known
to work.

Instead of fighting the bug, let's simply not reset the model
but send a dataChanged() for every element of the MapLocationModel.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06 11:48:47 -07:00
Berthold Stoeger
cabe70be80 Desktop: reload map after refreshing the list
In MainWindow::refreshDisplay() with doRecreateDiveList=true
the map was reset before the dive list was recreated. This
makes no sense and only worked because the map was reloaded
again when a dive in the list was selected.

Reload the map after recreating the dive list.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06 11:48:47 -07:00
Berthold Stoeger
bce31ab862 Map: generate pixmap name in model
Experimentation has shown that the image of a flag will
only be changed after dataChanged() if it is a simple
property. The old code had a complex QML expression and
then - for some reason - it didn't work.

To give us better control over the flags and avoid full
reloads of the map therefore introduce a model-property
pixmap name. The name depends on whether the site is
selected and if not, whether we are in divesite-edit mode.
This makes the code rather convoluted. Firstly, we have
to save whether the site is selected in the map-item.
Secondly we have to access the global map-widget, which
in turn has to go to the map-widget helper (layering
violation!).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-06 11:48:47 -07:00
Berthold Stoeger
009f47c5dc Desktop: improve recognition of HTML-notes
To recognize HTML-notes the text was scanned for <div> tags. But
apparently the planner notes do not feature such a thing. Therefore
extend recognition of HTML to <table> tags.

Note we can't use the <html> or <span> tags, because these are
*always* produced by the QTextEdit::toHtml() function.

Fixes #2265

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-30 09:31:50 -07:00
Paul Buxton
3c4fd5d599 Fix broken windows build with latest MXE
Replaces some enums with names that do not clash with windows #defines.
Specifically:
ERROR -> ERRORED, PASCAL->PASCALS, IGNORE->IGNORED,FLOAT->FLOATVAL

Signed-off-by: Paul Buxton <paulbuxton.mail@googlemail.com>
2019-08-29 12:55:25 -07:00
Berthold Stoeger
97380d6a36 Desktop: fix crash on copy & paste
The constructor of PasteState was clearing an uninitialized
weightsystem-table. Very silly. Initialize it instead.

Fixes #2253

Reported-by: Stefan Fuchs <sfuchs@gmx.de>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-24 14:00:06 -07:00
Berthold Stoeger
f25fa2adc5 Cleanup: turn CylinderObjectHelper into value type
CylinderObjectHelper is used for structured formatting of cylinder
values in grantlee types. Instead of keeping a reference to a
cylinder, turn it into a value type containing the formatted strings.

This should be distinctly safer, as we don't risk having stale
references flying around. Moreover, we don't have to use pointers
but can use containers containing plain CylinderObjectHelper. Thus,
no explicit memory management is needed, making the code distinctly
easier to understand.

Sadly, currently grantlee does not support Q_GADGET based Q_PROPERTY.
Therefore a GRANTLEE_*_LOOKUP block has to be added. This can be
removed in due course, as a patch to remedy this issue is in current
grantlee master.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-22 10:13:40 -07:00
Dirk Hohndel
5ffca686c2 Desktop: show local git repos in recent files
But don't show our cloud storage entry (as that is already in the File menu,
anyway).

This is extremely useful because while you can manually enter a file name to
save to (and therefore can use the 'magic' git repo syntax), on most OSs there
is no way to enter that non-existing 'file name' (which is the git branch in
square brackets) in the file open dialog.

Fixes: #2236

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-08-18 23:37:17 +03:00
Berthold Stoeger
594d1d3514 Cleanup: move file-related function declarations to file.h
A number of architecture-dependent functions were declared in
dive.h. Move them to file.h so that not all file-manipulating
translation units have to include dive.h. This is a small step
in avoiding mass-recompilation on every change to dive.h

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08 16:26:31 -07:00
Berthold Stoeger
5da09a21bb Cleanup: move error reporting function declarations to errorhelper.h
Move the declarations of the "report_error()" and "set_error_cb()"
functions and the "verbose" variable to errorhelper.h.
Thus, error-reporting translation units don't have to import the
big dive.h header file.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08 16:26:30 -07:00
willemferguson
78f425de68 Move the Suit text box from the Notes tab to the Equipment tab
Sqash latest commit with previous one.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2019-08-08 09:12:09 -07:00
Berthold Stoeger
344c85f499 Desktop: display trip time on main-tab
On the main tab, the trip time was not shown when switching to
a trip. Implement showing of the trip date in a function, as the
undo-code will also have to update the trip date in certain
circumstances.

Fixes #2207

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08 09:03:33 -07:00
Dirk Hohndel
29f5d15a66 Desktop: correct tooltip for filter close button
This button only closes the filter panel but doesn't clear it.

Reported-by: Adric Norris <landstander668@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-07-29 07:24:05 +02:00
Berthold Stoeger
999a63a5bb Desktop: fix index in weightsystems_equal()
The weightsystem_equal() function compares weightsystems of two dives
to decide whether the "commit changes" message should be shown and
to decide which dives are edited when changing multiple dives.

Due to an index mixup the function returned wrong results for
more than two weightsystems. Fix it.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-27 11:51:34 -07:00
Berthold Stoeger
726d08c2f7 Undo: make editing of dive number undoable
When pressing F2 in the dive list, the number can be edited.
Make this action undoable by implementing a EditNumber command.

This command is differs from the other undo commands, as not the
currently selected dives are changed. This means that the EditCommand
needs an alternative constructor taking a single dive. This constructor
was implemented in the base class so that all edit commands can now
be called with a single dive.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-19 21:44:13 -07:00
Berthold Stoeger
a5e7f4253a Core: dynamically resize weight table
Replace the fixed-size weightsystem table by a dynamically
relocated table. Reuse the table-macros used in other parts
of the code.

The table stores weightsystem entries, not pointers to
weightsystems. Thus, ownership of the description string is
taken when adding a weightsystem. An extra function adds
a cloned weightsystem at the end of the table.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18 06:01:07 -07:00
Berthold Stoeger
e3577ffd7e Cleanup: Remove unused function calls in main tab
per_cylinder_mean_depth() and selected_dives_gas_parts() are used
in the dive-information and statistics tab, respectively. Nevertheless,
these functions are called on the main tab as well and the result is
trashed. Therefore remove the calls. Must have been an artifact.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18 05:47:27 -07:00
Berthold Stoeger
8f119dcf72 Cleanup: remove includes from qthelper.h
To reduce interdependencies, remove the dive.h and divelist.h
includes in qthelper.h

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18 05:42:55 -07:00
Berthold Stoeger
0136d76cf4 Cleanup: move deco function declarations to deco.h
Another tiny step in making dive.h smaller: move function
declarations to deco.h if these functions are defined in deco.c
and don't directly concern dives.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18 05:42:55 -07:00
Berthold Stoeger
16214e753a Cleanup: remove includes from qt-models/models.h
qt-models/models.h included dive.h and divelist.h. Remove these
unnecessary includes, to reduce interdependencies. A drop in the
bucket, for sure.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18 05:42:55 -07:00
Doug Junkins
0fb4ac7602 Fixed filter scrollarea not adjusting to parent height
Changed the Qt Layout for FilterWidget2 to "Lay Out on a Grid" to
allow the scrollarea to adjust when the height of FilterWidget2
changes. Fixes issues #2174.

Signed-off-by: Doug Junkins <junkins@foghead.com>
2019-07-13 09:38:40 -07:00
Berthold Stoeger
5886550434 Desktop: clear notes on empty dive
If no dive is set, all fields except the note field were cleared.
Also clear notes.

Fixes #2172

Reported-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-11 15:58:30 +02:00
Berthold Stoeger
66a5b394d7 Preferences: warn if ffmpeg can't be loaded
In the preferences widget warn the user when they enter a non-executable
path to ffmpeg. Thus they don't have to start thumbnailing just to
find out that the path is wrong.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-11 00:24:23 +09:00
Dirk Hohndel
25bee36fcc Desktop: update BT selection when picking remembered dive computer
When switching to a BT dive computer, the device selection dialog is opened,
when switching away from BT, the device address is set.

Fixes #2139

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-07-09 21:41:04 +02:00
Dirk Hohndel
774e9ae143 Desktop: reduce minimum vertical size
The Filter widget really needed to be scrollable as it is very tall.

Fixes #2152

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-07-04 17:21:23 +09: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
Berthold Stoeger
57c22d3dcc Cleanup: avoid spurious updateDiveInfo() calls
In 2e230da361 the dive-selection signals
were unified. Sadly, this was done in a suboptimal way resulting in
numerous calls to updateDiveInfo(), which refreshes the main-tab.

Firstly, the MainWindow connected to selection changes from both,
the undo-command and the divelist. Secondly, every selected dive
in the divelist caused a single signal.

Thus, connect only to the divelist (this is necessary for user-initiated
selection changes) and only send a single signal in the divelist
per selection-reset.

This is still less than perfect as updateDiveInfo() is called even
if the current dive doesn't change.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-04 10:40:47 +09:00
Berthold Stoeger
019eeec93d Dive merge: don't use unset dive numbers
On merging, don't use the number of the first dive if it is 0.
Use the first non-zero number.

Fixes #2126

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-28 20:23:01 +09:00
Dirk Hohndel
bc4c8d7d74 Desktop: small optimization
This way we don't need to iteratively grow the QVector.

Suggested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-06-24 13:01:25 +02:00
Dirk Hohndel
d0df6a0073 Desktop: update dive list when dive sites change
Now when we change dive site location or name through a redo, the dive
list is updated as expected.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-06-24 13:01:25 +02: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
Dirk Hohndel
ca496c63ae Desktop: fix time editing
We were shifting in the wrong direction. Which caused the field to be marked as
'edited' again, which meant we shifted the wrong way and twice the distance.
This seems to fix the problem for both date and time editing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-06-24 10:32:41 +02:00
Berthold Stoeger
2e230da361 Cleanup: unify selection signals
For historic reasons, there where three distinct signals concerning
dive-selection from the undo-machinery:
1) divesSelected: sent newly selected dives
2) currentDiveChanged: sent if the current dive changed
3) selectionChanged: sent at the end of a command if either the selection
   or the current dive changed

Since now the undo-commands do a full reset of the selection, merge these
three signals into a single signal.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-23 20:08:46 +02:00
Berthold Stoeger
4716c82032 Cleanup: remove selectionChanged logic from dive-list commands
Since all commands now fully reset the selection, there is no point
in keeping track of whether the selection changed on addition or
removal of dives. This can be done in the function that sets the
selection.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-23 20:08:46 +02:00
Berthold Stoeger
e1abf9485c Undo: unify selection behavior in dive-list commands
Some commands tried to retain the current selection on undo/redo,
others set the selection to the modified dives.

The latter was introduced because it was easier in some cases, but
it is probably more user-friendly because the user gets feedback
on the change.

Therefore, unify to always select the affected dives on undo()/redo().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-23 20:08:46 +02:00
Berthold Stoeger
27944a52b1 Undo: don't send signals batched by trip
Since the default view is batched by trips, signals were sent trip-wise.
This seemed like a good idea at first, but when more and more parts used
these signals, it became a burden. Therefore push the batching to the
part of the code where it is needed: the trip view.

The divesAdded and divesDeleted are not yet converted, because these
are combined with trip addition/deletion. This should also be detangled,
but not now.

Since the dive-lists were sorted in the processByTrip function, the
dive-list model now does its own sorting. This will have to be
audited.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-23 20:08:46 +02:00
Dirk Hohndel
4b0f90ced3 Desktop: use local variable instead of displayed_dive
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-06-23 11:29:52 +02:00
Dirk Hohndel
6619bd972c Desktop: don't use planner to manually add dive
Instead of calling into the planner, simply create the dive computer
information right there, using the existing helper function we have to
create simple profiles.

Fixes #2128

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-06-23 11:29:52 +02:00
Berthold Stoeger
12a13d722a Undo: sort dives by dive_less_than() in signals
In signals dives were sorted by date. This criterion is not be unique.
Therefore sort by the dive_less_than() function of the core to avoid
any inconsistencies between the Qt-models and the core data.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19 13:11:10 -07:00
Berthold Stoeger
54d6c3f004 Cleanup: remove unnecessary get_gas_used() call
The result was not used anywhere, so why bother?

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19 13:11:10 -07:00
Berthold Stoeger
5d34103cb9 Cleanup: use quotation marks for non-system includes
That's common practice, so lets do it that way.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19 13:11:10 -07:00
Berthold Stoeger
3df32044ee Cleanup: generate clear_*_table() functions by macro
In analogy to the other table functions, generate these by
a macro as well.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19 13:11:10 -07:00
Berthold Stoeger
7f4d9db962 Cleanup: move trip-related functions into own translation unit
These functions were spread out over dive.c and divelist.c.
Move them into their own file to make all this a bit less monolithic.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19 13:11:10 -07:00
Berthold Stoeger
6200909ba4 Cleanup: move tag functions into own translation unit
Make dive.h a bit slimmer. It's only a drop in the bucket - but at
least when modifying tag functions not the *whole* application is
rebuilt anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19 13:11:10 -07:00
Berthold Stoeger
e329a53aab Undo: add undo button to multi-dive-edited warning message
Simply connect the button the the undo-action and the hide-message
action.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-15 11:20:49 -07:00
Berthold Stoeger
a20c22d907 Undo: hide multi-dive-edit warning message on subsequent edit
When a different field is edited, hide any old multi-dive-edit
warning message. The reason is that we might want to add an "undo"
button to the message. But this will undo the wrong command if
we don't hide the message.

Sadly, this means that we can't use animated show / hide, because
an animatedHide() followed immediately by an animatedShow() does
not necessarily show the message. In other words, and animatedShow()
does not interupt a started animatedHide()!?

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-15 11:20:49 -07:00
Berthold Stoeger
f51e402e04 Undo: only show warning message if dives were actually edited
The multiple-dives-edited message was shown even if the value was
not changed. Notably, when tab-flipping through the dive fields.

Therefore, changed the execute_edit() function to return zero
when no command was executed. For this, return a boolean from
the execute() function indicating whether the command was really
executed or trashed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-15 11:20:49 -07:00
Berthold Stoeger
944a9aed54 Undo: show warning message if more than one dive edited
On the MainTab, warn if more than one dive was edited. To this purpose,
add a new KMessageWidget with an "OK" button that closes the message.
Code is mostly a copy of the already existing "Editing dive" message.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-15 11:20:49 -07:00
Berthold Stoeger
99dc528a10 Cleanup: remove MainTab::addMessageAction() function
This is a pointless one-liner function. Let's remove it. The
message it shows will probably be moved to the profile in the
not-so-distant future anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-15 11:20:49 -07:00
Berthold Stoeger
bd7196d93e Cleanup: unify comments in desktop-widgets/command.h
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-15 11:20:49 -07:00
Berthold Stoeger
03d5e641e1 Undo: return number of changed dives from undo commands
To enable a "multiple dives edited" message, return the number
of edited dives from dive edit undo commands. Since there are
two kinds of these commands, viz. normal fields and tag fields,
and the former use templates, create a common base class that
can return the number of dives. Yes, the class hierarchy is
getting scarily deep! At least, this gives a tiny bit of
code-reuse.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-15 11:20:49 -07:00
Berthold Stoeger
1641147e7b Undo: don't create spurious undo commands for temperature fields
When tabbing through the dive-info fields we get *EditingFinished
signals. This would create undo commands. The undo commands should
recognize if nothing changed. But for the temperature fields,
owing to rounding, an unchanged text could actually represent a
different value.

This would lead to very confusing situations:
1) Edit air temperature
2) Press tab to finish editing
3) Focus goes to water temperature
4) Try to undo change in menu
5) When opening the menu water temperature loses focus
6) Water temperature is edited
7) Undo undos the water temperature, not the air temperature
8) Goto 4

Fortunately, QLineEdit fields have the isModified() member function
that returns true if the field was changed by the user. Use
this to prevent this case. This is not a general method, i.e.
it has to applied to every field with that problem. But it is
less intrusive than subclassing the QLineEdit class.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-15 11:07:15 -07:00
Berthold Stoeger
cdb3bcb1a6 Cleanup: remove silly typo in translation comments
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-15 11:07:15 -07:00
Berthold Stoeger
439fcead08 Cleanup: remove Q_PROPERTYs from MinMaxWidget
This is not used from QML - no apparent need for this property cruft.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-10 17:59:35 +03:00
Berthold Stoeger
b9154123ed Cleanup: Un-PIMPL-ize MinMaxAvgWidget
The PIMPL idiom is used by some frameworks (notably Qt) to
ensure binary compatibility. Objects consist only the general
object header (ref-count, connections, children, etc..) plus
a single pointer to private data.

MinMaxAvgWidget was implemented using this idiom. This seems
to make no sense, as we don't produce a general library with
the need of a stable ABI. Let's remove this unnecessary
indirection.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-10 17:59:35 +03:00
Berthold Stoeger
4a8ae2a090 Desktop: invalidate dive cache on equipment edit
Owing to the recent undo-changes, the git id was not invalidated
when accepting changes to cylinders and weights.

Do this in the MODIFY_DIVES macro for now.

Reported-by: Jan Iversen <jani@apache.org>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-07 04:51:04 +03:00
Berthold Stoeger
0e1b07bd6f Desktop: don't show location-popup button in trip-edit mode
The location fields are hidden in trip mode. Only the location-popup
button was shown. Hide it as well.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-07 04:47:39 +03:00
Berthold Stoeger
eefd58a5c8 Cleanup: remove unnecessary QRegularExpression copies
A regular expression was generated and then copied twice without
apparent reason. Remove these copies.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-06 14:52:42 +03:00
Berthold Stoeger
efb98cfd69 Printing: use regexp in preprocessTemplate()
preprocessTemplate() replaces variables of the kind "dive.weight0"
by "dive.weights.0". Replace the old code by regexps. This not
only makes the code significantly shorter, it also makes it independent
from the name of the dive variable (i.e. "dive").

Moreover, it removes a dependency on MAX_WEIGHTSYSTEMS and MAX_CYLINDERS,
which might help in removing these restrictions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-06 14:52:42 +03:00
Robert C. Helling
4ee307266b Reword configure dive computer
Some users understood "Configure dive computer" as the
menu entry where you configure which dive computer to
use. Reworded to make clear that this modifies the
settings on the dive computer.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-06-03 19:55:19 +02:00
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