Commit graph

72 commits

Author SHA1 Message Date
Berthold Stoeger
6ad7e577f1 core: pass event to event_type functions
Instead of passing name / flag pairs to event_type functions,
pass a pointer to the event. This hides implementation details.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-02-23 09:46:16 -08:00
Berthold Stoeger
d3c9cb14bf core: rename eventname.* to eventtype.*
This structure is used to hide events of a certain type.
The type was inferred from its name, but now includes flags.
So event_type is more appropriate.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-02-23 09:46:16 -08:00
Michael Keller
1309064873 Profile: Reinstate Hiding of Events by Type across Dives.
Reinstate the hiding of events by event type across
all dives in the log. This was unintentionally removed in #3948.
Also change the event type to be specific to name and severity, and fix
bug causing 'Unhide all events' to not show when only individual events
were hidden.

This still leaves the inconsistency that hiding of similar events is
persisted across the switch between dives, but hiding of individual
events is lost when switching dives, which is mildly confusing.

Follow-up to #4092.

Signed-off-by: Michael Keller <github@ike.ch>
2024-02-12 12:27:59 +01:00
Berthold Stoeger
0d3c9954f4 profile: redo eventname handling
The eventname handling code was splattered all over the place.
Collect it in a single source file and use C++ idioms to avoid
nasty memory management. Provide a C-only interface, however.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-02-17 06:46:46 -08:00
Robert C. Helling
77a5ca4234 For warnings, show icon in infobox
Render a warning sign in front of the event string
in the infobox. This is done in rich text.

Note: This shows the warning sign for all events,
not just warnings.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2022-09-12 19:30:31 +02:00
Berthold Stoeger
1a429d9b17 profile: don't plot event-icons outside of range
Do this by extending the isInteresting() function for
dive event items.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
b0faf2e4b1 profile: remove DiveCartesianAxis::sizeChanged() signal
This was used to animate the position of the dive event items
when the size of the axis changed. However, that doesn't work
since quite some time. The axes size are changed when
 1) switching dives
 2) resizing the drawing area
In the first case, the dive event items are fully recalculated.
In the second case, animation speed is set to instant, since
resizing of windows is done continuously on any reasonably
modern desktop anyway. It might make sense on mobile, where
size changes are discontinuous, but there we use static
profiles anyway. Moreover, I checked a few applications and
none of them had animations when switching orientation of
my tablet.

Let's just remove this disfunctional thing and replace it
later, should someone complain.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
9c7974928b profile: indicate bookmark by pole of flag
The event-icons are positioned according to the top-left
corner (as is usual in computer circles). For the flag
icon it seems more natural to use the bottom of the pole.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
9740651e01 profile: save depth of event
The DivePlotDataModel was saved with every event to access the
depth. However, since the depth never changes, we can simply
save the depth instead.

Also, since we only need the model to access the plot_info,
pass the plot_info directly. As noted in a previous commit
message, I believe that Qt models are a very bad choice
for intra-application data transfer. They should only ever
be used to interface with Qt.

And since touching this code, pass duration_t instead of int
to depthAtTime() to make the callers less cluttered.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
9ddaf791ae profile: use binary search to find depth at event
Instead of looping over the whole data via the Qt model,
do a simple binary search. Yes, this is premature optimization,
but I had to.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
8d4d35ea69 profile: remove redundant timestamp lookup for DiveEventItems
When placing the event icons, the timestamp is looked up and
then, the depth is checked which repeats this operation.
Remove the first instance of this lookup, as it is completely
redundant.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
8a9ca5fcda profile: don't create "uninteresting" event icons
There is code to dynamically show/hide event icons of a certain
type. The same code is used to hide generally non-interesting/
redundant items.

Instead, don't even create these items. Yes, this is idle
premature optimization.

A loop over all created event icons to hide them can be
removed, because the icon is hidden anyway on construction
time.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
f82ae2be7f profile: cache pixmaps for dive event items
For better scalability, we might replace the dive event icons
by SVGs. Since rendering SVGs is potentially very slow, cache
the pixmaps when the scene is generated.

Note: this does not yet do any SVG rendering, only the caching
of pixmaps.

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
69914964f6 cleanup: replace membuffer by qasprintf_loc()
There is a function to format QString with C-format strings. Let's
use it instead of doing a detour via membuffer.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-07-23 11:22:43 -07:00
Dirk Hohndel
235ee4803f printing: remote incorrect scaling of event icons
It appears that this well intended change in commit 52aa7d83b6 ("Increase event
icon size in print mode") actually causes the scaling of the event icons to be
generally wrong. This removes the hard 4* scaling and also adds some debugging
output in verbose mode.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-07-11 13:02:43 -07:00
Berthold Stoeger
65580fceda profile: scale dive event items according to font print scale
When printing with low DPI, the dive event items become comically
large, because they are not resized like the fonts. Therefore,
scale using the fontPrintScale.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-07-04 11:51:17 -07:00
Berthold Stoeger
0b190243dd profile: remove internal event-copy (fix deleting/renaming events)
The DiveEventItem had an internal copy of the event. It passed
that copy to the undo-machinery, which of course didn't work.

Simply keep a pointer to the event. All changes to a dive no
pass via the undo-machinery, which causes a reload of the profile,
so this should be safe.

Reported-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-06-05 11:29:00 -07:00
Berthold Stoeger
fd2862042b profile: pass axes and model to DiveEventItem on construction
Firstly, there is no point in supporting DiveEventItems without
model and axis. Secondly, this avoid pointless position-
recalculations.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-06-05 11:29:00 -07:00
Berthold Stoeger
c93fb83edf profile: pass event at construction time to DiveEventItem
There is no point in having a dive event without an event.
Let's pass the event at construction time to avoid having
to handle "invalid" events.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-06-05 11:29:00 -07:00
Berthold Stoeger
3fcac9022c profile: initialize DiveEventItem::dive to null
To simplify debugging, this should be initialized. Found by coverity.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-03-05 08:30:23 +01:00
Berthold Stoeger
be9f9efb0e profile: pass dive to EventItem
Don't access the global displayed_dive variable in an effort
to make the profile reentrant.

Note that this still accesses the global dc_number variable,
which will likely have to be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10 15:57:39 -08:00
Berthold Stoeger
0e196310f9 cleanup: split out divecomputer functions from dive.c
Since dive.c is so huge, split out divecomputer-related functions
into divecomputer.[c|h], sample.[c|h] and extradata.[c|h].

This does not give huge compile time improvements, since
struct dive contains a struct divecomputer and therefore
dive.h has to include divecomputer.h. However, it make things
distinctly more clear.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:52 -07:00
Berthold Stoeger
8212acc992 cleanup: break out event-related code into event.[c|h]
In an effort to reduce the size of dive.h and dive.c, break out
the event related functions. Moreover event-names were handled
by the profile-code, collect that also in the new source files.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:52 -07:00
Berthold Stoeger
f4b948e80d profile: properly update lastgasmix when populating events
When populating the events of a profile, a pointer to the current
gasmix was passed around to properly calculate isobaric_counterdiffusion.
The DiveEventItem::setupToolTipString() function updated this gasmix
when processing gas change events.

I inadvertently broke the code when replacing gasmix-pointers by
values. We could of course simply revert this part of the commit.
However, the data flow was horrible anyway: for example is supposed
that the setup functions were called in the correct order (i.e.
DiveEventItem::setupToolTipString() is called after all other
functions using the gasmix). Not exactly easy to follow.

Therefore, keep passing around the gasmix as value to make it clear
that the functions don't modify it. Keep the gasmix up-to-date at
the caller's site in ProfileWidget2::plotDive().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 21:44:50 +02:00
Berthold Stoeger
0c28821d28 cleanup: replace Q_ASSERT by qWarning
These two Q_ASSERTs made no sense - their expression (a string
literal) always evaluated to true. A qWarning() was intended here.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-30 16:55:19 -07:00
Berthold Stoeger
2d9dc40171 Profile: add speed parameter to Animation::* functions
For now always use the preferences value, so that this is a
no-op. This is a preparation for storing the speed in the
profile widget.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-12 09:59:28 +02:00
Berthold Stoeger
74244b3cfe Profile: take int instead of bool in DiveEventItem::recalculatePos
The goal here is to slowly make animation speed a variable of the
profile widget, not of the global preferences. Currently the code
does some trickeries with setting / unsetting the global animation
speed.

Start by not taking a bool "instant" but a speed in
DiveEventItem::recalculatePos().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-12 09:59:28 +02:00
Robert C. Helling
5e494ce761 Show a bit of surface degassing in the planner
to display the deco parameters at the surface,
in particular tissue saturation and heat map.

Suggeted-by: Matthias Heinrichs <info@heinrichsweikamp.com>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-03-29 06:51:12 -07: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
f5b11daffd Cleanup: return gasmix by value
Currently, get_gasmix_from_event() and get_gasmix() return pointers
to either static or to (possibly changing) dive data. This seems like
a dangerous practice and the returned data should be used immediately.

Instead, return the gasmix by value. This is in preparation of
const-ifying input parameters of a number of core functions, which
will ultimately let the merge() function take const-arguments in
preparation of undo of dive-merging.

On common 64-bit systems gasmix (two "int"s) is the size of a pointer
and can be returned in a register.

On 32-bit systems a pointer to the struct to be filled out will be
passed.

Since get_gasmix() now returns a value, the first invocation is
tested by a NULL-initialized "struct event *". Document this in
a comment.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23 05:16:38 -07: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
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
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
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
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
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
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
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
b5ce06c8b9 Free various struct membuffer in different functions
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-02 11:29:55 -08:00
Willem Ferguson
b9ac89574e Planner: print icd information at 0.1 resolution
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>
2018-01-24 22:03:42 +01:00
Stefan Fuchs
d5cb30efac Profile info box ICD: Change format of ICD string
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>
2018-01-21 18:01:56 +01:00
Robert C. Helling
c89cfcccbe Only give ICD warning if pN2 increases
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>
2018-01-21 15:24:46 +01:00
Robert C. Helling
d029feb2d5 Show ICD in gaschange icons
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>
2018-01-21 15:24:46 +01:00
Robert C. Helling
7b508e41cd Show ICD events data in infobox
If a gas switch violates our ICD criteria, show
this in the info box.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-01-21 15:24:46 +01:00
Berthold Stoeger
e85ecdd925 Introduce helper function empty_string()
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>
2018-01-11 06:07:13 +01:00
Martin Měřinský
8ef87e618a Use better aliases for icons.
Icon aliases were complete mess.
Some icons had alias some didn't.
Named with underscores vs. hyphens vs. camelCase.
Lower vs. upper case.
"ICON" prefix vs. suffix vs. nothing.
With vs. without filename suffix.
Some didn't make sence. Eg. mapwidget-marker-gray
(I can see, it's grey, but what does it represent?)
Some were duplicated, eg warning vs. warning-icon.
Some were name after widget, which is wrong.

Do not reinvent wheel. Use widely used naming scheme
close to Freedesktop Icon Naming Specification. This
will enable usage of common icons from current set in
the future. Thus Subsurface will fit nicely to GUI.

This changes icon aliases to one, easy grep-able style.

Signed-off-by: Martin Měřinský <mermar@centrum.cz>
2017-11-30 23:14:46 -08:00