1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Charts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30#ifndef QPIESLICE_H
31#define QPIESLICE_H
32
33#include <QtCharts/QChartGlobal>
34#include <QtCore/QObject>
35#include <QtGui/QPen>
36#include <QtGui/QBrush>
37#include <QtGui/QFont>
38
39QT_CHARTS_BEGIN_NAMESPACE
40class QPieSlicePrivate;
41class QPieSeries;
42
43class Q_CHARTS_EXPORT QPieSlice : public QObject
44{
45 Q_OBJECT
46 Q_ENUMS(LabelPosition)
47 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
48 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
49 Q_PROPERTY(bool labelVisible READ isLabelVisible WRITE setLabelVisible NOTIFY labelVisibleChanged)
50 Q_PROPERTY(LabelPosition labelPosition READ labelPosition WRITE setLabelPosition)
51 Q_PROPERTY(bool exploded READ isExploded WRITE setExploded)
52 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
53 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
54 Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged)
55 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
56 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
57 Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged)
58 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
59 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged)
60 Q_PROPERTY(qreal labelArmLengthFactor READ labelArmLengthFactor WRITE setLabelArmLengthFactor)
61 Q_PROPERTY(qreal explodeDistanceFactor READ explodeDistanceFactor WRITE setExplodeDistanceFactor)
62 Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged)
63 Q_PROPERTY(qreal startAngle READ startAngle NOTIFY startAngleChanged)
64 Q_PROPERTY(qreal angleSpan READ angleSpan NOTIFY angleSpanChanged)
65
66public:
67 enum LabelPosition {
68 LabelOutside,
69 LabelInsideHorizontal,
70 LabelInsideTangential,
71 LabelInsideNormal
72 };
73
74public:
75 explicit QPieSlice(QObject *parent = nullptr);
76 QPieSlice(QString label, qreal value, QObject *parent = nullptr);
77 virtual ~QPieSlice();
78
79 void setLabel(QString label);
80 QString label() const;
81
82 void setValue(qreal value);
83 qreal value() const;
84
85 void setLabelVisible(bool visible = true);
86 bool isLabelVisible() const;
87
88 LabelPosition labelPosition();
89 void setLabelPosition(LabelPosition position);
90
91 void setExploded(bool exploded = true);
92 bool isExploded() const;
93
94 void setPen(const QPen &pen);
95 QPen pen() const;
96
97 QColor borderColor();
98 void setBorderColor(QColor color);
99
100 int borderWidth();
101 void setBorderWidth(int width);
102
103 void setBrush(const QBrush &brush);
104 QBrush brush() const;
105
106 QColor color();
107 void setColor(QColor color);
108
109 void setLabelBrush(const QBrush &brush);
110 QBrush labelBrush() const;
111
112 QColor labelColor();
113 void setLabelColor(QColor color);
114
115 void setLabelFont(const QFont &font);
116 QFont labelFont() const;
117
118 void setLabelArmLengthFactor(qreal factor);
119 qreal labelArmLengthFactor() const;
120
121 void setExplodeDistanceFactor(qreal factor);
122 qreal explodeDistanceFactor() const;
123
124 qreal percentage() const;
125 qreal startAngle() const;
126 qreal angleSpan() const;
127
128 QPieSeries *series() const;
129
130Q_SIGNALS:
131 void clicked();
132 void hovered(bool state);
133 void pressed();
134 void released();
135 void doubleClicked();
136 void labelChanged();
137 void valueChanged();
138 void labelVisibleChanged();
139 void penChanged();
140 void brushChanged();
141 void labelBrushChanged();
142 void labelFontChanged();
143 void percentageChanged();
144 void startAngleChanged();
145 void angleSpanChanged();
146 void colorChanged();
147 void borderColorChanged();
148 void borderWidthChanged();
149 void labelColorChanged();
150
151private:
152 QPieSlicePrivate * const d_ptr;
153 Q_DECLARE_PRIVATE(QPieSlice)
154 Q_DISABLE_COPY(QPieSlice)
155};
156
157QT_CHARTS_END_NAMESPACE
158
159#endif // QPIESLICE_H
160

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