@@ -1,505 +1,526 | |||
|
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 <QGraphicsScene> |
|
29 | 29 | #include <QGraphicsSceneResizeEvent> |
|
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::minimumMargins |
|
88 | 88 | Minimum margins between the plot area (axes) and the edge of the chart widget. |
|
89 | 89 | */ |
|
90 | 90 | |
|
91 | 91 | /*! |
|
92 | 92 | \property QChart::theme |
|
93 | 93 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
94 | 94 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few |
|
95 | 95 | different themes. |
|
96 | 96 | Note: changing the theme will overwrite all customizations previously applied to the series. |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \property QChart::title |
|
101 | 101 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. |
|
102 | 102 | */ |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
106 | 106 | */ |
|
107 | 107 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
108 | 108 | : QGraphicsWidget(parent, wFlags), |
|
109 | 109 | d_ptr(new QChartPrivate()) |
|
110 | 110 | { |
|
111 | 111 | d_ptr->m_dataset = new ChartDataSet(this); |
|
112 | 112 | d_ptr->m_presenter = new ChartPresenter(this, d_ptr->m_dataset); |
|
113 | 113 | d_ptr->createConnections(); |
|
114 | 114 | d_ptr->m_legend = new LegendScroller(this); |
|
115 | 115 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); |
|
116 | 116 | //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF))); |
|
117 | 117 | setLayout(d_ptr->m_presenter->layout()); |
|
118 | 118 | } |
|
119 | 119 | |
|
120 | 120 | /*! |
|
121 | 121 | Destroys the object and it's children, like series and axis objects added to it. |
|
122 | 122 | */ |
|
123 | 123 | QChart::~QChart() |
|
124 | 124 | { |
|
125 | 125 | //delete first presenter , since this is a root of all the graphical items |
|
126 | 126 | setLayout(0); |
|
127 | 127 | delete d_ptr->m_presenter; |
|
128 | 128 | d_ptr->m_presenter = 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 | d_ptr->m_dataset->removeAllSeries(); |
|
164 | 164 | } |
|
165 | 165 | |
|
166 | 166 | /*! |
|
167 | 167 | Sets the \a brush that is used for painting the background of the chart area. |
|
168 | 168 | */ |
|
169 | 169 | void QChart::setBackgroundBrush(const QBrush &brush) |
|
170 | 170 | { |
|
171 | 171 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
172 | 172 | } |
|
173 | 173 | |
|
174 | 174 | /*! |
|
175 | 175 | Gets the brush that is used for painting the background of the chart area. |
|
176 | 176 | */ |
|
177 | 177 | QBrush QChart::backgroundBrush() const |
|
178 | 178 | { |
|
179 | 179 | return d_ptr->m_presenter->backgroundBrush(); |
|
180 | 180 | } |
|
181 | 181 | |
|
182 | 182 | /*! |
|
183 | 183 | Sets the \a pen that is used for painting the background of the chart area. |
|
184 | 184 | */ |
|
185 | 185 | void QChart::setBackgroundPen(const QPen &pen) |
|
186 | 186 | { |
|
187 | 187 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
188 | 188 | } |
|
189 | 189 | |
|
190 | 190 | /*! |
|
191 | 191 | Gets the pen that is used for painting the background of the chart area. |
|
192 | 192 | */ |
|
193 | 193 | QPen QChart::backgroundPen() const |
|
194 | 194 | { |
|
195 | 195 | return d_ptr->m_presenter->backgroundPen(); |
|
196 | 196 | } |
|
197 | 197 | |
|
198 | 198 | /*! |
|
199 | 199 | Sets the chart \a title. The description text that is drawn above the chart. |
|
200 | 200 | */ |
|
201 | 201 | void QChart::setTitle(const QString &title) |
|
202 | 202 | { |
|
203 | 203 | d_ptr->m_presenter->setTitle(title); |
|
204 | 204 | } |
|
205 | 205 | |
|
206 | 206 | /*! |
|
207 | 207 | Returns the chart title. The description text that is drawn above the chart. |
|
208 | 208 | */ |
|
209 | 209 | QString QChart::title() const |
|
210 | 210 | { |
|
211 | 211 | return d_ptr->m_presenter->title(); |
|
212 | 212 | } |
|
213 | 213 | |
|
214 | 214 | /*! |
|
215 | 215 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. |
|
216 | 216 | */ |
|
217 | 217 | void QChart::setTitleFont(const QFont &font) |
|
218 | 218 | { |
|
219 | 219 | d_ptr->m_presenter->setTitleFont(font); |
|
220 | 220 | } |
|
221 | 221 | |
|
222 | 222 | /*! |
|
223 | 223 | Gets the font that is used for drawing the chart description text that is rendered above the chart. |
|
224 | 224 | */ |
|
225 | 225 | QFont QChart::titleFont() const |
|
226 | 226 | { |
|
227 | 227 | return d_ptr->m_presenter->titleFont(); |
|
228 | 228 | } |
|
229 | 229 | |
|
230 | 230 | /*! |
|
231 | 231 | Sets the \a brush used for rendering the title text. |
|
232 | 232 | */ |
|
233 | 233 | void QChart::setTitleBrush(const QBrush &brush) |
|
234 | 234 | { |
|
235 | 235 | d_ptr->m_presenter->setTitleBrush(brush); |
|
236 | 236 | } |
|
237 | 237 | |
|
238 | 238 | /*! |
|
239 | 239 | Returns the brush used for rendering the title text. |
|
240 | 240 | */ |
|
241 | 241 | QBrush QChart::titleBrush() const |
|
242 | 242 | { |
|
243 | 243 | return d_ptr->m_presenter->titleBrush(); |
|
244 | 244 | } |
|
245 | 245 | |
|
246 | 246 | void QChart::setTheme(QChart::ChartTheme theme) |
|
247 | 247 | { |
|
248 | 248 | d_ptr->m_presenter->setTheme(theme); |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | QChart::ChartTheme QChart::theme() const |
|
252 | 252 | { |
|
253 | 253 | return d_ptr->m_presenter->theme(); |
|
254 | 254 | } |
|
255 | 255 | |
|
256 | 256 | /*! |
|
257 | 257 | Zooms in the view by a factor of 2 |
|
258 | 258 | */ |
|
259 | 259 | void QChart::zoomIn() |
|
260 | 260 | { |
|
261 | 261 | d_ptr->m_presenter->zoomIn(2.0); |
|
262 | 262 | } |
|
263 | 263 | |
|
264 | 264 | /*! |
|
265 | 265 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
266 | 266 | */ |
|
267 | 267 | void QChart::zoomIn(const QRectF &rect) |
|
268 | 268 | { |
|
269 | 269 | if (!rect.isValid()) |
|
270 | 270 | return; |
|
271 | 271 | d_ptr->m_presenter->zoomIn(rect); |
|
272 | 272 | } |
|
273 | 273 | |
|
274 | 274 | /*! |
|
275 | 275 | Restores the view zoom level to the previous one. |
|
276 | 276 | */ |
|
277 | 277 | void QChart::zoomOut() |
|
278 | 278 | { |
|
279 | 279 | d_ptr->m_presenter->zoomOut(2.0); |
|
280 | 280 | } |
|
281 | 281 | |
|
282 | 282 | /*! |
|
283 | 283 | Zooms in the view by a \a factor. |
|
284 | 284 | |
|
285 | 285 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
286 | 286 | */ |
|
287 | 287 | void QChart::zoom(qreal factor) |
|
288 | 288 | { |
|
289 | 289 | if (qFuzzyCompare(factor, 0)) |
|
290 | 290 | return; |
|
291 | 291 | |
|
292 | 292 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
293 | 293 | return; |
|
294 | 294 | |
|
295 | 295 | if (factor < 0) |
|
296 | 296 | return; |
|
297 | 297 | |
|
298 | 298 | if (factor > 1.0) |
|
299 | 299 | d_ptr->m_presenter->zoomIn(factor); |
|
300 | 300 | else |
|
301 | 301 | d_ptr->m_presenter->zoomOut(1.0 / factor); |
|
302 | 302 | } |
|
303 | 303 | |
|
304 | 304 | /*! |
|
305 | 305 | Returns the pointer to the x axis object of the chart asociated with the specified \a series |
|
306 | 306 | If no series is provided then pointer to currently visible axis is provided |
|
307 | 307 | */ |
|
308 | 308 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const |
|
309 | 309 | { |
|
310 | 310 | return d_ptr->m_dataset->axisX(series); |
|
311 | 311 | } |
|
312 | 312 | |
|
313 | 313 | /*! |
|
314 | 314 | Returns the pointer to the y axis object of the chart asociated with the specified \a series |
|
315 | 315 | If no series is provided then pointer to currently visible axis is provided |
|
316 | 316 | */ |
|
317 | 317 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const |
|
318 | 318 | { |
|
319 | 319 | return d_ptr->m_dataset->axisY(series); |
|
320 | 320 | } |
|
321 | 321 | |
|
322 | 322 | /*! |
|
323 | 323 | 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. |
|
324 | 324 | |
|
325 | 325 | Creates the axes for the chart based on the series that has already been added to the chart. |
|
326 | 326 | |
|
327 | 327 | \table |
|
328 | 328 | \header |
|
329 | 329 | \o Series type |
|
330 | 330 | \o X-axis |
|
331 | 331 | \o Y-axis |
|
332 | 332 | \row |
|
333 | 333 | \o QXYSeries |
|
334 | 334 | \o QValueAxis |
|
335 | 335 | \o QValueAxis |
|
336 | 336 | \row |
|
337 | 337 | \o QBarSeries |
|
338 | 338 | \o QBarCategoryAxis |
|
339 | 339 | \o QValueAxis |
|
340 | 340 | \row |
|
341 | 341 | \o QPieSeries |
|
342 | 342 | \o None |
|
343 | 343 | \o None |
|
344 | 344 | \endtable |
|
345 | 345 | |
|
346 | 346 | 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. |
|
347 | 347 | If there are sevaral series added of different types then each series gets its own axes pair. |
|
348 | 348 | |
|
349 | 349 | 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. |
|
350 | 350 | |
|
351 | 351 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. |
|
352 | 352 | QPieSeries does not create any axes. |
|
353 | 353 | |
|
354 | 354 | \sa axisX(), axisY(), setAxisX(), setAxisY() |
|
355 | 355 | */ |
|
356 | 356 | void QChart::createDefaultAxes() |
|
357 | 357 | { |
|
358 | 358 | d_ptr->m_dataset->createDefaultAxes(); |
|
359 | 359 | } |
|
360 | 360 | |
|
361 | 361 | /*! |
|
362 | 362 | Returns the legend object of the chart. Ownership stays in chart. |
|
363 | 363 | */ |
|
364 | 364 | QLegend *QChart::legend() const |
|
365 | 365 | { |
|
366 | 366 | return d_ptr->m_legend; |
|
367 | 367 | } |
|
368 | 368 | |
|
369 | 369 | /*! |
|
370 | 370 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
371 | Deprecated. Use setMargins(). | |
|
372 | */ | |
|
373 | void QChart::setMinimumMargins(const QMargins &margins) | |
|
374 | { | |
|
375 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; | |
|
376 | d_ptr->m_presenter->layout()->setMargins(margins); | |
|
377 | } | |
|
378 | ||
|
379 | /*! | |
|
380 | Returns the rect that contains information about margins (distance between chart widget edge and axes). | |
|
381 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. | |
|
382 | Deprecated. Use margins(). | |
|
383 | */ | |
|
384 | QMargins QChart::minimumMargins() const | |
|
385 | { | |
|
386 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; | |
|
387 | return d_ptr->m_presenter->layout()->margins(); | |
|
388 | } | |
|
389 | ||
|
390 | /*! | |
|
391 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. | |
|
371 | 392 | */ |
|
372 | 393 | void QChart::setMargins(const QMargins &margins) |
|
373 | 394 | { |
|
374 | 395 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
375 | 396 | } |
|
376 | 397 | |
|
377 | 398 | /*! |
|
378 | 399 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
379 | 400 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
380 | 401 | */ |
|
381 | 402 | QMargins QChart::margins() const |
|
382 | 403 | { |
|
383 | 404 | return d_ptr->m_presenter->layout()->margins(); |
|
384 | 405 | } |
|
385 | 406 | |
|
386 | 407 | /*! |
|
387 | 408 | Returns the the rect within which the drawing of the chart is done. |
|
388 | 409 | It does not include the area defines by margins. |
|
389 | 410 | */ |
|
390 | 411 | QRectF QChart::plotArea() const |
|
391 | 412 | { |
|
392 | 413 | return d_ptr->m_presenter->layout()->chartsGeometry(); |
|
393 | 414 | } |
|
394 | 415 | |
|
395 | 416 | ///*! |
|
396 | 417 | // TODO: Dummy. |
|
397 | 418 | // Adjest the ranges of the axes so that all the data of the specified \a series is visible |
|
398 | 419 | // */ |
|
399 | 420 | //void QChart::adjustViewToSeries(QAbstractSeries* series) |
|
400 | 421 | //{ |
|
401 | 422 | // // |
|
402 | 423 | //} |
|
403 | 424 | |
|
404 | 425 | /*! |
|
405 | 426 | Sets animation \a options for the chart |
|
406 | 427 | */ |
|
407 | 428 | void QChart::setAnimationOptions(AnimationOptions options) |
|
408 | 429 | { |
|
409 | 430 | d_ptr->m_presenter->setAnimationOptions(options); |
|
410 | 431 | } |
|
411 | 432 | |
|
412 | 433 | QChart::AnimationOptions QChart::animationOptions() const |
|
413 | 434 | { |
|
414 | 435 | return d_ptr->m_presenter->animationOptions(); |
|
415 | 436 | } |
|
416 | 437 | |
|
417 | 438 | /*! |
|
418 | 439 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
419 | 440 | */ |
|
420 | 441 | void QChart::scroll(qreal dx, qreal dy) |
|
421 | 442 | { |
|
422 | 443 | d_ptr->m_presenter->scroll(dx, dy); |
|
423 | 444 | } |
|
424 | 445 | |
|
425 | 446 | void QChart::setBackgroundVisible(bool visible) |
|
426 | 447 | { |
|
427 | 448 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
428 | 449 | } |
|
429 | 450 | |
|
430 | 451 | bool QChart::isBackgroundVisible() const |
|
431 | 452 | { |
|
432 | 453 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
433 | 454 | } |
|
434 | 455 | |
|
435 | 456 | void QChart::setDropShadowEnabled(bool enabled) |
|
436 | 457 | { |
|
437 | 458 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
438 | 459 | } |
|
439 | 460 | |
|
440 | 461 | bool QChart::isDropShadowEnabled() const |
|
441 | 462 | { |
|
442 | 463 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
443 | 464 | } |
|
444 | 465 | |
|
445 | 466 | /*! |
|
446 | 467 | Returns all the series that are added to the chart. |
|
447 | 468 | |
|
448 | 469 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
449 | 470 | */ |
|
450 | 471 | QList<QAbstractSeries *> QChart::series() const |
|
451 | 472 | { |
|
452 | 473 | return d_ptr->m_dataset->series(); |
|
453 | 474 | } |
|
454 | 475 | |
|
455 | 476 | /*! |
|
456 | 477 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
457 | 478 | |
|
458 | 479 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() |
|
459 | 480 | */ |
|
460 | 481 | void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series) |
|
461 | 482 | { |
|
462 | 483 | if (axis->alignment() == Qt::AlignLeft || axis->alignment() == Qt::AlignRight) |
|
463 | 484 | return; |
|
464 | 485 | d_ptr->m_dataset->setAxis(series, axis, Qt::Horizontal); |
|
465 | 486 | } |
|
466 | 487 | |
|
467 | 488 | /*! |
|
468 | 489 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
469 | 490 | |
|
470 | 491 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() |
|
471 | 492 | */ |
|
472 | 493 | void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series) |
|
473 | 494 | { |
|
474 | 495 | if (axis->alignment() == Qt::AlignTop || axis->alignment() == Qt::AlignBottom) |
|
475 | 496 | return; |
|
476 | 497 | d_ptr->m_dataset->setAxis(series, axis, Qt::Vertical); |
|
477 | 498 | } |
|
478 | 499 | |
|
479 | 500 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
480 | 501 | |
|
481 | 502 | QChartPrivate::QChartPrivate(): |
|
482 | 503 | m_legend(0), |
|
483 | 504 | m_dataset(0), |
|
484 | 505 | m_presenter(0) |
|
485 | 506 | { |
|
486 | 507 | |
|
487 | 508 | } |
|
488 | 509 | |
|
489 | 510 | QChartPrivate::~QChartPrivate() |
|
490 | 511 | { |
|
491 | 512 | |
|
492 | 513 | } |
|
493 | 514 | |
|
494 | 515 | void QChartPrivate::createConnections() |
|
495 | 516 | { |
|
496 | 517 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
497 | 518 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
498 | 519 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*,Domain*))); |
|
499 | 520 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
500 | 521 | //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF))); |
|
501 | 522 | } |
|
502 | 523 | |
|
503 | 524 | #include "moc_qchart.cpp" |
|
504 | 525 | |
|
505 | 526 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,133 +1,136 | |||
|
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 | struct 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 | 79 | void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
80 | 80 | void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
81 | 81 | |
|
82 | 82 | QAbstractAxis *axisX(QAbstractSeries *series = 0) const; |
|
83 | 83 | QAbstractAxis *axisY(QAbstractSeries *series = 0) const; |
|
84 | 84 | |
|
85 | 85 | void createDefaultAxes(); |
|
86 | 86 | |
|
87 | 87 | void setTheme(QChart::ChartTheme theme); |
|
88 | 88 | QChart::ChartTheme theme() const; |
|
89 | 89 | |
|
90 | 90 | void setTitle(const QString &title); |
|
91 | 91 | QString title() const; |
|
92 | 92 | void setTitleFont(const QFont &font); |
|
93 | 93 | QFont titleFont() const; |
|
94 | 94 | void setTitleBrush(const QBrush &brush); |
|
95 | 95 | QBrush titleBrush() const; |
|
96 | 96 | |
|
97 | 97 | void setBackgroundBrush(const QBrush &brush); |
|
98 | 98 | QBrush backgroundBrush() const; |
|
99 | 99 | void setBackgroundPen(const QPen &pen); |
|
100 | 100 | QPen backgroundPen() const; |
|
101 | 101 | void setBackgroundVisible(bool visible = true); |
|
102 | 102 | bool isBackgroundVisible() const; |
|
103 | 103 | |
|
104 | 104 | void setDropShadowEnabled(bool enabled = true); |
|
105 | 105 | bool isDropShadowEnabled() const; |
|
106 | 106 | void setAnimationOptions(AnimationOptions options); |
|
107 | 107 | AnimationOptions animationOptions() const; |
|
108 | 108 | |
|
109 | 109 | void zoomIn(); |
|
110 | 110 | void zoomIn(const QRectF &rect); |
|
111 | 111 | void zoomOut(); |
|
112 | 112 | void zoom(qreal factor); |
|
113 | 113 | void scroll(qreal dx, qreal dy); |
|
114 | 114 | |
|
115 | 115 | QLegend *legend() const; |
|
116 | 116 | |
|
117 | void setMinimumMargins(const QMargins& margins); | |
|
118 | QMargins minimumMargins() const; | |
|
119 | ||
|
117 | 120 | void setMargins(const QMargins &margins); |
|
118 | 121 | QMargins margins() const; |
|
119 | 122 | |
|
120 | 123 | QRectF plotArea() const; |
|
121 | 124 | |
|
122 | 125 | protected: |
|
123 | 126 | QScopedPointer<QChartPrivate> d_ptr; |
|
124 | 127 | friend class QLegend; |
|
125 | 128 | friend class DeclarativeChart; |
|
126 | 129 | Q_DISABLE_COPY(QChart) |
|
127 | 130 | }; |
|
128 | 131 | |
|
129 | 132 | QTCOMMERCIALCHART_END_NAMESPACE |
|
130 | 133 | |
|
131 | 134 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
132 | 135 | |
|
133 | 136 | #endif // QCHART_H |
General Comments 0
You need to be logged in to leave comments.
Login now