Commit graph

54 commits

Author SHA1 Message Date
Berthold Stoeger
9d3b15bf9c translations: initialize water type strings at run time
The water type strings were static and therefore passed through
gettextFromC::tr() before main(). One would hope to get a warning
in such a case, but this is not the case.

Therefore, use the QT_TRANSLATE_NOOP macro to register the strings
in Qt's translation system and translate the list when needed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-21 13:42:00 -07:00
Berthold Stoeger
891c0e7ec6 cleanup: whitespace fixes in TabDiveInformation
Use C-style function definitions (squirly brackets on new lines) and
remove empty lines at end of file.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-25 08:33:08 -07:00
Berthold Stoeger
2d17edeb40 desktop: localize salinity value
The salinity value was not displayed with localized thousands separators.
E.g. to a user of a German locale the density read as slightly over
1 g/l, when it should be approximately 1000 g/l. For consistency, also
localize that value.

Also localize the CNS and OTU numbers, even though these should
(hopefully!) never come with thousands separators.

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

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

This is the followup to do that.

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

Signed-off-by: Monty Taylor <mordred@inaugust.com>
2020-05-05 17:31:47 +03:00
Berthold Stoeger
2829909376 profile: remove outside callers of ProfileWidget2::replot()
There was a mix of ProfileWidget2::replot() and
ProfileWidget2::plotDive(current_dive, true), which is equivalent.
Since there was more of the latter and it is more flexible, unify on
that.

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

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

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

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

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

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-21 07:50:38 -07:00
Berthold Stoeger
b4e0968ed5 desktop: remove special QGroupBox stylesheet for non-Windows systems
That style-sheet made things look really ugly on most Linux themes.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-13 10:14:00 -07:00
Dirk Hohndel
2feb7077f8 code cleanup: add missing initialization
While technically the initial value of this variable makes no difference as
it is set when the first dive is displayed, technically Coverity is correct.

Fixes CID 353273

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

Suggested-by: willemferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-06 07:00:34 +09:00
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
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
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
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
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
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
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
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
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
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
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
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
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
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
b2b328fd7e Cleanup: remove redundant string clearing
The default QString constructor generates an empty string. No point
in assigning the empty string to such a thing.

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

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

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

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

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-29 12:58:49 -07:00
Berthold Stoeger
c32e71e64d Dive information: fix surface interval calculation
The old surface interval calculation had fundamental issues:

1) process_all_dives(), which calculates the statistics over *all*
   dives was used to get the pointer to the previous dive.
2) If two dives in the table had the same time, one of those would
   have been considered the "previous" dive.
3) If the dive, for which the surface interval is calculated is
   not yet in the table, no previous dive would be determined.

Fix all this by creating a get_surface_interval() function and
removing the "get previous dive" functionality of process_all_dives().
Remove the process_all_dives() call from TabDiveInformation::updateData().

Reported-by: Jan Mulder <jlmulder@xs4all.nl>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-07 05:41:48 +03:00
Berthold Stoeger
360f07e453 Cleanup: pass gasmix by value
In a previous commit, the get_gasmix_* functions were changed to
return by value. For consistency, also pass gasmix by value.

Note that on common 64-bit platforms struct gasmix is the size
of a pointer [2 * 32 bit vs. 64 bit] and therefore uses the
same space on the stack. On 32-bit platforms, the stack use
is probably doubled, but in return a dereference is avoided.

Supporting arbitrary gas-mixes (H2, Ar, ...) will be such an
invasive change that going back to pointers is probably the
least of our worries.

This commit is a step in const-ifying input parameters (passing
by value is the ultimate way of signaling that the input parameter
will not be changed [unless there are references to said parameter]).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23 05:16:38 -07:00
Berthold Stoeger
36b9e5e31e Cleanup: fold core/helpers.h into core/qthelper.h
helpers.h included qthelper.h and all functions declared in helpers.h
were defined in qthelper.h. Therefore fold the former into the latter,
since the split seems completely arbitrary.

While doing so, change the return-type of get_dc_nichname from
"const QString" to "QString".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-04 08:50:10 -07:00
Dirk Hohndel
ea83b5ed37 Core: remove dive.h from files that don't need it
Of course, quite a few of them indirectly get it through other header
files.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-14 10:13:39 -07:00
Stefan Fuchs
e7ae749d52 Consistently use the famous l for liters in info tab
For salinity in info tab change the l character to the famous
Subsurface "ℓ".

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-17 19:48:50 -08:00
Stefan Fuchs
7713c7e607 Use helper function dive_endtime() where apropriate
Calculating dive.when + dive.duration doesn't always give the correct
endtime of a dive especially when a dive has surface interval(s) in
the middle.
Using the helper function dive_endtime() fixes this issue.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-01 23:55:37 +03:00