1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef POINTRENDERER_H
5#define POINTRENDERER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the QtGraphs API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16
17#include <QQuickItem>
18#include <QtGraphs/qabstractseries.h>
19#include <QtQuick/private/qsgdefaultinternalrectanglenode_p.h>
20#include <QtQuickShapes/private/qquickshape_p.h>
21#include <QPainterPath>
22
23QT_BEGIN_NAMESPACE
24
25class QGraphsView;
26class QXYSeries;
27class QLineSeries;
28class QScatterSeries;
29class QSplineSeries;
30class AxisRenderer;
31class QQuickTapHandler;
32class QQuickDragHandler;
33struct QLegendData;
34
35class PointRenderer : public QQuickItem
36{
37 Q_OBJECT
38public:
39 PointRenderer(QGraphsView *graph, bool clipPlotArea);
40 ~PointRenderer() override;
41
42 void resetShapePathCount();
43
44 void handlePolish(QXYSeries *series);
45 void afterPolish(QList<QAbstractSeries *> &cleanupSeries);
46 void updateSeries(QXYSeries *series);
47 void afterUpdate(QList<QAbstractSeries *> &cleanupSeries);
48 bool handleHoverMove(QHoverEvent *event);
49
50 QPointF reverseRenderCoordinates(QAbstractSeries *series, qreal x, qreal y);
51
52private:
53 struct PointGroup
54 {
55 QXYSeries *series = nullptr;
56 QQuickShapePath *shapePath = nullptr;
57 QPainterPath painterPath;
58 QList<QQuickItem *> markers;
59 QList<QQuickDragHandler *> dragHandlers;
60 QQmlComponent *currentMarker = nullptr;
61 QQmlComponent *previousMarker = nullptr;
62 QList<QRectF> rects;
63 qsizetype colorIndex = -1;
64 bool hover = false;
65 };
66
67 QQmlComponent *m_tempMarker = nullptr;
68
69 QGraphsView *m_graph = nullptr;
70 QQuickShape m_shape;
71 QMap<QXYSeries *, PointGroup *> m_groups;
72 qsizetype m_currentShapePathIndex = 0;
73
74 // Point drag variables
75 QPoint m_previousDelta;
76 PointGroup *m_pressedGroup = nullptr;
77 qsizetype m_pressedPointIndex = 0;
78
79 // Render area variables
80 qreal m_maxVertical = 0;
81 qreal m_maxHorizontal = 0;
82 qreal m_verticalOffset = 0;
83 qreal m_horizontalOffset = 0;
84 qreal m_areaWidth = 0;
85 qreal m_areaHeight = 0;
86
87 QQuickTapHandler *m_tapHandler = nullptr;
88
89 qreal defaultSize(QXYSeries *series = nullptr);
90
91 struct SeriesStyle {
92 QColor color;
93 QColor selectedColor;
94 QColor borderColor;
95 qreal borderWidth;
96 };
97
98 SeriesStyle getSeriesStyle(PointGroup *group);
99
100 void calculateRenderCoordinates(AxisRenderer *axisRenderer,
101 QAbstractSeries *series,
102 qreal origX,
103 qreal origY,
104 qreal *renderX,
105 qreal *renderY);
106 void reverseRenderCoordinates(AxisRenderer *axisRenderer,
107 QAbstractSeries *series,
108 qreal renderX,
109 qreal renderY,
110 qreal *origX,
111 qreal *origY);
112 void updatePointDelegate(
113 QXYSeries *series, PointGroup *group, qsizetype pointIndex, qreal x, qreal y);
114 void hidePointDelegates(QXYSeries *series);
115 void updateLegendData(QXYSeries *series, QLegendData &legendData);
116
117 void onSingleTapped(QEventPoint eventPoint, Qt::MouseButton button);
118 void onDoubleTapped(QEventPoint eventPoint, Qt::MouseButton button);
119 void onPressedChanged();
120
121#ifdef USE_SCATTERGRAPH
122 void updateScatterSeries(QScatterSeries *scatter, QLegendData &legendData);
123#endif
124#ifdef USE_LINEGRAPH
125 void updateLineSeries(QLineSeries *line, QLegendData &legendData);
126#endif
127#ifdef USE_SPLINEGRAPH
128 void updateSplineSeries(QSplineSeries *spline, QLegendData &legendData);
129#endif
130};
131
132QT_END_NAMESPACE
133
134#endif // POINTRENDERER_H
135

source code of qtgraphs/src/graphs2d/qsgrenderer/pointrenderer_p.h