Commit graph

515 commits

Author SHA1 Message Date
Berthold Stoeger
abadbb6783 profile: add DiveCartesianAxis::height()
This is needed to properly layout the axes.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
15f20961c7 profile: render DiveTextItem onto a pixmap
The DiveTextItems were redrawn on every paint() call. This was
a prohibitively expensive operation (converting the text into
a path, drawing an outline, etc.), which was called numerous
times.

Instead, render the text only when changing into a QPixmap
and blit that pixmap in the paint() call.

This will make it possible to do absolutely positioned
DiveTextItems. So far they were placed relatively in
scene coordinates ranging from 0-100(!).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
04e0d96bae profile: set text and brush of DiveTextItem concurrently
The text and the brush are the two properties of text items
that change dynamically. To avoid complexities concerning
redrawing, set them concurrently instead of in two separate
calls.

Since setting one of the properties requires a full redraw,
there is no performance advantage in setting them individually.

This fixes a theoretical bug: the colors of axis labels were not
updated appropriately. However, it seems like value-dependent
labels weren't used anyway.

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
5540471ce4 profile: remove text related code in DivePercentageItem
This never sets any text.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
8343691a38 profile: add height() member function to DiveTextItem
To layout the profile we need to determine the height
of texts. Add versions for a DiveTextItem and a static
function, which is passed the scale and dpr. The latter
is used to setup items, where we do not necessarily
have a text at creation time (e.g. the tankbar).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
7dd9b65df0 profile: add width() function to DiveCartesian axis
To properly layout the profile we need to know the expected space
required by the vertical axes. In the general case, format the
the text "999". For the partial-pressure-axis, use "0.99".

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
d28f4d5347 profile: don't compile ProfileWidget2 on mobile
Since there (currently) is no interactive widget on mobile, there
is no point in compiling it. This was a bit more complicated than
expected, since there were other source files (divehandler.cpp
and ruleritem.cpp) which reference ProfileWidget2 and therefore
need to be removed. Otherwise, the dreadful MOC produces unresolved
references.

We could now remove all the conditional compiles in
profilewidget2.cpp, but let's keep them for now. We might have
to readd a number of them later, when making the mobile-profile
interactive.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
4fb2cc8267 profile: remove ProfileWidget::setPrintMode()
The print mode is passed on construction, not retroactively.
This function thus became unused.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
51dc5113c2 profile: for printing/mobile access ProfileScene directly
Instead of using the interactive ProfileWidget2, just
use the ProfileScene to render the profile for printing,
export and mobile. One layer (QWidget) less.

This removes all the kludges for handling DPR on mobile.
Thus, the rendering will now be off and have to be fixed
by redoing the scaling code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
84ebd1d67a profile: pass print-mode add construction of ProfileScene
Setting the profile and grayscale mode of the profile via
functions is from a time when the same profile widget was
used for printing and the UI. It is simpler to set the mode
when constructing the object and not deal with changes.

To prepare for this scenario, take the flag at construction
time. This still keeps the callers as-is. These will be
adapted later.

Logically, then the printFlag also has to be set in
DiveCartesianAxis at construction time.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
1327043d6e profile: rectify animSpeed data flow
The cartesian axes use animSpeed to animate changes. Instead
of passing down the value to the respective functions, the
speed was stored in the ProfileScene and the axes would
access it there. Very messy. Let's just pass down the speed.

There still are back-references from the axes to the scene,
notably to place labels "outside" of the scene. Let's try
to remove them later.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
d19b095db1 profile: remove settings-changed slots in DiveCartesianAxis
The profile is fully redrawn anyway, there is no point in these
redundant slots.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
d9dcf9ef37 profile: move non-interactive chart elements to ProfileScene
This finalizes the split between interactive (ProfileWidget2)
and non-interactive (ProfileScene) parts of the profile.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
bf12756819 profile: move printing-related variables to ProfileScene
Since the ProfileScene does the actual rendering, it needs
access to the "printMode", "isGrayScale" and "fontPrintScale"
variables. Move them down from ProfileView to ProfileScene.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
12fd102e4f profile: remove empty state from profile
This was moved to the desktop version. Enter the profile in
the constructor. Somewhat surprisingly, this seems to work.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
9f6e487790 profile: remove redundant parameter in setPrintMode()
Since using separate profile-instances for print/export,
we never exit print mode. Therefore, the mode parameter
can be removed. This is a preparatory commit for passing
the printMode at construction time.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
db726862ae profile: move axes to ProfileScene
Part of separating the static (for printing, export) and
dynamic (UI) parts of the profile. This is still quite messy
with many direct accesses from the ProfileWidget.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
c8b3ac0f99 profile: move initialization code to ProfileScene
A first in a number of commits to move code from the profile
view to the scene.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
15342232ca profile: introduce a ProfileScene stub
This simply subclasses QGraphicsScene and is used as
a drop-in replacement. The plan is to step-by-step
move rendering functions there until the non-interactive
code can only use the scene and doesn't have to use
the QGraphicsView. This will hopefully remove quite
some conditional code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
5a34bdccb5 cleanup: remove redundant ifdef in profile code
Remove a not-mobile #ifdef inside a not-mobile #ifdef.

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
f05cd702b5 profile: remove ProfileWidget2::getFontPrintScale()
The last user was removed recently.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
2caea1cd56 profile: remove ProfileWidget2::setFontPrintScale()
The font print scale is now set once on construction and this
function can therefore be removed.

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
7744fec0bf cleanup: reuse constructor of DiveCartesianAxis
The constructors of Time- and TemperatureAxis don't do anything.
In reasonable modern C++ we can simply reuse the constructor
of the base class with a "using" directive.

The point here is to simplify followup commits that will
add additional parameters to the constructors of the axes.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
d725170914 cleanup: remove DiveCartesianAxis::fontLabelScale accessor
This was only used internally - there is no point in an
accessor function. It only makes grepping more complicated.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
a14f740df0 profile: pass printFontScale on creation of the profile
Not having to readjust the scale on-demand will make the
code distinctly simpler. Let's just pass it once.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
5df0efbc7f profile: recreate the profile view when changing font size
Thus, we can keep the scale factor constant during existence
of the view. For now, this is simpler than adapting existing
text elements. We might want to make this more flexible later.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
e844b8dcad profile: move creation of mobile profile-widget into function
The current way of handling the "print scale factor" is
complex: The text fields are added and later resized via
signals. Things could be simplified by just redoing the
chart when changing the scale factor.

Moreover, in the future we will want to adapt the size of the
axes depending on the size of the texts.

As a first step, factor out the creation of the profile-widget.
This can then be used to recreate the profile when changing
the scale factor.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
23ab6b7a8c cleanup: remove unused function setToolTipVisibile()
The alternative spelling "visibile" made searching for this
function very annoying. That makes removing it even more
satisfying.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
b39e88b8c6 profile: remove need for MainWindow when rendering the profile
Very annoyingly, to render the profile for printing / export,
the profile still had to be show()n, thus requiring a parent
window.

Analysis of qmlprofile.c showed that this was due to the
transformation matrix not being properly set up on non-show()n
scenes.

Instead, we can simply render via the QGraphicsScene
(circumventing the QGraphicsView).

The code was factored out into the ProfileWidget2::draw()
function. This will hopefully make it easier to change
the size-code of the profile.

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
17dabe5d09 profile: remove gas-visibility signals
The visibility of the gas lines is updated on every profile-redraw,
which is performed when the preferences changes. No need to have
these signals.

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
009c91a8fc profile: call DiveCalculatedTissue::setVisible() correctly
This one is rich: when changing to profile-mode, the calculated
tissues are set according to the prefs.calcalltissues flag.

The DiveCalculatedTissue::setVisible() function ignores the
parameter and insteads sets the visibility according to the
expression "prefs.calcalltissues && prefs.calcceiling".

This is because the function is also called by signals,
which provide the wrong parameter.

Pass the correct parameter in the first place. Remove the
crazy signals and the overridden setVisible() function,
which ignores its parameter, later.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
adf6e6d31e profile: update visibility on replot
Currently, setting the visibility of chart features is a mess. It
is done when switching to the profile state and then via signals,
when the preferences are changed.

However, when the preferences are changed the chart is replot anyway.
So let us simply set the visibility on chart replot. Then in
a follow-up commit, the signals can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
cab179601f profile: factor out updating of visibility from setProfileState()
The plan is to simplify the visibility-control of non-interactive
chart features. As a first step identify those features that
depend on preferences-flags and factor out the setting of their
visibility into a new function updateVisibility().

This commit effectively only reorders the setting of the
visibility and therefore should have not user-visible effect.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Dirk Hohndel
b1d53481ad profile: use undo infrastructure for editing nicknames
This does the right thing even when removing a nickname by setting it to
an empty string. The oddly named DiveListNotifier handles the need to
redraw the profile when the name changes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-08-18 13:22:02 -07:00
Dirk Hohndel
2c12648156 WIP profile: add UI to edit dc nickname
This is just a quick first implementation - it will need to use the undo
code in the future, but for now this is a reasonable first step.

It's also missing the code to redraw the profile with the updated DC
name.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-08-18 13:22:02 -07:00
Linus Torvalds
35adf2d729 Add (nonfunctional) dive computer rename hooks
This adds the menu item to rename a dive computer (ie create a nickname
for it) when right-clicking on the dive computer name of a dive computer
that has a serial number (indicated by having a non-zero ->deviceid).

It is nonfunctional because it's really just the skeleton code: it needs
the UI to actually ask for a new nickname, and then it needs to actually
do the proper "create_device_node(model,serial,nickname)" to set it (or
remove the nickname if empty).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-08-18 13:22:02 -07:00
Dirk Hohndel
f7e222718a desktop: avoid crash when changing dive logs
If the last displayed dive had events, those DiveEventItems had slots connected
that would update those icons if things changed. When closing the dive log and
switching to a different one, those slots were still called and would then access
freed memory (the event structure from that old dive that is long gone by then).
This code explicitly deletes those DiveEventItems which also removes those signal
slot connections.

Fixes #3305

Sugested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-08-16 18:37:59 -07: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
f16a7c262e cleanup: unify the ProfileWidget2::shouldCalculateMax* variables
The shouldCalcluateMaxTime and shouldCalculateMaxDepth member
variables of ProfileWidget2 are set to false during drag-mode to
avoid strange shrinking of the graph. They always adopt the
same value. Therefore, replace by a single shouldCalculateMax
boolean.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-07-30 08:02:05 -07: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
Berthold Stoeger
16b31985c3 cleanup: replace membuffer by membufferpp in C-code
Thus, the membuffer data is automatically freed when going
out of scope - one thing less to worry about.

This fixes one use-after-free bug in uploadDiveLogsDE.cpp
and one extremely questionable practice in divetooltipitem.cpp:
The membuffer was a shared instance across all instances
of the DiveToolTipItem.

Remves unnecessary #include directives in files that didn't
even use membuffer.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-07-23 11:22:43 -07:00
Berthold Stoeger
9f277e65ff cleanup: remove function static variables
There were two function-static variables in ToolTipItem::refresh(),
which is a very scary proposition. Curently, there is only
one ToolTipItem, but this may change on mobile, where there
are multiple profiles at the same time.

Remove this timebomb and make the two objects subobjects.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-07-20 09:27:35 -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