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