Commit graph

19616 commits

Author SHA1 Message Date
Berthold Stoeger
db0f8ba045 statistics: add sort mode on mobile UI
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-01-04 11:14:24 -08:00
Berthold Stoeger
1e5191e33e statistics: add a sort mode for categorical bar charts
This was a user request: Sort bar charts by height of the bars.
Obviously, this can only work for categorical charts, not for
histograms.

The UI is a break from the old concept: the sorting is chosen
based on the chart, whereas for the rest of the features, the
viable charts are presented based on the binning, etc.

I found it confusing to have the possible charts be selected
based on sorting. I.e. if a non-bin sort mode is selected,
the histogram charts disappear. On the flip side, this would
be more consistent. We can change it later.

For value-based bar charts, there are three sort modes: by
bin, by count (i.e. number of dives in that bar) and by
value (i.e. length of the bar). This hopefully satisfies all
needs.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-01-04 11:14:24 -08:00
Berthold Stoeger
f76752ee03 cleanup: fix typos in comments in statistics code
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-01-04 11:14:24 -08:00
Dirk Hohndel
4fdbb116ef tests: fix integer constants
In TestUnitConversion we used casts instead of the more common suffix
designations to indicate the type of those integer constants.
Worse, in commit efab955d85 ("cleanup: make feet_to_mm signed") the
return type of feet_to_mm() changed, but the value it is compared to
wasn't adjusted in the test which caused some builds with more
aggressive compiler flags to fail.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2022-01-04 19:48:35 +01:00
Berthold Stoeger
efab955d85 cleanup: make feet_to_mm signed
Depths are pretty much universally stored using signed integers
(e.g. depth_t is signed int). For consistency, make feet_to_mm()
likewise return a signed value.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-01-02 13:51:07 -08:00
Berthold Stoeger
4f1034b605 cleanup: make a variable signed
The prev_time variable was defined as unsigned and mixed
with signed variables. gcc rightfully complains with -Wextra.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-01-02 13:51:07 -08:00
Berthold Stoeger
c43311614e cleanup: remove obsolete includes in core/device.cpp
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-01-02 13:51:07 -08:00
Berthold Stoeger
72ad4cedf5 cleanup: replace strcmp by std::string methods
Since these are std::strings anyway, there seems to be no point
in using the C-lib functions. YMMV, but to me that code is
distinctly more easy to parse.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-01-02 13:51:07 -08:00
Berthold Stoeger
66896ad7d7 cleaup: remove device::operator==()
The last user was removed when including devices in the undo
system.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-01-02 13:51:07 -08:00
Berthold Stoeger
c893d19ea4 cleanup: pass all parameters to weightsystem_t
With -Wextra, gcc/g++ complains that compound initialization
of weightsystem_t misses the auto_filled parameter. Add it.
For C++ code we might think about writing a constructor. However,
we use two versions: with and without copied string.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-01-02 13:51:07 -08:00
Berthold Stoeger
d89ef3d906 cleanup: fix narrowing type conversion warning
In pscr_o2() the result of a double calculation was implicitly
converted to int, which resulted in a gcc warning.

Part of the expression was explicitly converted to int, but then
subtracted from a double.

Instead, do all the calculations in double and cast the final
expression to int. This is probably the prudent thing to do.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-01-02 13:51:07 -08:00
Berthold Stoeger
4458535265 profile: use unique_ptr to store DiveTextItems
Pure bike-shedding:
The DiveTextItems of the DiveProfileItems were stored as raw
pointers. Instead, store them as unique_ptrs, so that they
don't have to be explicitly deleted.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
cf1ad3d831 profile: add space at bottom of temperature graph
The temperature graph connected directly to whatever was below.
Thus, the lowest temperature often was not clearly seen.

Add a general "bottom border" space to the main chart features
and set it to two pixels for the temperature and zero pixels
for the rest. Might need some fine-tuning.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
3ae160857d profile: reformat timestamp labels
The timestamp labels may change their format on zoom from
"mm" to "mm:ss", depending on the zoom level. Since the
animation kept old labels, this meant that one can end up
with a mix of labels.

Therefore, always reformat the labels. Of course, this
means that the labels switch instantaneously from one format
to the other. This is in conflict with the whole idea of
"smooth" animation. Such a smooth animation could be realized
by adding a "format" flag to the Label structure and keeping
thus fading in/out labels if the format changes. Do we want
that?

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
2645fa1495 profile: remove fast argument of create_plot_info_new()
This prevented calculation of the pressure data when dragging
planner handles. However, this lead to weird artifacts.

As an alternative, if this turns out to be too slow, we might
disable the plotting of the pressure curves instead.

That said, even on my super-slow fanless laptop, this performs
reasonably.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
352cdcc863 profile: fix crosshairs
In planner and edit mode, the cursor position is indicated using
crosshairs. They broke when changing to absolute scaling.

To fix them, remember the plot-area in the profile scene and
draw the crosshairs only inside this area (not on top of axes).
However, limit the position of the horizontal line to the
actual profile (dont paint inside the partial pressure, etc
graphs). The vertical line is painted above those graphs, so
that a timestamp can be related to partial pressure, tissue
loading, etc.

Also, set the z-value of the crosshairs. It was painted
inconsistently above some and below other chart features.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
26c6344e70 profile: remove two unneeded includes in profilewidget2.cpp
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
7e4973c5b1 profile: don't show "base line" for axes without labels/grid
The axes are implemented by a line, which determines the
position. For axes without labels/grids this looks ominous.
For now, make the line invisible. But really, this should
be changed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
3579e36b7d profile: don't show 0m label
The old profile code didn't show the 0m label, because that
was cut off. This was lost when redoing the axis code.
Reimplement this. The code is very ugly: it recognizes the
depth axis by the fact that is the only "inverted" axis.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
725fda3cd1 profile: don't add excessive depth
The old get_maxdepth() function in profile.c was accounting for
two things:
- the partial pressure graphs
- rounding to sane value

Both are now taken care of by the profile itself. This leads to
excessive max-depths. Remove the code from profile.c.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
de71435c11 profile: clear the chart when there is nothing to display
This is a shouldn't happen situation, because we always
fake a profile. Let's handle it gracefully anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
ecd3334a1c profile: when clearing the profile, also reset the profile data
When hovering over the chart after the chart was cleared,
there were artifacts owing to the stale profile data.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
789eb2c620 profile: clear plot_info structure when freeing data
free_plot_info_data() frees the sample and pressure arrays
and accordingly sets the corresponding pointers to NULL.

However, it doesn't clear the element-count and thus leaves
the structure in an inconsistent state.

Clear the whole structure with memset(). I am not a fan of
doing so, but there are existing memset() calls in the
same source file, so let's keep it like that for consistency.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
564cbc797c profile: remove DivePlotDataModel
All accesses to the plot data are now directly to the core
structures.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
7aacde3169 profile: remove ProfileScene::dataModel
All data access is now directly via the plot_info structure
owned by the ProfileScene itself.

Also removes DivePercentageItem::hColumn, which was an
artifact from the DivePlotDataModel.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
bdbcb1b7e3 profile: access the ProfileScene's plot_info
There were two plot_infos of the same dive: one owned by
ProfileScene and one owned by DivePlotDataModel. The latter
was (or at least should have been) a copy of the former.

Simply always access the plot-info which is owned by
ProfileScene anyway. That seems much less brittle. Why
risk some desyncing?

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
6f2965c5af profile: access profile data directly
The profile was using a Qt-model to access its data. This means
routing everything through Qt's QVariants and lead to verbose
code such as

double prev_y = dataModel.index(i-1, vDataColumn).data().toReal();

Instead of storing a data-column and do access via a template,
simply store accessor functions. The code from above now reads as

double prev_y = accessor(data[i-1]);

This should also be distinctly faster for the ns-optimizers among
us.

Only one case was somewhat nasty to convert: The accessors for
the 16 tissues are now generated via a recursive template. Thanks
to C++17's constexpr if, such a template is pleasantly easy
to follow, though.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
11913e614c profile: don't derive ProfileItems from QObject
The intention was to use QObject slots for animations.
However, these animations never materialized. Should we
ever want to animate them, we might use the animation
object that is already used for cartesian axes.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
6fa5e59994 profile: remove AbstractProfilePolygonItem::hDataColumn
This indicated the data of the horizontal axis. It was (obviously)
always the time axis. Remove.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
e0f44237cc profile: move max_gas() from DivePlotDataModel to ProfileScene
There is only one user of this - let's remove complex
interdependencies.

Note: there seem to be two independent plot_infos: in the
ProfileScene and in the DivePlotDataModel. To avoid behavioral
change, this keeps using the DivePlotDataModel's version.
In any case, this has to be unified.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
1df1f3d0b5 profile: remove DivePlotDataModel::dcShown()
The last user was removed in 2789bb05b1.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
f13768fe65 profile: fix instant logic
There was logic to disable animation when switching from "no dive"
to "show dive". However, that has bit-rotted away: the plotted
dive was set before plotting the dive and therefore the check
for "change from empty" did not work. Introduce an explicit
empty flag instead.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
e7b078a7fd profile: remove unused animation functions
A few animation function are not necessary anymore.
Remove them.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
5c5c0c4880 profile: redo animation of labels and grid lines
The old animation was weird: it would reuse the labels
based on the index, not on the value. Thus, with the
new scaling code, sometimes there was no animation at all,
if the value, but not the position changed.

Consider the values instead and let labels appear/disappear.
This makes things slightly more complex.

While changing this code, create our own animation-class.
Thus, we can avoid having the dive axes being QObjects.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
afb0978460 profile: shorten DiveCartesianAxis::posAtValue(qreal value)
This function was just needlessly complicated. For one, it
considered the position of the line, but that is never changed
since redoing the positioning code. Moreover, it does in
lots of lines what is a very idiomatic operation: a
one-dimensional affine transformation. Let's shorten the
actual calculation to two lines.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
8ff949650a profile: vertical center mean depth label
This label is put to the right of the corresponding curve,
so it should arguably be centered vertically. At least to
me this looks more natural.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
176a62f752 profile: improve calculation of the right border
The time axis might need some space and the average depth item
puts a formatted depth at to right of the profile. Consider
these when calculating the right border.

Since I found no way to turn of the average depth, this creates
a permanent border, which might or might not be a good thing.

Contains some refactoring of the label-size functions provided
by DiveTextItem.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
6b33c3e721 profile: better increments for the time axis
The usual increments (leading 1, 2, 4 or 5) don't look
natural for the time axis. Therefore special case the
time axis and to increments in 1, 2, 3, 4, 5, 6 or 12
parts of a minute or second.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
210660d057 profile: rewrite ProfileScene::pointOnProfile()
This function was used to check wether a screen-point
is located on the profile. Bizzarely, this was done by
transforming into local coordinates and checking
min/max value. Simply check the screen coordinates
directly. Moreover, make the function return whether
the point is inside the region, not outside the region,
to make logic more straight forward.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
7df0adef64 profile: only show thumbnails in range
Hide thumbnails, which are out of the shown range. This became
necessary when converting to absolute scaling.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
6cc6fe4d91 profile: fix y-coordinate of picture thumbnails
When changing from relative to absolute scaling of the char
elements, positioning of the picture thumbnails was broken.

To emulate the old behavior, add a function to DiveCartesianAxis,
that allows positioning with respect to the axis on the screen.

To simplify tuning of the poctuire positions, name a few
constants explicitly.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
51be326879 profile: don't recreate picture thumbnails on zoom / scroll
The picture thumbnails were recreated on every profile render,
even when zooming / scrolling. In that case, we should only change
the positions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
71629521b7 profile: don't recalculate plot-info when zooming / scrolling
This is a potentially expensive operation (e.g. interpolation of
pressure values), so don't recalculate the plot data for every
redraw.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
6dfc2da8d0 profile: use a flag variable in plotDive()
Positional bool parameters to control the rendering of the plot
have been a pain. We are down to one parameter (instant),
but more will be readded, so let's use the opportunity to
control rendering with a flags parameter.

Sadly, C++ has no reasonable way of defining flags that I know
of. Either the identifiers leak (enum), or can't be trivially
ORed (enum class) or are weakly typed (int). Let's just use an
integer for now.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
d3a2c40f52 profile: remove "changed" flag of DiveCartesianAxis
This prevented the axes from being redrawn on resize. It shouldn't
be necessary anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
b673355245 profile: don't check for printMode in ProfileWidget2
This widget is no longer used for printing, therefore these
tests are obsolete.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
685b7cb2a8 profile: no doClearPictures argument for ProfileWidget2::plotDive
All callers were passing the default value (false).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
01af4bcd00 profile: remove min/max entries from plot_data
These were the minimum and maximum of a 9-min window.
The profile now uses an adaptive peak-search, so this is not
used anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
7ef0ae02a8 profile: implement adaptive depth markings
The old code used the maximum / minimum values of nine-minute
intervals to indicate maximum / minimum depths. This does not
work well when zooming, since the labels will get sparse.

Instead implement a primitive peak finding algorithm, that
searches for the deepest peak in the whole plot and then
repeats the procedure for the right and left sides, leaving
out a certain distance to the origninal peak. This is repeated
until there are no more peaks found.

Only peaks of a certain prominence are considered, which
conveniently gives us the valleys.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
efc89b9d9c profile: use dynamic distances between labels on chart
Use variable intervals for printing temperature and heart
beat labels. Obviously, so that the labels don't become
sparse on zooming, but also to make them not too crowded
on mobile / small screens.

This doesn't work for depth labels, because these labels
use data provided from the profile.c core that doesn't
know about the size of the chart.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00