Commit graph

115 commits

Author SHA1 Message Date
Berthold Stoeger
80fe85067c statistics: add dive-trip variable
We have a dive-site variable, therefore we probably should also
have a dive-trip variable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 10:36:13 -08:00
Berthold Stoeger
5d1f12438b cleanup: remove 'const constexpr' pairs
'constexpr' implies 'const' since it is a stronger guarantee,
so let's remove the redundant 'const'.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 10:36:13 -08:00
Dirk Hohndel
bded5f3e5f statistics: clean up class vs. struct
Those should be equivalent, but apparently aren't with some compilers.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-12-17 09:30:59 -08:00
Dirk Hohndel
cfd6a1634f cleanup: fix SkipEmptyParts warning for mobile
And while doing that, have all the cases where we already include
qthelper.h simply use a define in that header file - but keep the two
other instances of the define where the C++ source don't need qthelper.h
otherwise.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-11-24 10:53:26 -08:00
Dirk Hohndel
d15ecef706 small whitespace fix
Just because QtCreator auto-fixed it for me...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-11-24 10:53:26 -08:00
Robert C. Helling
41258647d2 Don't access gasmix.o2.fraction
Air is a special gas that does not contain oxygen according
to gasmix.o2.fraction. If you want to use the fo2, you
need to use get_o2() to treat this special case correctly.

This fixes a bug when setting the MND of a gas containing
21% oxygen when o2 is considered not narcotic.

Reported-by: Christoph Gruen <gruen.christoph@gmail.com>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2021-10-01 08:50:36 -07:00
Berthold Stoeger
d1c89a55e1 stats: initialize InformationBox::width and height members
Fixes a Coverity warning. Good style anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-03-08 16:29:04 -08:00
Berthold Stoeger
7446e8cddd statistics: don't divide by totalCount = 0 in pie charts
This silences a Coverity warning. In principle, this should
never happen, since there are no slices if totalCount is 0.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-03-05 09:35:13 +01:00
Berthold Stoeger
9655417ad3 stats: initialize PieSeries::radius to 0 in constructor
This silences a Coverity warning. That what harmless, but
it's probably good practice to initialize all members.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-03-05 08:22:19 +01:00
Berthold Stoeger
5a8d7617ce statistics: implement primitive "restrict to selection" feature
Allow the user to restrict the analyzed dives based on the
current selection. One button restricts to the current selection
and one button resets the restriction.

Thus, the user can for example select bars in the bar chart
or a range in the scatter plot and perform statistics on
these sets.

The restriction works on top of the filter.

The UI can certainly be improved, but it is a start.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-13 13:02:54 -08:00
Berthold Stoeger
2943b1cbde statistics: implement shift-selection of ranges
For all the series but the scatter series (which supports
lasso selection), implement a range-selection using shift.

The code is fairly similar for all series and one might
think about factoring it out. But why bother?

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-13 13:02:54 -08:00
Berthold Stoeger
43b0ccca3e statistics: support ctrl-selection for all series
Multiple selection using ctrl was only supported for
scatter series. Factor out the corresponding code and
use it in all series.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-13 13:02:54 -08:00
Berthold Stoeger
64b82b16a2 statistics: make selection keyboard modifiers more general
Up to now, we passed a "shiftPressed" flag to the individual
selection functions. To be more general replace by a struct
with "shift" and "ctrl" flags.

While doing this:
1) Move the struct into a new statsselection file for better
   encapsulation.
2) Change shift to control in the scatter series, since individual
   selection of items is usually done with control, not shift.
   Shift usually means "select range".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-13 13:02:54 -08:00
Berthold Stoeger
21b8cded56 statistics: highlight selected pie slices
In analogy to the other charts, highlight selected pie slices.
Overlay them with a checkerboard pattern, like in the bar charts.

Since all charts now support highlighting, the divesSelected()
virtual function now doesn't need a default implementation
anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-13 13:02:54 -08:00
Berthold Stoeger
bd252fc820 statistics: highlight selected boxes in box plot
In analogy to bar plots, highlight selected boxes in box plots.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-13 13:02:54 -08:00
Berthold Stoeger
91d371374b statistics: remove horizontal flag from bar chart items
This flag existed for historical reasons: The base of bar items
had no line and therefore the lines had to be draw differently
for horizontal (base to the left) and vertical (base on the bottom)
item.

This did not work properly and therefore has been removed. Thus,
the flag became pointless.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-13 13:02:54 -08:00
Berthold Stoeger
06a091643e statistics: highlight selected bar
When all items of a bar in a bar chart are selected, highlight them
by overlaying with a checkerboard pattern. A gray checkerboard seems to
work reasonably well, regardless of base color.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-02-13 13:02:54 -08:00
Berthold Stoeger
d63d4cd3c3 statistics: implement rectangle selection in scatter plot
Allow the user to select regions of the scatter plot using
a rectangular selection. When shift is pressed, do an
incremental selection.

Unfortunately, the list-selection code is so slow that this
becomes unusable for a large number of selected dives.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-13 13:02:54 -08:00
Berthold Stoeger
e38b78b2aa statistics: select multiple dives in scatter-plot by shift-clicking
Somewhat improve selection mechanics in the scatter-plot by
allowing additional selections with shift-clicking. When the
dives under the mouse are already selected, then deselect them.
This appears to be a rather common UI idiom in desktop
applications.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-13 13:02:54 -08:00
Berthold Stoeger
d85b321784 statistics: show selected dives in scatter plot
As a visual feedback, show the selected dives in the scatter
plot. React to application-wide selection changes. Currently,
the dive list is deactivated while in statistics mode, but
that may change.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-13 13:02:54 -08:00
Robert C. Helling
5c098eea29 statistics: select dives from Scatter Plot
When clicking on items in a plot, select the corresponding
dives. This can be useful for data validation.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-13 13:02:54 -08:00
Berthold Stoeger
1797b59c10 statistics: replot stats if dives added / removed
It is crucial to replot the statistics when dives are
added / removed, to avoid stale pointers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-13 13:02:54 -08:00
Berthold Stoeger
b7e62307c5 statistics: save dive list with quartiles
To make box-and-whiskers charts selectable (select corresponding
dives when clicking on box), save the dive list with the quartile
data.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-13 13:02:54 -08:00
Berthold Stoeger
18a5b5b593 statistics: use dive instead of count bins
If we want to make bar charts selectable (when clicking on a
bar select the dives the bar represents), then we must store
the dives behind bars. Therefore, use dive-based bins instead
of count based bins in bar charts and pie charts. This gave
some churn because every structure where a count is stored
has to be changed to store a vector of dives. Try to use
move semantics where possible to avoid duplication of dive
lists.

On a positive note, the count_dives() function of the
binners can now be removed, since it is unused.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-13 13:02:54 -08:00
Berthold Stoeger
60a6b61fb6 statistics: fix placement of horizontal labels in bar charts
The subtraction of half the label width, needed for centered
labels, must have been lost somewhere.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-08 08:19:48 -08:00
Berthold Stoeger
5b6f468547 statistics: don't place labels at half-integer values
Placing labels at half-integer values gives horrible
rendering artifacts. Therefore, always round to integer
values. The easiest way to do this is right before setting
the position. Introduce a helper function to round QPointF
in such scenarios.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-06 10:05:41 -08:00
Berthold Stoeger
122092707c statistics: delete chart items when root node is deleted
When reparenting the statistics widget, QtQuick deletes
the rootNode and all the child nodes. It is unclear whether
this is a bug or intended behavior. In any case, it means
that the pointers to QSG nodes in the chart items become
stale.

To avoid this, delete all chart items in the root node's
destructor, before QtQuick can do anything. It is unclear
from which context this is called (render or UI) and whether
this is even valid. In some tests, it seemed to work.

The difficulty is that all the stale pointers to chart items
have to be deleted as well. All in all, the QSG memory
management is a big nuisance and very brittle.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-06 10:00:39 -08:00
Berthold Stoeger
54ff31f5c1 statistics: do resizing in UI thread, not render thread
The updatePaintNode() function, which is run on the render
thread detected a geometry change and initiated recalculation
of the chart layout.

This means that plotAreaChanged() was called in two different
thread contexts, which is questionable. Instead, hook into
the geometryChanged() function and recalculate the chart items
there.

This fixes a rendering bug, because the old code would first
delete unneeded items and then rerender the chart. Thus, old
grid and tick items were still visible.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-21 13:42:14 -08:00
Dirk Hohndel
f4d806c77a Merge branch 'tvalue' 2021-01-20 09:54:03 -08:00
Dirk Hohndel
29060feaa8 statistics/legend: fix dragging legend on touch screen
While this didn't appear to be needed when dragging the legend with a
mouse, on a touch screen for some reason the drag ended after 30 pixels
either way horizontally (but no apparent limit vertically). By setting
this flag to true, drags on a tablet appear to work as expected.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
4f58e9aa62 statistics: render bar and pie labels onto fill color
The labels in bar an pie charts are realized as individual
QSG pixmap nodes with an alpha channel. Sadly, rendering
bright labels onto a transparent background gives very
ugly artifacts.

As a stop gap measure, until the problem is understood,
render on a background with the color of the pie slice
or bar.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
2e2019dea7 statistics: move colors to statscolors.h
Most colors were already collected there, but a few were dispersed
throughout the source files.

For future themeability, move the remaining colors to this common
place.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
ba259fb1d6 statistics: make confidence area and regression line opt-in
This is not perfect - the polygon of the confidence area is
calculated even if it is not shown. Oh well.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
ff536e98fc statistics: don't replot chart when changing features
Up to now, when the user changed the visibility of chart features
(legend, quartiles, labels, etc.) the whole chart was replot.
Instead, only change the visibility status of these items.

After all, this modularity is one of the things the conversion
to QSG was all about.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
e32e6d63a7 statistics: leak textures on exit
The scatter plot items shared their textures. These were
std::unique_ptrs and cleaned up on exit. Owing to QSG's
broken memory model, freeing the textures after QApplication
terminated its threads led to crashes. Therefore, leak the
textures. Not satisfying, but ultimately harmless and better
than a crash.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
9e61a6372a statistics: fix range in categorical axes
Fix a bug that was fixed in b5c8d0dbb4 and reintroduced in
e7907c494f. Here is the original commit message:

The range for a one-bin chart is [-0.5,0.5], thus the range
in an n-bin chart is [-0.5,n-0.5], not [-0.5,n+0.5].

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
db69c38245 statistics: refactor QSG memory management
The code was wrong, because it deleted the ChartItems in the
main UI thread, not the render thread. This would delete the
QSG nodes in the UI thread and then crash on mobile.

Therefore refactor this part of the code by adding the
items to be deleted to a list that will be deleted by the
render thread.

As a drop in replacement of std::unique_ptr, implement
a silly ChartItemPtr class, which auto-initializes to null.

This turns the deterministic and easily controlled memory
management into a steaming pile of insanity. Obviously,
this can be made much more elegant, but this has to do for now.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
9d3de1801e statistics: remove QSceneGraph
All items are now painted with QSG.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
51f67c6350 statistics: remove float z-value
These values were used for items on the QGraphicsScene and
have been replaced by integer values used on the QSG scene.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
01accbfa3e statistics: replace chart title by QSG node
This one is trivial, since everything is there already:
Replace the QGraphicsSimpleTextItem with a ChartTextItem.
Only few functions have to be renamed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
2480d3b7e0 statistics: remove QGraphicsView from StatSeries
All series are converted to QSG. Thus, the pointer to the
QGraphicsView can be removed from the common base class.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
b068b2b0e7 statistics: replace PieSeries by QSG nodes
Since there are no disk-segment QSG primitives (one could draw
a triangle fan, but that doesn't seem optimal), this draws
into a pixmap and blits that as a QSG node.

Since this is the only series without axis, it needs a function
that returns the size of the plot area. This didn't exist, so
add it.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
b07a7fe5f1 statistics: convert scatter series to use QSG
The original plan to reuse the ChartPixmapItem for the
scatteritems was dumped, because it is unclear if the
textures are shared if generated for each item.

Instead, a new ChartScatterItem was created, where all
items share the same textures (one for highlighted,
one for non-highlighted). This means that the rendering
of the scatter items is now done in the chartitem.cpp
file, which feels like a layering violation. Not good,
but the easiest for now.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
409f159e1d statistics: convert box-and-whiskers plot to QSG
This is lazy: Derive from the bar chart item and add whiskers
in the subclassed render() function. The code is ugly, because
the base class function clears the dirty flags and therefore
the derived class has to remember them. Oh well.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
5d5ebfcf3c statistics: implement showing / hiding of items in QSG
To replace the QGraphicsScene, we need the possibility of
showing and hiding items.

Turns out, the QSG API is completely insane.

Whether an item should be shown is queried by the virtual
function isSubtreeBlocked(), which is supposed to be
overriden by the derived classes.

However, the common nodes for rectangles and pixmaps are
supposed to be created by QQuickWindow, for hardware
optimization. This gives nodes that cannot be derived
from and therefore whether the item is shown or not cannot
be controlled.

There are therefore two distinct cases to consider: The
node is allocated by the code directly or indirectly by
QQuickWindow.

In the latter case, we use a proxy node with the only
purpose of having a "visible" flag and add the obtained
node as a child.

This madness is performed with template trickery to get
unified code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
b42e19e36b statistics: convert bar series to QSGNodes
To this end, two new ChartItems were added: A "bar" (a rectangle
with a border) and a "text" (multiple lines of text).

It turns out that the text on the bars now looks atrocious.
The reason appears to be that the antialiasing of the font-rendering
does not blend into the alpha channel, but into a supposed
background color? This will have to be investigated.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
2008857660 statistics: render regression item using QSGNode
Render the confidence area and the regression line into a pixmap
and show that using a QSGNode.

It is unclear whether it is preferred to do it this way or to
triangulate the confidence area into triangles to be drawn by
the shader.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
faf3e7079d statistics: keep track of dirty items in double-linked list
So far the items to be recalculated in the drawing thread
had a "dirty" flag and were kept in one array par z-level.

Once the series are implemented in terms of QSGNodes, there
may lots of these items. To make this more efficient when
only one or two of these items change (e.g. highlighting due
to mouseover), keep the dirty items in a linked list.

Of course, this makes the draw first version of the chart
less efficient.

There are more fancy ways of implementing the double-linked
list, but the few ns gained in the render thread are hardly
worth it.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
ada5e8a49d statistics: turn axes into QSGNode
Render the labels and the title into a pixmap and render
the ticks and the base line using individual QSGNodes.
Attempting to render the ticks likewise into the pixmap
gave horrible results, because (quite obviously) rendering
with QPainter and the QSG shader gives non-matching ticks
and grid lines.

The memory management had to be changed a bit: The ChartItems
were collected in the root QSGNode. However, the axes are added
before the first plotting, so this node might not exist.
Therefore, store the axes in the StatsView object.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00
Berthold Stoeger
9b7565e81a statistics: turn ChartGrid into QSGNodes
Turn the background grid into QSGNodes. Each grid line is
represented by a QSG line item. An alternative would be
drawing the grid into a QImage and blasting that onto the
screen. It is unclear which one is preferred.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-20 08:47:18 +01:00