@@ -1,435 +1,435 | |||
|
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 | 87 | \property QChart::margins |
|
88 | 88 | Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes. |
|
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 | 105 | \fn void QChart::marginsChanged(QRectF newMargins) |
|
106 | 106 | The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size, |
|
107 | 107 | modify axes or hide/show legend. |
|
108 | 108 | */ |
|
109 | 109 | |
|
110 | 110 | /*! |
|
111 | 111 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
112 | 112 | */ |
|
113 | 113 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
114 | 114 | d_ptr(new QChartPrivate()) |
|
115 | 115 | { |
|
116 | 116 | d_ptr->m_dataset = new ChartDataSet(this); |
|
117 | 117 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
118 | 118 | d_ptr->createConnections(); |
|
119 | 119 | d_ptr->m_legend = new LegendScroller(this); |
|
120 | 120 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); |
|
121 | 121 | //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF))); |
|
122 | 122 | setLayout(d_ptr->m_presenter->layout()); |
|
123 | 123 | } |
|
124 | 124 | |
|
125 | 125 | /*! |
|
126 | 126 | Destroys the object and it's children, like series and axis objects added to it. |
|
127 | 127 | */ |
|
128 | 128 | QChart::~QChart() |
|
129 | 129 | { |
|
130 | 130 | //delete first presenter , since this is a root of all the graphical items |
|
131 | 131 | setLayout(0); |
|
132 | 132 | delete d_ptr->m_presenter; |
|
133 | 133 | d_ptr->m_presenter=0; |
|
134 | 134 | } |
|
135 | 135 | |
|
136 | 136 | /*! |
|
137 | 137 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
138 | 138 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
139 | 139 | the y axis). |
|
140 | 140 | |
|
141 | 141 | \sa removeSeries(), removeAllSeries() |
|
142 | 142 | */ |
|
143 | 143 | void QChart::addSeries(QAbstractSeries *series) |
|
144 | 144 | { |
|
145 | 145 | Q_ASSERT(series); |
|
146 | 146 | d_ptr->m_dataset->addSeries(series); |
|
147 | 147 | } |
|
148 | 148 | |
|
149 | 149 | /*! |
|
150 | 150 | Removes the \a series specified in a perameter from the QChartView. |
|
151 | 151 | It releses its ownership of the specified QChartSeries object. |
|
152 | 152 | It does not delete the pointed QChartSeries data object |
|
153 | 153 | \sa addSeries(), removeAllSeries() |
|
154 | 154 | */ |
|
155 | 155 | void QChart::removeSeries(QAbstractSeries *series) |
|
156 | 156 | { |
|
157 | 157 | Q_ASSERT(series); |
|
158 | 158 | d_ptr->m_dataset->removeSeries(series); |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | /*! |
|
162 | 162 | Removes all the QChartSeries that have been added to the QChartView |
|
163 | 163 | It also deletes the pointed QChartSeries data objects |
|
164 | 164 | \sa addSeries(), removeSeries() |
|
165 | 165 | */ |
|
166 | 166 | void QChart::removeAllSeries() |
|
167 | 167 | { |
|
168 | 168 | d_ptr->m_dataset->removeAllSeries(); |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | /*! |
|
172 | 172 | Sets the \a brush that is used for painting the background of the chart area. |
|
173 | 173 | */ |
|
174 | 174 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
175 | 175 | { |
|
176 | 176 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
177 | 177 | } |
|
178 | 178 | |
|
179 | 179 | /*! |
|
180 | 180 | Gets the brush that is used for painting the background of the chart area. |
|
181 | 181 | */ |
|
182 | 182 | QBrush QChart::backgroundBrush() const |
|
183 | 183 | { |
|
184 | 184 | return d_ptr->m_presenter->backgroundBrush(); |
|
185 | 185 | } |
|
186 | 186 | |
|
187 | 187 | /*! |
|
188 | 188 | Sets the \a pen that is used for painting the background of the chart area. |
|
189 | 189 | */ |
|
190 | 190 | void QChart::setBackgroundPen(const QPen& pen) |
|
191 | 191 | { |
|
192 | 192 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
193 | 193 | } |
|
194 | 194 | |
|
195 | 195 | /*! |
|
196 | 196 | Gets the pen that is used for painting the background of the chart area. |
|
197 | 197 | */ |
|
198 | 198 | QPen QChart::backgroundPen() const |
|
199 | 199 | { |
|
200 | 200 | return d_ptr->m_presenter->backgroundPen(); |
|
201 | 201 | } |
|
202 | 202 | |
|
203 | 203 | /*! |
|
204 | 204 | Sets the chart \a title. The description text that is drawn above the chart. |
|
205 | 205 | */ |
|
206 | 206 | void QChart::setTitle(const QString& title) |
|
207 | 207 | { |
|
208 | 208 | d_ptr->m_presenter->setTitle(title); |
|
209 | 209 | } |
|
210 | 210 | |
|
211 | 211 | /*! |
|
212 | 212 | Returns the chart title. The description text that is drawn above the chart. |
|
213 | 213 | */ |
|
214 | 214 | QString QChart::title() const |
|
215 | 215 | { |
|
216 | 216 | return d_ptr->m_presenter->title(); |
|
217 | 217 | } |
|
218 | 218 | |
|
219 | 219 | /*! |
|
220 | 220 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. |
|
221 | 221 | */ |
|
222 | 222 | void QChart::setTitleFont(const QFont& font) |
|
223 | 223 | { |
|
224 | 224 | d_ptr->m_presenter->setTitleFont(font); |
|
225 | 225 | } |
|
226 | 226 | |
|
227 | 227 | /*! |
|
228 | 228 | Gets the font that is used for drawing the chart description text that is rendered above the chart. |
|
229 | 229 | */ |
|
230 | 230 | QFont QChart::titleFont() const |
|
231 | 231 | { |
|
232 | 232 | return d_ptr->m_presenter->titleFont(); |
|
233 | 233 | } |
|
234 | 234 | |
|
235 | 235 | /*! |
|
236 | 236 | Sets the \a brush used for rendering the title text. |
|
237 | 237 | */ |
|
238 | 238 | void QChart::setTitleBrush(const QBrush &brush) |
|
239 | 239 | { |
|
240 | 240 | d_ptr->m_presenter->setTitleBrush(brush); |
|
241 | 241 | } |
|
242 | 242 | |
|
243 | 243 | /*! |
|
244 | 244 | Returns the brush used for rendering the title text. |
|
245 | 245 | */ |
|
246 | 246 | QBrush QChart::titleBrush() const |
|
247 | 247 | { |
|
248 | 248 | return d_ptr->m_presenter->titleBrush(); |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | void QChart::setTheme(QChart::ChartTheme theme) |
|
252 | 252 | { |
|
253 | 253 | d_ptr->m_presenter->setTheme(theme); |
|
254 | 254 | } |
|
255 | 255 | |
|
256 | 256 | QChart::ChartTheme QChart::theme() const |
|
257 | 257 | { |
|
258 | 258 | return d_ptr->m_presenter->theme(); |
|
259 | 259 | } |
|
260 | 260 | |
|
261 | 261 | /*! |
|
262 | 262 | Zooms in the view by a factor of 2 |
|
263 | 263 | */ |
|
264 | 264 | void QChart::zoomIn() |
|
265 | 265 | { |
|
266 | 266 | d_ptr->m_presenter->zoomIn(2.0); |
|
267 | 267 | } |
|
268 | 268 | |
|
269 | 269 | /*! |
|
270 | 270 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
271 | 271 | */ |
|
272 | 272 | void QChart::zoomIn(const QRectF& rect) |
|
273 | 273 | { |
|
274 | 274 | if (!rect.isValid()) return; |
|
275 | 275 | d_ptr->m_presenter->zoomIn(rect); |
|
276 | 276 | } |
|
277 | 277 | |
|
278 | 278 | /*! |
|
279 | 279 | Restores the view zoom level to the previous one. |
|
280 | 280 | */ |
|
281 | 281 | void QChart::zoomOut() |
|
282 | 282 | { |
|
283 | 283 | d_ptr->m_presenter->zoomOut(2.0); |
|
284 | 284 | } |
|
285 | 285 | |
|
286 | 286 | /*! |
|
287 | 287 | Zooms in the view by a \a factor. |
|
288 | 288 | |
|
289 | 289 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
290 | 290 | */ |
|
291 | 291 | void QChart::zoom(qreal factor) |
|
292 | 292 | { |
|
293 | 293 | if (qFuzzyIsNull(factor)) |
|
294 | 294 | return; |
|
295 | 295 | |
|
296 | 296 | if (qFuzzyCompare(factor, 1.0)) |
|
297 | 297 | return; |
|
298 | 298 | |
|
299 | 299 | if (factor < 0) |
|
300 | 300 | return; |
|
301 | 301 | |
|
302 | 302 | if (factor > 1.0) |
|
303 | 303 | d_ptr->m_presenter->zoomIn(factor); |
|
304 | 304 | else |
|
305 | 305 | d_ptr->m_presenter->zoomOut(1.0 / factor); |
|
306 | 306 | } |
|
307 | 307 | |
|
308 | 308 | /*! |
|
309 | 309 | Returns the pointer to the x axis object of the chart |
|
310 | 310 | */ |
|
311 | 311 | QAbstractAxis* QChart::axisX(QAbstractSeries* series) const |
|
312 | 312 | { |
|
313 |
return d_ptr->m_dataset->axisX(series); |
|
|
313 | return d_ptr->m_dataset->axisX(series); | |
|
314 | 314 | } |
|
315 | 315 | |
|
316 | 316 | /*! |
|
317 | 317 | Returns the pointer to the y axis object of the \a series |
|
318 | 318 | If no \a series is provided then default Y axis of the chart is returned. |
|
319 | 319 | */ |
|
320 | 320 | QAbstractAxis* QChart::axisY(QAbstractSeries *series) const |
|
321 | 321 | { |
|
322 | 322 | return d_ptr->m_dataset->axisY(series); |
|
323 | 323 | } |
|
324 | 324 | |
|
325 | 325 | /*! |
|
326 | 326 | Returns the legend object of the chart. Ownership stays in chart. |
|
327 | 327 | */ |
|
328 | 328 | QLegend* QChart::legend() const |
|
329 | 329 | { |
|
330 | 330 | return d_ptr->m_legend; |
|
331 | 331 | } |
|
332 | 332 | |
|
333 | 333 | /*! |
|
334 | 334 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
335 | 335 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
336 | 336 | */ |
|
337 | 337 | QRectF QChart::margins() const |
|
338 | 338 | { |
|
339 | 339 | return d_ptr->m_presenter->margins(); |
|
340 | 340 | } |
|
341 | 341 | |
|
342 | 342 | /*! |
|
343 | 343 | Sets animation \a options for the chart |
|
344 | 344 | */ |
|
345 | 345 | |
|
346 | 346 | void QChart::setAnimationOptions(AnimationOptions options) |
|
347 | 347 | { |
|
348 | 348 | d_ptr->m_presenter->setAnimationOptions(options); |
|
349 | 349 | } |
|
350 | 350 | |
|
351 | 351 | QChart::AnimationOptions QChart::animationOptions() const |
|
352 | 352 | { |
|
353 | 353 | return d_ptr->m_presenter->animationOptions(); |
|
354 | 354 | } |
|
355 | 355 | |
|
356 | 356 | /*! |
|
357 | 357 | Scrolls the visible area of the chart by the distance defined in the \a delta. |
|
358 | 358 | */ |
|
359 | 359 | void QChart::scroll(qreal dx, qreal dy) |
|
360 | 360 | { |
|
361 | 361 | d_ptr->m_presenter->scroll(dx, dy); |
|
362 | 362 | } |
|
363 | 363 | |
|
364 | 364 | void QChart::setBackgroundVisible(bool visible) |
|
365 | 365 | { |
|
366 | 366 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
367 | 367 | } |
|
368 | 368 | |
|
369 | 369 | bool QChart::isBackgroundVisible() const |
|
370 | 370 | { |
|
371 | 371 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
372 | 372 | } |
|
373 | 373 | |
|
374 | 374 | void QChart::setDropShadowEnabled(bool enabled) |
|
375 | 375 | { |
|
376 | 376 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
377 | 377 | } |
|
378 | 378 | |
|
379 | 379 | bool QChart::isDropShadowEnabled() const |
|
380 | 380 | { |
|
381 | 381 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
382 | 382 | } |
|
383 | 383 | |
|
384 | 384 | /*! |
|
385 | 385 | Returns all the series that are added to the chart. |
|
386 | 386 | |
|
387 | 387 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
388 | 388 | */ |
|
389 | 389 | QList<QAbstractSeries*> QChart::series() const |
|
390 | 390 | { |
|
391 | 391 | return d_ptr->m_dataset->series(); |
|
392 | 392 | } |
|
393 | 393 | |
|
394 | 394 | void QChart::setMarginsMinimum(const QRectF& margins) |
|
395 | 395 | { |
|
396 | 396 | d_ptr->m_presenter->setMarginsMinimum(margins); |
|
397 | 397 | } |
|
398 | 398 | |
|
399 | 399 | void QChart::setAxisX(QAbstractSeries *series, QAbstractAxis* axis) |
|
400 | 400 | { |
|
401 | 401 | d_ptr->m_dataset->setAxisX(series, axis); |
|
402 | 402 | } |
|
403 | 403 | |
|
404 | 404 | void QChart::setAxisY(QAbstractSeries *series, QAbstractAxis* axis) |
|
405 | 405 | { |
|
406 | 406 | d_ptr->m_dataset->setAxisY(series, axis); |
|
407 | 407 | } |
|
408 | 408 | |
|
409 | 409 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
410 | 410 | |
|
411 | 411 | QChartPrivate::QChartPrivate(): |
|
412 | 412 | m_legend(0), |
|
413 | 413 | m_dataset(0), |
|
414 | 414 | m_presenter(0) |
|
415 | 415 | { |
|
416 | 416 | |
|
417 | 417 | } |
|
418 | 418 | |
|
419 | 419 | QChartPrivate::~QChartPrivate() |
|
420 | 420 | { |
|
421 | 421 | |
|
422 | 422 | } |
|
423 | 423 | |
|
424 | 424 | void QChartPrivate::createConnections() |
|
425 | 425 | { |
|
426 | 426 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
427 | 427 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
428 | 428 | QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*))); |
|
429 | 429 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
430 | 430 | //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF))); |
|
431 | 431 | } |
|
432 | 432 | |
|
433 | 433 | #include "moc_qchart.cpp" |
|
434 | 434 | |
|
435 | 435 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now