Commit graph

48 commits

Author SHA1 Message Date
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
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
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
a496ab016b profile: remove visibilityKey members of a few DiveProfileItems
There were no users.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
073059f5ab profile: clip DiveProfileItems
Avoid "overshooting" of the profile items by linearly clipping
the first and last segment to the boundaries of the time-axis.

Sadly, quite a lot of code, because every profile item is
slightly different.

In particular the pressure-segment handling was rewritten.
It now stores the begin and end of each segment to draw
the appropriate text items.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
118700fd18 profile: pass [from,to] range to polygon plotting functions
Only plot the zoomed range. Currently this passes the sample
before and after the range, so it generally "overshoots" by
one sample in each direction. The plan is to do clipping
on the first and last polygon segment later on.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
505e4e47eb profile: reimplement DivePercentageItem
The tissue percentages were realized as 16 independent polygons.
That didn't work at all with the new absolute scaling.

Reimplement the item and blast it onto a pixmap. Not only is
this artifact-free, it also should (hopefully) be quite a bit
more efficient than painting numerous lines.

In contrast to the old code, this does access the plot_info
structure directly instead of using the model. Not so much
for performance reason, but rather to make things more robust:
We have a strongly typed language. Why would we shoehorn data
through the weakly typed QVariant and mess with wierd
index-arithmetics. Makes no sense to me. Qt-model have to
be used for interfacing with Qt. They are terrible for
intra-application data transfer.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
2ebe6e3684 profile: set alignment and scale of DiveTextItem at construction
Alignment and scale of DiveTextItems are never changed. Therefore,
pass them at construction time. This makes things much easier
if we want to cache the rendered text [currently the text is
rerendered at every paint() event].

This also removes the "parent=0" default parameter of the
constructor, because inadvertently leaving out the last argument
led to a subtle bug.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
f713858ba4 profile: rename printFontScale to dpr (device pixel ratio)
The printFontScale is used to scale up fonts (and icons) when
rendering to high-DPI devices. With absolute scaling, this
will also be used to scale the size of different chart
regions, line thickness, etc. Therefore, give it an more
appropriate name. "Device pixel ratio", which is a well
established term, seems to appropriately describe the
concept.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
064d861e97 profile: update comment
The usage of the DiveProfileItems has changed (axes, etc. are passed
at construction time). Update a comment accordingly.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
01983c65c3 profile: pass fontPrintScale at construction time
Instead of intializing the text fields and then changing the
font scale via signal-rigmarole, pass down the font-scale
at construction time.

Since the fontPrintScale is only set in print mode, we also
can access it directly instead of testing for printMode.

Since the DiveTextItem is not updated using signals anymore,
the connected flag can be removed.

The commit is larger than I had hoped for, but this makes
things ultimately less brittle.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
ca7a2df121 profile: remove AbstractProfilePolygonItem::setVisible()
This was just a stub to make the setVisible() function a "slot".
Since there are no more signals using it, remove it.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
13bd7aa163 profile: remove signals that update visibility of chart features
The visibility is set on every redraw, which is called when
the preferences change. No need for these signals.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
55bc1938ad cleanup: remove DiveCalculatedCeiling::profileWidget
The DiveCalculatedCeiling had a back-pointer to the profileWidget.
This was used for weird control-flow shenanigans, which were
removed in 975c123a30.

Remove this now useless member variable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-07-30 08:02:05 -07:00
Berthold Stoeger
a7002f4089 profile: remove DiveAmbPressureItem
This was replaced by the tissue map in 893bea700c.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-05-08 13:40:24 +02:00
Berthold Stoeger
8b0db14f64 profile: remove DiveGFLineItem
This was replaced by the tissue map in 893bea700c.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-05-08 13:40:24 +02:00
Berthold Stoeger
c6d78bc134 planner: pass in_planner argument to replot()
To remove reliance on global state, pass an "in_planner" argument
to AbstractProfilePolygonItem::replot(). Thus, calls to in_planner()
can be removed.

This is a bit sad, since the in_planner argument is now passed
to numerous replot() reimplementations of classes derived
from AbstractProfilePolygonItem. However, it is only needed
for one, viz. DiveGasPressureItem. Well, perhaps in the future
more features will depend on the planner mode...

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-17 07:26:55 -08:00
Berthold Stoeger
65720d2fce cleanup: remove function declaration
AbstractProfilePolygonItem::shouldCalculateStuff()'s definition
has been removed some time ago. Therefore, remove its declaration.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-17 07:26:55 -08:00
Berthold Stoeger
193513a61f profile: pass dive to plot function of profile-items
Instead of accessing the global displayed_dive variable,
pass the dive to the various profile items. This is a
step in making the profile code reentrant.

This removes the last user of the displayed_dc macro,
which can now be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10 15:57:39 -08:00
Berthold Stoeger
45ee3544d1 profile: remove DiveProfileItem::settingsToggled
This was used to force a replot on preferences changes.
However, the profile now does a replot in such a case
by itself. This can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10 15:57:39 -08:00
Berthold Stoeger
0392994df0 profile: move calculations out of DiveGasPressureItem::paint()
With the same argument as for DivePercentageItem, move access
to live data out of the paint() function. Instead, calculate
colors in replot(), where the other data are calculated.

This is slightly more complicated than in DivePercentageItem,
since there are multiple polygons. Therefore, replace QPolygonF
by a vector of structures contained the position and color
of the data point.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10 15:57:39 -08:00
Berthold Stoeger
acee77e516 profile: move calculations out of DivePercentageItem::paint()
The DivePercentageItem is a polygon-item with a custom paint()
method. Calculation of the polygon is done once in replot(),
but calculation of the corresponding colors is done in every
paint() call. The problem is, we have no control over paint().
It is called whenever Qt feels like. Therefore using live
dive data is a dangerous proposition if we ever want to get
rid of the global displayed_dive.

Do all the calculations in replot(). Store the colors in an
additional array of the same size as the polygon.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10 15:57:39 -08:00
Berthold Stoeger
f5e60b9618 profile: remove AbstractProfilePolygonItem::modelDataChanged()
The old mechanism to replot the profile items was to listen
to model-change signals. Then the code checked whether it
actually had to update anything by looking at the changed
model-indices.

However, the crucial replot was always initialized with
emitDataChanged(), which simple invalidated the full model
and therefore shouldCalculateStuff() always returned true.

Since now the replot() is called explicitly, remove the whole
logic and simply rename modelDataChanged() to replot().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10 15:57:39 -08:00
Berthold Stoeger
02fbaffe4c profile: explicitly clear profile items
In contrast to most other items, which are cleared in the
setEmptyState() function, the profile items are cleared
indirectly via a signal from the model. Very hard to follow
and indeed, I thought I could just remove the slot.

Do this explicitly instead for deterministic code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10 15:57:39 -08:00
Berthold Stoeger
72427adc1c profile: remove AbstractProfilePolygonItem::settingsChanged()
settingsChanged() is a virtual function, which is called
when the preferences dialog signals changes. In most derived
classes, the function does nothing.

In two classes, DiveProfileItem and DiveCalculatedTissue, it
replots the item respectively changes its visibility.

However, these two flags are *not* controlled by the preferences
dialog. Indeed, the functions are also connected to finer-grained
qPref signals. Therefore, settingsChanged() can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10 15:57:39 -08:00
Berthold Stoeger
3f100fda0a profile: initialize axis of DiveProfileItems on construction
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10 15:57:39 -08:00
Berthold Stoeger
ea88f4729d profile: set model of profile items on construction
The profile items had a "setModel()" function to set
the DivePlotDataModel post creation. The model is never
changed. It does however mean that the model might be
null in a short period between construction and setting
the model.

To simplify reasoning about this code, set the model
in the constructor. To drive the point home that the
can never change and cannot be null, turn it into a
reference.

Yes, this is gratuitous bike-shedding, but it helps
me analysis the code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10 15:57:39 -08:00
Berthold Stoeger
975c123a30 profile: remove redundant code in DiveCalculatedCeiling
The DiveCalculatedCeiling profile-item has a recalc()
function, which calls "dataModel->calculateDecompression()".
This is a questionable reversal of control-flow: The
profile-item should paint the model-data not change it.

The code was supposed to be called under two conditions:

1) The value of the calcceiling3m preferences flag changed.
   This code was buggy for two reasons: Firstly, the cached
   value was always initialized to false, which means that
   sometimes the first call was missed. Secondly, the
   settingsChanged() functions was only called when closing
   the preferences window, not when changing the flag in the
   profile widgets.

2) The datetime of the dive changed. The whole control-flow is
   pretty absurd (due to "bit rot"):
     - The replan-dive command sends a date-time changed signal.
     - The main tab changes the date-time and informs the profile.
     - The profile sends a signal to the item.
     - The item instructs the model to recalculate the
       decompression.
     - The model causes the profile to be redrawn.

In any case, the whole thing is moot, because the decompression
is recalculated for *every* profile plot in create_plot_info_new().

Let's remove the code from the DiveCalculatedCeiling profile-item
and the calculateDecompression() function, which is now not
used anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10 15:57:39 -08:00
Berthold Stoeger
ebb342c969 cleanup: turn protected into private members
Some profilewidget classes hat protected members which can
be made private as there is no subclassing.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-13 17:18:37 -07:00
Berthold Stoeger
574065b314 Cleanup: reinstate override modifiers
This reverts commit 1c4a859c8d,
where the override modifiers were removed owing to the noisy
"inconsistent override modifiers" which is default-on in clang.

This warning was disabled in 77577f717f,
so we can reinstate the overrides.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-29 15:23:25 -07:00
Berthold Stoeger
db57a633d5 Cleanup: constify threshold pointers in DiveProfileItem
These were pointers into the global prefs object. The user must
not use these to modify the settings, therefore make them
pointers-to-const.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-07 11:03:30 -07:00
Berthold Stoeger
1c4a859c8d Cleanup: remove all override modifiers
Commit df156a56c0 replaced "virtual"
by "override" where appropriate. Unfortunately, this had the
unintended consequence of producing numerous clang warnings. If
clang finds a override-modified function in a class definition,
it warns for *all* overriden virtual functions without the override
modifier.

To solve this, go the easy route and remove all overrides. At least
it is consistent.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-01 06:30:00 -07:00
Berthold Stoeger
df156a56c0 Cleanup: replace virtual by override where appropriate
The keyword "virtual" signalizes that the function is virtual,
i.e. the function of the derived class is called, even if the
call is on the parent class.

It is not necessary to repeat the "virtual" keyword in derived
classes. To highlight derived virtual functions, the keyword
"override" should be used instead. It results in a hard compile-
error, if no function is overridden, thus avoiding subtle bugs.

Replace "virtual" by "override" where appropriate. Moreover,
replace Q_DECL_OVERRIDE by override, since we require reasonably
recent compilers anyway. Likewise, replace /* reimp */ by
"override" for consistency and compiler support.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-31 11:02:34 +02:00
Berthold Stoeger
14e6c132c8 Typo: Threshould -> Threshold
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-10 21:25:02 +01:00
Dirk Hohndel
49d0bb8406 Add SPDX header to profile widgets
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29 13:32:55 -07:00
Jan Mulder
5a235aea12 minimal pO2 threshold: color the p02 graph also for minumum
Color the p02 graph also in red for going under the minumum p02 value as
set in the Preferences.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-03-28 11:17:03 -07:00
Rick Walsh
fd46167ae0 Heatmap: Color undersaturated values relative to inert gas pressure
Color "undersaturated" values relative to inert gas pressure of gas being
breathed, rather than relative to inert gas pressure of air.
Also change slightly the point at which bright green (hue = 120 deg) from 10%
of M value to 0% of M value (=ambient pressure).
Other than the slight shift in lower bound of the green-red scale, this does
not affect the colors of the tissues with inert gas pressure greater than
ambient pressure, which are relative to the Buhlmann M value.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-10-20 21:14:19 -07:00
Dirk Hohndel
0296a456b2 Hook up the code to toggle DC reported ceiling visibility
This got broken a long time ago it seems and no one ever noticed.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-24 12:38:24 -07:00
Robert C. Helling
1b57b6cc17 Separate method for heatmap color scaling
I separated out the color scaling and slightly simplified the expressions.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-17 13:42:46 -07:00
Robert C. Helling
893bea700c Introduce heat map
This replaces the tissue percentage graph that probably nobody ever
understood with a heat map like the one used in the discussion
of bubble model deco. The information shown is the same but the
saturation is now in the color while the tissue determines the y
position.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-17 13:39:54 -07:00
Tomaz Canabrava
7433396333 Fix Ceiling Graph
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-01-25 13:04:32 -08:00
Tomaz Canabrava
2d3f7f0a90 More Profile Itens on the new Settings
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-01-25 13:04:21 -08:00
Tomaz Canabrava
2d96139566 Changed quite a few shorts to bool on the c++ implementtion
The shorts where being used on the preferences since a long
while and we cannot just simply change them to bool since this
could break the preferences files, so work around that by
changing them to booleans, since it's the correct type for a
true / false answer.

Also, move some plot curves to the new settings style

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-01-25 13:04:16 -08:00
Lubomir I. Ivanov
8e7be1b50a Untangle DiveCalculatedCeiling from MainWindow
DiveCalculatedCeiling is the last class the references
MainWindow in the profile-widget stack.

In modelDataChanged() it looks for the information()
widget and sets a slot for the dateTimeChanged() signal that
information() emits.

To solve the issue we make DiveCalculatedCeiling recieve
a ProfileWidget2 reference and make ProfileWidget2 emit
the dateTimeChangedItems() signal.

ProfileWidget2 itself listens for the dateTimeChanged()
signal that information() emits and emits dateTimeChangedItems()
to notify any possible children/item listeners in the
ProfileWidget2::dateTimeChanged() slot.

The connection between ProfileWidget2 and information()
is set in MainWindow. This makes DiveCalculatedCeiling
unaware of MainWindow and which class originally emits
the dateTimeChanged() signal to ProfileWidget2.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
--
Think delegation.

Tomaz, please take a look at this one, to double check
if i messed up.

also i have zero idea how the mobile app is setting these
connections, if it does so even.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-11-06 09:58:34 -08:00
Tomaz Canabrava
1d6683f3e0 Move Profile widget out of desktop-widgets
The reason for that is, even if profile widget is made with qpainter
and for that reason it should be a desktop widget, it's being used
on the mobile version because of a lack of QML plotting library that
is fast and reliable.

We discovered that it was faster just to encapsulate our Profile in
a QML class and call it directly.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-30 10:36:49 -07:00
Renamed from desktop-widgets/profile/diveprofileitem.h (Browse further)