##// END OF EJS Templates
Doc fixes
Jani Honkonen -
r1023:c3a5732a8ea5
parent child
Show More
@@ -1,79 +1,79
1 1 /*!
2 2 \page classes.html
3 3 \title QtCommercial Charts API
4 4 \keyword All Classes
5 5
6 6 Charts API is build on top of Qt Graphics View Framework. Charts can be displayed as QGraphicsWidget using QChart class. However
7 7 there is also convenience class QChartView which is QWidget based. These lets quickly use QCharts as normal Qt widget.
8 8 The API supports following chart types:
9 9
10 10 \list
11 11 \o area
12 12 \o line
13 13 \o bar
14 14 \o percent bar
15 15 \o pie
16 16 \o scatter
17 17 \o spline
18 18 \o stacked bar
19 19 \endlist
20 20
21 21
22 22 Each chart type is represented by QSeries derived class. To create given chart type users have to use instace of releted sereis class and add it to QChart/QChartView instance.
23 23 \code
24 24 QLineSeries* series = new QLineSeries();
25 25 series->add(0, 6);
26 26 series->add(2, 4);
27 27 ...
28 28 chartView->addSeries(series);
29 29 \endcode
30 30
31 31 \raw HTML
32 32 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
33 33 <tr>
34 34 <th class="titleheader" width="33%">
35 35 List of classes
36 36 </th>
37 37 </tr>
38 38 <tr>
39 39 <td valign="top">
40 40 <ul>
41 41 <li><a href="qareaseries.html">QAreaSeries</a></li>
42 42 <li><a href="qbarseries.html">QBarSeries</a></li>
43 43 <li><a href="qbarset.html">QBarSet</a></li>
44 44 <li><a href="qchart.html">QChart</a></li>
45 <li><a href="qchartaxis.html">QChartAxis</a></li>
45 <li><a href="qaxis.html">QAxis</a></li>
46 46 <li><a href="qchartview.html">QChartView</a></li>
47 47 <li><a href="qlineseries.html">QLineSeries</a></li>
48 48 <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li>
49 49 <li><a href="qpieseries.html">QPieSeries</a></li>
50 50 <li><a href="qpieslice.html">QPieSlice</a></li>
51 51 <li><a href="qscatterseries.html">QScatterSeries</a></li>
52 52 <li><a href="qabstractseries.html">QAbstractSeries</a></li>
53 53 <li><a href="qsplineseries.html">QSplineSeries</a></li>
54 54 <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li>
55 55 <li><a href="qxyseries.html">QXYSeries</a></li>
56 56 <li><a href="qlegend.html">QLegend</a></li>
57 57 </ul>
58 58 </td>
59 59 </tr>
60 60 </table>
61 61
62 62 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
63 63 <tr>
64 64 <th class="titleheader" width="33%">
65 65 Other files:
66 66 </th>
67 67 </tr>
68 68 <tr>
69 69 <td valign="top">
70 70 <ul>
71 71 <li><a href="qchartglobal.html">QChartGlobal</a></li>
72 72 </ul>
73 73 </td>
74 74 </tr>
75 75 </table>
76 76
77 77 \endraw
78 78
79 79 */
@@ -1,533 +1,533
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 "qaxis.h"
22 22 #include "qaxis_p.h"
23 23
24 24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 25
26 26 /*!
27 27 \class QAxis
28 \brief The QChartAxis class is used for manipulating chart's axis
28 \brief The QAxis class is used for manipulating chart's axis
29 29 and for adding optional axes to the chart.
30 30 \mainclass
31 31
32 32 There is only one x Axis, however there can be multiple y axes.
33 33 Each chart series can be bound to exactly one Y axis and the share common X axis.
34 34 Axis can be setup to show axis line with ticks, gird lines and shades.
35 35
36 36 */
37 37
38 38 /*!
39 39 \fn bool QAxis::isAxisVisible() const
40 40 \brief Returns if axis is visible
41 41 \sa setAxisVisible()
42 42 */
43 43
44 44 /*!
45 45 \fn QPen QAxis::axisPen() const
46 46 \brief Returns pen used to draw axis and ticks.
47 47 \sa setAxisPen()
48 48 */
49 49
50 50
51 51 /*!
52 52 \fn bool QAxis::isGridLineVisible() const
53 53 \brief Returns if grid is visible
54 54 \sa setGridLineVisible()
55 55 */
56 56
57 57 /*!
58 58 \fn QPen QAxis::gridLinePen() const
59 59 \brief Returns pen used to draw grid.
60 60 \sa setGridLinePen()
61 61 */
62 62
63 63 /*!
64 64 \fn bool QAxis::labelsVisible() const
65 65 \brief Returns if grid is visible
66 66 \sa setLabelsVisible()
67 67 */
68 68
69 69 /*!
70 70 \fn QPen QAxis::labelsPen() const
71 71 \brief Returns the pen used to labels.
72 72 \sa setLabelsPen()
73 73 */
74 74
75 75 /*!
76 76 \fn QBrush QAxis::labelsBrush() const
77 77 \brief Returns brush used to draw labels.
78 78 \sa setLabelsBrush()
79 79 */
80 80
81 81 /*!
82 82 \fn QFont QAxis::labelsFont() const
83 83 \brief Returns font used to draw labels.
84 84 \sa setLabelsFont()
85 85 */
86 86
87 87 /*!
88 88 \fn QFont QAxis::labelsAngle() const
89 89 \brief Returns angle used to draw labels.
90 90 \sa setLabelsAngle()
91 91 */
92 92
93 93 /*!
94 94 \fn bool QAxis::shadesVisible() const
95 95 \brief Returns if shades are visible.
96 96 \sa setShadesVisible()
97 97 */
98 98
99 99 /*!
100 100 \fn qreal QAxis::shadesOpacity() const
101 101 \brief Returns opacity of shades.
102 102 */
103 103
104 104 /*!
105 105 \fn QPen QAxis::shadesPen() const
106 106 \brief Returns pen used to draw shades.
107 107 \sa setShadesPen()
108 108 */
109 109
110 110 /*!
111 111 \fn QBrush QAxis::shadesBrush() const
112 112 \brief Returns brush used to draw shades.
113 113 \sa setShadesBrush()
114 114 */
115 115
116 116 /*!
117 117 \fn qreal QAxis::min() const
118 118 \brief Returns minimum value on the axis.
119 119 \sa setMin()
120 120 */
121 121
122 122 /*!
123 123 \fn qreal QAxis::max() const
124 124 \brief Returns maximim value on the axis.
125 125 \sa setMax()
126 126 */
127 127
128 128 /*!
129 129 \fn void QAxis::minChanged(qreal min)
130 130 \brief Axis emits signal when \a min of axis has changed.
131 131 */
132 132
133 133 /*!
134 134 \fn void QAxis::maxChanged(qreal max)
135 135 \brief Axis emits signal when \a max of axis has changed.
136 136 */
137 137
138 138 /*!
139 139 \fn void QAxis::rangeChanged(qreal min, qreal max)
140 140 \brief Axis emits signal when \a min or \a max of axis has changed.
141 141 */
142 142
143 143 /*!
144 144 \fn int QAxis::ticksCount() const
145 145 \brief Return number of ticks on the axis
146 146 \sa setTicksCount()
147 147 */
148 148
149 149 /*!
150 150 \fn QChartAxisCategories* QAxis::categories()
151 151 \brief Returns pointer to the list of categories which correspond to the values on the axis.
152 152 */
153 153
154 154 /*!
155 155 \fn void QAxis::ticksCountChanged(int count)
156 156 \brief Emits the new \a count of ticks on the axis
157 157 Signal is emitted when the number of the ticks on the axis has been changed to a different value.
158 158 Parementer count\a count is the new number of ticks on the axis.
159 159 */
160 160
161 161 /*!
162 162 Constructs new axis object which is a child of \a parent. Ownership is taken by
163 QChatView or QChart when axis added.
163 QChart when axis added.
164 164 */
165 165
166 166 QAxis::QAxis(QObject *parent) : QObject(parent),
167 167 d_ptr(new QAxisPrivate(this))
168 168 {
169 169
170 170 }
171 171
172 172 /*!
173 173 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
174 174 */
175 175
176 176 QAxis::~QAxis()
177 177 {
178 178 }
179 179
180 180 /*!
181 181 Sets \a pen used to draw axis line and ticks.
182 182 */
183 183 void QAxis::setAxisPen(const QPen &pen)
184 184 {
185 185 if (d_ptr->m_axisPen!=pen) {
186 186 d_ptr->m_axisPen = pen;
187 187 emit d_ptr->updated();
188 188 }
189 189 }
190 190
191 191 QPen QAxis::axisPen() const
192 192 {
193 193 return d_ptr->m_axisPen;
194 194 }
195 195
196 196 /*!
197 197 Sets if axis and ticks are \a visible.
198 198 */
199 199 void QAxis::setAxisVisible(bool visible)
200 200 {
201 201 if (d_ptr->m_axisVisible != visible) {
202 202 d_ptr->m_axisVisible = visible;
203 203 emit d_ptr->updated();
204 204 }
205 205 }
206 206
207 207 bool QAxis::isAxisVisible() const
208 208 {
209 209 return d_ptr->m_axisVisible;
210 210 }
211 211
212 212 /*!
213 213 Sets if grid line is \a visible.
214 214 */
215 215 void QAxis::setGridLineVisible(bool visible)
216 216 {
217 217 if (d_ptr->m_gridLineVisible != visible) {
218 218 d_ptr->m_gridLineVisible = visible;
219 219 emit d_ptr->updated();
220 220 }
221 221 }
222 222
223 223 bool QAxis::isGridLineVisible() const
224 224 {
225 225 return d_ptr->m_gridLineVisible;
226 226 }
227 227 /*!
228 228 Sets \a pen used to draw grid line.
229 229 */
230 230 void QAxis::setGridLinePen(const QPen &pen)
231 231 {
232 232 if (d_ptr->m_gridLinePen != pen) {
233 233 d_ptr->m_gridLinePen = pen;
234 234 emit d_ptr->updated();
235 235 }
236 236 }
237 237
238 238 QPen QAxis::gridLinePen() const
239 239 {
240 240 return d_ptr->m_gridLinePen;
241 241 }
242 242
243 243 /*!
244 244 Sets if axis' labels are \a visible.
245 245 */
246 246 void QAxis::setLabelsVisible(bool visible)
247 247 {
248 248 if (d_ptr->m_labelsVisible != visible) {
249 249 d_ptr->m_labelsVisible = visible;
250 250 emit d_ptr->updated();
251 251 }
252 252 }
253 253
254 254 bool QAxis::labelsVisible() const
255 255 {
256 256 return d_ptr->m_labelsVisible;
257 257 }
258 258 /*!
259 259 Sets \a pen used to draw labels.
260 260 */
261 261 void QAxis::setLabelsPen(const QPen &pen)
262 262 {
263 263 if (d_ptr->m_labelsPen != pen) {
264 264 d_ptr->m_labelsPen = pen;
265 265 emit d_ptr->updated();
266 266 }
267 267 }
268 268
269 269 QPen QAxis::labelsPen() const
270 270 {
271 271 return d_ptr->m_labelsPen;
272 272 }
273 273
274 274 /*!
275 275 Sets \a brush used to draw labels.
276 276 */
277 277 void QAxis::setLabelsBrush(const QBrush &brush)
278 278 {
279 279 if (d_ptr->m_labelsBrush != brush) {
280 280 d_ptr->m_labelsBrush = brush;
281 281 emit d_ptr->updated();
282 282 }
283 283 }
284 284
285 285 QBrush QAxis::labelsBrush() const
286 286 {
287 287 return d_ptr->m_labelsBrush;
288 288 }
289 289
290 290 /*!
291 291 Sets \a font used to draw labels.
292 292 */
293 293 void QAxis::setLabelsFont(const QFont &font)
294 294 {
295 295 if (d_ptr->m_labelsFont != font) {
296 296 d_ptr->m_labelsFont = font;
297 297 emit d_ptr->updated();
298 298 }
299 299 }
300 300
301 301 QFont QAxis::labelsFont() const
302 302 {
303 303 return d_ptr->m_labelsFont;
304 304 }
305 305
306 306 /*!
307 307 Sets \a angle for all the labels on given axis.
308 308 */
309 309 void QAxis::setLabelsAngle(int angle)
310 310 {
311 311 if (d_ptr->m_labelsAngle != angle) {
312 312 d_ptr->m_labelsAngle = angle;
313 313 emit d_ptr->updated();
314 314 }
315 315 }
316 316
317 317 int QAxis::labelsAngle() const
318 318 {
319 319 return d_ptr->m_labelsAngle;
320 320 }
321 321
322 322 /*!
323 323 Sets if shades are \a visible.
324 324 */
325 325 void QAxis::setShadesVisible(bool visible)
326 326 {
327 327 if (d_ptr->m_shadesVisible != visible) {
328 328 d_ptr->m_shadesVisible = visible;
329 329 emit d_ptr->updated();
330 330 }
331 331 }
332 332
333 333 bool QAxis::shadesVisible() const
334 334 {
335 335 return d_ptr->m_shadesVisible;
336 336 }
337 337
338 338 /*!
339 339 Sets \a pen used to draw shades.
340 340 */
341 341 void QAxis::setShadesPen(const QPen &pen)
342 342 {
343 343 if (d_ptr->m_shadesPen != pen) {
344 344 d_ptr->m_shadesPen = pen;
345 345 emit d_ptr->updated();
346 346 }
347 347 }
348 348
349 349 QPen QAxis::shadesPen() const
350 350 {
351 351 return d_ptr->m_shadesPen;
352 352 }
353 353
354 354 /*!
355 355 Sets \a brush used to draw shades.
356 356 */
357 357 void QAxis::setShadesBrush(const QBrush &brush)
358 358 {
359 359 if (d_ptr->m_shadesBrush != brush) {
360 360 d_ptr->m_shadesBrush = brush;
361 361 emit d_ptr->updated();
362 362 }
363 363 }
364 364
365 365 QBrush QAxis::shadesBrush() const
366 366 {
367 367 return d_ptr->m_shadesBrush;
368 368 }
369 369
370 370 /*!
371 371 Sets \a opacity of the shades.
372 372 */
373 373 void QAxis::setShadesOpacity(qreal opacity)
374 374 {
375 375 if (d_ptr->m_shadesOpacity != opacity) {
376 376 d_ptr->m_shadesOpacity=opacity;
377 377 emit d_ptr->updated();
378 378 }
379 379 }
380 380
381 381 qreal QAxis::shadesOpacity() const
382 382 {
383 383 return d_ptr->m_shadesOpacity;
384 384 }
385 385
386 386 /*!
387 387 Sets \a min value on the axis.
388 388 */
389 389 void QAxis::setMin(qreal min)
390 390 {
391 391 setRange(min,d_ptr->m_max);
392 392 }
393 393
394 394 qreal QAxis::min() const
395 395 {
396 396 return d_ptr->m_min;
397 397 }
398 398
399 399 /*!
400 400 Sets \a max value on the axis.
401 401 */
402 402 void QAxis::setMax(qreal max)
403 403 {
404 404 setRange(d_ptr->m_min,max);
405 405 }
406 406
407 407 qreal QAxis::max() const
408 408 {
409 409 return d_ptr->m_max;
410 410 }
411 411
412 412 /*!
413 413 Sets range from \a min to \a max on the axis.
414 414 */
415 415 void QAxis::setRange(qreal min, qreal max)
416 416 {
417 417 bool changed = false;
418 418 if (!qFuzzyIsNull(d_ptr->m_min - min)) {
419 419 d_ptr->m_min = min;
420 420 changed = true;
421 421 emit minChanged(min);
422 422 }
423 423
424 424 if (!qFuzzyIsNull(d_ptr->m_max - max)) {
425 425 d_ptr->m_max = max;
426 426 changed = true;
427 427 emit maxChanged(max);
428 428 }
429 429
430 430 if (changed) {
431 431 emit rangeChanged(d_ptr->m_min,d_ptr->m_max);
432 432 emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers);
433 433 }
434 434 }
435 435
436 436 /*!
437 437 Sets \a count for ticks on the axis.
438 438 */
439 439 void QAxis::setTicksCount(int count)
440 440 {
441 441 if (d_ptr->m_ticksCount != count) {
442 442 d_ptr->m_ticksCount = count;
443 443 emit ticksCountChanged(count);
444 444 emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers);
445 445 }
446 446 }
447 447
448 448 int QAxis::ticksCount() const
449 449 {
450 450 return d_ptr->m_ticksCount;
451 451 }
452 452
453 453 /*!
454 454 Sets axis, shades, labels and grid lines to be visible.
455 455 */
456 456 void QAxis::show()
457 457 {
458 458 d_ptr->m_axisVisible=true;
459 459 d_ptr->m_gridLineVisible=true;
460 460 d_ptr->m_labelsVisible=true;
461 461 d_ptr->m_shadesVisible=true;
462 462 emit d_ptr->updated();
463 463 }
464 464
465 465 /*!
466 466 Sets axis, shades, labels and grid lines to not be visible.
467 467 */
468 468 void QAxis::hide()
469 469 {
470 470 d_ptr->m_axisVisible = false;
471 471 d_ptr->m_gridLineVisible = false;
472 472 d_ptr->m_labelsVisible = false;
473 473 d_ptr->m_shadesVisible = false;
474 474 emit d_ptr->updated();
475 475 }
476 476
477 477 /*!
478 478 Sets the nice numbers state to \a enable
479 479 */
480 480 void QAxis::setNiceNumbersEnabled(bool enable)
481 481 {
482 482 if (d_ptr->m_niceNumbers != enable){
483 483 d_ptr->m_niceNumbers = enable;
484 484 emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers);
485 485 }
486 486 }
487 487
488 488 /*!
489 489 Returns whether nice numbers are enabled or not.
490 490 */
491 491 bool QAxis::niceNumbersEnabled() const
492 492 {
493 493 return d_ptr->m_niceNumbers;
494 494 }
495 495
496 496 QChartAxisCategories* QAxis::categories()
497 497 {
498 498 return &d_ptr->m_category;
499 499 }
500 500
501 501 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
502 502
503 503 QAxisPrivate::QAxisPrivate(QAxis* q):
504 504 q_ptr(q),
505 505 m_axisVisible(true),
506 506 m_gridLineVisible(true),
507 507 m_labelsVisible(true),
508 508 m_labelsAngle(0),
509 509 m_shadesVisible(false),
510 510 m_shadesOpacity(1.0),
511 511 m_min(0),
512 512 m_max(0),
513 513 m_ticksCount(5),
514 514 m_niceNumbers(false)
515 515 {
516 516
517 517 }
518 518
519 519 QAxisPrivate::~QAxisPrivate()
520 520 {
521 521
522 522 }
523 523
524 524 void QAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
525 525 {
526 526 q_ptr->setRange(min,max);
527 527 q_ptr->setTicksCount(count);
528 528 }
529 529
530 530 #include "moc_qaxis.cpp"
531 531 #include "moc_qaxis_p.cpp"
532 532
533 533 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,436 +1,436
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 representation of different types of QChartSeries and other chart related objects like
63 QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the
62 representation of different types of series and other chart related objects like
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 69 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
70 70 */
71 71 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
72 72 d_ptr(new QChartPrivate())
73 73 {
74 74 d_ptr->m_dataset = new ChartDataSet(this);
75 75 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
76 76 d_ptr->createConnections();
77 77 d_ptr->m_legend = new LegendScroller(this);
78 78 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
79 79 }
80 80
81 81 /*!
82 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
82 Destroys the object and it's children, like series and axis objects added to it.
83 83 */
84 84 QChart::~QChart()
85 85 {
86 86 //delete first presenter , since this is a root of all the graphical items
87 87 delete d_ptr->m_presenter;
88 88 d_ptr->m_presenter=0;
89 89 }
90 90
91 91 /*!
92 92 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
93 93 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
94 94 the y axis).
95 95 */
96 96 void QChart::addSeries(QAbstractSeries *series, QAxis *axisY)
97 97 {
98 98 Q_ASSERT(series);
99 99 d_ptr->m_dataset->addSeries(series, axisY);
100 100 }
101 101
102 102 /*!
103 103 Removes the \a series specified in a perameter from the QChartView.
104 104 It releses its ownership of the specified QChartSeries object.
105 105 It does not delete the pointed QChartSeries data object
106 106 \sa addSeries(), removeAllSeries()
107 107 */
108 108 void QChart::removeSeries(QAbstractSeries *series)
109 109 {
110 110 Q_ASSERT(series);
111 111 d_ptr->m_dataset->removeSeries(series);
112 112 }
113 113
114 114 /*!
115 115 Removes all the QChartSeries that have been added to the QChartView
116 116 It also deletes the pointed QChartSeries data objects
117 117 \sa addSeries(), removeSeries()
118 118 */
119 119 void QChart::removeAllSeries()
120 120 {
121 121 d_ptr->m_dataset->removeAllSeries();
122 122 }
123 123
124 124 /*!
125 125 Sets the \a brush that is used for painting the background of the chart area.
126 126 */
127 127 void QChart::setBackgroundBrush(const QBrush& brush)
128 128 {
129 129 //TODO: refactor me
130 130 d_ptr->m_presenter->createChartBackgroundItem();
131 131 d_ptr->m_presenter->m_backgroundItem->setBrush(brush);
132 132 d_ptr->m_presenter->m_backgroundItem->update();
133 133 }
134 134
135 135 /*!
136 136 Gets the brush that is used for painting the background of the chart area.
137 137 */
138 138 QBrush QChart::backgroundBrush() const
139 139 {
140 140 //TODO: refactor me
141 141 if (!d_ptr->m_presenter->m_backgroundItem) return QBrush();
142 142 return (d_ptr->m_presenter->m_backgroundItem)->brush();
143 143 }
144 144
145 145 /*!
146 146 Sets the \a pen that is used for painting the background of the chart area.
147 147 */
148 148 void QChart::setBackgroundPen(const QPen& pen)
149 149 {
150 150 //TODO: refactor me
151 151 d_ptr->m_presenter->createChartBackgroundItem();
152 152 d_ptr->m_presenter->m_backgroundItem->setPen(pen);
153 153 d_ptr->m_presenter->m_backgroundItem->update();
154 154 }
155 155
156 156 /*!
157 157 Gets the pen that is used for painting the background of the chart area.
158 158 */
159 159 QPen QChart::backgroundPen() const
160 160 {
161 161 //TODO: refactor me
162 162 if (!d_ptr->m_presenter->m_backgroundItem) return QPen();
163 163 return d_ptr->m_presenter->m_backgroundItem->pen();
164 164 }
165 165
166 166 /*!
167 167 Sets the chart \a title. The description text that is drawn above the chart.
168 168 */
169 169 void QChart::setTitle(const QString& title)
170 170 {
171 171 //TODO: refactor me
172 172 d_ptr->m_presenter->createChartTitleItem();
173 173 d_ptr->m_presenter->m_titleItem->setText(title);
174 174 d_ptr->m_presenter->updateLayout();
175 175 }
176 176
177 177 /*!
178 178 Returns the chart title. The description text that is drawn above the chart.
179 179 */
180 180 QString QChart::title() const
181 181 {
182 182 //TODO: refactor me
183 183 if (d_ptr->m_presenter->m_titleItem)
184 184 return d_ptr->m_presenter->m_titleItem->text();
185 185 else
186 186 return QString();
187 187 }
188 188
189 189 /*!
190 190 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
191 191 */
192 192 void QChart::setTitleFont(const QFont& font)
193 193 {
194 194 //TODO: refactor me
195 195 d_ptr->m_presenter->createChartTitleItem();
196 196 d_ptr->m_presenter->m_titleItem->setFont(font);
197 197 d_ptr->m_presenter->updateLayout();
198 198 }
199 199
200 200 /*!
201 201 Gets the font that is used for drawing the chart description text that is rendered above the chart.
202 202 */
203 203 QFont QChart::titleFont() const
204 204 {
205 205 if (d_ptr->m_presenter->m_titleItem)
206 206 return d_ptr->m_presenter->m_titleItem->font();
207 207 else
208 208 return QFont();
209 209 }
210 210
211 211 /*!
212 212 Sets the \a brush used for rendering the title text.
213 213 */
214 214 void QChart::setTitleBrush(const QBrush &brush)
215 215 {
216 216 //TODO: refactor me
217 217 d_ptr->m_presenter->createChartTitleItem();
218 218 d_ptr->m_presenter->m_titleItem->setBrush(brush);
219 219 d_ptr->m_presenter->updateLayout();
220 220 }
221 221
222 222 /*!
223 223 Returns the brush used for rendering the title text.
224 224 */
225 225 QBrush QChart::titleBrush() const
226 226 {
227 227 //TODO: refactor me
228 228 if (!d_ptr->m_presenter->m_titleItem) return QBrush();
229 229 return d_ptr->m_presenter->m_titleItem->brush();
230 230 }
231 231
232 232 /*!
233 233 Sets the \a theme used by the chart for rendering the graphical representation of the data
234 234 \sa theme()
235 235 */
236 236 void QChart::setTheme(QChart::ChartTheme theme)
237 237 {
238 238 d_ptr->m_presenter->setTheme(theme);
239 239 }
240 240
241 241 /*!
242 242 Returns the theme enum used by the chart.
243 243 \sa ChartTheme, setTheme()
244 244 */
245 245 QChart::ChartTheme QChart::theme() const
246 246 {
247 247 return d_ptr->m_presenter->theme();
248 248 }
249 249
250 250 /*!
251 251 Zooms in the view by a factor of 2
252 252 */
253 253 void QChart::zoomIn()
254 254 {
255 255 d_ptr->m_presenter->zoomIn();
256 256 }
257 257
258 258 /*!
259 259 Zooms in the view to a maximum level at which \a rect is still fully visible.
260 260 */
261 261 void QChart::zoomIn(const QRectF& rect)
262 262 {
263 263 if (!rect.isValid()) return;
264 264 d_ptr->m_presenter->zoomIn(rect);
265 265 }
266 266
267 267 /*!
268 268 Restores the view zoom level to the previous one.
269 269 */
270 270 void QChart::zoomOut()
271 271 {
272 272 d_ptr->m_presenter->zoomOut();
273 273 }
274 274
275 275 /*!
276 276 Returns the pointer to the x axis object of the chart
277 277 */
278 278 QAxis* QChart::axisX() const
279 279 {
280 280 return d_ptr->m_dataset->axisX();
281 281 }
282 282
283 283 /*!
284 284 Returns the pointer to the y axis object of the \a series
285 285 If no \a series is provided then default Y axis of the chart is returned.
286 286 */
287 287 QAxis* QChart::axisY(QAbstractSeries *series) const
288 288 {
289 289 return d_ptr->m_dataset->axisY(series);
290 290 }
291 291
292 292 /*!
293 293 Returns the legend object of the chart. Ownership stays in chart.
294 294 */
295 295 QLegend* QChart::legend() const
296 296 {
297 297 return d_ptr->m_legend;
298 298 }
299 299
300 300 /*!
301 301 Returns the rect that contains information about margins (distance between chart widget edge and axes).
302 302 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
303 303 */
304 304 QRectF QChart::margins() const
305 305 {
306 306 return d_ptr->m_presenter->margins();
307 307 }
308 308
309 309
310 310 /*!
311 311 Resizes and updates the chart area using the \a event data
312 312 */
313 313 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
314 314 {
315 315 d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize());
316 316 QGraphicsWidget::resizeEvent(event);
317 317 d_ptr->m_presenter->setGeometry(d_ptr->m_rect);
318 318 }
319 319
320 320 /*!
321 321 Sets animation \a options for the chart
322 322 */
323 323 void QChart::setAnimationOptions(AnimationOptions options)
324 324 {
325 325 d_ptr->m_presenter->setAnimationOptions(options);
326 326 }
327 327
328 328 /*!
329 329 Returns animation options for the chart
330 330 */
331 331 QChart::AnimationOptions QChart::animationOptions() const
332 332 {
333 333 return d_ptr->m_presenter->animationOptions();
334 334 }
335 335
336 336 /*!
337 337 Scrolls the visible area of the chart to the left by the distance between two x axis ticks
338 338 */
339 339 void QChart::scrollLeft()
340 340 {
341 341 d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
342 342 }
343 343
344 344 /*!
345 345 Scrolls the visible area of the chart to the right by the distance between two x axis ticks
346 346 */
347 347 void QChart::scrollRight()
348 348 {
349 349 d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
350 350 }
351 351
352 352 /*!
353 353 Scrolls the visible area of the chart up by the distance between two y axis ticks
354 354 */
355 355 void QChart::scrollUp()
356 356 {
357 357 d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
358 358 }
359 359
360 360 /*!
361 361 Scrolls the visible area of the chart down by the distance between two y axis ticks
362 362 */
363 363 void QChart::scrollDown()
364 364 {
365 365 d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
366 366 }
367 367
368 368 /*!
369 369 Sets the chart background visibility state to \a visible
370 370 */
371 371 void QChart::setBackgroundVisible(bool visible)
372 372 {
373 373 //TODO: refactor me
374 374 d_ptr->m_presenter->createChartBackgroundItem();
375 375 d_ptr->m_presenter->m_backgroundItem->setVisible(visible);
376 376 }
377 377
378 378 /*!
379 379 Returns the chart's background visibility state
380 380 */
381 381 bool QChart::isBackgroundVisible() const
382 382 {
383 383 //TODO: refactor me
384 384 if (!d_ptr->m_presenter->m_backgroundItem)
385 385 return false;
386 386
387 387 return d_ptr->m_presenter->m_backgroundItem->isVisible();
388 388 }
389 389
390 390 /*!
391 391 Sets the background drop shadow effect state to \a enabled.
392 392 */
393 393 void QChart::setBackgroundDropShadowEnabled(bool enabled)
394 394 {
395 395 d_ptr->m_presenter->createChartBackgroundItem();
396 396 d_ptr->m_presenter->m_backgroundItem->setDropShadowEnabled(enabled);
397 397 }
398 398
399 399 /*!
400 400 Returns true if the drop shadow effect is enabled for the chart background.
401 401 */
402 402 bool QChart::isBackgroundDropShadowEnabled() const
403 403 {
404 404 if (!d_ptr->m_presenter->m_backgroundItem)
405 405 return false;
406 406
407 407 return d_ptr->m_presenter->m_backgroundItem->isDropShadowEnabled();
408 408 }
409 409
410 410 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
411 411
412 412 QChartPrivate::QChartPrivate():
413 413 m_legend(0),
414 414 m_dataset(0),
415 415 m_presenter(0)
416 416 {
417 417
418 418 }
419 419
420 420 QChartPrivate::~QChartPrivate()
421 421 {
422 422
423 423 }
424 424
425 425 void QChartPrivate::createConnections()
426 426 {
427 427
428 428 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries *, Domain *)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries *, Domain *)));
429 429 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries *)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries *)));
430 430 QObject::connect(m_dataset,SIGNAL(axisAdded(QAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAxis*,Domain*)));
431 431 QObject::connect(m_dataset,SIGNAL(axisRemoved(QAxis*)),m_presenter,SLOT(handleAxisRemoved(QAxis*)));
432 432 }
433 433
434 434 #include "moc_qchart.cpp"
435 435
436 436 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,218 +1,218
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 "qchartview.h"
22 22 #include "qchartview_p.h"
23 23 #include "qchart_p.h"
24 24 #include <QGraphicsScene>
25 25 #include <QRubberBand>
26 26
27 27 /*!
28 28 \enum QChartView::RubberBand
29 29
30 30 This enum describes the different types of rubber bands that can be used for zoom rect selection
31 31
32 32 \value NoRubberBand
33 33 \value VerticalRubberBand
34 34 \value HorizonalRubberBand
35 35 \value RectangleRubberBand
36 36 */
37 37
38 38 /*!
39 39 \class QChartView
40 40 \brief Standalone charting widget.
41 41
42 42 QChartView is a standalone widget that can display charts. It does not require separate
43 43 QGraphicsScene to work. It manages the graphical representation of different types of
44 QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to
44 series and other chart related objects like QAxis and QLegend. If you want to
45 45 display a chart in your existing QGraphicsScene, you can use the QChart class instead.
46 46
47 47 \sa QChart
48 48 */
49 49
50 50 QTCOMMERCIALCHART_BEGIN_NAMESPACE
51 51
52 52 /*!
53 53 Constructs a chartView object with parent \a parent to display a \a chart.
54 54 */
55 55 QChartView::QChartView(QChart *chart,QWidget *parent) :
56 56 QGraphicsView(parent),
57 57 d_ptr(new QChartViewPrivate())
58 58 {
59 59 Q_ASSERT(chart);
60 60 d_ptr->m_scene = new QGraphicsScene(this);
61 61 d_ptr->m_chart = chart;
62 62 setFrameShape(QFrame::NoFrame);
63 63 setBackgroundRole(QPalette::Window);
64 64 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
65 65 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
66 66 setScene(d_ptr->m_scene);
67 67 d_ptr->m_scene->addItem(chart);
68 68 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
69 69 }
70 70
71 71
72 72 /*!
73 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
73 Destroys the object and it's children, like series and axis objects added to it.
74 74 */
75 75 QChartView::~QChartView()
76 76 {
77 77 }
78 78
79 79 /*!
80 80 Returns the pointer to the associated chart
81 81 */
82 82 QChart* QChartView::chart() const
83 83 {
84 84 return d_ptr->m_chart;
85 85 }
86 86
87 87 /*!
88 88 Sets the RubberBandPlicy to \a rubberBand. Selected policy determines the way zooming is performed.
89 89 */
90 90 void QChartView::setRubberBand(const RubberBands& rubberBand)
91 91 {
92 92 d_ptr->m_rubberBandFlags=rubberBand;
93 93
94 94 if (!d_ptr->m_rubberBandFlags) {
95 95 delete d_ptr->m_rubberBand;
96 96 d_ptr->m_rubberBand=0;
97 97 return;
98 98 }
99 99
100 100 if (!d_ptr->m_rubberBand) {
101 101 d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
102 102 d_ptr->m_rubberBand->setEnabled(true);
103 103 }
104 104 }
105 105
106 106 /*!
107 107 Returns the RubberBandPolicy that is currently being used by the widget.
108 108 */
109 109 QChartView::RubberBands QChartView::rubberBand() const
110 110 {
111 111 return d_ptr->m_rubberBandFlags;
112 112 }
113 113
114 114 /*!
115 115 If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area.
116 116 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
117 117 */
118 118 void QChartView::mousePressEvent(QMouseEvent *event)
119 119 {
120 120 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
121 121
122 122 int padding = d_ptr->m_chart->margins().top();
123 123 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
124 124
125 125 if (rect.contains(event->pos())) {
126 126 d_ptr->m_rubberBandOrigin = event->pos();
127 127 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize()));
128 128 d_ptr->m_rubberBand->show();
129 129 event->accept();
130 130 }
131 131 }
132 132 else {
133 133 QGraphicsView::mousePressEvent(event);
134 134 }
135 135 }
136 136
137 137 /*!
138 138 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
139 139 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
140 140 */
141 141 void QChartView::mouseMoveEvent(QMouseEvent *event)
142 142 {
143 143 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) {
144 144 QRectF margins = d_ptr->m_chart->margins();
145 145 QRectF geometry = d_ptr->m_chart->geometry();
146 146 QRectF rect =geometry.adjusted(margins.left(),margins.top(),-margins.right(),-margins.bottom());
147 147 int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x();
148 148 int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y();
149 149 if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) {
150 150 d_ptr->m_rubberBandOrigin.setY(rect.top());
151 151 height = rect.height();
152 152 }
153 153 if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) {
154 154 d_ptr->m_rubberBandOrigin.setX(rect.left());
155 155 width= rect.width();
156 156 }
157 157 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized());
158 158 }
159 159 else {
160 160 QGraphicsView::mouseMoveEvent(event);
161 161 }
162 162 }
163 163
164 164 /*!
165 165 If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand
166 166 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
167 167 */
168 168 void QChartView::mouseReleaseEvent(QMouseEvent *event)
169 169 {
170 170 if(d_ptr->m_rubberBand) {
171 171 if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) {
172 172 d_ptr->m_rubberBand->hide();
173 173 QRect rect = d_ptr->m_rubberBand->geometry();
174 174 d_ptr->m_chart->zoomIn(rect);
175 175 event->accept();
176 176 }
177 177
178 178 if(event->button()==Qt::RightButton){
179 179 d_ptr->m_chart->zoomOut();
180 180 event->accept();
181 181 }
182 182 }
183 183 else {
184 184 QGraphicsView::mouseReleaseEvent(event);
185 185 }
186 186 }
187 187
188 188 /*!
189 189 Resizes and updates the chart area using the \a event data
190 190 */
191 191 void QChartView::resizeEvent(QResizeEvent *event)
192 192 {
193 193 QGraphicsView::resizeEvent(event);
194 194 d_ptr->m_chart->resize(size());
195 195 setMinimumSize(d_ptr->m_chart->minimumSize().toSize());
196 196 setSceneRect(d_ptr->m_chart->geometry());
197 197 }
198 198
199 199 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
200 200
201 201 QChartViewPrivate::QChartViewPrivate():
202 202 m_scene(0),
203 203 m_chart(0),
204 204 m_presenter(0),
205 205 m_rubberBand(0),
206 206 m_rubberBandFlags(QChartView::NoRubberBand)
207 207 {
208 208
209 209 }
210 210
211 211 QChartViewPrivate::~QChartViewPrivate()
212 212 {
213 213
214 214 }
215 215
216 216 #include "moc_qchartview.cpp"
217 217
218 218 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now