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