2021-01-01 21:30:30 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
// A small custom scatter series, where every item represents a dive
|
|
|
|
// The original QScatterSeries was buggy and distinctly slower
|
|
|
|
#ifndef SCATTER_SERIES_H
|
|
|
|
#define SCATTER_SERIES_H
|
|
|
|
|
|
|
|
#include "statsseries.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
statistics: convert chart to QQuickItem
It turns out that the wrong base class was used for the chart.
QQuickWidget can only be used on desktop, not in a mobile UI.
Therefore, turn this into a QQuickItem and move the container
QQuickWidget into desktop-only code.
Currently, this code is insane: The chart is rendered onto a
QGraphicsScene (as it was before), which is then rendered into
a QImage, which is transformed into a QSGTexture, which is then
projected onto the device. This is performed on every mouse
move event, since these events in general change the position
of the info-box.
The plan is to slowly convert elements such as the info-box into
QQuickItems. Browsing the QtQuick documentation, this will
not be much fun.
Also note that the rendering currently tears, flickers and has
antialiasing artifacts, most likely owing to integer (QImage)
to floating point (QGraphicsScene, QQuickItem) conversion
problems. The data flow is
QGraphicsScene (float) -> QImage (int) -> QQuickItem (float).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-07 13:38:37 +00:00
|
|
|
class QGraphicsScene;
|
2021-01-17 21:03:27 +00:00
|
|
|
class ChartScatterItem;
|
2021-01-11 12:22:39 +00:00
|
|
|
struct InformationBox;
|
2021-01-01 21:30:30 +00:00
|
|
|
struct StatsVariable;
|
|
|
|
struct dive;
|
|
|
|
|
|
|
|
class ScatterSeries : public StatsSeries {
|
|
|
|
public:
|
2021-01-13 13:56:48 +00:00
|
|
|
ScatterSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
|
2021-01-01 21:30:30 +00:00
|
|
|
const StatsVariable &varX, const StatsVariable &varY);
|
|
|
|
~ScatterSeries();
|
|
|
|
|
|
|
|
void updatePositions() override;
|
|
|
|
bool hover(QPointF pos) override;
|
|
|
|
void unhighlight() override;
|
|
|
|
|
|
|
|
// Note: this expects that all items are added with increasing pos!
|
|
|
|
void append(dive *d, double pos, double value);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Get items under mouse.
|
2021-01-05 11:11:46 +00:00
|
|
|
std::vector<int> getItemsUnderMouse(const QPointF &f) const;
|
2021-01-01 21:30:30 +00:00
|
|
|
|
|
|
|
struct Item {
|
2021-01-17 21:03:27 +00:00
|
|
|
std::unique_ptr<ChartScatterItem> item;
|
2021-01-01 21:30:30 +00:00
|
|
|
dive *d;
|
|
|
|
double pos, value;
|
2021-01-17 21:03:27 +00:00
|
|
|
Item(StatsView &view, ScatterSeries *series, dive *d, double pos, double value);
|
2021-01-05 11:11:46 +00:00
|
|
|
void updatePosition(ScatterSeries *series);
|
2021-01-01 21:30:30 +00:00
|
|
|
void highlight(bool highlight);
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unique_ptr<InformationBox> information;
|
|
|
|
std::vector<Item> items;
|
|
|
|
std::vector<int> highlighted;
|
|
|
|
const StatsVariable &varX;
|
|
|
|
const StatsVariable &varY;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|