##// END OF EJS Templates
Updated QChart margins documentation
sauimone -
r1971:8d30e80f6da9
parent child
Show More
@@ -1,505 +1,499
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 "qabstractaxis.h"
27 27 #include <QGraphicsScene>
28 28 #include <QGraphicsSceneResizeEvent>
29 29 #include <QGraphicsLayout>
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 33 /*!
34 34 \enum QChart::ChartTheme
35 35
36 36 This enum describes the theme used by the chart.
37 37
38 38 \value ChartThemeLight The default theme
39 39 \value ChartThemeBlueCerulean
40 40 \value ChartThemeDark
41 41 \value ChartThemeBrownSand
42 42 \value ChartThemeBlueNcs
43 43 \value ChartThemeHighContrast
44 44 \value ChartThemeBlueIcy
45 45 */
46 46
47 47 /*!
48 48 \enum QChart::AnimationOption
49 49
50 50 For enabling/disabling animations. Defaults to NoAnimation.
51 51
52 52 \value NoAnimation
53 53 \value GridAxisAnimations
54 54 \value SeriesAnimations
55 55 \value AllAnimations
56 56 */
57 57
58 58 /*!
59 59 \class QChart
60 60 \brief QtCommercial chart API.
61 61
62 62 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
63 63 representation of different types of series and other chart related objects like
64 64 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
65 65 convenience class QChartView instead of QChart.
66 66 \sa QChartView
67 67 */
68 68
69 69 /*!
70 70 \property QChart::animationOptions
71 71 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
72 72 */
73 73
74 74 /*!
75 75 \property QChart::backgroundVisible
76 76 Whether the chart background is visible or not.
77 77 \sa setBackgroundBrush(), setBackgroundPen()
78 78 */
79 79
80 80 /*!
81 81 \property QChart::dropShadowEnabled
82 82 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
83 83 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
84 84 */
85 85
86 86 /*!
87 \property QChart::margins
88 Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes.
87 \property QChart::minimumMargins
88 Minimum margins between the plot area (axes) and the edge of the chart widget.
89 89 */
90 90
91 91 /*!
92 92 \property QChart::theme
93 93 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
94 94 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
95 95 different themes.
96 96 Note: changing the theme will overwrite all customizations previously applied to the series.
97 97 */
98 98
99 99 /*!
100 100 \property QChart::title
101 101 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
102 102 */
103 103
104 104 /*!
105 \fn void QChart::marginsChanged(QRectF newMargins)
106 The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size,
107 modify axes or hide/show legend.
108 */
109
110 /*!
111 105 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
112 106 */
113 107 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
114 108 d_ptr(new QChartPrivate())
115 109 {
116 110 d_ptr->m_dataset = new ChartDataSet(this);
117 111 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
118 112 d_ptr->createConnections();
119 113 d_ptr->m_legend = new LegendScroller(this);
120 114 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
121 115 //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
122 116 setLayout(d_ptr->m_presenter->layout());
123 117 }
124 118
125 119 /*!
126 120 Destroys the object and it's children, like series and axis objects added to it.
127 121 */
128 122 QChart::~QChart()
129 123 {
130 124 //delete first presenter , since this is a root of all the graphical items
131 125 setLayout(0);
132 126 delete d_ptr->m_presenter;
133 127 d_ptr->m_presenter=0;
134 128 }
135 129
136 130 /*!
137 131 Adds the \a series onto the chart and takes the ownership of the object.
138 132 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
139 133 the y axis).
140 134
141 135 \sa removeSeries(), removeAllSeries()
142 136 */
143 137 void QChart::addSeries(QAbstractSeries *series)
144 138 {
145 139 Q_ASSERT(series);
146 140 d_ptr->m_dataset->addSeries(series);
147 141 }
148 142
149 143 /*!
150 144 Removes the \a series specified in a perameter from the QChartView.
151 145 It releses its ownership of the specified QChartSeries object.
152 146 It does not delete the pointed QChartSeries data object
153 147 \sa addSeries(), removeAllSeries()
154 148 */
155 149 void QChart::removeSeries(QAbstractSeries *series)
156 150 {
157 151 Q_ASSERT(series);
158 152 d_ptr->m_dataset->removeSeries(series);
159 153 }
160 154
161 155 /*!
162 156 Removes all the QChartSeries that have been added to the QChartView
163 157 It also deletes the pointed QChartSeries data objects
164 158 \sa addSeries(), removeSeries()
165 159 */
166 160 void QChart::removeAllSeries()
167 161 {
168 162 d_ptr->m_dataset->removeAllSeries();
169 163 }
170 164
171 165 /*!
172 166 Sets the \a brush that is used for painting the background of the chart area.
173 167 */
174 168 void QChart::setBackgroundBrush(const QBrush& brush)
175 169 {
176 170 d_ptr->m_presenter->setBackgroundBrush(brush);
177 171 }
178 172
179 173 /*!
180 174 Gets the brush that is used for painting the background of the chart area.
181 175 */
182 176 QBrush QChart::backgroundBrush() const
183 177 {
184 178 return d_ptr->m_presenter->backgroundBrush();
185 179 }
186 180
187 181 /*!
188 182 Sets the \a pen that is used for painting the background of the chart area.
189 183 */
190 184 void QChart::setBackgroundPen(const QPen& pen)
191 185 {
192 186 d_ptr->m_presenter->setBackgroundPen(pen);
193 187 }
194 188
195 189 /*!
196 190 Gets the pen that is used for painting the background of the chart area.
197 191 */
198 192 QPen QChart::backgroundPen() const
199 193 {
200 194 return d_ptr->m_presenter->backgroundPen();
201 195 }
202 196
203 197 /*!
204 198 Sets the chart \a title. The description text that is drawn above the chart.
205 199 */
206 200 void QChart::setTitle(const QString& title)
207 201 {
208 202 d_ptr->m_presenter->setTitle(title);
209 203 }
210 204
211 205 /*!
212 206 Returns the chart title. The description text that is drawn above the chart.
213 207 */
214 208 QString QChart::title() const
215 209 {
216 210 return d_ptr->m_presenter->title();
217 211 }
218 212
219 213 /*!
220 214 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
221 215 */
222 216 void QChart::setTitleFont(const QFont& font)
223 217 {
224 218 d_ptr->m_presenter->setTitleFont(font);
225 219 }
226 220
227 221 /*!
228 222 Gets the font that is used for drawing the chart description text that is rendered above the chart.
229 223 */
230 224 QFont QChart::titleFont() const
231 225 {
232 226 return d_ptr->m_presenter->titleFont();
233 227 }
234 228
235 229 /*!
236 230 Sets the \a brush used for rendering the title text.
237 231 */
238 232 void QChart::setTitleBrush(const QBrush &brush)
239 233 {
240 234 d_ptr->m_presenter->setTitleBrush(brush);
241 235 }
242 236
243 237 /*!
244 238 Returns the brush used for rendering the title text.
245 239 */
246 240 QBrush QChart::titleBrush() const
247 241 {
248 242 return d_ptr->m_presenter->titleBrush();
249 243 }
250 244
251 245 void QChart::setTheme(QChart::ChartTheme theme)
252 246 {
253 247 d_ptr->m_presenter->setTheme(theme);
254 248 }
255 249
256 250 QChart::ChartTheme QChart::theme() const
257 251 {
258 252 return d_ptr->m_presenter->theme();
259 253 }
260 254
261 255 /*!
262 256 Zooms in the view by a factor of 2
263 257 */
264 258 void QChart::zoomIn()
265 259 {
266 260 d_ptr->m_presenter->zoomIn(2.0);
267 261 }
268 262
269 263 /*!
270 264 Zooms in the view to a maximum level at which \a rect is still fully visible.
271 265 */
272 266 void QChart::zoomIn(const QRectF& rect)
273 267 {
274 268 if (!rect.isValid()) return;
275 269 d_ptr->m_presenter->zoomIn(rect);
276 270 }
277 271
278 272 /*!
279 273 Restores the view zoom level to the previous one.
280 274 */
281 275 void QChart::zoomOut()
282 276 {
283 277 d_ptr->m_presenter->zoomOut(2.0);
284 278 }
285 279
286 280 /*!
287 281 Zooms in the view by a \a factor.
288 282
289 283 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
290 284 */
291 285 void QChart::zoom(qreal factor)
292 286 {
293 287 if (qFuzzyIsNull(factor))
294 288 return;
295 289
296 290 if (qFuzzyCompare(factor, (qreal)1.0))
297 291 return;
298 292
299 293 if (factor < 0)
300 294 return;
301 295
302 296 if (factor > 1.0)
303 297 d_ptr->m_presenter->zoomIn(factor);
304 298 else
305 299 d_ptr->m_presenter->zoomOut(1.0 / factor);
306 300 }
307 301
308 302 /*!
309 303 Returns the pointer to the x axis object of the chart asociated with the specified \a series
310 304 If no series is provided then pointer to currently visible axis is provided
311 305 */
312 306 QAbstractAxis* QChart::axisX(QAbstractSeries* series) const
313 307 {
314 308 return d_ptr->m_dataset->axisX(series);
315 309 }
316 310
317 311 /*!
318 312 Returns the pointer to the y axis object of the chart asociated with the specified \a series
319 313 If no series is provided then pointer to currently visible axis is provided
320 314 */
321 315 QAbstractAxis* QChart::axisY(QAbstractSeries *series) const
322 316 {
323 317 return d_ptr->m_dataset->axisY(series);
324 318 }
325 319
326 320 /*!
327 321 NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL.
328 322
329 323 Creates the axes for the chart based on the series that has already been added to the chart.
330 324
331 325 \table
332 326 \header
333 327 \o Series type
334 328 \o X-axis
335 329 \o Y-axis
336 330 \row
337 331 \o QXYSeries
338 332 \o QValueAxis
339 333 \o QValueAxis
340 334 \row
341 335 \o QBarSeries
342 336 \o QBarCategoryAxis
343 337 \o QValueAxis
344 338 \row
345 339 \o QPieSeries
346 340 \o None
347 341 \o None
348 342 \endtable
349 343
350 344 If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created.
351 345 If there are sevaral series added of different types then each series gets its own axes pair.
352 346
353 347 NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown.
354 348
355 349 Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls.
356 350 QPieSeries does not create any axes.
357 351
358 352 \sa axisX(), axisY(), setAxisX(), setAxisY()
359 353 */
360 354 void QChart::createDefaultAxes()
361 355 {
362 356 d_ptr->m_dataset->createDefaultAxes();
363 357 }
364 358
365 359 /*!
366 360 Returns the legend object of the chart. Ownership stays in chart.
367 361 */
368 362 QLegend* QChart::legend() const
369 363 {
370 364 return d_ptr->m_legend;
371 365 }
372 366
373 367 /*!
374 368 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
375 369 */
376 370 void QChart::setMinimumMargins(const QMargins& margins)
377 371 {
378 372 d_ptr->m_presenter->setMinimumMargins(margins);
379 373 }
380 374
381 375 /*!
382 376 Returns the rect that contains information about margins (distance between chart widget edge and axes).
383 377 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
384 378 */
385 379 QMargins QChart::minimumMargins() const
386 380 {
387 381 return d_ptr->m_presenter->minimumMargins();
388 382 }
389 383
390 384 /*!
391 385 Returns the the rect within which the drawing of the chart is done.
392 386 It does not include the area defines by margins.
393 387 */
394 388 QRectF QChart::plotArea() const
395 389 {
396 390 return d_ptr->m_presenter->geometry();
397 391 }
398 392
399 393 ///*!
400 394 // TODO: Dummy.
401 395 // Adjest the ranges of the axes so that all the data of the specified \a series is visible
402 396 // */
403 397 //void QChart::adjustViewToSeries(QAbstractSeries* series)
404 398 //{
405 399 // //
406 400 //}
407 401
408 402 /*!
409 403 Sets animation \a options for the chart
410 404 */
411 405 void QChart::setAnimationOptions(AnimationOptions options)
412 406 {
413 407 d_ptr->m_presenter->setAnimationOptions(options);
414 408 }
415 409
416 410 QChart::AnimationOptions QChart::animationOptions() const
417 411 {
418 412 return d_ptr->m_presenter->animationOptions();
419 413 }
420 414
421 415 /*!
422 416 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
423 417 */
424 418 void QChart::scroll(qreal dx, qreal dy)
425 419 {
426 420 d_ptr->m_presenter->scroll(dx, dy);
427 421 }
428 422
429 423 void QChart::setBackgroundVisible(bool visible)
430 424 {
431 425 d_ptr->m_presenter->setBackgroundVisible(visible);
432 426 }
433 427
434 428 bool QChart::isBackgroundVisible() const
435 429 {
436 430 return d_ptr->m_presenter->isBackgroundVisible();
437 431 }
438 432
439 433 void QChart::setDropShadowEnabled(bool enabled)
440 434 {
441 435 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
442 436 }
443 437
444 438 bool QChart::isDropShadowEnabled() const
445 439 {
446 440 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
447 441 }
448 442
449 443 /*!
450 444 Returns all the series that are added to the chart.
451 445
452 446 \sa addSeries(), removeSeries(), removeAllSeries()
453 447 */
454 448 QList<QAbstractSeries*> QChart::series() const
455 449 {
456 450 return d_ptr->m_dataset->series();
457 451 }
458 452
459 453 /*!
460 454 Sets \a axis to the chart, which will control the presentation of the \a series
461 455
462 456 \sa axisX(), axisY(), setAxisY(), createDefaultAxes()
463 457 */
464 458 void QChart::setAxisX(QAbstractAxis* axis , QAbstractSeries *series)
465 459 {
466 460 d_ptr->m_dataset->setAxis(series,axis,Qt::Horizontal);
467 461 }
468 462
469 463 /*!
470 464 Sets \a axis to the chart, which will control the presentation of the \a series
471 465
472 466 \sa axisX(), axisY(), setAxisX(), createDefaultAxes()
473 467 */
474 468 void QChart::setAxisY( QAbstractAxis* axis , QAbstractSeries *series)
475 469 {
476 470 d_ptr->m_dataset->setAxis(series,axis,Qt::Vertical);
477 471 }
478 472
479 473 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
480 474
481 475 QChartPrivate::QChartPrivate():
482 476 m_legend(0),
483 477 m_dataset(0),
484 478 m_presenter(0)
485 479 {
486 480
487 481 }
488 482
489 483 QChartPrivate::~QChartPrivate()
490 484 {
491 485
492 486 }
493 487
494 488 void QChartPrivate::createConnections()
495 489 {
496 490 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
497 491 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*)));
498 492 QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*)));
499 493 QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*)));
500 494 //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF)));
501 495 }
502 496
503 497 #include "moc_qchart.cpp"
504 498
505 499 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now