Commit graph

223 commits

Author SHA1 Message Date
Robert C. Helling
c64e4b159f Copy divemode to Replan
this needs copying the divemode from the dive to the plan.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-06-24 09:35:55 +02:00
Stefan Fuchs
c953aadcf8 Change from gettextFromC::instance()->tr() to gettextFromC::tr();
Code cleanup.

Suggested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-06-18 07:42:39 +02:00
Stefan Fuchs
88e6ba2f61 Use correct "tr" call for translating dive mode names
Correctly use gettextFromC::instance()->tr(); instead of a simple
tr(); to translate the dive mode names.
This goes on top of 0bc9edf855
and finally makes the whole thing work.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-06-18 07:42:39 +02:00
Stefan Fuchs
0bc9edf855 Fix an error around translation of dive modes in the UI
This fixes an mistake introduced in
3d1072f886

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-06-17 06:36:20 +09:00
Stefan Fuchs
4ccc4d7329 Enable translation for even name "modechange"
Enable translations for dive event name "modechange".
But clearly don't do this for the string which is used internally
but only push "modechange" to the translation system to be able to
translate it in the UI.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-06-17 06:36:20 +09:00
Stefan Fuchs
632e6bb7c7 Remove a useless translation in diveeventitem.cpp
Giving the string ": %1" to translation makes no sense.
And it's also not consistent with code a few lines below this line.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-06-17 06:36:20 +09:00
Stefan Fuchs
c734a77cf5 Code cleanup: Correct typo "Swith" to "Switch"
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-06-17 06:36:20 +09:00
jan Iversen
aab8f0dcf6 profile: make profile self contained
move qmlprofile.* to profile dir, to keep all parts of the
widget in one place.

Signed-off-by: Jan Iversen <jani@apache.org>
2018-06-09 17:16:53 +02:00
jan Iversen
cade4829a3 profile: clean double calls on mobile version
Expanded #ifdef MOBILE with #else so that settings
are only called once.

Signed-off-by: Jan Iversen <jani@apache.org>
2018-06-09 17:16:53 +02:00
Berthold Stoeger
9293268027 Dive picture: fix toggling of picture-visibility
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>
2018-06-04 10:28:08 -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
Berthold Stoeger
9d73b66024 Profile: open pictures using local file path
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>
2018-06-04 07:44:32 +02:00
jan Iversen
3963e44404 desktop: use QElapsedTimer to measure time
QElapsedTimer is the preferred timer for measuring time
so lets use it.

Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-29 12:48:32 -07:00
Robert C. Helling
7c6e5ed5db Distinguish between user and internal divemode names
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>
2018-05-28 09:57:00 +02:00
jan Iversen
86ab5a91f7 profile-widget: set printmode but allow events for ssrf-mobile
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>
2018-05-24 12:04:14 -07:00
jan Iversen
ce800310a4 profile-widget: replace (void) with no parameter name
Unused parameters in C++ are "silenced" by removing the name.

Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-24 08:34:14 -07:00
jan Iversen
065af62f59 profile-widget: Change Q_UNUSED to no parameter name
C++ permits use of parameters without name, which signals unused

Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-21 12:48:04 -07:00
Berthold Stoeger
f47f2773fd Dive pictures: don't repopulate DivePictureModel on deletion
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>
2018-05-21 22:17:28 +03:00
Berthold Stoeger
3c0c1801cd Dive pictures: change removePicture() interface
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>
2018-05-21 22:17:28 +03:00
Berthold Stoeger
fbe1144eaf Dive pictures: use modelReset signal when reseting picture list
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>
2018-05-21 22:17:28 +03:00
jan Iversen
37ac354291 profile-widget: divepixmapitem.cpp, silence unused parameter
remove parameter name for not used parameter, to silence
unused warning.

Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-21 07:31:16 -07:00
jan Iversen
158be64883 profile-widget: profilewidget2.cpp, silence unused parameter
Add Q_UNUSED for not used parameter

Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-21 07:31:16 -07:00
Berthold Stoeger
7836a78dca Profile: minor coding style issues concerning axis-ticks
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>
2018-05-19 07:48:28 -07:00
Berthold Stoeger
555f2f9565 Profile: Fix leak in animation
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>
2018-05-19 07:48:28 -07:00
Berthold Stoeger
45395fd466 Dive pictures: Don't plot pictures twice when changing current dive
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>
2018-05-17 07:24:54 -07:00
Berthold Stoeger
f54268e527 Dive pictures: Fix crash on picture delete
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>
2018-05-17 07:22:04 -07:00
Robert C. Helling
969dfee9ec Rename enum dive_comp_type to divemode_t
...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>
2018-05-14 23:47:00 +03:00
Robert C. Helling
6b0ecb012d Place divemode changes in submenu of context menu
Also unify the repeated code in slots.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-05-14 23:47:00 +03:00
Willem Ferguson
718f9811b7 Show divemode swith options only for rebreather dives
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>
2018-05-14 23:47:00 +03:00
Willem Ferguson
e46cb2f800 Create divemode switches using profile context menu
Allow the manual creation of divemode switch events using the
profile context menu.

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-05-14 23:47:00 +03:00
Willem Ferguson
b9174332d5 Read and write divemode changes (xml and git)
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>
2018-05-14 23:47:00 +03:00
Willem Ferguson
5f95c226ef Provide icons for bailout events on the dive profile.
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-05-14 23:47:00 +03: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
Dirk Hohndel
d577467f97 Core: introduce new subsurface-string header
First small step to shrinking dive.h.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-14 10:13:39 -07:00
Berthold Stoeger
c71a5d7413 Dive pictures: Don't update all pictures on drag & drop to profile
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>
2018-05-13 13:52:35 -07:00
Berthold Stoeger
630862971f Dive pictures: remove close-button optimization
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>
2018-05-13 13:52:35 -07:00
Willem Ferguson
70bb4c145b Fix CCR setpoint display bug
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>
2018-05-07 13:56:23 +02:00
Berthold Stoeger
920ff15f71 Planner: don't return static data in fake_dc()
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>
2018-05-07 13:11:53 +03:00
Berthold Stoeger
fb84b11854 Profile: Fix crash on addition of dive to fresh logbook
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>
2018-05-03 02:14:03 +03:00
Willem Ferguson
81a812539c Plot OC-pO2 graph for SCR dives
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>
2018-04-28 20:11:22 +03:00
Berthold Stoeger
36249f2780 Profile: Conditionally compile pictures-vector on mobile.
This vector is not used on mobile and cause iOS compilation to fail.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-09 11:29:14 -07:00
Berthold Stoeger
f1830cd44e Profile: On dataChanged() only update pictures that actually changed
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>
2018-04-09 07:50:21 -07:00
Stefan Fuchs
b38eb45b29 Profile heartrate: Nicer min/max values and tic distance
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>
2018-03-19 15:44:02 -07:00
Berthold Stoeger
b72cc1f317 Cleanup: consistently use qPrintable()
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>
2018-03-14 13:55:36 +02:00
Stefan Fuchs
aacc688670 Use correct numeric format based on selected locale (Qt domain part)
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>
2018-03-05 16:28:18 +01:00
Stefan Fuchs
95a23cf470 Use temperature_t for temperatures in struct stats_t
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>
2018-02-24 11:45:17 -08:00
Stefan Fuchs
a7372d9340 Remove space between pressure value and pressure unit in profile
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>
2018-02-22 21:48:05 +02:00
Berthold Stoeger
5c248d91cd Coding-style: remove superfluous parentheses
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>
2018-02-17 19:38:52 -08:00
Stefan Fuchs
b5ce06c8b9 Free various struct membuffer in different functions
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-02 11:29:55 -08:00
Jan Mulder
20dc6a31f4 profile: replot handles while planning
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>
2018-01-31 14:48:31 +01:00