##// END OF EJS Templates
Fixed a bug in dynamic creation of area series
Tero Ahola -
r2114:6cd0efe52042
parent child
Show More
@@ -1,727 +1,730
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 "declarativechart.h"
21 #include "declarativechart.h"
22 #include <QPainter>
22 #include <QPainter>
23 #include <QDeclarativeEngine>
23 #include <QDeclarativeEngine>
24 #include "declarativelineseries.h"
24 #include "declarativelineseries.h"
25 #include "declarativeareaseries.h"
25 #include "declarativeareaseries.h"
26 #include "declarativebarseries.h"
26 #include "declarativebarseries.h"
27 #include "declarativepieseries.h"
27 #include "declarativepieseries.h"
28 #include "declarativesplineseries.h"
28 #include "declarativesplineseries.h"
29 #include "declarativescatterseries.h"
29 #include "declarativescatterseries.h"
30 #include "qbarcategoryaxis.h"
30 #include "qbarcategoryaxis.h"
31 #include "qvalueaxis.h"
31 #include "qvalueaxis.h"
32 #include "qcategoryaxis.h"
32 #include "qcategoryaxis.h"
33 #include "qabstractseries_p.h"
33 #include "qabstractseries_p.h"
34 #include "declarativemargins.h"
34 #include "declarativemargins.h"
35 #include "qchart_p.h"
35 #include "qchart_p.h"
36
36
37 #ifndef QT_ON_ARM
37 #ifndef QT_ON_ARM
38 #include "qdatetimeaxis.h"
38 #include "qdatetimeaxis.h"
39 #endif
39 #endif
40
40
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
42
42
43 /*!
43 /*!
44 \qmlclass ChartView DeclarativeChart
44 \qmlclass ChartView DeclarativeChart
45
45
46 ChartView element is the parent that is responsible for showing different chart series types.
46 ChartView element is the parent that is responsible for showing different chart series types.
47
47
48 The following QML shows how to create a simple chart with one pie series:
48 The following QML shows how to create a simple chart with one pie series:
49 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
49 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
50 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
50 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
51 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
51 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
52
52
53 \beginfloatleft
53 \beginfloatleft
54 \image examples_qmlpiechart.png
54 \image examples_qmlpiechart.png
55 \endfloat
55 \endfloat
56 \clearfloat
56 \clearfloat
57 */
57 */
58
58
59 /*!
59 /*!
60 \qmlproperty Theme ChartView::theme
60 \qmlproperty Theme ChartView::theme
61 Theme defines the visual appearance of the chart, including for example colors, fonts, line
61 Theme defines the visual appearance of the chart, including for example colors, fonts, line
62 widths and chart background.
62 widths and chart background.
63 */
63 */
64
64
65 /*!
65 /*!
66 \qmlproperty Animation ChartView::animationOptions
66 \qmlproperty Animation ChartView::animationOptions
67 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
67 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
68 ChartView.SeriesAnimations or ChartView.AllAnimations.
68 ChartView.SeriesAnimations or ChartView.AllAnimations.
69 */
69 */
70
70
71 /*!
71 /*!
72 \qmlproperty Font ChartView::titleFont
72 \qmlproperty Font ChartView::titleFont
73 The title font of the chart
73 The title font of the chart
74
74
75 See the \l {Font} {QML Font Element} for detailed documentation.
75 See the \l {Font} {QML Font Element} for detailed documentation.
76 */
76 */
77
77
78 /*!
78 /*!
79 \qmlproperty string ChartView::title
79 \qmlproperty string ChartView::title
80 The title of the chart, shown on top of the chart.
80 The title of the chart, shown on top of the chart.
81 \sa ChartView::titleColor
81 \sa ChartView::titleColor
82 */
82 */
83
83
84 /*!
84 /*!
85 \qmlproperty color ChartView::titleColor
85 \qmlproperty color ChartView::titleColor
86 The color of the title text.
86 The color of the title text.
87 */
87 */
88
88
89 /*!
89 /*!
90 \qmlproperty Legend ChartView::legend
90 \qmlproperty Legend ChartView::legend
91 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
91 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
92 */
92 */
93
93
94 /*!
94 /*!
95 \qmlproperty int ChartView::count
95 \qmlproperty int ChartView::count
96 The count of series added to the chart.
96 The count of series added to the chart.
97 */
97 */
98
98
99 /*!
99 /*!
100 \qmlproperty color ChartView::backgroundColor
100 \qmlproperty color ChartView::backgroundColor
101 The color of the chart's background. By default background color is defined by chart theme.
101 The color of the chart's background. By default background color is defined by chart theme.
102 \sa ChartView::theme
102 \sa ChartView::theme
103 */
103 */
104
104
105 /*!
105 /*!
106 \qmlproperty bool ChartView::dropShadowEnabled
106 \qmlproperty bool ChartView::dropShadowEnabled
107 The chart's border drop shadow. Set to true to enable drop shadow.
107 The chart's border drop shadow. Set to true to enable drop shadow.
108 */
108 */
109
109
110 /*!
110 /*!
111 \qmlproperty real ChartView::topMargin
111 \qmlproperty real ChartView::topMargin
112 Deprecated. Use minimumMargins and plotArea instead.
112 Deprecated. Use minimumMargins and plotArea instead.
113 */
113 */
114
114
115 /*!
115 /*!
116 \qmlproperty real ChartView::bottomMargin
116 \qmlproperty real ChartView::bottomMargin
117 Deprecated. Use minimumMargins and plotArea instead.
117 Deprecated. Use minimumMargins and plotArea instead.
118 */
118 */
119
119
120 /*!
120 /*!
121 \qmlproperty real ChartView::leftMargin
121 \qmlproperty real ChartView::leftMargin
122 Deprecated. Use minimumMargins and plotArea instead.
122 Deprecated. Use minimumMargins and plotArea instead.
123 */
123 */
124
124
125 /*!
125 /*!
126 \qmlproperty real ChartView::rightMargin
126 \qmlproperty real ChartView::rightMargin
127 Deprecated. Use minimumMargins and plotArea instead.
127 Deprecated. Use minimumMargins and plotArea instead.
128 */
128 */
129
129
130 /*!
130 /*!
131 \qmlproperty Margins ChartView::minimumMargins
131 \qmlproperty Margins ChartView::minimumMargins
132 The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins
132 The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins
133 area of ChartView is used for drawing title, axes and legend. Please note that setting the
133 area of ChartView is used for drawing title, axes and legend. Please note that setting the
134 properties of minimumMargins may be bigger than the defined value, depending on other ChartView
134 properties of minimumMargins may be bigger than the defined value, depending on other ChartView
135 properties that affect it's layout. If you need to know the actual plotting area used at any
135 properties that affect it's layout. If you need to know the actual plotting area used at any
136 given time, you can check ChartView::plotArea instead.
136 given time, you can check ChartView::plotArea instead.
137 */
137 */
138
138
139 /*!
139 /*!
140 \qmlproperty rect ChartView::plotArea
140 \qmlproperty rect ChartView::plotArea
141 The area on the ChartView that is used for drawing series. This is the ChartView rect without the
141 The area on the ChartView that is used for drawing series. This is the ChartView rect without the
142 margins.
142 margins.
143 \sa ChartView::minimumMargins
143 \sa ChartView::minimumMargins
144 */
144 */
145
145
146 /*!
146 /*!
147 \qmlmethod AbstractSeries ChartView::series(int index)
147 \qmlmethod AbstractSeries ChartView::series(int index)
148 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
148 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
149 the count property of the chart.
149 the count property of the chart.
150 */
150 */
151
151
152 /*!
152 /*!
153 \qmlmethod AbstractSeries ChartView::series(string name)
153 \qmlmethod AbstractSeries ChartView::series(string name)
154 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
154 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
155 */
155 */
156
156
157 /*!
157 /*!
158 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY)
158 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY)
159 Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and
159 Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and
160 optional axis \a axisY. For example:
160 optional axis \a axisY. For example:
161 \code
161 \code
162 // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes
162 // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes
163 var myAxisX = chartView.axisX(lineSeries);
163 var myAxisX = chartView.axisX(lineSeries);
164 var myAxisY = chartView.axisY(lineSeries);
164 var myAxisY = chartView.axisY(lineSeries);
165 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY);
165 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY);
166 \endcode
166 \endcode
167 */
167 */
168
168
169 /*!
169 /*!
170 \qmlmethod ChartView::removeSeries(AbstractSeries series)
170 \qmlmethod ChartView::removeSeries(AbstractSeries series)
171 Removes the \a series from the chart. The series object is also destroyed.
171 Removes the \a series from the chart. The series object is also destroyed.
172 */
172 */
173
173
174 /*!
174 /*!
175 \qmlmethod ChartView::removeAllSeries()
175 \qmlmethod ChartView::removeAllSeries()
176 Removes all series from the chart. All the series objects are also destroyed.
176 Removes all series from the chart. All the series objects are also destroyed.
177 */
177 */
178
178
179 /*!
179 /*!
180 \qmlmethod Axis ChartView::axisX(AbstractSeries series)
180 \qmlmethod Axis ChartView::axisX(AbstractSeries series)
181 The x-axis of the series.
181 The x-axis of the series.
182 */
182 */
183
183
184 /*!
184 /*!
185 \qmlmethod Axis ChartView::axisY(AbstractSeries series)
185 \qmlmethod Axis ChartView::axisY(AbstractSeries series)
186 The y-axis of the series.
186 The y-axis of the series.
187 */
187 */
188
188
189 /*!
189 /*!
190 \qmlmethod ChartView::zoomY(real factor)
190 \qmlmethod ChartView::zoomY(real factor)
191 Zooms in by \a factor on the center of the chart.
191 Zooms in by \a factor on the center of the chart.
192 */
192 */
193
193
194 /*!
194 /*!
195 \qmlmethod ChartView::scrollLeft(real pixels)
195 \qmlmethod ChartView::scrollLeft(real pixels)
196 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
196 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
197 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
197 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
198 */
198 */
199
199
200 /*!
200 /*!
201 \qmlmethod ChartView::scrollRight(real pixels)
201 \qmlmethod ChartView::scrollRight(real pixels)
202 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
202 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
203 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
203 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
204 */
204 */
205
205
206 /*!
206 /*!
207 \qmlmethod ChartView::scrollUp(real pixels)
207 \qmlmethod ChartView::scrollUp(real pixels)
208 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
208 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
209 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
209 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
210 */
210 */
211
211
212 /*!
212 /*!
213 \qmlmethod ChartView::scrollDown(real pixels)
213 \qmlmethod ChartView::scrollDown(real pixels)
214 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
214 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
215 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
215 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
216 */
216 */
217
217
218 /*!
218 /*!
219 \qmlsignal ChartView::onPlotAreaChanged(rect plotArea)
219 \qmlsignal ChartView::onPlotAreaChanged(rect plotArea)
220 The plot area of the chart has changed. This may happen for example, if you modify minimumMargins
220 The plot area of the chart has changed. This may happen for example, if you modify minimumMargins
221 or if you resize the chart, or if you modify font size related properties of the legend or chart
221 or if you resize the chart, or if you modify font size related properties of the legend or chart
222 title.
222 title.
223 */
223 */
224
224
225 /*!
225 /*!
226 \qmlsignal ChartView::seriesAdded(AbstractSeries series)
226 \qmlsignal ChartView::seriesAdded(AbstractSeries series)
227 The \a series has been added to the chart.
227 The \a series has been added to the chart.
228 */
228 */
229
229
230 /*!
230 /*!
231 \qmlsignal ChartView::seriesRemoved(AbstractSeries series)
231 \qmlsignal ChartView::seriesRemoved(AbstractSeries series)
232 The \a series has been removed from the chart. Please note that \a series is no longer a valid
232 The \a series has been removed from the chart. Please note that \a series is no longer a valid
233 object after the signal handler has completed.
233 object after the signal handler has completed.
234 */
234 */
235
235
236 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
236 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
237 : QDeclarativeItem(parent),
237 : QDeclarativeItem(parent),
238 m_chart(new QChart(this))
238 m_chart(new QChart(this))
239 {
239 {
240 setFlag(QGraphicsItem::ItemHasNoContents, false);
240 setFlag(QGraphicsItem::ItemHasNoContents, false);
241 m_margins = new DeclarativeMargins(this);
241 m_margins = new DeclarativeMargins(this);
242 m_margins->setTop(m_chart->margins().top());
242 m_margins->setTop(m_chart->margins().top());
243 m_margins->setLeft(m_chart->margins().left());
243 m_margins->setLeft(m_chart->margins().left());
244 m_margins->setRight(m_chart->margins().right());
244 m_margins->setRight(m_chart->margins().right());
245 m_margins->setBottom(m_chart->margins().bottom());
245 m_margins->setBottom(m_chart->margins().bottom());
246 connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
246 connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
247 connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
247 connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
248 connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
248 connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
249 connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
249 connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
250 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), this, SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
250 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), this, SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
251 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*)));
251 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*)));
252 }
252 }
253
253
254 void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
254 void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
255 {
255 {
256 Q_UNUSED(domain)
256 Q_UNUSED(domain)
257 emit seriesAdded(series);
257 emit seriesAdded(series);
258 }
258 }
259
259
260 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
260 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
261 {
261 {
262 m_chart->setMargins(QMargins(left, top, right, bottom));
262 m_chart->setMargins(QMargins(left, top, right, bottom));
263 emit minimumMarginsChanged();
263 emit minimumMarginsChanged();
264 emit plotAreaChanged(m_chart->plotArea());
264 emit plotAreaChanged(m_chart->plotArea());
265 }
265 }
266
266
267 DeclarativeChart::~DeclarativeChart()
267 DeclarativeChart::~DeclarativeChart()
268 {
268 {
269 delete m_chart;
269 delete m_chart;
270 }
270 }
271
271
272 void DeclarativeChart::childEvent(QChildEvent *event)
272 void DeclarativeChart::childEvent(QChildEvent *event)
273 {
273 {
274 if (event->type() == QEvent::ChildAdded) {
274 if (event->type() == QEvent::ChildAdded) {
275 if (qobject_cast<QAbstractSeries *>(event->child())) {
275 if (qobject_cast<QAbstractSeries *>(event->child())) {
276 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
276 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
277 }
277 }
278 }
278 }
279 }
279 }
280
280
281 void DeclarativeChart::componentComplete()
281 void DeclarativeChart::componentComplete()
282 {
282 {
283 foreach (QObject *child, children()) {
283 foreach (QObject *child, children()) {
284 if (qobject_cast<QAbstractSeries *>(child)) {
284 if (qobject_cast<QAbstractSeries *>(child)) {
285 // Add series to the chart
285 // Add series to the chart
286 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child);
286 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child);
287 m_chart->addSeries(series);
287 m_chart->addSeries(series);
288
288
289 // Set optional user defined axes for the series and connect axis related signals
289 // Set optional user defined axes for the series and connect axis related signals
290 if (qobject_cast<DeclarativeLineSeries *>(child)) {
290 if (qobject_cast<DeclarativeLineSeries *>(child)) {
291 DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child);
291 DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child);
292 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
292 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
293 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
293 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
294 setAxisX(s->axisX(), s);
294 setAxisX(s->axisX(), s);
295 setAxisY(s->axisY(), s);
295 setAxisY(s->axisY(), s);
296 } else if (qobject_cast<DeclarativeSplineSeries *>(child)) {
296 } else if (qobject_cast<DeclarativeSplineSeries *>(child)) {
297 DeclarativeSplineSeries *s = qobject_cast<DeclarativeSplineSeries *>(child);
297 DeclarativeSplineSeries *s = qobject_cast<DeclarativeSplineSeries *>(child);
298 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
298 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
299 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
299 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
300 setAxisX(s->axisX(), s);
300 setAxisX(s->axisX(), s);
301 setAxisY(s->axisY(), s);
301 setAxisY(s->axisY(), s);
302 } else if (qobject_cast<DeclarativeScatterSeries *>(child)) {
302 } else if (qobject_cast<DeclarativeScatterSeries *>(child)) {
303 DeclarativeScatterSeries *s = qobject_cast<DeclarativeScatterSeries *>(child);
303 DeclarativeScatterSeries *s = qobject_cast<DeclarativeScatterSeries *>(child);
304 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
304 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
305 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
305 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
306 setAxisX(s->axisX(), s);
306 setAxisX(s->axisX(), s);
307 setAxisY(s->axisY(), s);
307 setAxisY(s->axisY(), s);
308 } else if (qobject_cast<DeclarativeAreaSeries *>(child)) {
308 } else if (qobject_cast<DeclarativeAreaSeries *>(child)) {
309 DeclarativeAreaSeries *s = qobject_cast<DeclarativeAreaSeries *>(child);
309 DeclarativeAreaSeries *s = qobject_cast<DeclarativeAreaSeries *>(child);
310 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
310 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
311 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
311 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
312 setAxisX(s->axisX(), s);
312 setAxisX(s->axisX(), s);
313 setAxisY(s->axisY(), s);
313 setAxisY(s->axisY(), s);
314 } else if (qobject_cast<DeclarativeBarSeries *>(child)) {
314 } else if (qobject_cast<DeclarativeBarSeries *>(child)) {
315 DeclarativeBarSeries *s = qobject_cast<DeclarativeBarSeries *>(child);
315 DeclarativeBarSeries *s = qobject_cast<DeclarativeBarSeries *>(child);
316 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
316 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
317 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
317 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
318 setAxisX(s->axisX(), s);
318 setAxisX(s->axisX(), s);
319 setAxisY(s->axisY(), s);
319 setAxisY(s->axisY(), s);
320 } else if (qobject_cast<DeclarativeStackedBarSeries *>(child)) {
320 } else if (qobject_cast<DeclarativeStackedBarSeries *>(child)) {
321 DeclarativeStackedBarSeries *s = qobject_cast<DeclarativeStackedBarSeries *>(child);
321 DeclarativeStackedBarSeries *s = qobject_cast<DeclarativeStackedBarSeries *>(child);
322 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
322 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
323 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
323 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
324 setAxisX(s->axisX(), s);
324 setAxisX(s->axisX(), s);
325 setAxisY(s->axisY(), s);
325 setAxisY(s->axisY(), s);
326 } else if (qobject_cast<DeclarativePercentBarSeries *>(child)) {
326 } else if (qobject_cast<DeclarativePercentBarSeries *>(child)) {
327 DeclarativePercentBarSeries *s = qobject_cast<DeclarativePercentBarSeries *>(child);
327 DeclarativePercentBarSeries *s = qobject_cast<DeclarativePercentBarSeries *>(child);
328 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
328 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
329 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
329 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
330 setAxisX(s->axisX(), s);
330 setAxisX(s->axisX(), s);
331 setAxisY(s->axisY(), s);
331 setAxisY(s->axisY(), s);
332 } else if (qobject_cast<DeclarativeHorizontalBarSeries *>(child)) {
332 } else if (qobject_cast<DeclarativeHorizontalBarSeries *>(child)) {
333 DeclarativeHorizontalBarSeries *s = qobject_cast<DeclarativeHorizontalBarSeries *>(child);
333 DeclarativeHorizontalBarSeries *s = qobject_cast<DeclarativeHorizontalBarSeries *>(child);
334 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
334 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
335 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
335 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
336 setAxisX(s->axisX(), s);
336 setAxisX(s->axisX(), s);
337 setAxisY(s->axisY(), s);
337 setAxisY(s->axisY(), s);
338 } else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child)) {
338 } else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child)) {
339 DeclarativeHorizontalStackedBarSeries *s = qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child);
339 DeclarativeHorizontalStackedBarSeries *s = qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child);
340 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
340 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
341 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
341 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
342 setAxisX(s->axisX(), s);
342 setAxisX(s->axisX(), s);
343 setAxisY(s->axisY(), s);
343 setAxisY(s->axisY(), s);
344 } else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child)) {
344 } else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child)) {
345 DeclarativeHorizontalPercentBarSeries *s = qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child);
345 DeclarativeHorizontalPercentBarSeries *s = qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child);
346 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
346 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
347 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
347 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
348 setAxisX(s->axisX(), s);
348 setAxisX(s->axisX(), s);
349 setAxisY(s->axisY(), s);
349 setAxisY(s->axisY(), s);
350 }
350 }
351 }
351 }
352 }
352 }
353
353
354 // Create the missing axes for the series that cannot be painted without axes
354 // Create the missing axes for the series that cannot be painted without axes
355 foreach (QAbstractSeries *chartSeries, m_chart->series())
355 foreach (QAbstractSeries *chartSeries, m_chart->series())
356 createDefaultAxes(chartSeries);
356 createDefaultAxes(chartSeries);
357
357
358 QDeclarativeItem::componentComplete();
358 QDeclarativeItem::componentComplete();
359 }
359 }
360
360
361 void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis)
361 void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis)
362 {
362 {
363 // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis;
363 // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis;
364 if (axis && qobject_cast<QAbstractSeries *>(sender()))
364 if (axis && qobject_cast<QAbstractSeries *>(sender()))
365 m_chart->setAxisX(axis, qobject_cast<QAbstractSeries *>(sender()));
365 m_chart->setAxisX(axis, qobject_cast<QAbstractSeries *>(sender()));
366 else
366 else
367 qWarning() << "Trying to set axisX to null.";
367 qWarning() << "Trying to set axisX to null.";
368 }
368 }
369
369
370 void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis)
370 void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis)
371 {
371 {
372 // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis;
372 // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis;
373 if (axis && qobject_cast<QAbstractSeries *>(sender()))
373 if (axis && qobject_cast<QAbstractSeries *>(sender()))
374 m_chart->setAxisY(axis, qobject_cast<QAbstractSeries *>(sender()));
374 m_chart->setAxisY(axis, qobject_cast<QAbstractSeries *>(sender()));
375 else
375 else
376 qWarning() << "Trying to set axisY to null.";
376 qWarning() << "Trying to set axisY to null.";
377 }
377 }
378
378
379 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
379 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
380 {
380 {
381 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
381 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
382 if (newGeometry.isValid()) {
382 if (newGeometry.isValid()) {
383 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
383 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
384 m_chart->resize(newGeometry.width(), newGeometry.height());
384 m_chart->resize(newGeometry.width(), newGeometry.height());
385 }
385 }
386 }
386 }
387 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
387 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
388
388
389 // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or
389 // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or
390 // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is
390 // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is
391 // to implement it here for the QML API purposes.
391 // to implement it here for the QML API purposes.
392 emit plotAreaChanged(m_chart->plotArea());
392 emit plotAreaChanged(m_chart->plotArea());
393 }
393 }
394
394
395 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
395 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
396 {
396 {
397 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
397 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
398 if (chartTheme != m_chart->theme())
398 if (chartTheme != m_chart->theme())
399 m_chart->setTheme(chartTheme);
399 m_chart->setTheme(chartTheme);
400 }
400 }
401
401
402 DeclarativeChart::Theme DeclarativeChart::theme()
402 DeclarativeChart::Theme DeclarativeChart::theme()
403 {
403 {
404 return (DeclarativeChart::Theme) m_chart->theme();
404 return (DeclarativeChart::Theme) m_chart->theme();
405 }
405 }
406
406
407 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
407 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
408 {
408 {
409 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
409 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
410 if (animationOptions != m_chart->animationOptions())
410 if (animationOptions != m_chart->animationOptions())
411 m_chart->setAnimationOptions(animationOptions);
411 m_chart->setAnimationOptions(animationOptions);
412 }
412 }
413
413
414 DeclarativeChart::Animation DeclarativeChart::animationOptions()
414 DeclarativeChart::Animation DeclarativeChart::animationOptions()
415 {
415 {
416 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
416 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
417 return DeclarativeChart::AllAnimations;
417 return DeclarativeChart::AllAnimations;
418 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
418 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
419 return DeclarativeChart::GridAxisAnimations;
419 return DeclarativeChart::GridAxisAnimations;
420 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
420 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
421 return DeclarativeChart::SeriesAnimations;
421 return DeclarativeChart::SeriesAnimations;
422 else
422 else
423 return DeclarativeChart::NoAnimation;
423 return DeclarativeChart::NoAnimation;
424 }
424 }
425
425
426 void DeclarativeChart::setTitle(QString title)
426 void DeclarativeChart::setTitle(QString title)
427 {
427 {
428 if (title != m_chart->title())
428 if (title != m_chart->title())
429 m_chart->setTitle(title);
429 m_chart->setTitle(title);
430 }
430 }
431 QString DeclarativeChart::title()
431 QString DeclarativeChart::title()
432 {
432 {
433 return m_chart->title();
433 return m_chart->title();
434 }
434 }
435
435
436 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
436 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
437 {
437 {
438 return m_chart->axisX(series);
438 return m_chart->axisX(series);
439 }
439 }
440
440
441 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
441 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
442 {
442 {
443 return m_chart->axisY(series);
443 return m_chart->axisY(series);
444 }
444 }
445
445
446 QLegend *DeclarativeChart::legend()
446 QLegend *DeclarativeChart::legend()
447 {
447 {
448 return m_chart->legend();
448 return m_chart->legend();
449 }
449 }
450
450
451 void DeclarativeChart::setTitleColor(QColor color)
451 void DeclarativeChart::setTitleColor(QColor color)
452 {
452 {
453 QBrush b = m_chart->titleBrush();
453 QBrush b = m_chart->titleBrush();
454 if (color != b.color()) {
454 if (color != b.color()) {
455 b.setColor(color);
455 b.setColor(color);
456 m_chart->setTitleBrush(b);
456 m_chart->setTitleBrush(b);
457 emit titleColorChanged(color);
457 emit titleColorChanged(color);
458 }
458 }
459 }
459 }
460
460
461 QFont DeclarativeChart::titleFont() const
461 QFont DeclarativeChart::titleFont() const
462 {
462 {
463 return m_chart->titleFont();
463 return m_chart->titleFont();
464 }
464 }
465
465
466 void DeclarativeChart::setTitleFont(const QFont &font)
466 void DeclarativeChart::setTitleFont(const QFont &font)
467 {
467 {
468 m_chart->setTitleFont(font);
468 m_chart->setTitleFont(font);
469 }
469 }
470
470
471 QColor DeclarativeChart::titleColor()
471 QColor DeclarativeChart::titleColor()
472 {
472 {
473 return m_chart->titleBrush().color();
473 return m_chart->titleBrush().color();
474 }
474 }
475
475
476 void DeclarativeChart::setBackgroundColor(QColor color)
476 void DeclarativeChart::setBackgroundColor(QColor color)
477 {
477 {
478 QBrush b = m_chart->backgroundBrush();
478 QBrush b = m_chart->backgroundBrush();
479 if (b.style() != Qt::SolidPattern || color != b.color()) {
479 if (b.style() != Qt::SolidPattern || color != b.color()) {
480 b.setStyle(Qt::SolidPattern);
480 b.setStyle(Qt::SolidPattern);
481 b.setColor(color);
481 b.setColor(color);
482 m_chart->setBackgroundBrush(b);
482 m_chart->setBackgroundBrush(b);
483 emit backgroundColorChanged();
483 emit backgroundColorChanged();
484 }
484 }
485 }
485 }
486
486
487 QColor DeclarativeChart::backgroundColor()
487 QColor DeclarativeChart::backgroundColor()
488 {
488 {
489 return m_chart->backgroundBrush().color();
489 return m_chart->backgroundBrush().color();
490 }
490 }
491
491
492 int DeclarativeChart::count()
492 int DeclarativeChart::count()
493 {
493 {
494 return m_chart->series().count();
494 return m_chart->series().count();
495 }
495 }
496
496
497 void DeclarativeChart::setDropShadowEnabled(bool enabled)
497 void DeclarativeChart::setDropShadowEnabled(bool enabled)
498 {
498 {
499 if (enabled != m_chart->isDropShadowEnabled()) {
499 if (enabled != m_chart->isDropShadowEnabled()) {
500 m_chart->setDropShadowEnabled(enabled);
500 m_chart->setDropShadowEnabled(enabled);
501 dropShadowEnabledChanged(enabled);
501 dropShadowEnabledChanged(enabled);
502 }
502 }
503 }
503 }
504
504
505 bool DeclarativeChart::dropShadowEnabled()
505 bool DeclarativeChart::dropShadowEnabled()
506 {
506 {
507 return m_chart->isDropShadowEnabled();
507 return m_chart->isDropShadowEnabled();
508 }
508 }
509
509
510 qreal DeclarativeChart::topMargin()
510 qreal DeclarativeChart::topMargin()
511 {
511 {
512 qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead.";
512 qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead.";
513 return m_chart->plotArea().top();
513 return m_chart->plotArea().top();
514 }
514 }
515
515
516 qreal DeclarativeChart::bottomMargin()
516 qreal DeclarativeChart::bottomMargin()
517 {
517 {
518
518
519 qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead.";
519 qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead.";
520 return m_chart->plotArea().bottom();
520 return m_chart->plotArea().bottom();
521 }
521 }
522
522
523 qreal DeclarativeChart::leftMargin()
523 qreal DeclarativeChart::leftMargin()
524 {
524 {
525 qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead.";
525 qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead.";
526 return m_chart->plotArea().left();
526 return m_chart->plotArea().left();
527 }
527 }
528
528
529 qreal DeclarativeChart::rightMargin()
529 qreal DeclarativeChart::rightMargin()
530 {
530 {
531 qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead.";
531 qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead.";
532 return m_chart->plotArea().right();
532 return m_chart->plotArea().right();
533 }
533 }
534
534
535 void DeclarativeChart::zoom(qreal factor)
535 void DeclarativeChart::zoom(qreal factor)
536 {
536 {
537 m_chart->zoom(factor);
537 m_chart->zoom(factor);
538 }
538 }
539
539
540 void DeclarativeChart::scrollLeft(qreal pixels)
540 void DeclarativeChart::scrollLeft(qreal pixels)
541 {
541 {
542 m_chart->scroll(-pixels, 0);
542 m_chart->scroll(-pixels, 0);
543 }
543 }
544
544
545 void DeclarativeChart::scrollRight(qreal pixels)
545 void DeclarativeChart::scrollRight(qreal pixels)
546 {
546 {
547 m_chart->scroll(pixels, 0);
547 m_chart->scroll(pixels, 0);
548 }
548 }
549
549
550 void DeclarativeChart::scrollUp(qreal pixels)
550 void DeclarativeChart::scrollUp(qreal pixels)
551 {
551 {
552 m_chart->scroll(0, pixels);
552 m_chart->scroll(0, pixels);
553 }
553 }
554
554
555 void DeclarativeChart::scrollDown(qreal pixels)
555 void DeclarativeChart::scrollDown(qreal pixels)
556 {
556 {
557 m_chart->scroll(0, -pixels);
557 m_chart->scroll(0, -pixels);
558 }
558 }
559
559
560 QAbstractSeries *DeclarativeChart::series(int index)
560 QAbstractSeries *DeclarativeChart::series(int index)
561 {
561 {
562 if (index < m_chart->series().count()) {
562 if (index < m_chart->series().count()) {
563 return m_chart->series().at(index);
563 return m_chart->series().at(index);
564 }
564 }
565 return 0;
565 return 0;
566 }
566 }
567
567
568 QAbstractSeries *DeclarativeChart::series(QString seriesName)
568 QAbstractSeries *DeclarativeChart::series(QString seriesName)
569 {
569 {
570 foreach (QAbstractSeries *series, m_chart->series()) {
570 foreach (QAbstractSeries *series, m_chart->series()) {
571 if (series->name() == seriesName)
571 if (series->name() == seriesName)
572 return series;
572 return series;
573 }
573 }
574 return 0;
574 return 0;
575 }
575 }
576
576
577 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
577 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
578 {
578 {
579 return createSeries(type, name, 0, 0);
579 return createSeries(type, name, 0, 0);
580 }
580 }
581
581
582 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY)
582 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY)
583 {
583 {
584 QAbstractSeries *series = 0;
584 QAbstractSeries *series = 0;
585
585
586 switch (type) {
586 switch (type) {
587 case DeclarativeChart::SeriesTypeLine:
587 case DeclarativeChart::SeriesTypeLine:
588 series = new DeclarativeLineSeries();
588 series = new DeclarativeLineSeries();
589 break;
589 break;
590 case DeclarativeChart::SeriesTypeArea:
590 case DeclarativeChart::SeriesTypeArea: {
591 series = new DeclarativeAreaSeries();
591 DeclarativeAreaSeries *area = new DeclarativeAreaSeries();
592 area->setUpperSeries(new DeclarativeLineSeries());
593 series = area;
592 break;
594 break;
595 }
593 case DeclarativeChart::SeriesTypeStackedBar:
596 case DeclarativeChart::SeriesTypeStackedBar:
594 series = new DeclarativeStackedBarSeries();
597 series = new DeclarativeStackedBarSeries();
595 break;
598 break;
596 case DeclarativeChart::SeriesTypePercentBar:
599 case DeclarativeChart::SeriesTypePercentBar:
597 series = new DeclarativePercentBarSeries();
600 series = new DeclarativePercentBarSeries();
598 break;
601 break;
599 case DeclarativeChart::SeriesTypeBar:
602 case DeclarativeChart::SeriesTypeBar:
600 series = new DeclarativeBarSeries();
603 series = new DeclarativeBarSeries();
601 break;
604 break;
602 case DeclarativeChart::SeriesTypeHorizontalBar:
605 case DeclarativeChart::SeriesTypeHorizontalBar:
603 series = new DeclarativeHorizontalBarSeries();
606 series = new DeclarativeHorizontalBarSeries();
604 break;
607 break;
605 case DeclarativeChart::SeriesTypeHorizontalPercentBar:
608 case DeclarativeChart::SeriesTypeHorizontalPercentBar:
606 series = new DeclarativeHorizontalPercentBarSeries();
609 series = new DeclarativeHorizontalPercentBarSeries();
607 break;
610 break;
608 case DeclarativeChart::SeriesTypeHorizontalStackedBar:
611 case DeclarativeChart::SeriesTypeHorizontalStackedBar:
609 series = new DeclarativeHorizontalStackedBarSeries();
612 series = new DeclarativeHorizontalStackedBarSeries();
610 break;
613 break;
611 case DeclarativeChart::SeriesTypePie:
614 case DeclarativeChart::SeriesTypePie:
612 series = new DeclarativePieSeries();
615 series = new DeclarativePieSeries();
613 break;
616 break;
614 case DeclarativeChart::SeriesTypeScatter:
617 case DeclarativeChart::SeriesTypeScatter:
615 series = new DeclarativeScatterSeries();
618 series = new DeclarativeScatterSeries();
616 break;
619 break;
617 case DeclarativeChart::SeriesTypeSpline:
620 case DeclarativeChart::SeriesTypeSpline:
618 series = new DeclarativeSplineSeries();
621 series = new DeclarativeSplineSeries();
619 break;
622 break;
620 default:
623 default:
621 qWarning() << "Illegal series type";
624 qWarning() << "Illegal series type";
622 }
625 }
623
626
624 if (series) {
627 if (series) {
625 series->setName(name);
628 series->setName(name);
626 m_chart->addSeries(series);
629 m_chart->addSeries(series);
627 // Set possible user defined axes
630 // Set possible user defined axes
628 setAxisX(axisX, series);
631 setAxisX(axisX, series);
629 setAxisY(axisY, series);
632 setAxisY(axisY, series);
630 // Then create the missing axes
633 // Then create the missing axes
631 createDefaultAxes(series);
634 createDefaultAxes(series);
632 }
635 }
633
636
634 return series;
637 return series;
635 }
638 }
636
639
637 void DeclarativeChart::removeSeries(QAbstractSeries *series)
640 void DeclarativeChart::removeSeries(QAbstractSeries *series)
638 {
641 {
639 if (series)
642 if (series)
640 m_chart->removeSeries(series);
643 m_chart->removeSeries(series);
641 else
644 else
642 qWarning("removeSeries: cannot remove null");
645 qWarning("removeSeries: cannot remove null");
643 }
646 }
644
647
645 void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series)
648 void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series)
646 {
649 {
647 if (axis)
650 if (axis)
648 m_chart->setAxisX(axis, series);
651 m_chart->setAxisX(axis, series);
649 }
652 }
650
653
651 void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series)
654 void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series)
652 {
655 {
653 if (axis)
656 if (axis)
654 m_chart->setAxisY(axis, series);
657 m_chart->setAxisY(axis, series);
655 }
658 }
656
659
657 void DeclarativeChart::createDefaultAxes()
660 void DeclarativeChart::createDefaultAxes()
658 {
661 {
659 qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically.";
662 qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically.";
660 }
663 }
661
664
662 void DeclarativeChart::createDefaultAxes(QAbstractSeries *series)
665 void DeclarativeChart::createDefaultAxes(QAbstractSeries *series)
663 {
666 {
664 foreach (QAbstractSeries *s, m_chart->series()) {
667 foreach (QAbstractSeries *s, m_chart->series()) {
665 // If there is already an x axis of the correct type, re-use it
668 // If there is already an x axis of the correct type, re-use it
666 if (!m_chart->axisX(series) && s != series && m_chart->axisX(s)
669 if (!m_chart->axisX(series) && s != series && m_chart->axisX(s)
667 && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal))
670 && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal))
668 m_chart->setAxisX(m_chart->axisX(s), series);
671 m_chart->setAxisX(m_chart->axisX(s), series);
669
672
670 // If there is already a y axis of the correct type, re-use it
673 // If there is already a y axis of the correct type, re-use it
671 if (!m_chart->axisY(series) && s != series && m_chart->axisY(s)
674 if (!m_chart->axisY(series) && s != series && m_chart->axisY(s)
672 && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical))
675 && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical))
673 m_chart->setAxisY(m_chart->axisY(s), series);
676 m_chart->setAxisY(m_chart->axisY(s), series);
674 }
677 }
675
678
676 // If no x axis of correct type was found, create a new x axis based of default axis type
679 // If no x axis of correct type was found, create a new x axis based of default axis type
677 if (!m_chart->axisX(series)) {
680 if (!m_chart->axisX(series)) {
678 switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) {
681 switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) {
679 case QAbstractAxis::AxisTypeValue:
682 case QAbstractAxis::AxisTypeValue:
680 m_chart->setAxisX(new QValueAxis(this), series);
683 m_chart->setAxisX(new QValueAxis(this), series);
681 break;
684 break;
682 case QAbstractAxis::AxisTypeBarCategory:
685 case QAbstractAxis::AxisTypeBarCategory:
683 m_chart->setAxisX(new QBarCategoryAxis(this), series);
686 m_chart->setAxisX(new QBarCategoryAxis(this), series);
684 break;
687 break;
685 case QAbstractAxis::AxisTypeCategory:
688 case QAbstractAxis::AxisTypeCategory:
686 m_chart->setAxisX(new QCategoryAxis(this), series);
689 m_chart->setAxisX(new QCategoryAxis(this), series);
687 break;
690 break;
688 #ifndef QT_ON_ARM
691 #ifndef QT_ON_ARM
689 case QAbstractAxis::AxisTypeDateTime:
692 case QAbstractAxis::AxisTypeDateTime:
690 m_chart->setAxisX(new QDateTimeAxis(this), series);
693 m_chart->setAxisX(new QDateTimeAxis(this), series);
691 break;
694 break;
692 #endif
695 #endif
693 default:
696 default:
694 // Do nothing, assume AxisTypeNoAxis
697 // Do nothing, assume AxisTypeNoAxis
695 break;
698 break;
696 }
699 }
697 }
700 }
698
701
699 // If no y axis of correct type was found, create a new y axis based of default axis type
702 // If no y axis of correct type was found, create a new y axis based of default axis type
700 if (!m_chart->axisY(series)) {
703 if (!m_chart->axisY(series)) {
701 switch (series->d_ptr->defaultAxisType(Qt::Vertical)) {
704 switch (series->d_ptr->defaultAxisType(Qt::Vertical)) {
702 case QAbstractAxis::AxisTypeValue:
705 case QAbstractAxis::AxisTypeValue:
703 m_chart->setAxisY(new QValueAxis(this), series);
706 m_chart->setAxisY(new QValueAxis(this), series);
704 break;
707 break;
705 case QAbstractAxis::AxisTypeBarCategory:
708 case QAbstractAxis::AxisTypeBarCategory:
706 m_chart->setAxisY(new QBarCategoryAxis(this), series);
709 m_chart->setAxisY(new QBarCategoryAxis(this), series);
707 break;
710 break;
708 case QAbstractAxis::AxisTypeCategory:
711 case QAbstractAxis::AxisTypeCategory:
709 m_chart->setAxisY(new QCategoryAxis(this), series);
712 m_chart->setAxisY(new QCategoryAxis(this), series);
710 break;
713 break;
711 #ifndef QT_ON_ARM
714 #ifndef QT_ON_ARM
712 case QAbstractAxis::AxisTypeDateTime:
715 case QAbstractAxis::AxisTypeDateTime:
713 m_chart->setAxisY(new QDateTimeAxis(this), series);
716 m_chart->setAxisY(new QDateTimeAxis(this), series);
714 break;
717 break;
715 #endif
718 #endif
716 default:
719 default:
717 // Do nothing, assume AxisTypeNoAxis
720 // Do nothing, assume AxisTypeNoAxis
718 break;
721 break;
719 }
722 }
720 }
723 }
721
724
722 //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series);
725 //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series);
723 }
726 }
724
727
725 #include "moc_declarativechart.cpp"
728 #include "moc_declarativechart.cpp"
726
729
727 QTCOMMERCIALCHART_END_NAMESPACE
730 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now