1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4// W A R N I N G
5// -------------
6//
7// This file is not part of the Qt Chart API. It exists purely as an
8// implementation detail. This header file may change from version to
9// version without notice, or even be removed.
10//
11// We mean it.
12
13#ifndef PIECHARTITEM_H
14#define PIECHARTITEM_H
15
16#include <QtCharts/QPieSeries>
17#include <private/chartitem_p.h>
18#include <private/piesliceitem_p.h>
19#include <QtCore/QPointer>
20#include <QtCharts/private/qchartglobal_p.h>
21
22QT_BEGIN_NAMESPACE
23class QGraphicsItem;
24QT_END_NAMESPACE
25
26QT_BEGIN_NAMESPACE
27class QPieSlice;
28class ChartPresenter;
29class PieAnimation;
30
31class Q_CHARTS_PRIVATE_EXPORT PieChartItem : public ChartItem
32{
33 Q_OBJECT
34
35public:
36 explicit PieChartItem(QPieSeries *series, QGraphicsItem* item = 0);
37 ~PieChartItem();
38
39 // from QGraphicsItem
40 QRectF boundingRect() const override { return m_rect; }
41 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override {}
42
43protected:
44 void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
45 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
46 void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
47 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
48 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
49
50public Q_SLOTS:
51 // from Chart
52 void handleDomainUpdated() override;
53
54 void updateLayout();
55 void handleSlicesAdded(const QList<QPieSlice *> &slices);
56 void handleSlicesRemoved(const QList<QPieSlice *> &slices);
57 void handleSliceChanged();
58 void handleSeriesVisibleChanged();
59 void handleOpacityChanged();
60
61 void setAnimation(PieAnimation *animation);
62 ChartAnimation *animation() const override;
63
64 // From ChartItem
65 void cleanup() override;
66private:
67 PieSliceData updateSliceGeometry(QPieSlice *slice);
68
69private:
70 QHash<QPieSlice *, PieSliceItem *> m_sliceItems;
71 QPointer<QPieSeries> m_series;
72 QRectF m_rect;
73 QPointF m_pieCenter;
74 qreal m_pieRadius;
75 qreal m_holeSize;
76 PieAnimation *m_animation;
77
78};
79
80QT_END_NAMESPACE
81
82#endif // PIECHARTITEM_H
83

source code of qtcharts/src/charts/piechart/piechartitem_p.h