| 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 |  | 
| 23 | QT_BEGIN_NAMESPACE | 
| 24 |  | 
| 25 | class QGraphsView; | 
| 26 | class QXYSeries; | 
| 27 | class QLineSeries; | 
| 28 | class QScatterSeries; | 
| 29 | class QSplineSeries; | 
| 30 | class AxisRenderer; | 
| 31 | struct QLegendData; | 
| 32 |  | 
| 33 | class PointRenderer : public QQuickItem | 
| 34 | { | 
| 35 |     Q_OBJECT | 
| 36 | public: | 
| 37 |     PointRenderer(QGraphsView *graph); | 
| 38 |     ~PointRenderer() override; | 
| 39 |  | 
| 40 |     void handlePolish(QXYSeries *series); | 
| 41 |     void afterPolish(QList<QAbstractSeries *> &cleanupSeries); | 
| 42 |     void updateSeries(QXYSeries *series); | 
| 43 |     void afterUpdate(QList<QAbstractSeries *> &cleanupSeries); | 
| 44 |     bool handleMouseMove(QMouseEvent *event); | 
| 45 |     bool handleMousePress(QMouseEvent *event); | 
| 46 |     bool handleMouseRelease(QMouseEvent *event); | 
| 47 |     bool handleHoverMove(QHoverEvent *event); | 
| 48 |  | 
| 49 | private: | 
| 50 |     struct PointGroup | 
| 51 |     { | 
| 52 |         QXYSeries *series = nullptr; | 
| 53 |         QQuickShapePath *shapePath = nullptr; | 
| 54 |         QPainterPath painterPath; | 
| 55 |         QList<QQuickItem *> markers; | 
| 56 |         QQmlComponent *currentMarker = nullptr; | 
| 57 |         QQmlComponent *previousMarker = nullptr; | 
| 58 |         QList<QRectF> rects; | 
| 59 |         qsizetype colorIndex = -1; | 
| 60 |         bool hover = false; | 
| 61 |     }; | 
| 62 |  | 
| 63 |     QQmlComponent *m_tempMarker = nullptr; | 
| 64 |  | 
| 65 |     QGraphsView *m_graph = nullptr; | 
| 66 |     QQuickShape m_shape; | 
| 67 |     QMap<QXYSeries *, PointGroup *> m_groups; | 
| 68 |     qsizetype m_currentColorIndex = 0; | 
| 69 |  | 
| 70 |     // Point drag variables | 
| 71 |     bool m_pointPressed = false; | 
| 72 |     bool m_pointDragging = false; | 
| 73 |     QPoint m_pressStart; | 
| 74 |     PointGroup *m_pressedGroup = nullptr; | 
| 75 |     qsizetype m_pressedPointIndex = 0; | 
| 76 |  | 
| 77 |     // Render area variables | 
| 78 |     qreal m_maxVertical = 0; | 
| 79 |     qreal m_maxHorizontal = 0; | 
| 80 |     qreal m_verticalOffset = 0; | 
| 81 |     qreal m_horizontalOffset = 0; | 
| 82 |     qreal m_areaWidth = 0; | 
| 83 |     qreal m_areaHeight = 0; | 
| 84 |  | 
| 85 |     qreal defaultSize(QXYSeries *series = nullptr); | 
| 86 |  | 
| 87 |     struct SeriesStyle { | 
| 88 |         QColor color; | 
| 89 |         QColor selectedColor; | 
| 90 |         QColor borderColor; | 
| 91 |         qreal borderWidth; | 
| 92 |     }; | 
| 93 |  | 
| 94 |     SeriesStyle getSeriesStyle(PointGroup *group); | 
| 95 |  | 
| 96 |     void calculateRenderCoordinates( | 
| 97 |         AxisRenderer *axisRenderer, qreal origX, qreal origY, qreal *renderX, qreal *renderY); | 
| 98 |     void reverseRenderCoordinates( | 
| 99 |         AxisRenderer *axisRenderer, qreal renderX, qreal renderY, qreal *origX, qreal *origY); | 
| 100 |     void updatePointDelegate( | 
| 101 |         QXYSeries *series, PointGroup *group, qsizetype pointIndex, qreal x, qreal y); | 
| 102 |     void hidePointDelegates(QXYSeries *series); | 
| 103 |     void updateLegendData(QXYSeries *series, QLegendData &legendData); | 
| 104 |  | 
| 105 |     void updateScatterSeries(QScatterSeries *scatter, QLegendData &legendData); | 
| 106 |     void updateLineSeries(QLineSeries *line, QLegendData &legendData); | 
| 107 |     void updateSplineSeries(QSplineSeries *spline, QLegendData &legendData); | 
| 108 | }; | 
| 109 |  | 
| 110 | QT_END_NAMESPACE | 
| 111 |  | 
| 112 | #endif // POINTRENDERER_H | 
| 113 |  |