1// Copyright (C) 2024 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 <QtCore/qobject.h>
8#include <QtGraphs/qgraphsglobal.h>
9#include <QtQml/qqmlengine.h>
10
11QT_BEGIN_NAMESPACE
12
13class PieRenderer;
14class QPieSlicePrivate;
15class QPieSeries;
16
17class Q_GRAPHS_EXPORT QPieSlice : public QObject
18{
19 Q_OBJECT
20 Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
21 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged FINAL)
22 Q_PROPERTY(bool labelVisible READ isLabelVisible WRITE setLabelVisible NOTIFY
23 labelVisibleChanged FINAL)
24 Q_PROPERTY(LabelPosition labelPosition READ labelPosition WRITE setLabelPosition NOTIFY
25 labelPositionChanged FINAL)
26 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged FINAL)
27 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged FINAL)
28 Q_PROPERTY(qreal labelArmLengthFactor READ labelArmLengthFactor WRITE setLabelArmLengthFactor
29 NOTIFY labelArmLengthFactorChanged FINAL)
30 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL)
31 Q_PROPERTY(
32 QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged FINAL)
33 Q_PROPERTY(
34 qreal borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged FINAL)
35 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged FINAL)
36 Q_PROPERTY(bool exploded READ isExploded WRITE setExploded NOTIFY explodedChanged FINAL)
37 Q_PROPERTY(qreal explodeDistanceFactor READ explodeDistanceFactor WRITE setExplodeDistanceFactor
38 NOTIFY explodeDistanceFactorChanged FINAL)
39 Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged FINAL)
40 Q_PROPERTY(qreal startAngle READ startAngle NOTIFY startAngleChanged FINAL)
41 Q_PROPERTY(qreal angleSpan READ angleSpan NOTIFY angleSpanChanged FINAL)
42 QML_NAMED_ELEMENT(PieSlice)
43
44public:
45 enum class LabelPosition {
46 Outside,
47 InsideHorizontal,
48 InsideTangential,
49 InsideNormal,
50 };
51 Q_ENUM(LabelPosition)
52
53 explicit QPieSlice(QObject *parent = nullptr);
54 QPieSlice(const QString &label, qreal value, QObject *parent = nullptr);
55 ~QPieSlice() override;
56
57 void setLabel(const QString &label);
58 QString label() const;
59 void setLabelVisible(bool visible = true);
60 bool isLabelVisible() const;
61 void setLabelPosition(LabelPosition position);
62 LabelPosition labelPosition();
63 void setLabelColor(QColor color);
64 QColor labelColor() const;
65 void setLabelFont(const QFont &font);
66 QFont labelFont() const;
67 void setLabelArmLengthFactor(qreal factor);
68 qreal labelArmLengthFactor() const;
69
70 void setColor(QColor color);
71 QColor color() const;
72
73 void setBorderColor(QColor color);
74 QColor borderColor() const;
75 void setBorderWidth(qreal borderWidth);
76 qreal borderWidth() const;
77
78 void setValue(qreal value);
79 qreal value() const;
80
81 void setExploded(bool exploded);
82 bool isExploded() const;
83 void setExplodeDistanceFactor(qreal factor);
84 qreal explodeDistanceFactor() const;
85
86 qreal percentage() const;
87 qreal startAngle() const;
88 qreal angleSpan() const;
89
90 QPieSeries *series() const;
91
92Q_SIGNALS:
93 void labelChanged();
94 void labelVisibleChanged();
95 void labelFontChanged();
96 void labelColorChanged();
97 void valueChanged();
98 void explodedChanged();
99 void explodeDistanceFactorChanged();
100 void percentageChanged();
101 void startAngleChanged();
102 void angleSpanChanged();
103 void sliceChanged();
104 void labelPositionChanged();
105 void labelArmLengthFactorChanged();
106 void colorChanged();
107 void borderColorChanged();
108 void borderWidthChanged();
109
110private:
111 friend class PieRenderer;
112 friend class QPieSeries;
113 friend class QPieSeriesPrivate;
114
115 Q_DECLARE_PRIVATE(QPieSlice)
116 Q_DISABLE_COPY(QPieSlice)
117};
118
119QT_END_NAMESPACE
120
121#endif // QPIESLICE_H
122

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

source code of qtgraphs/src/graphs2d/piechart/qpieslice.h