##// END OF EJS Templates
make setAxisX setAxisY functionality compatible
Michal Klocek -
r2278:c185a1f604d6
parent child
Show More
@@ -1,662 +1,654
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 d_ptr->m_dataset->removeAllSeries();
163 d_ptr->m_dataset->removeAllSeries();
164 }
164 }
165
165
166 /*!
166 /*!
167 Sets the \a brush that is used for painting the background of the chart area.
167 Sets the \a brush that is used for painting the background of the chart area.
168 */
168 */
169 void QChart::setBackgroundBrush(const QBrush &brush)
169 void QChart::setBackgroundBrush(const QBrush &brush)
170 {
170 {
171 d_ptr->m_presenter->setBackgroundBrush(brush);
171 d_ptr->m_presenter->setBackgroundBrush(brush);
172 }
172 }
173
173
174 /*!
174 /*!
175 Gets the brush that is used for painting the background of the chart area.
175 Gets the brush that is used for painting the background of the chart area.
176 */
176 */
177 QBrush QChart::backgroundBrush() const
177 QBrush QChart::backgroundBrush() const
178 {
178 {
179 return d_ptr->m_presenter->backgroundBrush();
179 return d_ptr->m_presenter->backgroundBrush();
180 }
180 }
181
181
182 /*!
182 /*!
183 Sets the \a pen that is used for painting the background of the chart area.
183 Sets the \a pen that is used for painting the background of the chart area.
184 */
184 */
185 void QChart::setBackgroundPen(const QPen &pen)
185 void QChart::setBackgroundPen(const QPen &pen)
186 {
186 {
187 d_ptr->m_presenter->setBackgroundPen(pen);
187 d_ptr->m_presenter->setBackgroundPen(pen);
188 }
188 }
189
189
190 /*!
190 /*!
191 Gets the pen that is used for painting the background of the chart area.
191 Gets the pen that is used for painting the background of the chart area.
192 */
192 */
193 QPen QChart::backgroundPen() const
193 QPen QChart::backgroundPen() const
194 {
194 {
195 return d_ptr->m_presenter->backgroundPen();
195 return d_ptr->m_presenter->backgroundPen();
196 }
196 }
197
197
198 /*!
198 /*!
199 Sets the chart \a title. The description text that is drawn above the chart.
199 Sets the chart \a title. The description text that is drawn above the chart.
200 */
200 */
201 void QChart::setTitle(const QString &title)
201 void QChart::setTitle(const QString &title)
202 {
202 {
203 d_ptr->m_presenter->setTitle(title);
203 d_ptr->m_presenter->setTitle(title);
204 }
204 }
205
205
206 /*!
206 /*!
207 Returns the chart title. The description text that is drawn above the chart.
207 Returns the chart title. The description text that is drawn above the chart.
208 */
208 */
209 QString QChart::title() const
209 QString QChart::title() const
210 {
210 {
211 return d_ptr->m_presenter->title();
211 return d_ptr->m_presenter->title();
212 }
212 }
213
213
214 /*!
214 /*!
215 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
215 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
216 */
216 */
217 void QChart::setTitleFont(const QFont &font)
217 void QChart::setTitleFont(const QFont &font)
218 {
218 {
219 d_ptr->m_presenter->setTitleFont(font);
219 d_ptr->m_presenter->setTitleFont(font);
220 }
220 }
221
221
222 /*!
222 /*!
223 Gets the font that is used for drawing the chart description text that is rendered above the chart.
223 Gets the font that is used for drawing the chart description text that is rendered above the chart.
224 */
224 */
225 QFont QChart::titleFont() const
225 QFont QChart::titleFont() const
226 {
226 {
227 return d_ptr->m_presenter->titleFont();
227 return d_ptr->m_presenter->titleFont();
228 }
228 }
229
229
230 /*!
230 /*!
231 Sets the \a brush used for rendering the title text.
231 Sets the \a brush used for rendering the title text.
232 */
232 */
233 void QChart::setTitleBrush(const QBrush &brush)
233 void QChart::setTitleBrush(const QBrush &brush)
234 {
234 {
235 d_ptr->m_presenter->setTitleBrush(brush);
235 d_ptr->m_presenter->setTitleBrush(brush);
236 }
236 }
237
237
238 /*!
238 /*!
239 Returns the brush used for rendering the title text.
239 Returns the brush used for rendering the title text.
240 */
240 */
241 QBrush QChart::titleBrush() const
241 QBrush QChart::titleBrush() const
242 {
242 {
243 return d_ptr->m_presenter->titleBrush();
243 return d_ptr->m_presenter->titleBrush();
244 }
244 }
245
245
246 void QChart::setTheme(QChart::ChartTheme theme)
246 void QChart::setTheme(QChart::ChartTheme theme)
247 {
247 {
248 d_ptr->m_themeManager->setTheme(theme);
248 d_ptr->m_themeManager->setTheme(theme);
249 }
249 }
250
250
251 QChart::ChartTheme QChart::theme() const
251 QChart::ChartTheme QChart::theme() const
252 {
252 {
253 return d_ptr->m_themeManager->theme()->id();
253 return d_ptr->m_themeManager->theme()->id();
254 }
254 }
255
255
256 /*!
256 /*!
257 Zooms in the view by a factor of 2
257 Zooms in the view by a factor of 2
258 */
258 */
259 void QChart::zoomIn()
259 void QChart::zoomIn()
260 {
260 {
261 d_ptr->zoomIn(2.0);
261 d_ptr->zoomIn(2.0);
262 }
262 }
263
263
264 /*!
264 /*!
265 Zooms in the view to a maximum level at which \a rect is still fully visible.
265 Zooms in the view to a maximum level at which \a rect is still fully visible.
266 */
266 */
267 void QChart::zoomIn(const QRectF &rect)
267 void QChart::zoomIn(const QRectF &rect)
268 {
268 {
269 d_ptr->zoomIn(rect);
269 d_ptr->zoomIn(rect);
270 }
270 }
271
271
272 /*!
272 /*!
273 Restores the view zoom level to the previous one.
273 Restores the view zoom level to the previous one.
274 */
274 */
275 void QChart::zoomOut()
275 void QChart::zoomOut()
276 {
276 {
277 d_ptr->zoomOut(2.0);
277 d_ptr->zoomOut(2.0);
278 }
278 }
279
279
280 /*!
280 /*!
281 Zooms in the view by a \a factor.
281 Zooms in the view by a \a factor.
282
282
283 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
283 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
284 */
284 */
285 void QChart::zoom(qreal factor)
285 void QChart::zoom(qreal factor)
286 {
286 {
287 if (qFuzzyCompare(factor, 0))
287 if (qFuzzyCompare(factor, 0))
288 return;
288 return;
289
289
290 if (qFuzzyCompare(factor, (qreal)1.0))
290 if (qFuzzyCompare(factor, (qreal)1.0))
291 return;
291 return;
292
292
293 if (factor < 0)
293 if (factor < 0)
294 return;
294 return;
295
295
296 if (factor > 1.0)
296 if (factor > 1.0)
297 d_ptr->zoomIn(factor);
297 d_ptr->zoomIn(factor);
298 else
298 else
299 d_ptr->zoomOut(1.0 / factor);
299 d_ptr->zoomOut(1.0 / factor);
300 }
300 }
301
301
302 /*!
302 /*!
303 Returns the pointer to the x axis object of the chart asociated with the specified \a series
303 Returns the pointer to the x axis object of the chart asociated with the specified \a series
304 If no series is provided then pointer to currently visible axis is provided
304 If no series is provided then pointer to currently visible axis is provided
305 */
305 */
306 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
306 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
307 {
307 {
308 if(!series && d_ptr->m_dataset->series().size()>0){
308 if(!series && d_ptr->m_dataset->series().size()>0){
309 series = d_ptr->m_dataset->series().first();
309 series = d_ptr->m_dataset->series().first();
310 }else{
311 return 0;
312 }
310 }
313
311
314 QList<QAbstractAxis*> axes = series->attachedAxes();
312 QList<QAbstractAxis*> axes = series->attachedAxes();
315 QAbstractAxis* bottom=0;
313 QAbstractAxis* bottom=0;
316 QAbstractAxis* top=0;
314 QAbstractAxis* top=0;
317
315
318 foreach(QAbstractAxis* axis, axes){
316 foreach(QAbstractAxis* axis, axes){
319
317
320 if(axis->alignment()==Qt::AlignTop){
318 if(axis->alignment()==Qt::AlignTop){
321 top=axis;
319 top=axis;
322 }
320 }
323
321
324 if(axis->alignment()==Qt::AlignBottom){
322 if(axis->alignment()==Qt::AlignBottom){
325 bottom=axis;
323 bottom=axis;
326 }
324 }
327 }
325 }
328 return bottom?bottom:top;
326 return bottom?bottom:top;
329 }
327 }
330
328
331 /*!
329 /*!
332 Returns the pointer to the y axis object of the chart asociated with the specified \a series
330 Returns the pointer to the y axis object of the chart asociated with the specified \a series
333 If no series is provided then pointer to currently visible axis is provided
331 If no series is provided then pointer to currently visible axis is provided
334 */
332 */
335 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
333 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
336 {
334 {
337 if(!series && d_ptr->m_dataset->series().size()>0) {
335 if(!series && d_ptr->m_dataset->series().size()>0) {
338 series = d_ptr->m_dataset->series().first();
336 series = d_ptr->m_dataset->series().first();
339 } else {
340 return 0;
341 }
337 }
342
338
343 QList<QAbstractAxis*> axes = series->attachedAxes();
339 QList<QAbstractAxis*> axes = series->attachedAxes();
344
340
345 QAbstractAxis* left=0;
341 QAbstractAxis* left=0;
346 QAbstractAxis* right=0;
342 QAbstractAxis* right=0;
347
343
348 foreach(QAbstractAxis* axis, axes){
344 foreach(QAbstractAxis* axis, axes){
349
345
350 if(axis->alignment()==Qt::AlignLeft){
346 if(axis->alignment()==Qt::AlignLeft){
351 left=axis;
347 left=axis;
352 }
348 }
353
349
354 if(axis->alignment()==Qt::AlignRight){
350 if(axis->alignment()==Qt::AlignRight){
355 right=axis;
351 right=axis;
356 }
352 }
357 }
353 }
358
354
359 return left?left:right;
355 return left?left:right;
360 }
356 }
361
357
362
358
363 QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const
359 QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const
364 {
360 {
365 QList<QAbstractAxis *> result ;
361 QList<QAbstractAxis *> result ;
366
362
367 foreach(QAbstractAxis* axis,series->attachedAxes()){
363 foreach(QAbstractAxis* axis,series->attachedAxes()){
368 if(orientation.testFlag(axis->orientation()))
364 if(orientation.testFlag(axis->orientation()))
369 result << axis;
365 result << axis;
370 }
366 }
371
367
372 return result;
368 return result;
373 }
369 }
374
370
375 /*!
371 /*!
376 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.
372 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.
377
373
378 Creates the axes for the chart based on the series that has already been added to the chart.
374 Creates the axes for the chart based on the series that has already been added to the chart.
379
375
380 \table
376 \table
381 \header
377 \header
382 \o Series type
378 \o Series type
383 \o X-axis
379 \o X-axis
384 \o Y-axis
380 \o Y-axis
385 \row
381 \row
386 \o QXYSeries
382 \o QXYSeries
387 \o QValueAxis
383 \o QValueAxis
388 \o QValueAxis
384 \o QValueAxis
389 \row
385 \row
390 \o QBarSeries
386 \o QBarSeries
391 \o QBarCategoryAxis
387 \o QBarCategoryAxis
392 \o QValueAxis
388 \o QValueAxis
393 \row
389 \row
394 \o QPieSeries
390 \o QPieSeries
395 \o None
391 \o None
396 \o None
392 \o None
397 \endtable
393 \endtable
398
394
399 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.
395 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.
400 If there are sevaral series added of different types then each series gets its own axes pair.
396 If there are sevaral series added of different types then each series gets its own axes pair.
401
397
402 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.
398 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.
403
399
404 Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls.
400 Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls.
405 QPieSeries does not create any axes.
401 QPieSeries does not create any axes.
406
402
407 \sa axisX(), axisY(), setAxisX(), setAxisY()
403 \sa axisX(), axisY(), setAxisX(), setAxisY()
408 */
404 */
409 void QChart::createDefaultAxes()
405 void QChart::createDefaultAxes()
410 {
406 {
411 d_ptr->m_dataset->createDefaultAxes();
407 d_ptr->m_dataset->createDefaultAxes();
412 }
408 }
413
409
414 /*!
410 /*!
415 Returns the legend object of the chart. Ownership stays in chart.
411 Returns the legend object of the chart. Ownership stays in chart.
416 */
412 */
417 QLegend *QChart::legend() const
413 QLegend *QChart::legend() const
418 {
414 {
419 return d_ptr->m_legend;
415 return d_ptr->m_legend;
420 }
416 }
421
417
422 /*!
418 /*!
423 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
419 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
424 Deprecated. Use setMargins().
420 Deprecated. Use setMargins().
425 */
421 */
426 void QChart::setMinimumMargins(const QMargins &margins)
422 void QChart::setMinimumMargins(const QMargins &margins)
427 {
423 {
428 qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead.";
424 qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead.";
429 d_ptr->m_presenter->layout()->setMargins(margins);
425 d_ptr->m_presenter->layout()->setMargins(margins);
430 }
426 }
431
427
432 /*!
428 /*!
433 Returns the rect that contains information about margins (distance between chart widget edge and axes).
429 Returns the rect that contains information about margins (distance between chart widget edge and axes).
434 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
430 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
435 Deprecated. Use margins().
431 Deprecated. Use margins().
436 */
432 */
437 QMargins QChart::minimumMargins() const
433 QMargins QChart::minimumMargins() const
438 {
434 {
439 qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead.";
435 qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead.";
440 return d_ptr->m_presenter->layout()->margins();
436 return d_ptr->m_presenter->layout()->margins();
441 }
437 }
442
438
443 /*!
439 /*!
444 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
440 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
445 */
441 */
446 void QChart::setMargins(const QMargins &margins)
442 void QChart::setMargins(const QMargins &margins)
447 {
443 {
448 d_ptr->m_presenter->layout()->setMargins(margins);
444 d_ptr->m_presenter->layout()->setMargins(margins);
449 }
445 }
450
446
451 /*!
447 /*!
452 Returns the rect that contains information about margins (distance between chart widget edge and axes).
448 Returns the rect that contains information about margins (distance between chart widget edge and axes).
453 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
449 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
454 */
450 */
455 QMargins QChart::margins() const
451 QMargins QChart::margins() const
456 {
452 {
457 return d_ptr->m_presenter->layout()->margins();
453 return d_ptr->m_presenter->layout()->margins();
458 }
454 }
459
455
460 /*!
456 /*!
461 Returns the the rect within which the drawing of the chart is done.
457 Returns the the rect within which the drawing of the chart is done.
462 It does not include the area defines by margins.
458 It does not include the area defines by margins.
463 */
459 */
464 QRectF QChart::plotArea() const
460 QRectF QChart::plotArea() const
465 {
461 {
466 return d_ptr->m_presenter->geometry();
462 return d_ptr->m_presenter->geometry();
467 }
463 }
468
464
469 ///*!
465 ///*!
470 // TODO: Dummy.
466 // TODO: Dummy.
471 // Adjest the ranges of the axes so that all the data of the specified \a series is visible
467 // Adjest the ranges of the axes so that all the data of the specified \a series is visible
472 // */
468 // */
473 //void QChart::adjustViewToSeries(QAbstractSeries* series)
469 //void QChart::adjustViewToSeries(QAbstractSeries* series)
474 //{
470 //{
475 // //
471 // //
476 //}
472 //}
477
473
478 /*!
474 /*!
479 Sets animation \a options for the chart
475 Sets animation \a options for the chart
480 */
476 */
481 void QChart::setAnimationOptions(AnimationOptions options)
477 void QChart::setAnimationOptions(AnimationOptions options)
482 {
478 {
483 d_ptr->m_presenter->setAnimationOptions(options);
479 d_ptr->m_presenter->setAnimationOptions(options);
484 }
480 }
485
481
486 QChart::AnimationOptions QChart::animationOptions() const
482 QChart::AnimationOptions QChart::animationOptions() const
487 {
483 {
488 return d_ptr->m_presenter->animationOptions();
484 return d_ptr->m_presenter->animationOptions();
489 }
485 }
490
486
491 /*!
487 /*!
492 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
488 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
493 */
489 */
494 void QChart::scroll(qreal dx, qreal dy)
490 void QChart::scroll(qreal dx, qreal dy)
495 {
491 {
496 d_ptr->scroll(dx,dy);
492 d_ptr->scroll(dx,dy);
497 }
493 }
498
494
499 void QChart::setBackgroundVisible(bool visible)
495 void QChart::setBackgroundVisible(bool visible)
500 {
496 {
501 d_ptr->m_presenter->setBackgroundVisible(visible);
497 d_ptr->m_presenter->setBackgroundVisible(visible);
502 }
498 }
503
499
504 bool QChart::isBackgroundVisible() const
500 bool QChart::isBackgroundVisible() const
505 {
501 {
506 return d_ptr->m_presenter->isBackgroundVisible();
502 return d_ptr->m_presenter->isBackgroundVisible();
507 }
503 }
508
504
509 void QChart::setDropShadowEnabled(bool enabled)
505 void QChart::setDropShadowEnabled(bool enabled)
510 {
506 {
511 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
507 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
512 }
508 }
513
509
514 bool QChart::isDropShadowEnabled() const
510 bool QChart::isDropShadowEnabled() const
515 {
511 {
516 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
512 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
517 }
513 }
518
514
519 /*!
515 /*!
520 Returns all the series that are added to the chart.
516 Returns all the series that are added to the chart.
521
517
522 \sa addSeries(), removeSeries(), removeAllSeries()
518 \sa addSeries(), removeSeries(), removeAllSeries()
523 */
519 */
524 QList<QAbstractSeries *> QChart::series() const
520 QList<QAbstractSeries *> QChart::series() const
525 {
521 {
526 return d_ptr->m_dataset->series();
522 return d_ptr->m_dataset->series();
527 }
523 }
528
524
529 /*!
525 /*!
530 Sets \a axis to the chart, which will control the presentation of the \a series
526 Sets \a axis to the chart, which will control the presentation of the \a series
531
527
532 \sa axisX(), axisY(), setAxisY(), createDefaultAxes()
528 \sa axisX(), axisY(), setAxisY(), createDefaultAxes()
533 */
529 */
534 void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series)
530 void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series)
535 {
531 {
536 QList<QAbstractAxis*> list = axes(Qt::Horizontal,series);
532 QList<QAbstractAxis*> list = axes(Qt::Horizontal,series);
537
533
538 foreach(QAbstractAxis* a, list){
534 foreach(QAbstractAxis* a, list){
539 if(a->alignment()==axis->alignment()){
540 d_ptr->m_dataset->removeAxis(a);
535 d_ptr->m_dataset->removeAxis(a);
541 delete a;
536 delete a;
542 }
537 }
543 }
544
538
545 if(!d_ptr->m_dataset->axes().contains(axis))
539 if(!d_ptr->m_dataset->axes().contains(axis))
546 d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom);
540 d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom);
547 d_ptr->m_dataset->attachAxis(series,axis);
541 d_ptr->m_dataset->attachAxis(series,axis);
548 }
542 }
549
543
550 /*!
544 /*!
551 Sets \a axis to the chart, which will control the presentation of the \a series
545 Sets \a axis to the chart, which will control the presentation of the \a series
552
546
553 \sa axisX(), axisY(), setAxisX(), createDefaultAxes()
547 \sa axisX(), axisY(), setAxisX(), createDefaultAxes()
554 */
548 */
555 void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series)
549 void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series)
556 {
550 {
557 QList<QAbstractAxis*> list = axes(Qt::Vertical,series);
551 QList<QAbstractAxis*> list = axes(Qt::Vertical,series);
558
552
559 foreach(QAbstractAxis* a, list) {
553 foreach(QAbstractAxis* a, list) {
560 if(a->alignment()==axis->alignment()) {
561 d_ptr->m_dataset->removeAxis(a);
554 d_ptr->m_dataset->removeAxis(a);
562 delete a;
555 delete a;
563 }
556 }
564 }
565
557
566 if(!d_ptr->m_dataset->axes().contains(axis))
558 if(!d_ptr->m_dataset->axes().contains(axis))
567 d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft);
559 d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft);
568 d_ptr->m_dataset->attachAxis(series,axis);
560 d_ptr->m_dataset->attachAxis(series,axis);
569 }
561 }
570
562
571 void QChart::addAxis(QAbstractAxis *axis,Qt::Alignment aligment)
563 void QChart::addAxis(QAbstractAxis *axis,Qt::Alignment aligment)
572 {
564 {
573 d_ptr->m_dataset->addAxis(axis,aligment);
565 d_ptr->m_dataset->addAxis(axis,aligment);
574 }
566 }
575
567
576 void QChart::removeAxis(QAbstractAxis *axis)
568 void QChart::removeAxis(QAbstractAxis *axis)
577 {
569 {
578 d_ptr->m_dataset->removeAxis(axis);
570 d_ptr->m_dataset->removeAxis(axis);
579 }
571 }
580
572
581 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
573 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
582
574
583 QChartPrivate::QChartPrivate(QChart *q):
575 QChartPrivate::QChartPrivate(QChart *q):
584 q_ptr(q),
576 q_ptr(q),
585 m_legend(0),
577 m_legend(0),
586 m_dataset(new ChartDataSet(q)),
578 m_dataset(new ChartDataSet(q)),
587 m_presenter(new ChartPresenter(q)),
579 m_presenter(new ChartPresenter(q)),
588 m_themeManager(new ChartThemeManager(q))
580 m_themeManager(new ChartThemeManager(q))
589 {
581 {
590 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*)));
582 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*)));
591 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*)));
583 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*)));
592 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*)));
584 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*)));
593 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*)));
585 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*)));
594 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*)));
586 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*)));
595 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*)));
587 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*)));
596 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*)));
588 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*)));
597 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*)));
589 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*)));
598 }
590 }
599
591
600 QChartPrivate::~QChartPrivate()
592 QChartPrivate::~QChartPrivate()
601 {
593 {
602
594
603 }
595 }
604
596
605 void QChartPrivate::zoomIn(qreal factor)
597 void QChartPrivate::zoomIn(qreal factor)
606 {
598 {
607 QRectF rect = m_presenter->geometry();
599 QRectF rect = m_presenter->geometry();
608 rect.setWidth(rect.width() / factor);
600 rect.setWidth(rect.width() / factor);
609 rect.setHeight(rect.height() / factor);
601 rect.setHeight(rect.height() / factor);
610 rect.moveCenter(m_presenter->geometry().center());
602 rect.moveCenter(m_presenter->geometry().center());
611 zoomIn(rect);
603 zoomIn(rect);
612 }
604 }
613
605
614 void QChartPrivate::zoomIn(const QRectF &rect)
606 void QChartPrivate::zoomIn(const QRectF &rect)
615 {
607 {
616 if (!rect.isValid())
608 if (!rect.isValid())
617 return;
609 return;
618
610
619 QRectF r = rect.normalized();
611 QRectF r = rect.normalized();
620 const QRectF geometry = m_presenter->geometry();
612 const QRectF geometry = m_presenter->geometry();
621 r.translate(-geometry.topLeft());
613 r.translate(-geometry.topLeft());
622
614
623 if (!r.isValid())
615 if (!r.isValid())
624 return;
616 return;
625
617
626 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
618 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
627 m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint);
619 m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint);
628 m_dataset->zoomInDomain(r);
620 m_dataset->zoomInDomain(r);
629 m_presenter->setState(ChartPresenter::ShowState,QPointF());
621 m_presenter->setState(ChartPresenter::ShowState,QPointF());
630
622
631 }
623 }
632
624
633 void QChartPrivate::zoomOut(qreal factor)
625 void QChartPrivate::zoomOut(qreal factor)
634 {
626 {
635 const QRectF geometry = m_presenter->geometry();
627 const QRectF geometry = m_presenter->geometry();
636
628
637 QRectF r;
629 QRectF r;
638 r.setSize(geometry.size() / factor);
630 r.setSize(geometry.size() / factor);
639 r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2));
631 r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2));
640 if (!r.isValid())
632 if (!r.isValid())
641 return;
633 return;
642
634
643 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
635 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
644 m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint);
636 m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint);
645 m_dataset->zoomOutDomain(r);
637 m_dataset->zoomOutDomain(r);
646 m_presenter->setState(ChartPresenter::ShowState,QPointF());
638 m_presenter->setState(ChartPresenter::ShowState,QPointF());
647 }
639 }
648
640
649 void QChartPrivate::scroll(qreal dx, qreal dy)
641 void QChartPrivate::scroll(qreal dx, qreal dy)
650 {
642 {
651 if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF());
643 if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF());
652 if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF());
644 if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF());
653 if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF());
645 if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF());
654 if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF());
646 if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF());
655
647
656 m_dataset->scrollDomain(dx, dy);
648 m_dataset->scrollDomain(dx, dy);
657 m_presenter->setState(ChartPresenter::ShowState,QPointF());
649 m_presenter->setState(ChartPresenter::ShowState,QPointF());
658 }
650 }
659
651
660 #include "moc_qchart.cpp"
652 #include "moc_qchart.cpp"
661
653
662 QTCOMMERCIALCHART_END_NAMESPACE
654 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now