1 | // Copyright (C) 2024 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include <QtGraphs/qareaseries.h> |
5 | #include <private/qareaseries_p.h> |
6 | #include <private/qgraphsview_p.h> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | /*! |
11 | \class QAreaSeries |
12 | \inmodule QtGraphs |
13 | \ingroup graphs_2D |
14 | \brief The QAreaSeries class presents data in area graphs. |
15 | |
16 | An area graph is used to draw an area composed by points. |
17 | The points are defined by two series: upperSeries and lowerSeries. |
18 | The area between the series is drawn as a graph. If only the upperSeries |
19 | is defined, the area is then between the bottom of the graph and the upper series. |
20 | */ |
21 | /*! |
22 | \qmltype AreaSeries |
23 | \nativetype QAreaSeries |
24 | \inqmlmodule QtGraphs |
25 | \ingroup graphs_qml_2D |
26 | \inherits AbstractSeries |
27 | |
28 | \brief Presents data in area graphs. |
29 | |
30 | An area graph is used to draw an area composed by points. |
31 | The points are defined by two series: upperSeries and lowerSeries. |
32 | The area between the series is drawn as a graph. If only the upperSeries |
33 | is defined, the area is then between the bottom of the graph and the upper series. |
34 | |
35 | \image graphs2d-area.png |
36 | */ |
37 | |
38 | /*! |
39 | \property QAreaSeries::color |
40 | \brief The fill color of the area. |
41 | The default value is \c Qt::transparent, meaning the color is defined by the theme. |
42 | */ |
43 | /*! |
44 | \qmlproperty color AreaSeries::color |
45 | The fill color of the area. |
46 | The default value is \c transparent, meaning the color is defined by the theme. |
47 | */ |
48 | |
49 | /*! |
50 | \property QAreaSeries::selectedColor |
51 | \brief The fill color of the area when selected. |
52 | The default value is \c Qt::transparent, meaning the selected color is defined by the theme. |
53 | */ |
54 | /*! |
55 | \qmlproperty color AreaSeries::selectedColor |
56 | The fill color of the area when selected. |
57 | The default value is \c transparent, meaning the selected color is defined by the theme. |
58 | */ |
59 | |
60 | /*! |
61 | \property QAreaSeries::borderColor |
62 | \brief The border color of the area. |
63 | The default value is \c Qt::transparent, meaning the border color is defined by the theme. |
64 | */ |
65 | /*! |
66 | \qmlproperty color AreaSeries::borderColor |
67 | The border color of the area. |
68 | The default value is \c transparent, meaning the border color is defined by the theme. |
69 | */ |
70 | |
71 | /*! |
72 | \property QAreaSeries::selectedBorderColor |
73 | \brief The border color of the area when selected. |
74 | The default value is \c Qt::transparent, meaning the selected border color is defined by the theme. |
75 | */ |
76 | /*! |
77 | \qmlproperty color AreaSeries::selectedBorderColor |
78 | The border color of the area when selected. |
79 | The default value is \c transparent, meaning the selected border color is defined by the theme. |
80 | */ |
81 | |
82 | /*! |
83 | \property QAreaSeries::borderWidth |
84 | \brief The width of the line that encloses the area. |
85 | The default value is \c -1, meaning the border width is defined by the theme. |
86 | */ |
87 | /*! |
88 | \qmlproperty real AreaSeries::borderWidth |
89 | The width of the line that encloses the area. |
90 | The default value is \c -1, meaning the border width is defined by the theme. |
91 | */ |
92 | |
93 | /*! |
94 | \property QAreaSeries::selected |
95 | \brief Sets this area as selected. |
96 | The default value is \c false. |
97 | */ |
98 | /*! |
99 | \qmlproperty bool AreaSeries::selected |
100 | Sets this area as selected. |
101 | The default value is \c false. |
102 | */ |
103 | |
104 | /*! |
105 | \property QAreaSeries::upperSeries |
106 | \brief Sets the upper boundary of the area. No area is drawn if this is null. |
107 | */ |
108 | /*! |
109 | \qmlproperty XYSeries AreaSeries::upperSeries |
110 | Sets the upper boundary of the area. No area is drawn if this is null. |
111 | */ |
112 | |
113 | /*! |
114 | \property QAreaSeries::lowerSeries |
115 | \brief Sets the lower boundary of the area. If this is null, the graph bottom |
116 | is considered the lower bound. |
117 | */ |
118 | /*! |
119 | \qmlproperty XYSeries AreaSeries::lowerSeries |
120 | Sets the lower boundary of the area. If this is null, the graph bottom |
121 | is considered the lower bound. |
122 | */ |
123 | |
124 | /*! |
125 | \qmlsignal AreaSeries::colorChanged(color newColor) |
126 | This signal is emitted when the area \l color changes to \a newColor. |
127 | */ |
128 | |
129 | /*! |
130 | \qmlsignal AreaSeries::selectedColorChanged(color newSelectedColor) |
131 | This signal is emitted when the color of a selected area changes to |
132 | \a newSelectedColor. |
133 | */ |
134 | |
135 | /*! |
136 | \qmlsignal AreaSeries::borderColorChanged(color newBorderColor) |
137 | This signal is emitted when the area border color changes to |
138 | \a newBorderColor. |
139 | */ |
140 | |
141 | /*! |
142 | \qmlsignal AreaSeries::selectedBorderColorChanged(color newSelectedBorderColor); |
143 | This signal is emitted when the border color of a selected area changes to |
144 | \a newSelectedBorderColor. |
145 | */ |
146 | |
147 | /*! |
148 | \qmlsignal AreaSeries::borderWidthChanged(); |
149 | This signal is emitted when the width of the area border width changes. |
150 | */ |
151 | |
152 | /*! |
153 | \qmlsignal AreaSeries::selectedChanged(); |
154 | This signal is emitted when the current area is selected. |
155 | */ |
156 | |
157 | /*! |
158 | \qmlsignal AreaSeries::upperSeriesChanged(); |
159 | This signal is emitted when the upper series changes. |
160 | */ |
161 | |
162 | /*! |
163 | \qmlsignal AreaSeries::lowerSeriesChanged(); |
164 | This signal is emitted when the lower series changes. |
165 | */ |
166 | |
167 | QAreaSeries::QAreaSeries(QObject *parent) |
168 | : QAbstractSeries(*(new QAreaSeriesPrivate()), parent) |
169 | {} |
170 | |
171 | QAreaSeries::~QAreaSeries() {} |
172 | |
173 | QAreaSeries::QAreaSeries(QAreaSeriesPrivate &dd, QObject *parent) |
174 | : QAbstractSeries(dd, parent) |
175 | {} |
176 | |
177 | QAbstractSeries::SeriesType QAreaSeries::type() const |
178 | { |
179 | return QAbstractSeries::SeriesType::Area; |
180 | } |
181 | |
182 | QColor QAreaSeries::color() const |
183 | { |
184 | Q_D(const QAreaSeries); |
185 | return d->m_color; |
186 | } |
187 | |
188 | void QAreaSeries::setColor(QColor newColor) |
189 | { |
190 | Q_D(QAreaSeries); |
191 | if (color() != newColor) { |
192 | d->m_color = newColor; |
193 | emit colorChanged(newColor); |
194 | } |
195 | } |
196 | |
197 | QColor QAreaSeries::selectedColor() const |
198 | { |
199 | Q_D(const QAreaSeries); |
200 | return d->m_selectedColor; |
201 | } |
202 | |
203 | void QAreaSeries::setSelectedColor(QColor newSelectedColor) |
204 | { |
205 | Q_D(QAreaSeries); |
206 | if (selectedColor() != newSelectedColor) { |
207 | d->m_selectedColor = newSelectedColor; |
208 | emit selectedColorChanged(newSelectedColor); |
209 | } |
210 | } |
211 | |
212 | QColor QAreaSeries::borderColor() const |
213 | { |
214 | Q_D(const QAreaSeries); |
215 | return d->m_borderColor; |
216 | } |
217 | |
218 | void QAreaSeries::setBorderColor(QColor newBorderColor) |
219 | { |
220 | Q_D(QAreaSeries); |
221 | if (d->m_borderColor == newBorderColor) |
222 | return; |
223 | d->m_borderColor = newBorderColor; |
224 | emit borderColorChanged(newBorderColor); |
225 | } |
226 | |
227 | QColor QAreaSeries::selectedBorderColor() const |
228 | { |
229 | Q_D(const QAreaSeries); |
230 | return d->m_selectedBorderColor; |
231 | } |
232 | |
233 | void QAreaSeries::setSelectedBorderColor(QColor newSelectedBorderColor) |
234 | { |
235 | Q_D(QAreaSeries); |
236 | if (d->m_selectedBorderColor == newSelectedBorderColor) |
237 | return; |
238 | d->m_selectedBorderColor = newSelectedBorderColor; |
239 | emit selectedBorderColorChanged(newSelectedBorderColor); |
240 | } |
241 | |
242 | qreal QAreaSeries::borderWidth() const |
243 | { |
244 | Q_D(const QAreaSeries); |
245 | return d->m_borderWidth; |
246 | } |
247 | |
248 | void QAreaSeries::setBorderWidth(qreal newBorderWidth) |
249 | { |
250 | Q_D(QAreaSeries); |
251 | if (qFuzzyCompare(p1: d->m_borderWidth, p2: newBorderWidth)) |
252 | return; |
253 | d->m_borderWidth = newBorderWidth; |
254 | emit borderWidthChanged(); |
255 | } |
256 | |
257 | bool QAreaSeries::isSelected() const |
258 | { |
259 | Q_D(const QAreaSeries); |
260 | return d->m_selected; |
261 | } |
262 | |
263 | void QAreaSeries::setSelected(bool newSelected) |
264 | { |
265 | Q_D(QAreaSeries); |
266 | if (d->m_selected == newSelected) |
267 | return; |
268 | d->m_selected = newSelected; |
269 | emit selectedChanged(); |
270 | } |
271 | |
272 | QXYSeries *QAreaSeries::upperSeries() const |
273 | { |
274 | Q_D(const QAreaSeries); |
275 | return d->m_upperSeries; |
276 | } |
277 | |
278 | void QAreaSeries::setUpperSeries(QXYSeries *newUpperSeries) |
279 | { |
280 | Q_D(QAreaSeries); |
281 | if (d->m_upperSeries == newUpperSeries) |
282 | return; |
283 | |
284 | if (d->m_upperSeries) |
285 | disconnect(sender: newUpperSeries, signal: &QXYSeries::update, receiver: this, slot: &QAreaSeries::update); |
286 | |
287 | d->m_upperSeries = newUpperSeries; |
288 | |
289 | connect(sender: newUpperSeries, signal: &QXYSeries::update, context: this, slot: &QAreaSeries::update); |
290 | |
291 | emit upperSeriesChanged(); |
292 | } |
293 | |
294 | QXYSeries *QAreaSeries::lowerSeries() const |
295 | { |
296 | Q_D(const QAreaSeries); |
297 | return d->m_lowerSeries; |
298 | } |
299 | |
300 | void QAreaSeries::setLowerSeries(QXYSeries *newLowerSeries) |
301 | { |
302 | Q_D(QAreaSeries); |
303 | if (d->m_lowerSeries == newLowerSeries) |
304 | return; |
305 | |
306 | if (d->m_lowerSeries) |
307 | disconnect(sender: newLowerSeries, signal: &QXYSeries::update, receiver: this, slot: &QAreaSeries::update); |
308 | |
309 | d->m_lowerSeries = newLowerSeries; |
310 | |
311 | connect(sender: newLowerSeries, signal: &QXYSeries::update, context: this, slot: &QAreaSeries::update); |
312 | |
313 | emit lowerSeriesChanged(); |
314 | } |
315 | |
316 | QAreaSeriesPrivate::QAreaSeriesPrivate() {} |
317 | |
318 | QT_END_NAMESPACE |
319 | |