##// END OF EJS Templates
Added some missing restrictions to OpenGL series usage docs...
Miikka Heikkinen -
r2831:9aa888c2f56c
parent child
Show More
@@ -1,458 +1,462
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/QAbstractSeries>
20 20 #include <private/qabstractseries_p.h>
21 21 #include <private/chartdataset_p.h>
22 22 #include <QtCharts/QChart>
23 23 #include <private/qchart_p.h>
24 24 #include <private/chartitem_p.h>
25 25 #include <private/xydomain_p.h>
26 26 #include <private/xlogydomain_p.h>
27 27 #include <private/logxydomain_p.h>
28 28 #include <private/logxlogydomain_p.h>
29 29
30 30 QT_CHARTS_BEGIN_NAMESPACE
31 31
32 32 /*!
33 33 \class QAbstractSeries
34 34 \inmodule Qt Charts
35 35 \brief Base class for all Qt Chart series.
36 36
37 37 Usually you use the series type specific inherited classes instead of the base class.
38 38 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries,
39 39 QPercentBarSeries, QPieSeries
40 40 */
41 41 /*!
42 42 \qmltype AbstractSeries
43 43 \instantiates QAbstractSeries
44 44 \inqmlmodule QtCharts
45 45
46 46 \brief Base class for all Qt Chart series.
47 47
48 48 AbstractSeries is the base class for all series.
49 49 The class cannot be instantiated by the user.
50 50 */
51 51
52 52 /*!
53 53 \enum QAbstractSeries::SeriesType
54 54
55 55 The type of the series object.
56 56
57 57 \value SeriesTypeLine
58 58 \value SeriesTypeArea
59 59 \value SeriesTypeBar
60 60 \value SeriesTypeStackedBar
61 61 \value SeriesTypePercentBar
62 62 \value SeriesTypePie
63 63 \value SeriesTypeScatter
64 64 \value SeriesTypeSpline
65 65 \value SeriesTypeHorizontalBar
66 66 \value SeriesTypeHorizontalStackedBar
67 67 \value SeriesTypeHorizontalPercentBar
68 68 \value SeriesTypeBoxPlot
69 69 */
70 70
71 71 /*!
72 72 \property QAbstractSeries::type
73 73 The type of the series.
74 74 */
75 75 /*!
76 76 \qmlproperty ChartView.SeriesType AbstractSeries::type
77 77 The type of the series.
78 78 */
79 79
80 80 /*!
81 81 \property QAbstractSeries::name
82 82 \brief name of the series property. The name is shown in legend for series and supports html formatting.
83 83 */
84 84 /*!
85 85 \qmlproperty string AbstractSeries::name
86 86 Name of the series. The name is shown in legend for series and supports html formatting.
87 87 */
88 88
89 89 /*!
90 90 \fn void QAbstractSeries::nameChanged()
91 91 This signal is emitted when the series name changes.
92 92 */
93 93 /*!
94 94 \qmlsignal AbstractSeries::onNameChanged()
95 95 This signal is emitted when the series name changes.
96 96 */
97 97
98 98 /*!
99 99 \property QAbstractSeries::visible
100 100 \brief whether the series is visible or not; true by default.
101 101 */
102 102 /*!
103 103 \qmlproperty bool AbstractSeries::visible
104 104 Visibility of the series. True by default.
105 105 */
106 106
107 107 /*!
108 108 \fn void QAbstractSeries::visibleChanged()
109 109 Emitted when the series visibility changes.
110 110 */
111 111 /*!
112 112 \qmlsignal AbstractSeries::onVisibleChanged()
113 113 Emitted when the series visibility changes.
114 114 */
115 115
116 116 /*!
117 117 \property QAbstractSeries::opacity
118 118 \brief The opacity of the series.
119 119
120 120 By default the opacity is 1.0. The valid values range from 0.0 (transparent) to 1.0 (opaque).
121 121 */
122 122 /*!
123 123 \qmlproperty real AbstractSeries::opacity
124 124 The opacity of the series. By default the opacity is 1.0.
125 125 The valid values range from 0.0 (transparent) to 1.0 (opaque).
126 126 */
127 127
128 128 /*!
129 129 \fn void QAbstractSeries::opacityChanged()
130 130 Emitted when the opacity of the series changes.
131 131 */
132 132 /*!
133 133 \qmlsignal AbstractSeries::onOpacityChanged()
134 134 Emitted when the opacity of the series changes.
135 135 */
136 136
137 137 /*!
138 138 \property QAbstractSeries::useOpenGL
139 139 \brief Specifies whether or not the series drawing is accelerated with OpenGL.
140 140
141 141 Drawing series with OpenGL is supported only for QLineSeries and QScatterSeries.
142 142 Line series used as edge series for a QAreaSeries cannot use OpenGL acceleration.
143 143 When a chart contains any series that are drawn with OpenGL, a transparent QOpenGLWidget
144 144 is created on top of the chart plot area. Specified series are not drawn on the underlying
145 145 QGraphicsView, but are instead drawn on the created QOpenGLWidget.
146 146
147 147 Performance gained from using OpenGL to accelerate series drawing depends on the underlying
148 148 hardware, but in most cases it is significant. For example, on a standard desktop computer,
149 149 enabling OpenGL acceleration for a series typically allows rendering at least hundred times
150 150 more points without reduction on the frame rate.
151 151 Chart size also has less effect on the frame rate.
152 152
153 153 The OpenGL acceleration of series drawing is meant for use cases that need fast drawing of
154 154 large numbers of points. It is optimized for efficiency, and therefore the series using
155 155 it lack support for some features available to non-accelerated series.
156 156
157 157 There are the following restrictions imposed on charts and series when using OpenGL
158 158 acceleration:
159 159
160 160 \list
161 161 \li Series animations are not supported for accelerated series.
162 162 \li Antialiasing is not supported for accelerated series.
163 \li Point labels are not supported for accelerated series.
163 164 \li Pen styles and marker shapes are ignored for accelerated series.
164 165 Only solid lines and plain scatter dots are supported.
165 166 The scatter dots may be circular or rectangular, depending on the underlying graphics
166 167 hardware and drivers.
167 168 \li Polar charts are not supported for accelerated series.
169 \li Mouse events are not supported for accelerated series.
168 170 \li Since the accelerated series are drawn on top of the entire graphics view, they get drawn
169 171 on top of any other graphics items that you may have on top chart in the same scene.
170 172 \li To enable QOpenGLWidget to be partially transparent, it needs to be stacked on top of
171 173 all other widgets. This means you cannot have other widgets partially covering the
172 174 chart.
175 \li Enabling chart drop shadow is not recommended when using accelerated series,
176 as that can slow the frame rate down significantly.
173 177 \endlist
174 178
175 179 The default value is \c{false}.
176 180 */
177 181 /*!
178 182 \qmlproperty bool AbstractSeries::useOpenGL
179 183 Specifies whether or not the series is drawn with OpenGL.
180 184
181 185 Drawing series with OpenGL is supported only for LineSeries and ScatterSeries.
182 186
183 187 For more details, see QAbstractSeries::useOpenGL documentation. QML applications have similar
184 188 restrictions as those listed in QAbstractSeries::useOpenGL documentation,
185 189 except there is no restriction about covering the ChartView partially with other
186 190 items due to different rendering mechanism.
187 191
188 192 The default value is \c{false}.
189 193 */
190 194
191 195 /*!
192 196 \fn void QAbstractSeries::useOpenGLChanged()
193 197 Emitted when the useOpenGL property value changes.
194 198 */
195 199 /*!
196 200 \qmlsignal AbstractSeries::onUseOpenGLChanged()
197 201 Emitted when the useOpenGL property value changes.
198 202 */
199 203
200 204 /*!
201 205 \internal
202 206 \brief Constructs QAbstractSeries object with \a parent.
203 207 */
204 208 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) :
205 209 QObject(parent),
206 210 d_ptr(&d)
207 211 {
208 212 }
209 213
210 214 /*!
211 215 \brief Virtual destructor for the chart series.
212 216 */
213 217 QAbstractSeries::~QAbstractSeries()
214 218 {
215 219 if (d_ptr->m_chart)
216 220 qFatal("Series still bound to a chart when destroyed!");
217 221 }
218 222
219 223 void QAbstractSeries::setName(const QString &name)
220 224 {
221 225 if (name != d_ptr->m_name) {
222 226 d_ptr->m_name = name;
223 227 emit nameChanged();
224 228 }
225 229 }
226 230
227 231 QString QAbstractSeries::name() const
228 232 {
229 233 return d_ptr->m_name;
230 234 }
231 235
232 236 void QAbstractSeries::setVisible(bool visible)
233 237 {
234 238 if (visible != d_ptr->m_visible) {
235 239 d_ptr->m_visible = visible;
236 240 emit visibleChanged();
237 241 }
238 242 }
239 243
240 244 bool QAbstractSeries::isVisible() const
241 245 {
242 246 return d_ptr->m_visible;
243 247 }
244 248
245 249 qreal QAbstractSeries::opacity() const
246 250 {
247 251 return d_ptr->m_opacity;
248 252 }
249 253
250 254 void QAbstractSeries::setOpacity(qreal opacity)
251 255 {
252 256 if (opacity != d_ptr->m_opacity) {
253 257 d_ptr->m_opacity = opacity;
254 258 emit opacityChanged();
255 259 }
256 260 }
257 261
258 262 void QAbstractSeries::setUseOpenGL(bool enable)
259 263 {
260 264 #ifdef QT_NO_OPENGL
261 265 Q_UNUSED(enable)
262 266 #else
263 267 bool polarChart = d_ptr->m_chart && d_ptr->m_chart->chartType() == QChart::ChartTypePolar;
264 268 bool supportedSeries = (type() == SeriesTypeLine || type() == SeriesTypeScatter);
265 269 if ((!enable || !d_ptr->m_blockOpenGL)
266 270 && supportedSeries
267 271 && enable != d_ptr->m_useOpenGL
268 272 && (!enable || !polarChart)) {
269 273 d_ptr->m_useOpenGL = enable;
270 274 emit useOpenGLChanged();
271 275 }
272 276 #endif
273 277 }
274 278
275 279 bool QAbstractSeries::useOpenGL() const
276 280 {
277 281 return d_ptr->m_useOpenGL;
278 282 }
279 283
280 284 /*!
281 285 \brief Returns the chart where series belongs to.
282 286
283 287 Set automatically when the series is added to the chart
284 288 and unset when the series is removed from the chart.
285 289 */
286 290 QChart *QAbstractSeries::chart() const
287 291 {
288 292 return d_ptr->m_chart;
289 293 }
290 294
291 295 /*!
292 296 \brief Sets the visibility of the series to true.
293 297
294 298 \sa setVisible(), isVisible()
295 299 */
296 300 void QAbstractSeries::show()
297 301 {
298 302 setVisible(true);
299 303 }
300 304
301 305 /*!
302 306 \brief Sets the visibility of the series to false.
303 307
304 308 \sa setVisible(), isVisible()
305 309 */
306 310 void QAbstractSeries::hide()
307 311 {
308 312 setVisible(false);
309 313 }
310 314
311 315 /*!
312 316 Attach \a axis to the series.
313 317 \return true if the axis was attached successfully, false otherwise.
314 318 \note If multiple axes of same orientation are attached to same series,
315 319 they will have same min/max ranges.
316 320 \sa QChart::addAxis(), QChart::createDefaultAxes()
317 321 */
318 322 bool QAbstractSeries::attachAxis(QAbstractAxis* axis)
319 323 {
320 324 if(d_ptr->m_chart) {
321 325 return d_ptr->m_chart->d_ptr->m_dataset->attachAxis(this, axis);
322 326 } else {
323 327 qWarning()<<"Series not in the chart. Please addSeries to chart first.";
324 328 return false;
325 329 }
326 330 }
327 331
328 332 /*!
329 333 Detach \a axis from the series.
330 334 \return true if the axis was detached successfully, false otherwise.
331 335 \sa QChart::removeAxis()
332 336 */
333 337 bool QAbstractSeries::detachAxis(QAbstractAxis* axis)
334 338 {
335 339 if(d_ptr->m_chart) {
336 340 return d_ptr->m_chart->d_ptr->m_dataset->detachAxis(this, axis);
337 341 }
338 342 else {
339 343 qWarning()<<"Series not in the chart. Please addSeries to chart first.";
340 344 return false;
341 345 }
342 346 }
343 347
344 348 /*!
345 349 Returns the list of axes attached to the series. Usually there is an x-axis and a y-axis attached to a series, except
346 350 in case of a QPieSeries, which does not have any axes attached.
347 351 \sa attachAxis(), detachAxis()
348 352 */
349 353 QList<QAbstractAxis*> QAbstractSeries::attachedAxes()
350 354 {
351 355 return d_ptr->m_axes;
352 356 }
353 357
354 358 ///////////////////////////////////////////////////////////////////////////////////////////////////
355 359
356 360 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries *q)
357 361 : q_ptr(q),
358 362 m_chart(0),
359 363 m_item(0),
360 364 m_domain(new XYDomain()),
361 365 m_visible(true),
362 366 m_opacity(1.0),
363 367 m_useOpenGL(false),
364 368 m_blockOpenGL(false)
365 369 {
366 370 }
367 371
368 372 QAbstractSeriesPrivate::~QAbstractSeriesPrivate()
369 373 {
370 374 }
371 375
372 376 void QAbstractSeriesPrivate::setDomain(AbstractDomain* domain)
373 377 {
374 378 Q_ASSERT(domain);
375 379 if(m_domain.data()!=domain) {
376 380 if(!m_item.isNull()) QObject::disconnect(m_domain.data(), SIGNAL(updated()), m_item.data(), SLOT(handleDomainUpdated()));
377 381 m_domain.reset(domain);
378 382 if(!m_item.isNull()) {
379 383 QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated()));
380 384 m_item->handleDomainUpdated();
381 385 }
382 386 }
383 387 }
384 388
385 389 void QAbstractSeriesPrivate::setPresenter(ChartPresenter *presenter)
386 390 {
387 391 m_presenter = presenter;
388 392 }
389 393
390 394 ChartPresenter *QAbstractSeriesPrivate::presenter() const
391 395 {
392 396 return m_presenter;
393 397 }
394 398
395 399 void QAbstractSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
396 400 {
397 401 Q_ASSERT(!m_item.isNull());
398 402 Q_UNUSED(parent);
399 403 QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated()));
400 404 }
401 405
402 406 void QAbstractSeriesPrivate::initializeAnimations(QChart::AnimationOptions options, int duration,
403 407 QEasingCurve &curve)
404 408 {
405 409 Q_UNUSED(options);
406 410 Q_UNUSED(duration);
407 411 Q_UNUSED(curve);
408 412 }
409 413
410 414 bool QAbstractSeriesPrivate::reverseXAxis()
411 415 {
412 416 bool reverseXAxis = false;
413 417 if (m_axes.size() != 0 && !(m_chart->chartType() == QChart::ChartTypePolar)) {
414 418 int i = 0;
415 419 while (i < m_axes.size()) {
416 420 if (m_axes.at(i)->orientation() == Qt::Horizontal && m_axes.at(i)->isReverse()) {
417 421 reverseXAxis = true;
418 422 break;
419 423 }
420 424 i++;
421 425 }
422 426 }
423 427
424 428 return reverseXAxis;
425 429 }
426 430
427 431 bool QAbstractSeriesPrivate::reverseYAxis()
428 432 {
429 433 bool reverseYAxis = false;
430 434 if (m_axes.size() != 0 && !(m_chart->chartType() == QChart::ChartTypePolar)) {
431 435 int i = 0;
432 436 while (i < m_axes.size()) {
433 437 if (m_axes.at(i)->orientation() == Qt::Vertical && m_axes.at(i)->isReverse()) {
434 438 reverseYAxis = true;
435 439 break;
436 440 }
437 441 i++;
438 442 }
439 443 }
440 444
441 445 return reverseYAxis;
442 446 }
443 447
444 448 // This function can be used to explicitly block OpenGL use from some otherwise supported series,
445 449 // such as the line series used as edge series of an area series.
446 450 void QAbstractSeriesPrivate::setBlockOpenGL(bool enable)
447 451 {
448 452 m_blockOpenGL = enable;
449 453 if (enable)
450 454 q_ptr->setUseOpenGL(false);
451 455 }
452 456
453 457 #include "moc_qabstractseries.cpp"
454 458 #include "moc_qabstractseries_p.cpp"
455 459
456 460 QT_CHARTS_END_NAMESPACE
457 461
458 462
General Comments 0
You need to be logged in to leave comments. Login now