| 1 | // Copyright (C) 2024 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef PIERENDERER_H |
| 5 | #define PIERENDERER_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 <QtGui/qpainterpath.h> |
| 19 | |
| 20 | QT_BEGIN_NAMESPACE |
| 21 | |
| 22 | class QGraphsView; |
| 23 | class QPieSeries; |
| 24 | class QPieSlice; |
| 25 | class QQuickShape; |
| 26 | class QAbstractSeries; |
| 27 | class QQuickTapHandler; |
| 28 | |
| 29 | class PieRenderer : public QQuickItem |
| 30 | { |
| 31 | Q_OBJECT |
| 32 | public: |
| 33 | PieRenderer(QGraphsView *graph, bool clipPlotArea); |
| 34 | ~PieRenderer() override; |
| 35 | |
| 36 | void handlePolish(QPieSeries *series); |
| 37 | void afterPolish(QList<QAbstractSeries *> &cleanupSeries); |
| 38 | void updateSeries(QPieSeries *series); |
| 39 | void afterUpdate(QList<QAbstractSeries *> &cleanupSeries); |
| 40 | void markedDeleted(QList<QPieSlice *> deleted); |
| 41 | |
| 42 | void setSize(QSizeF size); |
| 43 | |
| 44 | bool handleHoverMove(QHoverEvent *event); |
| 45 | |
| 46 | private: |
| 47 | struct SliceData |
| 48 | { |
| 49 | bool initialized; |
| 50 | }; |
| 51 | |
| 52 | void onSingleTapped(QEventPoint eventPoint, Qt::MouseButton button); |
| 53 | void onDoubleTapped(QEventPoint eventPoint, Qt::MouseButton button); |
| 54 | void onPressedChanged(); |
| 55 | |
| 56 | bool isPointInSlice(QPointF point, QPieSlice *slice, qreal *angle = nullptr); |
| 57 | |
| 58 | QGraphsView *m_graph = nullptr; |
| 59 | QQuickShape *m_shape = nullptr; |
| 60 | QHash<QPieSlice *, SliceData> m_activeSlices; |
| 61 | |
| 62 | QQuickTapHandler *m_tapHandler = nullptr; |
| 63 | QPieSlice *m_currentHoverSlice = nullptr; |
| 64 | |
| 65 | QPainterPath m_painterPath; |
| 66 | qsizetype m_colorIndex = -1; |
| 67 | }; |
| 68 | |
| 69 | QT_END_NAMESPACE |
| 70 | |
| 71 | #endif // QPIERENDERER_H |
| 72 |
