In a recent commit, the profile widget was changed to reuse
DivePictureItems. This made toggling of picture-visibility
disfunctional, because the visibility was set in the constructor.
Only on change of dive would the setting take effect.
Therefore, move the setting of the visibility up to the
ProfileWidget2::plotPictures() call. This is more consistent
anyway, since at this level pixmap and fileUrl are set.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
Make the behavior of the profile-pictures consistent with the pictures
in the photos-tab: Use the local file path to open the picture in the
system viewer instead of the canonical filename (which might point to
a non-existing location).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The former should be translated but not those that
go to xml/git.
... and fix capitalization of pSCR.
Suggested-by: Stefan Fuchs <sfuchs@gmx.de>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Reactivate printMode true for ssrf-mobile to avoid font problems,
do not discard events if ssrf-mobile (even though printMode is true)
Signed-off-by: Jan Iversen <jani@apache.org>
On deletion of a single or multiple pictures, the whole DivePictureModel
was repopulated, which was clearly visible in the UI, owing to the
reconstructing of all images in the profile plot.
To avoid this vexing behavior, implement proper deletion routines in
DivePictureModel and ProfileWidget2. Since this needs sensible erase()
semantics the QList<PictureEntry> member of DivePictureModel was
replaced by a QVector. A QVector should be the default anyway, unless
there are very specific reasons to use a QList (which actually is
a deque, not a classical linked list).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The function removePicture() had a flag "last", which would indicate
that the called had finished removing pictures. Only then would
the model be recalculated.
This is a strange interface and, matter of fact, the caller was buggy:
if the last picture to be removed didn't have a proper url, removePicture()
was never called with "last" being set.
Change the interface to take a list of pictures to be deleted. This
will allow us to make picture deletion smarter in follow-up commits.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In the old code a combination of removeRows()/insertRows() was used
to signal a model reset.
Replace this by a single, modelReset signal. This saves a call to
plotPictures() and will allow us to be smarter in the future,
when removing pictures.
Reset-model and remove-items are semantically different.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
1) Fix the English of a comment.
2) Remove a number of int-to-double compares:
Make "steps" an integer variable (the number of steps).
Rename the old double "steps" variable to "stepsInRange". This gives
a non-integer number of steps and is necessary to calculate the
correct step size
3) Replace a "x = x/y" by a "x /= y" construct.
4) Remove an unnecessary if clause.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
If animDelete() was called with prefs.animation_speed == 0, the
object would not be marked for deletion, as opposed to calling
with prefs.animation_speed != 0. This would leak the objects.
Therefore delete the objects if called with prefs.animation_speed == 0.
The caller doesn't keep a reference to the objects. Therefore,
a plain delete is fine, as opposed to a deleteLater().
While touching this function, use the function-pointer version
of connect().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In MainWindow::current_dive_changed() first plotDive() is called,
which replots all the pictures by calling plotPictures(). This
is pointess, because it plots the pictures of the previous dive.
Then, updateDiveInfo() is called, which resets the dive pictures
and automatically replots them. Thus, switching between dives
both with hundreds of pictures is way slower than necessary.
Switching the plotDive() and updateDiveInfo() calls doesn't work.
The reason is not 100% clear, but it doesn't make sense to plot
pictures of the new dive as long as the profile still shows the
old dive anyway.
As a quick-fix, add a flag to plotDive(), which tells the function
to clear the pictures list instead of redrawing it.
Ultimately, plotDive() should probably be split in two functions.
One for the callers who update the pictures themselves and one
for the others.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The recent simplification of the close button code introduced a crash:
Deletion of pictures caused an invalid memory access, because the
CloseButtonItem was deleted with the parent DivePicture item.
For some (not fully understood!) reason, a reference to this button
was stored in the depths of Qt.
Empirically, it was found out that removing the first line of the pair
QGraphicsItem::mousePressEvent(event);
emit clicked();
fixed the crash.
It seemed therefore prudent to remove the whole questionable signal/slot
mechanism and directly call the removePicture() function of the parent.
Thus, the intermediate DiveButtonItem class became unnecessary and was
removed, leading to a shallower class hierarchy.
Unfortunately, CloseButtonItem must still be derived from QObject owing
to the Q_PROPERTY machinery, which is in turn needed for animation.
To make this compile on mobile, the conditional compilation of
removePicture() (#ifndef SUBSURFACE_MOBILE) was removed. After all,
if DivePixmapItem is used, there are pictures, so removePicture()
should be functional. Conditional compilation should concern the
whole class, not only this function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
...as the usuage is not anymore about a computer but
a momentary dive mode. Rename the end indicator as well.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
The dive profile context menu gets rather long with three
additional divome switches that can be selected. This is now changed
so that the additional options are only shown when in CCR
or in PSCR divemode.
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
This provides for reading of divemode change events from dive logs
and for writing them to dive logs. This applies to xml and git
divelogs. Divemode change events have the following structure:
event->name = "modechange"
event->value = integer corresponding to enum dive_comp_type (dive.c),
reflecting the type of divemode change (OC, CCR, PSCR, etc).
In the dive log file, the event value is written as a string that
corresponds to each of the enum values, e.g.
<event name='modechange' divemode='OC' />
This xml is also read from the dive log file and translated to an
appropriate value of event->value.
The file diveeventitem.cpp was udated to reflect this new way of
dealing with divemode change events.
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
In the old code, we used to reload the whole picture list on drag & drop
to the profile. Instead, only update the drag&dropped picture and repaint
the profile-pictures.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
One close-button object was used for all dive pictures. This seems
like a brittle premature optimization and the pixmap is shared
anyway. Make the button a subobject of the dive picture object.
Change the object-hierarchy to be based on QGraphicsItem instead
of QObject. The QObject here is only used as a kludge to support
signals and properties (the latter are necessary for animations).
Remove a comment, which does not seem to be relevant after this
change.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
1) The connection for the display of CCR-setpoint o2SetpointGasItem
was erroneous, being connected to partialpressuregasSettings. It
is now correctly connected to technicalDetailsSettings.
2) The colour of the setpoint graph is changed from PO2_ALERT (red) to
an orange colour in order to show setpoint in red only when it
exceeds 1.6. This emphasises the visibility of red parts of the
gas pressure graphs whenever gas limits are exceeed.
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
fake_dc() used to return a statically allocated dc with statically
allocated samples. This is of course a questionable practice in
the light of multi-threading / resource ownership. Once these
problems were recognized, the parameter "alloc" was added. If set
to true, the function would still return a statically allocated
dc, but heap-allocated samples, which could then be copied in
a different dc.
All in all an ownership nightmare and a recipie for disaster.
The returned static dc was only used as a pointer to the samples
anyway. There are four callers of fake_dc() and they all have access
to a dc-structure without samples. Therefore, change the semantics
of fake_dc() to fill out the passed in dc. If the caller does
not care about the samples, it can simply reset the sample number
to zero after work.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
If there is no current dive, the macro current_dc returns NULL.
This led to a null-pointer dereference.
Reported-by: Martin Měřinský <mermar@centrum.cz>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit allows plotting the OC-equivalent pO2 graph for PSCR
dives. This happens in both the cases where there is no external
O2-monitoring AND when there is external pO2 monitoring. The
calculations are only done for PSCR dives and is achieved as
follows:
1) Within plot-info create a pressure-t called OC_pO2 in
profile.h and populate this variable with the open-circuit
pO2 values in profile.c.
2) Create a new partialPressureGasItem ocpo2GasItem in
profilewidget2.h and, in profilewidget2.cpp, initialise it
to read the plot-info OC_pO2 values and enable its
display by using the setVisible method. The
diveplotdatamodel was also touched in order to achieve
this.
3) Create a pref button that controls the display of OC-pO2 for SCR dives
4) Change the colour of the OC-pO2 grpah to orange
5) Change the connection of the crr_OC_pO2 signal to be appropriate
6) rename the OC_pO2 attribute to scr_OC-pO2
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Only update those pictures of the DivePictureModel that actually changed.
This will be useful once pictures are loaded incrementally.
To do so, replace the pictures array by an array with stable ids. Before
this commit, not-shown pictures are left out of the pictures array, which
makes the mapping from DivePictureModel-ids to the picture array index
non-trivial.
Replace the QList<DivePictureItem *> by a std::vector<std::unique_ptr<DivePictureItem>>
to ease memory management. Sadly, owing to COW semantics, QVector is incompatible
with QScopedPointer.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Correct a bug in finding the minimum heartrate.
Use the minimum and maximum heartrate value to set min/max and
tic distance for the heartrate axis in the profile.
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
Replace constructs of the kind
s.toUtf8().data(),
s.toUtf8().constData(),
s.toLocal8Bit().data(),
s.toLocal8Bit.constData() or
qUtf8Printable(s)
by
qPrintable(s).
This is concise, consistent and - in principle - more performant than
the .data() versions.
Sadly, owing to a suboptimal implementation, qPrintable(s) currently
is a pessimization compared to s.toUtf8().data(). A fix is scheduled for
new Qt versions: https://codereview.qt-project.org/#/c/221331/
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This changes the numeric format of many values printed to the UI to
reflect the correct numeric format of the selected locale:
- dot or comma as decimal separator
- comma or dot as thousands separator
In the Qt domain the `L` flag is used case specific mostly
in qthelper.cpp.
Then the helper functions get_xxx_string() are used more consistently.
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
Use struct temperature_t for temperatures in struct stats_t and
use get_temperature_string() when printing these temperatures for
statistics and HTML export.
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
Bring one more value plus unit pair which is the pressure value printed
in the profile in accordance with the coding style/UI style rule of
not having a space between value and unit.
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
Mostly replace "return (expression);" by "return expression;" and one
case of "function((parameter))" by "function(parameter)".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The settingsChanged() function of the profile widget tries to be
clever and tries to prevent not needed replots of the profile.
I'm not sure this is very relevant in the first place as change
of settings are almost instantly, with or without replot. It
appears that replot is always executed when there are
calculated ceilings visible. But without calculated ceilings
a replot is "optimized out". This does, however, introduce dangling
divehandles in PLAN/EDIT and ADD mode of the profile, when
any setting that influences the y-axis is changed.
The fix is trivial. Just force a replot in the PLAN/EDIT and ADD
modes.
Fixes: #1070
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
The gas fractions (in %) are now printed at a resolution of 0.1%
and not at 0.01% as previously.
The string in the info box that provides icd data is reformatted
so that the info-box is as narrow as possible.
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
The reason for this issue, and fix for this is very similar
to commit b4d37e8ee. Just set both recalculate flags on a mouse
release event, so that the cylinder pressure line is recalculated.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Change the format from (example!)
ICD: ΔHe=-34% ΔN₂=3%<3%
to
ICD: ΔHe=-34% ΔN₂=+3%<+2.8%
Change strings given to translation to less complex ones.
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
as otherwise there are warning on the descent.
The ICD line in the info box is generated for all
gas switches with decreasing He content.
Also change the presentation in the info box to align it
with the notes.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Add an exclamation mark in the gas change icons if
the change violates our isobaric counter diffusion
criterium.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
See mentioned GitHub issue for the full issue, and images.
The reason for this weird behavior is the existence of 2 flags in
the profile code: shouldCalculateMaxTime and shouldCalculateMaxDepth.
When exactly following the use case and test data as attached to
the GitHub issue (a very short dive, shorter than most of the
dives in the logbook), the shouldCalculateMaxTime flag never got
back to its true status, causing the the time scale not to adapt
to other dives when just clicking (or selecting) them from the dive
list.
The problem is fixed here by also setting the shouldCalculateMaxTime
flag on manipulating wayppoints in the dive plan.
Fixes: #1039
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
There are ca. 50 constructs of the kind
same_string(s, "")
to test for empty or null strings. Replace them by the new helper
function empty_string().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Move divepicturemodel.cpp to the desktop only category and deal
with the (limited) fallout. We, currently, do not support dive
pictures tied to the profile on mobile, so there is no use
including this code.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>