1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QPIESLICE_H
5#define QPIESLICE_H
6
7#include <QtCharts/QChartGlobal>
8#include <QtCore/QObject>
9#include <QtGui/QPen>
10#include <QtGui/QBrush>
11#include <QtGui/QFont>
12
13QT_BEGIN_NAMESPACE
14class QPieSlicePrivate;
15class QPieSeries;
16
17class Q_CHARTS_EXPORT QPieSlice : public QObject
18{
19 Q_OBJECT
20 Q_ENUMS(LabelPosition)
21 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
22 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
23 Q_PROPERTY(bool labelVisible READ isLabelVisible WRITE setLabelVisible NOTIFY labelVisibleChanged)
24 Q_PROPERTY(LabelPosition labelPosition READ labelPosition WRITE setLabelPosition)
25 Q_PROPERTY(bool exploded READ isExploded WRITE setExploded)
26 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
27 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
28 Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged)
29 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
30 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
31 Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged)
32 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
33 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged)
34 Q_PROPERTY(qreal labelArmLengthFactor READ labelArmLengthFactor WRITE setLabelArmLengthFactor)
35 Q_PROPERTY(qreal explodeDistanceFactor READ explodeDistanceFactor WRITE setExplodeDistanceFactor)
36 Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged)
37 Q_PROPERTY(qreal startAngle READ startAngle NOTIFY startAngleChanged)
38 Q_PROPERTY(qreal angleSpan READ angleSpan NOTIFY angleSpanChanged)
39
40public:
41 enum LabelPosition {
42 LabelOutside,
43 LabelInsideHorizontal,
44 LabelInsideTangential,
45 LabelInsideNormal
46 };
47
48public:
49 explicit QPieSlice(QObject *parent = nullptr);
50 QPieSlice(QString label, qreal value, QObject *parent = nullptr);
51 virtual ~QPieSlice();
52
53 void setLabel(QString label);
54 QString label() const;
55
56 void setValue(qreal value);
57 qreal value() const;
58
59 void setLabelVisible(bool visible = true);
60 bool isLabelVisible() const;
61
62 LabelPosition labelPosition();
63 void setLabelPosition(LabelPosition position);
64
65 void setExploded(bool exploded = true);
66 bool isExploded() const;
67
68 void setPen(const QPen &pen);
69 QPen pen() const;
70
71 QColor borderColor();
72 void setBorderColor(QColor color);
73
74 int borderWidth();
75 void setBorderWidth(int width);
76
77 void setBrush(const QBrush &brush);
78 QBrush brush() const;
79
80 QColor color();
81 void setColor(QColor color);
82
83 void setLabelBrush(const QBrush &brush);
84 QBrush labelBrush() const;
85
86 QColor labelColor();
87 void setLabelColor(QColor color);
88
89 void setLabelFont(const QFont &font);
90 QFont labelFont() const;
91
92 void setLabelArmLengthFactor(qreal factor);
93 qreal labelArmLengthFactor() const;
94
95 void setExplodeDistanceFactor(qreal factor);
96 qreal explodeDistanceFactor() const;
97
98 qreal percentage() const;
99 qreal startAngle() const;
100 qreal angleSpan() const;
101
102 QPieSeries *series() const;
103
104Q_SIGNALS:
105 void clicked();
106 void hovered(bool state);
107 void pressed();
108 void released();
109 void doubleClicked();
110 void labelChanged();
111 void valueChanged();
112 void labelVisibleChanged();
113 void penChanged();
114 void brushChanged();
115 void labelBrushChanged();
116 void labelFontChanged();
117 void percentageChanged();
118 void startAngleChanged();
119 void angleSpanChanged();
120 void colorChanged();
121 void borderColorChanged();
122 void borderWidthChanged();
123 void labelColorChanged();
124
125private:
126 QPieSlicePrivate * const d_ptr;
127 Q_DECLARE_PRIVATE(QPieSlice)
128 Q_DISABLE_COPY(QPieSlice)
129};
130
131QT_END_NAMESPACE
132
133#endif // QPIESLICE_H
134

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