##// END OF EJS Templates
Fix another memory leak....
Miikka Heikkinen -
r2735:7d77c52a3f95
parent child
Show More
@@ -1,1057 +1,1059
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 <QtGui/QPainter>
22 #include <QtGui/QPainter>
23 #include "declarativelineseries.h"
23 #include "declarativelineseries.h"
24 #include "declarativeareaseries.h"
24 #include "declarativeareaseries.h"
25 #include "declarativebarseries.h"
25 #include "declarativebarseries.h"
26 #include "declarativepieseries.h"
26 #include "declarativepieseries.h"
27 #include "declarativesplineseries.h"
27 #include "declarativesplineseries.h"
28 #include "declarativeboxplotseries.h"
28 #include "declarativeboxplotseries.h"
29 #include "declarativescatterseries.h"
29 #include "declarativescatterseries.h"
30 #include <QtCharts/QBarCategoryAxis>
30 #include <QtCharts/QBarCategoryAxis>
31 #include <QtCharts/QValueAxis>
31 #include <QtCharts/QValueAxis>
32 #include <QtCharts/QLogValueAxis>
32 #include <QtCharts/QLogValueAxis>
33 #include <QtCharts/QCategoryAxis>
33 #include <QtCharts/QCategoryAxis>
34 #include <private/qabstractseries_p.h>
34 #include <private/qabstractseries_p.h>
35 #include "declarativemargins.h"
35 #include "declarativemargins.h"
36 #include <private/chartdataset_p.h>
36 #include <private/chartdataset_p.h>
37 #include "declarativeaxes.h"
37 #include "declarativeaxes.h"
38 #include <private/qchart_p.h>
38 #include <private/qchart_p.h>
39 #include <QtCharts/QPolarChart>
39 #include <QtCharts/QPolarChart>
40
40
41 #ifndef QT_ON_ARM
41 #ifndef QT_ON_ARM
42 #include <QtCharts/QDateTimeAxis>
42 #include <QtCharts/QDateTimeAxis>
43 #endif
43 #endif
44
44
45 #include <QtWidgets/QGraphicsSceneMouseEvent>
45 #include <QtWidgets/QGraphicsSceneMouseEvent>
46 #include <QtWidgets/QGraphicsSceneHoverEvent>
46 #include <QtWidgets/QGraphicsSceneHoverEvent>
47 #include <QtWidgets/QApplication>
47 #include <QtWidgets/QApplication>
48 #include <QtCore/QTimer>
48 #include <QtCore/QTimer>
49 #include <QtCore/QThread>
49 #include <QtCore/QThread>
50
50
51 QT_CHARTS_BEGIN_NAMESPACE
51 QT_CHARTS_BEGIN_NAMESPACE
52
52
53 /*!
53 /*!
54 \qmltype ChartView
54 \qmltype ChartView
55 \instantiates DeclarativeChart
55 \instantiates DeclarativeChart
56 \inqmlmodule QtCharts
56 \inqmlmodule QtCharts
57
57
58 \brief Chart element.
58 \brief Chart element.
59
59
60 ChartView element is the parent that is responsible for showing different chart series types.
60 ChartView element is the parent that is responsible for showing different chart series types.
61
61
62 The following QML shows how to create a simple chart with one pie series:
62 The following QML shows how to create a simple chart with one pie series:
63 \snippet qmlpiechart/qml/qmlpiechart/main.qml 1
63 \snippet qmlpiechart/qml/qmlpiechart/main.qml 1
64 \snippet qmlpiechart/qml/qmlpiechart/main.qml 2
64 \snippet qmlpiechart/qml/qmlpiechart/main.qml 2
65 \snippet qmlpiechart/qml/qmlpiechart/main.qml 3
65 \snippet qmlpiechart/qml/qmlpiechart/main.qml 3
66
66
67 \beginfloatleft
67 \beginfloatleft
68 \image examples_qmlpiechart.png
68 \image examples_qmlpiechart.png
69 \endfloat
69 \endfloat
70 \clearfloat
70 \clearfloat
71 */
71 */
72
72
73 /*!
73 /*!
74 \qmlproperty Theme ChartView::theme
74 \qmlproperty Theme ChartView::theme
75 Theme defines the visual appearance of the chart, including for example colors, fonts, line
75 Theme defines the visual appearance of the chart, including for example colors, fonts, line
76 widths and chart background.
76 widths and chart background.
77 */
77 */
78
78
79 /*!
79 /*!
80 \qmlproperty Animation ChartView::animationOptions
80 \qmlproperty Animation ChartView::animationOptions
81 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
81 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
82 ChartView.SeriesAnimations or ChartView.AllAnimations.
82 ChartView.SeriesAnimations or ChartView.AllAnimations.
83 */
83 */
84
84
85 /*!
85 /*!
86 \qmlproperty Font ChartView::titleFont
86 \qmlproperty Font ChartView::titleFont
87 The title font of the chart.
87 The title font of the chart.
88
88
89 See the Qt documentation for more details of Font.
89 See the Qt documentation for more details of Font.
90 */
90 */
91
91
92 /*!
92 /*!
93 \qmlproperty string ChartView::title
93 \qmlproperty string ChartView::title
94 The title of the chart, shown on top of the chart.
94 The title of the chart, shown on top of the chart.
95 \sa ChartView::titleColor
95 \sa ChartView::titleColor
96 */
96 */
97
97
98 /*!
98 /*!
99 \qmlproperty color ChartView::titleColor
99 \qmlproperty color ChartView::titleColor
100 The color of the title text.
100 The color of the title text.
101 */
101 */
102
102
103 /*!
103 /*!
104 \qmlproperty Legend ChartView::legend
104 \qmlproperty Legend ChartView::legend
105 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
105 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
106 */
106 */
107
107
108 /*!
108 /*!
109 \qmlproperty int ChartView::count
109 \qmlproperty int ChartView::count
110 The count of series added to the chart.
110 The count of series added to the chart.
111 */
111 */
112
112
113 /*!
113 /*!
114 \qmlproperty color ChartView::backgroundColor
114 \qmlproperty color ChartView::backgroundColor
115 The color of the chart's background. By default background color is defined by chart theme.
115 The color of the chart's background. By default background color is defined by chart theme.
116 \sa ChartView::theme
116 \sa ChartView::theme
117 */
117 */
118
118
119 /*!
119 /*!
120 \qmlproperty real ChartView::backgroundRoundness
120 \qmlproperty real ChartView::backgroundRoundness
121 The diameter of the rounding cirle at the corners of the chart background.
121 The diameter of the rounding cirle at the corners of the chart background.
122 */
122 */
123
123
124 /*!
124 /*!
125 \qmlproperty color ChartView::plotAreaColor
125 \qmlproperty color ChartView::plotAreaColor
126 The color of the background of the chart's plot area. By default plot area background uses chart's
126 The color of the background of the chart's plot area. By default plot area background uses chart's
127 background color.
127 background color.
128 \sa ChartView::backgroundColor
128 \sa ChartView::backgroundColor
129 */
129 */
130
130
131 /*!
131 /*!
132 \qmlproperty bool ChartView::dropShadowEnabled
132 \qmlproperty bool ChartView::dropShadowEnabled
133 The chart's border drop shadow. Set to true to enable drop shadow.
133 The chart's border drop shadow. Set to true to enable drop shadow.
134 */
134 */
135
135
136 /*!
136 /*!
137 \qmlproperty real ChartView::topMargin
137 \qmlproperty real ChartView::topMargin
138 Deprecated; use margins instead.
138 Deprecated; use margins instead.
139 */
139 */
140
140
141 /*!
141 /*!
142 \qmlproperty real ChartView::bottomMargin
142 \qmlproperty real ChartView::bottomMargin
143 Deprecated; use margins instead.
143 Deprecated; use margins instead.
144 */
144 */
145
145
146 /*!
146 /*!
147 \qmlproperty real ChartView::leftMargin
147 \qmlproperty real ChartView::leftMargin
148 Deprecated; use margins instead.
148 Deprecated; use margins instead.
149 */
149 */
150
150
151 /*!
151 /*!
152 \qmlproperty real ChartView::rightMargin
152 \qmlproperty real ChartView::rightMargin
153 Deprecated; use margins instead.
153 Deprecated; use margins instead.
154 */
154 */
155
155
156 /*!
156 /*!
157 \qmlproperty Margins ChartView::minimumMargins
157 \qmlproperty Margins ChartView::minimumMargins
158 Deprecated; use margins instead.
158 Deprecated; use margins instead.
159 The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins
159 The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins
160 area of ChartView is used for drawing title, axes and legend. Please note that setting the
160 area of ChartView is used for drawing title, axes and legend. Please note that setting the
161 properties of minimumMargins may be bigger than the defined value, depending on other ChartView
161 properties of minimumMargins may be bigger than the defined value, depending on other ChartView
162 properties that affect it's layout. If you need to know the actual plotting area used at any
162 properties that affect it's layout. If you need to know the actual plotting area used at any
163 given time, you can check ChartView::plotArea instead.
163 given time, you can check ChartView::plotArea instead.
164 */
164 */
165
165
166 /*!
166 /*!
167 \qmlproperty rect ChartView::plotArea
167 \qmlproperty rect ChartView::plotArea
168 The area on the ChartView that is used for drawing series. This is the ChartView rect without the
168 The area on the ChartView that is used for drawing series. This is the ChartView rect without the
169 margins.
169 margins.
170 \sa ChartView::minimumMargins
170 \sa ChartView::minimumMargins
171 */
171 */
172
172
173 /*!
173 /*!
174 \qmlproperty Margins ChartView::margins
174 \qmlproperty Margins ChartView::margins
175 The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins
175 The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins
176 area of ChartView is used for drawing title, axes and legend.
176 area of ChartView is used for drawing title, axes and legend.
177 */
177 */
178
178
179 /*!
179 /*!
180 \qmlproperty bool ChartView::localizeNumbers
180 \qmlproperty bool ChartView::localizeNumbers
181 \since QtCharts 2.0
181 \since QtCharts 2.0
182 When \c{true}, all generated numbers appearing in various series and axis labels will be
182 When \c{true}, all generated numbers appearing in various series and axis labels will be
183 localized using the default QLocale of the application, which defaults to the system locale.
183 localized using the default QLocale of the application, which defaults to the system locale.
184 When \c{false}, the "C" locale is always used.
184 When \c{false}, the "C" locale is always used.
185 Defaults to \c{false}.
185 Defaults to \c{false}.
186
186
187 \sa locale
187 \sa locale
188 */
188 */
189
189
190 /*!
190 /*!
191 \qmlproperty locale ChartView::locale
191 \qmlproperty locale ChartView::locale
192 \since QtCharts 2.0
192 \since QtCharts 2.0
193 Sets the locale used to format various chart labels when localizeNumbers is \c{true}.
193 Sets the locale used to format various chart labels when localizeNumbers is \c{true}.
194 This also determines the locale used to format DateTimeAxis labels regardless of
194 This also determines the locale used to format DateTimeAxis labels regardless of
195 localizeNumbers property.
195 localizeNumbers property.
196 Defaults to application default locale at the time the chart is constructed.
196 Defaults to application default locale at the time the chart is constructed.
197
197
198 \sa localizeNumbers
198 \sa localizeNumbers
199 */
199 */
200
200
201 /*!
201 /*!
202 \qmlmethod AbstractSeries ChartView::series(int index)
202 \qmlmethod AbstractSeries ChartView::series(int index)
203 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
203 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
204 the count property of the chart.
204 the count property of the chart.
205 */
205 */
206
206
207 /*!
207 /*!
208 \qmlmethod AbstractSeries ChartView::series(string name)
208 \qmlmethod AbstractSeries ChartView::series(string name)
209 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
209 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
210 */
210 */
211
211
212 /*!
212 /*!
213 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY)
213 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY)
214 Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and
214 Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and
215 optional axis \a axisY. For example:
215 optional axis \a axisY. For example:
216 \code
216 \code
217 // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes
217 // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes
218 var myAxisX = chartView.axisX(lineSeries);
218 var myAxisX = chartView.axisX(lineSeries);
219 var myAxisY = chartView.axisY(lineSeries);
219 var myAxisY = chartView.axisY(lineSeries);
220 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY);
220 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY);
221 \endcode
221 \endcode
222 */
222 */
223
223
224 /*!
224 /*!
225 \qmlmethod ChartView::removeSeries(AbstractSeries series)
225 \qmlmethod ChartView::removeSeries(AbstractSeries series)
226 Removes the \a series from the chart. The series object is also destroyed.
226 Removes the \a series from the chart. The series object is also destroyed.
227 */
227 */
228
228
229 /*!
229 /*!
230 \qmlmethod ChartView::removeAllSeries()
230 \qmlmethod ChartView::removeAllSeries()
231 Removes all series from the chart. All the series objects are also destroyed.
231 Removes all series from the chart. All the series objects are also destroyed.
232 */
232 */
233
233
234 /*!
234 /*!
235 \qmlmethod Axis ChartView::axisX(AbstractSeries series)
235 \qmlmethod Axis ChartView::axisX(AbstractSeries series)
236 The x-axis of the series.
236 The x-axis of the series.
237 */
237 */
238
238
239 /*!
239 /*!
240 \qmlmethod Axis ChartView::axisY(AbstractSeries series)
240 \qmlmethod Axis ChartView::axisY(AbstractSeries series)
241 The y-axis of the series.
241 The y-axis of the series.
242 */
242 */
243
243
244 /*!
244 /*!
245 \qmlmethod ChartView::zoomY(real factor)
245 \qmlmethod ChartView::zoomY(real factor)
246 Zooms in by \a factor on the center of the chart.
246 Zooms in by \a factor on the center of the chart.
247 */
247 */
248
248
249 /*!
249 /*!
250 \qmlmethod ChartView::scrollLeft(real pixels)
250 \qmlmethod ChartView::scrollLeft(real pixels)
251 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
251 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
252 */
252 */
253
253
254 /*!
254 /*!
255 \qmlmethod ChartView::scrollRight(real pixels)
255 \qmlmethod ChartView::scrollRight(real pixels)
256 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
256 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
257 */
257 */
258
258
259 /*!
259 /*!
260 \qmlmethod ChartView::scrollUp(real pixels)
260 \qmlmethod ChartView::scrollUp(real pixels)
261 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
261 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
262 */
262 */
263
263
264 /*!
264 /*!
265 \qmlmethod ChartView::scrollDown(real pixels)
265 \qmlmethod ChartView::scrollDown(real pixels)
266 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
266 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
267 */
267 */
268
268
269 /*!
269 /*!
270 \qmlsignal ChartView::seriesAdded(AbstractSeries series)
270 \qmlsignal ChartView::seriesAdded(AbstractSeries series)
271 The \a series has been added to the chart.
271 The \a series has been added to the chart.
272 */
272 */
273
273
274 /*!
274 /*!
275 \qmlsignal ChartView::seriesRemoved(AbstractSeries series)
275 \qmlsignal ChartView::seriesRemoved(AbstractSeries series)
276 The \a series has been removed from the chart. Please note that \a series is no longer a valid
276 The \a series has been removed from the chart. Please note that \a series is no longer a valid
277 object after the signal handler has completed.
277 object after the signal handler has completed.
278 */
278 */
279
279
280 DeclarativeChart::DeclarativeChart(QQuickItem *parent)
280 DeclarativeChart::DeclarativeChart(QQuickItem *parent)
281 : QQuickPaintedItem(parent)
281 : QQuickPaintedItem(parent)
282 {
282 {
283 initChart(QChart::ChartTypeCartesian);
283 initChart(QChart::ChartTypeCartesian);
284 }
284 }
285
285
286 DeclarativeChart::DeclarativeChart(QChart::ChartType type, QQuickItem *parent)
286 DeclarativeChart::DeclarativeChart(QChart::ChartType type, QQuickItem *parent)
287 : QQuickPaintedItem(parent)
287 : QQuickPaintedItem(parent)
288 {
288 {
289 initChart(type);
289 initChart(type);
290 }
290 }
291
291
292 void DeclarativeChart::initChart(QChart::ChartType type)
292 void DeclarativeChart::initChart(QChart::ChartType type)
293 {
293 {
294 m_currentSceneImage = 0;
294 m_currentSceneImage = 0;
295 m_guiThreadId = QThread::currentThreadId();
295 m_guiThreadId = QThread::currentThreadId();
296 m_paintThreadId = 0;
296 m_paintThreadId = 0;
297 m_updatePending = false;
297 m_updatePending = false;
298
298
299 if (type == QChart::ChartTypePolar)
299 if (type == QChart::ChartTypePolar)
300 m_chart = new QPolarChart();
300 m_chart = new QPolarChart();
301 else
301 else
302 m_chart = new QChart();
302 m_chart = new QChart();
303
303
304 m_scene = new QGraphicsScene(this);
304 m_scene = new QGraphicsScene(this);
305 m_scene->addItem(m_chart);
305 m_scene->addItem(m_chart);
306
306
307 setAntialiasing(QQuickItem::antialiasing());
307 setAntialiasing(QQuickItem::antialiasing());
308 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(sceneChanged(QList<QRectF>)));
308 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(sceneChanged(QList<QRectF>)));
309 connect(this, SIGNAL(antialiasingChanged(bool)), this, SLOT(handleAntialiasingChanged(bool)));
309 connect(this, SIGNAL(antialiasingChanged(bool)), this, SLOT(handleAntialiasingChanged(bool)));
310
310
311 setAcceptedMouseButtons(Qt::AllButtons);
311 setAcceptedMouseButtons(Qt::AllButtons);
312 setAcceptHoverEvents(true);
312 setAcceptHoverEvents(true);
313
313
314 m_margins = new DeclarativeMargins(this);
314 m_margins = new DeclarativeMargins(this);
315 m_margins->setTop(m_chart->margins().top());
315 m_margins->setTop(m_chart->margins().top());
316 m_margins->setLeft(m_chart->margins().left());
316 m_margins->setLeft(m_chart->margins().left());
317 m_margins->setRight(m_chart->margins().right());
317 m_margins->setRight(m_chart->margins().right());
318 m_margins->setBottom(m_chart->margins().bottom());
318 m_margins->setBottom(m_chart->margins().bottom());
319 connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
319 connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
320 connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
320 connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
321 connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
321 connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
322 connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
322 connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
323 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*)));
323 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*)));
324 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*)));
324 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*)));
325 connect(m_chart, &QChart::plotAreaChanged, this, &DeclarativeChart::plotAreaChanged);
325 connect(m_chart, &QChart::plotAreaChanged, this, &DeclarativeChart::plotAreaChanged);
326 }
326 }
327
327
328 void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series)
328 void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series)
329 {
329 {
330 emit seriesAdded(series);
330 emit seriesAdded(series);
331 }
331 }
332
332
333 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
333 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
334 {
334 {
335 m_chart->setMargins(QMargins(left, top, right, bottom));
335 m_chart->setMargins(QMargins(left, top, right, bottom));
336 emit minimumMarginsChanged();
336 emit minimumMarginsChanged();
337 }
337 }
338
338
339 DeclarativeChart::~DeclarativeChart()
339 DeclarativeChart::~DeclarativeChart()
340 {
340 {
341 delete m_chart;
341 delete m_chart;
342 m_sceneImageLock.lock();
342 m_sceneImageLock.lock();
343 delete m_currentSceneImage;
343 delete m_currentSceneImage;
344 m_currentSceneImage = 0;
344 m_currentSceneImage = 0;
345 m_sceneImageLock.unlock();
345 m_sceneImageLock.unlock();
346 }
346 }
347
347
348 void DeclarativeChart::childEvent(QChildEvent *event)
348 void DeclarativeChart::childEvent(QChildEvent *event)
349 {
349 {
350 if (event->type() == QEvent::ChildAdded) {
350 if (event->type() == QEvent::ChildAdded) {
351 if (qobject_cast<QAbstractSeries *>(event->child())) {
351 if (qobject_cast<QAbstractSeries *>(event->child())) {
352 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
352 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
353 }
353 }
354 }
354 }
355 }
355 }
356
356
357 void DeclarativeChart::componentComplete()
357 void DeclarativeChart::componentComplete()
358 {
358 {
359 foreach (QObject *child, children()) {
359 foreach (QObject *child, children()) {
360 if (qobject_cast<QAbstractSeries *>(child)) {
360 if (qobject_cast<QAbstractSeries *>(child)) {
361 // Add series to the chart
361 // Add series to the chart
362 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child);
362 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child);
363 m_chart->addSeries(series);
363 m_chart->addSeries(series);
364
364
365 // Connect to axis changed signals (unless this is a pie series)
365 // Connect to axis changed signals (unless this is a pie series)
366 if (!qobject_cast<DeclarativePieSeries *>(series)) {
366 if (!qobject_cast<DeclarativePieSeries *>(series)) {
367 connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
367 connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
368 connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXTopSet(QAbstractAxis*)));
368 connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXTopSet(QAbstractAxis*)));
369 connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
369 connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
370 connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*)));
370 connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*)));
371 }
371 }
372
372
373 initializeAxes(series);
373 initializeAxes(series);
374 }
374 }
375 }
375 }
376
376
377 QQuickItem::componentComplete();
377 QQuickItem::componentComplete();
378 }
378 }
379
379
380 void DeclarativeChart::seriesAxisAttachHelper(QAbstractSeries *series, QAbstractAxis *axis,
380 void DeclarativeChart::seriesAxisAttachHelper(QAbstractSeries *series, QAbstractAxis *axis,
381 Qt::Orientations orientation,
381 Qt::Orientations orientation,
382 Qt::Alignment alignment)
382 Qt::Alignment alignment)
383 {
383 {
384 if (!series->attachedAxes().contains(axis)) {
384 if (!series->attachedAxes().contains(axis)) {
385 // Remove & delete old axes that are not attached to any other series
385 // Remove & delete old axes that are not attached to any other series
386 foreach (QAbstractAxis* oldAxis, m_chart->axes(orientation, series)) {
386 foreach (QAbstractAxis* oldAxis, m_chart->axes(orientation, series)) {
387 bool otherAttachments = false;
387 bool otherAttachments = false;
388 if (oldAxis != axis) {
388 if (oldAxis != axis) {
389 foreach (QAbstractSeries *oldSeries, m_chart->series()) {
389 foreach (QAbstractSeries *oldSeries, m_chart->series()) {
390 if (oldSeries != series && oldSeries->attachedAxes().contains(oldAxis)) {
390 if (oldSeries != series && oldSeries->attachedAxes().contains(oldAxis)) {
391 otherAttachments = true;
391 otherAttachments = true;
392 break;
392 break;
393 }
393 }
394 }
394 }
395 if (!otherAttachments) {
395 if (!otherAttachments) {
396 m_chart->removeAxis(oldAxis);
396 m_chart->removeAxis(oldAxis);
397 delete oldAxis;
397 delete oldAxis;
398 }
398 }
399 }
399 }
400 }
400 }
401 if (!m_chart->axes(orientation).contains(axis))
401 if (!m_chart->axes(orientation).contains(axis))
402 m_chart->addAxis(axis, alignment);
402 m_chart->addAxis(axis, alignment);
403
403
404 series->attachAxis(axis);
404 series->attachAxis(axis);
405 }
405 }
406 }
406 }
407
407
408 void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis)
408 void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis)
409 {
409 {
410 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
410 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
411 if (axis && s) {
411 if (axis && s) {
412 seriesAxisAttachHelper(s, axis, Qt::Horizontal, Qt::AlignBottom);
412 seriesAxisAttachHelper(s, axis, Qt::Horizontal, Qt::AlignBottom);
413 } else {
413 } else {
414 qWarning() << "Trying to set axisX to null.";
414 qWarning() << "Trying to set axisX to null.";
415 }
415 }
416 }
416 }
417
417
418 void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis)
418 void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis)
419 {
419 {
420 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
420 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
421 if (axis && s) {
421 if (axis && s) {
422 seriesAxisAttachHelper(s, axis, Qt::Horizontal, Qt::AlignTop);
422 seriesAxisAttachHelper(s, axis, Qt::Horizontal, Qt::AlignTop);
423 } else {
423 } else {
424 qWarning() << "Trying to set axisXTop to null.";
424 qWarning() << "Trying to set axisXTop to null.";
425 }
425 }
426 }
426 }
427
427
428 void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis)
428 void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis)
429 {
429 {
430 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
430 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
431 if (axis && s) {
431 if (axis && s) {
432 seriesAxisAttachHelper(s, axis, Qt::Vertical, Qt::AlignLeft);
432 seriesAxisAttachHelper(s, axis, Qt::Vertical, Qt::AlignLeft);
433 } else {
433 } else {
434 qWarning() << "Trying to set axisY to null.";
434 qWarning() << "Trying to set axisY to null.";
435 }
435 }
436 }
436 }
437
437
438 void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis)
438 void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis)
439 {
439 {
440 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
440 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
441 if (axis && s) {
441 if (axis && s) {
442 seriesAxisAttachHelper(s, axis, Qt::Vertical, Qt::AlignRight);
442 seriesAxisAttachHelper(s, axis, Qt::Vertical, Qt::AlignRight);
443 } else {
443 } else {
444 qWarning() << "Trying to set axisYRight to null.";
444 qWarning() << "Trying to set axisYRight to null.";
445 }
445 }
446 }
446 }
447
447
448 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
448 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
449 {
449 {
450 if (newGeometry.isValid()) {
450 if (newGeometry.isValid()) {
451 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
451 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
452 m_chart->resize(newGeometry.width(), newGeometry.height());
452 m_chart->resize(newGeometry.width(), newGeometry.height());
453 }
453 }
454 }
454 }
455 QQuickItem::geometryChanged(newGeometry, oldGeometry);
455 QQuickItem::geometryChanged(newGeometry, oldGeometry);
456 }
456 }
457
457
458 void DeclarativeChart::sceneChanged(QList<QRectF> region)
458 void DeclarativeChart::sceneChanged(QList<QRectF> region)
459 {
459 {
460 Q_UNUSED(region);
460 Q_UNUSED(region);
461
461
462 if (m_guiThreadId == m_paintThreadId) {
462 if (m_guiThreadId == m_paintThreadId) {
463 // Rendering in gui thread, no need for shenannigans, just update
463 // Rendering in gui thread, no need for shenannigans, just update
464 update();
464 update();
465 } else {
465 } else {
466 // Multi-threaded rendering, need to ensure scene is actually rendered in gui thread
466 // Multi-threaded rendering, need to ensure scene is actually rendered in gui thread
467 if (!m_updatePending) {
467 if (!m_updatePending) {
468 m_updatePending = true;
468 m_updatePending = true;
469 // Do async render to avoid some unnecessary renders.
469 // Do async render to avoid some unnecessary renders.
470 QTimer::singleShot(0, this, SLOT(renderScene()));
470 QTimer::singleShot(0, this, SLOT(renderScene()));
471 }
471 }
472 }
472 }
473 }
473 }
474
474
475 void DeclarativeChart::renderScene()
475 void DeclarativeChart::renderScene()
476 {
476 {
477 m_updatePending = false;
477 m_updatePending = false;
478 m_sceneImageLock.lock();
478 m_sceneImageLock.lock();
479 delete m_currentSceneImage;
479 delete m_currentSceneImage;
480 m_currentSceneImage = new QImage(m_chart->size().toSize(), QImage::Format_ARGB32);
480 m_currentSceneImage = new QImage(m_chart->size().toSize(), QImage::Format_ARGB32);
481 m_currentSceneImage->fill(Qt::transparent);
481 m_currentSceneImage->fill(Qt::transparent);
482 QPainter painter(m_currentSceneImage);
482 QPainter painter(m_currentSceneImage);
483 if (antialiasing())
483 if (antialiasing())
484 painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
484 painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
485 QRect renderRect(QPoint(0, 0), m_chart->size().toSize());
485 QRect renderRect(QPoint(0, 0), m_chart->size().toSize());
486 m_scene->render(&painter, renderRect, renderRect);
486 m_scene->render(&painter, renderRect, renderRect);
487 m_sceneImageLock.unlock();
487 m_sceneImageLock.unlock();
488
488
489 update();
489 update();
490 }
490 }
491
491
492 void DeclarativeChart::paint(QPainter *painter)
492 void DeclarativeChart::paint(QPainter *painter)
493 {
493 {
494 if (!m_paintThreadId) {
494 if (!m_paintThreadId) {
495 m_paintThreadId = QThread::currentThreadId();
495 m_paintThreadId = QThread::currentThreadId();
496 if (m_guiThreadId == m_paintThreadId) {
496 if (m_guiThreadId == m_paintThreadId) {
497 // No need for scene image in single threaded rendering, so delete
497 // No need for scene image in single threaded rendering, so delete
498 // the one that got made by default before the rendering type was
498 // the one that got made by default before the rendering type was
499 // detected.
499 // detected.
500 delete m_currentSceneImage;
500 delete m_currentSceneImage;
501 m_currentSceneImage = 0;
501 m_currentSceneImage = 0;
502 }
502 }
503 }
503 }
504
504
505 if (m_guiThreadId == m_paintThreadId) {
505 if (m_guiThreadId == m_paintThreadId) {
506 QRectF renderRect(QPointF(0, 0), m_chart->size());
506 QRectF renderRect(QPointF(0, 0), m_chart->size());
507 m_scene->render(painter, renderRect, renderRect);
507 m_scene->render(painter, renderRect, renderRect);
508 } else {
508 } else {
509 m_sceneImageLock.lock();
509 m_sceneImageLock.lock();
510 if (m_currentSceneImage) {
510 if (m_currentSceneImage) {
511 QRect imageRect(QPoint(0, 0), m_currentSceneImage->size());
511 QRect imageRect(QPoint(0, 0), m_currentSceneImage->size());
512 QRect itemRect(QPoint(0, 0), QSize(width(), height()));
512 QRect itemRect(QPoint(0, 0), QSize(width(), height()));
513 painter->drawImage(itemRect, *m_currentSceneImage, imageRect);
513 painter->drawImage(itemRect, *m_currentSceneImage, imageRect);
514 }
514 }
515 m_sceneImageLock.unlock();
515 m_sceneImageLock.unlock();
516 }
516 }
517 }
517 }
518
518
519 void DeclarativeChart::mousePressEvent(QMouseEvent *event)
519 void DeclarativeChart::mousePressEvent(QMouseEvent *event)
520 {
520 {
521 m_mousePressScenePoint = event->pos();
521 m_mousePressScenePoint = event->pos();
522 m_mousePressScreenPoint = event->globalPos();
522 m_mousePressScreenPoint = event->globalPos();
523 m_lastMouseMoveScenePoint = m_mousePressScenePoint;
523 m_lastMouseMoveScenePoint = m_mousePressScenePoint;
524 m_lastMouseMoveScreenPoint = m_mousePressScreenPoint;
524 m_lastMouseMoveScreenPoint = m_mousePressScreenPoint;
525 m_mousePressButton = event->button();
525 m_mousePressButton = event->button();
526 m_mousePressButtons = event->buttons();
526 m_mousePressButtons = event->buttons();
527
527
528 QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMousePress);
528 QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMousePress);
529 mouseEvent.setWidget(0);
529 mouseEvent.setWidget(0);
530 mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint);
530 mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint);
531 mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint);
531 mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint);
532 mouseEvent.setScenePos(m_mousePressScenePoint);
532 mouseEvent.setScenePos(m_mousePressScenePoint);
533 mouseEvent.setScreenPos(m_mousePressScreenPoint);
533 mouseEvent.setScreenPos(m_mousePressScreenPoint);
534 mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint);
534 mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint);
535 mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint);
535 mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint);
536 mouseEvent.setButtons(m_mousePressButtons);
536 mouseEvent.setButtons(m_mousePressButtons);
537 mouseEvent.setButton(m_mousePressButton);
537 mouseEvent.setButton(m_mousePressButton);
538 mouseEvent.setModifiers(event->modifiers());
538 mouseEvent.setModifiers(event->modifiers());
539 mouseEvent.setAccepted(false);
539 mouseEvent.setAccepted(false);
540
540
541 QApplication::sendEvent(m_scene, &mouseEvent);
541 QApplication::sendEvent(m_scene, &mouseEvent);
542 }
542 }
543
543
544 void DeclarativeChart::mouseReleaseEvent(QMouseEvent *event)
544 void DeclarativeChart::mouseReleaseEvent(QMouseEvent *event)
545 {
545 {
546 QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseRelease);
546 QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseRelease);
547 mouseEvent.setWidget(0);
547 mouseEvent.setWidget(0);
548 mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint);
548 mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint);
549 mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint);
549 mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint);
550 mouseEvent.setScenePos(event->pos());
550 mouseEvent.setScenePos(event->pos());
551 mouseEvent.setScreenPos(event->globalPos());
551 mouseEvent.setScreenPos(event->globalPos());
552 mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint);
552 mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint);
553 mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint);
553 mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint);
554 mouseEvent.setButtons(event->buttons());
554 mouseEvent.setButtons(event->buttons());
555 mouseEvent.setButton(event->button());
555 mouseEvent.setButton(event->button());
556 mouseEvent.setModifiers(event->modifiers());
556 mouseEvent.setModifiers(event->modifiers());
557 mouseEvent.setAccepted(false);
557 mouseEvent.setAccepted(false);
558
558
559 QApplication::sendEvent(m_scene, &mouseEvent);
559 QApplication::sendEvent(m_scene, &mouseEvent);
560
560
561 m_mousePressButtons = event->buttons();
561 m_mousePressButtons = event->buttons();
562 m_mousePressButton = Qt::NoButton;
562 m_mousePressButton = Qt::NoButton;
563 }
563 }
564
564
565 void DeclarativeChart::hoverMoveEvent(QHoverEvent *event)
565 void DeclarativeChart::hoverMoveEvent(QHoverEvent *event)
566 {
566 {
567 // Convert hover move to mouse move, since we don't seem to get actual mouse move events.
567 // Convert hover move to mouse move, since we don't seem to get actual mouse move events.
568 // QGraphicsScene generates hover events from mouse move events, so we don't need
568 // QGraphicsScene generates hover events from mouse move events, so we don't need
569 // to pass hover events there.
569 // to pass hover events there.
570 QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove);
570 QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove);
571 mouseEvent.setWidget(0);
571 mouseEvent.setWidget(0);
572 mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint);
572 mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint);
573 mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint);
573 mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint);
574 mouseEvent.setScenePos(event->pos());
574 mouseEvent.setScenePos(event->pos());
575 // Hover events do not have global pos in them, and the screen position doesn't seem to
575 // Hover events do not have global pos in them, and the screen position doesn't seem to
576 // matter anyway in this use case, so just pass event pos instead of trying to
576 // matter anyway in this use case, so just pass event pos instead of trying to
577 // calculate the real screen position.
577 // calculate the real screen position.
578 mouseEvent.setScreenPos(event->pos());
578 mouseEvent.setScreenPos(event->pos());
579 mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint);
579 mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint);
580 mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint);
580 mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint);
581 mouseEvent.setButtons(m_mousePressButtons);
581 mouseEvent.setButtons(m_mousePressButtons);
582 mouseEvent.setButton(m_mousePressButton);
582 mouseEvent.setButton(m_mousePressButton);
583 mouseEvent.setModifiers(event->modifiers());
583 mouseEvent.setModifiers(event->modifiers());
584 m_lastMouseMoveScenePoint = mouseEvent.scenePos();
584 m_lastMouseMoveScenePoint = mouseEvent.scenePos();
585 m_lastMouseMoveScreenPoint = mouseEvent.screenPos();
585 m_lastMouseMoveScreenPoint = mouseEvent.screenPos();
586 mouseEvent.setAccepted(false);
586 mouseEvent.setAccepted(false);
587
587
588 QApplication::sendEvent(m_scene, &mouseEvent);
588 QApplication::sendEvent(m_scene, &mouseEvent);
589 }
589 }
590
590
591 void DeclarativeChart::handleAntialiasingChanged(bool enable)
591 void DeclarativeChart::handleAntialiasingChanged(bool enable)
592 {
592 {
593 setAntialiasing(enable);
593 setAntialiasing(enable);
594 }
594 }
595
595
596 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
596 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
597 {
597 {
598 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
598 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
599 if (chartTheme != m_chart->theme())
599 if (chartTheme != m_chart->theme())
600 m_chart->setTheme(chartTheme);
600 m_chart->setTheme(chartTheme);
601 }
601 }
602
602
603 DeclarativeChart::Theme DeclarativeChart::theme()
603 DeclarativeChart::Theme DeclarativeChart::theme()
604 {
604 {
605 return (DeclarativeChart::Theme) m_chart->theme();
605 return (DeclarativeChart::Theme) m_chart->theme();
606 }
606 }
607
607
608 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
608 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
609 {
609 {
610 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
610 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
611 if (animationOptions != m_chart->animationOptions())
611 if (animationOptions != m_chart->animationOptions())
612 m_chart->setAnimationOptions(animationOptions);
612 m_chart->setAnimationOptions(animationOptions);
613 }
613 }
614
614
615 DeclarativeChart::Animation DeclarativeChart::animationOptions()
615 DeclarativeChart::Animation DeclarativeChart::animationOptions()
616 {
616 {
617 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
617 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
618 return DeclarativeChart::AllAnimations;
618 return DeclarativeChart::AllAnimations;
619 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
619 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
620 return DeclarativeChart::GridAxisAnimations;
620 return DeclarativeChart::GridAxisAnimations;
621 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
621 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
622 return DeclarativeChart::SeriesAnimations;
622 return DeclarativeChart::SeriesAnimations;
623 else
623 else
624 return DeclarativeChart::NoAnimation;
624 return DeclarativeChart::NoAnimation;
625 }
625 }
626
626
627 void DeclarativeChart::setTitle(QString title)
627 void DeclarativeChart::setTitle(QString title)
628 {
628 {
629 if (title != m_chart->title())
629 if (title != m_chart->title())
630 m_chart->setTitle(title);
630 m_chart->setTitle(title);
631 }
631 }
632 QString DeclarativeChart::title()
632 QString DeclarativeChart::title()
633 {
633 {
634 return m_chart->title();
634 return m_chart->title();
635 }
635 }
636
636
637 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
637 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
638 {
638 {
639 QList<QAbstractAxis *> axes = m_chart->axes(Qt::Horizontal, series);
639 QList<QAbstractAxis *> axes = m_chart->axes(Qt::Horizontal, series);
640 if (axes.count())
640 if (axes.count())
641 return axes[0];
641 return axes[0];
642 return 0;
642 return 0;
643 }
643 }
644
644
645 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
645 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
646 {
646 {
647 QList<QAbstractAxis *> axes = m_chart->axes(Qt::Vertical, series);
647 QList<QAbstractAxis *> axes = m_chart->axes(Qt::Vertical, series);
648 if (axes.count())
648 if (axes.count())
649 return axes[0];
649 return axes[0];
650 return 0;
650 return 0;
651 }
651 }
652
652
653 QLegend *DeclarativeChart::legend()
653 QLegend *DeclarativeChart::legend()
654 {
654 {
655 return m_chart->legend();
655 return m_chart->legend();
656 }
656 }
657
657
658 void DeclarativeChart::setTitleColor(QColor color)
658 void DeclarativeChart::setTitleColor(QColor color)
659 {
659 {
660 QBrush b = m_chart->titleBrush();
660 QBrush b = m_chart->titleBrush();
661 if (color != b.color()) {
661 if (color != b.color()) {
662 b.setColor(color);
662 b.setColor(color);
663 m_chart->setTitleBrush(b);
663 m_chart->setTitleBrush(b);
664 emit titleColorChanged(color);
664 emit titleColorChanged(color);
665 }
665 }
666 }
666 }
667
667
668 QFont DeclarativeChart::titleFont() const
668 QFont DeclarativeChart::titleFont() const
669 {
669 {
670 return m_chart->titleFont();
670 return m_chart->titleFont();
671 }
671 }
672
672
673 void DeclarativeChart::setTitleFont(const QFont &font)
673 void DeclarativeChart::setTitleFont(const QFont &font)
674 {
674 {
675 m_chart->setTitleFont(font);
675 m_chart->setTitleFont(font);
676 }
676 }
677
677
678 QColor DeclarativeChart::titleColor()
678 QColor DeclarativeChart::titleColor()
679 {
679 {
680 return m_chart->titleBrush().color();
680 return m_chart->titleBrush().color();
681 }
681 }
682
682
683 void DeclarativeChart::setBackgroundColor(QColor color)
683 void DeclarativeChart::setBackgroundColor(QColor color)
684 {
684 {
685 QBrush b = m_chart->backgroundBrush();
685 QBrush b = m_chart->backgroundBrush();
686 if (b.style() != Qt::SolidPattern || color != b.color()) {
686 if (b.style() != Qt::SolidPattern || color != b.color()) {
687 b.setStyle(Qt::SolidPattern);
687 b.setStyle(Qt::SolidPattern);
688 b.setColor(color);
688 b.setColor(color);
689 m_chart->setBackgroundBrush(b);
689 m_chart->setBackgroundBrush(b);
690 emit backgroundColorChanged();
690 emit backgroundColorChanged();
691 }
691 }
692 }
692 }
693
693
694 QColor DeclarativeChart::backgroundColor()
694 QColor DeclarativeChart::backgroundColor()
695 {
695 {
696 return m_chart->backgroundBrush().color();
696 return m_chart->backgroundBrush().color();
697 }
697 }
698
698
699 void QtCharts::DeclarativeChart::setPlotAreaColor(QColor color)
699 void QtCharts::DeclarativeChart::setPlotAreaColor(QColor color)
700 {
700 {
701 QBrush b = m_chart->plotAreaBackgroundBrush();
701 QBrush b = m_chart->plotAreaBackgroundBrush();
702 if (b.style() != Qt::SolidPattern || color != b.color()) {
702 if (b.style() != Qt::SolidPattern || color != b.color()) {
703 b.setStyle(Qt::SolidPattern);
703 b.setStyle(Qt::SolidPattern);
704 b.setColor(color);
704 b.setColor(color);
705 m_chart->setPlotAreaBackgroundBrush(b);
705 m_chart->setPlotAreaBackgroundBrush(b);
706 m_chart->setPlotAreaBackgroundVisible(true);
706 m_chart->setPlotAreaBackgroundVisible(true);
707 emit plotAreaColorChanged();
707 emit plotAreaColorChanged();
708 }
708 }
709 }
709 }
710
710
711 QColor QtCharts::DeclarativeChart::plotAreaColor()
711 QColor QtCharts::DeclarativeChart::plotAreaColor()
712 {
712 {
713 return m_chart->plotAreaBackgroundBrush().color();
713 return m_chart->plotAreaBackgroundBrush().color();
714 }
714 }
715
715
716 void DeclarativeChart::setLocalizeNumbers(bool localize)
716 void DeclarativeChart::setLocalizeNumbers(bool localize)
717 {
717 {
718 if (m_chart->localizeNumbers() != localize) {
718 if (m_chart->localizeNumbers() != localize) {
719 m_chart->setLocalizeNumbers(localize);
719 m_chart->setLocalizeNumbers(localize);
720 emit localizeNumbersChanged();
720 emit localizeNumbersChanged();
721 }
721 }
722 }
722 }
723
723
724 bool DeclarativeChart::localizeNumbers() const
724 bool DeclarativeChart::localizeNumbers() const
725 {
725 {
726 return m_chart->localizeNumbers();
726 return m_chart->localizeNumbers();
727 }
727 }
728
728
729 void QtCharts::DeclarativeChart::setLocale(const QLocale &locale)
729 void QtCharts::DeclarativeChart::setLocale(const QLocale &locale)
730 {
730 {
731 if (m_chart->locale() != locale) {
731 if (m_chart->locale() != locale) {
732 m_chart->setLocale(locale);
732 m_chart->setLocale(locale);
733 emit localeChanged();
733 emit localeChanged();
734 }
734 }
735 }
735 }
736
736
737 QLocale QtCharts::DeclarativeChart::locale() const
737 QLocale QtCharts::DeclarativeChart::locale() const
738 {
738 {
739 return m_chart->locale();
739 return m_chart->locale();
740 }
740 }
741
741
742 int DeclarativeChart::count()
742 int DeclarativeChart::count()
743 {
743 {
744 return m_chart->series().count();
744 return m_chart->series().count();
745 }
745 }
746
746
747 void DeclarativeChart::setDropShadowEnabled(bool enabled)
747 void DeclarativeChart::setDropShadowEnabled(bool enabled)
748 {
748 {
749 if (enabled != m_chart->isDropShadowEnabled()) {
749 if (enabled != m_chart->isDropShadowEnabled()) {
750 m_chart->setDropShadowEnabled(enabled);
750 m_chart->setDropShadowEnabled(enabled);
751 dropShadowEnabledChanged(enabled);
751 dropShadowEnabledChanged(enabled);
752 }
752 }
753 }
753 }
754
754
755 bool DeclarativeChart::dropShadowEnabled()
755 bool DeclarativeChart::dropShadowEnabled()
756 {
756 {
757 return m_chart->isDropShadowEnabled();
757 return m_chart->isDropShadowEnabled();
758 }
758 }
759
759
760 qreal DeclarativeChart::backgroundRoundness() const
760 qreal DeclarativeChart::backgroundRoundness() const
761 {
761 {
762 return m_chart->backgroundRoundness();
762 return m_chart->backgroundRoundness();
763 }
763 }
764
764
765 void DeclarativeChart::setBackgroundRoundness(qreal diameter)
765 void DeclarativeChart::setBackgroundRoundness(qreal diameter)
766 {
766 {
767 if (m_chart->backgroundRoundness() != diameter) {
767 if (m_chart->backgroundRoundness() != diameter) {
768 m_chart->setBackgroundRoundness(diameter);
768 m_chart->setBackgroundRoundness(diameter);
769 emit backgroundRoundnessChanged(diameter);
769 emit backgroundRoundnessChanged(diameter);
770 }
770 }
771 }
771 }
772
772
773 qreal DeclarativeChart::topMargin()
773 qreal DeclarativeChart::topMargin()
774 {
774 {
775 qWarning() << "ChartView.topMargin is deprecated. Use margins instead.";
775 qWarning() << "ChartView.topMargin is deprecated. Use margins instead.";
776 return m_chart->margins().top();
776 return m_chart->margins().top();
777 }
777 }
778
778
779 qreal DeclarativeChart::bottomMargin()
779 qreal DeclarativeChart::bottomMargin()
780 {
780 {
781 qWarning() << "ChartView.bottomMargin is deprecated. Use margins instead.";
781 qWarning() << "ChartView.bottomMargin is deprecated. Use margins instead.";
782 return m_chart->margins().bottom();
782 return m_chart->margins().bottom();
783 }
783 }
784
784
785 qreal DeclarativeChart::leftMargin()
785 qreal DeclarativeChart::leftMargin()
786 {
786 {
787 qWarning() << "ChartView.leftMargin is deprecated. Use margins instead.";
787 qWarning() << "ChartView.leftMargin is deprecated. Use margins instead.";
788 return m_chart->margins().left();
788 return m_chart->margins().left();
789 }
789 }
790
790
791 qreal DeclarativeChart::rightMargin()
791 qreal DeclarativeChart::rightMargin()
792 {
792 {
793 qWarning() << "ChartView.rightMargin is deprecated. Use margins instead.";
793 qWarning() << "ChartView.rightMargin is deprecated. Use margins instead.";
794 return m_chart->margins().right();
794 return m_chart->margins().right();
795 }
795 }
796
796
797 void DeclarativeChart::zoom(qreal factor)
797 void DeclarativeChart::zoom(qreal factor)
798 {
798 {
799 m_chart->zoom(factor);
799 m_chart->zoom(factor);
800 }
800 }
801
801
802 void DeclarativeChart::scrollLeft(qreal pixels)
802 void DeclarativeChart::scrollLeft(qreal pixels)
803 {
803 {
804 m_chart->scroll(-pixels, 0);
804 m_chart->scroll(-pixels, 0);
805 }
805 }
806
806
807 void DeclarativeChart::scrollRight(qreal pixels)
807 void DeclarativeChart::scrollRight(qreal pixels)
808 {
808 {
809 m_chart->scroll(pixels, 0);
809 m_chart->scroll(pixels, 0);
810 }
810 }
811
811
812 void DeclarativeChart::scrollUp(qreal pixels)
812 void DeclarativeChart::scrollUp(qreal pixels)
813 {
813 {
814 m_chart->scroll(0, pixels);
814 m_chart->scroll(0, pixels);
815 }
815 }
816
816
817 void DeclarativeChart::scrollDown(qreal pixels)
817 void DeclarativeChart::scrollDown(qreal pixels)
818 {
818 {
819 m_chart->scroll(0, -pixels);
819 m_chart->scroll(0, -pixels);
820 }
820 }
821
821
822 QQmlListProperty<QAbstractAxis> DeclarativeChart::axes()
822 QQmlListProperty<QAbstractAxis> DeclarativeChart::axes()
823 {
823 {
824 return QQmlListProperty<QAbstractAxis>(this, 0,
824 return QQmlListProperty<QAbstractAxis>(this, 0,
825 &DeclarativeChart::axesAppendFunc,
825 &DeclarativeChart::axesAppendFunc,
826 &DeclarativeChart::axesCountFunc,
826 &DeclarativeChart::axesCountFunc,
827 &DeclarativeChart::axesAtFunc,
827 &DeclarativeChart::axesAtFunc,
828 &DeclarativeChart::axesClearFunc);
828 &DeclarativeChart::axesClearFunc);
829 }
829 }
830
830
831 void DeclarativeChart::axesAppendFunc(QQmlListProperty<QAbstractAxis> *list, QAbstractAxis *element)
831 void DeclarativeChart::axesAppendFunc(QQmlListProperty<QAbstractAxis> *list, QAbstractAxis *element)
832 {
832 {
833 // Empty implementation
833 // Empty implementation
834 Q_UNUSED(list);
834 Q_UNUSED(list);
835 Q_UNUSED(element);
835 Q_UNUSED(element);
836 }
836 }
837
837
838 int DeclarativeChart::axesCountFunc(QQmlListProperty<QAbstractAxis> *list)
838 int DeclarativeChart::axesCountFunc(QQmlListProperty<QAbstractAxis> *list)
839 {
839 {
840 if (qobject_cast<DeclarativeChart *>(list->object)) {
840 if (qobject_cast<DeclarativeChart *>(list->object)) {
841 DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object);
841 DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object);
842 return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical).count();
842 return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical).count();
843 }
843 }
844 return 0;
844 return 0;
845 }
845 }
846
846
847 QAbstractAxis *DeclarativeChart::axesAtFunc(QQmlListProperty<QAbstractAxis> *list, int index)
847 QAbstractAxis *DeclarativeChart::axesAtFunc(QQmlListProperty<QAbstractAxis> *list, int index)
848 {
848 {
849 if (qobject_cast<DeclarativeChart *>(list->object)) {
849 if (qobject_cast<DeclarativeChart *>(list->object)) {
850 DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object);
850 DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object);
851 QList<QAbstractAxis *> axes = chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]);
851 QList<QAbstractAxis *> axes = chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]);
852 return axes.at(index);
852 return axes.at(index);
853 }
853 }
854 return 0;
854 return 0;
855 }
855 }
856
856
857 void DeclarativeChart::axesClearFunc(QQmlListProperty<QAbstractAxis> *list)
857 void DeclarativeChart::axesClearFunc(QQmlListProperty<QAbstractAxis> *list)
858 {
858 {
859 // Empty implementation
859 // Empty implementation
860 Q_UNUSED(list);
860 Q_UNUSED(list);
861 }
861 }
862
862
863
863
864 QAbstractSeries *DeclarativeChart::series(int index)
864 QAbstractSeries *DeclarativeChart::series(int index)
865 {
865 {
866 if (index < m_chart->series().count()) {
866 if (index < m_chart->series().count()) {
867 return m_chart->series().at(index);
867 return m_chart->series().at(index);
868 }
868 }
869 return 0;
869 return 0;
870 }
870 }
871
871
872 QAbstractSeries *DeclarativeChart::series(QString seriesName)
872 QAbstractSeries *DeclarativeChart::series(QString seriesName)
873 {
873 {
874 foreach (QAbstractSeries *series, m_chart->series()) {
874 foreach (QAbstractSeries *series, m_chart->series()) {
875 if (series->name() == seriesName)
875 if (series->name() == seriesName)
876 return series;
876 return series;
877 }
877 }
878 return 0;
878 return 0;
879 }
879 }
880
880
881 QAbstractSeries *DeclarativeChart::createSeries(int type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY)
881 QAbstractSeries *DeclarativeChart::createSeries(int type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY)
882 {
882 {
883 QAbstractSeries *series = 0;
883 QAbstractSeries *series = 0;
884
884
885 switch (type) {
885 switch (type) {
886 case DeclarativeChart::SeriesTypeLine:
886 case DeclarativeChart::SeriesTypeLine:
887 series = new DeclarativeLineSeries();
887 series = new DeclarativeLineSeries();
888 break;
888 break;
889 case DeclarativeChart::SeriesTypeArea: {
889 case DeclarativeChart::SeriesTypeArea: {
890 DeclarativeAreaSeries *area = new DeclarativeAreaSeries();
890 DeclarativeAreaSeries *area = new DeclarativeAreaSeries();
891 area->setUpperSeries(new DeclarativeLineSeries());
891 DeclarativeLineSeries *line = new DeclarativeLineSeries();
892 line->setParent(area);
893 area->setUpperSeries(line);
892 series = area;
894 series = area;
893 break;
895 break;
894 }
896 }
895 case DeclarativeChart::SeriesTypeStackedBar:
897 case DeclarativeChart::SeriesTypeStackedBar:
896 series = new DeclarativeStackedBarSeries();
898 series = new DeclarativeStackedBarSeries();
897 break;
899 break;
898 case DeclarativeChart::SeriesTypePercentBar:
900 case DeclarativeChart::SeriesTypePercentBar:
899 series = new DeclarativePercentBarSeries();
901 series = new DeclarativePercentBarSeries();
900 break;
902 break;
901 case DeclarativeChart::SeriesTypeBar:
903 case DeclarativeChart::SeriesTypeBar:
902 series = new DeclarativeBarSeries();
904 series = new DeclarativeBarSeries();
903 break;
905 break;
904 case DeclarativeChart::SeriesTypeHorizontalBar:
906 case DeclarativeChart::SeriesTypeHorizontalBar:
905 series = new DeclarativeHorizontalBarSeries();
907 series = new DeclarativeHorizontalBarSeries();
906 break;
908 break;
907 case DeclarativeChart::SeriesTypeHorizontalPercentBar:
909 case DeclarativeChart::SeriesTypeHorizontalPercentBar:
908 series = new DeclarativeHorizontalPercentBarSeries();
910 series = new DeclarativeHorizontalPercentBarSeries();
909 break;
911 break;
910 case DeclarativeChart::SeriesTypeHorizontalStackedBar:
912 case DeclarativeChart::SeriesTypeHorizontalStackedBar:
911 series = new DeclarativeHorizontalStackedBarSeries();
913 series = new DeclarativeHorizontalStackedBarSeries();
912 break;
914 break;
913 case DeclarativeChart::SeriesTypeBoxPlot:
915 case DeclarativeChart::SeriesTypeBoxPlot:
914 series = new DeclarativeBoxPlotSeries();
916 series = new DeclarativeBoxPlotSeries();
915 break;
917 break;
916 case DeclarativeChart::SeriesTypePie:
918 case DeclarativeChart::SeriesTypePie:
917 series = new DeclarativePieSeries();
919 series = new DeclarativePieSeries();
918 break;
920 break;
919 case DeclarativeChart::SeriesTypeScatter:
921 case DeclarativeChart::SeriesTypeScatter:
920 series = new DeclarativeScatterSeries();
922 series = new DeclarativeScatterSeries();
921 break;
923 break;
922 case DeclarativeChart::SeriesTypeSpline:
924 case DeclarativeChart::SeriesTypeSpline:
923 series = new DeclarativeSplineSeries();
925 series = new DeclarativeSplineSeries();
924 break;
926 break;
925 default:
927 default:
926 qWarning() << "Illegal series type";
928 qWarning() << "Illegal series type";
927 }
929 }
928
930
929 if (series) {
931 if (series) {
930 // Connect to axis changed signals (unless this is a pie series)
932 // Connect to axis changed signals (unless this is a pie series)
931 if (!qobject_cast<DeclarativePieSeries *>(series)) {
933 if (!qobject_cast<DeclarativePieSeries *>(series)) {
932 connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
934 connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
933 connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
935 connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
934 connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
936 connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
935 connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*)));
937 connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*)));
936 }
938 }
937
939
938 series->setName(name);
940 series->setName(name);
939 m_chart->addSeries(series);
941 m_chart->addSeries(series);
940
942
941 if (!axisX || !axisY)
943 if (!axisX || !axisY)
942 initializeAxes(series);
944 initializeAxes(series);
943
945
944 if (axisX)
946 if (axisX)
945 setAxisX(axisX, series);
947 setAxisX(axisX, series);
946 if (axisY)
948 if (axisY)
947 setAxisY(axisY, series);
949 setAxisY(axisY, series);
948 }
950 }
949
951
950 return series;
952 return series;
951 }
953 }
952
954
953 void DeclarativeChart::removeSeries(QAbstractSeries *series)
955 void DeclarativeChart::removeSeries(QAbstractSeries *series)
954 {
956 {
955 if (series)
957 if (series)
956 m_chart->removeSeries(series);
958 m_chart->removeSeries(series);
957 else
959 else
958 qWarning("removeSeries: cannot remove null");
960 qWarning("removeSeries: cannot remove null");
959 }
961 }
960
962
961 void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series)
963 void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series)
962 {
964 {
963 if (axis && series)
965 if (axis && series)
964 seriesAxisAttachHelper(series, axis, Qt::Horizontal, Qt::AlignBottom);
966 seriesAxisAttachHelper(series, axis, Qt::Horizontal, Qt::AlignBottom);
965 }
967 }
966
968
967 void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series)
969 void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series)
968 {
970 {
969 if (axis && series)
971 if (axis && series)
970 seriesAxisAttachHelper(series, axis, Qt::Vertical, Qt::AlignLeft);
972 seriesAxisAttachHelper(series, axis, Qt::Vertical, Qt::AlignLeft);
971 }
973 }
972
974
973 void DeclarativeChart::createDefaultAxes()
975 void DeclarativeChart::createDefaultAxes()
974 {
976 {
975 qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically.";
977 qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically.";
976 }
978 }
977
979
978 QAbstractAxis *DeclarativeChart::defaultAxis(Qt::Orientation orientation, QAbstractSeries *series)
980 QAbstractAxis *DeclarativeChart::defaultAxis(Qt::Orientation orientation, QAbstractSeries *series)
979 {
981 {
980 if (!series) {
982 if (!series) {
981 qWarning() << "No axis type defined for null series";
983 qWarning() << "No axis type defined for null series";
982 return 0;
984 return 0;
983 }
985 }
984
986
985 foreach (QAbstractAxis *existingAxis, m_chart->axes(orientation)) {
987 foreach (QAbstractAxis *existingAxis, m_chart->axes(orientation)) {
986 if (existingAxis->type() == series->d_ptr->defaultAxisType(orientation))
988 if (existingAxis->type() == series->d_ptr->defaultAxisType(orientation))
987 return existingAxis;
989 return existingAxis;
988 }
990 }
989
991
990 switch (series->d_ptr->defaultAxisType(orientation)) {
992 switch (series->d_ptr->defaultAxisType(orientation)) {
991 case QAbstractAxis::AxisTypeValue:
993 case QAbstractAxis::AxisTypeValue:
992 return new QValueAxis(this);
994 return new QValueAxis(this);
993 case QAbstractAxis::AxisTypeBarCategory:
995 case QAbstractAxis::AxisTypeBarCategory:
994 return new QBarCategoryAxis(this);
996 return new QBarCategoryAxis(this);
995 case QAbstractAxis::AxisTypeCategory:
997 case QAbstractAxis::AxisTypeCategory:
996 return new QCategoryAxis(this);
998 return new QCategoryAxis(this);
997 #ifndef QT_ON_ARM
999 #ifndef QT_ON_ARM
998 case QAbstractAxis::AxisTypeDateTime:
1000 case QAbstractAxis::AxisTypeDateTime:
999 return new QDateTimeAxis(this);
1001 return new QDateTimeAxis(this);
1000 #endif
1002 #endif
1001 case QAbstractAxis::AxisTypeLogValue:
1003 case QAbstractAxis::AxisTypeLogValue:
1002 return new QLogValueAxis(this);
1004 return new QLogValueAxis(this);
1003 default:
1005 default:
1004 // assume AxisTypeNoAxis
1006 // assume AxisTypeNoAxis
1005 return 0;
1007 return 0;
1006 }
1008 }
1007 }
1009 }
1008
1010
1009 void DeclarativeChart::initializeAxes(QAbstractSeries *series)
1011 void DeclarativeChart::initializeAxes(QAbstractSeries *series)
1010 {
1012 {
1011 if (qobject_cast<DeclarativeLineSeries *>(series))
1013 if (qobject_cast<DeclarativeLineSeries *>(series))
1012 doInitializeAxes(series, qobject_cast<DeclarativeLineSeries *>(series)->m_axes);
1014 doInitializeAxes(series, qobject_cast<DeclarativeLineSeries *>(series)->m_axes);
1013 else if (qobject_cast<DeclarativeScatterSeries *>(series))
1015 else if (qobject_cast<DeclarativeScatterSeries *>(series))
1014 doInitializeAxes(series, qobject_cast<DeclarativeScatterSeries *>(series)->m_axes);
1016 doInitializeAxes(series, qobject_cast<DeclarativeScatterSeries *>(series)->m_axes);
1015 else if (qobject_cast<DeclarativeSplineSeries *>(series))
1017 else if (qobject_cast<DeclarativeSplineSeries *>(series))
1016 doInitializeAxes(series, qobject_cast<DeclarativeSplineSeries *>(series)->m_axes);
1018 doInitializeAxes(series, qobject_cast<DeclarativeSplineSeries *>(series)->m_axes);
1017 else if (qobject_cast<DeclarativeAreaSeries *>(series))
1019 else if (qobject_cast<DeclarativeAreaSeries *>(series))
1018 doInitializeAxes(series, qobject_cast<DeclarativeAreaSeries *>(series)->m_axes);
1020 doInitializeAxes(series, qobject_cast<DeclarativeAreaSeries *>(series)->m_axes);
1019 else if (qobject_cast<DeclarativeBarSeries *>(series))
1021 else if (qobject_cast<DeclarativeBarSeries *>(series))
1020 doInitializeAxes(series, qobject_cast<DeclarativeBarSeries *>(series)->m_axes);
1022 doInitializeAxes(series, qobject_cast<DeclarativeBarSeries *>(series)->m_axes);
1021 else if (qobject_cast<DeclarativeStackedBarSeries *>(series))
1023 else if (qobject_cast<DeclarativeStackedBarSeries *>(series))
1022 doInitializeAxes(series, qobject_cast<DeclarativeStackedBarSeries *>(series)->m_axes);
1024 doInitializeAxes(series, qobject_cast<DeclarativeStackedBarSeries *>(series)->m_axes);
1023 else if (qobject_cast<DeclarativePercentBarSeries *>(series))
1025 else if (qobject_cast<DeclarativePercentBarSeries *>(series))
1024 doInitializeAxes(series, qobject_cast<DeclarativePercentBarSeries *>(series)->m_axes);
1026 doInitializeAxes(series, qobject_cast<DeclarativePercentBarSeries *>(series)->m_axes);
1025 else if (qobject_cast<DeclarativeHorizontalBarSeries *>(series))
1027 else if (qobject_cast<DeclarativeHorizontalBarSeries *>(series))
1026 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalBarSeries *>(series)->m_axes);
1028 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalBarSeries *>(series)->m_axes);
1027 else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series))
1029 else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series))
1028 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)->m_axes);
1030 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)->m_axes);
1029 else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series))
1031 else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series))
1030 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)->m_axes);
1032 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)->m_axes);
1031 else if (qobject_cast<DeclarativeBoxPlotSeries *>(series))
1033 else if (qobject_cast<DeclarativeBoxPlotSeries *>(series))
1032 doInitializeAxes(series, qobject_cast<DeclarativeBoxPlotSeries *>(series)->m_axes);
1034 doInitializeAxes(series, qobject_cast<DeclarativeBoxPlotSeries *>(series)->m_axes);
1033 // else: do nothing
1035 // else: do nothing
1034 }
1036 }
1035
1037
1036 void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes)
1038 void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes)
1037 {
1039 {
1038 // Initialize axis X
1040 // Initialize axis X
1039 if (axes->axisX())
1041 if (axes->axisX())
1040 axes->emitAxisXChanged();
1042 axes->emitAxisXChanged();
1041 else if (axes->axisXTop())
1043 else if (axes->axisXTop())
1042 axes->emitAxisXTopChanged();
1044 axes->emitAxisXTopChanged();
1043 else
1045 else
1044 axes->setAxisX(defaultAxis(Qt::Horizontal, series));
1046 axes->setAxisX(defaultAxis(Qt::Horizontal, series));
1045
1047
1046 // Initialize axis Y
1048 // Initialize axis Y
1047 if (axes->axisY())
1049 if (axes->axisY())
1048 axes->emitAxisYChanged();
1050 axes->emitAxisYChanged();
1049 else if (axes->axisYRight())
1051 else if (axes->axisYRight())
1050 axes->emitAxisYRightChanged();
1052 axes->emitAxisYRightChanged();
1051 else
1053 else
1052 axes->setAxisY(defaultAxis(Qt::Vertical, series));
1054 axes->setAxisY(defaultAxis(Qt::Vertical, series));
1053 }
1055 }
1054
1056
1055 #include "moc_declarativechart.cpp"
1057 #include "moc_declarativechart.cpp"
1056
1058
1057 QT_CHARTS_END_NAMESPACE
1059 QT_CHARTS_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now