##// END OF EJS Templates
Fix documentation...
Titta Heikkala -
r2632:698e1bd0e999
parent child
Show More
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -1,826 +1,827
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qchart.h"
21 #include "qchart.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include "legendscroller_p.h"
23 #include "legendscroller_p.h"
24 #include "qlegend_p.h"
24 #include "qlegend_p.h"
25 #include "chartbackground_p.h"
25 #include "chartbackground_p.h"
26 #include "qabstractaxis.h"
26 #include "qabstractaxis.h"
27 #include "abstractchartlayout_p.h"
27 #include "abstractchartlayout_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "chartpresenter_p.h"
29 #include "chartpresenter_p.h"
30 #include "chartdataset_p.h"
30 #include "chartdataset_p.h"
31 #include <QGraphicsScene>
31 #include <QGraphicsScene>
32 #include <QGraphicsSceneResizeEvent>
32 #include <QGraphicsSceneResizeEvent>
33
33
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35
35
36 /*!
36 /*!
37 \enum QChart::ChartTheme
37 \enum QChart::ChartTheme
38
38
39 This enum describes the theme used by the chart.
39 This enum describes the theme used by the chart.
40
40
41 \value ChartThemeLight The default theme
41 \value ChartThemeLight The default theme
42 \value ChartThemeBlueCerulean
42 \value ChartThemeBlueCerulean
43 \value ChartThemeDark
43 \value ChartThemeDark
44 \value ChartThemeBrownSand
44 \value ChartThemeBrownSand
45 \value ChartThemeBlueNcs
45 \value ChartThemeBlueNcs
46 \value ChartThemeHighContrast
46 \value ChartThemeHighContrast
47 \value ChartThemeBlueIcy
47 \value ChartThemeBlueIcy
48 \value ChartThemeQt
48 */
49 */
49
50
50 /*!
51 /*!
51 \enum QChart::AnimationOption
52 \enum QChart::AnimationOption
52
53
53 For enabling/disabling animations. Defaults to NoAnimation.
54 For enabling/disabling animations. Defaults to NoAnimation.
54
55
55 \value NoAnimation
56 \value NoAnimation
56 \value GridAxisAnimations
57 \value GridAxisAnimations
57 \value SeriesAnimations
58 \value SeriesAnimations
58 \value AllAnimations
59 \value AllAnimations
59 */
60 */
60
61
61 /*!
62 /*!
62 \enum QChart::ChartType
63 \enum QChart::ChartType
63
64
64 This enum describes the chart type.
65 This enum describes the chart type.
65
66
66 \value ChartTypeUndefined
67 \value ChartTypeUndefined
67 \value ChartTypeCartesian
68 \value ChartTypeCartesian
68 \value ChartTypePolar
69 \value ChartTypePolar
69 */
70 */
70
71
71 /*!
72 /*!
72 \class QChart
73 \class QChart
73 \brief Main chart API for Qt Charts.
74 \brief Main chart API for Qt Charts.
74
75
75 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
76 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
76 representation of different types of series and other chart related objects like legend and
77 representation of different types of series and other chart related objects like legend and
77 axes. If you simply want to show a chart in a layout, you can use the
78 axes. If you simply want to show a chart in a layout, you can use the
78 convenience class QChartView instead of QChart.
79 convenience class QChartView instead of QChart.
79 \sa QChartView, QPolarChart
80 \sa QChartView, QPolarChart
80 */
81 */
81
82
82 /*!
83 /*!
83 \property QChart::animationOptions
84 \property QChart::animationOptions
84 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
85 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
85 */
86 */
86
87
87 /*!
88 /*!
88 \property QChart::backgroundVisible
89 \property QChart::backgroundVisible
89 Specifies whether the chart background is visible or not.
90 Specifies whether the chart background is visible or not.
90 \sa setBackgroundBrush(), setBackgroundPen(), plotAreaBackgroundVisible
91 \sa setBackgroundBrush(), setBackgroundPen(), plotAreaBackgroundVisible
91 */
92 */
92
93
93 /*!
94 /*!
94 \property QChart::dropShadowEnabled
95 \property QChart::dropShadowEnabled
95 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
96 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
96 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
97 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
97 */
98 */
98
99
99 /*!
100 /*!
100 \property QChart::backgroundRoundness
101 \property QChart::backgroundRoundness
101 The diameter of the rounding cirle at the corners of the chart background.
102 The diameter of the rounding cirle at the corners of the chart background.
102 */
103 */
103
104
104 /*!
105 /*!
105 \property QChart::minimumMargins
106 \property QChart::minimumMargins
106 Minimum margins between the plot area (axes) and the edge of the chart widget.
107 Minimum margins between the plot area (axes) and the edge of the chart widget.
107 This property is deprecated; use margins property instead.
108 This property is deprecated; use margins property instead.
108
109
109 \sa margins
110 \sa margins
110 */
111 */
111
112
112 /*!
113 /*!
113 \property QChart::margins
114 \property QChart::margins
114 Margins between the plot area (axes) and the edge of the chart widget.
115 Margins between the plot area (axes) and the edge of the chart widget.
115 */
116 */
116
117
117 /*!
118 /*!
118 \property QChart::theme
119 \property QChart::theme
119 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
120 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
120 pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes demo} shows an example with a few
121 pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes demo} shows an example with a few
121 different themes.
122 different themes.
122 \note Changing the theme will overwrite all customizations previously applied to the series.
123 \note Changing the theme will overwrite all customizations previously applied to the series.
123 */
124 */
124
125
125 /*!
126 /*!
126 \property QChart::title
127 \property QChart::title
127 Title is the name (label) of a chart. It is shown as a headline on top of the chart. Chart title supports html formatting.
128 Title is the name (label) of a chart. It is shown as a headline on top of the chart. Chart title supports html formatting.
128 */
129 */
129
130
130 /*!
131 /*!
131 \property QChart::chartType
132 \property QChart::chartType
132 Chart type indicates if the chart is a cartesian chart or a polar chart.
133 Chart type indicates if the chart is a cartesian chart or a polar chart.
133 This property is set internally and it is read only.
134 This property is set internally and it is read only.
134 \sa QPolarChart
135 \sa QPolarChart
135 */
136 */
136
137
137 /*!
138 /*!
138 \property QChart::plotAreaBackgroundVisible
139 \property QChart::plotAreaBackgroundVisible
139 Specifies whether the chart plot area background is visible or not.
140 Specifies whether the chart plot area background is visible or not.
140 \note By default the plot area background is not visible and the plot area uses
141 \note By default the plot area background is not visible and the plot area uses
141 the general chart background.
142 the general chart background.
142 \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible
143 \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible
143 */
144 */
144
145
145 /*!
146 /*!
146 \internal
147 \internal
147 Constructs a chart object of \a type which is a child of a \a parent.
148 Constructs a chart object of \a type which is a child of a \a parent.
148 Parameter \a wFlags is passed to the QGraphicsWidget constructor.
149 Parameter \a wFlags is passed to the QGraphicsWidget constructor.
149 This constructor is called only by subclasses.
150 This constructor is called only by subclasses.
150 */
151 */
151 QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags)
152 QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags)
152 : QGraphicsWidget(parent, wFlags),
153 : QGraphicsWidget(parent, wFlags),
153 d_ptr(new QChartPrivate(this, type))
154 d_ptr(new QChartPrivate(this, type))
154 {
155 {
155 d_ptr->init();
156 d_ptr->init();
156 }
157 }
157
158
158 /*!
159 /*!
159 Constructs a chart object which is a child of a \a parent.
160 Constructs a chart object which is a child of a \a parent.
160 Parameter \a wFlags is passed to the QGraphicsWidget constructor.
161 Parameter \a wFlags is passed to the QGraphicsWidget constructor.
161 */
162 */
162 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
163 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
163 : QGraphicsWidget(parent, wFlags),
164 : QGraphicsWidget(parent, wFlags),
164 d_ptr(new QChartPrivate(this, ChartTypeCartesian))
165 d_ptr(new QChartPrivate(this, ChartTypeCartesian))
165 {
166 {
166 d_ptr->init();
167 d_ptr->init();
167 }
168 }
168
169
169 /*!
170 /*!
170 Destroys the chart object and its children, like series and axis objects added to it.
171 Destroys the chart object and its children, like series and axis objects added to it.
171 */
172 */
172 QChart::~QChart()
173 QChart::~QChart()
173 {
174 {
174 //start by deleting dataset, it will remove all series and axes
175 //start by deleting dataset, it will remove all series and axes
175 delete d_ptr->m_dataset;
176 delete d_ptr->m_dataset;
176 d_ptr->m_dataset = 0;
177 d_ptr->m_dataset = 0;
177 }
178 }
178
179
179 /*!
180 /*!
180 Adds the \a series onto the chart and takes the ownership of it.
181 Adds the \a series onto the chart and takes the ownership of it.
181
182
182 \note A newly added series is attached to no axes by default, including any axes that were created for the chart
183 \note A newly added series is attached to no axes by default, including any axes that were created for the chart
183 using createDefaultAxes() before the series was added to the chart. If no axes are attached to
184 using createDefaultAxes() before the series was added to the chart. If no axes are attached to
184 the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges
185 the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges
185 that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other
186 that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other
186 series that have properly attached axes, so always make sure you either call createDefaultAxes() after
187 series that have properly attached axes, so always make sure you either call createDefaultAxes() after
187 a series has been added or explicitly attach axes for the series.
188 a series has been added or explicitly attach axes for the series.
188
189
189 \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis()
190 \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis()
190 */
191 */
191 void QChart::addSeries(QAbstractSeries *series)
192 void QChart::addSeries(QAbstractSeries *series)
192 {
193 {
193 Q_ASSERT(series);
194 Q_ASSERT(series);
194 d_ptr->m_dataset->addSeries(series);
195 d_ptr->m_dataset->addSeries(series);
195 }
196 }
196
197
197 /*!
198 /*!
198 Removes the \a series from the chart.
199 Removes the \a series from the chart.
199 The chart releases its ownership of the specified \a series object.
200 The chart releases its ownership of the specified \a series object.
200
201
201 \sa addSeries(), removeAllSeries()
202 \sa addSeries(), removeAllSeries()
202 */
203 */
203 void QChart::removeSeries(QAbstractSeries *series)
204 void QChart::removeSeries(QAbstractSeries *series)
204 {
205 {
205 Q_ASSERT(series);
206 Q_ASSERT(series);
206 d_ptr->m_dataset->removeSeries(series);
207 d_ptr->m_dataset->removeSeries(series);
207 }
208 }
208
209
209 /*!
210 /*!
210 Removes and deletes all series objects that have been added to the chart.
211 Removes and deletes all series objects that have been added to the chart.
211
212
212 \sa addSeries(), removeSeries()
213 \sa addSeries(), removeSeries()
213 */
214 */
214 void QChart::removeAllSeries()
215 void QChart::removeAllSeries()
215 {
216 {
216 foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){
217 foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){
217 removeSeries(s);
218 removeSeries(s);
218 delete s;
219 delete s;
219 }
220 }
220 }
221 }
221
222
222 /*!
223 /*!
223 Sets the \a brush that is used for painting the background of the chart area.
224 Sets the \a brush that is used for painting the background of the chart area.
224 */
225 */
225 void QChart::setBackgroundBrush(const QBrush &brush)
226 void QChart::setBackgroundBrush(const QBrush &brush)
226 {
227 {
227 d_ptr->m_presenter->setBackgroundBrush(brush);
228 d_ptr->m_presenter->setBackgroundBrush(brush);
228 }
229 }
229
230
230 /*!
231 /*!
231 Gets the brush that is used for painting the background of the chart area.
232 Gets the brush that is used for painting the background of the chart area.
232 */
233 */
233 QBrush QChart::backgroundBrush() const
234 QBrush QChart::backgroundBrush() const
234 {
235 {
235 return d_ptr->m_presenter->backgroundBrush();
236 return d_ptr->m_presenter->backgroundBrush();
236 }
237 }
237
238
238 /*!
239 /*!
239 Sets the \a pen that is used for painting the background of the chart area.
240 Sets the \a pen that is used for painting the background of the chart area.
240 */
241 */
241 void QChart::setBackgroundPen(const QPen &pen)
242 void QChart::setBackgroundPen(const QPen &pen)
242 {
243 {
243 d_ptr->m_presenter->setBackgroundPen(pen);
244 d_ptr->m_presenter->setBackgroundPen(pen);
244 }
245 }
245
246
246 /*!
247 /*!
247 Gets the pen that is used for painting the background of the chart area.
248 Gets the pen that is used for painting the background of the chart area.
248 */
249 */
249 QPen QChart::backgroundPen() const
250 QPen QChart::backgroundPen() const
250 {
251 {
251 return d_ptr->m_presenter->backgroundPen();
252 return d_ptr->m_presenter->backgroundPen();
252 }
253 }
253
254
254 void QChart::setTitle(const QString &title)
255 void QChart::setTitle(const QString &title)
255 {
256 {
256 d_ptr->m_presenter->setTitle(title);
257 d_ptr->m_presenter->setTitle(title);
257 }
258 }
258
259
259 QString QChart::title() const
260 QString QChart::title() const
260 {
261 {
261 return d_ptr->m_presenter->title();
262 return d_ptr->m_presenter->title();
262 }
263 }
263
264
264 /*!
265 /*!
265 Sets the \a font that is used for drawing the chart title.
266 Sets the \a font that is used for drawing the chart title.
266 */
267 */
267 void QChart::setTitleFont(const QFont &font)
268 void QChart::setTitleFont(const QFont &font)
268 {
269 {
269 d_ptr->m_presenter->setTitleFont(font);
270 d_ptr->m_presenter->setTitleFont(font);
270 }
271 }
271
272
272 /*!
273 /*!
273 Gets the font that is used for drawing the chart title.
274 Gets the font that is used for drawing the chart title.
274 */
275 */
275 QFont QChart::titleFont() const
276 QFont QChart::titleFont() const
276 {
277 {
277 return d_ptr->m_presenter->titleFont();
278 return d_ptr->m_presenter->titleFont();
278 }
279 }
279
280
280 /*!
281 /*!
281 Sets the \a brush used for drawing the title text.
282 Sets the \a brush used for drawing the title text.
282 */
283 */
283 void QChart::setTitleBrush(const QBrush &brush)
284 void QChart::setTitleBrush(const QBrush &brush)
284 {
285 {
285 d_ptr->m_presenter->setTitleBrush(brush);
286 d_ptr->m_presenter->setTitleBrush(brush);
286 }
287 }
287
288
288 /*!
289 /*!
289 Returns the brush used for drawing the title text.
290 Returns the brush used for drawing the title text.
290 */
291 */
291 QBrush QChart::titleBrush() const
292 QBrush QChart::titleBrush() const
292 {
293 {
293 return d_ptr->m_presenter->titleBrush();
294 return d_ptr->m_presenter->titleBrush();
294 }
295 }
295
296
296 void QChart::setTheme(QChart::ChartTheme theme)
297 void QChart::setTheme(QChart::ChartTheme theme)
297 {
298 {
298 d_ptr->m_themeManager->setTheme(theme);
299 d_ptr->m_themeManager->setTheme(theme);
299 }
300 }
300
301
301 QChart::ChartTheme QChart::theme() const
302 QChart::ChartTheme QChart::theme() const
302 {
303 {
303 return d_ptr->m_themeManager->theme()->id();
304 return d_ptr->m_themeManager->theme()->id();
304 }
305 }
305
306
306 /*!
307 /*!
307 Zooms in the view by a factor of two.
308 Zooms in the view by a factor of two.
308 */
309 */
309 void QChart::zoomIn()
310 void QChart::zoomIn()
310 {
311 {
311 d_ptr->zoomIn(2.0);
312 d_ptr->zoomIn(2.0);
312 }
313 }
313
314
314 /*!
315 /*!
315 Zooms in the view to a maximum level at which \a rect is still fully visible.
316 Zooms in the view to a maximum level at which \a rect is still fully visible.
316 \note This is not supported for polar charts.
317 \note This is not supported for polar charts.
317 */
318 */
318 void QChart::zoomIn(const QRectF &rect)
319 void QChart::zoomIn(const QRectF &rect)
319 {
320 {
320 if (d_ptr->m_type == QChart::ChartTypePolar)
321 if (d_ptr->m_type == QChart::ChartTypePolar)
321 return;
322 return;
322 d_ptr->zoomIn(rect);
323 d_ptr->zoomIn(rect);
323 }
324 }
324
325
325 /*!
326 /*!
326 Zooms out the view by a factor of two.
327 Zooms out the view by a factor of two.
327 */
328 */
328 void QChart::zoomOut()
329 void QChart::zoomOut()
329 {
330 {
330 d_ptr->zoomOut(2.0);
331 d_ptr->zoomOut(2.0);
331 }
332 }
332
333
333 /*!
334 /*!
334 Zooms in the view by a custom \a factor.
335 Zooms in the view by a custom \a factor.
335
336
336 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
337 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
337 */
338 */
338 void QChart::zoom(qreal factor)
339 void QChart::zoom(qreal factor)
339 {
340 {
340 if (qFuzzyCompare(factor, 0))
341 if (qFuzzyCompare(factor, 0))
341 return;
342 return;
342
343
343 if (qFuzzyCompare(factor, (qreal)1.0))
344 if (qFuzzyCompare(factor, (qreal)1.0))
344 return;
345 return;
345
346
346 if (factor < 0)
347 if (factor < 0)
347 return;
348 return;
348
349
349 if (factor > 1.0)
350 if (factor > 1.0)
350 d_ptr->zoomIn(factor);
351 d_ptr->zoomIn(factor);
351 else
352 else
352 d_ptr->zoomOut(1.0 / factor);
353 d_ptr->zoomOut(1.0 / factor);
353 }
354 }
354
355
355
356
356 /*!
357 /*!
357 Resets the series domains to what they were before any zoom method was called.
358 Resets the series domains to what they were before any zoom method was called.
358 Note that this will also reset any scrolls and explicit axis range settings done between
359 Note that this will also reset any scrolls and explicit axis range settings done between
359 the first zoom operation and calling this method. If no zoom operation has been
360 the first zoom operation and calling this method. If no zoom operation has been
360 done, this method does nothing.
361 done, this method does nothing.
361 */
362 */
362 void QChart::zoomReset()
363 void QChart::zoomReset()
363 {
364 {
364 d_ptr->zoomReset();
365 d_ptr->zoomReset();
365 }
366 }
366
367
367 /*!
368 /*!
368 Returns true if any series has a zoomed domain.
369 Returns true if any series has a zoomed domain.
369 */
370 */
370 bool QChart::isZoomed()
371 bool QChart::isZoomed()
371 {
372 {
372 return d_ptr->isZoomed();
373 return d_ptr->isZoomed();
373 }
374 }
374
375
375 /*!
376 /*!
376 Returns a pointer to the horizontal axis attached to the specified \a series.
377 Returns a pointer to the horizontal axis attached to the specified \a series.
377 If no \a series is specified, the first horizontal axis added to the chart is returned.
378 If no \a series is specified, the first horizontal axis added to the chart is returned.
378
379
379 \sa addAxis(), QAbstractSeries::attachAxis()
380 \sa addAxis(), QAbstractSeries::attachAxis()
380 */
381 */
381 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
382 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
382 {
383 {
383 QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series);
384 QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series);
384 if (axisList.count())
385 if (axisList.count())
385 return axisList[0];
386 return axisList[0];
386 return 0;
387 return 0;
387 }
388 }
388
389
389 /*!
390 /*!
390 Returns a pointer to the vertical axis attached to the specified \a series.
391 Returns a pointer to the vertical axis attached to the specified \a series.
391 If no \a series is specified, the first vertical axis added to the chart is returned.
392 If no \a series is specified, the first vertical axis added to the chart is returned.
392
393
393 \sa addAxis(), QAbstractSeries::attachAxis()
394 \sa addAxis(), QAbstractSeries::attachAxis()
394 */
395 */
395 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
396 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
396 {
397 {
397 QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series);
398 QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series);
398 if (axisList.count())
399 if (axisList.count())
399 return axisList[0];
400 return axisList[0];
400 return 0;
401 return 0;
401 }
402 }
402
403
403 /*!
404 /*!
404 Returns the axes attached to the \a series with \a orientation. If no \a series is provided,
405 Returns the axes attached to the \a series with \a orientation. If no \a series is provided,
405 then all axes added to the chart with the specified orientation are returned.
406 then all axes added to the chart with the specified orientation are returned.
406 \sa addAxis(), createDefaultAxes()
407 \sa addAxis(), createDefaultAxes()
407 */
408 */
408 QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const
409 QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const
409 {
410 {
410 QList<QAbstractAxis *> result ;
411 QList<QAbstractAxis *> result ;
411
412
412 if (series) {
413 if (series) {
413 foreach (QAbstractAxis *axis, series->attachedAxes()){
414 foreach (QAbstractAxis *axis, series->attachedAxes()){
414 if (orientation.testFlag(axis->orientation()))
415 if (orientation.testFlag(axis->orientation()))
415 result << axis;
416 result << axis;
416 }
417 }
417 } else {
418 } else {
418 foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){
419 foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){
419 if (orientation.testFlag(axis->orientation()) && !result.contains(axis))
420 if (orientation.testFlag(axis->orientation()) && !result.contains(axis))
420 result << axis;
421 result << axis;
421 }
422 }
422 }
423 }
423
424
424 return result;
425 return result;
425 }
426 }
426
427
427 /*!
428 /*!
428 Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to
429 Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to
429 the chart will be deleted.
430 the chart will be deleted.
430
431
431 \note This function has to be called after all series have been added to the chart. The axes created by this function
432 \note This function has to be called after all series have been added to the chart. The axes created by this function
432 will NOT get automatically attached to any series added to the chart after this function has been called.
433 will NOT get automatically attached to any series added to the chart after this function has been called.
433 A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing
434 A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing
434 if there are other series with properly attached axes also present.
435 if there are other series with properly attached axes also present.
435
436
436 \table
437 \table
437 \header
438 \header
438 \o Series type
439 \o Series type
439 \o X-axis
440 \o X-axis
440 \o Y-axis
441 \o Y-axis
441 \row
442 \row
442 \o QXYSeries
443 \o QXYSeries
443 \o QValueAxis
444 \o QValueAxis
444 \o QValueAxis
445 \o QValueAxis
445 \row
446 \row
446 \o QBarSeries
447 \o QBarSeries
447 \o QBarCategoryAxis
448 \o QBarCategoryAxis
448 \o QValueAxis
449 \o QValueAxis
449 \row
450 \row
450 \o QPieSeries
451 \o QPieSeries
451 \o None
452 \o None
452 \o None
453 \o None
453 \endtable
454 \endtable
454
455
455 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.
456 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.
456 If there are several series of different types added to the chart, then each series gets its own axes pair.
457 If there are several series of different types added to the chart, then each series gets its own axes pair.
457
458
458 The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call.
459 The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call.
459 QPieSeries does not create any axes.
460 QPieSeries does not create any axes.
460
461
461 \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis()
462 \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis()
462 */
463 */
463 void QChart::createDefaultAxes()
464 void QChart::createDefaultAxes()
464 {
465 {
465 d_ptr->m_dataset->createDefaultAxes();
466 d_ptr->m_dataset->createDefaultAxes();
466 }
467 }
467
468
468 /*!
469 /*!
469 Returns the legend object of the chart. Ownership stays with the chart.
470 Returns the legend object of the chart. Ownership stays with the chart.
470 */
471 */
471 QLegend *QChart::legend() const
472 QLegend *QChart::legend() const
472 {
473 {
473 return d_ptr->m_legend;
474 return d_ptr->m_legend;
474 }
475 }
475
476
476 void QChart::setMinimumMargins(const QMargins &margins)
477 void QChart::setMinimumMargins(const QMargins &margins)
477 {
478 {
478 qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead.";
479 qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead.";
479 d_ptr->m_presenter->layout()->setMargins(margins);
480 d_ptr->m_presenter->layout()->setMargins(margins);
480 }
481 }
481
482
482 QMargins QChart::minimumMargins() const
483 QMargins QChart::minimumMargins() const
483 {
484 {
484 qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead.";
485 qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead.";
485 return d_ptr->m_presenter->layout()->margins();
486 return d_ptr->m_presenter->layout()->margins();
486 }
487 }
487
488
488 void QChart::setMargins(const QMargins &margins)
489 void QChart::setMargins(const QMargins &margins)
489 {
490 {
490 d_ptr->m_presenter->layout()->setMargins(margins);
491 d_ptr->m_presenter->layout()->setMargins(margins);
491 }
492 }
492
493
493 QMargins QChart::margins() const
494 QMargins QChart::margins() const
494 {
495 {
495 return d_ptr->m_presenter->layout()->margins();
496 return d_ptr->m_presenter->layout()->margins();
496 }
497 }
497
498
498 QChart::ChartType QChart::chartType() const
499 QChart::ChartType QChart::chartType() const
499 {
500 {
500 return d_ptr->m_type;
501 return d_ptr->m_type;
501 }
502 }
502
503
503 /*!
504 /*!
504 Returns the the rectangle within which the drawing of the chart is done.
505 Returns the the rectangle within which the drawing of the chart is done.
505 It does not include the area defined by margins.
506 It does not include the area defined by margins.
506 */
507 */
507 QRectF QChart::plotArea() const
508 QRectF QChart::plotArea() const
508 {
509 {
509 return d_ptr->m_presenter->geometry();
510 return d_ptr->m_presenter->geometry();
510 }
511 }
511
512
512 /*!
513 /*!
513 Sets the \a brush for the background of the plot area of the chart.
514 Sets the \a brush for the background of the plot area of the chart.
514
515
515 \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush()
516 \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush()
516 */
517 */
517 void QChart::setPlotAreaBackgroundBrush(const QBrush &brush)
518 void QChart::setPlotAreaBackgroundBrush(const QBrush &brush)
518 {
519 {
519 d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush);
520 d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush);
520 }
521 }
521
522
522 /*!
523 /*!
523 Returns the brush for the background of the plot area of the chart.
524 Returns the brush for the background of the plot area of the chart.
524
525
525 \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush()
526 \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush()
526 */
527 */
527 QBrush QChart::plotAreaBackgroundBrush() const
528 QBrush QChart::plotAreaBackgroundBrush() const
528 {
529 {
529 return d_ptr->m_presenter->plotAreaBackgroundBrush();
530 return d_ptr->m_presenter->plotAreaBackgroundBrush();
530 }
531 }
531
532
532 /*!
533 /*!
533 Sets the \a pen for the background of the plot area of the chart.
534 Sets the \a pen for the background of the plot area of the chart.
534
535
535 \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen()
536 \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen()
536 */
537 */
537 void QChart::setPlotAreaBackgroundPen(const QPen &pen)
538 void QChart::setPlotAreaBackgroundPen(const QPen &pen)
538 {
539 {
539 d_ptr->m_presenter->setPlotAreaBackgroundPen(pen);
540 d_ptr->m_presenter->setPlotAreaBackgroundPen(pen);
540 }
541 }
541
542
542 /*!
543 /*!
543 Returns the pen for the background of the plot area of the chart.
544 Returns the pen for the background of the plot area of the chart.
544
545
545 \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen()
546 \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen()
546 */
547 */
547 QPen QChart::plotAreaBackgroundPen() const
548 QPen QChart::plotAreaBackgroundPen() const
548 {
549 {
549 return d_ptr->m_presenter->plotAreaBackgroundPen();
550 return d_ptr->m_presenter->plotAreaBackgroundPen();
550 }
551 }
551
552
552 void QChart::setPlotAreaBackgroundVisible(bool visible)
553 void QChart::setPlotAreaBackgroundVisible(bool visible)
553 {
554 {
554 d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible);
555 d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible);
555 }
556 }
556
557
557 bool QChart::isPlotAreaBackgroundVisible() const
558 bool QChart::isPlotAreaBackgroundVisible() const
558 {
559 {
559 return d_ptr->m_presenter->isPlotAreaBackgroundVisible();
560 return d_ptr->m_presenter->isPlotAreaBackgroundVisible();
560 }
561 }
561
562
562 void QChart::setAnimationOptions(AnimationOptions options)
563 void QChart::setAnimationOptions(AnimationOptions options)
563 {
564 {
564 d_ptr->m_presenter->setAnimationOptions(options);
565 d_ptr->m_presenter->setAnimationOptions(options);
565 }
566 }
566
567
567 QChart::AnimationOptions QChart::animationOptions() const
568 QChart::AnimationOptions QChart::animationOptions() const
568 {
569 {
569 return d_ptr->m_presenter->animationOptions();
570 return d_ptr->m_presenter->animationOptions();
570 }
571 }
571
572
572 /*!
573 /*!
573 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
574 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
574
575
575 For polar charts, \a dx indicates the angle along angular axis instead of distance.
576 For polar charts, \a dx indicates the angle along angular axis instead of distance.
576 */
577 */
577 void QChart::scroll(qreal dx, qreal dy)
578 void QChart::scroll(qreal dx, qreal dy)
578 {
579 {
579 d_ptr->scroll(dx,dy);
580 d_ptr->scroll(dx,dy);
580 }
581 }
581
582
582 void QChart::setBackgroundVisible(bool visible)
583 void QChart::setBackgroundVisible(bool visible)
583 {
584 {
584 d_ptr->m_presenter->setBackgroundVisible(visible);
585 d_ptr->m_presenter->setBackgroundVisible(visible);
585 }
586 }
586
587
587 bool QChart::isBackgroundVisible() const
588 bool QChart::isBackgroundVisible() const
588 {
589 {
589 return d_ptr->m_presenter->isBackgroundVisible();
590 return d_ptr->m_presenter->isBackgroundVisible();
590 }
591 }
591
592
592 void QChart::setDropShadowEnabled(bool enabled)
593 void QChart::setDropShadowEnabled(bool enabled)
593 {
594 {
594 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
595 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
595 }
596 }
596
597
597 bool QChart::isDropShadowEnabled() const
598 bool QChart::isDropShadowEnabled() const
598 {
599 {
599 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
600 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
600 }
601 }
601
602
602 void QChart::setBackgroundRoundness(qreal diameter)
603 void QChart::setBackgroundRoundness(qreal diameter)
603 {
604 {
604 d_ptr->m_presenter->setBackgroundRoundness(diameter);
605 d_ptr->m_presenter->setBackgroundRoundness(diameter);
605 }
606 }
606
607
607 qreal QChart::backgroundRoundness() const
608 qreal QChart::backgroundRoundness() const
608 {
609 {
609 return d_ptr->m_presenter->backgroundRoundness();
610 return d_ptr->m_presenter->backgroundRoundness();
610 }
611 }
611
612
612 /*!
613 /*!
613 Returns all series that are added to the chart.
614 Returns all series that are added to the chart.
614
615
615 \sa addSeries(), removeSeries(), removeAllSeries()
616 \sa addSeries(), removeSeries(), removeAllSeries()
616 */
617 */
617 QList<QAbstractSeries *> QChart::series() const
618 QList<QAbstractSeries *> QChart::series() const
618 {
619 {
619 return d_ptr->m_dataset->series();
620 return d_ptr->m_dataset->series();
620 }
621 }
621
622
622 /*!
623 /*!
623 Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis.
624 Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis.
624 The chart takes ownership of both the \a axis and the \a series.
625 The chart takes ownership of both the \a axis and the \a series.
625 Any horizontal axes previously attached to the \a series are deleted.
626 Any horizontal axes previously attached to the \a series are deleted.
626
627
627 \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis()
628 \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis()
628 */
629 */
629 void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series)
630 void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series)
630 {
631 {
631 QList<QAbstractAxis*> list = axes(Qt::Horizontal, series);
632 QList<QAbstractAxis*> list = axes(Qt::Horizontal, series);
632
633
633 foreach (QAbstractAxis* a, list) {
634 foreach (QAbstractAxis* a, list) {
634 d_ptr->m_dataset->removeAxis(a);
635 d_ptr->m_dataset->removeAxis(a);
635 delete a;
636 delete a;
636 }
637 }
637
638
638 if (!d_ptr->m_dataset->axes().contains(axis))
639 if (!d_ptr->m_dataset->axes().contains(axis))
639 d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom);
640 d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom);
640 d_ptr->m_dataset->attachAxis(series, axis);
641 d_ptr->m_dataset->attachAxis(series, axis);
641 }
642 }
642
643
643 /*!
644 /*!
644 Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis.
645 Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis.
645 The chart takes ownership of both the \a axis and the \a series.
646 The chart takes ownership of both the \a axis and the \a series.
646 Any vertical axes previously attached to the \a series are deleted.
647 Any vertical axes previously attached to the \a series are deleted.
647
648
648 \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis()
649 \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis()
649 */
650 */
650 void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series)
651 void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series)
651 {
652 {
652 QList<QAbstractAxis*> list = axes(Qt::Vertical, series);
653 QList<QAbstractAxis*> list = axes(Qt::Vertical, series);
653
654
654 foreach (QAbstractAxis* a, list) {
655 foreach (QAbstractAxis* a, list) {
655 d_ptr->m_dataset->removeAxis(a);
656 d_ptr->m_dataset->removeAxis(a);
656 delete a;
657 delete a;
657 }
658 }
658
659
659 if (!d_ptr->m_dataset->axes().contains(axis))
660 if (!d_ptr->m_dataset->axes().contains(axis))
660 d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft);
661 d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft);
661 d_ptr->m_dataset->attachAxis(series, axis);
662 d_ptr->m_dataset->attachAxis(series, axis);
662 }
663 }
663
664
664 /*!
665 /*!
665 Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis.
666 Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis.
666
667
667 \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis()
668 \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis()
668 */
669 */
669 void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment)
670 void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment)
670 {
671 {
671 d_ptr->m_dataset->addAxis(axis, alignment);
672 d_ptr->m_dataset->addAxis(axis, alignment);
672 }
673 }
673
674
674 /*!
675 /*!
675 Removes the \a axis from the chart.
676 Removes the \a axis from the chart.
676 The chart releases its ownership of the specified \a axis object.
677 The chart releases its ownership of the specified \a axis object.
677
678
678 \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis()
679 \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis()
679 */
680 */
680 void QChart::removeAxis(QAbstractAxis *axis)
681 void QChart::removeAxis(QAbstractAxis *axis)
681 {
682 {
682 d_ptr->m_dataset->removeAxis(axis);
683 d_ptr->m_dataset->removeAxis(axis);
683 }
684 }
684
685
685 /*!
686 /*!
686 Returns the value in the \a series domain that corresponds to the \a position relative to chart widget.
687 Returns the value in the \a series domain that corresponds to the \a position relative to chart widget.
687 */
688 */
688 QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series)
689 QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series)
689 {
690 {
690 return d_ptr->m_dataset->mapToValue(position, series);
691 return d_ptr->m_dataset->mapToValue(position, series);
691 }
692 }
692
693
693 /*!
694 /*!
694 Returns the position on the chart widget that corresponds to the \a value in the \a series domain.
695 Returns the position on the chart widget that corresponds to the \a value in the \a series domain.
695 */
696 */
696 QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series)
697 QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series)
697 {
698 {
698 return d_ptr->m_dataset->mapToPosition(value, series);
699 return d_ptr->m_dataset->mapToPosition(value, series);
699 }
700 }
700
701
701 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
702 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
702
703
703 QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type):
704 QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type):
704 q_ptr(q),
705 q_ptr(q),
705 m_legend(0),
706 m_legend(0),
706 m_dataset(new ChartDataSet(q)),
707 m_dataset(new ChartDataSet(q)),
707 m_presenter(new ChartPresenter(q, type)),
708 m_presenter(new ChartPresenter(q, type)),
708 m_themeManager(new ChartThemeManager(q)),
709 m_themeManager(new ChartThemeManager(q)),
709 m_type(type)
710 m_type(type)
710 {
711 {
711 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*)));
712 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*)));
712 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*)));
713 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*)));
713 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*)));
714 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*)));
714 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*)));
715 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*)));
715 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*)));
716 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*)));
716 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*)));
717 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*)));
717 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*)));
718 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*)));
718 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*)));
719 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*)));
719 }
720 }
720
721
721 QChartPrivate::~QChartPrivate()
722 QChartPrivate::~QChartPrivate()
722 {
723 {
723 }
724 }
724
725
725 // Hackish solution to the problem of explicitly assigning the default pen/brush/font
726 // Hackish solution to the problem of explicitly assigning the default pen/brush/font
726 // to a series or axis and having theme override it:
727 // to a series or axis and having theme override it:
727 // Initialize pens, brushes, and fonts to something nobody is likely to ever use,
728 // Initialize pens, brushes, and fonts to something nobody is likely to ever use,
728 // so that default theme initialization will always set these properly.
729 // so that default theme initialization will always set these properly.
729 QPen &QChartPrivate::defaultPen()
730 QPen &QChartPrivate::defaultPen()
730 {
731 {
731 static QPen defaultPen(QColor(1, 2, 0), 0.93247536);
732 static QPen defaultPen(QColor(1, 2, 0), 0.93247536);
732 return defaultPen;
733 return defaultPen;
733 }
734 }
734
735
735 QBrush &QChartPrivate::defaultBrush()
736 QBrush &QChartPrivate::defaultBrush()
736 {
737 {
737 static QBrush defaultBrush(QColor(1, 2, 0), Qt::Dense7Pattern);
738 static QBrush defaultBrush(QColor(1, 2, 0), Qt::Dense7Pattern);
738 return defaultBrush;
739 return defaultBrush;
739 }
740 }
740
741
741 QFont &QChartPrivate::defaultFont()
742 QFont &QChartPrivate::defaultFont()
742 {
743 {
743 static bool defaultFontInitialized(false);
744 static bool defaultFontInitialized(false);
744 static QFont defaultFont;
745 static QFont defaultFont;
745 if (!defaultFontInitialized) {
746 if (!defaultFontInitialized) {
746 defaultFont.setPointSizeF(8.34563465);
747 defaultFont.setPointSizeF(8.34563465);
747 defaultFontInitialized = true;
748 defaultFontInitialized = true;
748 }
749 }
749 return defaultFont;
750 return defaultFont;
750 }
751 }
751
752
752 void QChartPrivate::init()
753 void QChartPrivate::init()
753 {
754 {
754 m_legend = new LegendScroller(q_ptr);
755 m_legend = new LegendScroller(q_ptr);
755 q_ptr->setTheme(QChart::ChartThemeLight);
756 q_ptr->setTheme(QChart::ChartThemeLight);
756 q_ptr->setLayout(m_presenter->layout());
757 q_ptr->setLayout(m_presenter->layout());
757 }
758 }
758
759
759 void QChartPrivate::zoomIn(qreal factor)
760 void QChartPrivate::zoomIn(qreal factor)
760 {
761 {
761 QRectF rect = m_presenter->geometry();
762 QRectF rect = m_presenter->geometry();
762 rect.setWidth(rect.width() / factor);
763 rect.setWidth(rect.width() / factor);
763 rect.setHeight(rect.height() / factor);
764 rect.setHeight(rect.height() / factor);
764 rect.moveCenter(m_presenter->geometry().center());
765 rect.moveCenter(m_presenter->geometry().center());
765 zoomIn(rect);
766 zoomIn(rect);
766 }
767 }
767
768
768 void QChartPrivate::zoomIn(const QRectF &rect)
769 void QChartPrivate::zoomIn(const QRectF &rect)
769 {
770 {
770 if (!rect.isValid())
771 if (!rect.isValid())
771 return;
772 return;
772
773
773 QRectF r = rect.normalized();
774 QRectF r = rect.normalized();
774 const QRectF geometry = m_presenter->geometry();
775 const QRectF geometry = m_presenter->geometry();
775 r.translate(-geometry.topLeft());
776 r.translate(-geometry.topLeft());
776
777
777 if (!r.isValid())
778 if (!r.isValid())
778 return;
779 return;
779
780
780 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
781 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
781 m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint);
782 m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint);
782 m_dataset->zoomInDomain(r);
783 m_dataset->zoomInDomain(r);
783 m_presenter->setState(ChartPresenter::ShowState,QPointF());
784 m_presenter->setState(ChartPresenter::ShowState,QPointF());
784
785
785 }
786 }
786
787
787 void QChartPrivate::zoomReset()
788 void QChartPrivate::zoomReset()
788 {
789 {
789 m_dataset->zoomResetDomain();
790 m_dataset->zoomResetDomain();
790 }
791 }
791
792
792 bool QChartPrivate::isZoomed()
793 bool QChartPrivate::isZoomed()
793 {
794 {
794 return m_dataset->isZoomedDomain();
795 return m_dataset->isZoomedDomain();
795 }
796 }
796
797
797 void QChartPrivate::zoomOut(qreal factor)
798 void QChartPrivate::zoomOut(qreal factor)
798 {
799 {
799 const QRectF geometry = m_presenter->geometry();
800 const QRectF geometry = m_presenter->geometry();
800
801
801 QRectF r;
802 QRectF r;
802 r.setSize(geometry.size() / factor);
803 r.setSize(geometry.size() / factor);
803 r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2));
804 r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2));
804 if (!r.isValid())
805 if (!r.isValid())
805 return;
806 return;
806
807
807 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
808 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
808 m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint);
809 m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint);
809 m_dataset->zoomOutDomain(r);
810 m_dataset->zoomOutDomain(r);
810 m_presenter->setState(ChartPresenter::ShowState,QPointF());
811 m_presenter->setState(ChartPresenter::ShowState,QPointF());
811 }
812 }
812
813
813 void QChartPrivate::scroll(qreal dx, qreal dy)
814 void QChartPrivate::scroll(qreal dx, qreal dy)
814 {
815 {
815 if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF());
816 if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF());
816 if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF());
817 if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF());
817 if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF());
818 if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF());
818 if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF());
819 if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF());
819
820
820 m_dataset->scrollDomain(dx, dy);
821 m_dataset->scrollDomain(dx, dy);
821 m_presenter->setState(ChartPresenter::ShowState,QPointF());
822 m_presenter->setState(ChartPresenter::ShowState,QPointF());
822 }
823 }
823
824
824 #include "moc_qchart.cpp"
825 #include "moc_qchart.cpp"
825
826
826 QTCOMMERCIALCHART_END_NAMESPACE
827 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now