1 | // Copyright (C) 2022 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QXYSERIES_H |
5 | #define QXYSERIES_H |
6 | |
7 | #include <QtCharts/QChartGlobal> |
8 | #include <QtCharts/QAbstractSeries> |
9 | #include <QtGui/QPen> |
10 | #include <QtGui/QBrush> |
11 | #include <QtGui/QImage> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | class QModelIndex; |
15 | QT_END_NAMESPACE |
16 | |
17 | QT_BEGIN_NAMESPACE |
18 | |
19 | class QXYSeriesPrivate; |
20 | class QXYModelMapper; |
21 | |
22 | class Q_CHARTS_EXPORT QXYSeries : public QAbstractSeries |
23 | { |
24 | Q_OBJECT |
25 | Q_PROPERTY(bool pointsVisible READ pointsVisible WRITE setPointsVisible) |
26 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
27 | Q_PROPERTY(QColor selectedColor READ color WRITE setSelectedColor NOTIFY selectedColorChanged REVISION(6, 2)) |
28 | Q_PROPERTY(QString pointLabelsFormat READ pointLabelsFormat WRITE setPointLabelsFormat NOTIFY pointLabelsFormatChanged) |
29 | Q_PROPERTY(bool pointLabelsVisible READ pointLabelsVisible WRITE setPointLabelsVisible NOTIFY pointLabelsVisibilityChanged) |
30 | Q_PROPERTY(QFont pointLabelsFont READ pointLabelsFont WRITE setPointLabelsFont NOTIFY pointLabelsFontChanged) |
31 | Q_PROPERTY(QColor pointLabelsColor READ pointLabelsColor WRITE setPointLabelsColor NOTIFY pointLabelsColorChanged) |
32 | Q_PROPERTY(bool pointLabelsClipping READ pointLabelsClipping WRITE setPointLabelsClipping NOTIFY pointLabelsClippingChanged) |
33 | Q_PROPERTY(bool bestFitLineVisible READ bestFitLineVisible WRITE setBestFitLineVisible NOTIFY bestFitLineVisibilityChanged REVISION(6, 2)) |
34 | Q_PROPERTY(QColor bestFitLineColor READ bestFitLineColor WRITE setBestFitLineColor NOTIFY bestFitLineColorChanged REVISION(6, 2)) |
35 | |
36 | protected: |
37 | explicit QXYSeries(QXYSeriesPrivate &d, QObject *parent = nullptr); |
38 | |
39 | public: |
40 | enum class PointConfiguration { |
41 | Color = 0, |
42 | Size, |
43 | Visibility, |
44 | LabelVisibility, |
45 | LabelFormat |
46 | }; |
47 | Q_ENUM(PointConfiguration) |
48 | |
49 | using PointsConfigurationHash = QHash<int, QHash<PointConfiguration, QVariant>>; |
50 | |
51 | public: |
52 | ~QXYSeries(); |
53 | void append(qreal x, qreal y); |
54 | void append(const QPointF &point); |
55 | void append(const QList<QPointF> &points); |
56 | void replace(qreal oldX, qreal oldY, qreal newX, qreal newY); |
57 | void replace(const QPointF &oldPoint, const QPointF &newPoint); |
58 | void replace(int index, qreal newX, qreal newY); |
59 | void replace(int index, const QPointF &newPoint); |
60 | void remove(qreal x, qreal y); |
61 | void remove(const QPointF &point); |
62 | void remove(int index); |
63 | void removePoints(int index, int count); |
64 | void insert(int index, const QPointF &point); |
65 | void clear(); |
66 | |
67 | int count() const; |
68 | QList<QPointF> points() const; |
69 | #if QT_DEPRECATED_SINCE(6, 0) |
70 | QT_DEPRECATED_X("Use points() instead" ) |
71 | QList<QPointF> pointsVector() const; |
72 | #endif |
73 | const QPointF &at(int index) const; |
74 | |
75 | QXYSeries &operator << (const QPointF &point); |
76 | QXYSeries &operator << (const QList<QPointF> &points); |
77 | |
78 | virtual void setPen(const QPen &pen); |
79 | QPen pen() const; |
80 | |
81 | virtual void setBrush(const QBrush &brush); |
82 | QBrush brush() const; |
83 | |
84 | virtual void setColor(const QColor &color); |
85 | virtual QColor color() const; |
86 | |
87 | void setSelectedColor(const QColor &color); |
88 | QColor selectedColor() const; |
89 | |
90 | void setPointsVisible(bool visible = true); |
91 | bool pointsVisible() const; |
92 | |
93 | void setPointLabelsFormat(const QString &format); |
94 | QString pointLabelsFormat() const; |
95 | |
96 | void setPointLabelsVisible(bool visible = true); |
97 | bool pointLabelsVisible() const; |
98 | |
99 | void setPointLabelsFont(const QFont &font); |
100 | QFont pointLabelsFont() const; |
101 | |
102 | void setPointLabelsColor(const QColor &color); |
103 | QColor pointLabelsColor() const; |
104 | |
105 | void setPointLabelsClipping(bool enabled = true); |
106 | bool pointLabelsClipping() const; |
107 | |
108 | void replace(const QList<QPointF> &points); |
109 | |
110 | bool isPointSelected(int index); |
111 | void selectPoint(int index); |
112 | void deselectPoint(int index); |
113 | void setPointSelected(int index, bool selected); |
114 | void selectAllPoints(); |
115 | void deselectAllPoints(); |
116 | void selectPoints(const QList<int> &indexes); |
117 | void deselectPoints(const QList<int> &indexes); |
118 | void toggleSelection(const QList<int> &indexes); |
119 | QList<int> selectedPoints() const; |
120 | |
121 | void setLightMarker(const QImage &lightMarker); |
122 | const QImage &lightMarker() const; |
123 | |
124 | void setSelectedLightMarker(const QImage &selectedLightMarker); |
125 | const QImage &selectedLightMarker() const; |
126 | |
127 | void setMarkerSize(qreal size); |
128 | qreal markerSize() const; |
129 | |
130 | void setBestFitLineVisible(bool visible = true); |
131 | bool bestFitLineVisible() const; |
132 | QPair<qreal, qreal> bestFitLineEquation(bool &ok) const; |
133 | |
134 | void setBestFitLinePen(const QPen &pen); |
135 | QPen bestFitLinePen() const; |
136 | void setBestFitLineColor(const QColor &color); |
137 | QColor bestFitLineColor() const; |
138 | |
139 | void clearPointConfiguration(const int index); |
140 | void clearPointConfiguration(const int index, const PointConfiguration key); |
141 | void clearPointsConfiguration(); |
142 | void clearPointsConfiguration(const PointConfiguration key); |
143 | void setPointConfiguration(const int index, |
144 | const QHash<PointConfiguration, QVariant> &configuration); |
145 | void setPointConfiguration(const int index, const PointConfiguration key, |
146 | const QVariant &value); |
147 | void setPointsConfiguration( |
148 | const QHash<int, QHash<QXYSeries::PointConfiguration, QVariant>> &pointsConfiguration); |
149 | QHash<PointConfiguration, QVariant> pointConfiguration(const int index) const; |
150 | PointsConfigurationHash pointsConfiguration() const; |
151 | |
152 | void sizeBy(const QList<qreal> &sourceData, const qreal minSize, const qreal maxSize); |
153 | void colorBy(const QList<qreal> &sourceData, const QLinearGradient &gradient = QLinearGradient()); |
154 | |
155 | Q_SIGNALS: |
156 | void clicked(const QPointF &point); |
157 | void hovered(const QPointF &point, bool state); |
158 | void pressed(const QPointF &point); |
159 | void released(const QPointF &point); |
160 | void doubleClicked(const QPointF &point); |
161 | void pointReplaced(int index); |
162 | void pointRemoved(int index); |
163 | void pointAdded(int index); |
164 | void colorChanged(QColor color); |
165 | Q_REVISION(6, 2) void selectedColorChanged(const QColor &color); |
166 | void pointsReplaced(); |
167 | void pointLabelsFormatChanged(const QString &format); |
168 | void pointLabelsVisibilityChanged(bool visible); |
169 | void pointLabelsFontChanged(const QFont &font); |
170 | void pointLabelsColorChanged(const QColor &color); |
171 | void pointLabelsClippingChanged(bool clipping); |
172 | void pointsRemoved(int index, int count); |
173 | void penChanged(const QPen &pen); |
174 | void selectedPointsChanged(); |
175 | Q_REVISION(6, 2) void lightMarkerChanged(const QImage &lightMarker); |
176 | Q_REVISION(6, 2) void selectedLightMarkerChanged(const QImage &selectedLightMarker); |
177 | Q_REVISION(6, 2) void bestFitLineVisibilityChanged(bool visible); |
178 | Q_REVISION(6, 2) void bestFitLinePenChanged(const QPen &pen); |
179 | Q_REVISION(6, 2) void bestFitLineColorChanged(const QColor &color); |
180 | Q_REVISION(6, 2) void pointsConfigurationChanged( |
181 | const QXYSeries::PointsConfigurationHash &configuration); |
182 | void markerSizeChanged(qreal size); |
183 | |
184 | private: |
185 | Q_DECLARE_PRIVATE(QXYSeries) |
186 | Q_DISABLE_COPY(QXYSeries) |
187 | friend class QXYLegendMarkerPrivate; |
188 | friend class XYLegendMarker; |
189 | friend class XYChart; |
190 | friend class QColorAxisPrivate; |
191 | }; |
192 | |
193 | QT_END_NAMESPACE |
194 | |
195 | #endif // QXYSERIES_H |
196 | |