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