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