##// END OF EJS Templates
Documented QChart properties
Tero Ahola -
r1526:3a8d24692369
parent child
Show More
@@ -1,480 +1,493
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qchart.h"
22 22 #include "qchart_p.h"
23 23 #include "legendscroller_p.h"
24 24 #include "qlegend_p.h"
25 25 #include "chartbackground_p.h"
26 26 #include "qaxis.h"
27 27 #include <QGraphicsScene>
28 28 #include <QGraphicsSceneResizeEvent>
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 /*!
33 33 \enum QChart::ChartTheme
34 34
35 35 This enum describes the theme used by the chart.
36 36
37 37 \value ChartThemeLight The default theme
38 38 \value ChartThemeBlueCerulean
39 39 \value ChartThemeDark
40 40 \value ChartThemeBrownSand
41 41 \value ChartThemeBlueNcs
42 42 \value ChartThemeHighContrast
43 43 \value ChartThemeBlueIcy
44 44 */
45 45
46 46 /*!
47 47 \enum QChart::AnimationOption
48 48
49 49 For enabling/disabling animations. Defaults to NoAnimation.
50 50
51 51 \value NoAnimation
52 52 \value GridAxisAnimations
53 53 \value SeriesAnimations
54 54 \value AllAnimations
55 55 */
56 56
57 57 /*!
58 58 \class QChart
59 59 \brief QtCommercial chart API.
60 60
61 61 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
62 62 representation of different types of series and other chart related objects like
63 63 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
64 64 convenience class QChartView instead of QChart.
65 65 \sa QChartView
66 66 */
67 67
68 68 /*!
69 \property QChart::animationOptions
70 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
71 */
72
73 /*!
74 \property QChart::backgroundVisible
75 Whether the chart background is visible or not.
76 \sa setBackgroundBrush(), setBackgroundPen()
77 */
78
79 /*!
80 \property QChart::dropShadowEnabled
81 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
82 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
83 */
84
85 /*!
86 \property QChart::margins
87 Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes.
88 */
89
90 /*!
91 \property QChart::theme
92 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
93 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
94 different themes.
95 Note: changing the theme will overwrite all customizations previously applied to the series.
96 */
97
98 /*!
99 \property QChart::title
100 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
101 */
102
103 /*!
104 \fn void QChart::marginsChanged(QRectF newMargins)
105 The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size,
106 modify axes or hide/show legend.
107 */
108
109 /*!
69 110 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
70 111 */
71 112 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
72 113 d_ptr(new QChartPrivate())
73 114 {
74 115 d_ptr->m_dataset = new ChartDataSet(this);
75 116 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
76 117 d_ptr->createConnections();
77 118 d_ptr->m_legend = new LegendScroller(this);
78 119 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
79 120 connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
80 121 }
81 122
82 123 /*!
83 124 Destroys the object and it's children, like series and axis objects added to it.
84 125 */
85 126 QChart::~QChart()
86 127 {
87 128 //delete first presenter , since this is a root of all the graphical items
88 129 delete d_ptr->m_presenter;
89 130 d_ptr->m_presenter=0;
90 131 }
91 132
92 133 /*!
93 134 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
94 135 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
95 136 the y axis).
96 137
97 138 \sa removeSeries(), removeAllSeries()
98 139 */
99 140 void QChart::addSeries(QAbstractSeries *series, QAxis *axisY)
100 141 {
101 142 Q_ASSERT(series);
102 143 d_ptr->m_dataset->addSeries(series, axisY);
103 144 }
104 145
105 146 /*!
106 147 Removes the \a series specified in a perameter from the QChartView.
107 148 It releses its ownership of the specified QChartSeries object.
108 149 It does not delete the pointed QChartSeries data object
109 150 \sa addSeries(), removeAllSeries()
110 151 */
111 152 void QChart::removeSeries(QAbstractSeries *series)
112 153 {
113 154 Q_ASSERT(series);
114 155 d_ptr->m_dataset->removeSeries(series);
115 156 }
116 157
117 158 /*!
118 159 Removes all the QChartSeries that have been added to the QChartView
119 160 It also deletes the pointed QChartSeries data objects
120 161 \sa addSeries(), removeSeries()
121 162 */
122 163 void QChart::removeAllSeries()
123 164 {
124 165 d_ptr->m_dataset->removeAllSeries();
125 166 }
126 167
127 168 /*!
128 169 Sets the \a brush that is used for painting the background of the chart area.
129 170 */
130 171 void QChart::setBackgroundBrush(const QBrush& brush)
131 172 {
132 173 //TODO: refactor me
133 174 d_ptr->m_presenter->createChartBackgroundItem();
134 175 d_ptr->m_presenter->m_backgroundItem->setBrush(brush);
135 176 d_ptr->m_presenter->m_backgroundItem->update();
136 177 }
137 178
138 179 /*!
139 180 Gets the brush that is used for painting the background of the chart area.
140 181 */
141 182 QBrush QChart::backgroundBrush() const
142 183 {
143 184 //TODO: refactor me
144 185 if (!d_ptr->m_presenter->m_backgroundItem) return QBrush();
145 186 return (d_ptr->m_presenter->m_backgroundItem)->brush();
146 187 }
147 188
148 189 /*!
149 190 Sets the \a pen that is used for painting the background of the chart area.
150 191 */
151 192 void QChart::setBackgroundPen(const QPen& pen)
152 193 {
153 194 //TODO: refactor me
154 195 d_ptr->m_presenter->createChartBackgroundItem();
155 196 d_ptr->m_presenter->m_backgroundItem->setPen(pen);
156 197 d_ptr->m_presenter->m_backgroundItem->update();
157 198 }
158 199
159 200 /*!
160 201 Gets the pen that is used for painting the background of the chart area.
161 202 */
162 203 QPen QChart::backgroundPen() const
163 204 {
164 205 //TODO: refactor me
165 206 if (!d_ptr->m_presenter->m_backgroundItem) return QPen();
166 207 return d_ptr->m_presenter->m_backgroundItem->pen();
167 208 }
168 209
169 210 /*!
170 211 Sets the chart \a title. The description text that is drawn above the chart.
171 212 */
172 213 void QChart::setTitle(const QString& title)
173 214 {
174 215 //TODO: refactor me
175 216 d_ptr->m_presenter->createChartTitleItem();
176 217 d_ptr->m_presenter->m_titleItem->setText(title);
177 218 d_ptr->m_presenter->updateLayout();
178 219 }
179 220
180 221 /*!
181 222 Returns the chart title. The description text that is drawn above the chart.
182 223 */
183 224 QString QChart::title() const
184 225 {
185 226 //TODO: refactor me
186 227 if (d_ptr->m_presenter->m_titleItem)
187 228 return d_ptr->m_presenter->m_titleItem->text();
188 229 else
189 230 return QString();
190 231 }
191 232
192 233 /*!
193 234 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
194 235 */
195 236 void QChart::setTitleFont(const QFont& font)
196 237 {
197 238 //TODO: refactor me
198 239 d_ptr->m_presenter->createChartTitleItem();
199 240 d_ptr->m_presenter->m_titleItem->setFont(font);
200 241 d_ptr->m_presenter->updateLayout();
201 242 }
202 243
203 244 /*!
204 245 Gets the font that is used for drawing the chart description text that is rendered above the chart.
205 246 */
206 247 QFont QChart::titleFont() const
207 248 {
208 249 if (d_ptr->m_presenter->m_titleItem)
209 250 return d_ptr->m_presenter->m_titleItem->font();
210 251 else
211 252 return QFont();
212 253 }
213 254
214 255 /*!
215 256 Sets the \a brush used for rendering the title text.
216 257 */
217 258 void QChart::setTitleBrush(const QBrush &brush)
218 259 {
219 260 //TODO: refactor me
220 261 d_ptr->m_presenter->createChartTitleItem();
221 262 d_ptr->m_presenter->m_titleItem->setBrush(brush);
222 263 d_ptr->m_presenter->updateLayout();
223 264 }
224 265
225 266 /*!
226 267 Returns the brush used for rendering the title text.
227 268 */
228 269 QBrush QChart::titleBrush() const
229 270 {
230 271 //TODO: refactor me
231 272 if (!d_ptr->m_presenter->m_titleItem) return QBrush();
232 273 return d_ptr->m_presenter->m_titleItem->brush();
233 274 }
234 275
235 /*!
236 Sets the \a theme used by the chart for rendering the graphical representation of the data.
237
238 Note: changing the theme will overwrite all customizations (pen, brush, font, ect.) done to the series.
239 \sa theme()
240 */
241 276 void QChart::setTheme(QChart::ChartTheme theme)
242 277 {
243 278 d_ptr->m_presenter->setTheme(theme);
244 279 }
245 280
246 /*!
247 Returns the theme enum used by the chart.
248 \sa ChartTheme, setTheme()
249 */
250 281 QChart::ChartTheme QChart::theme() const
251 282 {
252 283 return d_ptr->m_presenter->theme();
253 284 }
254 285
255 286 /*!
256 287 Zooms in the view by a factor of 2
257 288 */
258 289 void QChart::zoomIn()
259 290 {
260 291 d_ptr->m_presenter->zoomIn(2.0);
261 292 }
262 293
263 294 /*!
264 295 Zooms in the view to a maximum level at which \a rect is still fully visible.
265 296 */
266 297 void QChart::zoomIn(const QRectF& rect)
267 298 {
268 299 if (!rect.isValid()) return;
269 300 d_ptr->m_presenter->zoomIn(rect);
270 301 }
271 302
272 303 /*!
273 304 Restores the view zoom level to the previous one.
274 305 */
275 306 void QChart::zoomOut()
276 307 {
277 308 d_ptr->m_presenter->zoomOut(2.0);
278 309 }
279 310
280 311 /*!
281 312 Zooms in the view by a \a factor.
282 313
283 314 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
284 315 */
285 316 void QChart::zoom(qreal factor)
286 317 {
287 318 if (qFuzzyIsNull(factor))
288 319 return;
289 320
290 321 if (qFuzzyCompare(factor, 1.0))
291 322 return;
292 323
293 324 if (factor < 0)
294 325 return;
295 326
296 327 if (factor > 1.0)
297 328 d_ptr->m_presenter->zoomIn(factor);
298 329 else
299 330 d_ptr->m_presenter->zoomOut(1.0 / factor);
300 331 }
301 332
302 333 /*!
303 334 Returns the pointer to the x axis object of the chart
304 335 */
305 336 QAxis* QChart::axisX() const
306 337 {
307 338 return d_ptr->m_dataset->axisX();
308 339 }
309 340
310 341 /*!
311 342 Returns the pointer to the y axis object of the \a series
312 343 If no \a series is provided then default Y axis of the chart is returned.
313 344 */
314 345 QAxis* QChart::axisY(QAbstractSeries *series) const
315 346 {
316 347 return d_ptr->m_dataset->axisY(series);
317 348 }
318 349
319 350 /*!
320 351 Returns the legend object of the chart. Ownership stays in chart.
321 352 */
322 353 QLegend* QChart::legend() const
323 354 {
324 355 return d_ptr->m_legend;
325 356 }
326 357
327 358 /*!
328 359 Returns the rect that contains information about margins (distance between chart widget edge and axes).
329 360 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
330 361 */
331 362 QRectF QChart::margins() const
332 363 {
333 364 return d_ptr->m_presenter->margins();
334 365 }
335 366
336 367
337 368 /*!
338 369 Resizes and updates the chart area using the \a event data
339 370 */
340 371 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
341 372 {
342 373 d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize());
343 374 QGraphicsWidget::resizeEvent(event);
344 375 d_ptr->m_presenter->setGeometry(d_ptr->m_rect);
345 376 }
346 377
347 /*!
348 Sets animation \a options for the chart
349 */
350 378 void QChart::setAnimationOptions(AnimationOptions options)
351 379 {
352 380 d_ptr->m_presenter->setAnimationOptions(options);
353 381 }
354 382
355 /*!
356 Returns animation options for the chart
357 */
358 383 QChart::AnimationOptions QChart::animationOptions() const
359 384 {
360 385 return d_ptr->m_presenter->animationOptions();
361 386 }
362 387
363 388 /*!
364 389 Scrolls the visible area of the chart to the left by the distance between two x axis ticks
365 390 */
366 391 void QChart::scrollLeft()
367 392 {
368 393 d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
369 394 }
370 395
371 396 /*!
372 397 Scrolls the visible area of the chart to the right by the distance between two x axis ticks
373 398 */
374 399 void QChart::scrollRight()
375 400 {
376 401 d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
377 402 }
378 403
379 404 /*!
380 405 Scrolls the visible area of the chart up by the distance between two y axis ticks
381 406 */
382 407 void QChart::scrollUp()
383 408 {
384 409 d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
385 410 }
386 411
387 412 /*!
388 413 Scrolls the visible area of the chart down by the distance between two y axis ticks
389 414 */
390 415 void QChart::scrollDown()
391 416 {
392 417 d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
393 418 }
394 419
395 420 /*!
396 421 Scrolls the visible area of the chart by the distance defined in the \a delta.
397 422 */
398 423 void QChart::scroll(const QPointF &delta)
399 424 {
400 425 d_ptr->m_presenter->scroll(-delta.x(), delta.y());
401 426 }
402 427
403 /*!
404 Sets the chart background visibility state to \a visible
405 */
406 428 void QChart::setBackgroundVisible(bool visible)
407 429 {
408 430 //TODO: refactor me
409 431 d_ptr->m_presenter->createChartBackgroundItem();
410 432 d_ptr->m_presenter->m_backgroundItem->setVisible(visible);
411 433 }
412 434
413 /*!
414 Returns the chart's background visibility state
415 */
416 435 bool QChart::isBackgroundVisible() const
417 436 {
418 437 //TODO: refactor me
419 438 if (!d_ptr->m_presenter->m_backgroundItem)
420 439 return false;
421 440
422 441 return d_ptr->m_presenter->m_backgroundItem->isVisible();
423 442 }
424 443
425 /*!
426 Sets the background drop shadow effect state to \a enabled.
427 */
428 444 void QChart::setDropShadowEnabled(bool enabled)
429 445 {
430 446 d_ptr->m_presenter->createChartBackgroundItem();
431 447 d_ptr->m_presenter->m_backgroundItem->setDropShadowEnabled(enabled);
432 448 }
433 449
434 /*!
435 Returns true if the drop shadow effect is enabled for the chart background.
436 */
437 450 bool QChart::isDropShadowEnabled() const
438 451 {
439 452 if (!d_ptr->m_presenter->m_backgroundItem)
440 453 return false;
441 454
442 455 return d_ptr->m_presenter->m_backgroundItem->isDropShadowEnabled();
443 456 }
444 457
445 458 /*!
446 459 Returns all the series that are added to the chart.
447 460
448 461 \sa addSeries(), removeSeries(), removeAllSeries()
449 462 */
450 463 QList<QAbstractSeries*> QChart::series() const
451 464 {
452 465 return d_ptr->m_dataset->series();
453 466 }
454 467
455 468 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
456 469
457 470 QChartPrivate::QChartPrivate():
458 471 m_legend(0),
459 472 m_dataset(0),
460 473 m_presenter(0)
461 474 {
462 475
463 476 }
464 477
465 478 QChartPrivate::~QChartPrivate()
466 479 {
467 480
468 481 }
469 482
470 483 void QChartPrivate::createConnections()
471 484 {
472 485 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
473 486 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*)));
474 487 QObject::connect(m_dataset,SIGNAL(axisAdded(QAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAxis*,Domain*)));
475 488 QObject::connect(m_dataset,SIGNAL(axisRemoved(QAxis*)),m_presenter,SLOT(handleAxisRemoved(QAxis*)));
476 489 }
477 490
478 491 #include "moc_qchart.cpp"
479 492
480 493 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now