1 | // Copyright (C) 2024 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QPIESERIES_H |
5 | #define QPIESERIES_H |
6 | |
7 | #include <QtGraphs/qabstractseries.h> |
8 | #include <QtGraphs/qgraphsglobal.h> |
9 | #include <QtGraphs/qpieslice.h> |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | class QPieSeriesPrivate; |
14 | |
15 | class Q_GRAPHS_EXPORT QPieSeries : public QAbstractSeries |
16 | { |
17 | Q_OBJECT |
18 | Q_PROPERTY(qreal horizontalPosition READ horizontalPosition WRITE setHorizontalPosition NOTIFY |
19 | horizontalPositionChanged FINAL) |
20 | Q_PROPERTY(qreal verticalPosition READ verticalPosition WRITE setVerticalPosition NOTIFY |
21 | verticalPositionChanged FINAL) |
22 | Q_PROPERTY(qreal pieSize READ pieSize WRITE setPieSize NOTIFY pieSizeChanged FINAL) |
23 | Q_PROPERTY(qreal startAngle READ startAngle WRITE setStartAngle NOTIFY startAngleChanged FINAL) |
24 | Q_PROPERTY(qreal endAngle READ endAngle WRITE setEndAngle NOTIFY endAngleChanged FINAL) |
25 | Q_PROPERTY(qsizetype count READ count NOTIFY countChanged FINAL) |
26 | Q_PROPERTY(qreal sum READ sum NOTIFY sumChanged FINAL) |
27 | Q_PROPERTY(qreal holeSize READ holeSize WRITE setHoleSize NOTIFY holeSizeChanged FINAL) |
28 | QML_NAMED_ELEMENT(PieSeries) |
29 | |
30 | public: |
31 | explicit QPieSeries(QObject *parent = nullptr); |
32 | ~QPieSeries() override; |
33 | QAbstractSeries::SeriesType type() const override; |
34 | |
35 | Q_INVOKABLE bool append(QPieSlice *slice); |
36 | Q_INVOKABLE bool append(const QList<QPieSlice *> &slices); |
37 | Q_INVOKABLE bool insert(qsizetype index, QPieSlice *slice); |
38 | Q_INVOKABLE bool remove(QPieSlice *slice); |
39 | Q_INVOKABLE void clear(); |
40 | Q_INVOKABLE QPieSlice *append(const QString &label, qreal value); |
41 | Q_INVOKABLE QPieSlice *at(qsizetype index); |
42 | Q_INVOKABLE QPieSlice *find(const QString &label); |
43 | Q_INVOKABLE bool replace(qsizetype index, QPieSlice *slice); |
44 | Q_INVOKABLE void removeMultiple(qsizetype index, int count); |
45 | Q_INVOKABLE bool remove(qsizetype index); |
46 | Q_INVOKABLE bool replace(QPieSlice *oldSlice, QPieSlice *newSlice); |
47 | Q_INVOKABLE bool replace(const QList<QPieSlice *> &slices); |
48 | Q_INVOKABLE bool take(QPieSlice *slice); |
49 | |
50 | QPieSeries &operator<<(QPieSlice *slice); |
51 | |
52 | QList<QPieSlice *> slices() const; |
53 | qsizetype count() const; |
54 | |
55 | bool isEmpty() const; |
56 | |
57 | qreal sum() const; |
58 | |
59 | void setHorizontalPosition(qreal relativePosition); |
60 | qreal horizontalPosition() const; |
61 | |
62 | void setVerticalPosition(qreal relativePosition); |
63 | qreal verticalPosition() const; |
64 | void setPieSize(qreal relativeSize); |
65 | qreal pieSize() const; |
66 | |
67 | void setStartAngle(qreal startAngle); |
68 | qreal startAngle() const; |
69 | |
70 | void setEndAngle(qreal endAngle); |
71 | qreal endAngle() const; |
72 | |
73 | void setHoleSize(qreal holeSize); |
74 | qreal holeSize() const; |
75 | |
76 | void setLabelsVisible(bool visible); |
77 | void setLabelsPosition(QPieSlice::LabelPosition position); |
78 | |
79 | public Q_SLOTS: |
80 | void handleSliceChange(); |
81 | |
82 | protected: |
83 | QPieSeries(QPieSeriesPrivate &dd, QObject *parent = nullptr); |
84 | void componentComplete() override; |
85 | |
86 | Q_SIGNALS: |
87 | void added(const QList<QPieSlice *> &slices); |
88 | void removed(const QList<QPieSlice *> &slices); |
89 | void replaced(const QList<QPieSlice *> &slices); |
90 | void countChanged(); |
91 | void sumChanged(); |
92 | void pieSizeChanged(); |
93 | void startAngleChanged(); |
94 | void endAngleChanged(); |
95 | void horizontalPositionChanged(); |
96 | void verticalPositionChanged(); |
97 | void holeSizeChanged(); |
98 | |
99 | private: |
100 | friend class PieRenderer; |
101 | Q_DECLARE_PRIVATE(QPieSeries) |
102 | Q_DISABLE_COPY(QPieSeries) |
103 | }; |
104 | |
105 | QT_END_NAMESPACE |
106 | |
107 | #endif // QPIESERIES_H |
108 | |