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