2021-01-01 21:23:29 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
// A small custom box plot series, which displays quartiles.
|
|
|
|
// The QtCharts bar series were too inflexible with respect
|
|
|
|
// to placement of the bars.
|
|
|
|
#ifndef BOX_SERIES_H
|
|
|
|
#define BOX_SERIES_H
|
|
|
|
|
2021-01-17 20:07:57 +00:00
|
|
|
#include "chartitem.h"
|
2021-01-01 21:23:29 +00:00
|
|
|
#include "statsseries.h"
|
|
|
|
#include "statsvariables.h" // for StatsQuartiles
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2021-01-11 12:22:39 +00:00
|
|
|
struct InformationBox;
|
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-01 21:23:29 +00:00
|
|
|
|
|
|
|
class BoxSeries : public StatsSeries {
|
|
|
|
public:
|
2021-01-13 13:56:48 +00:00
|
|
|
BoxSeries(QGraphicsScene *scene, StatsView &view, StatsAxis *xAxis, StatsAxis *yAxis,
|
2021-01-01 21:23:29 +00:00
|
|
|
const QString &variable, const QString &unit, int decimals);
|
|
|
|
~BoxSeries();
|
|
|
|
|
|
|
|
void updatePositions() override;
|
|
|
|
bool hover(QPointF pos) override;
|
|
|
|
void unhighlight() override;
|
|
|
|
|
|
|
|
// Note: this expects that all items are added with increasing pos
|
|
|
|
// and that no bar is inside another bar, i.e. lowerBound and upperBound
|
|
|
|
// are ordered identically.
|
|
|
|
void append(double lowerBound, double upperBound, const StatsQuartiles &q, const QString &binName);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Get item under mouse pointer, or -1 if none
|
|
|
|
int getItemUnderMouse(const QPointF &f);
|
|
|
|
|
|
|
|
struct Item {
|
2021-01-17 20:07:57 +00:00
|
|
|
std::unique_ptr<ChartBoxItem> item;
|
2021-01-01 21:23:29 +00:00
|
|
|
double lowerBound, upperBound;
|
|
|
|
StatsQuartiles q;
|
|
|
|
QString binName;
|
2021-01-17 20:07:57 +00:00
|
|
|
Item(StatsView &view, BoxSeries *series, double lowerBound, double upperBound, const StatsQuartiles &q, const QString &binName);
|
|
|
|
~Item();
|
2021-01-05 11:11:46 +00:00
|
|
|
void updatePosition(BoxSeries *series);
|
2021-01-01 21:23:29 +00:00
|
|
|
void highlight(bool highlight);
|
|
|
|
};
|
|
|
|
|
|
|
|
QString variable, unit;
|
|
|
|
int decimals;
|
|
|
|
|
|
|
|
std::vector<QString> formatInformation(const Item &item) const;
|
|
|
|
std::unique_ptr<InformationBox> information;
|
|
|
|
std::vector<std::unique_ptr<Item>> items;
|
|
|
|
int highlighted; // -1: no item highlighted
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|