2021-01-01 21:43:21 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef STATS_VIEW_H
|
|
|
|
#define STATS_VIEW_H
|
|
|
|
|
|
|
|
#include "statsstate.h"
|
2021-01-18 21:29:34 +00:00
|
|
|
#include "statshelper.h"
|
2021-02-08 16:07:37 +00:00
|
|
|
#include "statsselection.h"
|
2021-01-01 21:43:21 +00:00
|
|
|
#include <memory>
|
2021-01-04 20:41:30 +00:00
|
|
|
#include <QFont>
|
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
|
|
|
#include <QImage>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QQuickItem>
|
2021-01-01 21:43:21 +00:00
|
|
|
|
|
|
|
struct dive;
|
|
|
|
struct StatsBinner;
|
|
|
|
struct StatsBin;
|
|
|
|
struct StatsState;
|
|
|
|
struct StatsVariable;
|
|
|
|
|
|
|
|
class StatsSeries;
|
|
|
|
class CategoryAxis;
|
2021-01-12 14:20:05 +00:00
|
|
|
class ChartItem;
|
2021-02-01 22:17:04 +00:00
|
|
|
class ChartRectLineItem;
|
2021-01-18 11:47:24 +00:00
|
|
|
class ChartTextItem;
|
2021-01-01 21:43:21 +00:00
|
|
|
class CountAxis;
|
|
|
|
class HistogramAxis;
|
2021-01-14 08:48:44 +00:00
|
|
|
class HistogramMarker;
|
2021-01-14 07:48:56 +00:00
|
|
|
class QuartileMarker;
|
2021-01-15 17:39:14 +00:00
|
|
|
class RegressionItem;
|
2021-01-01 21:43:21 +00:00
|
|
|
class StatsAxis;
|
2021-01-05 12:51:39 +00:00
|
|
|
class StatsGrid;
|
2021-01-01 21:43:21 +00:00
|
|
|
class Legend;
|
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 QSGTexture;
|
2021-01-13 15:19:27 +00:00
|
|
|
class RootNode; // Internal implementation detail
|
2021-01-01 21:43:21 +00:00
|
|
|
|
|
|
|
enum class ChartSubType : int;
|
2021-01-13 15:19:27 +00:00
|
|
|
enum class ChartZValue : int;
|
2021-01-01 21:43:21 +00:00
|
|
|
enum class StatsOperation : int;
|
2021-12-31 17:29:06 +00:00
|
|
|
enum class ChartSortMode : int;
|
2021-01-01 21:43:21 +00: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 13:38:37 +00:00
|
|
|
class StatsView : public QQuickItem {
|
2021-01-01 21:43:21 +00: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 13:38:37 +00:00
|
|
|
StatsView();
|
|
|
|
StatsView(QQuickItem *parent);
|
2021-01-01 21:43:21 +00:00
|
|
|
~StatsView();
|
|
|
|
|
|
|
|
void plot(const StatsState &state);
|
2021-01-21 12:51:03 +00:00
|
|
|
void updateFeatures(const StatsState &state); // Updates the visibility of chart features, such as legend, regression, etc.
|
2021-02-12 09:56:48 +00:00
|
|
|
void restrictToSelection();
|
|
|
|
void unrestrict();
|
|
|
|
int restrictionCount() const; // <0: no restriction
|
2021-01-19 08:54:39 +00:00
|
|
|
QQuickWindow *w() const; // Make window available to items
|
2021-01-12 14:20:05 +00:00
|
|
|
QSizeF size() const;
|
2021-01-18 11:08:46 +00:00
|
|
|
QRectF plotArea() const;
|
2021-01-13 15:19:27 +00:00
|
|
|
void addQSGNode(QSGNode *node, ChartZValue z); // Must only be called in render thread!
|
2021-01-18 21:29:34 +00:00
|
|
|
void registerChartItem(ChartItem &item);
|
2021-01-15 11:22:32 +00:00
|
|
|
void registerDirtyChartItem(ChartItem &item);
|
2021-02-12 09:56:48 +00:00
|
|
|
void emergencyShutdown(); // Called when QQuick decides to delete our root node.
|
2021-01-18 21:29:34 +00:00
|
|
|
|
|
|
|
// Create a chart item and add it to the scene.
|
|
|
|
// The item must not be deleted by the caller, but can be
|
|
|
|
// scheduled for deletion using deleteChartItem() below.
|
|
|
|
// Most items can be made invisible, which is preferred over deletion.
|
|
|
|
// All items on the scene will be deleted once the chart is reset.
|
2021-01-13 14:17:54 +00:00
|
|
|
template <typename T, class... Args>
|
2021-01-18 21:29:34 +00:00
|
|
|
ChartItemPtr<T> createChartItem(Args&&... args);
|
2021-01-13 14:17:54 +00:00
|
|
|
|
2021-01-18 21:29:34 +00:00
|
|
|
template <typename T>
|
|
|
|
void deleteChartItem(ChartItemPtr<T> &item);
|
2021-01-01 21:43:21 +00:00
|
|
|
private slots:
|
|
|
|
void replotIfVisible();
|
2021-01-31 19:48:12 +00:00
|
|
|
void divesSelected(const QVector<dive *> &dives);
|
2021-01-01 21:43:21 +00:00
|
|
|
private:
|
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
|
|
|
// QtQuick related things
|
2021-01-20 22:13:54 +00:00
|
|
|
bool backgroundDirty;
|
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
|
|
|
QRectF plotRect;
|
|
|
|
QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *updatePaintNodeData) override;
|
|
|
|
|
2021-01-20 22:13:54 +00:00
|
|
|
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
|
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
|
|
|
void plotAreaChanged(const QSizeF &size);
|
2021-01-01 21:43:21 +00:00
|
|
|
void reset(); // clears all series and axes
|
2021-01-05 11:11:46 +00:00
|
|
|
void setAxes(StatsAxis *x, StatsAxis *y);
|
2021-01-01 21:43:21 +00:00
|
|
|
void plotBarChart(const std::vector<dive *> &dives,
|
2021-12-31 17:29:06 +00:00
|
|
|
ChartSubType subType, ChartSortMode sortMode,
|
2021-01-01 21:43:21 +00:00
|
|
|
const StatsVariable *categoryVariable, const StatsBinner *categoryBinner,
|
2021-01-19 08:54:39 +00:00
|
|
|
const StatsVariable *valueVariable, const StatsBinner *valueBinner);
|
2021-01-01 21:43:21 +00:00
|
|
|
void plotValueChart(const std::vector<dive *> &dives,
|
2021-12-31 17:29:06 +00:00
|
|
|
ChartSubType subType, ChartSortMode sortMode,
|
2021-01-01 21:43:21 +00:00
|
|
|
const StatsVariable *categoryVariable, const StatsBinner *categoryBinner,
|
2021-01-19 08:54:39 +00:00
|
|
|
const StatsVariable *valueVariable, StatsOperation valueAxisOperation);
|
2021-01-01 21:43:21 +00:00
|
|
|
void plotDiscreteCountChart(const std::vector<dive *> &dives,
|
2021-12-31 17:29:06 +00:00
|
|
|
ChartSubType subType, ChartSortMode sortMode,
|
2021-01-19 08:54:39 +00:00
|
|
|
const StatsVariable *categoryVariable, const StatsBinner *categoryBinner);
|
2021-12-31 17:29:06 +00:00
|
|
|
void plotPieChart(const std::vector<dive *> &dives, ChartSortMode sortMode,
|
2021-01-19 08:54:39 +00:00
|
|
|
const StatsVariable *categoryVariable, const StatsBinner *categoryBinner);
|
2021-01-01 21:43:21 +00: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 08:54:39 +00:00
|
|
|
const StatsVariable *valueVariable);
|
2021-01-01 21:43:21 +00:00
|
|
|
void plotHistogramCountChart(const std::vector<dive *> &dives,
|
|
|
|
ChartSubType subType,
|
2021-01-19 08:54:39 +00:00
|
|
|
const StatsVariable *categoryVariable, const StatsBinner *categoryBinner);
|
2021-01-01 21:43:21 +00:00
|
|
|
void plotHistogramValueChart(const std::vector<dive *> &dives,
|
|
|
|
ChartSubType subType,
|
|
|
|
const StatsVariable *categoryVariable, const StatsBinner *categoryBinner,
|
2021-01-19 08:54:39 +00:00
|
|
|
const StatsVariable *valueVariable, StatsOperation valueAxisOperation);
|
2021-01-01 21:43:21 +00:00
|
|
|
void plotHistogramStackedChart(const std::vector<dive *> &dives,
|
|
|
|
ChartSubType subType,
|
|
|
|
const StatsVariable *categoryVariable, const StatsBinner *categoryBinner,
|
2021-01-19 08:54:39 +00:00
|
|
|
const StatsVariable *valueVariable, const StatsBinner *valueBinner);
|
2021-01-01 21:43:21 +00: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 20:41:30 +00:00
|
|
|
void updateTitlePos(); // After resizing, set title to correct position
|
|
|
|
void plotChart();
|
2021-01-19 08:54:39 +00:00
|
|
|
void updateFeatures(); // Updates the visibility of chart features, such as legend, regression, etc.
|
2021-01-01 21:43:21 +00: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-01-04 20:41:30 +00:00
|
|
|
QFont titleFont;
|
2021-01-01 21:43:21 +00:00
|
|
|
std::vector<std::unique_ptr<StatsSeries>> series;
|
2021-01-18 21:29:34 +00:00
|
|
|
std::unique_ptr<StatsGrid> grid;
|
|
|
|
std::vector<ChartItemPtr<QuartileMarker>> quartileMarkers;
|
2021-01-19 08:54:39 +00:00
|
|
|
ChartItemPtr<HistogramMarker> medianMarker, meanMarker;
|
2021-01-01 21:43:21 +00:00
|
|
|
StatsSeries *highlightedSeries;
|
2021-01-05 11:11:46 +00:00
|
|
|
StatsAxis *xAxis, *yAxis;
|
2021-01-18 21:29:34 +00:00
|
|
|
ChartItemPtr<ChartTextItem> title;
|
|
|
|
ChartItemPtr<Legend> legend;
|
2021-01-13 12:23:41 +00:00
|
|
|
Legend *draggedItem;
|
2021-01-18 21:29:34 +00:00
|
|
|
ChartItemPtr<RegressionItem> regressionItem;
|
2021-02-01 22:17:04 +00:00
|
|
|
ChartItemPtr<ChartRectLineItem> selectionRect;
|
2021-01-13 12:23:41 +00:00
|
|
|
QPointF dragStartMouse, dragStartItem;
|
2021-02-08 16:07:37 +00:00
|
|
|
SelectionModifier selectionModifier;
|
2021-02-01 22:17:04 +00:00
|
|
|
std::vector<dive *> oldSelection;
|
2021-02-12 09:56:48 +00:00
|
|
|
bool restrictDives;
|
|
|
|
std::vector<dive *> restrictedDives; // sorted by pointer for quick lookup.
|
2021-01-01 21:43:21 +00: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 13:38:37 +00:00
|
|
|
void hoverEnterEvent(QHoverEvent *event) override;
|
|
|
|
void hoverMoveEvent(QHoverEvent *event) override;
|
2021-01-13 12:23:41 +00:00
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *event) override;
|
2021-01-13 15:19:27 +00:00
|
|
|
RootNode *rootNode;
|
2021-01-18 21:29:34 +00:00
|
|
|
|
|
|
|
// There are three double linked lists of chart items:
|
|
|
|
// clean items, dirty items and items to be deleted.
|
2021-01-21 12:51:03 +00:00
|
|
|
// Note that only the render thread must delete chart items,
|
|
|
|
// and therefore these lists are the only owning pointers
|
|
|
|
// to chart items. All other pointers are non-owning and
|
|
|
|
// can therefore become stale.
|
2021-01-18 21:29:34 +00:00
|
|
|
struct ChartItemList {
|
|
|
|
ChartItemList();
|
|
|
|
ChartItem *first, *last;
|
|
|
|
void append(ChartItem &item);
|
|
|
|
void remove(ChartItem &item);
|
|
|
|
void clear();
|
|
|
|
void splice(ChartItemList &list);
|
|
|
|
};
|
|
|
|
ChartItemList cleanItems, dirtyItems, deletedItems;
|
|
|
|
void deleteChartItemInternal(ChartItem &item);
|
2021-01-21 12:51:03 +00:00
|
|
|
void freeDeletedChartItems();
|
2021-01-01 21:43:21 +00:00
|
|
|
};
|
|
|
|
|
2021-01-13 14:17:54 +00:00
|
|
|
// This implementation detail must be known to users of the class.
|
|
|
|
// Perhaps move it into a statsview_impl.h file.
|
|
|
|
template <typename T, class... Args>
|
2021-01-18 21:29:34 +00:00
|
|
|
ChartItemPtr<T> StatsView::createChartItem(Args&&... args)
|
|
|
|
{
|
|
|
|
return ChartItemPtr(new T(*this, std::forward<Args>(args)...));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void StatsView::deleteChartItem(ChartItemPtr<T> &item)
|
2021-01-13 14:17:54 +00:00
|
|
|
{
|
2021-01-18 21:29:34 +00:00
|
|
|
deleteChartItemInternal(*item);
|
|
|
|
item.reset();
|
2021-01-13 14:17:54 +00:00
|
|
|
}
|
|
|
|
|
2021-01-01 21:43:21 +00:00
|
|
|
#endif
|