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