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