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 | #include <QtCharts/QAreaSeries> |
31 | #include <private/qareaseries_p.h> |
32 | #include <QtCharts/QLineSeries> |
33 | #include <private/areachartitem_p.h> |
34 | #include <private/abstractdomain_p.h> |
35 | #include <private/chartdataset_p.h> |
36 | #include <private/charttheme_p.h> |
37 | #include <QtCharts/QValueAxis> |
38 | #include <QtCharts/QAreaLegendMarker> |
39 | #include <private/qchart_p.h> |
40 | |
41 | QT_CHARTS_BEGIN_NAMESPACE |
42 | |
43 | /*! |
44 | \class QAreaSeries |
45 | \inmodule QtCharts |
46 | \brief The QAreaSeries class presents data in area charts. |
47 | |
48 | An area series is used to show quantitative data. It is based on a line series, in the way that |
49 | the area between the boundary lines is emphasized with color. Since the area series is based on |
50 | the line series, the QAreaSeries constructor needs a QLineSeries instance, which defines the |
51 | \e upper boundary of the area. The area chart is drawn using the bottom of the plot area as the |
52 | \e lower boundary by default. Instead of the bottom of the plot area, the lower boundary can be |
53 | specified by another line. In that case, QAreaSeries should be initialized with two QLineSeries |
54 | instances. |
55 | |
56 | \note The terms \e upper and \e lower boundary can be misleading in cases where the value of the |
57 | lower boundary is greater than that of the upper boundary. The main point is that the |
58 | area between these two boundary lines will be filled. |
59 | |
60 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. |
61 | \image examples_areachart.png |
62 | */ |
63 | |
64 | /*! |
65 | \qmltype AreaSeries |
66 | \instantiates QAreaSeries |
67 | \inqmlmodule QtCharts |
68 | |
69 | \inherits AbstractSeries |
70 | |
71 | \brief Presents data in area charts. |
72 | |
73 | An area series is used to show quantitative data. It is based on a line |
74 | series, in the way that the area between the boundary lines is emphasized |
75 | with color. The LineSeries type defines the \e upper boundary of the |
76 | area. The area chart is drawn using the bottom of the plot area as the |
77 | \e lower boundary by default. Instead of the bottom of the plot area, the |
78 | lower boundary can be specified by another line. In that case, the |
79 | AreaSeries should use two LineSeries types. |
80 | |
81 | \note The terms \e upper and \e lower boundary can be misleading in cases |
82 | where the value of the lower boundary is greater than that of the upper |
83 | boundary. The main point is that the area between these two boundary lines |
84 | will be filled. |
85 | |
86 | \image examples_qmlchart4.png |
87 | |
88 | The following QML shows how to create a simple area chart: |
89 | \snippet qmlchart/qml/qmlchart/View4.qml 1 |
90 | |
91 | \note Adding the same line series to a chart and area series is not supported. The series used as |
92 | boundary lines should be defined only for the area series. |
93 | */ |
94 | |
95 | /*! |
96 | \qmlproperty AbstractAxis AreaSeries::axisX |
97 | The x-axis used for the series. If you leave both axisX and axisXTop |
98 | undefined, a value axis is created for the series. |
99 | \sa axisXTop, ValueAxis |
100 | */ |
101 | |
102 | /*! |
103 | \qmlproperty AbstractAxis AreaSeries::axisY |
104 | The y-axis used for the series. If you leave both axisY and axisYRight |
105 | undefined, a value axis is created for the series. |
106 | \sa axisYRight, ValueAxis |
107 | */ |
108 | |
109 | /*! |
110 | \qmlproperty AbstractAxis AreaSeries::axisXTop |
111 | The x-axis used for the series, drawn on top of the chart view. |
112 | |
113 | \note You can only provide either axisX or axisXTop, not both. |
114 | \sa axisX |
115 | */ |
116 | |
117 | /*! |
118 | \qmlproperty AbstractAxis AreaSeries::axisYRight |
119 | The y-axis used for the series, drawn to the right on the chart view. |
120 | |
121 | \note You can only provide either axisY or axisYRight, not both. |
122 | \sa axisY |
123 | */ |
124 | |
125 | /*! |
126 | \qmlproperty AbstractAxis AreaSeries::axisAngular |
127 | The angular axis used for the series, drawn around the polar chart view. |
128 | \sa axisX, PolarChartView |
129 | */ |
130 | |
131 | /*! |
132 | \qmlproperty AbstractAxis AreaSeries::axisRadial |
133 | The radial axis used for the series, drawn inside the polar chart view. |
134 | \sa axisY, PolarChartView |
135 | */ |
136 | |
137 | /*! |
138 | \property QAreaSeries::upperSeries |
139 | \brief The upper one of the two line series used to define area series boundaries. |
140 | */ |
141 | /*! |
142 | \qmlproperty LineSeries AreaSeries::upperSeries |
143 | The upper one of the two line series used to define area series boundaries. |
144 | */ |
145 | |
146 | /*! |
147 | \property QAreaSeries::lowerSeries |
148 | \brief The lower one of the two line series used to define area series boundaries. |
149 | |
150 | \note If QAreaSeries was constructed without a\ lowerSeries, this is null. |
151 | */ |
152 | /*! |
153 | \qmlproperty LineSeries AreaSeries::lowerSeries |
154 | The lower one of the two line series used to define area series boundaries. |
155 | |
156 | \note If AreaSeries was constructed without a\ lowerSeries, this is null. |
157 | */ |
158 | |
159 | /*! |
160 | \property QAreaSeries::color |
161 | \brief The fill (brush) color of the series. This is a convenience property for modifying the |
162 | color of the brush. |
163 | \sa QAreaSeries::brush() |
164 | */ |
165 | /*! |
166 | \qmlproperty color AreaSeries::color |
167 | Fill (brush) color of the series. |
168 | */ |
169 | |
170 | /*! |
171 | \property QAreaSeries::borderColor |
172 | \brief The line (pen) color of the series. This is a convenience property for modifying the |
173 | color of the pen. |
174 | \sa QAreaSeries::pen() |
175 | */ |
176 | /*! |
177 | \qmlproperty color AreaSeries::borderColor |
178 | Line (pen) color of the series. |
179 | */ |
180 | |
181 | /*! |
182 | \qmlproperty real AreaSeries::borderWidth |
183 | The width of the border line. By default, the width is 2.0. |
184 | */ |
185 | |
186 | /*! |
187 | \fn QPen QAreaSeries::pen() const |
188 | \brief Returns the pen used to draw the line for this series. |
189 | \sa setPen() |
190 | */ |
191 | |
192 | /*! |
193 | \fn QPen QAreaSeries::brush() const |
194 | \brief Returns the brush used to draw the line for this series. |
195 | \sa setBrush() |
196 | */ |
197 | |
198 | /*! |
199 | \qmlproperty brush AreaSeries::brush |
200 | The brush used to draw to draw the line for this series. |
201 | */ |
202 | |
203 | /*! |
204 | \qmlproperty QString AreaSeries::brushFilename |
205 | The name of the file used as a brush image for the series. |
206 | */ |
207 | |
208 | /*! |
209 | \fn void QAreaSeries::colorChanged(QColor color) |
210 | \brief This signal is emitted when the fill (brush) color changes to \a color. |
211 | */ |
212 | |
213 | /*! |
214 | \fn void QAreaSeries::borderColorChanged(QColor color) |
215 | \brief This signal is emitted when the line (pen) color changes to \a color. |
216 | */ |
217 | |
218 | /*! |
219 | \fn void QAreaSeries::clicked(const QPointF& point) |
220 | \brief This signal is emitted when the user triggers a press on \a point by clicking it in an |
221 | area chart. |
222 | \sa pressed, released, doubleClicked |
223 | */ |
224 | /*! |
225 | \qmlsignal AreaSeries::clicked(point point) |
226 | This signal is emitted when the user triggers a press on \a point by clicking it in an |
227 | area chart. |
228 | |
229 | The corresponding signal handler is \c {onClicked}. |
230 | |
231 | \sa pressed, released, doubleClicked |
232 | */ |
233 | |
234 | /*! |
235 | \fn void QAreaSeries::hovered(const QPointF &point, bool state) |
236 | This signal is emitted when the user hovers the mouse cursor over a series or moves it away from |
237 | the series. \a point shows the origin (coordinate) of the hover event. \a state is \c true when |
238 | the cursor hovers over the series and turns \e false when it moves away from the series. |
239 | */ |
240 | /*! |
241 | \qmlsignal AreaSeries::hovered(point point, bool state) |
242 | This signal is emitted when the user hovers the mouse cursor over a series or moves it away from |
243 | the series. \a point shows the origin (coordinate) of the hover event. \a state is \c true when |
244 | the cursor hovers over the series and turns \e false when it moves away from the series. |
245 | |
246 | The corresponding signal handler is \c {onHovered}. |
247 | */ |
248 | |
249 | /*! |
250 | \fn void QAreaSeries::pressed(const QPointF& point) |
251 | \brief This signal is emitted when the user presses the point specified by \a point |
252 | in an area chart. |
253 | \sa clicked, released, doubleClicked |
254 | */ |
255 | /*! |
256 | \qmlsignal AreaSeries::pressed(point point) |
257 | This signal is emitted when the user presses the point specified by \a point in an area chart. |
258 | |
259 | The corresponding signal handler is \c {onPressed}. |
260 | |
261 | \sa clicked, released, doubleClicked |
262 | */ |
263 | |
264 | /*! |
265 | \fn void QAreaSeries::released(const QPointF& point) |
266 | \brief This signal is emitted when the user releases a press that was triggered on |
267 | \a point in an area chart. |
268 | \sa pressed, clicked, doubleClicked |
269 | */ |
270 | /*! |
271 | \qmlsignal AreaSeries::released(point point) |
272 | This signal is emitted when the user releases a press that was triggered on |
273 | \a point in an area chart. |
274 | |
275 | The corresponding signal handler is \c {onReleased}. |
276 | |
277 | \sa pressed, clicked, doubleClicked |
278 | */ |
279 | |
280 | /*! |
281 | \fn void QAreaSeries::doubleClicked(const QPointF& point) |
282 | \brief This signal is emitted when the user triggers the first press in an area chart |
283 | by doubleclicking \a point. |
284 | \sa pressed, released, clicked |
285 | */ |
286 | /*! |
287 | \qmlsignal AreaSeries::doubleClicked(point point) |
288 | This signal is emitted when the user triggers the first press in an area chart |
289 | by doubleclicking \a point. |
290 | |
291 | The corresponding signal handler is \c {onDoubleClicked}. |
292 | |
293 | \sa pressed, released, clicked |
294 | */ |
295 | |
296 | /*! |
297 | \fn void QAreaSeries::selected() |
298 | \internal |
299 | */ |
300 | |
301 | /*! |
302 | \fn void QAreaSeriesPrivate::updated() |
303 | \internal |
304 | */ |
305 | |
306 | /*! |
307 | \property QAreaSeries::pointLabelsFormat |
308 | \brief The format used for showing labels with series points. |
309 | |
310 | QAreaSeries supports the following format tags: |
311 | \table |
312 | \row |
313 | \li @xPoint \li The x value of the data point |
314 | \row |
315 | \li @yPoint \li The y value of the data point |
316 | \endtable |
317 | |
318 | For example, the following usage of the format tags would produce labels that have the data |
319 | point (x, y) shown inside brackets separated by a comma: |
320 | \code |
321 | series->setPointLabelsFormat("(@xPoint, @yPoint)"); |
322 | \endcode |
323 | |
324 | By default, the label format is set to \c{@xPoint, @yPoint}. The labels are shown on the plot |
325 | area, whereas labels on the edge of the plot area are cut. If the points are close to each |
326 | other, the labels may overlap. |
327 | |
328 | \sa QAreaSeries::pointLabelsVisible, QAreaSeries::pointLabelsFont, QAreaSeries::pointLabelsColor |
329 | */ |
330 | /*! |
331 | \qmlproperty string AreaSeries::pointLabelsFormat |
332 | The format used for showing labels with series points. |
333 | |
334 | \sa QAreaSeries::pointLabelsFormat, pointLabelsVisible, pointLabelsFont, pointLabelsColor |
335 | */ |
336 | /*! |
337 | \fn void QAreaSeries::pointLabelsFormatChanged(const QString &format) |
338 | This signal is emitted when the \a format of data point labels is changed. |
339 | */ |
340 | |
341 | /*! |
342 | \property QAreaSeries::pointLabelsVisible |
343 | \brief The visibility of data point labels. False by default. |
344 | |
345 | \sa QAreaSeries::pointLabelsFormat, QAreaSeries::pointLabelsClipping |
346 | */ |
347 | /*! |
348 | \qmlproperty bool AreaSeries::pointLabelsVisible |
349 | Defines the visibility of data point labels. |
350 | |
351 | \sa pointLabelsFormat, pointLabelsClipping |
352 | */ |
353 | /*! |
354 | \fn void QAreaSeries::pointLabelsVisibilityChanged(bool visible) |
355 | This signal is emitted when the visibility of the data point labels changes to \a visible. |
356 | */ |
357 | |
358 | /*! |
359 | \property QAreaSeries::pointLabelsFont |
360 | \brief The font used for data point labels. |
361 | |
362 | \sa QAreaSeries::pointLabelsFormat |
363 | */ |
364 | /*! |
365 | \qmlproperty font AreaSeries::pointLabelsFont |
366 | Defines the font used for data point labels. |
367 | |
368 | \sa pointLabelsFormat |
369 | */ |
370 | /*! |
371 | \fn void QAreaSeries::pointLabelsFontChanged(const QFont &font); |
372 | This signal is emitted when the font used for data point labels changes to \a font. |
373 | */ |
374 | |
375 | /*! |
376 | \property QAreaSeries::pointLabelsColor |
377 | \brief The color used for data point labels. By default, the color is the color of the brush |
378 | defined for labels in the theme. |
379 | |
380 | \sa QAreaSeries::pointLabelsFormat |
381 | */ |
382 | /*! |
383 | \qmlproperty font AreaSeries::pointLabelsColor |
384 | Defines the color used for data point labels. By default, the color is the color of the brush |
385 | defined for labels in the theme. |
386 | |
387 | \sa pointLabelsFormat |
388 | */ |
389 | /*! |
390 | \fn void QAreaSeries::pointLabelsColorChanged(const QColor &color); |
391 | This signal is emitted when the color used for data point labels changes to \a color. |
392 | */ |
393 | |
394 | /*! |
395 | \property QAreaSeries::pointLabelsClipping |
396 | \brief The clipping for data point labels. True by default. The labels on the edge of the plot |
397 | area are cut when clipping is enabled. |
398 | |
399 | \sa pointLabelsVisible |
400 | */ |
401 | /*! |
402 | \qmlproperty bool AreaSeries::pointLabelsClipping |
403 | Defines the clipping for data point labels. True by default. The labels on the edge of the plot |
404 | area are cut when clipping is enabled. |
405 | |
406 | \sa pointLabelsVisible |
407 | */ |
408 | /*! |
409 | \fn void QAreaSeries::pointLabelsClippingChanged(bool clipping) |
410 | This signal is emitted when the clipping of the data point labels changes to \a clipping. |
411 | */ |
412 | |
413 | /*! |
414 | Constructs an area series object that will be spanned between an \a upperSeries line and a |
415 | \a lowerSeries line. If no \a lowerSeries is passed to the constructor, the x-axis is used |
416 | as the lower bound instead. |
417 | |
418 | The QAreaSeries does not own the upper or lower series, but the ownership stays with the caller. |
419 | When the series object is added to QChartView or QChart, the instance ownership is transferred. |
420 | */ |
421 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) |
422 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries) |
423 | { |
424 | if (upperSeries) |
425 | upperSeries->d_ptr->setBlockOpenGL(true); |
426 | if (lowerSeries) |
427 | lowerSeries->d_ptr->setBlockOpenGL(true); |
428 | } |
429 | |
430 | /*! |
431 | Constructs an area series object without an upper or a lower series with the \a parent object. |
432 | */ |
433 | QAreaSeries::QAreaSeries(QObject *parent) |
434 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) |
435 | { |
436 | } |
437 | |
438 | /*! |
439 | Destroys the object. |
440 | */ |
441 | QAreaSeries::~QAreaSeries() |
442 | { |
443 | Q_D(QAreaSeries); |
444 | if (d->m_chart) |
445 | d->m_chart->removeSeries(series: this); |
446 | } |
447 | |
448 | /*! |
449 | Returns QAbstractSeries::SeriesTypeArea. |
450 | */ |
451 | QAbstractSeries::SeriesType QAreaSeries::type() const |
452 | { |
453 | return QAbstractSeries::SeriesTypeArea; |
454 | } |
455 | |
456 | /*! |
457 | Sets the \a series that is to be used as the area chart upper series. |
458 | If the upper series is null, the area chart is not drawn, even if it has a lower series. |
459 | */ |
460 | void QAreaSeries::setUpperSeries(QLineSeries *series) |
461 | { |
462 | Q_D(QAreaSeries); |
463 | |
464 | if (d->m_upperSeries != series) { |
465 | if (series) |
466 | series->d_ptr->setBlockOpenGL(true); |
467 | d->m_upperSeries = series; |
468 | if (!d->m_item.isNull()) |
469 | static_cast<AreaChartItem *>(d->m_item.data())->setUpperSeries(series); |
470 | } |
471 | } |
472 | |
473 | QLineSeries *QAreaSeries::upperSeries() const |
474 | { |
475 | Q_D(const QAreaSeries); |
476 | return d->m_upperSeries; |
477 | } |
478 | |
479 | /*! |
480 | Sets the \a series that is to be used as the area chart lower series. |
481 | */ |
482 | void QAreaSeries::setLowerSeries(QLineSeries *series) |
483 | { |
484 | Q_D(QAreaSeries); |
485 | if (d->m_lowerSeries != series) { |
486 | if (series) |
487 | series->d_ptr->setBlockOpenGL(true); |
488 | d->m_lowerSeries = series; |
489 | if (!d->m_item.isNull()) |
490 | static_cast<AreaChartItem *>(d->m_item.data())->setLowerSeries(series); |
491 | } |
492 | } |
493 | |
494 | QLineSeries *QAreaSeries::lowerSeries() const |
495 | { |
496 | Q_D(const QAreaSeries); |
497 | return d->m_lowerSeries; |
498 | } |
499 | |
500 | /*! |
501 | Sets the \a pen used for drawing the area outline. |
502 | */ |
503 | void QAreaSeries::setPen(const QPen &pen) |
504 | { |
505 | Q_D(QAreaSeries); |
506 | if (d->m_pen != pen) { |
507 | bool emitColorChanged = pen.color() != d->m_pen.color(); |
508 | d->m_pen = pen; |
509 | emit d->updated(); |
510 | if (emitColorChanged) |
511 | emit borderColorChanged(color: pen.color()); |
512 | } |
513 | } |
514 | |
515 | QPen QAreaSeries::pen() const |
516 | { |
517 | Q_D(const QAreaSeries); |
518 | if (d->m_pen == QChartPrivate::defaultPen()) |
519 | return QPen(); |
520 | else |
521 | return d->m_pen; |
522 | } |
523 | |
524 | /*! |
525 | Sets the \a brush used for filling the area. |
526 | */ |
527 | void QAreaSeries::setBrush(const QBrush &brush) |
528 | { |
529 | Q_D(QAreaSeries); |
530 | if (d->m_brush != brush) { |
531 | bool emitColorChanged = brush.color() != d->m_brush.color(); |
532 | d->m_brush = brush; |
533 | emit d->updated(); |
534 | if (emitColorChanged) |
535 | emit colorChanged(color: brush.color()); |
536 | } |
537 | } |
538 | |
539 | QBrush QAreaSeries::brush() const |
540 | { |
541 | Q_D(const QAreaSeries); |
542 | if (d->m_brush == QChartPrivate::defaultBrush()) |
543 | return QBrush(); |
544 | else |
545 | return d->m_brush; |
546 | } |
547 | |
548 | void QAreaSeries::setColor(const QColor &color) |
549 | { |
550 | QBrush b = brush(); |
551 | if (b == QBrush()) |
552 | b.setStyle(Qt::SolidPattern); |
553 | b.setColor(color); |
554 | setBrush(b); |
555 | } |
556 | |
557 | QColor QAreaSeries::color() const |
558 | { |
559 | return brush().color(); |
560 | } |
561 | |
562 | void QAreaSeries::setBorderColor(const QColor &color) |
563 | { |
564 | QPen p = pen(); |
565 | p.setColor(color); |
566 | setPen(p); |
567 | } |
568 | |
569 | QColor QAreaSeries::borderColor() const |
570 | { |
571 | return pen().color(); |
572 | } |
573 | |
574 | /*! |
575 | Determines whether data points are \a visible and should be drawn on the line. |
576 | */ |
577 | void QAreaSeries::setPointsVisible(bool visible) |
578 | { |
579 | Q_D(QAreaSeries); |
580 | if (d->m_pointsVisible != visible) { |
581 | d->m_pointsVisible = visible; |
582 | emit d->updated(); |
583 | } |
584 | } |
585 | |
586 | /*! |
587 | Returns whether the points are drawn for this series. |
588 | \sa setPointsVisible() |
589 | */ |
590 | bool QAreaSeries::pointsVisible() const |
591 | { |
592 | Q_D(const QAreaSeries); |
593 | return d->m_pointsVisible; |
594 | } |
595 | |
596 | void QAreaSeries::setPointLabelsFormat(const QString &format) |
597 | { |
598 | Q_D(QAreaSeries); |
599 | if (d->m_pointLabelsFormat != format) { |
600 | d->m_pointLabelsFormat = format; |
601 | emit pointLabelsFormatChanged(format); |
602 | } |
603 | } |
604 | |
605 | QString QAreaSeries::pointLabelsFormat() const |
606 | { |
607 | Q_D(const QAreaSeries); |
608 | return d->m_pointLabelsFormat; |
609 | } |
610 | |
611 | void QAreaSeries::setPointLabelsVisible(bool visible) |
612 | { |
613 | Q_D(QAreaSeries); |
614 | if (d->m_pointLabelsVisible != visible) { |
615 | d->m_pointLabelsVisible = visible; |
616 | emit pointLabelsVisibilityChanged(visible); |
617 | } |
618 | } |
619 | |
620 | bool QAreaSeries::pointLabelsVisible() const |
621 | { |
622 | Q_D(const QAreaSeries); |
623 | return d->m_pointLabelsVisible; |
624 | } |
625 | |
626 | void QAreaSeries::setPointLabelsFont(const QFont &font) |
627 | { |
628 | Q_D(QAreaSeries); |
629 | if (d->m_pointLabelsFont != font) { |
630 | d->m_pointLabelsFont = font; |
631 | emit pointLabelsFontChanged(font); |
632 | } |
633 | } |
634 | |
635 | QFont QAreaSeries::pointLabelsFont() const |
636 | { |
637 | Q_D(const QAreaSeries); |
638 | return d->m_pointLabelsFont; |
639 | } |
640 | |
641 | void QAreaSeries::setPointLabelsColor(const QColor &color) |
642 | { |
643 | Q_D(QAreaSeries); |
644 | if (d->m_pointLabelsColor != color) { |
645 | d->m_pointLabelsColor = color; |
646 | emit pointLabelsColorChanged(color); |
647 | } |
648 | } |
649 | |
650 | QColor QAreaSeries::pointLabelsColor() const |
651 | { |
652 | Q_D(const QAreaSeries); |
653 | if (d->m_pointLabelsColor == QChartPrivate::defaultPen().color()) |
654 | return QPen().color(); |
655 | else |
656 | return d->m_pointLabelsColor; |
657 | } |
658 | |
659 | void QAreaSeries::setPointLabelsClipping(bool enabled) |
660 | { |
661 | Q_D(QAreaSeries); |
662 | if (d->m_pointLabelsClipping != enabled) { |
663 | d->m_pointLabelsClipping = enabled; |
664 | emit pointLabelsClippingChanged(clipping: enabled); |
665 | } |
666 | } |
667 | |
668 | bool QAreaSeries::pointLabelsClipping() const |
669 | { |
670 | Q_D(const QAreaSeries); |
671 | return d->m_pointLabelsClipping; |
672 | } |
673 | |
674 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
675 | |
676 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q) |
677 | : QAbstractSeriesPrivate(q), |
678 | m_brush(QChartPrivate::defaultBrush()), |
679 | m_pen(QChartPrivate::defaultPen()), |
680 | m_upperSeries(upperSeries), |
681 | m_lowerSeries(lowerSeries), |
682 | m_pointsVisible(false), |
683 | m_pointLabelsFormat(QLatin1String("@xPoint, @yPoint" )), |
684 | m_pointLabelsVisible(false), |
685 | m_pointLabelsFont(QChartPrivate::defaultFont()), |
686 | m_pointLabelsColor(QChartPrivate::defaultPen().color()), |
687 | m_pointLabelsClipping(true) |
688 | { |
689 | } |
690 | |
691 | void QAreaSeriesPrivate::initializeDomain() |
692 | { |
693 | Q_Q(QAreaSeries); |
694 | |
695 | qreal minX(0.0); |
696 | qreal minY(0.0); |
697 | qreal maxX(1.0); |
698 | qreal maxY(1.0); |
699 | |
700 | QLineSeries *upperSeries = q->upperSeries(); |
701 | QLineSeries *lowerSeries = q->lowerSeries(); |
702 | |
703 | if (upperSeries) { |
704 | const QVector<QPointF> &points = upperSeries->pointsVector(); |
705 | |
706 | if (!points.isEmpty()) { |
707 | minX = points[0].x(); |
708 | minY = points[0].y(); |
709 | maxX = minX; |
710 | maxY = minY; |
711 | |
712 | for (int i = 0; i < points.count(); i++) { |
713 | qreal x = points[i].x(); |
714 | qreal y = points[i].y(); |
715 | minX = qMin(a: minX, b: x); |
716 | minY = qMin(a: minY, b: y); |
717 | maxX = qMax(a: maxX, b: x); |
718 | maxY = qMax(a: maxY, b: y); |
719 | } |
720 | } |
721 | } |
722 | if (lowerSeries) { |
723 | const QVector<QPointF> &points = lowerSeries->pointsVector(); |
724 | |
725 | if (!points.isEmpty()) { |
726 | if (!upperSeries) { |
727 | minX = points[0].x(); |
728 | minY = points[0].y(); |
729 | maxX = minX; |
730 | maxY = minY; |
731 | } |
732 | |
733 | for (int i = 0; i < points.count(); i++) { |
734 | qreal x = points[i].x(); |
735 | qreal y = points[i].y(); |
736 | minX = qMin(a: minX, b: x); |
737 | minY = qMin(a: minY, b: y); |
738 | maxX = qMax(a: maxX, b: x); |
739 | maxY = qMax(a: maxY, b: y); |
740 | } |
741 | } |
742 | } |
743 | |
744 | domain()->setRange(minX, maxX, minY, maxY); |
745 | } |
746 | |
747 | void QAreaSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
748 | { |
749 | Q_Q(QAreaSeries); |
750 | AreaChartItem *area = new AreaChartItem(q,parent); |
751 | m_item.reset(other: area); |
752 | QAbstractSeriesPrivate::initializeGraphics(parent); |
753 | } |
754 | void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options, int duration, |
755 | QEasingCurve &curve) |
756 | { |
757 | Q_Q(QAreaSeries); |
758 | AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data()); |
759 | |
760 | if (q->upperSeries() && area->upperLineItem()->animation()) |
761 | area->upperLineItem()->animation()->stopAndDestroyLater(); |
762 | if (q->lowerSeries() && area->lowerLineItem()->animation()) |
763 | area->lowerLineItem()->animation()->stopAndDestroyLater(); |
764 | |
765 | if (options.testFlag(flag: QChart::SeriesAnimations)) { |
766 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem(), duration, |
767 | curve)); |
768 | if (q->lowerSeries()) |
769 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem(), duration, |
770 | curve)); |
771 | } else { |
772 | if (q->upperSeries()) |
773 | area->upperLineItem()->setAnimation(0); |
774 | if (q->lowerSeries()) |
775 | area->lowerLineItem()->setAnimation(0); |
776 | } |
777 | QAbstractSeriesPrivate::initializeAnimations(options, duration, curve); |
778 | } |
779 | |
780 | QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend) |
781 | { |
782 | Q_Q(QAreaSeries); |
783 | QList<QLegendMarker*> list; |
784 | return list << new QAreaLegendMarker(q,legend); |
785 | } |
786 | |
787 | |
788 | void QAreaSeriesPrivate::initializeAxes() |
789 | { |
790 | |
791 | } |
792 | |
793 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
794 | { |
795 | Q_UNUSED(orientation); |
796 | return QAbstractAxis::AxisTypeValue; |
797 | } |
798 | |
799 | QAbstractAxis* QAreaSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
800 | { |
801 | Q_UNUSED(orientation); |
802 | return new QValueAxis; |
803 | } |
804 | |
805 | void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
806 | { |
807 | Q_Q(QAreaSeries); |
808 | |
809 | const QList<QGradient> gradients = theme->seriesGradients(); |
810 | const QList<QColor> colors = theme->seriesColors(); |
811 | |
812 | if (forced || QChartPrivate::defaultPen() == m_pen) { |
813 | QPen pen; |
814 | pen.setColor(ChartThemeManager::colorAt(gradient: gradients.at(i: index % gradients.size()), pos: 0.0)); |
815 | pen.setWidthF(2); |
816 | q->setPen(pen); |
817 | } |
818 | |
819 | if (forced || QChartPrivate::defaultBrush() == m_brush) { |
820 | QBrush brush(colors.at(i: index % colors.size())); |
821 | q->setBrush(brush); |
822 | } |
823 | |
824 | if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) { |
825 | QColor color = theme->labelBrush().color(); |
826 | q->setPointLabelsColor(color); |
827 | } |
828 | } |
829 | |
830 | QT_CHARTS_END_NAMESPACE |
831 | |
832 | #include "moc_qareaseries.cpp" |
833 | #include "moc_qareaseries_p.cpp" |
834 | |