@@ -1,754 +1,754 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 "abstractchartlayout_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 | \enum QChart::ChartType |
|
63 | 63 | |
|
64 | 64 | This enum describes the chart type. |
|
65 | 65 | |
|
66 | 66 | \value ChartTypeUndefined |
|
67 | 67 | \value ChartTypeCartesian |
|
68 | 68 | \value ChartTypePolar |
|
69 | 69 | */ |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | \class QChart |
|
73 | 73 | \brief QtCommercial chart API. |
|
74 | 74 | |
|
75 | 75 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
76 | 76 | representation of different types of series and other chart related objects like legend and |
|
77 | 77 | axes. If you simply want to show a chart in a layout, you can use the |
|
78 | 78 | convenience class QChartView instead of QChart. |
|
79 | 79 | \sa QChartView, QPolarChart |
|
80 | 80 | */ |
|
81 | 81 | |
|
82 | 82 | /*! |
|
83 | 83 | \property QChart::animationOptions |
|
84 | 84 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
85 | 85 | */ |
|
86 | 86 | |
|
87 | 87 | /*! |
|
88 | 88 | \property QChart::backgroundVisible |
|
89 | 89 | Specifies whether the chart background is visible or not. |
|
90 | 90 | \sa setBackgroundBrush(), setBackgroundPen(), plotAreaBackgroundVisible |
|
91 | 91 | */ |
|
92 | 92 | |
|
93 | 93 | /*! |
|
94 | 94 | \property QChart::dropShadowEnabled |
|
95 | 95 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
96 | 96 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \property QChart::minimumMargins |
|
101 | 101 | Minimum margins between the plot area (axes) and the edge of the chart widget. |
|
102 | 102 | This property is deprecated; use margins property instead. |
|
103 | 103 | |
|
104 | 104 | \sa margins |
|
105 | 105 | */ |
|
106 | 106 | |
|
107 | 107 | /*! |
|
108 | 108 | \property QChart::margins |
|
109 | 109 | Margins between the plot area (axes) and the edge of the chart widget. |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | \property QChart::theme |
|
114 | 114 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
115 | 115 | pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes demo} shows an example with a few |
|
116 | 116 | different themes. |
|
117 | 117 | \note Changing the theme will overwrite all customizations previously applied to the series. |
|
118 | 118 | */ |
|
119 | 119 | |
|
120 | 120 | /*! |
|
121 | 121 | \property QChart::title |
|
122 | 122 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. |
|
123 | 123 | */ |
|
124 | 124 | |
|
125 | 125 | /*! |
|
126 | 126 | \property QChart::chartType |
|
127 | 127 | Chart type indicates if the chart is a cartesian chart or a polar chart. |
|
128 | 128 | This property is set internally and it is read only. |
|
129 | 129 | \sa QPolarChart |
|
130 | 130 | */ |
|
131 | 131 | |
|
132 | 132 | /*! |
|
133 | 133 | \property QChart::plotAreaBackgroundVisible |
|
134 | 134 | Specifies whether the chart plot area background is visible or not. |
|
135 | 135 | \note By default the plot area background is not visible and the plot area uses |
|
136 | 136 | the general chart background. |
|
137 | 137 | \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible |
|
138 | 138 | */ |
|
139 | 139 | |
|
140 | 140 | /*! |
|
141 | 141 | \internal |
|
142 | 142 | Constructs a chart object of \a type which is a child of a \a parent. |
|
143 | 143 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
144 | 144 | This constructor is called only by subclasses. |
|
145 | 145 | */ |
|
146 | 146 | QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
147 | 147 | : QGraphicsWidget(parent, wFlags), |
|
148 | 148 | d_ptr(new QChartPrivate(this, type)) |
|
149 | 149 | { |
|
150 | 150 | d_ptr->init(); |
|
151 | 151 | } |
|
152 | 152 | |
|
153 | 153 | /*! |
|
154 | 154 | Constructs a chart object which is a child of a \a parent. |
|
155 | 155 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
156 | 156 | */ |
|
157 | 157 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
158 | 158 | : QGraphicsWidget(parent, wFlags), |
|
159 | 159 | d_ptr(new QChartPrivate(this, ChartTypeCartesian)) |
|
160 | 160 | { |
|
161 | 161 | d_ptr->init(); |
|
162 | 162 | } |
|
163 | 163 | |
|
164 | 164 | /*! |
|
165 | 165 | Destroys the chart object and its children, like series and axis objects added to it. |
|
166 | 166 | */ |
|
167 | 167 | QChart::~QChart() |
|
168 | 168 | { |
|
169 | 169 | //start by deleting dataset, it will remove all series and axes |
|
170 | 170 | delete d_ptr->m_dataset; |
|
171 | 171 | d_ptr->m_dataset = 0; |
|
172 | 172 | } |
|
173 | 173 | |
|
174 | 174 | /*! |
|
175 | 175 | Adds the \a series onto the chart and takes the ownership of it. |
|
176 | 176 | |
|
177 | 177 | \note A newly added series is attached to no axes by default, including any axes that were created for the chart |
|
178 | 178 | using createDefaultAxes() before the series was added to the chart. If no axes are attached to |
|
179 | 179 | the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges |
|
180 | 180 | that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other |
|
181 | 181 | series that have properly attached axes, so always make sure you either call createDefaultAxes() after |
|
182 | 182 | a series has been added or explicitly attach axes for the series. |
|
183 | 183 | |
|
184 | 184 | \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
185 | 185 | */ |
|
186 | 186 | void QChart::addSeries(QAbstractSeries *series) |
|
187 | 187 | { |
|
188 | 188 | Q_ASSERT(series); |
|
189 | 189 | d_ptr->m_dataset->addSeries(series); |
|
190 | 190 | } |
|
191 | 191 | |
|
192 | 192 | /*! |
|
193 | 193 | Removes the \a series from the chart. |
|
194 | 194 | The chart releases its ownership of the specified \a series object. |
|
195 | 195 | |
|
196 | 196 | \sa addSeries(), removeAllSeries() |
|
197 | 197 | */ |
|
198 | 198 | void QChart::removeSeries(QAbstractSeries *series) |
|
199 | 199 | { |
|
200 | 200 | Q_ASSERT(series); |
|
201 | 201 | d_ptr->m_dataset->removeSeries(series); |
|
202 | 202 | } |
|
203 | 203 | |
|
204 | 204 | /*! |
|
205 | 205 | Removes and deletes all series objects that have been added to the chart. |
|
206 | 206 | |
|
207 | 207 | \sa addSeries(), removeSeries() |
|
208 | 208 | */ |
|
209 | 209 | void QChart::removeAllSeries() |
|
210 | 210 | { |
|
211 | 211 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ |
|
212 | 212 | removeSeries(s); |
|
213 | 213 | delete s; |
|
214 | 214 | } |
|
215 | 215 | } |
|
216 | 216 | |
|
217 | 217 | /*! |
|
218 | 218 | Sets the \a brush that is used for painting the background of the chart area. |
|
219 | 219 | */ |
|
220 | 220 | void QChart::setBackgroundBrush(const QBrush &brush) |
|
221 | 221 | { |
|
222 | 222 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
223 | 223 | } |
|
224 | 224 | |
|
225 | 225 | /*! |
|
226 | 226 | Gets the brush that is used for painting the background of the chart area. |
|
227 | 227 | */ |
|
228 | 228 | QBrush QChart::backgroundBrush() const |
|
229 | 229 | { |
|
230 | 230 | return d_ptr->m_presenter->backgroundBrush(); |
|
231 | 231 | } |
|
232 | 232 | |
|
233 | 233 | /*! |
|
234 | 234 | Sets the \a pen that is used for painting the background of the chart area. |
|
235 | 235 | */ |
|
236 | 236 | void QChart::setBackgroundPen(const QPen &pen) |
|
237 | 237 | { |
|
238 | 238 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
239 | 239 | } |
|
240 | 240 | |
|
241 | 241 | /*! |
|
242 | 242 | Gets the pen that is used for painting the background of the chart area. |
|
243 | 243 | */ |
|
244 | 244 | QPen QChart::backgroundPen() const |
|
245 | 245 | { |
|
246 | 246 | return d_ptr->m_presenter->backgroundPen(); |
|
247 | 247 | } |
|
248 | 248 | |
|
249 | 249 | void QChart::setTitle(const QString &title) |
|
250 | 250 | { |
|
251 | 251 | d_ptr->m_presenter->setTitle(title); |
|
252 | 252 | } |
|
253 | 253 | |
|
254 | 254 | QString QChart::title() const |
|
255 | 255 | { |
|
256 | 256 | return d_ptr->m_presenter->title(); |
|
257 | 257 | } |
|
258 | 258 | |
|
259 | 259 | /*! |
|
260 | 260 | Sets the \a font that is used for drawing the chart title. |
|
261 | 261 | */ |
|
262 | 262 | void QChart::setTitleFont(const QFont &font) |
|
263 | 263 | { |
|
264 | 264 | d_ptr->m_presenter->setTitleFont(font); |
|
265 | 265 | } |
|
266 | 266 | |
|
267 | 267 | /*! |
|
268 | 268 | Gets the font that is used for drawing the chart title. |
|
269 | 269 | */ |
|
270 | 270 | QFont QChart::titleFont() const |
|
271 | 271 | { |
|
272 | 272 | return d_ptr->m_presenter->titleFont(); |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | /*! |
|
276 | 276 | Sets the \a brush used for drawing the title text. |
|
277 | 277 | */ |
|
278 | 278 | void QChart::setTitleBrush(const QBrush &brush) |
|
279 | 279 | { |
|
280 | 280 | d_ptr->m_presenter->setTitleBrush(brush); |
|
281 | 281 | } |
|
282 | 282 | |
|
283 | 283 | /*! |
|
284 | 284 | Returns the brush used for drawing the title text. |
|
285 | 285 | */ |
|
286 | 286 | QBrush QChart::titleBrush() const |
|
287 | 287 | { |
|
288 | 288 | return d_ptr->m_presenter->titleBrush(); |
|
289 | 289 | } |
|
290 | 290 | |
|
291 | 291 | void QChart::setTheme(QChart::ChartTheme theme) |
|
292 | 292 | { |
|
293 | 293 | d_ptr->m_themeManager->setTheme(theme); |
|
294 | 294 | } |
|
295 | 295 | |
|
296 | 296 | QChart::ChartTheme QChart::theme() const |
|
297 | 297 | { |
|
298 | 298 | return d_ptr->m_themeManager->theme()->id(); |
|
299 | 299 | } |
|
300 | 300 | |
|
301 | 301 | /*! |
|
302 | 302 | Zooms in the view by a factor of two. |
|
303 | 303 | */ |
|
304 | 304 | void QChart::zoomIn() |
|
305 | 305 | { |
|
306 | 306 | d_ptr->zoomIn(2.0); |
|
307 | 307 | } |
|
308 | 308 | |
|
309 | 309 | /*! |
|
310 | 310 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
311 | 311 | \note This is not supported for polar charts. |
|
312 | 312 | */ |
|
313 | 313 | void QChart::zoomIn(const QRectF &rect) |
|
314 | 314 | { |
|
315 | 315 | if (d_ptr->m_type == QChart::ChartTypePolar) |
|
316 | 316 | return; |
|
317 | 317 | d_ptr->zoomIn(rect); |
|
318 | 318 | } |
|
319 | 319 | |
|
320 | 320 | /*! |
|
321 | 321 | Zooms out the view by a factor of two. |
|
322 | 322 | */ |
|
323 | 323 | void QChart::zoomOut() |
|
324 | 324 | { |
|
325 | 325 | d_ptr->zoomOut(2.0); |
|
326 | 326 | } |
|
327 | 327 | |
|
328 | 328 | /*! |
|
329 | 329 | Zooms in the view by a custom \a factor. |
|
330 | 330 | |
|
331 | 331 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
332 | 332 | */ |
|
333 | 333 | void QChart::zoom(qreal factor) |
|
334 | 334 | { |
|
335 | 335 | if (qFuzzyCompare(factor, 0)) |
|
336 | 336 | return; |
|
337 | 337 | |
|
338 | 338 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
339 | 339 | return; |
|
340 | 340 | |
|
341 | 341 | if (factor < 0) |
|
342 | 342 | return; |
|
343 | 343 | |
|
344 | 344 | if (factor > 1.0) |
|
345 | 345 | d_ptr->zoomIn(factor); |
|
346 | 346 | else |
|
347 | 347 | d_ptr->zoomOut(1.0 / factor); |
|
348 | 348 | } |
|
349 | 349 | |
|
350 | 350 | /*! |
|
351 | 351 | Returns a pointer to the horizontal axis attached to the specified \a series. |
|
352 | 352 | If no \a series is specified, the first horizontal axis added to the chart is returned. |
|
353 | 353 | |
|
354 | 354 | \sa addAxis(), QAbstractSeries::attachAxis() |
|
355 | 355 | */ |
|
356 | 356 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const |
|
357 | 357 | { |
|
358 | 358 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); |
|
359 | 359 | if (axisList.count()) |
|
360 | 360 | return axisList[0]; |
|
361 | 361 | return 0; |
|
362 | 362 | } |
|
363 | 363 | |
|
364 | 364 | /*! |
|
365 | 365 | Returns a pointer to the vertical axis attached to the specified \a series. |
|
366 | 366 | If no \a series is specified, the first vertical axis added to the chart is returned. |
|
367 | 367 | |
|
368 | 368 | \sa addAxis(), QAbstractSeries::attachAxis() |
|
369 | 369 | */ |
|
370 | 370 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const |
|
371 | 371 | { |
|
372 | 372 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); |
|
373 | 373 | if (axisList.count()) |
|
374 | 374 | return axisList[0]; |
|
375 | 375 | return 0; |
|
376 | 376 | } |
|
377 | 377 | |
|
378 | 378 | /*! |
|
379 | 379 | Returns the axes attached to the \a series with \a orientation. If no \a series is provided, |
|
380 | 380 | then all axes added to the chart with the specified orientation are returned. |
|
381 | 381 | \sa addAxis(), createDefaultAxes() |
|
382 | 382 | */ |
|
383 | 383 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const |
|
384 | 384 | { |
|
385 | 385 | QList<QAbstractAxis *> result ; |
|
386 | 386 | |
|
387 | 387 | if (series) { |
|
388 | 388 | foreach (QAbstractAxis *axis, series->attachedAxes()){ |
|
389 | 389 | if (orientation.testFlag(axis->orientation())) |
|
390 | 390 | result << axis; |
|
391 | 391 | } |
|
392 | 392 | } else { |
|
393 | 393 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ |
|
394 | 394 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) |
|
395 | 395 | result << axis; |
|
396 | 396 | } |
|
397 | 397 | } |
|
398 | 398 | |
|
399 | 399 | return result; |
|
400 | 400 | } |
|
401 | 401 | |
|
402 | 402 | /*! |
|
403 | 403 | Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to |
|
404 | 404 | the chart will be deleted. |
|
405 | 405 | |
|
406 | 406 | \note This function has to be called after all series have been added to the chart. The axes created by this function |
|
407 | 407 | will NOT get automatically attached to any series added to the chart after this function has been called. |
|
408 | 408 | A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing |
|
409 | 409 | if there are other series with properly attached axes also present. |
|
410 | 410 | |
|
411 | 411 | \table |
|
412 | 412 | \header |
|
413 | 413 | \o Series type |
|
414 | 414 | \o X-axis |
|
415 | 415 | \o Y-axis |
|
416 | 416 | \row |
|
417 | 417 | \o QXYSeries |
|
418 | 418 | \o QValueAxis |
|
419 | 419 | \o QValueAxis |
|
420 | 420 | \row |
|
421 | 421 | \o QBarSeries |
|
422 | 422 | \o QBarCategoryAxis |
|
423 | 423 | \o QValueAxis |
|
424 | 424 | \row |
|
425 | 425 | \o QPieSeries |
|
426 | 426 | \o None |
|
427 | 427 | \o None |
|
428 | 428 | \endtable |
|
429 | 429 | |
|
430 | 430 | If there are several QXYSeries derived series added to the chart and no series of other types have been added, then only one pair of axes is created. |
|
431 | 431 | If there are several series of different types added to the chart, then each series gets its own axes pair. |
|
432 | 432 | |
|
433 | 433 | The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call. |
|
434 | 434 | QPieSeries does not create any axes. |
|
435 | 435 | |
|
436 | 436 | \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis() |
|
437 | 437 | */ |
|
438 | 438 | void QChart::createDefaultAxes() |
|
439 | 439 | { |
|
440 | 440 | d_ptr->m_dataset->createDefaultAxes(); |
|
441 | 441 | } |
|
442 | 442 | |
|
443 | 443 | /*! |
|
444 | 444 | Returns the legend object of the chart. Ownership stays with the chart. |
|
445 | 445 | */ |
|
446 | 446 | QLegend *QChart::legend() const |
|
447 | 447 | { |
|
448 | 448 | return d_ptr->m_legend; |
|
449 | 449 | } |
|
450 | 450 | |
|
451 | 451 | void QChart::setMinimumMargins(const QMargins &margins) |
|
452 | 452 | { |
|
453 | 453 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; |
|
454 | 454 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
455 | 455 | } |
|
456 | 456 | |
|
457 | 457 | QMargins QChart::minimumMargins() const |
|
458 | 458 | { |
|
459 | 459 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; |
|
460 | 460 | return d_ptr->m_presenter->layout()->margins(); |
|
461 | 461 | } |
|
462 | 462 | |
|
463 | 463 | void QChart::setMargins(const QMargins &margins) |
|
464 | 464 | { |
|
465 | 465 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
466 | 466 | } |
|
467 | 467 | |
|
468 | 468 | QMargins QChart::margins() const |
|
469 | 469 | { |
|
470 | 470 | return d_ptr->m_presenter->layout()->margins(); |
|
471 | 471 | } |
|
472 | 472 | |
|
473 | 473 | QChart::ChartType QChart::chartType() const |
|
474 | 474 | { |
|
475 | 475 | return d_ptr->m_type; |
|
476 | 476 | } |
|
477 | 477 | |
|
478 | 478 | /*! |
|
479 | 479 | Returns the the rectangle within which the drawing of the chart is done. |
|
480 | 480 | It does not include the area defined by margins. |
|
481 | 481 | */ |
|
482 | 482 | QRectF QChart::plotArea() const |
|
483 | 483 | { |
|
484 | 484 | return d_ptr->m_presenter->geometry(); |
|
485 | 485 | } |
|
486 | 486 | |
|
487 | 487 | /*! |
|
488 | 488 | Sets the \a brush for the background of the plot area of the chart. |
|
489 | 489 | |
|
490 | 490 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush() |
|
491 | 491 | */ |
|
492 | 492 | void QChart::setPlotAreaBackgroundBrush(const QBrush &brush) |
|
493 | 493 | { |
|
494 | 494 | d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush); |
|
495 | 495 | } |
|
496 | 496 | |
|
497 | 497 | /*! |
|
498 | 498 | Returns the brush for the background of the plot area of the chart. |
|
499 | 499 | |
|
500 | 500 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush() |
|
501 | 501 | */ |
|
502 | 502 | QBrush QChart::plotAreaBackgroundBrush() const |
|
503 | 503 | { |
|
504 | 504 | return d_ptr->m_presenter->plotAreaBackgroundBrush(); |
|
505 | 505 | } |
|
506 | 506 | |
|
507 | 507 | /*! |
|
508 | 508 | Sets the \a pen for the background of the plot area of the chart. |
|
509 | 509 | |
|
510 | 510 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen() |
|
511 | 511 | */ |
|
512 | 512 | void QChart::setPlotAreaBackgroundPen(const QPen &pen) |
|
513 | 513 | { |
|
514 | 514 | d_ptr->m_presenter->setPlotAreaBackgroundPen(pen); |
|
515 | 515 | } |
|
516 | 516 | |
|
517 | 517 | /*! |
|
518 |
Returns the |
|
|
518 | Returns the pen for the background of the plot area of the chart. | |
|
519 | 519 | |
|
520 | 520 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen() |
|
521 | 521 | */ |
|
522 | 522 | QPen QChart::plotAreaBackgroundPen() const |
|
523 | 523 | { |
|
524 | 524 | return d_ptr->m_presenter->plotAreaBackgroundPen(); |
|
525 | 525 | } |
|
526 | 526 | |
|
527 | 527 | void QChart::setPlotAreaBackgroundVisible(bool visible) |
|
528 | 528 | { |
|
529 | 529 | d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible); |
|
530 | 530 | } |
|
531 | 531 | |
|
532 | 532 | bool QChart::isPlotAreaBackgroundVisible() const |
|
533 | 533 | { |
|
534 | 534 | return d_ptr->m_presenter->isPlotAreaBackgroundVisible(); |
|
535 | 535 | } |
|
536 | 536 | |
|
537 | 537 | void QChart::setAnimationOptions(AnimationOptions options) |
|
538 | 538 | { |
|
539 | 539 | d_ptr->m_presenter->setAnimationOptions(options); |
|
540 | 540 | } |
|
541 | 541 | |
|
542 | 542 | QChart::AnimationOptions QChart::animationOptions() const |
|
543 | 543 | { |
|
544 | 544 | return d_ptr->m_presenter->animationOptions(); |
|
545 | 545 | } |
|
546 | 546 | |
|
547 | 547 | /*! |
|
548 | 548 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
549 | 549 | |
|
550 | 550 | For polar charts, \a dx indicates the angle along angular axis instead of distance. |
|
551 | 551 | */ |
|
552 | 552 | void QChart::scroll(qreal dx, qreal dy) |
|
553 | 553 | { |
|
554 | 554 | d_ptr->scroll(dx,dy); |
|
555 | 555 | } |
|
556 | 556 | |
|
557 | 557 | void QChart::setBackgroundVisible(bool visible) |
|
558 | 558 | { |
|
559 | 559 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
560 | 560 | } |
|
561 | 561 | |
|
562 | 562 | bool QChart::isBackgroundVisible() const |
|
563 | 563 | { |
|
564 | 564 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
565 | 565 | } |
|
566 | 566 | |
|
567 | 567 | void QChart::setDropShadowEnabled(bool enabled) |
|
568 | 568 | { |
|
569 | 569 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
570 | 570 | } |
|
571 | 571 | |
|
572 | 572 | bool QChart::isDropShadowEnabled() const |
|
573 | 573 | { |
|
574 | 574 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
575 | 575 | } |
|
576 | 576 | |
|
577 | 577 | /*! |
|
578 | 578 | Returns all series that are added to the chart. |
|
579 | 579 | |
|
580 | 580 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
581 | 581 | */ |
|
582 | 582 | QList<QAbstractSeries *> QChart::series() const |
|
583 | 583 | { |
|
584 | 584 | return d_ptr->m_dataset->series(); |
|
585 | 585 | } |
|
586 | 586 | |
|
587 | 587 | /*! |
|
588 | 588 | Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis. |
|
589 | 589 | The chart takes ownership of both the \a axis and the \a series. |
|
590 | 590 | Any horizontal axes previously attached to the \a series are deleted. |
|
591 | 591 | |
|
592 | 592 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
593 | 593 | */ |
|
594 | 594 | void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series) |
|
595 | 595 | { |
|
596 | 596 | QList<QAbstractAxis*> list = axes(Qt::Horizontal, series); |
|
597 | 597 | |
|
598 | 598 | foreach (QAbstractAxis* a, list) { |
|
599 | 599 | d_ptr->m_dataset->removeAxis(a); |
|
600 | 600 | delete a; |
|
601 | 601 | } |
|
602 | 602 | |
|
603 | 603 | if (!d_ptr->m_dataset->axes().contains(axis)) |
|
604 | 604 | d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom); |
|
605 | 605 | d_ptr->m_dataset->attachAxis(series, axis); |
|
606 | 606 | } |
|
607 | 607 | |
|
608 | 608 | /*! |
|
609 | 609 | Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis. |
|
610 | 610 | The chart takes ownership of both the \a axis and the \a series. |
|
611 | 611 | Any vertical axes previously attached to the \a series are deleted. |
|
612 | 612 | |
|
613 | 613 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
614 | 614 | */ |
|
615 | 615 | void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series) |
|
616 | 616 | { |
|
617 | 617 | QList<QAbstractAxis*> list = axes(Qt::Vertical, series); |
|
618 | 618 | |
|
619 | 619 | foreach (QAbstractAxis* a, list) { |
|
620 | 620 | d_ptr->m_dataset->removeAxis(a); |
|
621 | 621 | delete a; |
|
622 | 622 | } |
|
623 | 623 | |
|
624 | 624 | if (!d_ptr->m_dataset->axes().contains(axis)) |
|
625 | 625 | d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft); |
|
626 | 626 | d_ptr->m_dataset->attachAxis(series, axis); |
|
627 | 627 | } |
|
628 | 628 | |
|
629 | 629 | /*! |
|
630 | 630 | Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis. |
|
631 | 631 | |
|
632 | 632 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
633 | 633 | */ |
|
634 | 634 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) |
|
635 | 635 | { |
|
636 | 636 | d_ptr->m_dataset->addAxis(axis, alignment); |
|
637 | 637 | } |
|
638 | 638 | |
|
639 | 639 | /*! |
|
640 | 640 | Removes the \a axis from the chart. |
|
641 | 641 | The chart releases its ownership of the specified \a axis object. |
|
642 | 642 | |
|
643 | 643 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() |
|
644 | 644 | */ |
|
645 | 645 | void QChart::removeAxis(QAbstractAxis *axis) |
|
646 | 646 | { |
|
647 | 647 | d_ptr->m_dataset->removeAxis(axis); |
|
648 | 648 | } |
|
649 | 649 | |
|
650 | 650 | /*! |
|
651 | 651 | Returns the value in the \a series domain that corresponds to the \a position relative to chart widget. |
|
652 | 652 | */ |
|
653 | 653 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
654 | 654 | { |
|
655 | 655 | return d_ptr->m_dataset->mapToValue(position, series); |
|
656 | 656 | } |
|
657 | 657 | |
|
658 | 658 | /*! |
|
659 | 659 | Returns the position on the chart widget that corresponds to the \a value in the \a series domain. |
|
660 | 660 | */ |
|
661 | 661 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
662 | 662 | { |
|
663 | 663 | return d_ptr->m_dataset->mapToPosition(value, series); |
|
664 | 664 | } |
|
665 | 665 | |
|
666 | 666 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
667 | 667 | |
|
668 | 668 | QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type): |
|
669 | 669 | q_ptr(q), |
|
670 | 670 | m_type(type), |
|
671 | 671 | m_legend(0), |
|
672 | 672 | m_dataset(new ChartDataSet(q)), |
|
673 | 673 | m_presenter(new ChartPresenter(q, type)), |
|
674 | 674 | m_themeManager(new ChartThemeManager(q)) |
|
675 | 675 | { |
|
676 | 676 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
677 | 677 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
678 | 678 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
679 | 679 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
680 | 680 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
681 | 681 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
682 | 682 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
683 | 683 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
684 | 684 | } |
|
685 | 685 | |
|
686 | 686 | QChartPrivate::~QChartPrivate() |
|
687 | 687 | { |
|
688 | 688 | } |
|
689 | 689 | |
|
690 | 690 | void QChartPrivate::init() |
|
691 | 691 | { |
|
692 | 692 | m_legend = new LegendScroller(q_ptr); |
|
693 | 693 | q_ptr->setTheme(QChart::ChartThemeLight); |
|
694 | 694 | q_ptr->setLayout(m_presenter->layout()); |
|
695 | 695 | } |
|
696 | 696 | |
|
697 | 697 | void QChartPrivate::zoomIn(qreal factor) |
|
698 | 698 | { |
|
699 | 699 | QRectF rect = m_presenter->geometry(); |
|
700 | 700 | rect.setWidth(rect.width() / factor); |
|
701 | 701 | rect.setHeight(rect.height() / factor); |
|
702 | 702 | rect.moveCenter(m_presenter->geometry().center()); |
|
703 | 703 | zoomIn(rect); |
|
704 | 704 | } |
|
705 | 705 | |
|
706 | 706 | void QChartPrivate::zoomIn(const QRectF &rect) |
|
707 | 707 | { |
|
708 | 708 | if (!rect.isValid()) |
|
709 | 709 | return; |
|
710 | 710 | |
|
711 | 711 | QRectF r = rect.normalized(); |
|
712 | 712 | const QRectF geometry = m_presenter->geometry(); |
|
713 | 713 | r.translate(-geometry.topLeft()); |
|
714 | 714 | |
|
715 | 715 | if (!r.isValid()) |
|
716 | 716 | return; |
|
717 | 717 | |
|
718 | 718 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
719 | 719 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); |
|
720 | 720 | m_dataset->zoomInDomain(r); |
|
721 | 721 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
722 | 722 | |
|
723 | 723 | } |
|
724 | 724 | |
|
725 | 725 | void QChartPrivate::zoomOut(qreal factor) |
|
726 | 726 | { |
|
727 | 727 | const QRectF geometry = m_presenter->geometry(); |
|
728 | 728 | |
|
729 | 729 | QRectF r; |
|
730 | 730 | r.setSize(geometry.size() / factor); |
|
731 | 731 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); |
|
732 | 732 | if (!r.isValid()) |
|
733 | 733 | return; |
|
734 | 734 | |
|
735 | 735 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
736 | 736 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); |
|
737 | 737 | m_dataset->zoomOutDomain(r); |
|
738 | 738 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
739 | 739 | } |
|
740 | 740 | |
|
741 | 741 | void QChartPrivate::scroll(qreal dx, qreal dy) |
|
742 | 742 | { |
|
743 | 743 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); |
|
744 | 744 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); |
|
745 | 745 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); |
|
746 | 746 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); |
|
747 | 747 | |
|
748 | 748 | m_dataset->scrollDomain(dx, dy); |
|
749 | 749 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
750 | 750 | } |
|
751 | 751 | |
|
752 | 752 | #include "moc_qchart.cpp" |
|
753 | 753 | |
|
754 | 754 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,576 +1,587 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 "qxyseries.h" |
|
22 | 22 | #include "qxyseries_p.h" |
|
23 | 23 | #include "abstractdomain_p.h" |
|
24 | 24 | #include "qvalueaxis.h" |
|
25 | 25 | #include "xychart_p.h" |
|
26 | 26 | #include "qxylegendmarker.h" |
|
27 | 27 | #include "charthelpers_p.h" |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | /*! |
|
32 | 32 | \class QXYSeries |
|
33 | 33 | \brief The QXYSeries class is a base class for line, spline and scatter series. |
|
34 | 34 | */ |
|
35 | 35 | /*! |
|
36 | 36 | \qmlclass XYSeries |
|
37 | 37 | \inherits AbstractSeries |
|
38 | 38 | The XYSeries class is a base class for line, spline and scatter series. |
|
39 | 39 | |
|
40 | 40 | The class cannot be instantiated directly. |
|
41 | 41 | */ |
|
42 | 42 | |
|
43 | 43 | /*! |
|
44 | 44 | \qmlproperty AbstractAxis XYSeries::axisX |
|
45 | 45 | The x axis used for the series. If you leave both axisX and axisXTop undefined, a ValueAxis is created for |
|
46 | 46 | the series. |
|
47 | 47 | \sa axisXTop |
|
48 | 48 | */ |
|
49 | 49 | |
|
50 | 50 | /*! |
|
51 | 51 | \qmlproperty AbstractAxis XYSeries::axisY |
|
52 | 52 | The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for |
|
53 | 53 | the series. |
|
54 | 54 | \sa axisYRight |
|
55 | 55 | */ |
|
56 | 56 | |
|
57 | 57 | /*! |
|
58 | 58 | \qmlproperty AbstractAxis XYSeries::axisXTop |
|
59 | 59 | The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or |
|
60 | 60 | axisXTop, but not both. |
|
61 | 61 | \sa axisX |
|
62 | 62 | */ |
|
63 | 63 | |
|
64 | 64 | /*! |
|
65 | 65 | \qmlproperty AbstractAxis XYSeries::axisYRight |
|
66 | 66 | The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY |
|
67 | 67 | or axisYRight, but not both. |
|
68 | 68 | \sa axisY |
|
69 | 69 | */ |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | \qmlproperty AbstractAxis XYSeries::axisAngular |
|
73 | 73 | The angular axis used for the series, drawn around the polar chart view. |
|
74 | 74 | \sa axisX |
|
75 | 75 | */ |
|
76 | 76 | |
|
77 | 77 | /*! |
|
78 | 78 | \qmlproperty AbstractAxis XYSeries::axisRadial |
|
79 | 79 | The radial axis used for the series, drawn inside the polar chart view. |
|
80 | 80 | \sa axisY |
|
81 | 81 | */ |
|
82 | 82 | |
|
83 | 83 | /*! |
|
84 | 84 | \property QXYSeries::pointsVisible |
|
85 | 85 | Controls if the data points are visible and should be drawn. |
|
86 | 86 | */ |
|
87 | 87 | /*! |
|
88 | 88 | \qmlproperty bool XYSeries::pointsVisible |
|
89 | 89 | Controls if the data points are visible and should be drawn. |
|
90 | 90 | */ |
|
91 | 91 | |
|
92 | 92 | /*! |
|
93 | 93 | \fn QPen QXYSeries::pen() const |
|
94 | 94 | \brief Returns pen used to draw points for series. |
|
95 | 95 | \sa setPen() |
|
96 | 96 | */ |
|
97 | 97 | |
|
98 | 98 | /*! |
|
99 | 99 | \fn QBrush QXYSeries::brush() const |
|
100 | 100 | \brief Returns brush used to draw points for series. |
|
101 | 101 | \sa setBrush() |
|
102 | 102 | */ |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | \property QXYSeries::color |
|
106 | 106 | The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and |
|
107 | 107 | fill (brush) color in case of QScatterSeries or QAreaSeries. |
|
108 | 108 | \sa QXYSeries::pen(), QXYSeries::brush() |
|
109 | 109 | */ |
|
110 | 110 | /*! |
|
111 | 111 | \qmlproperty color XYSeries::color |
|
112 | 112 | The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and |
|
113 | 113 | fill (brush) color in case of ScatterSeries or AreaSeries. |
|
114 | 114 | */ |
|
115 | 115 | |
|
116 | 116 | /*! |
|
117 | 117 | \fn void QXYSeries::clicked(const QPointF& point) |
|
118 | 118 | \brief Signal is emitted when user clicks the \a point on chart. |
|
119 | 119 | */ |
|
120 | 120 | /*! |
|
121 | 121 | \qmlsignal XYSeries::onClicked(QPointF point) |
|
122 | 122 | Signal is emitted when user clicks the \a point on chart. For example: |
|
123 | 123 | \code |
|
124 | 124 | LineSeries { |
|
125 | 125 | XYPoint { x: 0; y: 0 } |
|
126 | 126 | XYPoint { x: 1.1; y: 2.1 } |
|
127 | 127 | onClicked: console.log("onClicked: " + point.x + ", " + point.y); |
|
128 | 128 | } |
|
129 | 129 | \endcode |
|
130 | 130 | */ |
|
131 | 131 | |
|
132 | 132 | /*! |
|
133 | 133 | \fn void QXYSeries::hovered(const QPointF &point, bool state) |
|
134 | 134 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) |
|
135 | 135 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from |
|
136 | 136 | the series. |
|
137 | 137 | */ |
|
138 | 138 | /*! |
|
139 | 139 | \qmlsignal XYSeries::onHovered(point point, bool state) |
|
140 | 140 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) |
|
141 | 141 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from |
|
142 | 142 | the series. |
|
143 | 143 | */ |
|
144 | 144 | |
|
145 | 145 | /*! |
|
146 | 146 | \fn void QXYSeries::pointReplaced(int index) |
|
147 | 147 | Signal is emitted when a point has been replaced at \a index. |
|
148 | 148 | \sa replace() |
|
149 | 149 | */ |
|
150 | 150 | /*! |
|
151 | 151 | \qmlsignal XYSeries::onPointReplaced(int index) |
|
152 | 152 | Signal is emitted when a point has been replaced at \a index. |
|
153 | 153 | */ |
|
154 | 154 | |
|
155 | 155 | /*! |
|
156 | 156 | \fn void QXYSeries::pointsReplaced() |
|
157 | 157 | Signal is emitted when all points have been replaced with other points. |
|
158 | 158 | \sa replace() |
|
159 | 159 | */ |
|
160 | 160 | /*! |
|
161 | 161 | \qmlsignal XYSeries::onPointsReplaced() |
|
162 | 162 | */ |
|
163 | 163 | |
|
164 | 164 | /*! |
|
165 | 165 | \fn void QXYSeries::pointAdded(int index) |
|
166 | 166 | Signal is emitted when a point has been added at \a index. |
|
167 | 167 | \sa append(), insert() |
|
168 | 168 | */ |
|
169 | 169 | /*! |
|
170 | 170 | \qmlsignal XYSeries::onPointAdded(int index) |
|
171 | 171 | Signal is emitted when a point has been added at \a index. |
|
172 | 172 | */ |
|
173 | 173 | |
|
174 | 174 | /*! |
|
175 | 175 | \fn void QXYSeries::pointRemoved(int index) |
|
176 | 176 | Signal is emitted when a point has been removed from \a index. |
|
177 | 177 | \sa remove() |
|
178 | 178 | */ |
|
179 | 179 | /*! |
|
180 | 180 | \qmlsignal XYSeries::onPointRemoved(int index) |
|
181 | 181 | Signal is emitted when a point has been removed from \a index. |
|
182 | 182 | */ |
|
183 | 183 | |
|
184 | 184 | /*! |
|
185 | 185 | \fn void QXYSeries::colorChanged(QColor color) |
|
186 | 186 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
187 | 187 | */ |
|
188 | 188 | /*! |
|
189 | 189 | \qmlsignal XYSeries::onColorChanged(color color) |
|
190 | 190 | Signal is emitted when the line (pen) color has changed to \a color. |
|
191 | 191 | */ |
|
192 | 192 | |
|
193 | 193 | /*! |
|
194 | 194 | \fn void QXYSeriesPrivate::updated() |
|
195 | 195 | \brief \internal |
|
196 | 196 | */ |
|
197 | 197 | |
|
198 | 198 | /*! |
|
199 | 199 | \qmlmethod XYSeries::append(real x, real y) |
|
200 | 200 | Append point (\a x, \a y) to the series |
|
201 | 201 | */ |
|
202 | 202 | |
|
203 | 203 | /*! |
|
204 | 204 | \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY) |
|
205 | 205 | Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not |
|
206 | 206 | exist. |
|
207 | 207 | */ |
|
208 | 208 | |
|
209 | 209 | /*! |
|
210 | 210 | \qmlmethod XYSeries::remove(real x, real y) |
|
211 | 211 | Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist. |
|
212 | 212 | */ |
|
213 | 213 | |
|
214 | 214 | /*! |
|
215 | 215 | \qmlmethod XYSeries::insert(int index, real x, real y) |
|
216 | 216 | Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of |
|
217 | 217 | points. If index is the same as or bigger than count, the point is appended to the list of points. |
|
218 | 218 | */ |
|
219 | 219 | |
|
220 | 220 | /*! |
|
221 | 221 | \qmlmethod QPointF XYSeries::at(int index) |
|
222 | 222 | Returns point at \a index. Returns (0, 0) if the index is not valid. |
|
223 | 223 | */ |
|
224 | 224 | |
|
225 | 225 | /*! |
|
226 | 226 | \internal |
|
227 | 227 | |
|
228 | 228 | Constructs empty series object which is a child of \a parent. |
|
229 | 229 | When series object is added to QChart instance ownerships is transferred. |
|
230 | 230 | */ |
|
231 | 231 | QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent) |
|
232 | 232 | : QAbstractSeries(d, parent) |
|
233 | 233 | { |
|
234 | 234 | } |
|
235 | 235 | |
|
236 | 236 | /*! |
|
237 | 237 | Destroys the object. Series added to QChart instances are owned by those, |
|
238 | 238 | and are destroyed when QChart instances are destroyed. |
|
239 | 239 | */ |
|
240 | 240 | QXYSeries::~QXYSeries() |
|
241 | 241 | { |
|
242 | 242 | } |
|
243 | 243 | |
|
244 | 244 | /*! |
|
245 | 245 | Adds data point (\a x, \a y) to the series. |
|
246 | 246 | */ |
|
247 | 247 | void QXYSeries::append(qreal x, qreal y) |
|
248 | 248 | { |
|
249 | 249 | append(QPointF(x, y)); |
|
250 | 250 | } |
|
251 | 251 | |
|
252 | 252 | /*! |
|
253 | 253 | This is an overloaded function. |
|
254 | 254 | Adds data \a point to the series. |
|
255 | 255 | */ |
|
256 | 256 | void QXYSeries::append(const QPointF &point) |
|
257 | 257 | { |
|
258 | 258 | Q_D(QXYSeries); |
|
259 | 259 | |
|
260 | 260 | if (isValidValue(point)) { |
|
261 | 261 | d->m_points << point; |
|
262 | 262 | emit pointAdded(d->m_points.count() - 1); |
|
263 | 263 | } |
|
264 | 264 | } |
|
265 | 265 | |
|
266 | 266 | /*! |
|
267 | 267 | This is an overloaded function. |
|
268 | 268 | Adds list of data \a points to the series. |
|
269 | 269 | */ |
|
270 | 270 | void QXYSeries::append(const QList<QPointF> &points) |
|
271 | 271 | { |
|
272 | 272 | foreach (const QPointF &point , points) |
|
273 | 273 | append(point); |
|
274 | 274 | } |
|
275 | 275 | |
|
276 | 276 | /*! |
|
277 | 277 | Replaces data point (\a oldX, \a oldY) with data point (\a newX, \a newY). |
|
278 | 278 | \sa QXYSeries::pointReplaced() |
|
279 | 279 | */ |
|
280 | 280 | void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY) |
|
281 | 281 | { |
|
282 | 282 | replace(QPointF(oldX, oldY), QPointF(newX, newY)); |
|
283 | 283 | } |
|
284 | 284 | |
|
285 | 285 | /*! |
|
286 | 286 | Replaces \a oldPoint with \a newPoint. |
|
287 | 287 | \sa QXYSeries::pointReplaced() |
|
288 | 288 | */ |
|
289 | 289 | void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint) |
|
290 | 290 | { |
|
291 | 291 | Q_D(QXYSeries); |
|
292 | 292 | int index = d->m_points.indexOf(oldPoint); |
|
293 | 293 | if (index == -1) |
|
294 | 294 | return; |
|
295 | 295 | replace(index, newPoint); |
|
296 | 296 | } |
|
297 | 297 | |
|
298 | /*! | |
|
299 | Replaces the point at \a index with data point (\a newX, \a newY). | |
|
300 | \sa QXYSeries::pointReplaced() | |
|
301 | */ | |
|
298 | 302 | void QXYSeries::replace(int index, qreal newX, qreal newY) |
|
299 | 303 | { |
|
300 | 304 | replace(index, QPointF(newX, newY)); |
|
301 | 305 | } |
|
302 | 306 | |
|
307 | /*! | |
|
308 | Replaces the point at \a index with \a newPoint. | |
|
309 | \sa QXYSeries::pointReplaced() | |
|
310 | */ | |
|
303 | 311 | void QXYSeries::replace(int index, const QPointF &newPoint) |
|
304 | 312 | { |
|
305 | 313 | Q_D(QXYSeries); |
|
306 | 314 | if (isValidValue(newPoint)) { |
|
307 | 315 | d->m_points[index] = newPoint; |
|
308 | 316 | emit pointReplaced(index); |
|
309 | 317 | } |
|
310 | 318 | } |
|
311 | 319 | |
|
312 | 320 | /*! |
|
313 | 321 | Replaces the current points with \a points. |
|
314 | 322 | \note This is much faster than replacing data points one by one, |
|
315 | 323 | or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced() |
|
316 | 324 | when the points have been replaced. |
|
317 | 325 | \sa QXYSeries::pointsReplaced() |
|
318 | 326 | */ |
|
319 | 327 | void QXYSeries::replace(QList<QPointF> points) |
|
320 | 328 | { |
|
321 | 329 | Q_D(QXYSeries); |
|
322 | 330 | d->m_points = points.toVector(); |
|
323 | 331 | emit pointsReplaced(); |
|
324 | 332 | } |
|
325 | 333 | |
|
326 | 334 | /*! |
|
327 | 335 | Removes the point (\a x, \a y) from the series. |
|
328 | 336 | */ |
|
329 | 337 | void QXYSeries::remove(qreal x, qreal y) |
|
330 | 338 | { |
|
331 | 339 | remove(QPointF(x, y)); |
|
332 | 340 | } |
|
333 | 341 | |
|
334 | 342 | /*! |
|
335 | 343 | Removes the \a point from the series. |
|
336 | 344 | */ |
|
337 | 345 | void QXYSeries::remove(const QPointF &point) |
|
338 | 346 | { |
|
339 | 347 | Q_D(QXYSeries); |
|
340 | 348 | int index = d->m_points.indexOf(point); |
|
341 | 349 | if (index == -1) |
|
342 | 350 | return; |
|
343 | 351 | remove(index); |
|
344 | 352 | } |
|
345 | 353 | |
|
354 | /*! | |
|
355 | Removes the point at \a index from the series. | |
|
356 | */ | |
|
346 | 357 | void QXYSeries::remove(int index) |
|
347 | 358 | { |
|
348 | 359 | Q_D(QXYSeries); |
|
349 | 360 | d->m_points.remove(index); |
|
350 | 361 | emit pointRemoved(index); |
|
351 | 362 | } |
|
352 | 363 | |
|
353 | 364 | /*! |
|
354 | 365 | Inserts a \a point in the series at \a index position. |
|
355 | 366 | */ |
|
356 | 367 | void QXYSeries::insert(int index, const QPointF &point) |
|
357 | 368 | { |
|
358 | 369 | Q_D(QXYSeries); |
|
359 | 370 | if (isValidValue(point)) { |
|
360 | 371 | d->m_points.insert(index, point); |
|
361 | 372 | emit pointAdded(index); |
|
362 | 373 | } |
|
363 | 374 | } |
|
364 | 375 | |
|
365 | 376 | /*! |
|
366 | 377 | Removes all points from the series. |
|
367 | 378 | */ |
|
368 | 379 | void QXYSeries::clear() |
|
369 | 380 | { |
|
370 | 381 | Q_D(QXYSeries); |
|
371 | 382 | for (int i = d->m_points.size() - 1; i >= 0; i--) |
|
372 | 383 | remove(d->m_points.at(i)); |
|
373 | 384 | } |
|
374 | 385 | |
|
375 | 386 | /*! |
|
376 | 387 | Returns list of points in the series. |
|
377 | 388 | */ |
|
378 | 389 | QList<QPointF> QXYSeries::points() const |
|
379 | 390 | { |
|
380 | 391 | Q_D(const QXYSeries); |
|
381 | 392 | return d->m_points.toList(); |
|
382 | 393 | } |
|
383 | 394 | |
|
384 | 395 | /*! |
|
385 | 396 | Returns point at \a index in internal points vector. |
|
386 | 397 | */ |
|
387 | 398 | const QPointF &QXYSeries::at(int index) const |
|
388 | 399 | { |
|
389 | 400 | Q_D(const QXYSeries); |
|
390 | 401 | return d->m_points.at(index); |
|
391 | 402 | } |
|
392 | 403 | |
|
393 | 404 | /*! |
|
394 | 405 | Returns number of data points within series. |
|
395 | 406 | */ |
|
396 | 407 | int QXYSeries::count() const |
|
397 | 408 | { |
|
398 | 409 | Q_D(const QXYSeries); |
|
399 | 410 | return d->m_points.count(); |
|
400 | 411 | } |
|
401 | 412 | |
|
402 | 413 | |
|
403 | 414 | /*! |
|
404 | 415 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
405 | 416 | pen from chart theme is used. |
|
406 | 417 | \sa QChart::setTheme() |
|
407 | 418 | */ |
|
408 | 419 | void QXYSeries::setPen(const QPen &pen) |
|
409 | 420 | { |
|
410 | 421 | Q_D(QXYSeries); |
|
411 | 422 | if (d->m_pen != pen) { |
|
412 | 423 | bool emitColorChanged = d->m_pen.color() != pen.color(); |
|
413 | 424 | d->m_pen = pen; |
|
414 | 425 | emit d->updated(); |
|
415 | 426 | if (emitColorChanged) |
|
416 | 427 | emit colorChanged(pen.color()); |
|
417 | 428 | } |
|
418 | 429 | } |
|
419 | 430 | |
|
420 | 431 | QPen QXYSeries::pen() const |
|
421 | 432 | { |
|
422 | 433 | Q_D(const QXYSeries); |
|
423 | 434 | return d->m_pen; |
|
424 | 435 | } |
|
425 | 436 | |
|
426 | 437 | /*! |
|
427 | 438 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
428 | 439 | from chart theme setting is used. |
|
429 | 440 | \sa QChart::setTheme() |
|
430 | 441 | */ |
|
431 | 442 | void QXYSeries::setBrush(const QBrush &brush) |
|
432 | 443 | { |
|
433 | 444 | Q_D(QXYSeries); |
|
434 | 445 | if (d->m_brush != brush) { |
|
435 | 446 | d->m_brush = brush; |
|
436 | 447 | emit d->updated(); |
|
437 | 448 | } |
|
438 | 449 | } |
|
439 | 450 | |
|
440 | 451 | QBrush QXYSeries::brush() const |
|
441 | 452 | { |
|
442 | 453 | Q_D(const QXYSeries); |
|
443 | 454 | return d->m_brush; |
|
444 | 455 | } |
|
445 | 456 | |
|
446 | 457 | void QXYSeries::setColor(const QColor &color) |
|
447 | 458 | { |
|
448 | 459 | QPen p = pen(); |
|
449 | 460 | if (p.color() != color) { |
|
450 | 461 | p.setColor(color); |
|
451 | 462 | setPen(p); |
|
452 | 463 | } |
|
453 | 464 | } |
|
454 | 465 | |
|
455 | 466 | QColor QXYSeries::color() const |
|
456 | 467 | { |
|
457 | 468 | return pen().color(); |
|
458 | 469 | } |
|
459 | 470 | |
|
460 | 471 | void QXYSeries::setPointsVisible(bool visible) |
|
461 | 472 | { |
|
462 | 473 | Q_D(QXYSeries); |
|
463 | 474 | if (d->m_pointsVisible != visible) { |
|
464 | 475 | d->m_pointsVisible = visible; |
|
465 | 476 | emit d->updated(); |
|
466 | 477 | } |
|
467 | 478 | } |
|
468 | 479 | |
|
469 | 480 | bool QXYSeries::pointsVisible() const |
|
470 | 481 | { |
|
471 | 482 | Q_D(const QXYSeries); |
|
472 | 483 | return d->m_pointsVisible; |
|
473 | 484 | } |
|
474 | 485 | |
|
475 | 486 | |
|
476 | 487 | /*! |
|
477 | 488 | Stream operator for adding a data \a point to the series. |
|
478 | 489 | \sa append() |
|
479 | 490 | */ |
|
480 | 491 | QXYSeries &QXYSeries::operator<< (const QPointF &point) |
|
481 | 492 | { |
|
482 | 493 | append(point); |
|
483 | 494 | return *this; |
|
484 | 495 | } |
|
485 | 496 | |
|
486 | 497 | |
|
487 | 498 | /*! |
|
488 | 499 | Stream operator for adding a list of \a points to the series. |
|
489 | 500 | \sa append() |
|
490 | 501 | */ |
|
491 | 502 | |
|
492 | 503 | QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points) |
|
493 | 504 | { |
|
494 | 505 | append(points); |
|
495 | 506 | return *this; |
|
496 | 507 | } |
|
497 | 508 | |
|
498 | 509 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
499 | 510 | |
|
500 | 511 | |
|
501 | 512 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) |
|
502 | 513 | : QAbstractSeriesPrivate(q), |
|
503 | 514 | m_pointsVisible(false) |
|
504 | 515 | { |
|
505 | 516 | } |
|
506 | 517 | |
|
507 | 518 | void QXYSeriesPrivate::initializeDomain() |
|
508 | 519 | { |
|
509 | 520 | qreal minX(0); |
|
510 | 521 | qreal minY(0); |
|
511 | 522 | qreal maxX(1); |
|
512 | 523 | qreal maxY(1); |
|
513 | 524 | |
|
514 | 525 | Q_Q(QXYSeries); |
|
515 | 526 | |
|
516 | 527 | const QList<QPointF>& points = q->points(); |
|
517 | 528 | |
|
518 | 529 | if (!points.isEmpty()) { |
|
519 | 530 | minX = points[0].x(); |
|
520 | 531 | minY = points[0].y(); |
|
521 | 532 | maxX = minX; |
|
522 | 533 | maxY = minY; |
|
523 | 534 | |
|
524 | 535 | for (int i = 0; i < points.count(); i++) { |
|
525 | 536 | qreal x = points[i].x(); |
|
526 | 537 | qreal y = points[i].y(); |
|
527 | 538 | minX = qMin(minX, x); |
|
528 | 539 | minY = qMin(minY, y); |
|
529 | 540 | maxX = qMax(maxX, x); |
|
530 | 541 | maxY = qMax(maxY, y); |
|
531 | 542 | } |
|
532 | 543 | } |
|
533 | 544 | |
|
534 | 545 | domain()->setRange(minX, maxX, minY, maxY); |
|
535 | 546 | } |
|
536 | 547 | |
|
537 | 548 | QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
538 | 549 | { |
|
539 | 550 | Q_Q(QXYSeries); |
|
540 | 551 | QList<QLegendMarker*> list; |
|
541 | 552 | return list << new QXYLegendMarker(q,legend); |
|
542 | 553 | } |
|
543 | 554 | |
|
544 | 555 | void QXYSeriesPrivate::initializeAxes() |
|
545 | 556 | { |
|
546 | 557 | |
|
547 | 558 | } |
|
548 | 559 | |
|
549 | 560 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
550 | 561 | { |
|
551 | 562 | Q_UNUSED(orientation); |
|
552 | 563 | return QAbstractAxis::AxisTypeValue; |
|
553 | 564 | } |
|
554 | 565 | |
|
555 | 566 | QAbstractAxis* QXYSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
556 | 567 | { |
|
557 | 568 | Q_UNUSED(orientation); |
|
558 | 569 | return 0; |
|
559 | 570 | } |
|
560 | 571 | |
|
561 | 572 | void QXYSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) |
|
562 | 573 | { |
|
563 | 574 | XYChart *item = static_cast<XYChart *>(m_item.data()); |
|
564 | 575 | Q_ASSERT(item); |
|
565 | 576 | if (options.testFlag(QChart::SeriesAnimations)) { |
|
566 | 577 | item->setAnimation(new XYAnimation(item)); |
|
567 | 578 | }else{ |
|
568 | 579 | item->setAnimation(0); |
|
569 | 580 | } |
|
570 | 581 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
571 | 582 | } |
|
572 | 583 | |
|
573 | 584 | #include "moc_qxyseries.cpp" |
|
574 | 585 | #include "moc_qxyseries_p.cpp" |
|
575 | 586 | |
|
576 | 587 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now