2021-01-01 22:43:21 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef STATS_VIEW_H
|
|
|
|
#define STATS_VIEW_H
|
|
|
|
|
|
|
|
#include "statsstate.h"
|
2021-02-08 17:07:37 +01:00
|
|
|
#include "statsselection.h"
|
2023-04-16 20:05:36 +02:00
|
|
|
#include "qt-quick/chartview.h"
|
|
|
|
|
2021-01-01 22:43:21 +01:00
|
|
|
#include <memory>
|
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 14:38:37 +01:00
|
|
|
#include <QImage>
|
|
|
|
#include <QPainter>
|
2021-01-01 22:43:21 +01:00
|
|
|
|
|
|
|
struct dive;
|
|
|
|
struct StatsBinner;
|
|
|
|
struct StatsBin;
|
|
|
|
struct StatsState;
|
|
|
|
struct StatsVariable;
|
|
|
|
|
|
|
|
class StatsSeries;
|
|
|
|
class CategoryAxis;
|
2021-02-01 23:17:04 +01:00
|
|
|
class ChartRectLineItem;
|
2021-01-18 12:47:24 +01:00
|
|
|
class ChartTextItem;
|
2021-01-01 22:43:21 +01:00
|
|
|
class CountAxis;
|
|
|
|
class HistogramAxis;
|
2021-01-14 09:48:44 +01:00
|
|
|
class HistogramMarker;
|
2021-01-14 08:48:56 +01:00
|
|
|
class QuartileMarker;
|
2021-01-15 18:39:14 +01:00
|
|
|
class RegressionItem;
|
2021-01-01 22:43:21 +01:00
|
|
|
class StatsAxis;
|
2021-01-05 13:51:39 +01:00
|
|
|
class StatsGrid;
|
2021-02-16 17:05:39 +01:00
|
|
|
class StatsTheme;
|
2021-01-01 22:43:21 +01:00
|
|
|
class Legend;
|
|
|
|
|
|
|
|
enum class ChartSubType : int;
|
|
|
|
enum class StatsOperation : int;
|
2021-12-31 18:29:06 +01:00
|
|
|
enum class ChartSortMode : int;
|
2021-01-01 22:43:21 +01:00
|
|
|
|
2023-04-16 20:05:36 +02:00
|
|
|
class StatsView : public ChartView {
|
2021-01-01 22:43:21 +01:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
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 14:38:37 +01:00
|
|
|
StatsView();
|
|
|
|
StatsView(QQuickItem *parent);
|
2021-01-01 22:43:21 +01:00
|
|
|
~StatsView();
|
|
|
|
|
|
|
|
void plot(const StatsState &state);
|
2021-01-21 13:51:03 +01:00
|
|
|
void updateFeatures(const StatsState &state); // Updates the visibility of chart features, such as legend, regression, etc.
|
2021-02-12 10:56:48 +01:00
|
|
|
void restrictToSelection();
|
|
|
|
void unrestrict();
|
|
|
|
int restrictionCount() const; // <0: no restriction
|
2021-02-21 16:17:24 +01:00
|
|
|
void setTheme(bool dark); // Chart must be replot for theme to become effective.
|
2021-02-16 17:05:39 +01:00
|
|
|
const StatsTheme &getCurrentTheme() const;
|
2021-01-13 15:17:54 +01:00
|
|
|
|
2021-01-01 22:43:21 +01:00
|
|
|
void replotIfVisible();
|
2021-01-31 20:48:12 +01:00
|
|
|
void divesSelected(const QVector<dive *> &dives);
|
2021-01-01 22:43:21 +01:00
|
|
|
private:
|
2023-04-16 20:05:36 +02:00
|
|
|
void plotAreaChanged(const QSizeF &size) override;
|
2021-01-01 22:43:21 +01:00
|
|
|
void reset(); // clears all series and axes
|
2023-04-16 20:05:36 +02:00
|
|
|
void resetPointers() override;
|
2021-01-05 12:11:46 +01:00
|
|
|
void setAxes(StatsAxis *x, StatsAxis *y);
|
2021-01-01 22:43:21 +01:00
|
|
|
void plotBarChart(const std::vector<dive *> &dives,
|
2021-12-31 18:29:06 +01:00
|
|
|
ChartSubType subType, ChartSortMode sortMode,
|
2021-01-01 22:43:21 +01:00
|
|
|
const StatsVariable *categoryVariable, const StatsBinner *categoryBinner,
|
2021-01-19 09:54:39 +01:00
|
|
|
const StatsVariable *valueVariable, const StatsBinner *valueBinner);
|
2021-01-01 22:43:21 +01:00
|
|
|
void plotValueChart(const std::vector<dive *> &dives,
|
2021-12-31 18:29:06 +01:00
|
|
|
ChartSubType subType, ChartSortMode sortMode,
|
2021-01-01 22:43:21 +01:00
|
|
|
const StatsVariable *categoryVariable, const StatsBinner *categoryBinner,
|
2021-01-19 09:54:39 +01:00
|
|
|
const StatsVariable *valueVariable, StatsOperation valueAxisOperation);
|
2021-01-01 22:43:21 +01:00
|
|
|
void plotDiscreteCountChart(const std::vector<dive *> &dives,
|
2021-12-31 18:29:06 +01:00
|
|
|
ChartSubType subType, ChartSortMode sortMode,
|
2021-01-19 09:54:39 +01:00
|
|
|
const StatsVariable *categoryVariable, const StatsBinner *categoryBinner);
|
2021-12-31 18:29:06 +01:00
|
|
|
void plotPieChart(const std::vector<dive *> &dives, ChartSortMode sortMode,
|
2021-01-19 09:54:39 +01:00
|
|
|
const StatsVariable *categoryVariable, const StatsBinner *categoryBinner);
|
2021-01-01 22:43:21 +01:00
|
|
|
void plotDiscreteBoxChart(const std::vector<dive *> &dives,
|
|
|
|
const StatsVariable *categoryVariable, const StatsBinner *categoryBinner, const StatsVariable *valueVariable);
|
|
|
|
void plotDiscreteScatter(const std::vector<dive *> &dives,
|
|
|
|
const StatsVariable *categoryVariable, const StatsBinner *categoryBinner,
|
2021-01-19 09:54:39 +01:00
|
|
|
const StatsVariable *valueVariable);
|
2021-01-01 22:43:21 +01:00
|
|
|
void plotHistogramCountChart(const std::vector<dive *> &dives,
|
|
|
|
ChartSubType subType,
|
2021-01-19 09:54:39 +01:00
|
|
|
const StatsVariable *categoryVariable, const StatsBinner *categoryBinner);
|
2021-01-01 22:43:21 +01:00
|
|
|
void plotHistogramValueChart(const std::vector<dive *> &dives,
|
|
|
|
ChartSubType subType,
|
|
|
|
const StatsVariable *categoryVariable, const StatsBinner *categoryBinner,
|
2021-01-19 09:54:39 +01:00
|
|
|
const StatsVariable *valueVariable, StatsOperation valueAxisOperation);
|
2021-01-01 22:43:21 +01:00
|
|
|
void plotHistogramStackedChart(const std::vector<dive *> &dives,
|
|
|
|
ChartSubType subType,
|
|
|
|
const StatsVariable *categoryVariable, const StatsBinner *categoryBinner,
|
2021-01-19 09:54:39 +01:00
|
|
|
const StatsVariable *valueVariable, const StatsBinner *valueBinner);
|
2021-01-01 22:43:21 +01:00
|
|
|
void plotHistogramBoxChart(const std::vector<dive *> &dives,
|
|
|
|
const StatsVariable *categoryVariable, const StatsBinner *categoryBinner, const StatsVariable *valueVariable);
|
|
|
|
void plotScatter(const std::vector<dive *> &dives, const StatsVariable *categoryVariable, const StatsVariable *valueVariable);
|
|
|
|
void setTitle(const QString &);
|
2021-01-04 21:41:30 +01:00
|
|
|
void updateTitlePos(); // After resizing, set title to correct position
|
|
|
|
void plotChart();
|
2021-01-19 09:54:39 +01:00
|
|
|
void updateFeatures(); // Updates the visibility of chart features, such as legend, regression, etc.
|
2021-01-01 22:43:21 +01:00
|
|
|
|
|
|
|
template <typename T, class... Args>
|
|
|
|
T *createSeries(Args&&... args);
|
|
|
|
|
|
|
|
template <typename T, class... Args>
|
|
|
|
T *createAxis(const QString &title, Args&&... args);
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
CategoryAxis *createCategoryAxis(const QString &title, const StatsBinner &binner,
|
|
|
|
const std::vector<T> &bins, bool isHorizontal);
|
|
|
|
template<typename T>
|
|
|
|
HistogramAxis *createHistogramAxis(const QString &title, const StatsBinner &binner,
|
|
|
|
const std::vector<T> &bins, bool isHorizontal);
|
|
|
|
CountAxis *createCountAxis(int maxVal, bool isHorizontal);
|
|
|
|
|
|
|
|
// Helper functions to add feature to the chart
|
|
|
|
void addLineMarker(double pos, double low, double high, const QPen &pen, bool isHorizontal);
|
|
|
|
|
|
|
|
StatsState state;
|
2021-02-16 17:05:39 +01:00
|
|
|
const StatsTheme *currentTheme;
|
2021-01-01 22:43:21 +01:00
|
|
|
std::vector<std::unique_ptr<StatsSeries>> series;
|
2021-01-18 22:29:34 +01:00
|
|
|
std::unique_ptr<StatsGrid> grid;
|
|
|
|
std::vector<ChartItemPtr<QuartileMarker>> quartileMarkers;
|
2021-01-19 09:54:39 +01:00
|
|
|
ChartItemPtr<HistogramMarker> medianMarker, meanMarker;
|
2021-01-01 22:43:21 +01:00
|
|
|
StatsSeries *highlightedSeries;
|
2021-01-05 12:11:46 +01:00
|
|
|
StatsAxis *xAxis, *yAxis;
|
2021-01-18 22:29:34 +01:00
|
|
|
ChartItemPtr<ChartTextItem> title;
|
|
|
|
ChartItemPtr<Legend> legend;
|
2021-01-13 13:23:41 +01:00
|
|
|
Legend *draggedItem;
|
2021-01-18 22:29:34 +01:00
|
|
|
ChartItemPtr<RegressionItem> regressionItem;
|
2021-02-01 23:17:04 +01:00
|
|
|
ChartItemPtr<ChartRectLineItem> selectionRect;
|
2021-01-13 13:23:41 +01:00
|
|
|
QPointF dragStartMouse, dragStartItem;
|
2021-02-08 17:07:37 +01:00
|
|
|
SelectionModifier selectionModifier;
|
2021-02-01 23:17:04 +01:00
|
|
|
std::vector<dive *> oldSelection;
|
2021-02-12 10:56:48 +01:00
|
|
|
bool restrictDives;
|
|
|
|
std::vector<dive *> restrictedDives; // sorted by pointer for quick lookup.
|
2021-01-01 22:43:21 +01:00
|
|
|
|
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 14:38:37 +01:00
|
|
|
void hoverEnterEvent(QHoverEvent *event) override;
|
|
|
|
void hoverMoveEvent(QHoverEvent *event) override;
|
2021-01-13 13:23:41 +01:00
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *event) override;
|
2021-01-01 22:43:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|