@@ -1,665 +1,665 | |||
|
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 "chartlayout_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | #include "chartpresenter_p.h" |
|
30 | 30 | #include "chartdataset_p.h" |
|
31 | 31 | #include <QGraphicsScene> |
|
32 | 32 | #include <QGraphicsSceneResizeEvent> |
|
33 | 33 | |
|
34 | 34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | 35 | |
|
36 | 36 | /*! |
|
37 | 37 | \enum QChart::ChartTheme |
|
38 | 38 | |
|
39 | 39 | This enum describes the theme used by the chart. |
|
40 | 40 | |
|
41 | 41 | \value ChartThemeLight The default theme |
|
42 | 42 | \value ChartThemeBlueCerulean |
|
43 | 43 | \value ChartThemeDark |
|
44 | 44 | \value ChartThemeBrownSand |
|
45 | 45 | \value ChartThemeBlueNcs |
|
46 | 46 | \value ChartThemeHighContrast |
|
47 | 47 | \value ChartThemeBlueIcy |
|
48 | 48 | */ |
|
49 | 49 | |
|
50 | 50 | /*! |
|
51 | 51 | \enum QChart::AnimationOption |
|
52 | 52 | |
|
53 | 53 | For enabling/disabling animations. Defaults to NoAnimation. |
|
54 | 54 | |
|
55 | 55 | \value NoAnimation |
|
56 | 56 | \value GridAxisAnimations |
|
57 | 57 | \value SeriesAnimations |
|
58 | 58 | \value AllAnimations |
|
59 | 59 | */ |
|
60 | 60 | |
|
61 | 61 | /*! |
|
62 | 62 | \class QChart |
|
63 | 63 | \brief QtCommercial chart API. |
|
64 | 64 | |
|
65 | 65 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
66 | 66 | representation of different types of series and other chart related objects like |
|
67 | 67 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the |
|
68 | 68 | convenience class QChartView instead of QChart. |
|
69 | 69 | \sa QChartView |
|
70 | 70 | */ |
|
71 | 71 | |
|
72 | 72 | /*! |
|
73 | 73 | \property QChart::animationOptions |
|
74 | 74 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
75 | 75 | */ |
|
76 | 76 | |
|
77 | 77 | /*! |
|
78 | 78 | \property QChart::backgroundVisible |
|
79 | 79 | Whether the chart background is visible or not. |
|
80 | 80 | \sa setBackgroundBrush(), setBackgroundPen() |
|
81 | 81 | */ |
|
82 | 82 | |
|
83 | 83 | /*! |
|
84 | 84 | \property QChart::dropShadowEnabled |
|
85 | 85 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
86 | 86 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
87 | 87 | */ |
|
88 | 88 | |
|
89 | 89 | /*! |
|
90 | 90 | \property QChart::minimumMargins |
|
91 | 91 | Minimum margins between the plot area (axes) and the edge of the chart widget. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \property QChart::theme |
|
96 | 96 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
97 | 97 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few |
|
98 | 98 | different themes. |
|
99 | 99 | Note: changing the theme will overwrite all customizations previously applied to the series. |
|
100 | 100 | */ |
|
101 | 101 | |
|
102 | 102 | /*! |
|
103 | 103 | \property QChart::title |
|
104 | 104 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. |
|
105 | 105 | */ |
|
106 | 106 | |
|
107 | 107 | /*! |
|
108 | 108 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
109 | 109 | */ |
|
110 | 110 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
111 | 111 | : QGraphicsWidget(parent, wFlags), |
|
112 | 112 | d_ptr(new QChartPrivate(this)) |
|
113 | 113 | { |
|
114 | 114 | d_ptr->m_legend = new LegendScroller(this); |
|
115 | 115 | setTheme(QChart::ChartThemeLight); |
|
116 | 116 | //TODO: what is that ? |
|
117 | 117 | //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF))); |
|
118 | 118 | setLayout(d_ptr->m_presenter->layout()); |
|
119 | 119 | } |
|
120 | 120 | |
|
121 | 121 | /*! |
|
122 | 122 | Destroys the object and it's children, like series and axis objects added to it. |
|
123 | 123 | */ |
|
124 | 124 | QChart::~QChart() |
|
125 | 125 | { |
|
126 | 126 | //start by deleting dataset, it will remove all series and axes |
|
127 | 127 | delete d_ptr->m_dataset; |
|
128 | 128 | d_ptr->m_dataset = 0; |
|
129 | 129 | } |
|
130 | 130 | |
|
131 | 131 | /*! |
|
132 | 132 | Adds the \a series onto the chart and takes the ownership of the object. |
|
133 | 133 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
134 | 134 | the y axis). |
|
135 | 135 | |
|
136 | 136 | \sa removeSeries(), removeAllSeries() |
|
137 | 137 | */ |
|
138 | 138 | void QChart::addSeries(QAbstractSeries *series) |
|
139 | 139 | { |
|
140 | 140 | Q_ASSERT(series); |
|
141 | 141 | d_ptr->m_dataset->addSeries(series); |
|
142 | 142 | } |
|
143 | 143 | |
|
144 | 144 | /*! |
|
145 | 145 | Removes the \a series specified in a perameter from the QChartView. |
|
146 | 146 | It releses its ownership of the specified QChartSeries object. |
|
147 | 147 | It does not delete the pointed QChartSeries data object |
|
148 | 148 | \sa addSeries(), removeAllSeries() |
|
149 | 149 | */ |
|
150 | 150 | void QChart::removeSeries(QAbstractSeries *series) |
|
151 | 151 | { |
|
152 | 152 | Q_ASSERT(series); |
|
153 | 153 | d_ptr->m_dataset->removeSeries(series); |
|
154 | 154 | } |
|
155 | 155 | |
|
156 | 156 | /*! |
|
157 | 157 | Removes all the QChartSeries that have been added to the QChartView |
|
158 | 158 | It also deletes the pointed QChartSeries data objects |
|
159 | 159 | \sa addSeries(), removeSeries() |
|
160 | 160 | */ |
|
161 | 161 | void QChart::removeAllSeries() |
|
162 | 162 | { |
|
163 | 163 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ |
|
164 | 164 | removeSeries(s); |
|
165 | 165 | delete s; |
|
166 | 166 | } |
|
167 | 167 | } |
|
168 | 168 | |
|
169 | 169 | /*! |
|
170 | 170 | Sets the \a brush that is used for painting the background of the chart area. |
|
171 | 171 | */ |
|
172 | 172 | void QChart::setBackgroundBrush(const QBrush &brush) |
|
173 | 173 | { |
|
174 | 174 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
175 | 175 | } |
|
176 | 176 | |
|
177 | 177 | /*! |
|
178 | 178 | Gets the brush that is used for painting the background of the chart area. |
|
179 | 179 | */ |
|
180 | 180 | QBrush QChart::backgroundBrush() const |
|
181 | 181 | { |
|
182 | 182 | return d_ptr->m_presenter->backgroundBrush(); |
|
183 | 183 | } |
|
184 | 184 | |
|
185 | 185 | /*! |
|
186 | 186 | Sets the \a pen that is used for painting the background of the chart area. |
|
187 | 187 | */ |
|
188 | 188 | void QChart::setBackgroundPen(const QPen &pen) |
|
189 | 189 | { |
|
190 | 190 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
191 | 191 | } |
|
192 | 192 | |
|
193 | 193 | /*! |
|
194 | 194 | Gets the pen that is used for painting the background of the chart area. |
|
195 | 195 | */ |
|
196 | 196 | QPen QChart::backgroundPen() const |
|
197 | 197 | { |
|
198 | 198 | return d_ptr->m_presenter->backgroundPen(); |
|
199 | 199 | } |
|
200 | 200 | |
|
201 | 201 | /*! |
|
202 | 202 | Sets the chart \a title. The description text that is drawn above the chart. |
|
203 | 203 | */ |
|
204 | 204 | void QChart::setTitle(const QString &title) |
|
205 | 205 | { |
|
206 | 206 | d_ptr->m_presenter->setTitle(title); |
|
207 | 207 | } |
|
208 | 208 | |
|
209 | 209 | /*! |
|
210 | 210 | Returns the chart title. The description text that is drawn above the chart. |
|
211 | 211 | */ |
|
212 | 212 | QString QChart::title() const |
|
213 | 213 | { |
|
214 | 214 | return d_ptr->m_presenter->title(); |
|
215 | 215 | } |
|
216 | 216 | |
|
217 | 217 | /*! |
|
218 | 218 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. |
|
219 | 219 | */ |
|
220 | 220 | void QChart::setTitleFont(const QFont &font) |
|
221 | 221 | { |
|
222 | 222 | d_ptr->m_presenter->setTitleFont(font); |
|
223 | 223 | } |
|
224 | 224 | |
|
225 | 225 | /*! |
|
226 | 226 | Gets the font that is used for drawing the chart description text that is rendered above the chart. |
|
227 | 227 | */ |
|
228 | 228 | QFont QChart::titleFont() const |
|
229 | 229 | { |
|
230 | 230 | return d_ptr->m_presenter->titleFont(); |
|
231 | 231 | } |
|
232 | 232 | |
|
233 | 233 | /*! |
|
234 | 234 | Sets the \a brush used for rendering the title text. |
|
235 | 235 | */ |
|
236 | 236 | void QChart::setTitleBrush(const QBrush &brush) |
|
237 | 237 | { |
|
238 | 238 | d_ptr->m_presenter->setTitleBrush(brush); |
|
239 | 239 | } |
|
240 | 240 | |
|
241 | 241 | /*! |
|
242 | 242 | Returns the brush used for rendering the title text. |
|
243 | 243 | */ |
|
244 | 244 | QBrush QChart::titleBrush() const |
|
245 | 245 | { |
|
246 | 246 | return d_ptr->m_presenter->titleBrush(); |
|
247 | 247 | } |
|
248 | 248 | |
|
249 | 249 | void QChart::setTheme(QChart::ChartTheme theme) |
|
250 | 250 | { |
|
251 | 251 | d_ptr->m_themeManager->setTheme(theme); |
|
252 | 252 | } |
|
253 | 253 | |
|
254 | 254 | QChart::ChartTheme QChart::theme() const |
|
255 | 255 | { |
|
256 | 256 | return d_ptr->m_themeManager->theme()->id(); |
|
257 | 257 | } |
|
258 | 258 | |
|
259 | 259 | /*! |
|
260 | 260 | Zooms in the view by a factor of 2 |
|
261 | 261 | */ |
|
262 | 262 | void QChart::zoomIn() |
|
263 | 263 | { |
|
264 | 264 | d_ptr->zoomIn(2.0); |
|
265 | 265 | } |
|
266 | 266 | |
|
267 | 267 | /*! |
|
268 | 268 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
269 | 269 | */ |
|
270 | 270 | void QChart::zoomIn(const QRectF &rect) |
|
271 | 271 | { |
|
272 | 272 | d_ptr->zoomIn(rect); |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | /*! |
|
276 | 276 | Restores the view zoom level to the previous one. |
|
277 | 277 | */ |
|
278 | 278 | void QChart::zoomOut() |
|
279 | 279 | { |
|
280 | 280 | d_ptr->zoomOut(2.0); |
|
281 | 281 | } |
|
282 | 282 | |
|
283 | 283 | /*! |
|
284 | 284 | Zooms in the view by a \a factor. |
|
285 | 285 | |
|
286 | 286 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
287 | 287 | */ |
|
288 | 288 | void QChart::zoom(qreal factor) |
|
289 | 289 | { |
|
290 | 290 | if (qFuzzyCompare(factor, 0)) |
|
291 | 291 | return; |
|
292 | 292 | |
|
293 | 293 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
294 | 294 | return; |
|
295 | 295 | |
|
296 | 296 | if (factor < 0) |
|
297 | 297 | return; |
|
298 | 298 | |
|
299 | 299 | if (factor > 1.0) |
|
300 | 300 | d_ptr->zoomIn(factor); |
|
301 | 301 | else |
|
302 | 302 | d_ptr->zoomOut(1.0 / factor); |
|
303 | 303 | } |
|
304 | 304 | |
|
305 | 305 | /*! |
|
306 | 306 | Returns the pointer to the x axis object of the chart asociated with the specified \a series |
|
307 | 307 | If no series is provided then pointer to currently visible axis is provided |
|
308 | 308 | */ |
|
309 | 309 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const |
|
310 | 310 | { |
|
311 | 311 | if(!series && d_ptr->m_dataset->series().size()>0){ |
|
312 | 312 | series = d_ptr->m_dataset->series().first(); |
|
313 | 313 | } |
|
314 | 314 | |
|
315 | 315 | QList<QAbstractAxis*> axes = series->attachedAxes(); |
|
316 | 316 | QAbstractAxis* bottom=0; |
|
317 | 317 | QAbstractAxis* top=0; |
|
318 | 318 | |
|
319 | 319 | foreach(QAbstractAxis* axis, axes){ |
|
320 | 320 | |
|
321 | 321 | if(axis->alignment()==Qt::AlignTop){ |
|
322 | 322 | top=axis; |
|
323 | 323 | } |
|
324 | 324 | |
|
325 | 325 | if(axis->alignment()==Qt::AlignBottom){ |
|
326 | 326 | bottom=axis; |
|
327 | 327 | } |
|
328 | 328 | } |
|
329 | 329 | return bottom?bottom:top; |
|
330 | 330 | } |
|
331 | 331 | |
|
332 | 332 | /*! |
|
333 | 333 | Returns the pointer to the y axis object of the chart asociated with the specified \a series |
|
334 | 334 | If no series is provided then pointer to currently visible axis is provided |
|
335 | 335 | */ |
|
336 | 336 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const |
|
337 | 337 | { |
|
338 | 338 | if(!series && d_ptr->m_dataset->series().size()>0) { |
|
339 | 339 | series = d_ptr->m_dataset->series().first(); |
|
340 | 340 | } |
|
341 | 341 | |
|
342 | 342 | QList<QAbstractAxis*> axes = series->attachedAxes(); |
|
343 | 343 | |
|
344 | 344 | QAbstractAxis* left=0; |
|
345 | 345 | QAbstractAxis* right=0; |
|
346 | 346 | |
|
347 | 347 | foreach(QAbstractAxis* axis, axes){ |
|
348 | 348 | |
|
349 | 349 | if(axis->alignment()==Qt::AlignLeft){ |
|
350 | 350 | left=axis; |
|
351 | 351 | } |
|
352 | 352 | |
|
353 | 353 | if(axis->alignment()==Qt::AlignRight){ |
|
354 | 354 | right=axis; |
|
355 | 355 | } |
|
356 | 356 | } |
|
357 | 357 | |
|
358 | 358 | return left?left:right; |
|
359 | 359 | } |
|
360 | 360 | |
|
361 | 361 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const |
|
362 | 362 | { |
|
363 | 363 | QList<QAbstractAxis *> result ; |
|
364 | 364 | |
|
365 | 365 | if (series) { |
|
366 | 366 | foreach (QAbstractAxis *axis, series->attachedAxes()){ |
|
367 | 367 | if (orientation.testFlag(axis->orientation())) |
|
368 | 368 | result << axis; |
|
369 | 369 | } |
|
370 | 370 | } else { |
|
371 | 371 | foreach (QAbstractSeries *s, QChart::series()) { |
|
372 | 372 | foreach (QAbstractAxis *axis, s->attachedAxes()){ |
|
373 | if (orientation.testFlag(axis->orientation())) | |
|
373 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) | |
|
374 | 374 | result << axis; |
|
375 | 375 | } |
|
376 | 376 | } |
|
377 | 377 | } |
|
378 | 378 | |
|
379 | 379 | return result; |
|
380 | 380 | } |
|
381 | 381 | |
|
382 | 382 | /*! |
|
383 | 383 | 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. |
|
384 | 384 | |
|
385 | 385 | Creates the axes for the chart based on the series that has already been added to the chart. |
|
386 | 386 | |
|
387 | 387 | \table |
|
388 | 388 | \header |
|
389 | 389 | \o Series type |
|
390 | 390 | \o X-axis |
|
391 | 391 | \o Y-axis |
|
392 | 392 | \row |
|
393 | 393 | \o QXYSeries |
|
394 | 394 | \o QValueAxis |
|
395 | 395 | \o QValueAxis |
|
396 | 396 | \row |
|
397 | 397 | \o QBarSeries |
|
398 | 398 | \o QBarCategoryAxis |
|
399 | 399 | \o QValueAxis |
|
400 | 400 | \row |
|
401 | 401 | \o QPieSeries |
|
402 | 402 | \o None |
|
403 | 403 | \o None |
|
404 | 404 | \endtable |
|
405 | 405 | |
|
406 | 406 | 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. |
|
407 | 407 | If there are sevaral series added of different types then each series gets its own axes pair. |
|
408 | 408 | |
|
409 | 409 | 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. |
|
410 | 410 | |
|
411 | 411 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. |
|
412 | 412 | QPieSeries does not create any axes. |
|
413 | 413 | |
|
414 | 414 | \sa axisX(), axisY(), setAxisX(), setAxisY() |
|
415 | 415 | */ |
|
416 | 416 | void QChart::createDefaultAxes() |
|
417 | 417 | { |
|
418 | 418 | d_ptr->m_dataset->createDefaultAxes(); |
|
419 | 419 | } |
|
420 | 420 | |
|
421 | 421 | /*! |
|
422 | 422 | Returns the legend object of the chart. Ownership stays in chart. |
|
423 | 423 | */ |
|
424 | 424 | QLegend *QChart::legend() const |
|
425 | 425 | { |
|
426 | 426 | return d_ptr->m_legend; |
|
427 | 427 | } |
|
428 | 428 | |
|
429 | 429 | /*! |
|
430 | 430 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
431 | 431 | Deprecated. Use setMargins(). |
|
432 | 432 | */ |
|
433 | 433 | void QChart::setMinimumMargins(const QMargins &margins) |
|
434 | 434 | { |
|
435 | 435 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; |
|
436 | 436 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
437 | 437 | } |
|
438 | 438 | |
|
439 | 439 | /*! |
|
440 | 440 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
441 | 441 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
442 | 442 | Deprecated. Use margins(). |
|
443 | 443 | */ |
|
444 | 444 | QMargins QChart::minimumMargins() const |
|
445 | 445 | { |
|
446 | 446 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; |
|
447 | 447 | return d_ptr->m_presenter->layout()->margins(); |
|
448 | 448 | } |
|
449 | 449 | |
|
450 | 450 | /*! |
|
451 | 451 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
452 | 452 | */ |
|
453 | 453 | void QChart::setMargins(const QMargins &margins) |
|
454 | 454 | { |
|
455 | 455 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
456 | 456 | } |
|
457 | 457 | |
|
458 | 458 | /*! |
|
459 | 459 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
460 | 460 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
461 | 461 | */ |
|
462 | 462 | QMargins QChart::margins() const |
|
463 | 463 | { |
|
464 | 464 | return d_ptr->m_presenter->layout()->margins(); |
|
465 | 465 | } |
|
466 | 466 | |
|
467 | 467 | /*! |
|
468 | 468 | Returns the the rect within which the drawing of the chart is done. |
|
469 | 469 | It does not include the area defines by margins. |
|
470 | 470 | */ |
|
471 | 471 | QRectF QChart::plotArea() const |
|
472 | 472 | { |
|
473 | 473 | return d_ptr->m_presenter->geometry(); |
|
474 | 474 | } |
|
475 | 475 | |
|
476 | 476 | ///*! |
|
477 | 477 | // TODO: Dummy. |
|
478 | 478 | // Adjest the ranges of the axes so that all the data of the specified \a series is visible |
|
479 | 479 | // */ |
|
480 | 480 | //void QChart::adjustViewToSeries(QAbstractSeries* series) |
|
481 | 481 | //{ |
|
482 | 482 | // // |
|
483 | 483 | //} |
|
484 | 484 | |
|
485 | 485 | /*! |
|
486 | 486 | Sets animation \a options for the chart |
|
487 | 487 | */ |
|
488 | 488 | void QChart::setAnimationOptions(AnimationOptions options) |
|
489 | 489 | { |
|
490 | 490 | d_ptr->m_presenter->setAnimationOptions(options); |
|
491 | 491 | } |
|
492 | 492 | |
|
493 | 493 | QChart::AnimationOptions QChart::animationOptions() const |
|
494 | 494 | { |
|
495 | 495 | return d_ptr->m_presenter->animationOptions(); |
|
496 | 496 | } |
|
497 | 497 | |
|
498 | 498 | /*! |
|
499 | 499 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
500 | 500 | */ |
|
501 | 501 | void QChart::scroll(qreal dx, qreal dy) |
|
502 | 502 | { |
|
503 | 503 | d_ptr->scroll(dx,dy); |
|
504 | 504 | } |
|
505 | 505 | |
|
506 | 506 | void QChart::setBackgroundVisible(bool visible) |
|
507 | 507 | { |
|
508 | 508 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
509 | 509 | } |
|
510 | 510 | |
|
511 | 511 | bool QChart::isBackgroundVisible() const |
|
512 | 512 | { |
|
513 | 513 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
514 | 514 | } |
|
515 | 515 | |
|
516 | 516 | void QChart::setDropShadowEnabled(bool enabled) |
|
517 | 517 | { |
|
518 | 518 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
519 | 519 | } |
|
520 | 520 | |
|
521 | 521 | bool QChart::isDropShadowEnabled() const |
|
522 | 522 | { |
|
523 | 523 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
524 | 524 | } |
|
525 | 525 | |
|
526 | 526 | /*! |
|
527 | 527 | Returns all the series that are added to the chart. |
|
528 | 528 | |
|
529 | 529 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
530 | 530 | */ |
|
531 | 531 | QList<QAbstractSeries *> QChart::series() const |
|
532 | 532 | { |
|
533 | 533 | return d_ptr->m_dataset->series(); |
|
534 | 534 | } |
|
535 | 535 | |
|
536 | 536 | /*! |
|
537 | 537 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
538 | 538 | |
|
539 | 539 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() |
|
540 | 540 | */ |
|
541 | 541 | void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series) |
|
542 | 542 | { |
|
543 | 543 | QList<QAbstractAxis*> list = axes(Qt::Horizontal,series); |
|
544 | 544 | |
|
545 | 545 | foreach(QAbstractAxis* a, list){ |
|
546 | 546 | d_ptr->m_dataset->removeAxis(a); |
|
547 | 547 | delete a; |
|
548 | 548 | } |
|
549 | 549 | |
|
550 | 550 | if(!d_ptr->m_dataset->axes().contains(axis)) |
|
551 | 551 | d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom); |
|
552 | 552 | d_ptr->m_dataset->attachAxis(series,axis); |
|
553 | 553 | } |
|
554 | 554 | |
|
555 | 555 | /*! |
|
556 | 556 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
557 | 557 | |
|
558 | 558 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() |
|
559 | 559 | */ |
|
560 | 560 | void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series) |
|
561 | 561 | { |
|
562 | 562 | QList<QAbstractAxis*> list = axes(Qt::Vertical,series); |
|
563 | 563 | |
|
564 | 564 | foreach(QAbstractAxis* a, list) { |
|
565 | 565 | d_ptr->m_dataset->removeAxis(a); |
|
566 | 566 | delete a; |
|
567 | 567 | } |
|
568 | 568 | |
|
569 | 569 | if(!d_ptr->m_dataset->axes().contains(axis)) |
|
570 | 570 | d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft); |
|
571 | 571 | d_ptr->m_dataset->attachAxis(series,axis); |
|
572 | 572 | } |
|
573 | 573 | |
|
574 | 574 | void QChart::addAxis(QAbstractAxis *axis,Qt::Alignment aligment) |
|
575 | 575 | { |
|
576 | 576 | d_ptr->m_dataset->addAxis(axis,aligment); |
|
577 | 577 | } |
|
578 | 578 | |
|
579 | 579 | void QChart::removeAxis(QAbstractAxis *axis) |
|
580 | 580 | { |
|
581 | 581 | d_ptr->m_dataset->removeAxis(axis); |
|
582 | 582 | } |
|
583 | 583 | |
|
584 | 584 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
585 | 585 | |
|
586 | 586 | QChartPrivate::QChartPrivate(QChart *q): |
|
587 | 587 | q_ptr(q), |
|
588 | 588 | m_legend(0), |
|
589 | 589 | m_dataset(new ChartDataSet(q)), |
|
590 | 590 | m_presenter(new ChartPresenter(q)), |
|
591 | 591 | m_themeManager(new ChartThemeManager(q)) |
|
592 | 592 | { |
|
593 | 593 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
594 | 594 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
595 | 595 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
596 | 596 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
597 | 597 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
598 | 598 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
599 | 599 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
600 | 600 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
601 | 601 | } |
|
602 | 602 | |
|
603 | 603 | QChartPrivate::~QChartPrivate() |
|
604 | 604 | { |
|
605 | 605 | |
|
606 | 606 | } |
|
607 | 607 | |
|
608 | 608 | void QChartPrivate::zoomIn(qreal factor) |
|
609 | 609 | { |
|
610 | 610 | QRectF rect = m_presenter->geometry(); |
|
611 | 611 | rect.setWidth(rect.width() / factor); |
|
612 | 612 | rect.setHeight(rect.height() / factor); |
|
613 | 613 | rect.moveCenter(m_presenter->geometry().center()); |
|
614 | 614 | zoomIn(rect); |
|
615 | 615 | } |
|
616 | 616 | |
|
617 | 617 | void QChartPrivate::zoomIn(const QRectF &rect) |
|
618 | 618 | { |
|
619 | 619 | if (!rect.isValid()) |
|
620 | 620 | return; |
|
621 | 621 | |
|
622 | 622 | QRectF r = rect.normalized(); |
|
623 | 623 | const QRectF geometry = m_presenter->geometry(); |
|
624 | 624 | r.translate(-geometry.topLeft()); |
|
625 | 625 | |
|
626 | 626 | if (!r.isValid()) |
|
627 | 627 | return; |
|
628 | 628 | |
|
629 | 629 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
630 | 630 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); |
|
631 | 631 | m_dataset->zoomInDomain(r); |
|
632 | 632 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
633 | 633 | |
|
634 | 634 | } |
|
635 | 635 | |
|
636 | 636 | void QChartPrivate::zoomOut(qreal factor) |
|
637 | 637 | { |
|
638 | 638 | const QRectF geometry = m_presenter->geometry(); |
|
639 | 639 | |
|
640 | 640 | QRectF r; |
|
641 | 641 | r.setSize(geometry.size() / factor); |
|
642 | 642 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); |
|
643 | 643 | if (!r.isValid()) |
|
644 | 644 | return; |
|
645 | 645 | |
|
646 | 646 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
647 | 647 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); |
|
648 | 648 | m_dataset->zoomOutDomain(r); |
|
649 | 649 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
650 | 650 | } |
|
651 | 651 | |
|
652 | 652 | void QChartPrivate::scroll(qreal dx, qreal dy) |
|
653 | 653 | { |
|
654 | 654 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); |
|
655 | 655 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); |
|
656 | 656 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); |
|
657 | 657 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); |
|
658 | 658 | |
|
659 | 659 | m_dataset->scrollDomain(dx, dy); |
|
660 | 660 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
661 | 661 | } |
|
662 | 662 | |
|
663 | 663 | #include "moc_qchart.cpp" |
|
664 | 664 | |
|
665 | 665 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now