Revision control
Copy as Markdown
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
// Qt-Security score:significant reason:default
#ifndef PIERENDERER_H
#define PIERENDERER_H
//
// W A R N I N G
// -------------
//
// This file is not part of the QtGraphs API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
#include "graphs2d/qabstractseries.h"
#include <QQuickItem>
#include <QtGui/qpainterpath.h>
#include <private/qgraphsglobal_p.h>
QT_BEGIN_NAMESPACE
class QGraphsView;
class QPieSeries;
class QPieSlice;
class QPieSlicePrivate;
class QQuickShape;
class QQuickShapePath;
class QAbstractSeries;
class QQuickTapHandler;
class QQuickDragHandler;
#if QT_CONFIG(graphs_2d_high_performance_backend)
class QCanvasPainter;
#endif
class PieRenderer : public QQuickItem
{
Q_OBJECT
public:
struct SliceData
{
QPainterPath shapePainterPath;
QPainterPath labelPainterPath;
qreal resolvedBorderWidth;
QColor resolvedColor;
QColor resolvedBorderColor;
QColor resolvedLabelTextColor;
int sliceIndex;
bool initialized;
bool seriesVisible;
bool labelPathVisible;
#if QT_CONFIG(graphs_2d_high_quality_backend)
QQuickShapePath *shapePath;
#endif
};
PieRenderer(QGraphsView *graph, bool clipPlotArea);
~PieRenderer() override;
#if QT_CONFIG(graphs_2d_high_performance_backend)
using PaintSnapshot = QHash<QPieSlice *, SliceData>;
static void paintSnapshot(const PaintSnapshot &paintSnapshot, QCanvasPainter *p);
void synchronizeData();
PaintSnapshot paintSnapshot() const;
#endif
void updateActiveSlices(QPieSeries *series, QList<QPieSlice *> slicelist);
void handlePolish(QPieSeries *series);
void handleSlicesPolish(QPieSeries *series,
QList<QLegendData> &legendDataList,
QList<QPieSlice *> slicelist,
qreal startAngle,
qreal endAngle,
QPointF center,
qreal radius,
qreal radiusRatio);
void afterPolish(QList<QAbstractSeries *> &cleanupSeries);
void handleSlicesAfterPolish(QList<QPieSlice *> slicelist);
void updateSeries(QPieSeries *series);
void seriesAboutToBeRemoved(QAbstractSeries *series);
void afterUpdate(QList<QAbstractSeries *> &cleanupSeries);
void markedDeleted(QList<QPieSlice *> deleted);
void setSize(QSizeF size);
bool handleHoverMove(QHoverEvent *event);
private:
struct DragState
{
bool dragging = false;
qreal dragSeriesRadius = 0.0;
QVector2D dragSeriesCenter;
};
Qt::Edge m_closerEdge = Qt::LeftEdge;
void onSingleTapped(QEventPoint eventPoint, Qt::MouseButton button);
void onDoubleTapped(QEventPoint eventPoint, Qt::MouseButton button);
void onPressedChanged();
void onGrabChanged(QPointingDevice::GrabTransition transition, QEventPoint eventPoint);
void onTranslationChanged(QVector2D delta);
bool isPointInSlice(QPointF point, QPieSlice *slice, qreal *angle = nullptr);
bool isPointInSubSlices(QPointF point, QPieSlice *slice);
qreal distanceToSegment(const QVector2D p, const QVector2D segmentStart,
const QVector2D segmentEnd);
void freeSlice(const QPieSlicePrivate *privSlice);
#if QT_CONFIG(graphs_2d_high_quality_backend)
void rebuildShapePaths();
void appendShapePaths(QQmlListProperty<QObject> &data, const QList<QPieSlice *> &slicelist);
#endif
QGraphsView *m_graph = nullptr;
QQuickShape *m_shape = nullptr;
QHash<QPieSlice *, SliceData> m_activeSlices;
#if QT_CONFIG(graphs_2d_high_performance_backend)
QHash<QPieSlice *, SliceData> m_paintSnapshot;
#endif
QQuickTapHandler *m_tapHandler = nullptr;
QPieSlice *m_currentHoverSlice = nullptr;
QQuickDragHandler *m_dragHandler = nullptr;
QPieSlice *m_dragSlice = nullptr;
DragState m_dragState;
QPainterPath m_painterPath;
qsizetype m_colorIndex = -1;
};
QT_END_NAMESPACE
#endif // QPIERENDERER_H