@@ -1,1054 +1,1054 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2014 Digia Plc |
|
3 | ** Copyright (C) 2014 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Enterprise Charts Add-on. |
|
7 | ** This file is part of the Qt Enterprise Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
11 | ** accordance with the Qt Enterprise License Agreement provided with the |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "declarativechart.h" |
|
21 | #include "declarativechart.h" | |
22 | #include <QPainter> |
|
22 | #include <QPainter> | |
23 | #include "declarativelineseries.h" |
|
23 | #include "declarativelineseries.h" | |
24 | #include "declarativeareaseries.h" |
|
24 | #include "declarativeareaseries.h" | |
25 | #include "declarativebarseries.h" |
|
25 | #include "declarativebarseries.h" | |
26 | #include "declarativepieseries.h" |
|
26 | #include "declarativepieseries.h" | |
27 | #include "declarativesplineseries.h" |
|
27 | #include "declarativesplineseries.h" | |
28 | #include "declarativeboxplotseries.h" |
|
28 | #include "declarativeboxplotseries.h" | |
29 | #include "declarativescatterseries.h" |
|
29 | #include "declarativescatterseries.h" | |
30 | #include "qbarcategoryaxis.h" |
|
30 | #include "qbarcategoryaxis.h" | |
31 | #include "qvalueaxis.h" |
|
31 | #include "qvalueaxis.h" | |
32 | #include "qlogvalueaxis.h" |
|
32 | #include "qlogvalueaxis.h" | |
33 | #include "qcategoryaxis.h" |
|
33 | #include "qcategoryaxis.h" | |
34 | #include "qabstractseries_p.h" |
|
34 | #include "qabstractseries_p.h" | |
35 | #include "declarativemargins.h" |
|
35 | #include "declarativemargins.h" | |
36 | #include "chartdataset_p.h" |
|
36 | #include "chartdataset_p.h" | |
37 | #include "declarativeaxes.h" |
|
37 | #include "declarativeaxes.h" | |
38 | #include "qchart_p.h" |
|
38 | #include "qchart_p.h" | |
39 | #include "qpolarchart.h" |
|
39 | #include "qpolarchart.h" | |
40 |
|
40 | |||
41 | #ifndef QT_ON_ARM |
|
41 | #ifndef QT_ON_ARM | |
42 | #include "qdatetimeaxis.h" |
|
42 | #include "qdatetimeaxis.h" | |
43 | #endif |
|
43 | #endif | |
44 |
|
44 | |||
45 | #ifdef CHARTS_FOR_QUICK2 |
|
45 | #ifdef CHARTS_FOR_QUICK2 | |
46 | #include <QGraphicsSceneMouseEvent> |
|
46 | #include <QGraphicsSceneMouseEvent> | |
47 | #include <QGraphicsSceneHoverEvent> |
|
47 | #include <QGraphicsSceneHoverEvent> | |
48 | #include <QApplication> |
|
48 | #include <QApplication> | |
49 | #include <QTimer> |
|
49 | #include <QTimer> | |
50 | #include <QThread> |
|
50 | #include <QThread> | |
51 | #endif |
|
51 | #endif | |
52 |
|
52 | |||
53 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
53 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
54 |
|
54 | |||
55 | #ifdef QDOC_QT5 |
|
55 | #ifdef QDOC_QT5 | |
56 | /*! |
|
56 | /*! | |
57 | \qmltype ChartView |
|
57 | \qmltype ChartView | |
58 | \instantiates DeclarativeChart |
|
58 | \instantiates DeclarativeChart | |
59 | \inqmlmodule QtCommercial.Chart |
|
59 | \inqmlmodule QtCommercial.Chart | |
60 |
|
60 | |||
61 | \include doc/src/chartview.qdocinc |
|
61 | \include doc/src/chartview.qdocinc | |
62 | */ |
|
62 | */ | |
63 | #else |
|
63 | #else | |
64 | /*! |
|
64 | /*! | |
65 | \qmlclass ChartView DeclarativeChart |
|
65 | \qmlclass ChartView DeclarativeChart | |
66 |
|
66 | |||
67 | \include ../doc/src/chartview.qdocinc |
|
67 | \include ../doc/src/chartview.qdocinc | |
68 | */ |
|
68 | */ | |
69 | #endif |
|
69 | #endif | |
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 cirle at the corners of the chart background. |
|
119 | The diameter of the rounding cirle 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 bool ChartView::dropShadowEnabled |
|
130 | \qmlproperty bool ChartView::dropShadowEnabled | |
131 | The chart's border drop shadow. Set to true to enable drop shadow. |
|
131 | The chart's border drop shadow. Set to true to enable drop shadow. | |
132 | */ |
|
132 | */ | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | \qmlproperty real ChartView::topMargin |
|
135 | \qmlproperty real ChartView::topMargin | |
136 | Deprecated; use margins instead. |
|
136 | Deprecated; use margins instead. | |
137 | */ |
|
137 | */ | |
138 |
|
138 | |||
139 | /*! |
|
139 | /*! | |
140 | \qmlproperty real ChartView::bottomMargin |
|
140 | \qmlproperty real ChartView::bottomMargin | |
141 | Deprecated; use margins instead. |
|
141 | Deprecated; use margins instead. | |
142 | */ |
|
142 | */ | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \qmlproperty real ChartView::leftMargin |
|
145 | \qmlproperty real ChartView::leftMargin | |
146 | Deprecated; use margins instead. |
|
146 | Deprecated; use margins instead. | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | \qmlproperty real ChartView::rightMargin |
|
150 | \qmlproperty real ChartView::rightMargin | |
151 | Deprecated; use margins instead. |
|
151 | Deprecated; use margins instead. | |
152 | */ |
|
152 | */ | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | \qmlproperty Margins ChartView::minimumMargins |
|
155 | \qmlproperty Margins ChartView::minimumMargins | |
156 | Deprecated; use margins instead. |
|
156 | Deprecated; use margins instead. | |
157 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins |
|
157 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins | |
158 | area of ChartView is used for drawing title, axes and legend. Please note that setting the |
|
158 | area of ChartView is used for drawing title, axes and legend. Please note that setting the | |
159 | properties of minimumMargins may be bigger than the defined value, depending on other ChartView |
|
159 | properties of minimumMargins may be bigger than the defined value, depending on other ChartView | |
160 | properties that affect it's layout. If you need to know the actual plotting area used at any |
|
160 | properties that affect it's layout. If you need to know the actual plotting area used at any | |
161 | given time, you can check ChartView::plotArea instead. |
|
161 | given time, you can check ChartView::plotArea instead. | |
162 | */ |
|
162 | */ | |
163 |
|
163 | |||
164 | /*! |
|
164 | /*! | |
165 | \qmlproperty rect ChartView::plotArea |
|
165 | \qmlproperty rect ChartView::plotArea | |
166 | The area on the ChartView that is used for drawing series. This is the ChartView rect without the |
|
166 | The area on the ChartView that is used for drawing series. This is the ChartView rect without the | |
167 | margins. |
|
167 | margins. | |
168 | \sa ChartView::minimumMargins |
|
168 | \sa ChartView::minimumMargins | |
169 | */ |
|
169 | */ | |
170 |
|
170 | |||
171 | /*! |
|
171 | /*! | |
172 | \qmlproperty Margins ChartView::margins |
|
172 | \qmlproperty Margins ChartView::margins | |
173 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins |
|
173 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins | |
174 | area of ChartView is used for drawing title, axes and legend. |
|
174 | area of ChartView is used for drawing title, axes and legend. | |
175 | */ |
|
175 | */ | |
176 |
|
176 | |||
177 | /*! |
|
177 | /*! | |
178 | \qmlproperty bool ChartView::localizeNumbers |
|
178 | \qmlproperty bool ChartView::localizeNumbers | |
179 | \since QtCharts 2.0 |
|
179 | \since QtCharts 2.0 | |
180 | When \c{true}, all generated numbers appearing in various series and axis labels will be |
|
180 | When \c{true}, all generated numbers appearing in various series and axis labels will be | |
181 | localized using the default QLocale of the application, which defaults to the system locale. |
|
181 | localized using the default QLocale of the application, which defaults to the system locale. | |
182 | When \c{false}, the "C" locale is always used. |
|
182 | When \c{false}, the "C" locale is always used. | |
183 |
Defaults to \c{ |
|
183 | Defaults to \c{true}. | |
184 | */ |
|
184 | */ | |
185 |
|
185 | |||
186 | /*! |
|
186 | /*! | |
187 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
187 | \qmlmethod AbstractSeries ChartView::series(int index) | |
188 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
188 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with | |
189 | the count property of the chart. |
|
189 | the count property of the chart. | |
190 | */ |
|
190 | */ | |
191 |
|
191 | |||
192 | /*! |
|
192 | /*! | |
193 | \qmlmethod AbstractSeries ChartView::series(string name) |
|
193 | \qmlmethod AbstractSeries ChartView::series(string name) | |
194 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. |
|
194 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. | |
195 | */ |
|
195 | */ | |
196 |
|
196 | |||
197 | /*! |
|
197 | /*! | |
198 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY) |
|
198 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY) | |
199 | Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and |
|
199 | Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and | |
200 | optional axis \a axisY. For example: |
|
200 | optional axis \a axisY. For example: | |
201 | \code |
|
201 | \code | |
202 | // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes |
|
202 | // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes | |
203 | var myAxisX = chartView.axisX(lineSeries); |
|
203 | var myAxisX = chartView.axisX(lineSeries); | |
204 | var myAxisY = chartView.axisY(lineSeries); |
|
204 | var myAxisY = chartView.axisY(lineSeries); | |
205 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY); |
|
205 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY); | |
206 | \endcode |
|
206 | \endcode | |
207 | */ |
|
207 | */ | |
208 |
|
208 | |||
209 | /*! |
|
209 | /*! | |
210 | \qmlmethod ChartView::removeSeries(AbstractSeries series) |
|
210 | \qmlmethod ChartView::removeSeries(AbstractSeries series) | |
211 | Removes the \a series from the chart. The series object is also destroyed. |
|
211 | Removes the \a series from the chart. The series object is also destroyed. | |
212 | */ |
|
212 | */ | |
213 |
|
213 | |||
214 | /*! |
|
214 | /*! | |
215 | \qmlmethod ChartView::removeAllSeries() |
|
215 | \qmlmethod ChartView::removeAllSeries() | |
216 | Removes all series from the chart. All the series objects are also destroyed. |
|
216 | Removes all series from the chart. All the series objects are also destroyed. | |
217 | */ |
|
217 | */ | |
218 |
|
218 | |||
219 | /*! |
|
219 | /*! | |
220 | \qmlmethod Axis ChartView::axisX(AbstractSeries series) |
|
220 | \qmlmethod Axis ChartView::axisX(AbstractSeries series) | |
221 | The x-axis of the series. |
|
221 | The x-axis of the series. | |
222 | */ |
|
222 | */ | |
223 |
|
223 | |||
224 | /*! |
|
224 | /*! | |
225 | \qmlmethod Axis ChartView::axisY(AbstractSeries series) |
|
225 | \qmlmethod Axis ChartView::axisY(AbstractSeries series) | |
226 | The y-axis of the series. |
|
226 | The y-axis of the series. | |
227 | */ |
|
227 | */ | |
228 |
|
228 | |||
229 | /*! |
|
229 | /*! | |
230 | \qmlmethod ChartView::zoomY(real factor) |
|
230 | \qmlmethod ChartView::zoomY(real factor) | |
231 | Zooms in by \a factor on the center of the chart. |
|
231 | Zooms in by \a factor on the center of the chart. | |
232 | */ |
|
232 | */ | |
233 |
|
233 | |||
234 | /*! |
|
234 | /*! | |
235 | \qmlmethod ChartView::scrollLeft(real pixels) |
|
235 | \qmlmethod ChartView::scrollLeft(real pixels) | |
236 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. |
|
236 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. | |
237 | */ |
|
237 | */ | |
238 |
|
238 | |||
239 | /*! |
|
239 | /*! | |
240 | \qmlmethod ChartView::scrollRight(real pixels) |
|
240 | \qmlmethod ChartView::scrollRight(real pixels) | |
241 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. |
|
241 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. | |
242 | */ |
|
242 | */ | |
243 |
|
243 | |||
244 | /*! |
|
244 | /*! | |
245 | \qmlmethod ChartView::scrollUp(real pixels) |
|
245 | \qmlmethod ChartView::scrollUp(real pixels) | |
246 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. |
|
246 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. | |
247 | */ |
|
247 | */ | |
248 |
|
248 | |||
249 | /*! |
|
249 | /*! | |
250 | \qmlmethod ChartView::scrollDown(real pixels) |
|
250 | \qmlmethod ChartView::scrollDown(real pixels) | |
251 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. |
|
251 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. | |
252 | */ |
|
252 | */ | |
253 |
|
253 | |||
254 | /*! |
|
254 | /*! | |
255 | \qmlsignal ChartView::onPlotAreaChanged(rect plotArea) |
|
255 | \qmlsignal ChartView::onPlotAreaChanged(rect plotArea) | |
256 | The plot area of the chart has changed. This may happen for example, if you modify minimumMargins |
|
256 | The plot area of the chart has changed. This may happen for example, if you modify minimumMargins | |
257 | or if you resize the chart, or if you modify font size related properties of the legend or chart |
|
257 | or if you resize the chart, or if you modify font size related properties of the legend or chart | |
258 | title. |
|
258 | title. | |
259 | */ |
|
259 | */ | |
260 |
|
260 | |||
261 | /*! |
|
261 | /*! | |
262 | \qmlsignal ChartView::seriesAdded(AbstractSeries series) |
|
262 | \qmlsignal ChartView::seriesAdded(AbstractSeries series) | |
263 | The \a series has been added to the chart. |
|
263 | The \a series has been added to the chart. | |
264 | */ |
|
264 | */ | |
265 |
|
265 | |||
266 | /*! |
|
266 | /*! | |
267 | \qmlsignal ChartView::seriesRemoved(AbstractSeries series) |
|
267 | \qmlsignal ChartView::seriesRemoved(AbstractSeries series) | |
268 | The \a series has been removed from the chart. Please note that \a series is no longer a valid |
|
268 | The \a series has been removed from the chart. Please note that \a series is no longer a valid | |
269 | object after the signal handler has completed. |
|
269 | object after the signal handler has completed. | |
270 | */ |
|
270 | */ | |
271 |
|
271 | |||
272 | DeclarativeChart::DeclarativeChart(QDECLARATIVE_ITEM *parent) |
|
272 | DeclarativeChart::DeclarativeChart(QDECLARATIVE_ITEM *parent) | |
273 | : QDECLARATIVE_PAINTED_ITEM(parent) |
|
273 | : QDECLARATIVE_PAINTED_ITEM(parent) | |
274 | { |
|
274 | { | |
275 | initChart(QChart::ChartTypeCartesian); |
|
275 | initChart(QChart::ChartTypeCartesian); | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | DeclarativeChart::DeclarativeChart(QChart::ChartType type, QDECLARATIVE_ITEM *parent) |
|
278 | DeclarativeChart::DeclarativeChart(QChart::ChartType type, QDECLARATIVE_ITEM *parent) | |
279 | : QDECLARATIVE_PAINTED_ITEM(parent) |
|
279 | : QDECLARATIVE_PAINTED_ITEM(parent) | |
280 | { |
|
280 | { | |
281 | initChart(type); |
|
281 | initChart(type); | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | void DeclarativeChart::initChart(QChart::ChartType type) |
|
284 | void DeclarativeChart::initChart(QChart::ChartType type) | |
285 | { |
|
285 | { | |
286 | #ifdef CHARTS_FOR_QUICK2 |
|
286 | #ifdef CHARTS_FOR_QUICK2 | |
287 | m_currentSceneImage = 0; |
|
287 | m_currentSceneImage = 0; | |
288 | m_guiThreadId = QThread::currentThreadId(); |
|
288 | m_guiThreadId = QThread::currentThreadId(); | |
289 | m_paintThreadId = 0; |
|
289 | m_paintThreadId = 0; | |
290 | m_updatePending = false; |
|
290 | m_updatePending = false; | |
291 |
|
291 | |||
292 | if (type == QChart::ChartTypePolar) |
|
292 | if (type == QChart::ChartTypePolar) | |
293 | m_chart = new QPolarChart(); |
|
293 | m_chart = new QPolarChart(); | |
294 | else |
|
294 | else | |
295 | m_chart = new QChart(); |
|
295 | m_chart = new QChart(); | |
296 |
|
296 | |||
297 | m_scene = new QGraphicsScene(this); |
|
297 | m_scene = new QGraphicsScene(this); | |
298 | m_scene->addItem(m_chart); |
|
298 | m_scene->addItem(m_chart); | |
299 |
|
299 | |||
300 | setAntialiasing(QQuickItem::antialiasing()); |
|
300 | setAntialiasing(QQuickItem::antialiasing()); | |
301 | connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(sceneChanged(QList<QRectF>))); |
|
301 | connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(sceneChanged(QList<QRectF>))); | |
302 | connect(this, SIGNAL(antialiasingChanged(bool)), this, SLOT(handleAntialiasingChanged(bool))); |
|
302 | connect(this, SIGNAL(antialiasingChanged(bool)), this, SLOT(handleAntialiasingChanged(bool))); | |
303 |
|
303 | |||
304 | setAcceptedMouseButtons(Qt::AllButtons); |
|
304 | setAcceptedMouseButtons(Qt::AllButtons); | |
305 | setAcceptHoverEvents(true); |
|
305 | setAcceptHoverEvents(true); | |
306 | #else |
|
306 | #else | |
307 | if (type == QChart::ChartTypePolar) |
|
307 | if (type == QChart::ChartTypePolar) | |
308 | m_chart = new QPolarChart(this); |
|
308 | m_chart = new QPolarChart(this); | |
309 | else |
|
309 | else | |
310 | m_chart = new QChart(this); |
|
310 | m_chart = new QChart(this); | |
311 |
|
311 | |||
312 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
312 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
313 | #endif |
|
313 | #endif | |
314 |
|
314 | |||
315 | m_margins = new DeclarativeMargins(this); |
|
315 | m_margins = new DeclarativeMargins(this); | |
316 | m_margins->setTop(m_chart->margins().top()); |
|
316 | m_margins->setTop(m_chart->margins().top()); | |
317 | m_margins->setLeft(m_chart->margins().left()); |
|
317 | m_margins->setLeft(m_chart->margins().left()); | |
318 | m_margins->setRight(m_chart->margins().right()); |
|
318 | m_margins->setRight(m_chart->margins().right()); | |
319 | m_margins->setBottom(m_chart->margins().bottom()); |
|
319 | m_margins->setBottom(m_chart->margins().bottom()); | |
320 | connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
320 | connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); | |
321 | connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
321 | connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); | |
322 | connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
322 | connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); | |
323 | connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
323 | connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); | |
324 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
324 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
325 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
325 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
326 | } |
|
326 | } | |
327 |
|
327 | |||
328 | void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series) |
|
328 | void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series) | |
329 | { |
|
329 | { | |
330 | emit seriesAdded(series); |
|
330 | emit seriesAdded(series); | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 | void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right) |
|
333 | void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right) | |
334 | { |
|
334 | { | |
335 | m_chart->setMargins(QMargins(left, top, right, bottom)); |
|
335 | m_chart->setMargins(QMargins(left, top, right, bottom)); | |
336 | emit minimumMarginsChanged(); |
|
336 | emit minimumMarginsChanged(); | |
337 | emit plotAreaChanged(m_chart->plotArea()); |
|
337 | emit plotAreaChanged(m_chart->plotArea()); | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | DeclarativeChart::~DeclarativeChart() |
|
340 | DeclarativeChart::~DeclarativeChart() | |
341 | { |
|
341 | { | |
342 | delete m_chart; |
|
342 | delete m_chart; | |
343 | #ifdef CHARTS_FOR_QUICK2 |
|
343 | #ifdef CHARTS_FOR_QUICK2 | |
344 | m_sceneImageLock.lock(); |
|
344 | m_sceneImageLock.lock(); | |
345 | delete m_currentSceneImage; |
|
345 | delete m_currentSceneImage; | |
346 | m_currentSceneImage = 0; |
|
346 | m_currentSceneImage = 0; | |
347 | m_sceneImageLock.unlock(); |
|
347 | m_sceneImageLock.unlock(); | |
348 | #endif |
|
348 | #endif | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
351 | void DeclarativeChart::childEvent(QChildEvent *event) | |
352 | { |
|
352 | { | |
353 | if (event->type() == QEvent::ChildAdded) { |
|
353 | if (event->type() == QEvent::ChildAdded) { | |
354 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
354 | if (qobject_cast<QAbstractSeries *>(event->child())) { | |
355 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
355 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); | |
356 | } |
|
356 | } | |
357 | } |
|
357 | } | |
358 | } |
|
358 | } | |
359 |
|
359 | |||
360 | void DeclarativeChart::componentComplete() |
|
360 | void DeclarativeChart::componentComplete() | |
361 | { |
|
361 | { | |
362 | foreach (QObject *child, children()) { |
|
362 | foreach (QObject *child, children()) { | |
363 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
363 | if (qobject_cast<QAbstractSeries *>(child)) { | |
364 | // Add series to the chart |
|
364 | // Add series to the chart | |
365 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child); |
|
365 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child); | |
366 | m_chart->addSeries(series); |
|
366 | m_chart->addSeries(series); | |
367 |
|
367 | |||
368 | // Connect to axis changed signals (unless this is a pie series) |
|
368 | // Connect to axis changed signals (unless this is a pie series) | |
369 | if (!qobject_cast<DeclarativePieSeries *>(series)) { |
|
369 | if (!qobject_cast<DeclarativePieSeries *>(series)) { | |
370 | connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
370 | connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
371 | connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXTopSet(QAbstractAxis*))); |
|
371 | connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXTopSet(QAbstractAxis*))); | |
372 | connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
372 | connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
373 | connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); |
|
373 | connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); | |
374 | } |
|
374 | } | |
375 |
|
375 | |||
376 | initializeAxes(series); |
|
376 | initializeAxes(series); | |
377 | } |
|
377 | } | |
378 | } |
|
378 | } | |
379 |
|
379 | |||
380 | QDECLARATIVE_ITEM::componentComplete(); |
|
380 | QDECLARATIVE_ITEM::componentComplete(); | |
381 | } |
|
381 | } | |
382 |
|
382 | |||
383 | void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis) |
|
383 | void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis) | |
384 | { |
|
384 | { | |
385 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
385 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); | |
386 | if (axis && s) { |
|
386 | if (axis && s) { | |
387 | if (!m_chart->axes(Qt::Horizontal).contains(axis)) |
|
387 | if (!m_chart->axes(Qt::Horizontal).contains(axis)) | |
388 | m_chart->setAxisX(axis, s); |
|
388 | m_chart->setAxisX(axis, s); | |
389 | if (!s->attachedAxes().contains(axis)) |
|
389 | if (!s->attachedAxes().contains(axis)) | |
390 | s->attachAxis(axis); |
|
390 | s->attachAxis(axis); | |
391 | } else { |
|
391 | } else { | |
392 | qWarning() << "Trying to set axisX to null."; |
|
392 | qWarning() << "Trying to set axisX to null."; | |
393 | } |
|
393 | } | |
394 | } |
|
394 | } | |
395 |
|
395 | |||
396 | void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis) |
|
396 | void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis) | |
397 | { |
|
397 | { | |
398 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
398 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); | |
399 | if (axis && s) { |
|
399 | if (axis && s) { | |
400 | if (!m_chart->axes(Qt::Horizontal).contains(axis)) { |
|
400 | if (!m_chart->axes(Qt::Horizontal).contains(axis)) { | |
401 | QList<QAbstractAxis *> oldAxes = m_chart->axes(Qt::Horizontal, s); |
|
401 | QList<QAbstractAxis *> oldAxes = m_chart->axes(Qt::Horizontal, s); | |
402 | foreach (QAbstractAxis* a, oldAxes) { |
|
402 | foreach (QAbstractAxis* a, oldAxes) { | |
403 | m_chart->removeAxis(a); |
|
403 | m_chart->removeAxis(a); | |
404 | delete a; |
|
404 | delete a; | |
405 | } |
|
405 | } | |
406 | m_chart->addAxis(axis, Qt::AlignTop); |
|
406 | m_chart->addAxis(axis, Qt::AlignTop); | |
407 | } |
|
407 | } | |
408 | if (!s->attachedAxes().contains(axis)) |
|
408 | if (!s->attachedAxes().contains(axis)) | |
409 | s->attachAxis(axis); |
|
409 | s->attachAxis(axis); | |
410 | } else { |
|
410 | } else { | |
411 | qWarning() << "Trying to set axisXTop to null."; |
|
411 | qWarning() << "Trying to set axisXTop to null."; | |
412 | } |
|
412 | } | |
413 | } |
|
413 | } | |
414 |
|
414 | |||
415 | void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis) |
|
415 | void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis) | |
416 | { |
|
416 | { | |
417 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
417 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); | |
418 | if (axis && s) { |
|
418 | if (axis && s) { | |
419 | if (!m_chart->axes(Qt::Vertical).contains(axis)) |
|
419 | if (!m_chart->axes(Qt::Vertical).contains(axis)) | |
420 | m_chart->setAxisY(axis, s); |
|
420 | m_chart->setAxisY(axis, s); | |
421 | if (!s->attachedAxes().contains(axis)) |
|
421 | if (!s->attachedAxes().contains(axis)) | |
422 | s->attachAxis(axis); |
|
422 | s->attachAxis(axis); | |
423 | } else { |
|
423 | } else { | |
424 | qWarning() << "Trying to set axisY to null."; |
|
424 | qWarning() << "Trying to set axisY to null."; | |
425 | } |
|
425 | } | |
426 | } |
|
426 | } | |
427 |
|
427 | |||
428 | void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis) |
|
428 | void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis) | |
429 | { |
|
429 | { | |
430 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
430 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); | |
431 | if (axis && s) { |
|
431 | if (axis && s) { | |
432 | if (!m_chart->axes(Qt::Vertical).contains(axis)) { |
|
432 | if (!m_chart->axes(Qt::Vertical).contains(axis)) { | |
433 | QList<QAbstractAxis *> oldAxes = m_chart->axes((Qt::Vertical), s); |
|
433 | QList<QAbstractAxis *> oldAxes = m_chart->axes((Qt::Vertical), s); | |
434 | foreach (QAbstractAxis* a, oldAxes) { |
|
434 | foreach (QAbstractAxis* a, oldAxes) { | |
435 | m_chart->removeAxis(a); |
|
435 | m_chart->removeAxis(a); | |
436 | delete a; |
|
436 | delete a; | |
437 | } |
|
437 | } | |
438 | m_chart->addAxis(axis, Qt::AlignRight); |
|
438 | m_chart->addAxis(axis, Qt::AlignRight); | |
439 | } |
|
439 | } | |
440 | if (!s->attachedAxes().contains(axis)) |
|
440 | if (!s->attachedAxes().contains(axis)) | |
441 | s->attachAxis(axis); |
|
441 | s->attachAxis(axis); | |
442 | } else { |
|
442 | } else { | |
443 | qWarning() << "Trying to set axisYRight to null."; |
|
443 | qWarning() << "Trying to set axisYRight to null."; | |
444 | } |
|
444 | } | |
445 | } |
|
445 | } | |
446 |
|
446 | |||
447 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
447 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) | |
448 | { |
|
448 | { | |
449 | if (newGeometry.isValid()) { |
|
449 | if (newGeometry.isValid()) { | |
450 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
450 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { | |
451 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
451 | m_chart->resize(newGeometry.width(), newGeometry.height()); | |
452 | } |
|
452 | } | |
453 | } |
|
453 | } | |
454 | QDECLARATIVE_ITEM::geometryChanged(newGeometry, oldGeometry); |
|
454 | QDECLARATIVE_ITEM::geometryChanged(newGeometry, oldGeometry); | |
455 |
|
455 | |||
456 | // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or |
|
456 | // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or | |
457 | // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is |
|
457 | // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is | |
458 | // to implement it here for the QML API purposes. |
|
458 | // to implement it here for the QML API purposes. | |
459 | emit plotAreaChanged(m_chart->plotArea()); |
|
459 | emit plotAreaChanged(m_chart->plotArea()); | |
460 | } |
|
460 | } | |
461 |
|
461 | |||
462 | #ifdef CHARTS_FOR_QUICK2 |
|
462 | #ifdef CHARTS_FOR_QUICK2 | |
463 | void DeclarativeChart::sceneChanged(QList<QRectF> region) |
|
463 | void DeclarativeChart::sceneChanged(QList<QRectF> region) | |
464 | { |
|
464 | { | |
465 | Q_UNUSED(region); |
|
465 | Q_UNUSED(region); | |
466 |
|
466 | |||
467 | if (m_guiThreadId == m_paintThreadId) { |
|
467 | if (m_guiThreadId == m_paintThreadId) { | |
468 | // Rendering in gui thread, no need for shenannigans, just update |
|
468 | // Rendering in gui thread, no need for shenannigans, just update | |
469 | update(); |
|
469 | update(); | |
470 | } else { |
|
470 | } else { | |
471 | // Multi-threaded rendering, need to ensure scene is actually rendered in gui thread |
|
471 | // Multi-threaded rendering, need to ensure scene is actually rendered in gui thread | |
472 | if (!m_updatePending) { |
|
472 | if (!m_updatePending) { | |
473 | m_updatePending = true; |
|
473 | m_updatePending = true; | |
474 | // Do async render to avoid some unnecessary renders. |
|
474 | // Do async render to avoid some unnecessary renders. | |
475 | QTimer::singleShot(0, this, SLOT(renderScene())); |
|
475 | QTimer::singleShot(0, this, SLOT(renderScene())); | |
476 | } |
|
476 | } | |
477 | } |
|
477 | } | |
478 | } |
|
478 | } | |
479 |
|
479 | |||
480 | void DeclarativeChart::renderScene() |
|
480 | void DeclarativeChart::renderScene() | |
481 | { |
|
481 | { | |
482 | m_updatePending = false; |
|
482 | m_updatePending = false; | |
483 | m_sceneImageLock.lock(); |
|
483 | m_sceneImageLock.lock(); | |
484 | delete m_currentSceneImage; |
|
484 | delete m_currentSceneImage; | |
485 | m_currentSceneImage = new QImage(m_chart->size().toSize(), QImage::Format_ARGB32); |
|
485 | m_currentSceneImage = new QImage(m_chart->size().toSize(), QImage::Format_ARGB32); | |
486 | m_currentSceneImage->fill(Qt::transparent); |
|
486 | m_currentSceneImage->fill(Qt::transparent); | |
487 | QPainter painter(m_currentSceneImage); |
|
487 | QPainter painter(m_currentSceneImage); | |
488 | if (antialiasing()) |
|
488 | if (antialiasing()) | |
489 | painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); |
|
489 | painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); | |
490 | QRect renderRect(QPoint(0, 0), m_chart->size().toSize()); |
|
490 | QRect renderRect(QPoint(0, 0), m_chart->size().toSize()); | |
491 | m_scene->render(&painter, renderRect, renderRect); |
|
491 | m_scene->render(&painter, renderRect, renderRect); | |
492 | m_sceneImageLock.unlock(); |
|
492 | m_sceneImageLock.unlock(); | |
493 |
|
493 | |||
494 | update(); |
|
494 | update(); | |
495 | } |
|
495 | } | |
496 |
|
496 | |||
497 | void DeclarativeChart::paint(QPainter *painter) |
|
497 | void DeclarativeChart::paint(QPainter *painter) | |
498 | { |
|
498 | { | |
499 | if (!m_paintThreadId) { |
|
499 | if (!m_paintThreadId) { | |
500 | m_paintThreadId = QThread::currentThreadId(); |
|
500 | m_paintThreadId = QThread::currentThreadId(); | |
501 | if (m_guiThreadId == m_paintThreadId) { |
|
501 | if (m_guiThreadId == m_paintThreadId) { | |
502 | // No need for scene image in single threaded rendering, so delete |
|
502 | // No need for scene image in single threaded rendering, so delete | |
503 | // the one that got made by default before the rendering type was |
|
503 | // the one that got made by default before the rendering type was | |
504 | // detected. |
|
504 | // detected. | |
505 | delete m_currentSceneImage; |
|
505 | delete m_currentSceneImage; | |
506 | m_currentSceneImage = 0; |
|
506 | m_currentSceneImage = 0; | |
507 | } |
|
507 | } | |
508 | } |
|
508 | } | |
509 |
|
509 | |||
510 | if (m_guiThreadId == m_paintThreadId) { |
|
510 | if (m_guiThreadId == m_paintThreadId) { | |
511 | QRectF renderRect(QPointF(0, 0), m_chart->size()); |
|
511 | QRectF renderRect(QPointF(0, 0), m_chart->size()); | |
512 | m_scene->render(painter, renderRect, renderRect); |
|
512 | m_scene->render(painter, renderRect, renderRect); | |
513 | } else { |
|
513 | } else { | |
514 | m_sceneImageLock.lock(); |
|
514 | m_sceneImageLock.lock(); | |
515 | if (m_currentSceneImage) { |
|
515 | if (m_currentSceneImage) { | |
516 | QRect imageRect(QPoint(0, 0), m_currentSceneImage->size()); |
|
516 | QRect imageRect(QPoint(0, 0), m_currentSceneImage->size()); | |
517 | QRect itemRect(QPoint(0, 0), QSize(width(), height())); |
|
517 | QRect itemRect(QPoint(0, 0), QSize(width(), height())); | |
518 | painter->drawImage(itemRect, *m_currentSceneImage, imageRect); |
|
518 | painter->drawImage(itemRect, *m_currentSceneImage, imageRect); | |
519 | } |
|
519 | } | |
520 | m_sceneImageLock.unlock(); |
|
520 | m_sceneImageLock.unlock(); | |
521 | } |
|
521 | } | |
522 | } |
|
522 | } | |
523 |
|
523 | |||
524 | void DeclarativeChart::mousePressEvent(QMouseEvent *event) |
|
524 | void DeclarativeChart::mousePressEvent(QMouseEvent *event) | |
525 | { |
|
525 | { | |
526 | m_mousePressScenePoint = event->pos(); |
|
526 | m_mousePressScenePoint = event->pos(); | |
527 | m_mousePressScreenPoint = event->globalPos(); |
|
527 | m_mousePressScreenPoint = event->globalPos(); | |
528 | m_lastMouseMoveScenePoint = m_mousePressScenePoint; |
|
528 | m_lastMouseMoveScenePoint = m_mousePressScenePoint; | |
529 | m_lastMouseMoveScreenPoint = m_mousePressScreenPoint; |
|
529 | m_lastMouseMoveScreenPoint = m_mousePressScreenPoint; | |
530 | m_mousePressButton = event->button(); |
|
530 | m_mousePressButton = event->button(); | |
531 | m_mousePressButtons = event->buttons(); |
|
531 | m_mousePressButtons = event->buttons(); | |
532 |
|
532 | |||
533 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMousePress); |
|
533 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMousePress); | |
534 | mouseEvent.setWidget(0); |
|
534 | mouseEvent.setWidget(0); | |
535 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
535 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); | |
536 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
536 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); | |
537 | mouseEvent.setScenePos(m_mousePressScenePoint); |
|
537 | mouseEvent.setScenePos(m_mousePressScenePoint); | |
538 | mouseEvent.setScreenPos(m_mousePressScreenPoint); |
|
538 | mouseEvent.setScreenPos(m_mousePressScreenPoint); | |
539 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
539 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); | |
540 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
540 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); | |
541 | mouseEvent.setButtons(m_mousePressButtons); |
|
541 | mouseEvent.setButtons(m_mousePressButtons); | |
542 | mouseEvent.setButton(m_mousePressButton); |
|
542 | mouseEvent.setButton(m_mousePressButton); | |
543 | mouseEvent.setModifiers(event->modifiers()); |
|
543 | mouseEvent.setModifiers(event->modifiers()); | |
544 | mouseEvent.setAccepted(false); |
|
544 | mouseEvent.setAccepted(false); | |
545 |
|
545 | |||
546 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
546 | QApplication::sendEvent(m_scene, &mouseEvent); | |
547 | } |
|
547 | } | |
548 |
|
548 | |||
549 | void DeclarativeChart::mouseReleaseEvent(QMouseEvent *event) |
|
549 | void DeclarativeChart::mouseReleaseEvent(QMouseEvent *event) | |
550 | { |
|
550 | { | |
551 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseRelease); |
|
551 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseRelease); | |
552 | mouseEvent.setWidget(0); |
|
552 | mouseEvent.setWidget(0); | |
553 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
553 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); | |
554 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
554 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); | |
555 | mouseEvent.setScenePos(event->pos()); |
|
555 | mouseEvent.setScenePos(event->pos()); | |
556 | mouseEvent.setScreenPos(event->globalPos()); |
|
556 | mouseEvent.setScreenPos(event->globalPos()); | |
557 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
557 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); | |
558 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
558 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); | |
559 | mouseEvent.setButtons(event->buttons()); |
|
559 | mouseEvent.setButtons(event->buttons()); | |
560 | mouseEvent.setButton(event->button()); |
|
560 | mouseEvent.setButton(event->button()); | |
561 | mouseEvent.setModifiers(event->modifiers()); |
|
561 | mouseEvent.setModifiers(event->modifiers()); | |
562 | mouseEvent.setAccepted(false); |
|
562 | mouseEvent.setAccepted(false); | |
563 |
|
563 | |||
564 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
564 | QApplication::sendEvent(m_scene, &mouseEvent); | |
565 |
|
565 | |||
566 | m_mousePressButtons = event->buttons(); |
|
566 | m_mousePressButtons = event->buttons(); | |
567 | m_mousePressButton = Qt::NoButton; |
|
567 | m_mousePressButton = Qt::NoButton; | |
568 | } |
|
568 | } | |
569 |
|
569 | |||
570 | void DeclarativeChart::hoverMoveEvent(QHoverEvent *event) |
|
570 | void DeclarativeChart::hoverMoveEvent(QHoverEvent *event) | |
571 | { |
|
571 | { | |
572 | // Convert hover move to mouse move, since we don't seem to get actual mouse move events. |
|
572 | // Convert hover move to mouse move, since we don't seem to get actual mouse move events. | |
573 | // QGraphicsScene generates hover events from mouse move events, so we don't need |
|
573 | // QGraphicsScene generates hover events from mouse move events, so we don't need | |
574 | // to pass hover events there. |
|
574 | // to pass hover events there. | |
575 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); |
|
575 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); | |
576 | mouseEvent.setWidget(0); |
|
576 | mouseEvent.setWidget(0); | |
577 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
577 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); | |
578 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
578 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); | |
579 | mouseEvent.setScenePos(event->pos()); |
|
579 | mouseEvent.setScenePos(event->pos()); | |
580 | // Hover events do not have global pos in them, and the screen position doesn't seem to |
|
580 | // Hover events do not have global pos in them, and the screen position doesn't seem to | |
581 | // matter anyway in this use case, so just pass event pos instead of trying to |
|
581 | // matter anyway in this use case, so just pass event pos instead of trying to | |
582 | // calculate the real screen position. |
|
582 | // calculate the real screen position. | |
583 | mouseEvent.setScreenPos(event->pos()); |
|
583 | mouseEvent.setScreenPos(event->pos()); | |
584 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
584 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); | |
585 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
585 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); | |
586 | mouseEvent.setButtons(m_mousePressButtons); |
|
586 | mouseEvent.setButtons(m_mousePressButtons); | |
587 | mouseEvent.setButton(m_mousePressButton); |
|
587 | mouseEvent.setButton(m_mousePressButton); | |
588 | mouseEvent.setModifiers(event->modifiers()); |
|
588 | mouseEvent.setModifiers(event->modifiers()); | |
589 | m_lastMouseMoveScenePoint = mouseEvent.scenePos(); |
|
589 | m_lastMouseMoveScenePoint = mouseEvent.scenePos(); | |
590 | m_lastMouseMoveScreenPoint = mouseEvent.screenPos(); |
|
590 | m_lastMouseMoveScreenPoint = mouseEvent.screenPos(); | |
591 | mouseEvent.setAccepted(false); |
|
591 | mouseEvent.setAccepted(false); | |
592 |
|
592 | |||
593 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
593 | QApplication::sendEvent(m_scene, &mouseEvent); | |
594 | } |
|
594 | } | |
595 |
|
595 | |||
596 | void DeclarativeChart::handleAntialiasingChanged(bool enable) |
|
596 | void DeclarativeChart::handleAntialiasingChanged(bool enable) | |
597 | { |
|
597 | { | |
598 | setAntialiasing(enable); |
|
598 | setAntialiasing(enable); | |
599 | } |
|
599 | } | |
600 | #endif |
|
600 | #endif | |
601 |
|
601 | |||
602 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
602 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) | |
603 | { |
|
603 | { | |
604 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
604 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; | |
605 | if (chartTheme != m_chart->theme()) |
|
605 | if (chartTheme != m_chart->theme()) | |
606 | m_chart->setTheme(chartTheme); |
|
606 | m_chart->setTheme(chartTheme); | |
607 | } |
|
607 | } | |
608 |
|
608 | |||
609 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
609 | DeclarativeChart::Theme DeclarativeChart::theme() | |
610 | { |
|
610 | { | |
611 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
611 | return (DeclarativeChart::Theme) m_chart->theme(); | |
612 | } |
|
612 | } | |
613 |
|
613 | |||
614 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
614 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) | |
615 | { |
|
615 | { | |
616 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
616 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; | |
617 | if (animationOptions != m_chart->animationOptions()) |
|
617 | if (animationOptions != m_chart->animationOptions()) | |
618 | m_chart->setAnimationOptions(animationOptions); |
|
618 | m_chart->setAnimationOptions(animationOptions); | |
619 | } |
|
619 | } | |
620 |
|
620 | |||
621 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
621 | DeclarativeChart::Animation DeclarativeChart::animationOptions() | |
622 | { |
|
622 | { | |
623 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
623 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) | |
624 | return DeclarativeChart::AllAnimations; |
|
624 | return DeclarativeChart::AllAnimations; | |
625 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
625 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) | |
626 | return DeclarativeChart::GridAxisAnimations; |
|
626 | return DeclarativeChart::GridAxisAnimations; | |
627 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
627 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) | |
628 | return DeclarativeChart::SeriesAnimations; |
|
628 | return DeclarativeChart::SeriesAnimations; | |
629 | else |
|
629 | else | |
630 | return DeclarativeChart::NoAnimation; |
|
630 | return DeclarativeChart::NoAnimation; | |
631 | } |
|
631 | } | |
632 |
|
632 | |||
633 | void DeclarativeChart::setTitle(QString title) |
|
633 | void DeclarativeChart::setTitle(QString title) | |
634 | { |
|
634 | { | |
635 | if (title != m_chart->title()) |
|
635 | if (title != m_chart->title()) | |
636 | m_chart->setTitle(title); |
|
636 | m_chart->setTitle(title); | |
637 | } |
|
637 | } | |
638 | QString DeclarativeChart::title() |
|
638 | QString DeclarativeChart::title() | |
639 | { |
|
639 | { | |
640 | return m_chart->title(); |
|
640 | return m_chart->title(); | |
641 | } |
|
641 | } | |
642 |
|
642 | |||
643 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) |
|
643 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) | |
644 | { |
|
644 | { | |
645 | QList<QAbstractAxis *> axes = m_chart->axes(Qt::Horizontal, series); |
|
645 | QList<QAbstractAxis *> axes = m_chart->axes(Qt::Horizontal, series); | |
646 | if (axes.count()) |
|
646 | if (axes.count()) | |
647 | return axes[0]; |
|
647 | return axes[0]; | |
648 | return 0; |
|
648 | return 0; | |
649 | } |
|
649 | } | |
650 |
|
650 | |||
651 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
651 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) | |
652 | { |
|
652 | { | |
653 | QList<QAbstractAxis *> axes = m_chart->axes(Qt::Vertical, series); |
|
653 | QList<QAbstractAxis *> axes = m_chart->axes(Qt::Vertical, series); | |
654 | if (axes.count()) |
|
654 | if (axes.count()) | |
655 | return axes[0]; |
|
655 | return axes[0]; | |
656 | return 0; |
|
656 | return 0; | |
657 | } |
|
657 | } | |
658 |
|
658 | |||
659 | QLegend *DeclarativeChart::legend() |
|
659 | QLegend *DeclarativeChart::legend() | |
660 | { |
|
660 | { | |
661 | return m_chart->legend(); |
|
661 | return m_chart->legend(); | |
662 | } |
|
662 | } | |
663 |
|
663 | |||
664 | void DeclarativeChart::setTitleColor(QColor color) |
|
664 | void DeclarativeChart::setTitleColor(QColor color) | |
665 | { |
|
665 | { | |
666 | QBrush b = m_chart->titleBrush(); |
|
666 | QBrush b = m_chart->titleBrush(); | |
667 | if (color != b.color()) { |
|
667 | if (color != b.color()) { | |
668 | b.setColor(color); |
|
668 | b.setColor(color); | |
669 | m_chart->setTitleBrush(b); |
|
669 | m_chart->setTitleBrush(b); | |
670 | emit titleColorChanged(color); |
|
670 | emit titleColorChanged(color); | |
671 | } |
|
671 | } | |
672 | } |
|
672 | } | |
673 |
|
673 | |||
674 | QFont DeclarativeChart::titleFont() const |
|
674 | QFont DeclarativeChart::titleFont() const | |
675 | { |
|
675 | { | |
676 | return m_chart->titleFont(); |
|
676 | return m_chart->titleFont(); | |
677 | } |
|
677 | } | |
678 |
|
678 | |||
679 | void DeclarativeChart::setTitleFont(const QFont &font) |
|
679 | void DeclarativeChart::setTitleFont(const QFont &font) | |
680 | { |
|
680 | { | |
681 | m_chart->setTitleFont(font); |
|
681 | m_chart->setTitleFont(font); | |
682 | } |
|
682 | } | |
683 |
|
683 | |||
684 | QColor DeclarativeChart::titleColor() |
|
684 | QColor DeclarativeChart::titleColor() | |
685 | { |
|
685 | { | |
686 | return m_chart->titleBrush().color(); |
|
686 | return m_chart->titleBrush().color(); | |
687 | } |
|
687 | } | |
688 |
|
688 | |||
689 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
689 | void DeclarativeChart::setBackgroundColor(QColor color) | |
690 | { |
|
690 | { | |
691 | QBrush b = m_chart->backgroundBrush(); |
|
691 | QBrush b = m_chart->backgroundBrush(); | |
692 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
692 | if (b.style() != Qt::SolidPattern || color != b.color()) { | |
693 | b.setStyle(Qt::SolidPattern); |
|
693 | b.setStyle(Qt::SolidPattern); | |
694 | b.setColor(color); |
|
694 | b.setColor(color); | |
695 | m_chart->setBackgroundBrush(b); |
|
695 | m_chart->setBackgroundBrush(b); | |
696 | emit backgroundColorChanged(); |
|
696 | emit backgroundColorChanged(); | |
697 | } |
|
697 | } | |
698 | } |
|
698 | } | |
699 |
|
699 | |||
700 | QColor DeclarativeChart::backgroundColor() |
|
700 | QColor DeclarativeChart::backgroundColor() | |
701 | { |
|
701 | { | |
702 | return m_chart->backgroundBrush().color(); |
|
702 | return m_chart->backgroundBrush().color(); | |
703 | } |
|
703 | } | |
704 |
|
704 | |||
705 | void QtCommercialChart::DeclarativeChart::setPlotAreaColor(QColor color) |
|
705 | void QtCommercialChart::DeclarativeChart::setPlotAreaColor(QColor color) | |
706 | { |
|
706 | { | |
707 | QBrush b = m_chart->plotAreaBackgroundBrush(); |
|
707 | QBrush b = m_chart->plotAreaBackgroundBrush(); | |
708 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
708 | if (b.style() != Qt::SolidPattern || color != b.color()) { | |
709 | b.setStyle(Qt::SolidPattern); |
|
709 | b.setStyle(Qt::SolidPattern); | |
710 | b.setColor(color); |
|
710 | b.setColor(color); | |
711 | m_chart->setPlotAreaBackgroundBrush(b); |
|
711 | m_chart->setPlotAreaBackgroundBrush(b); | |
712 | m_chart->setPlotAreaBackgroundVisible(true); |
|
712 | m_chart->setPlotAreaBackgroundVisible(true); | |
713 | emit plotAreaColorChanged(); |
|
713 | emit plotAreaColorChanged(); | |
714 | } |
|
714 | } | |
715 | } |
|
715 | } | |
716 |
|
716 | |||
717 | QColor QtCommercialChart::DeclarativeChart::plotAreaColor() |
|
717 | QColor QtCommercialChart::DeclarativeChart::plotAreaColor() | |
718 | { |
|
718 | { | |
719 | return m_chart->plotAreaBackgroundBrush().color(); |
|
719 | return m_chart->plotAreaBackgroundBrush().color(); | |
720 | } |
|
720 | } | |
721 |
|
721 | |||
722 | void DeclarativeChart::setLocalizeNumbers(bool localize) |
|
722 | void DeclarativeChart::setLocalizeNumbers(bool localize) | |
723 | { |
|
723 | { | |
724 | if (m_chart->localizeNumbers() != localize) { |
|
724 | if (m_chart->localizeNumbers() != localize) { | |
725 | m_chart->setLocalizeNumbers(localize); |
|
725 | m_chart->setLocalizeNumbers(localize); | |
726 | emit localizeNumbersChanged(); |
|
726 | emit localizeNumbersChanged(); | |
727 | } |
|
727 | } | |
728 | } |
|
728 | } | |
729 |
|
729 | |||
730 | bool DeclarativeChart::localizeNumbers() const |
|
730 | bool DeclarativeChart::localizeNumbers() const | |
731 | { |
|
731 | { | |
732 | return m_chart->localizeNumbers(); |
|
732 | return m_chart->localizeNumbers(); | |
733 | } |
|
733 | } | |
734 |
|
734 | |||
735 | int DeclarativeChart::count() |
|
735 | int DeclarativeChart::count() | |
736 | { |
|
736 | { | |
737 | return m_chart->series().count(); |
|
737 | return m_chart->series().count(); | |
738 | } |
|
738 | } | |
739 |
|
739 | |||
740 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
740 | void DeclarativeChart::setDropShadowEnabled(bool enabled) | |
741 | { |
|
741 | { | |
742 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
742 | if (enabled != m_chart->isDropShadowEnabled()) { | |
743 | m_chart->setDropShadowEnabled(enabled); |
|
743 | m_chart->setDropShadowEnabled(enabled); | |
744 | dropShadowEnabledChanged(enabled); |
|
744 | dropShadowEnabledChanged(enabled); | |
745 | } |
|
745 | } | |
746 | } |
|
746 | } | |
747 |
|
747 | |||
748 | bool DeclarativeChart::dropShadowEnabled() |
|
748 | bool DeclarativeChart::dropShadowEnabled() | |
749 | { |
|
749 | { | |
750 | return m_chart->isDropShadowEnabled(); |
|
750 | return m_chart->isDropShadowEnabled(); | |
751 | } |
|
751 | } | |
752 |
|
752 | |||
753 | qreal DeclarativeChart::backgroundRoundness() const |
|
753 | qreal DeclarativeChart::backgroundRoundness() const | |
754 | { |
|
754 | { | |
755 | return m_chart->backgroundRoundness(); |
|
755 | return m_chart->backgroundRoundness(); | |
756 | } |
|
756 | } | |
757 |
|
757 | |||
758 | void DeclarativeChart::setBackgroundRoundness(qreal diameter) |
|
758 | void DeclarativeChart::setBackgroundRoundness(qreal diameter) | |
759 | { |
|
759 | { | |
760 | if (m_chart->backgroundRoundness() != diameter) { |
|
760 | if (m_chart->backgroundRoundness() != diameter) { | |
761 | m_chart->setBackgroundRoundness(diameter); |
|
761 | m_chart->setBackgroundRoundness(diameter); | |
762 | emit backgroundRoundnessChanged(diameter); |
|
762 | emit backgroundRoundnessChanged(diameter); | |
763 | } |
|
763 | } | |
764 | } |
|
764 | } | |
765 |
|
765 | |||
766 | qreal DeclarativeChart::topMargin() |
|
766 | qreal DeclarativeChart::topMargin() | |
767 | { |
|
767 | { | |
768 | qWarning() << "ChartView.topMargin is deprecated. Use margins instead."; |
|
768 | qWarning() << "ChartView.topMargin is deprecated. Use margins instead."; | |
769 | return m_chart->margins().top(); |
|
769 | return m_chart->margins().top(); | |
770 | } |
|
770 | } | |
771 |
|
771 | |||
772 | qreal DeclarativeChart::bottomMargin() |
|
772 | qreal DeclarativeChart::bottomMargin() | |
773 | { |
|
773 | { | |
774 | qWarning() << "ChartView.bottomMargin is deprecated. Use margins instead."; |
|
774 | qWarning() << "ChartView.bottomMargin is deprecated. Use margins instead."; | |
775 | return m_chart->margins().bottom(); |
|
775 | return m_chart->margins().bottom(); | |
776 | } |
|
776 | } | |
777 |
|
777 | |||
778 | qreal DeclarativeChart::leftMargin() |
|
778 | qreal DeclarativeChart::leftMargin() | |
779 | { |
|
779 | { | |
780 | qWarning() << "ChartView.leftMargin is deprecated. Use margins instead."; |
|
780 | qWarning() << "ChartView.leftMargin is deprecated. Use margins instead."; | |
781 | return m_chart->margins().left(); |
|
781 | return m_chart->margins().left(); | |
782 | } |
|
782 | } | |
783 |
|
783 | |||
784 | qreal DeclarativeChart::rightMargin() |
|
784 | qreal DeclarativeChart::rightMargin() | |
785 | { |
|
785 | { | |
786 | qWarning() << "ChartView.rightMargin is deprecated. Use margins instead."; |
|
786 | qWarning() << "ChartView.rightMargin is deprecated. Use margins instead."; | |
787 | return m_chart->margins().right(); |
|
787 | return m_chart->margins().right(); | |
788 | } |
|
788 | } | |
789 |
|
789 | |||
790 | void DeclarativeChart::zoom(qreal factor) |
|
790 | void DeclarativeChart::zoom(qreal factor) | |
791 | { |
|
791 | { | |
792 | m_chart->zoom(factor); |
|
792 | m_chart->zoom(factor); | |
793 | } |
|
793 | } | |
794 |
|
794 | |||
795 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
795 | void DeclarativeChart::scrollLeft(qreal pixels) | |
796 | { |
|
796 | { | |
797 | m_chart->scroll(-pixels, 0); |
|
797 | m_chart->scroll(-pixels, 0); | |
798 | } |
|
798 | } | |
799 |
|
799 | |||
800 | void DeclarativeChart::scrollRight(qreal pixels) |
|
800 | void DeclarativeChart::scrollRight(qreal pixels) | |
801 | { |
|
801 | { | |
802 | m_chart->scroll(pixels, 0); |
|
802 | m_chart->scroll(pixels, 0); | |
803 | } |
|
803 | } | |
804 |
|
804 | |||
805 | void DeclarativeChart::scrollUp(qreal pixels) |
|
805 | void DeclarativeChart::scrollUp(qreal pixels) | |
806 | { |
|
806 | { | |
807 | m_chart->scroll(0, pixels); |
|
807 | m_chart->scroll(0, pixels); | |
808 | } |
|
808 | } | |
809 |
|
809 | |||
810 | void DeclarativeChart::scrollDown(qreal pixels) |
|
810 | void DeclarativeChart::scrollDown(qreal pixels) | |
811 | { |
|
811 | { | |
812 | m_chart->scroll(0, -pixels); |
|
812 | m_chart->scroll(0, -pixels); | |
813 | } |
|
813 | } | |
814 |
|
814 | |||
815 | QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> DeclarativeChart::axes() |
|
815 | QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> DeclarativeChart::axes() | |
816 | { |
|
816 | { | |
817 | return QDECLARATIVE_LIST_PROPERTY<QAbstractAxis>(this, 0, |
|
817 | return QDECLARATIVE_LIST_PROPERTY<QAbstractAxis>(this, 0, | |
818 | &DeclarativeChart::axesAppendFunc, |
|
818 | &DeclarativeChart::axesAppendFunc, | |
819 | &DeclarativeChart::axesCountFunc, |
|
819 | &DeclarativeChart::axesCountFunc, | |
820 | #ifdef CHARTS_FOR_QUICK2 |
|
820 | #ifdef CHARTS_FOR_QUICK2 | |
821 | &DeclarativeChart::axesAtFunc, |
|
821 | &DeclarativeChart::axesAtFunc, | |
822 | &DeclarativeChart::axesClearFunc); |
|
822 | &DeclarativeChart::axesClearFunc); | |
823 | #else |
|
823 | #else | |
824 | &DeclarativeChart::axesAtFunc); |
|
824 | &DeclarativeChart::axesAtFunc); | |
825 | #endif |
|
825 | #endif | |
826 | } |
|
826 | } | |
827 |
|
827 | |||
828 | void DeclarativeChart::axesAppendFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, QAbstractAxis *element) |
|
828 | void DeclarativeChart::axesAppendFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, QAbstractAxis *element) | |
829 | { |
|
829 | { | |
830 | // Empty implementation |
|
830 | // Empty implementation | |
831 | Q_UNUSED(list); |
|
831 | Q_UNUSED(list); | |
832 | Q_UNUSED(element); |
|
832 | Q_UNUSED(element); | |
833 | } |
|
833 | } | |
834 |
|
834 | |||
835 | int DeclarativeChart::axesCountFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list) |
|
835 | int DeclarativeChart::axesCountFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list) | |
836 | { |
|
836 | { | |
837 | if (qobject_cast<DeclarativeChart *>(list->object)) { |
|
837 | if (qobject_cast<DeclarativeChart *>(list->object)) { | |
838 | DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object); |
|
838 | DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object); | |
839 | return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical).count(); |
|
839 | return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical).count(); | |
840 | } |
|
840 | } | |
841 | return 0; |
|
841 | return 0; | |
842 | } |
|
842 | } | |
843 |
|
843 | |||
844 | QAbstractAxis *DeclarativeChart::axesAtFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, int index) |
|
844 | QAbstractAxis *DeclarativeChart::axesAtFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, int index) | |
845 | { |
|
845 | { | |
846 | if (qobject_cast<DeclarativeChart *>(list->object)) { |
|
846 | if (qobject_cast<DeclarativeChart *>(list->object)) { | |
847 | DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object); |
|
847 | DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object); | |
848 | QList<QAbstractAxis *> axes = chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]); |
|
848 | QList<QAbstractAxis *> axes = chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]); | |
849 | return axes.at(index); |
|
849 | return axes.at(index); | |
850 | } |
|
850 | } | |
851 | return 0; |
|
851 | return 0; | |
852 | } |
|
852 | } | |
853 |
|
853 | |||
854 | void DeclarativeChart::axesClearFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list) |
|
854 | void DeclarativeChart::axesClearFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list) | |
855 | { |
|
855 | { | |
856 | // Empty implementation |
|
856 | // Empty implementation | |
857 | Q_UNUSED(list); |
|
857 | Q_UNUSED(list); | |
858 | } |
|
858 | } | |
859 |
|
859 | |||
860 |
|
860 | |||
861 | QAbstractSeries *DeclarativeChart::series(int index) |
|
861 | QAbstractSeries *DeclarativeChart::series(int index) | |
862 | { |
|
862 | { | |
863 | if (index < m_chart->series().count()) { |
|
863 | if (index < m_chart->series().count()) { | |
864 | return m_chart->series().at(index); |
|
864 | return m_chart->series().at(index); | |
865 | } |
|
865 | } | |
866 | return 0; |
|
866 | return 0; | |
867 | } |
|
867 | } | |
868 |
|
868 | |||
869 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
869 | QAbstractSeries *DeclarativeChart::series(QString seriesName) | |
870 | { |
|
870 | { | |
871 | foreach (QAbstractSeries *series, m_chart->series()) { |
|
871 | foreach (QAbstractSeries *series, m_chart->series()) { | |
872 | if (series->name() == seriesName) |
|
872 | if (series->name() == seriesName) | |
873 | return series; |
|
873 | return series; | |
874 | } |
|
874 | } | |
875 | return 0; |
|
875 | return 0; | |
876 | } |
|
876 | } | |
877 |
|
877 | |||
878 | QAbstractSeries *DeclarativeChart::createSeries(int type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY) |
|
878 | QAbstractSeries *DeclarativeChart::createSeries(int type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY) | |
879 | { |
|
879 | { | |
880 | QAbstractSeries *series = 0; |
|
880 | QAbstractSeries *series = 0; | |
881 |
|
881 | |||
882 | switch (type) { |
|
882 | switch (type) { | |
883 | case DeclarativeChart::SeriesTypeLine: |
|
883 | case DeclarativeChart::SeriesTypeLine: | |
884 | series = new DeclarativeLineSeries(); |
|
884 | series = new DeclarativeLineSeries(); | |
885 | break; |
|
885 | break; | |
886 | case DeclarativeChart::SeriesTypeArea: { |
|
886 | case DeclarativeChart::SeriesTypeArea: { | |
887 | DeclarativeAreaSeries *area = new DeclarativeAreaSeries(); |
|
887 | DeclarativeAreaSeries *area = new DeclarativeAreaSeries(); | |
888 | area->setUpperSeries(new DeclarativeLineSeries()); |
|
888 | area->setUpperSeries(new DeclarativeLineSeries()); | |
889 | series = area; |
|
889 | series = area; | |
890 | break; |
|
890 | break; | |
891 | } |
|
891 | } | |
892 | case DeclarativeChart::SeriesTypeStackedBar: |
|
892 | case DeclarativeChart::SeriesTypeStackedBar: | |
893 | series = new DeclarativeStackedBarSeries(); |
|
893 | series = new DeclarativeStackedBarSeries(); | |
894 | break; |
|
894 | break; | |
895 | case DeclarativeChart::SeriesTypePercentBar: |
|
895 | case DeclarativeChart::SeriesTypePercentBar: | |
896 | series = new DeclarativePercentBarSeries(); |
|
896 | series = new DeclarativePercentBarSeries(); | |
897 | break; |
|
897 | break; | |
898 | case DeclarativeChart::SeriesTypeBar: |
|
898 | case DeclarativeChart::SeriesTypeBar: | |
899 | series = new DeclarativeBarSeries(); |
|
899 | series = new DeclarativeBarSeries(); | |
900 | break; |
|
900 | break; | |
901 | case DeclarativeChart::SeriesTypeHorizontalBar: |
|
901 | case DeclarativeChart::SeriesTypeHorizontalBar: | |
902 | series = new DeclarativeHorizontalBarSeries(); |
|
902 | series = new DeclarativeHorizontalBarSeries(); | |
903 | break; |
|
903 | break; | |
904 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: |
|
904 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: | |
905 | series = new DeclarativeHorizontalPercentBarSeries(); |
|
905 | series = new DeclarativeHorizontalPercentBarSeries(); | |
906 | break; |
|
906 | break; | |
907 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: |
|
907 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: | |
908 | series = new DeclarativeHorizontalStackedBarSeries(); |
|
908 | series = new DeclarativeHorizontalStackedBarSeries(); | |
909 | break; |
|
909 | break; | |
910 | case DeclarativeChart::SeriesTypeBoxPlot: |
|
910 | case DeclarativeChart::SeriesTypeBoxPlot: | |
911 | series = new DeclarativeBoxPlotSeries(); |
|
911 | series = new DeclarativeBoxPlotSeries(); | |
912 | break; |
|
912 | break; | |
913 | case DeclarativeChart::SeriesTypePie: |
|
913 | case DeclarativeChart::SeriesTypePie: | |
914 | series = new DeclarativePieSeries(); |
|
914 | series = new DeclarativePieSeries(); | |
915 | break; |
|
915 | break; | |
916 | case DeclarativeChart::SeriesTypeScatter: |
|
916 | case DeclarativeChart::SeriesTypeScatter: | |
917 | series = new DeclarativeScatterSeries(); |
|
917 | series = new DeclarativeScatterSeries(); | |
918 | break; |
|
918 | break; | |
919 | case DeclarativeChart::SeriesTypeSpline: |
|
919 | case DeclarativeChart::SeriesTypeSpline: | |
920 | series = new DeclarativeSplineSeries(); |
|
920 | series = new DeclarativeSplineSeries(); | |
921 | break; |
|
921 | break; | |
922 | default: |
|
922 | default: | |
923 | qWarning() << "Illegal series type"; |
|
923 | qWarning() << "Illegal series type"; | |
924 | } |
|
924 | } | |
925 |
|
925 | |||
926 | if (series) { |
|
926 | if (series) { | |
927 | // Connect to axis changed signals (unless this is a pie series) |
|
927 | // Connect to axis changed signals (unless this is a pie series) | |
928 | if (!qobject_cast<DeclarativePieSeries *>(series)) { |
|
928 | if (!qobject_cast<DeclarativePieSeries *>(series)) { | |
929 | connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
929 | connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
930 | connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
930 | connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
931 | connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
931 | connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
932 | connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); |
|
932 | connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); | |
933 | } |
|
933 | } | |
934 |
|
934 | |||
935 | series->setName(name); |
|
935 | series->setName(name); | |
936 | m_chart->addSeries(series); |
|
936 | m_chart->addSeries(series); | |
937 |
|
937 | |||
938 | if (axisX) |
|
938 | if (axisX) | |
939 | setAxisX(axisX, series); |
|
939 | setAxisX(axisX, series); | |
940 | if (axisY) |
|
940 | if (axisY) | |
941 | setAxisY(axisY, series); |
|
941 | setAxisY(axisY, series); | |
942 |
|
942 | |||
943 | if (series->attachedAxes().count() < 2) |
|
943 | if (series->attachedAxes().count() < 2) | |
944 | initializeAxes(series); |
|
944 | initializeAxes(series); | |
945 | } |
|
945 | } | |
946 |
|
946 | |||
947 | return series; |
|
947 | return series; | |
948 | } |
|
948 | } | |
949 |
|
949 | |||
950 | void DeclarativeChart::removeSeries(QAbstractSeries *series) |
|
950 | void DeclarativeChart::removeSeries(QAbstractSeries *series) | |
951 | { |
|
951 | { | |
952 | if (series) |
|
952 | if (series) | |
953 | m_chart->removeSeries(series); |
|
953 | m_chart->removeSeries(series); | |
954 | else |
|
954 | else | |
955 | qWarning("removeSeries: cannot remove null"); |
|
955 | qWarning("removeSeries: cannot remove null"); | |
956 | } |
|
956 | } | |
957 |
|
957 | |||
958 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) |
|
958 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) | |
959 | { |
|
959 | { | |
960 | if (axis) |
|
960 | if (axis) | |
961 | m_chart->setAxisX(axis, series); |
|
961 | m_chart->setAxisX(axis, series); | |
962 | } |
|
962 | } | |
963 |
|
963 | |||
964 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) |
|
964 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) | |
965 | { |
|
965 | { | |
966 | if (axis) |
|
966 | if (axis) | |
967 | m_chart->setAxisY(axis, series); |
|
967 | m_chart->setAxisY(axis, series); | |
968 | } |
|
968 | } | |
969 |
|
969 | |||
970 | void DeclarativeChart::createDefaultAxes() |
|
970 | void DeclarativeChart::createDefaultAxes() | |
971 | { |
|
971 | { | |
972 | qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; |
|
972 | qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; | |
973 | } |
|
973 | } | |
974 |
|
974 | |||
975 | QAbstractAxis *DeclarativeChart::defaultAxis(Qt::Orientation orientation, QAbstractSeries *series) |
|
975 | QAbstractAxis *DeclarativeChart::defaultAxis(Qt::Orientation orientation, QAbstractSeries *series) | |
976 | { |
|
976 | { | |
977 | if (!series) { |
|
977 | if (!series) { | |
978 | qWarning() << "No axis type defined for null series"; |
|
978 | qWarning() << "No axis type defined for null series"; | |
979 | return 0; |
|
979 | return 0; | |
980 | } |
|
980 | } | |
981 |
|
981 | |||
982 | foreach (QAbstractAxis *existingAxis, m_chart->axes(orientation)) { |
|
982 | foreach (QAbstractAxis *existingAxis, m_chart->axes(orientation)) { | |
983 | if (existingAxis->type() == series->d_ptr->defaultAxisType(orientation)) |
|
983 | if (existingAxis->type() == series->d_ptr->defaultAxisType(orientation)) | |
984 | return existingAxis; |
|
984 | return existingAxis; | |
985 | } |
|
985 | } | |
986 |
|
986 | |||
987 | switch (series->d_ptr->defaultAxisType(orientation)) { |
|
987 | switch (series->d_ptr->defaultAxisType(orientation)) { | |
988 | case QAbstractAxis::AxisTypeValue: |
|
988 | case QAbstractAxis::AxisTypeValue: | |
989 | return new QValueAxis(this); |
|
989 | return new QValueAxis(this); | |
990 | case QAbstractAxis::AxisTypeBarCategory: |
|
990 | case QAbstractAxis::AxisTypeBarCategory: | |
991 | return new QBarCategoryAxis(this); |
|
991 | return new QBarCategoryAxis(this); | |
992 | case QAbstractAxis::AxisTypeCategory: |
|
992 | case QAbstractAxis::AxisTypeCategory: | |
993 | return new QCategoryAxis(this); |
|
993 | return new QCategoryAxis(this); | |
994 | #ifndef QT_ON_ARM |
|
994 | #ifndef QT_ON_ARM | |
995 | case QAbstractAxis::AxisTypeDateTime: |
|
995 | case QAbstractAxis::AxisTypeDateTime: | |
996 | return new QDateTimeAxis(this); |
|
996 | return new QDateTimeAxis(this); | |
997 | #endif |
|
997 | #endif | |
998 | case QAbstractAxis::AxisTypeLogValue: |
|
998 | case QAbstractAxis::AxisTypeLogValue: | |
999 | return new QLogValueAxis(this); |
|
999 | return new QLogValueAxis(this); | |
1000 | default: |
|
1000 | default: | |
1001 | // assume AxisTypeNoAxis |
|
1001 | // assume AxisTypeNoAxis | |
1002 | return 0; |
|
1002 | return 0; | |
1003 | } |
|
1003 | } | |
1004 | } |
|
1004 | } | |
1005 |
|
1005 | |||
1006 | void DeclarativeChart::initializeAxes(QAbstractSeries *series) |
|
1006 | void DeclarativeChart::initializeAxes(QAbstractSeries *series) | |
1007 | { |
|
1007 | { | |
1008 | if (qobject_cast<DeclarativeLineSeries *>(series)) |
|
1008 | if (qobject_cast<DeclarativeLineSeries *>(series)) | |
1009 | doInitializeAxes(series, qobject_cast<DeclarativeLineSeries *>(series)->m_axes); |
|
1009 | doInitializeAxes(series, qobject_cast<DeclarativeLineSeries *>(series)->m_axes); | |
1010 | else if (qobject_cast<DeclarativeScatterSeries *>(series)) |
|
1010 | else if (qobject_cast<DeclarativeScatterSeries *>(series)) | |
1011 | doInitializeAxes(series, qobject_cast<DeclarativeScatterSeries *>(series)->m_axes); |
|
1011 | doInitializeAxes(series, qobject_cast<DeclarativeScatterSeries *>(series)->m_axes); | |
1012 | else if (qobject_cast<DeclarativeSplineSeries *>(series)) |
|
1012 | else if (qobject_cast<DeclarativeSplineSeries *>(series)) | |
1013 | doInitializeAxes(series, qobject_cast<DeclarativeSplineSeries *>(series)->m_axes); |
|
1013 | doInitializeAxes(series, qobject_cast<DeclarativeSplineSeries *>(series)->m_axes); | |
1014 | else if (qobject_cast<DeclarativeAreaSeries *>(series)) |
|
1014 | else if (qobject_cast<DeclarativeAreaSeries *>(series)) | |
1015 | doInitializeAxes(series, qobject_cast<DeclarativeAreaSeries *>(series)->m_axes); |
|
1015 | doInitializeAxes(series, qobject_cast<DeclarativeAreaSeries *>(series)->m_axes); | |
1016 | else if (qobject_cast<DeclarativeBarSeries *>(series)) |
|
1016 | else if (qobject_cast<DeclarativeBarSeries *>(series)) | |
1017 | doInitializeAxes(series, qobject_cast<DeclarativeBarSeries *>(series)->m_axes); |
|
1017 | doInitializeAxes(series, qobject_cast<DeclarativeBarSeries *>(series)->m_axes); | |
1018 | else if (qobject_cast<DeclarativeStackedBarSeries *>(series)) |
|
1018 | else if (qobject_cast<DeclarativeStackedBarSeries *>(series)) | |
1019 | doInitializeAxes(series, qobject_cast<DeclarativeStackedBarSeries *>(series)->m_axes); |
|
1019 | doInitializeAxes(series, qobject_cast<DeclarativeStackedBarSeries *>(series)->m_axes); | |
1020 | else if (qobject_cast<DeclarativePercentBarSeries *>(series)) |
|
1020 | else if (qobject_cast<DeclarativePercentBarSeries *>(series)) | |
1021 | doInitializeAxes(series, qobject_cast<DeclarativePercentBarSeries *>(series)->m_axes); |
|
1021 | doInitializeAxes(series, qobject_cast<DeclarativePercentBarSeries *>(series)->m_axes); | |
1022 | else if (qobject_cast<DeclarativeHorizontalBarSeries *>(series)) |
|
1022 | else if (qobject_cast<DeclarativeHorizontalBarSeries *>(series)) | |
1023 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalBarSeries *>(series)->m_axes); |
|
1023 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalBarSeries *>(series)->m_axes); | |
1024 | else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)) |
|
1024 | else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)) | |
1025 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)->m_axes); |
|
1025 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)->m_axes); | |
1026 | else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)) |
|
1026 | else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)) | |
1027 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)->m_axes); |
|
1027 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)->m_axes); | |
1028 | else if (qobject_cast<DeclarativeBoxPlotSeries *>(series)) |
|
1028 | else if (qobject_cast<DeclarativeBoxPlotSeries *>(series)) | |
1029 | doInitializeAxes(series, qobject_cast<DeclarativeBoxPlotSeries *>(series)->m_axes); |
|
1029 | doInitializeAxes(series, qobject_cast<DeclarativeBoxPlotSeries *>(series)->m_axes); | |
1030 | // else: do nothing |
|
1030 | // else: do nothing | |
1031 | } |
|
1031 | } | |
1032 |
|
1032 | |||
1033 | void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes) |
|
1033 | void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes) | |
1034 | { |
|
1034 | { | |
1035 | // Initialize axis X |
|
1035 | // Initialize axis X | |
1036 | if (axes->axisX()) |
|
1036 | if (axes->axisX()) | |
1037 | axes->emitAxisXChanged(); |
|
1037 | axes->emitAxisXChanged(); | |
1038 | else if (axes->axisXTop()) |
|
1038 | else if (axes->axisXTop()) | |
1039 | axes->emitAxisXTopChanged(); |
|
1039 | axes->emitAxisXTopChanged(); | |
1040 | else |
|
1040 | else | |
1041 | axes->setAxisX(defaultAxis(Qt::Horizontal, series)); |
|
1041 | axes->setAxisX(defaultAxis(Qt::Horizontal, series)); | |
1042 |
|
1042 | |||
1043 | // Initialize axis Y |
|
1043 | // Initialize axis Y | |
1044 | if (axes->axisY()) |
|
1044 | if (axes->axisY()) | |
1045 | axes->emitAxisYChanged(); |
|
1045 | axes->emitAxisYChanged(); | |
1046 | else if (axes->axisYRight()) |
|
1046 | else if (axes->axisYRight()) | |
1047 | axes->emitAxisYRightChanged(); |
|
1047 | axes->emitAxisYRightChanged(); | |
1048 | else |
|
1048 | else | |
1049 | axes->setAxisY(defaultAxis(Qt::Vertical, series)); |
|
1049 | axes->setAxisY(defaultAxis(Qt::Vertical, series)); | |
1050 | } |
|
1050 | } | |
1051 |
|
1051 | |||
1052 | #include "moc_declarativechart.cpp" |
|
1052 | #include "moc_declarativechart.cpp" | |
1053 |
|
1053 | |||
1054 | QTCOMMERCIALCHART_END_NAMESPACE |
|
1054 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,240 +1,240 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2014 Digia Plc |
|
3 | ** Copyright (C) 2014 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Enterprise Charts Add-on. |
|
7 | ** This file is part of the Qt Enterprise Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
11 | ** accordance with the Qt Enterprise License Agreement provided with the |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef DECLARATIVECHART_H |
|
21 | #ifndef DECLARATIVECHART_H | |
22 | #define DECLARATIVECHART_H |
|
22 | #define DECLARATIVECHART_H | |
23 |
|
23 | |||
24 | #include <QtCore/QtGlobal> |
|
24 | #include <QtCore/QtGlobal> | |
25 | #include "shared_defines.h" |
|
25 | #include "shared_defines.h" | |
26 |
|
26 | |||
27 | #ifdef CHARTS_FOR_QUICK2 |
|
27 | #ifdef CHARTS_FOR_QUICK2 | |
28 | #include <QtQuick/QQuickItem> |
|
28 | #include <QtQuick/QQuickItem> | |
29 | #include <QtQuick/QQuickPaintedItem> |
|
29 | #include <QtQuick/QQuickPaintedItem> | |
30 | #include <QtWidgets/QGraphicsScene> |
|
30 | #include <QtWidgets/QGraphicsScene> | |
31 | #include <QtCore/QMutex> |
|
31 | #include <QtCore/QMutex> | |
32 | #else |
|
32 | #else | |
33 | #include <QtDeclarative/QDeclarativeItem> |
|
33 | #include <QtDeclarative/QDeclarativeItem> | |
34 | #endif |
|
34 | #endif | |
35 |
|
35 | |||
36 | #include "qchart.h" |
|
36 | #include "qchart.h" | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | class DeclarativeMargins; |
|
40 | class DeclarativeMargins; | |
41 | class Domain; |
|
41 | class Domain; | |
42 | class DeclarativeAxes; |
|
42 | class DeclarativeAxes; | |
43 |
|
43 | |||
44 | class DeclarativeChart : public QDECLARATIVE_PAINTED_ITEM |
|
44 | class DeclarativeChart : public QDECLARATIVE_PAINTED_ITEM | |
45 | { |
|
45 | { | |
46 | Q_OBJECT |
|
46 | Q_OBJECT | |
47 | Q_PROPERTY(Theme theme READ theme WRITE setTheme) |
|
47 | Q_PROPERTY(Theme theme READ theme WRITE setTheme) | |
48 | Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions) |
|
48 | Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions) | |
49 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
49 | Q_PROPERTY(QString title READ title WRITE setTitle) | |
50 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) |
|
50 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) | |
51 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) |
|
51 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) | |
52 | Q_PROPERTY(QLegend *legend READ legend CONSTANT) |
|
52 | Q_PROPERTY(QLegend *legend READ legend CONSTANT) | |
53 | Q_PROPERTY(int count READ count) |
|
53 | Q_PROPERTY(int count READ count) | |
54 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) |
|
54 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) | |
55 | Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged) |
|
55 | Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged) | |
56 | Q_PROPERTY(qreal backgroundRoundness READ backgroundRoundness WRITE setBackgroundRoundness NOTIFY backgroundRoundnessChanged REVISION 3) |
|
56 | Q_PROPERTY(qreal backgroundRoundness READ backgroundRoundness WRITE setBackgroundRoundness NOTIFY backgroundRoundnessChanged REVISION 3) | |
57 | Q_PROPERTY(qreal topMargin READ topMargin) |
|
57 | Q_PROPERTY(qreal topMargin READ topMargin) | |
58 | Q_PROPERTY(qreal bottomMargin READ bottomMargin) |
|
58 | Q_PROPERTY(qreal bottomMargin READ bottomMargin) | |
59 | Q_PROPERTY(qreal leftMargin READ leftMargin) |
|
59 | Q_PROPERTY(qreal leftMargin READ leftMargin) | |
60 | Q_PROPERTY(qreal rightMargin READ rightMargin) |
|
60 | Q_PROPERTY(qreal rightMargin READ rightMargin) | |
61 | Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1) |
|
61 | Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1) | |
62 | Q_PROPERTY(DeclarativeMargins *margins READ margins NOTIFY marginsChanged REVISION 2) |
|
62 | Q_PROPERTY(DeclarativeMargins *margins READ margins NOTIFY marginsChanged REVISION 2) | |
63 | Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1) |
|
63 | Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1) | |
64 | Q_PROPERTY(QColor plotAreaColor READ plotAreaColor WRITE setPlotAreaColor NOTIFY plotAreaColorChanged REVISION 3) |
|
64 | Q_PROPERTY(QColor plotAreaColor READ plotAreaColor WRITE setPlotAreaColor NOTIFY plotAreaColorChanged REVISION 3) | |
65 | #ifdef CHARTS_FOR_QUICK2 |
|
65 | #ifdef CHARTS_FOR_QUICK2 | |
66 | Q_PROPERTY(QQmlListProperty<QAbstractAxis> axes READ axes REVISION 2) |
|
66 | Q_PROPERTY(QQmlListProperty<QAbstractAxis> axes READ axes REVISION 2) | |
67 | #else |
|
67 | #else | |
68 | Q_PROPERTY(QDeclarativeListProperty<QAbstractAxis> axes READ axes REVISION 2) |
|
68 | Q_PROPERTY(QDeclarativeListProperty<QAbstractAxis> axes READ axes REVISION 2) | |
69 | #endif |
|
69 | #endif | |
70 | Q_PROPERTY(bool localizeNumbers READ localizeNumbers WRITE setLocalizeNumbers NOTIFY localizeNumbersChanged REVISION 4) |
|
70 | Q_PROPERTY(bool localizeNumbers READ localizeNumbers WRITE setLocalizeNumbers NOTIFY localizeNumbersChanged REVISION 4) | |
71 | Q_ENUMS(Animation) |
|
71 | Q_ENUMS(Animation) | |
72 | Q_ENUMS(Theme) |
|
72 | Q_ENUMS(Theme) | |
73 | Q_ENUMS(SeriesType) |
|
73 | Q_ENUMS(SeriesType) | |
74 |
|
74 | |||
75 | public: |
|
75 | public: | |
76 | // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api |
|
76 | // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api | |
77 | enum Theme { |
|
77 | enum Theme { | |
78 | ChartThemeLight = 0, |
|
78 | ChartThemeLight = 0, | |
79 | ChartThemeBlueCerulean, |
|
79 | ChartThemeBlueCerulean, | |
80 | ChartThemeDark, |
|
80 | ChartThemeDark, | |
81 | ChartThemeBrownSand, |
|
81 | ChartThemeBrownSand, | |
82 | ChartThemeBlueNcs, |
|
82 | ChartThemeBlueNcs, | |
83 | ChartThemeHighContrast, |
|
83 | ChartThemeHighContrast, | |
84 | ChartThemeBlueIcy, |
|
84 | ChartThemeBlueIcy, | |
85 | ChartThemeQt |
|
85 | ChartThemeQt | |
86 | }; |
|
86 | }; | |
87 |
|
87 | |||
88 | enum Animation { |
|
88 | enum Animation { | |
89 | NoAnimation = 0x0, |
|
89 | NoAnimation = 0x0, | |
90 | GridAxisAnimations = 0x1, |
|
90 | GridAxisAnimations = 0x1, | |
91 | SeriesAnimations = 0x2, |
|
91 | SeriesAnimations = 0x2, | |
92 | AllAnimations = 0x3 |
|
92 | AllAnimations = 0x3 | |
93 | }; |
|
93 | }; | |
94 |
|
94 | |||
95 | enum SeriesType { |
|
95 | enum SeriesType { | |
96 | SeriesTypeLine, |
|
96 | SeriesTypeLine, | |
97 | SeriesTypeArea, |
|
97 | SeriesTypeArea, | |
98 | SeriesTypeBar, |
|
98 | SeriesTypeBar, | |
99 | SeriesTypeStackedBar, |
|
99 | SeriesTypeStackedBar, | |
100 | SeriesTypePercentBar, |
|
100 | SeriesTypePercentBar, | |
101 | SeriesTypeBoxPlot, |
|
101 | SeriesTypeBoxPlot, | |
102 | SeriesTypePie, |
|
102 | SeriesTypePie, | |
103 | SeriesTypeScatter, |
|
103 | SeriesTypeScatter, | |
104 | SeriesTypeSpline, |
|
104 | SeriesTypeSpline, | |
105 | SeriesTypeHorizontalBar, |
|
105 | SeriesTypeHorizontalBar, | |
106 | SeriesTypeHorizontalStackedBar, |
|
106 | SeriesTypeHorizontalStackedBar, | |
107 | SeriesTypeHorizontalPercentBar |
|
107 | SeriesTypeHorizontalPercentBar | |
108 | }; |
|
108 | }; | |
109 |
|
109 | |||
110 | public: |
|
110 | public: | |
111 | DeclarativeChart(QDECLARATIVE_ITEM *parent = 0); |
|
111 | DeclarativeChart(QDECLARATIVE_ITEM *parent = 0); | |
112 | ~DeclarativeChart(); |
|
112 | ~DeclarativeChart(); | |
113 |
|
113 | |||
114 | public: // From parent classes |
|
114 | public: // From parent classes | |
115 | void childEvent(QChildEvent *event); |
|
115 | void childEvent(QChildEvent *event); | |
116 | void componentComplete(); |
|
116 | void componentComplete(); | |
117 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
117 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); | |
118 | #ifdef CHARTS_FOR_QUICK2 |
|
118 | #ifdef CHARTS_FOR_QUICK2 | |
119 | void paint(QPainter *painter); |
|
119 | void paint(QPainter *painter); | |
120 | protected: |
|
120 | protected: | |
121 | void mousePressEvent(QMouseEvent *event); |
|
121 | void mousePressEvent(QMouseEvent *event); | |
122 | void mouseReleaseEvent(QMouseEvent *event); |
|
122 | void mouseReleaseEvent(QMouseEvent *event); | |
123 | void hoverMoveEvent(QHoverEvent *event); |
|
123 | void hoverMoveEvent(QHoverEvent *event); | |
124 | private Q_SLOTS: |
|
124 | private Q_SLOTS: | |
125 | void handleAntialiasingChanged(bool enable); |
|
125 | void handleAntialiasingChanged(bool enable); | |
126 | void sceneChanged(QList<QRectF> region); |
|
126 | void sceneChanged(QList<QRectF> region); | |
127 | void renderScene(); |
|
127 | void renderScene(); | |
128 | #endif |
|
128 | #endif | |
129 |
|
129 | |||
130 | public: |
|
130 | public: | |
131 | void setTheme(DeclarativeChart::Theme theme); |
|
131 | void setTheme(DeclarativeChart::Theme theme); | |
132 | DeclarativeChart::Theme theme(); |
|
132 | DeclarativeChart::Theme theme(); | |
133 | void setAnimationOptions(DeclarativeChart::Animation animations); |
|
133 | void setAnimationOptions(DeclarativeChart::Animation animations); | |
134 | DeclarativeChart::Animation animationOptions(); |
|
134 | DeclarativeChart::Animation animationOptions(); | |
135 | void setTitle(QString title); |
|
135 | void setTitle(QString title); | |
136 | QString title(); |
|
136 | QString title(); | |
137 | QLegend *legend(); |
|
137 | QLegend *legend(); | |
138 | QFont titleFont() const; |
|
138 | QFont titleFont() const; | |
139 | void setTitleFont(const QFont &font); |
|
139 | void setTitleFont(const QFont &font); | |
140 | void setTitleColor(QColor color); |
|
140 | void setTitleColor(QColor color); | |
141 | QColor titleColor(); |
|
141 | QColor titleColor(); | |
142 | void setBackgroundColor(QColor color); |
|
142 | void setBackgroundColor(QColor color); | |
143 | QColor backgroundColor(); |
|
143 | QColor backgroundColor(); | |
144 | Q_REVISION(3) void setPlotAreaColor(QColor color); |
|
144 | Q_REVISION(3) void setPlotAreaColor(QColor color); | |
145 | Q_REVISION(3) QColor plotAreaColor(); |
|
145 | Q_REVISION(3) QColor plotAreaColor(); | |
146 | Q_REVISION(4) void setLocalizeNumbers(bool localize); |
|
146 | Q_REVISION(4) void setLocalizeNumbers(bool localize); | |
147 | Q_REVISION(4) bool localizeNumbers() const; |
|
147 | Q_REVISION(4) bool localizeNumbers() const; | |
148 |
|
148 | |||
149 | int count(); |
|
149 | int count(); | |
150 | void setDropShadowEnabled(bool enabled); |
|
150 | void setDropShadowEnabled(bool enabled); | |
151 | bool dropShadowEnabled(); |
|
151 | bool dropShadowEnabled(); | |
152 | Q_REVISION(3) qreal backgroundRoundness() const; |
|
152 | Q_REVISION(3) qreal backgroundRoundness() const; | |
153 | Q_REVISION(3) void setBackgroundRoundness(qreal diameter); |
|
153 | Q_REVISION(3) void setBackgroundRoundness(qreal diameter); | |
154 |
|
154 | |||
155 | // Margins & plotArea |
|
155 | // Margins & plotArea | |
156 | qreal topMargin(); |
|
156 | qreal topMargin(); | |
157 | qreal bottomMargin(); |
|
157 | qreal bottomMargin(); | |
158 | qreal leftMargin(); |
|
158 | qreal leftMargin(); | |
159 | qreal rightMargin(); |
|
159 | qreal rightMargin(); | |
160 | DeclarativeMargins *minimumMargins() { return m_margins; } |
|
160 | DeclarativeMargins *minimumMargins() { return m_margins; } | |
161 | Q_REVISION(2) DeclarativeMargins *margins() { return m_margins; } |
|
161 | Q_REVISION(2) DeclarativeMargins *margins() { return m_margins; } | |
162 | QRectF plotArea() { return m_chart->plotArea(); } |
|
162 | QRectF plotArea() { return m_chart->plotArea(); } | |
163 |
|
163 | |||
164 | // Axis handling |
|
164 | // Axis handling | |
165 | QAbstractAxis *defaultAxis(Qt::Orientation orientation, QAbstractSeries *series); |
|
165 | QAbstractAxis *defaultAxis(Qt::Orientation orientation, QAbstractSeries *series); | |
166 | void initializeAxes(QAbstractSeries *series); |
|
166 | void initializeAxes(QAbstractSeries *series); | |
167 | void doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes); |
|
167 | void doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes); | |
168 | QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> axes(); |
|
168 | QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> axes(); | |
169 | static void axesAppendFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, QAbstractAxis *element); |
|
169 | static void axesAppendFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, QAbstractAxis *element); | |
170 | static int axesCountFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list); |
|
170 | static int axesCountFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list); | |
171 | static QAbstractAxis *axesAtFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, int index); |
|
171 | static QAbstractAxis *axesAtFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, int index); | |
172 | static void axesClearFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list); |
|
172 | static void axesClearFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list); | |
173 |
|
173 | |||
174 | public: |
|
174 | public: | |
175 | Q_INVOKABLE QAbstractSeries *series(int index); |
|
175 | Q_INVOKABLE QAbstractSeries *series(int index); | |
176 | Q_INVOKABLE QAbstractSeries *series(QString seriesName); |
|
176 | Q_INVOKABLE QAbstractSeries *series(QString seriesName); | |
177 | Q_INVOKABLE QAbstractSeries *createSeries(int type, QString name = "", QAbstractAxis *axisX = 0, QAbstractAxis *axisY = 0); |
|
177 | Q_INVOKABLE QAbstractSeries *createSeries(int type, QString name = "", QAbstractAxis *axisX = 0, QAbstractAxis *axisY = 0); | |
178 | Q_INVOKABLE void removeSeries(QAbstractSeries *series); |
|
178 | Q_INVOKABLE void removeSeries(QAbstractSeries *series); | |
179 | Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); } |
|
179 | Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); } | |
180 | Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
180 | Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); | |
181 | Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
181 | Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); | |
182 | Q_INVOKABLE void createDefaultAxes(); |
|
182 | Q_INVOKABLE void createDefaultAxes(); | |
183 | Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0); |
|
183 | Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0); | |
184 | Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0); |
|
184 | Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0); | |
185 | Q_INVOKABLE void zoom(qreal factor); |
|
185 | Q_INVOKABLE void zoom(qreal factor); | |
186 | Q_INVOKABLE void scrollLeft(qreal pixels); |
|
186 | Q_INVOKABLE void scrollLeft(qreal pixels); | |
187 | Q_INVOKABLE void scrollRight(qreal pixels); |
|
187 | Q_INVOKABLE void scrollRight(qreal pixels); | |
188 | Q_INVOKABLE void scrollUp(qreal pixels); |
|
188 | Q_INVOKABLE void scrollUp(qreal pixels); | |
189 | Q_INVOKABLE void scrollDown(qreal pixels); |
|
189 | Q_INVOKABLE void scrollDown(qreal pixels); | |
190 |
|
190 | |||
191 | Q_SIGNALS: |
|
191 | Q_SIGNALS: | |
192 | void axisLabelsChanged(); |
|
192 | void axisLabelsChanged(); | |
193 | void titleColorChanged(QColor color); |
|
193 | void titleColorChanged(QColor color); | |
194 | void backgroundColorChanged(); |
|
194 | void backgroundColorChanged(); | |
195 | void dropShadowEnabledChanged(bool enabled); |
|
195 | void dropShadowEnabledChanged(bool enabled); | |
196 | void minimumMarginsChanged(); |
|
196 | void minimumMarginsChanged(); | |
197 | Q_REVISION(2) void marginsChanged(); |
|
197 | Q_REVISION(2) void marginsChanged(); | |
198 | void plotAreaChanged(QRectF plotArea); |
|
198 | void plotAreaChanged(QRectF plotArea); | |
199 | void seriesAdded(QAbstractSeries *series); |
|
199 | void seriesAdded(QAbstractSeries *series); | |
200 | void seriesRemoved(QAbstractSeries *series); |
|
200 | void seriesRemoved(QAbstractSeries *series); | |
201 | Q_REVISION(3) void plotAreaColorChanged(); |
|
201 | Q_REVISION(3) void plotAreaColorChanged(); | |
202 | Q_REVISION(3) void backgroundRoundnessChanged(qreal diameter); |
|
202 | Q_REVISION(3) void backgroundRoundnessChanged(qreal diameter); | |
203 |
Q_REVISION(4) |
|
203 | Q_REVISION(4) void localizeNumbersChanged(); | |
204 |
|
204 | |||
205 | private Q_SLOTS: |
|
205 | private Q_SLOTS: | |
206 | void changeMinimumMargins(int top, int bottom, int left, int right); |
|
206 | void changeMinimumMargins(int top, int bottom, int left, int right); | |
207 | void handleAxisXSet(QAbstractAxis *axis); |
|
207 | void handleAxisXSet(QAbstractAxis *axis); | |
208 | void handleAxisYSet(QAbstractAxis *axis); |
|
208 | void handleAxisYSet(QAbstractAxis *axis); | |
209 | void handleAxisXTopSet(QAbstractAxis *axis); |
|
209 | void handleAxisXTopSet(QAbstractAxis *axis); | |
210 | void handleAxisYRightSet(QAbstractAxis *axis); |
|
210 | void handleAxisYRightSet(QAbstractAxis *axis); | |
211 | void handleSeriesAdded(QAbstractSeries *series); |
|
211 | void handleSeriesAdded(QAbstractSeries *series); | |
212 |
|
212 | |||
213 | protected: |
|
213 | protected: | |
214 | explicit DeclarativeChart(QChart::ChartType type, QDECLARATIVE_ITEM *parent); |
|
214 | explicit DeclarativeChart(QChart::ChartType type, QDECLARATIVE_ITEM *parent); | |
215 |
|
215 | |||
216 | private: |
|
216 | private: | |
217 | void initChart(QChart::ChartType type); |
|
217 | void initChart(QChart::ChartType type); | |
218 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
218 | // Extending QChart with DeclarativeChart is not possible because QObject does not support | |
219 | // multi inheritance, so we now have a QChart as a member instead |
|
219 | // multi inheritance, so we now have a QChart as a member instead | |
220 | QChart *m_chart; |
|
220 | QChart *m_chart; | |
221 | #ifdef CHARTS_FOR_QUICK2 |
|
221 | #ifdef CHARTS_FOR_QUICK2 | |
222 | QGraphicsScene *m_scene; |
|
222 | QGraphicsScene *m_scene; | |
223 | QPointF m_mousePressScenePoint; |
|
223 | QPointF m_mousePressScenePoint; | |
224 | QPoint m_mousePressScreenPoint; |
|
224 | QPoint m_mousePressScreenPoint; | |
225 | QPointF m_lastMouseMoveScenePoint; |
|
225 | QPointF m_lastMouseMoveScenePoint; | |
226 | QPoint m_lastMouseMoveScreenPoint; |
|
226 | QPoint m_lastMouseMoveScreenPoint; | |
227 | Qt::MouseButton m_mousePressButton; |
|
227 | Qt::MouseButton m_mousePressButton; | |
228 | Qt::MouseButtons m_mousePressButtons; |
|
228 | Qt::MouseButtons m_mousePressButtons; | |
229 | QMutex m_sceneImageLock; |
|
229 | QMutex m_sceneImageLock; | |
230 | QImage *m_currentSceneImage; |
|
230 | QImage *m_currentSceneImage; | |
231 | bool m_updatePending; |
|
231 | bool m_updatePending; | |
232 | Qt::HANDLE m_paintThreadId; |
|
232 | Qt::HANDLE m_paintThreadId; | |
233 | Qt::HANDLE m_guiThreadId; |
|
233 | Qt::HANDLE m_guiThreadId; | |
234 | #endif |
|
234 | #endif | |
235 | DeclarativeMargins *m_margins; |
|
235 | DeclarativeMargins *m_margins; | |
236 | }; |
|
236 | }; | |
237 |
|
237 | |||
238 | QTCOMMERCIALCHART_END_NAMESPACE |
|
238 | QTCOMMERCIALCHART_END_NAMESPACE | |
239 |
|
239 | |||
240 | #endif // DECLARATIVECHART_H |
|
240 | #endif // DECLARATIVECHART_H |
@@ -1,400 +1,400 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2014 Digia Plc |
|
3 | ** Copyright (C) 2014 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Enterprise Charts Add-on. |
|
7 | ** This file is part of the Qt Enterprise Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
11 | ** accordance with the Qt Enterprise License Agreement provided with the |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartaxiselement_p.h" |
|
21 | #include "chartaxiselement_p.h" | |
22 | #include "qabstractaxis_p.h" |
|
22 | #include "qabstractaxis_p.h" | |
23 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
24 | #include "abstractchartlayout_p.h" |
|
24 | #include "abstractchartlayout_p.h" | |
25 | #include <qmath.h> |
|
25 | #include <qmath.h> | |
26 | #include <QDateTime> |
|
26 | #include <QDateTime> | |
27 | #include <QTextDocument> |
|
27 | #include <QTextDocument> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | static const char *labelFormatMatchString = "%[\\-\\+#\\s\\d\\.lhjztL]*([dicuoxfegXFEG])"; |
|
31 | static const char *labelFormatMatchString = "%[\\-\\+#\\s\\d\\.lhjztL]*([dicuoxfegXFEG])"; | |
32 | static const char *labelFormatMatchLocalizedString = "^([^%]*)%\\.?(\\d)*([defgEG])(.*)$"; |
|
32 | static const char *labelFormatMatchLocalizedString = "^([^%]*)%\\.?(\\d)*([defgEG])(.*)$"; | |
33 | static QRegExp *labelFormatMatcher = 0; |
|
33 | static QRegExp *labelFormatMatcher = 0; | |
34 | static QRegExp *labelFormatMatcherLocalized = 0; |
|
34 | static QRegExp *labelFormatMatcherLocalized = 0; | |
35 | class StaticLabelFormatMatcherDeleter |
|
35 | class StaticLabelFormatMatcherDeleter | |
36 | { |
|
36 | { | |
37 | public: |
|
37 | public: | |
38 | StaticLabelFormatMatcherDeleter() {} |
|
38 | StaticLabelFormatMatcherDeleter() {} | |
39 | ~StaticLabelFormatMatcherDeleter() { |
|
39 | ~StaticLabelFormatMatcherDeleter() { | |
40 | delete labelFormatMatcher; |
|
40 | delete labelFormatMatcher; | |
41 | delete labelFormatMatcherLocalized; |
|
41 | delete labelFormatMatcherLocalized; | |
42 | } |
|
42 | } | |
43 | }; |
|
43 | }; | |
44 | static StaticLabelFormatMatcherDeleter staticLabelFormatMatcherDeleter; |
|
44 | static StaticLabelFormatMatcherDeleter staticLabelFormatMatcherDeleter; | |
45 |
|
45 | |||
46 | ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis) |
|
46 | ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis) | |
47 | : ChartElement(item), |
|
47 | : ChartElement(item), | |
48 | m_axis(axis), |
|
48 | m_axis(axis), | |
49 | m_animation(0), |
|
49 | m_animation(0), | |
50 | m_grid(new QGraphicsItemGroup(item)), |
|
50 | m_grid(new QGraphicsItemGroup(item)), | |
51 | m_arrow(new QGraphicsItemGroup(item)), |
|
51 | m_arrow(new QGraphicsItemGroup(item)), | |
52 | m_shades(new QGraphicsItemGroup(item)), |
|
52 | m_shades(new QGraphicsItemGroup(item)), | |
53 | m_labels(new QGraphicsItemGroup(item)), |
|
53 | m_labels(new QGraphicsItemGroup(item)), | |
54 | m_title(new QGraphicsTextItem(item)), |
|
54 | m_title(new QGraphicsTextItem(item)), | |
55 | m_intervalAxis(intervalAxis) |
|
55 | m_intervalAxis(intervalAxis) | |
56 |
|
56 | |||
57 | { |
|
57 | { | |
58 | //initial initialization |
|
58 | //initial initialization | |
59 | m_arrow->setHandlesChildEvents(false); |
|
59 | m_arrow->setHandlesChildEvents(false); | |
60 | m_arrow->setZValue(ChartPresenter::AxisZValue); |
|
60 | m_arrow->setZValue(ChartPresenter::AxisZValue); | |
61 | m_labels->setZValue(ChartPresenter::AxisZValue); |
|
61 | m_labels->setZValue(ChartPresenter::AxisZValue); | |
62 | m_shades->setZValue(ChartPresenter::ShadesZValue); |
|
62 | m_shades->setZValue(ChartPresenter::ShadesZValue); | |
63 | m_grid->setZValue(ChartPresenter::GridZValue); |
|
63 | m_grid->setZValue(ChartPresenter::GridZValue); | |
64 | m_title->setZValue(ChartPresenter::GridZValue); |
|
64 | m_title->setZValue(ChartPresenter::GridZValue); | |
65 | m_title->document()->setDocumentMargin(ChartPresenter::textMargin()); |
|
65 | m_title->document()->setDocumentMargin(ChartPresenter::textMargin()); | |
66 | handleVisibleChanged(axis->isVisible()); |
|
66 | handleVisibleChanged(axis->isVisible()); | |
67 | connectSlots(); |
|
67 | connectSlots(); | |
68 |
|
68 | |||
69 | setFlag(QGraphicsItem::ItemHasNoContents, true); |
|
69 | setFlag(QGraphicsItem::ItemHasNoContents, true); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | ChartAxisElement::~ChartAxisElement() |
|
72 | ChartAxisElement::~ChartAxisElement() | |
73 | { |
|
73 | { | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | void ChartAxisElement::connectSlots() |
|
76 | void ChartAxisElement::connectSlots() | |
77 | { |
|
77 | { | |
78 | QObject::connect(axis(), SIGNAL(visibleChanged(bool)), this, SLOT(handleVisibleChanged(bool))); |
|
78 | QObject::connect(axis(), SIGNAL(visibleChanged(bool)), this, SLOT(handleVisibleChanged(bool))); | |
79 | QObject::connect(axis(), SIGNAL(lineVisibleChanged(bool)), this, SLOT(handleArrowVisibleChanged(bool))); |
|
79 | QObject::connect(axis(), SIGNAL(lineVisibleChanged(bool)), this, SLOT(handleArrowVisibleChanged(bool))); | |
80 | QObject::connect(axis(), SIGNAL(gridVisibleChanged(bool)), this, SLOT(handleGridVisibleChanged(bool))); |
|
80 | QObject::connect(axis(), SIGNAL(gridVisibleChanged(bool)), this, SLOT(handleGridVisibleChanged(bool))); | |
81 | QObject::connect(axis(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); |
|
81 | QObject::connect(axis(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); | |
82 | QObject::connect(axis(), SIGNAL(shadesVisibleChanged(bool)), this, SLOT(handleShadesVisibleChanged(bool))); |
|
82 | QObject::connect(axis(), SIGNAL(shadesVisibleChanged(bool)), this, SLOT(handleShadesVisibleChanged(bool))); | |
83 | QObject::connect(axis(), SIGNAL(labelsAngleChanged(int)), this, SLOT(handleLabelsAngleChanged(int))); |
|
83 | QObject::connect(axis(), SIGNAL(labelsAngleChanged(int)), this, SLOT(handleLabelsAngleChanged(int))); | |
84 | QObject::connect(axis(), SIGNAL(linePenChanged(const QPen&)), this, SLOT(handleArrowPenChanged(const QPen&))); |
|
84 | QObject::connect(axis(), SIGNAL(linePenChanged(const QPen&)), this, SLOT(handleArrowPenChanged(const QPen&))); | |
85 | QObject::connect(axis(), SIGNAL(labelsPenChanged(const QPen&)), this, SLOT(handleLabelsPenChanged(const QPen&))); |
|
85 | QObject::connect(axis(), SIGNAL(labelsPenChanged(const QPen&)), this, SLOT(handleLabelsPenChanged(const QPen&))); | |
86 | QObject::connect(axis(), SIGNAL(labelsBrushChanged(const QBrush&)), this, SLOT(handleLabelsBrushChanged(const QBrush&))); |
|
86 | QObject::connect(axis(), SIGNAL(labelsBrushChanged(const QBrush&)), this, SLOT(handleLabelsBrushChanged(const QBrush&))); | |
87 | QObject::connect(axis(), SIGNAL(labelsFontChanged(const QFont&)), this, SLOT(handleLabelsFontChanged(const QFont&))); |
|
87 | QObject::connect(axis(), SIGNAL(labelsFontChanged(const QFont&)), this, SLOT(handleLabelsFontChanged(const QFont&))); | |
88 | QObject::connect(axis(), SIGNAL(gridLinePenChanged(const QPen&)), this, SLOT(handleGridPenChanged(const QPen&))); |
|
88 | QObject::connect(axis(), SIGNAL(gridLinePenChanged(const QPen&)), this, SLOT(handleGridPenChanged(const QPen&))); | |
89 | QObject::connect(axis(), SIGNAL(shadesPenChanged(const QPen&)), this, SLOT(handleShadesPenChanged(const QPen&))); |
|
89 | QObject::connect(axis(), SIGNAL(shadesPenChanged(const QPen&)), this, SLOT(handleShadesPenChanged(const QPen&))); | |
90 | QObject::connect(axis(), SIGNAL(shadesBrushChanged(const QBrush&)), this, SLOT(handleShadesBrushChanged(const QBrush&))); |
|
90 | QObject::connect(axis(), SIGNAL(shadesBrushChanged(const QBrush&)), this, SLOT(handleShadesBrushChanged(const QBrush&))); | |
91 | QObject::connect(axis(), SIGNAL(titleTextChanged(const QString&)), this, SLOT(handleTitleTextChanged(const QString&))); |
|
91 | QObject::connect(axis(), SIGNAL(titleTextChanged(const QString&)), this, SLOT(handleTitleTextChanged(const QString&))); | |
92 | QObject::connect(axis(), SIGNAL(titleFontChanged(const QFont&)), this, SLOT(handleTitleFontChanged(const QFont&))); |
|
92 | QObject::connect(axis(), SIGNAL(titleFontChanged(const QFont&)), this, SLOT(handleTitleFontChanged(const QFont&))); | |
93 | QObject::connect(axis(), SIGNAL(titlePenChanged(const QPen&)), this, SLOT(handleTitlePenChanged(const QPen&))); |
|
93 | QObject::connect(axis(), SIGNAL(titlePenChanged(const QPen&)), this, SLOT(handleTitlePenChanged(const QPen&))); | |
94 | QObject::connect(axis(), SIGNAL(titleBrushChanged(const QBrush&)), this, SLOT(handleTitleBrushChanged(const QBrush&))); |
|
94 | QObject::connect(axis(), SIGNAL(titleBrushChanged(const QBrush&)), this, SLOT(handleTitleBrushChanged(const QBrush&))); | |
95 | QObject::connect(axis(), SIGNAL(titleVisibleChanged(bool)), this, SLOT(handleTitleVisibleChanged(bool))); |
|
95 | QObject::connect(axis(), SIGNAL(titleVisibleChanged(bool)), this, SLOT(handleTitleVisibleChanged(bool))); | |
96 | QObject::connect(axis()->d_ptr.data(), SIGNAL(rangeChanged(qreal, qreal)), this, SLOT(handleRangeChanged(qreal, qreal))); |
|
96 | QObject::connect(axis()->d_ptr.data(), SIGNAL(rangeChanged(qreal, qreal)), this, SLOT(handleRangeChanged(qreal, qreal))); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void ChartAxisElement::handleArrowVisibleChanged(bool visible) |
|
99 | void ChartAxisElement::handleArrowVisibleChanged(bool visible) | |
100 | { |
|
100 | { | |
101 | m_arrow->setVisible(visible); |
|
101 | m_arrow->setVisible(visible); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void ChartAxisElement::handleGridVisibleChanged(bool visible) |
|
104 | void ChartAxisElement::handleGridVisibleChanged(bool visible) | |
105 | { |
|
105 | { | |
106 | m_grid->setVisible(visible); |
|
106 | m_grid->setVisible(visible); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void ChartAxisElement::handleLabelsVisibleChanged(bool visible) |
|
109 | void ChartAxisElement::handleLabelsVisibleChanged(bool visible) | |
110 | { |
|
110 | { | |
111 | QGraphicsLayoutItem::updateGeometry(); |
|
111 | QGraphicsLayoutItem::updateGeometry(); | |
112 | presenter()->layout()->invalidate(); |
|
112 | presenter()->layout()->invalidate(); | |
113 | m_labels->setVisible(visible); |
|
113 | m_labels->setVisible(visible); | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | void ChartAxisElement::handleShadesVisibleChanged(bool visible) |
|
116 | void ChartAxisElement::handleShadesVisibleChanged(bool visible) | |
117 | { |
|
117 | { | |
118 | m_shades->setVisible(visible); |
|
118 | m_shades->setVisible(visible); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | void ChartAxisElement::handleTitleVisibleChanged(bool visible) |
|
121 | void ChartAxisElement::handleTitleVisibleChanged(bool visible) | |
122 | { |
|
122 | { | |
123 | QGraphicsLayoutItem::updateGeometry(); |
|
123 | QGraphicsLayoutItem::updateGeometry(); | |
124 | presenter()->layout()->invalidate(); |
|
124 | presenter()->layout()->invalidate(); | |
125 | m_title->setVisible(visible); |
|
125 | m_title->setVisible(visible); | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | void ChartAxisElement::handleLabelsAngleChanged(int angle) |
|
128 | void ChartAxisElement::handleLabelsAngleChanged(int angle) | |
129 | { |
|
129 | { | |
130 | foreach (QGraphicsItem *item, m_labels->childItems()) |
|
130 | foreach (QGraphicsItem *item, m_labels->childItems()) | |
131 | item->setRotation(angle); |
|
131 | item->setRotation(angle); | |
132 |
|
132 | |||
133 | QGraphicsLayoutItem::updateGeometry(); |
|
133 | QGraphicsLayoutItem::updateGeometry(); | |
134 | presenter()->layout()->invalidate(); |
|
134 | presenter()->layout()->invalidate(); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | void ChartAxisElement::handleLabelsPenChanged(const QPen &pen) |
|
137 | void ChartAxisElement::handleLabelsPenChanged(const QPen &pen) | |
138 | { |
|
138 | { | |
139 | Q_UNUSED(pen) |
|
139 | Q_UNUSED(pen) | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | void ChartAxisElement::handleLabelsBrushChanged(const QBrush &brush) |
|
142 | void ChartAxisElement::handleLabelsBrushChanged(const QBrush &brush) | |
143 | { |
|
143 | { | |
144 | foreach (QGraphicsItem *item, m_labels->childItems()) |
|
144 | foreach (QGraphicsItem *item, m_labels->childItems()) | |
145 | static_cast<QGraphicsTextItem *>(item)->setDefaultTextColor(brush.color()); |
|
145 | static_cast<QGraphicsTextItem *>(item)->setDefaultTextColor(brush.color()); | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | void ChartAxisElement::handleLabelsFontChanged(const QFont &font) |
|
148 | void ChartAxisElement::handleLabelsFontChanged(const QFont &font) | |
149 | { |
|
149 | { | |
150 | foreach (QGraphicsItem *item, m_labels->childItems()) |
|
150 | foreach (QGraphicsItem *item, m_labels->childItems()) | |
151 | static_cast<QGraphicsTextItem *>(item)->setFont(font); |
|
151 | static_cast<QGraphicsTextItem *>(item)->setFont(font); | |
152 | QGraphicsLayoutItem::updateGeometry(); |
|
152 | QGraphicsLayoutItem::updateGeometry(); | |
153 | presenter()->layout()->invalidate(); |
|
153 | presenter()->layout()->invalidate(); | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void ChartAxisElement::handleTitleTextChanged(const QString &title) |
|
156 | void ChartAxisElement::handleTitleTextChanged(const QString &title) | |
157 | { |
|
157 | { | |
158 | QGraphicsLayoutItem::updateGeometry(); |
|
158 | QGraphicsLayoutItem::updateGeometry(); | |
159 | presenter()->layout()->invalidate(); |
|
159 | presenter()->layout()->invalidate(); | |
160 | if (title.isEmpty() || !m_title->isVisible()) |
|
160 | if (title.isEmpty() || !m_title->isVisible()) | |
161 | m_title->setHtml(title); |
|
161 | m_title->setHtml(title); | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | void ChartAxisElement::handleTitlePenChanged(const QPen &pen) |
|
164 | void ChartAxisElement::handleTitlePenChanged(const QPen &pen) | |
165 | { |
|
165 | { | |
166 | Q_UNUSED(pen) |
|
166 | Q_UNUSED(pen) | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | void ChartAxisElement::handleTitleBrushChanged(const QBrush &brush) |
|
169 | void ChartAxisElement::handleTitleBrushChanged(const QBrush &brush) | |
170 | { |
|
170 | { | |
171 | m_title->setDefaultTextColor(brush.color()); |
|
171 | m_title->setDefaultTextColor(brush.color()); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | void ChartAxisElement::handleTitleFontChanged(const QFont &font) |
|
174 | void ChartAxisElement::handleTitleFontChanged(const QFont &font) | |
175 | { |
|
175 | { | |
176 | if (m_title->font() != font) { |
|
176 | if (m_title->font() != font) { | |
177 | m_title->setFont(font); |
|
177 | m_title->setFont(font); | |
178 | QGraphicsLayoutItem::updateGeometry(); |
|
178 | QGraphicsLayoutItem::updateGeometry(); | |
179 | presenter()->layout()->invalidate(); |
|
179 | presenter()->layout()->invalidate(); | |
180 | } |
|
180 | } | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | void ChartAxisElement::handleVisibleChanged(bool visible) |
|
183 | void ChartAxisElement::handleVisibleChanged(bool visible) | |
184 | { |
|
184 | { | |
185 | setVisible(visible); |
|
185 | setVisible(visible); | |
186 | if (!visible) { |
|
186 | if (!visible) { | |
187 | m_grid->setVisible(visible); |
|
187 | m_grid->setVisible(visible); | |
188 | m_arrow->setVisible(visible); |
|
188 | m_arrow->setVisible(visible); | |
189 | m_shades->setVisible(visible); |
|
189 | m_shades->setVisible(visible); | |
190 | m_labels->setVisible(visible); |
|
190 | m_labels->setVisible(visible); | |
191 | m_title->setVisible(visible); |
|
191 | m_title->setVisible(visible); | |
192 | } else { |
|
192 | } else { | |
193 | m_grid->setVisible(axis()->isGridLineVisible()); |
|
193 | m_grid->setVisible(axis()->isGridLineVisible()); | |
194 | m_arrow->setVisible(axis()->isLineVisible()); |
|
194 | m_arrow->setVisible(axis()->isLineVisible()); | |
195 | m_shades->setVisible(axis()->shadesVisible()); |
|
195 | m_shades->setVisible(axis()->shadesVisible()); | |
196 | m_labels->setVisible(axis()->labelsVisible()); |
|
196 | m_labels->setVisible(axis()->labelsVisible()); | |
197 | m_title->setVisible(axis()->isTitleVisible()); |
|
197 | m_title->setVisible(axis()->isTitleVisible()); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | if (presenter()) presenter()->layout()->invalidate(); |
|
200 | if (presenter()) presenter()->layout()->invalidate(); | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | void ChartAxisElement::handleRangeChanged(qreal min, qreal max) |
|
203 | void ChartAxisElement::handleRangeChanged(qreal min, qreal max) | |
204 | { |
|
204 | { | |
205 | Q_UNUSED(min); |
|
205 | Q_UNUSED(min); | |
206 | Q_UNUSED(max); |
|
206 | Q_UNUSED(max); | |
207 |
|
207 | |||
208 | if (!isEmpty()) { |
|
208 | if (!isEmpty()) { | |
209 | QVector<qreal> layout = calculateLayout(); |
|
209 | QVector<qreal> layout = calculateLayout(); | |
210 | updateLayout(layout); |
|
210 | updateLayout(layout); | |
211 | QSizeF before = effectiveSizeHint(Qt::PreferredSize); |
|
211 | QSizeF before = effectiveSizeHint(Qt::PreferredSize); | |
212 | QSizeF after = sizeHint(Qt::PreferredSize); |
|
212 | QSizeF after = sizeHint(Qt::PreferredSize); | |
213 |
|
213 | |||
214 | if (before != after) { |
|
214 | if (before != after) { | |
215 | QGraphicsLayoutItem::updateGeometry(); |
|
215 | QGraphicsLayoutItem::updateGeometry(); | |
216 | // We don't want to call invalidate on layout, since it will change minimum size of |
|
216 | // We don't want to call invalidate on layout, since it will change minimum size of | |
217 | // component, which we would like to avoid since it causes nasty flips when scrolling |
|
217 | // component, which we would like to avoid since it causes nasty flips when scrolling | |
218 | // or zooming, instead recalculate layout and use plotArea for extra space. |
|
218 | // or zooming, instead recalculate layout and use plotArea for extra space. | |
219 | presenter()->layout()->setGeometry(presenter()->layout()->geometry()); |
|
219 | presenter()->layout()->setGeometry(presenter()->layout()->geometry()); | |
220 | } |
|
220 | } | |
221 | } |
|
221 | } | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | bool ChartAxisElement::isEmpty() |
|
224 | bool ChartAxisElement::isEmpty() | |
225 | { |
|
225 | { | |
226 | return axisGeometry().isEmpty() |
|
226 | return axisGeometry().isEmpty() | |
227 | || gridGeometry().isEmpty() |
|
227 | || gridGeometry().isEmpty() | |
228 | || qFuzzyCompare(min(), max()); |
|
228 | || qFuzzyCompare(min(), max()); | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | qreal ChartAxisElement::min() const |
|
231 | qreal ChartAxisElement::min() const | |
232 | { |
|
232 | { | |
233 | return m_axis->d_ptr->min(); |
|
233 | return m_axis->d_ptr->min(); | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | qreal ChartAxisElement::max() const |
|
236 | qreal ChartAxisElement::max() const | |
237 | { |
|
237 | { | |
238 | return m_axis->d_ptr->max(); |
|
238 | return m_axis->d_ptr->max(); | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | QString ChartAxisElement::formatLabel(const QString &formatSpec, const QByteArray &array, |
|
241 | QString ChartAxisElement::formatLabel(const QString &formatSpec, const QByteArray &array, | |
242 | qreal value, int precision, const QString &preStr, |
|
242 | qreal value, int precision, const QString &preStr, | |
243 | const QString &postStr) const |
|
243 | const QString &postStr) const | |
244 | { |
|
244 | { | |
245 | QString retVal; |
|
245 | QString retVal; | |
246 | if (!formatSpec.isEmpty()) { |
|
246 | if (!formatSpec.isEmpty()) { | |
247 | if (formatSpec.at(0) == QLatin1Char('d') |
|
247 | if (formatSpec.at(0) == QLatin1Char('d') | |
248 | || formatSpec.at(0) == QLatin1Char('i') |
|
248 | || formatSpec.at(0) == QLatin1Char('i') | |
249 | || formatSpec.at(0) == QLatin1Char('c')) { |
|
249 | || formatSpec.at(0) == QLatin1Char('c')) { | |
250 | if (presenter()->localizeNumbers()) |
|
250 | if (presenter()->localizeNumbers()) | |
251 | retVal = preStr + presenter()->locale().toString(qint64(value)) + postStr; |
|
251 | retVal = preStr + presenter()->locale().toString(qint64(value)) + postStr; | |
252 | else |
|
252 | else | |
253 | retVal = QString().sprintf(array, qint64(value)); |
|
253 | retVal = QString().sprintf(array, qint64(value)); | |
254 | } else if (formatSpec.at(0) == QLatin1Char('u') |
|
254 | } else if (formatSpec.at(0) == QLatin1Char('u') | |
255 | || formatSpec.at(0) == QLatin1Char('o') |
|
255 | || formatSpec.at(0) == QLatin1Char('o') | |
256 | || formatSpec.at(0) == QLatin1Char('x') |
|
256 | || formatSpec.at(0) == QLatin1Char('x') | |
257 | || formatSpec.at(0) == QLatin1Char('X')) { |
|
257 | || formatSpec.at(0) == QLatin1Char('X')) { | |
258 | // These formats are not supported by localized numbers |
|
258 | // These formats are not supported by localized numbers | |
259 | retVal = QString().sprintf(array, quint64(value)); |
|
259 | retVal = QString().sprintf(array, quint64(value)); | |
260 | } else if (formatSpec.at(0) == QLatin1Char('f') |
|
260 | } else if (formatSpec.at(0) == QLatin1Char('f') | |
261 | || formatSpec.at(0) == QLatin1Char('F') |
|
261 | || formatSpec.at(0) == QLatin1Char('F') | |
262 | || formatSpec.at(0) == QLatin1Char('e') |
|
262 | || formatSpec.at(0) == QLatin1Char('e') | |
263 | || formatSpec.at(0) == QLatin1Char('E') |
|
263 | || formatSpec.at(0) == QLatin1Char('E') | |
264 | || formatSpec.at(0) == QLatin1Char('g') |
|
264 | || formatSpec.at(0) == QLatin1Char('g') | |
265 | || formatSpec.at(0) == QLatin1Char('G')) { |
|
265 | || formatSpec.at(0) == QLatin1Char('G')) { | |
266 | if (presenter()->localizeNumbers()) { |
|
266 | if (presenter()->localizeNumbers()) { | |
267 | retVal = preStr |
|
267 | retVal = preStr | |
268 | + presenter()->locale().toString(value, formatSpec.at(0).toLatin1(), |
|
268 | + presenter()->locale().toString(value, formatSpec.at(0).toLatin1(), | |
269 | precision) |
|
269 | precision) | |
270 | + postStr; |
|
270 | + postStr; | |
271 | } else { |
|
271 | } else { | |
272 | retVal = QString().sprintf(array, value); |
|
272 | retVal = QString().sprintf(array, value); | |
273 | } |
|
273 | } | |
274 | } |
|
274 | } | |
275 | } |
|
275 | } | |
276 | return retVal; |
|
276 | return retVal; | |
277 | } |
|
277 | } | |
278 |
|
278 | |||
279 | QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks, |
|
279 | QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks, | |
280 | const QString &format) const |
|
280 | const QString &format) const | |
281 | { |
|
281 | { | |
282 | QStringList labels; |
|
282 | QStringList labels; | |
283 |
|
283 | |||
284 | if (max <= min || ticks < 1) |
|
284 | if (max <= min || ticks < 1) | |
285 | return labels; |
|
285 | return labels; | |
286 |
|
286 | |||
287 | if (format.isNull()) { |
|
287 | if (format.isNull()) { | |
288 | int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0) + 1; |
|
288 | int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0) + 1; | |
289 | for (int i = 0; i < ticks; i++) { |
|
289 | for (int i = 0; i < ticks; i++) { | |
290 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
290 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
291 | labels << presenter()->numberToString(value, 'f', n); |
|
291 | labels << presenter()->numberToString(value, 'f', n); | |
292 | } |
|
292 | } | |
293 | } else { |
|
293 | } else { | |
294 | QByteArray array = format.toLatin1(); |
|
294 | QByteArray array = format.toLatin1(); | |
295 | QString formatSpec; |
|
295 | QString formatSpec; | |
296 | QString preStr; |
|
296 | QString preStr; | |
297 | QString postStr; |
|
297 | QString postStr; | |
298 | int precision = 0; |
|
298 | int precision = 0; | |
299 | if (presenter()->localizeNumbers()) { |
|
299 | if (presenter()->localizeNumbers()) { | |
300 | if (!labelFormatMatcherLocalized) |
|
300 | if (!labelFormatMatcherLocalized) | |
301 | labelFormatMatcherLocalized = new QRegExp(labelFormatMatchLocalizedString); |
|
301 | labelFormatMatcherLocalized = new QRegExp(labelFormatMatchLocalizedString); | |
302 | if (labelFormatMatcherLocalized->indexIn(format, 0) != -1) { |
|
302 | if (labelFormatMatcherLocalized->indexIn(format, 0) != -1) { | |
303 | preStr = labelFormatMatcherLocalized->cap(1); |
|
303 | preStr = labelFormatMatcherLocalized->cap(1); | |
304 | precision = labelFormatMatcherLocalized->cap(2).toInt(); |
|
304 | precision = labelFormatMatcherLocalized->cap(2).toInt(); | |
305 | formatSpec = labelFormatMatcherLocalized->cap(3); |
|
305 | formatSpec = labelFormatMatcherLocalized->cap(3); | |
306 | postStr = labelFormatMatcherLocalized->cap(4); |
|
306 | postStr = labelFormatMatcherLocalized->cap(4); | |
307 | } |
|
307 | } | |
308 | } else { |
|
308 | } else { | |
309 | if (!labelFormatMatcher) |
|
309 | if (!labelFormatMatcher) | |
310 | labelFormatMatcher = new QRegExp(labelFormatMatchString); |
|
310 | labelFormatMatcher = new QRegExp(labelFormatMatchString); | |
311 | if (labelFormatMatcher->indexIn(format, 0) != -1) |
|
311 | if (labelFormatMatcher->indexIn(format, 0) != -1) | |
312 | formatSpec = labelFormatMatcher->cap(1); |
|
312 | formatSpec = labelFormatMatcher->cap(1); | |
313 | } |
|
313 | } | |
314 | for (int i = 0; i < ticks; i++) { |
|
314 | for (int i = 0; i < ticks; i++) { | |
315 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
315 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
316 | labels << formatLabel(formatSpec, array, value, precision, preStr, postStr); |
|
316 | labels << formatLabel(formatSpec, array, value, precision, preStr, postStr); | |
317 | } |
|
317 | } | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | return labels; |
|
320 | return labels; | |
321 | } |
|
321 | } | |
322 |
|
322 | |||
323 | QStringList ChartAxisElement::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, |
|
323 | QStringList ChartAxisElement::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, | |
324 | const QString &format) const |
|
324 | const QString &format) const | |
325 | { |
|
325 | { | |
326 | QStringList labels; |
|
326 | QStringList labels; | |
327 |
|
327 | |||
328 | if (max <= min || ticks < 1) |
|
328 | if (max <= min || ticks < 1) | |
329 | return labels; |
|
329 | return labels; | |
330 |
|
330 | |||
331 | int firstTick; |
|
331 | int firstTick; | |
332 | if (base > 1) |
|
332 | if (base > 1) | |
333 | firstTick = ceil(log10(min) / log10(base)); |
|
333 | firstTick = ceil(log10(min) / log10(base)); | |
334 | else |
|
334 | else | |
335 | firstTick = ceil(log10(max) / log10(base)); |
|
335 | firstTick = ceil(log10(max) / log10(base)); | |
336 |
|
336 | |||
337 | if (format.isNull()) { |
|
337 | if (format.isNull()) { | |
338 | int n = 0; |
|
338 | int n = 0; | |
339 | if (ticks > 1) |
|
339 | if (ticks > 1) | |
340 | n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); |
|
340 | n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); | |
341 | n++; |
|
341 | n++; | |
342 | for (int i = firstTick; i < ticks + firstTick; i++) { |
|
342 | for (int i = firstTick; i < ticks + firstTick; i++) { | |
343 | qreal value = qPow(base, i); |
|
343 | qreal value = qPow(base, i); | |
344 | labels << presenter()->numberToString(value, 'f', n); |
|
344 | labels << presenter()->numberToString(value, 'f', n); | |
345 | } |
|
345 | } | |
346 | } else { |
|
346 | } else { | |
347 | QByteArray array = format.toLatin1(); |
|
347 | QByteArray array = format.toLatin1(); | |
348 | QString formatSpec; |
|
348 | QString formatSpec; | |
349 | QString preStr; |
|
349 | QString preStr; | |
350 | QString postStr; |
|
350 | QString postStr; | |
351 | int precision = 0; |
|
351 | int precision = 0; | |
352 | if (presenter()->localizeNumbers()) { |
|
352 | if (presenter()->localizeNumbers()) { | |
353 | if (!labelFormatMatcherLocalized) |
|
353 | if (!labelFormatMatcherLocalized) | |
354 | labelFormatMatcherLocalized = new QRegExp(labelFormatMatchLocalizedString); |
|
354 | labelFormatMatcherLocalized = new QRegExp(labelFormatMatchLocalizedString); | |
355 | if (labelFormatMatcherLocalized->indexIn(format, 0) != -1) { |
|
355 | if (labelFormatMatcherLocalized->indexIn(format, 0) != -1) { | |
356 | preStr = labelFormatMatcherLocalized->cap(1); |
|
356 | preStr = labelFormatMatcherLocalized->cap(1); | |
357 | precision = labelFormatMatcherLocalized->cap(2).toInt(); |
|
357 | precision = labelFormatMatcherLocalized->cap(2).toInt(); | |
358 | formatSpec = labelFormatMatcherLocalized->cap(3); |
|
358 | formatSpec = labelFormatMatcherLocalized->cap(3); | |
359 | postStr = labelFormatMatcherLocalized->cap(4); |
|
359 | postStr = labelFormatMatcherLocalized->cap(4); | |
360 | } |
|
360 | } | |
361 | } else { |
|
361 | } else { | |
362 | if (!labelFormatMatcher) |
|
362 | if (!labelFormatMatcher) | |
363 | labelFormatMatcher = new QRegExp(labelFormatMatchString); |
|
363 | labelFormatMatcher = new QRegExp(labelFormatMatchString); | |
364 | if (labelFormatMatcher->indexIn(format, 0) != -1) |
|
364 | if (labelFormatMatcher->indexIn(format, 0) != -1) | |
365 | formatSpec = labelFormatMatcher->cap(1); |
|
365 | formatSpec = labelFormatMatcher->cap(1); | |
366 | } |
|
366 | } | |
367 | for (int i = firstTick; i < ticks + firstTick; i++) { |
|
367 | for (int i = firstTick; i < ticks + firstTick; i++) { | |
368 | qreal value = qPow(base, i); |
|
368 | qreal value = qPow(base, i); | |
369 | labels << formatLabel(formatSpec, array, value, precision, preStr, postStr); |
|
369 | labels << formatLabel(formatSpec, array, value, precision, preStr, postStr); | |
370 | } |
|
370 | } | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
373 | return labels; |
|
373 | return labels; | |
374 | } |
|
374 | } | |
375 |
|
375 | |||
376 | QStringList ChartAxisElement::createDateTimeLabels(qreal min, qreal max,int ticks, |
|
376 | QStringList ChartAxisElement::createDateTimeLabels(qreal min, qreal max,int ticks, | |
377 | const QString &format) const |
|
377 | const QString &format) const | |
378 | { |
|
378 | { | |
379 | QStringList labels; |
|
379 | QStringList labels; | |
380 |
|
380 | |||
381 | if (max <= min || ticks < 1) |
|
381 | if (max <= min || ticks < 1) | |
382 | return labels; |
|
382 | return labels; | |
383 |
|
383 | |||
384 | int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0); |
|
384 | int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0); | |
385 | n++; |
|
385 | n++; | |
386 | for (int i = 0; i < ticks; i++) { |
|
386 | for (int i = 0; i < ticks; i++) { | |
387 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
387 | qreal value = min + (i * (max - min) / (ticks - 1)); | |
388 |
labels << QDateTime::fromMSecsSinceEpoch(value) |
|
388 | labels << presenter()->locale().toString(QDateTime::fromMSecsSinceEpoch(value), format); | |
389 | } |
|
389 | } | |
390 | return labels; |
|
390 | return labels; | |
391 | } |
|
391 | } | |
392 |
|
392 | |||
393 | void ChartAxisElement::axisSelected() |
|
393 | void ChartAxisElement::axisSelected() | |
394 | { |
|
394 | { | |
395 | emit clicked(); |
|
395 | emit clicked(); | |
396 | } |
|
396 | } | |
397 |
|
397 | |||
398 | #include "moc_chartaxiselement_p.cpp" |
|
398 | #include "moc_chartaxiselement_p.cpp" | |
399 |
|
399 | |||
400 | QTCOMMERCIALCHART_END_NAMESPACE |
|
400 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,391 +1,393 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2014 Digia Plc |
|
3 | ** Copyright (C) 2014 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Enterprise Charts Add-on. |
|
7 | ** This file is part of the Qt Enterprise Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
11 | ** accordance with the Qt Enterprise License Agreement provided with the |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qdatetimeaxis.h" |
|
21 | #include "qdatetimeaxis.h" | |
22 | #include "qdatetimeaxis_p.h" |
|
22 | #include "qdatetimeaxis_p.h" | |
23 | #include "chartdatetimeaxisx_p.h" |
|
23 | #include "chartdatetimeaxisx_p.h" | |
24 | #include "chartdatetimeaxisy_p.h" |
|
24 | #include "chartdatetimeaxisy_p.h" | |
25 | #include "polarchartdatetimeaxisangular_p.h" |
|
25 | #include "polarchartdatetimeaxisangular_p.h" | |
26 | #include "polarchartdatetimeaxisradial_p.h" |
|
26 | #include "polarchartdatetimeaxisradial_p.h" | |
27 | #include "abstractdomain_p.h" |
|
27 | #include "abstractdomain_p.h" | |
28 | #include "qchart.h" |
|
28 | #include "qchart.h" | |
29 | #include <float.h> |
|
29 | #include <float.h> | |
30 | #include <cmath> |
|
30 | #include <cmath> | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 | /*! |
|
33 | /*! | |
34 | \class QDateTimeAxis |
|
34 | \class QDateTimeAxis | |
35 | \inmodule Qt Charts |
|
35 | \inmodule Qt Charts | |
36 | \brief The QDateTimeAxis class is used for manipulating chart's axis. |
|
36 | \brief The QDateTimeAxis class is used for manipulating chart's axis. | |
37 | \mainclass |
|
37 | \mainclass | |
38 |
|
38 | |||
39 | The labels can be configured by setting an appropriate DateTime format. |
|
39 | The labels can be configured by setting an appropriate DateTime format. | |
40 | QDateTimeAxis works correctly with dates from 4714 BCE to 287396 CE. |
|
40 | QDateTimeAxis works correctly with dates from 4714 BCE to 287396 CE. | |
41 | There are also other limitiation related to QDateTime. Please refer to QDateTime documentation. |
|
41 | There are also other limitiation related to QDateTime. Please refer to QDateTime documentation. | |
42 | QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
42 | QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. | |
43 |
|
43 | |||
44 | Note: QDateTimeAxis is disabled on ARM architecture. |
|
44 | Note: QDateTimeAxis is disabled on ARM architecture. | |
45 |
|
45 | |||
46 | \image api_datatime_axis.png |
|
46 | \image api_datatime_axis.png | |
47 |
|
47 | |||
48 | QDateTimeAxis can be used with any QXYSeries. |
|
48 | QDateTimeAxis can be used with any QXYSeries. | |
49 | To add a data point to the series QDateTime::toMSecsSinceEpoch() is used. |
|
49 | To add a data point to the series QDateTime::toMSecsSinceEpoch() is used. | |
50 | \code |
|
50 | \code | |
51 | QLineSeries *series = new QLineSeries; |
|
51 | QLineSeries *series = new QLineSeries; | |
52 |
|
52 | |||
53 | QDateTime xValue; |
|
53 | QDateTime xValue; | |
54 | xValue.setDate(QDate(2012, 1 , 18)); |
|
54 | xValue.setDate(QDate(2012, 1 , 18)); | |
55 | xValue.setTime(QTime(9, 34)); |
|
55 | xValue.setTime(QTime(9, 34)); | |
56 | qreal yValue = 12; |
|
56 | qreal yValue = 12; | |
57 | series->append(xValue.toMSecsSinceEpoch(), yValue); |
|
57 | series->append(xValue.toMSecsSinceEpoch(), yValue); | |
58 |
|
58 | |||
59 | xValue.setDate(QDate(2013, 5 , 11)); |
|
59 | xValue.setDate(QDate(2013, 5 , 11)); | |
60 | xValue.setTime(QTime(11, 14)); |
|
60 | xValue.setTime(QTime(11, 14)); | |
61 | qreal yValue = 22; |
|
61 | qreal yValue = 22; | |
62 | series->append(xValue.toMSecsSinceEpoch(), yValue); |
|
62 | series->append(xValue.toMSecsSinceEpoch(), yValue); | |
63 | \endcode |
|
63 | \endcode | |
64 |
|
64 | |||
65 | Adding the series to the chart and setting up the QDateTimeAxis. |
|
65 | Adding the series to the chart and setting up the QDateTimeAxis. | |
66 | \code |
|
66 | \code | |
67 | QChartView *chartView = new QChartView; |
|
67 | QChartView *chartView = new QChartView; | |
68 | chartView->chart()->addSeries(series); |
|
68 | chartView->chart()->addSeries(series); | |
69 |
|
69 | |||
70 | // ... |
|
70 | // ... | |
71 | QDateTimeAxis *axisX = new QDateTimeAxis; |
|
71 | QDateTimeAxis *axisX = new QDateTimeAxis; | |
72 | axisX->setFormat("dd-MM-yyyy h:mm"); |
|
72 | axisX->setFormat("dd-MM-yyyy h:mm"); | |
73 | chartView->chart()->setAxisX(axisX, series); |
|
73 | chartView->chart()->setAxisX(axisX, series); | |
74 | \endcode |
|
74 | \endcode | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | #ifdef QDOC_QT5 |
|
77 | #ifdef QDOC_QT5 | |
78 | /*! |
|
78 | /*! | |
79 | \qmltype DateTimeAxis |
|
79 | \qmltype DateTimeAxis | |
80 | \instantiates QDateTimeAxis |
|
80 | \instantiates QDateTimeAxis | |
81 | \inqmlmodule QtCommercial.Chart |
|
81 | \inqmlmodule QtCommercial.Chart | |
82 |
|
82 | |||
83 | \include doc/src/datetimeaxis.qdocinc |
|
83 | \include doc/src/datetimeaxis.qdocinc | |
84 | */ |
|
84 | */ | |
85 | #else |
|
85 | #else | |
86 | /*! |
|
86 | /*! | |
87 | \qmlclass DateTimeAxis QDateTimeAxis |
|
87 | \qmlclass DateTimeAxis QDateTimeAxis | |
88 |
|
88 | |||
89 | \include ../doc/src/datetimeaxis.qdocinc |
|
89 | \include ../doc/src/datetimeaxis.qdocinc | |
90 | */ |
|
90 | */ | |
91 | #endif |
|
91 | #endif | |
92 |
|
92 | |||
93 | /*! |
|
93 | /*! | |
94 | \property QDateTimeAxis::min |
|
94 | \property QDateTimeAxis::min | |
95 | Defines the minimum value on the axis. |
|
95 | Defines the minimum value on the axis. | |
96 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
96 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
97 | */ |
|
97 | */ | |
98 | /*! |
|
98 | /*! | |
99 | \qmlproperty datetime DateTimeAxis::min |
|
99 | \qmlproperty datetime DateTimeAxis::min | |
100 | Defines the minimum value on the axis. |
|
100 | Defines the minimum value on the axis. | |
101 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
101 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | \property QDateTimeAxis::max |
|
105 | \property QDateTimeAxis::max | |
106 | Defines the maximum value on the axis. |
|
106 | Defines the maximum value on the axis. | |
107 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
107 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
108 | */ |
|
108 | */ | |
109 | /*! |
|
109 | /*! | |
110 | \qmlproperty datetime DateTimeAxis::max |
|
110 | \qmlproperty datetime DateTimeAxis::max | |
111 | Defines the maximum value on the axis. |
|
111 | Defines the maximum value on the axis. | |
112 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
112 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
113 | */ |
|
113 | */ | |
114 |
|
114 | |||
115 | /*! |
|
115 | /*! | |
116 | \fn void QDateTimeAxis::minChanged(QDateTime min) |
|
116 | \fn void QDateTimeAxis::minChanged(QDateTime min) | |
117 | Axis emits signal when \a min of axis has changed. |
|
117 | Axis emits signal when \a min of axis has changed. | |
118 | */ |
|
118 | */ | |
119 | /*! |
|
119 | /*! | |
120 | \qmlsignal DateTimeAxis::onMinChanged(datetime min) |
|
120 | \qmlsignal DateTimeAxis::onMinChanged(datetime min) | |
121 | Axis emits signal when \a min of axis has changed. |
|
121 | Axis emits signal when \a min of axis has changed. | |
122 | */ |
|
122 | */ | |
123 |
|
123 | |||
124 | /*! |
|
124 | /*! | |
125 | \fn void QDateTimeAxis::maxChanged(QDateTime max) |
|
125 | \fn void QDateTimeAxis::maxChanged(QDateTime max) | |
126 | Axis emits signal when \a max of axis has changed. |
|
126 | Axis emits signal when \a max of axis has changed. | |
127 | */ |
|
127 | */ | |
128 | /*! |
|
128 | /*! | |
129 | \qmlsignal DateTimeAxis::onMaxChanged(datetime max) |
|
129 | \qmlsignal DateTimeAxis::onMaxChanged(datetime max) | |
130 | Axis emits signal when \a max of axis has changed. |
|
130 | Axis emits signal when \a max of axis has changed. | |
131 | */ |
|
131 | */ | |
132 |
|
132 | |||
133 | /*! |
|
133 | /*! | |
134 | \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max) |
|
134 | \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max) | |
135 | Axis emits signal when \a min or \a max of axis has changed. |
|
135 | Axis emits signal when \a min or \a max of axis has changed. | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | \property QDateTimeAxis::tickCount |
|
139 | \property QDateTimeAxis::tickCount | |
140 | The number of tick marks for the axis. |
|
140 | The number of tick marks for the axis. | |
141 | */ |
|
141 | */ | |
142 |
|
142 | |||
143 | /*! |
|
143 | /*! | |
144 | \qmlproperty int DateTimeAxis::tickCount |
|
144 | \qmlproperty int DateTimeAxis::tickCount | |
145 | The number of tick marks for the axis. |
|
145 | The number of tick marks for the axis. | |
146 | */ |
|
146 | */ | |
147 |
|
147 | |||
148 | /*! |
|
148 | /*! | |
149 | \property QDateTimeAxis::format |
|
149 | \property QDateTimeAxis::format | |
150 | The format string that is used when creating label for the axis out of a QDateTime object. |
|
150 | The format string that is used when creating label for the axis out of a QDateTime object. | |
151 | Check QDateTime documentation for information on how the string should be defined. |
|
151 | Check QDateTime documentation for information on how the string should be defined. | |
|
152 | ||||
|
153 | \sa QChart::locale | |||
152 | */ |
|
154 | */ | |
153 | /*! |
|
155 | /*! | |
154 | \qmlproperty string DateTimeAxis::format |
|
156 | \qmlproperty string DateTimeAxis::format | |
155 | The format string that is used when creating label for the axis out of a QDateTime object. |
|
157 | The format string that is used when creating label for the axis out of a QDateTime object. | |
156 | Check QDateTime documentation for information on how the string should be defined. |
|
158 | Check QDateTime documentation for information on how the string should be defined. | |
157 | */ |
|
159 | */ | |
158 |
|
160 | |||
159 | /*! |
|
161 | /*! | |
160 | \fn void QDateTimeAxis::tickCountChanged(int tickCount) |
|
162 | \fn void QDateTimeAxis::tickCountChanged(int tickCount) | |
161 | Axis emits signal when \a tickCount number on axis have changed. |
|
163 | Axis emits signal when \a tickCount number on axis have changed. | |
162 | */ |
|
164 | */ | |
163 | /*! |
|
165 | /*! | |
164 | \qmlsignal DateTimeAxis::tickCountChanged(int tickCount) |
|
166 | \qmlsignal DateTimeAxis::tickCountChanged(int tickCount) | |
165 | Axis emits signal when \a tickCount number on axis have changed. |
|
167 | Axis emits signal when \a tickCount number on axis have changed. | |
166 | */ |
|
168 | */ | |
167 |
|
169 | |||
168 | /*! |
|
170 | /*! | |
169 | \fn void QDateTimeAxis::formatChanged(QString format) |
|
171 | \fn void QDateTimeAxis::formatChanged(QString format) | |
170 | Axis emits signal when \a format of the axis has changed. |
|
172 | Axis emits signal when \a format of the axis has changed. | |
171 | */ |
|
173 | */ | |
172 | /*! |
|
174 | /*! | |
173 | \qmlsignal DateTimeAxis::onFormatChanged(string format) |
|
175 | \qmlsignal DateTimeAxis::onFormatChanged(string format) | |
174 | Axis emits signal when \a format of the axis has changed. |
|
176 | Axis emits signal when \a format of the axis has changed. | |
175 | */ |
|
177 | */ | |
176 |
|
178 | |||
177 | /*! |
|
179 | /*! | |
178 | Constructs an axis object which is a child of \a parent. |
|
180 | Constructs an axis object which is a child of \a parent. | |
179 | */ |
|
181 | */ | |
180 | QDateTimeAxis::QDateTimeAxis(QObject *parent) : |
|
182 | QDateTimeAxis::QDateTimeAxis(QObject *parent) : | |
181 | QAbstractAxis(*new QDateTimeAxisPrivate(this), parent) |
|
183 | QAbstractAxis(*new QDateTimeAxisPrivate(this), parent) | |
182 | { |
|
184 | { | |
183 |
|
185 | |||
184 | } |
|
186 | } | |
185 |
|
187 | |||
186 | /*! |
|
188 | /*! | |
187 | \internal |
|
189 | \internal | |
188 | */ |
|
190 | */ | |
189 | QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent) |
|
191 | QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent) | |
190 | { |
|
192 | { | |
191 |
|
193 | |||
192 | } |
|
194 | } | |
193 |
|
195 | |||
194 | /*! |
|
196 | /*! | |
195 | Destroys the object. |
|
197 | Destroys the object. | |
196 | */ |
|
198 | */ | |
197 | QDateTimeAxis::~QDateTimeAxis() |
|
199 | QDateTimeAxis::~QDateTimeAxis() | |
198 | { |
|
200 | { | |
199 | Q_D(QDateTimeAxis); |
|
201 | Q_D(QDateTimeAxis); | |
200 | if (d->m_chart) |
|
202 | if (d->m_chart) | |
201 | d->m_chart->removeAxis(this); |
|
203 | d->m_chart->removeAxis(this); | |
202 | } |
|
204 | } | |
203 |
|
205 | |||
204 | void QDateTimeAxis::setMin(QDateTime min) |
|
206 | void QDateTimeAxis::setMin(QDateTime min) | |
205 | { |
|
207 | { | |
206 | Q_D(QDateTimeAxis); |
|
208 | Q_D(QDateTimeAxis); | |
207 | if (min.isValid()) |
|
209 | if (min.isValid()) | |
208 | d->setRange(min.toMSecsSinceEpoch(), qMax(d->m_max, qreal(min.toMSecsSinceEpoch()))); |
|
210 | d->setRange(min.toMSecsSinceEpoch(), qMax(d->m_max, qreal(min.toMSecsSinceEpoch()))); | |
209 | } |
|
211 | } | |
210 |
|
212 | |||
211 | QDateTime QDateTimeAxis::min() const |
|
213 | QDateTime QDateTimeAxis::min() const | |
212 | { |
|
214 | { | |
213 | Q_D(const QDateTimeAxis); |
|
215 | Q_D(const QDateTimeAxis); | |
214 | return QDateTime::fromMSecsSinceEpoch(d->m_min); |
|
216 | return QDateTime::fromMSecsSinceEpoch(d->m_min); | |
215 | } |
|
217 | } | |
216 |
|
218 | |||
217 | void QDateTimeAxis::setMax(QDateTime max) |
|
219 | void QDateTimeAxis::setMax(QDateTime max) | |
218 | { |
|
220 | { | |
219 | Q_D(QDateTimeAxis); |
|
221 | Q_D(QDateTimeAxis); | |
220 | if (max.isValid()) |
|
222 | if (max.isValid()) | |
221 | d->setRange(qMin(d->m_min, qreal(max.toMSecsSinceEpoch())), max.toMSecsSinceEpoch()); |
|
223 | d->setRange(qMin(d->m_min, qreal(max.toMSecsSinceEpoch())), max.toMSecsSinceEpoch()); | |
222 | } |
|
224 | } | |
223 |
|
225 | |||
224 | QDateTime QDateTimeAxis::max() const |
|
226 | QDateTime QDateTimeAxis::max() const | |
225 | { |
|
227 | { | |
226 | Q_D(const QDateTimeAxis); |
|
228 | Q_D(const QDateTimeAxis); | |
227 | return QDateTime::fromMSecsSinceEpoch(d->m_max); |
|
229 | return QDateTime::fromMSecsSinceEpoch(d->m_max); | |
228 | } |
|
230 | } | |
229 |
|
231 | |||
230 | /*! |
|
232 | /*! | |
231 | Sets range from \a min to \a max on the axis. |
|
233 | Sets range from \a min to \a max on the axis. | |
232 | If min is greater than max then this function returns without making any changes. |
|
234 | If min is greater than max then this function returns without making any changes. | |
233 | */ |
|
235 | */ | |
234 | void QDateTimeAxis::setRange(QDateTime min, QDateTime max) |
|
236 | void QDateTimeAxis::setRange(QDateTime min, QDateTime max) | |
235 | { |
|
237 | { | |
236 | Q_D(QDateTimeAxis); |
|
238 | Q_D(QDateTimeAxis); | |
237 | if (!min.isValid() || !max.isValid() || min > max) |
|
239 | if (!min.isValid() || !max.isValid() || min > max) | |
238 | return; |
|
240 | return; | |
239 |
|
241 | |||
240 | d->setRange(min.toMSecsSinceEpoch(),max.toMSecsSinceEpoch()); |
|
242 | d->setRange(min.toMSecsSinceEpoch(),max.toMSecsSinceEpoch()); | |
241 | } |
|
243 | } | |
242 |
|
244 | |||
243 | void QDateTimeAxis::setFormat(QString format) |
|
245 | void QDateTimeAxis::setFormat(QString format) | |
244 | { |
|
246 | { | |
245 | Q_D(QDateTimeAxis); |
|
247 | Q_D(QDateTimeAxis); | |
246 | if (d->m_format != format) { |
|
248 | if (d->m_format != format) { | |
247 | d->m_format = format; |
|
249 | d->m_format = format; | |
248 | emit formatChanged(format); |
|
250 | emit formatChanged(format); | |
249 | } |
|
251 | } | |
250 | } |
|
252 | } | |
251 |
|
253 | |||
252 | QString QDateTimeAxis::format() const |
|
254 | QString QDateTimeAxis::format() const | |
253 | { |
|
255 | { | |
254 | Q_D(const QDateTimeAxis); |
|
256 | Q_D(const QDateTimeAxis); | |
255 | return d->m_format; |
|
257 | return d->m_format; | |
256 | } |
|
258 | } | |
257 |
|
259 | |||
258 | /*! |
|
260 | /*! | |
259 | Sets \a count for ticks on the axis. |
|
261 | Sets \a count for ticks on the axis. | |
260 | */ |
|
262 | */ | |
261 | void QDateTimeAxis::setTickCount(int count) |
|
263 | void QDateTimeAxis::setTickCount(int count) | |
262 | { |
|
264 | { | |
263 | Q_D(QDateTimeAxis); |
|
265 | Q_D(QDateTimeAxis); | |
264 | if (d->m_tickCount != count && count >= 2) { |
|
266 | if (d->m_tickCount != count && count >= 2) { | |
265 | d->m_tickCount = count; |
|
267 | d->m_tickCount = count; | |
266 | emit tickCountChanged(count); |
|
268 | emit tickCountChanged(count); | |
267 | } |
|
269 | } | |
268 | } |
|
270 | } | |
269 |
|
271 | |||
270 | /*! |
|
272 | /*! | |
271 | \fn int QDateTimeAxis::tickCount() const |
|
273 | \fn int QDateTimeAxis::tickCount() const | |
272 | Return number of ticks on the axis. |
|
274 | Return number of ticks on the axis. | |
273 | */ |
|
275 | */ | |
274 | int QDateTimeAxis::tickCount() const |
|
276 | int QDateTimeAxis::tickCount() const | |
275 | { |
|
277 | { | |
276 | Q_D(const QDateTimeAxis); |
|
278 | Q_D(const QDateTimeAxis); | |
277 | return d->m_tickCount; |
|
279 | return d->m_tickCount; | |
278 | } |
|
280 | } | |
279 |
|
281 | |||
280 | /*! |
|
282 | /*! | |
281 | Returns the type of the axis. |
|
283 | Returns the type of the axis. | |
282 | */ |
|
284 | */ | |
283 | QAbstractAxis::AxisType QDateTimeAxis::type() const |
|
285 | QAbstractAxis::AxisType QDateTimeAxis::type() const | |
284 | { |
|
286 | { | |
285 | return AxisTypeDateTime; |
|
287 | return AxisTypeDateTime; | |
286 | } |
|
288 | } | |
287 |
|
289 | |||
288 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
290 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
289 |
|
291 | |||
290 | QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis *q) |
|
292 | QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis *q) | |
291 | : QAbstractAxisPrivate(q), |
|
293 | : QAbstractAxisPrivate(q), | |
292 | m_min(0), |
|
294 | m_min(0), | |
293 | m_max(0), |
|
295 | m_max(0), | |
294 | m_tickCount(5) |
|
296 | m_tickCount(5) | |
295 | { |
|
297 | { | |
296 | m_format = "dd-MM-yyyy\nh:mm"; |
|
298 | m_format = "dd-MM-yyyy\nh:mm"; | |
297 | } |
|
299 | } | |
298 |
|
300 | |||
299 | QDateTimeAxisPrivate::~QDateTimeAxisPrivate() |
|
301 | QDateTimeAxisPrivate::~QDateTimeAxisPrivate() | |
300 | { |
|
302 | { | |
301 |
|
303 | |||
302 | } |
|
304 | } | |
303 |
|
305 | |||
304 | void QDateTimeAxisPrivate::setRange(qreal min,qreal max) |
|
306 | void QDateTimeAxisPrivate::setRange(qreal min,qreal max) | |
305 | { |
|
307 | { | |
306 | Q_Q(QDateTimeAxis); |
|
308 | Q_Q(QDateTimeAxis); | |
307 |
|
309 | |||
308 | bool changed = false; |
|
310 | bool changed = false; | |
309 |
|
311 | |||
310 | if (m_min != min) { |
|
312 | if (m_min != min) { | |
311 | m_min = min; |
|
313 | m_min = min; | |
312 | changed = true; |
|
314 | changed = true; | |
313 | emit q->minChanged(QDateTime::fromMSecsSinceEpoch(min)); |
|
315 | emit q->minChanged(QDateTime::fromMSecsSinceEpoch(min)); | |
314 | } |
|
316 | } | |
315 |
|
317 | |||
316 | if (m_max != max) { |
|
318 | if (m_max != max) { | |
317 | m_max = max; |
|
319 | m_max = max; | |
318 | changed = true; |
|
320 | changed = true; | |
319 | emit q->maxChanged(QDateTime::fromMSecsSinceEpoch(max)); |
|
321 | emit q->maxChanged(QDateTime::fromMSecsSinceEpoch(max)); | |
320 | } |
|
322 | } | |
321 |
|
323 | |||
322 | if (changed) { |
|
324 | if (changed) { | |
323 | emit q->rangeChanged(QDateTime::fromMSecsSinceEpoch(min), QDateTime::fromMSecsSinceEpoch(max)); |
|
325 | emit q->rangeChanged(QDateTime::fromMSecsSinceEpoch(min), QDateTime::fromMSecsSinceEpoch(max)); | |
324 | emit rangeChanged(m_min,m_max); |
|
326 | emit rangeChanged(m_min,m_max); | |
325 | } |
|
327 | } | |
326 | } |
|
328 | } | |
327 |
|
329 | |||
328 |
|
330 | |||
329 | void QDateTimeAxisPrivate::setMin(const QVariant &min) |
|
331 | void QDateTimeAxisPrivate::setMin(const QVariant &min) | |
330 | { |
|
332 | { | |
331 | Q_Q(QDateTimeAxis); |
|
333 | Q_Q(QDateTimeAxis); | |
332 | if (min.canConvert(QVariant::DateTime)) |
|
334 | if (min.canConvert(QVariant::DateTime)) | |
333 | q->setMin(min.toDateTime()); |
|
335 | q->setMin(min.toDateTime()); | |
334 | } |
|
336 | } | |
335 |
|
337 | |||
336 | void QDateTimeAxisPrivate::setMax(const QVariant &max) |
|
338 | void QDateTimeAxisPrivate::setMax(const QVariant &max) | |
337 | { |
|
339 | { | |
338 |
|
340 | |||
339 | Q_Q(QDateTimeAxis); |
|
341 | Q_Q(QDateTimeAxis); | |
340 | if (max.canConvert(QVariant::DateTime)) |
|
342 | if (max.canConvert(QVariant::DateTime)) | |
341 | q->setMax(max.toDateTime()); |
|
343 | q->setMax(max.toDateTime()); | |
342 | } |
|
344 | } | |
343 |
|
345 | |||
344 | void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
346 | void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
345 | { |
|
347 | { | |
346 | Q_Q(QDateTimeAxis); |
|
348 | Q_Q(QDateTimeAxis); | |
347 | if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime)) |
|
349 | if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime)) | |
348 | q->setRange(min.toDateTime(), max.toDateTime()); |
|
350 | q->setRange(min.toDateTime(), max.toDateTime()); | |
349 | } |
|
351 | } | |
350 |
|
352 | |||
351 | void QDateTimeAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
353 | void QDateTimeAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |
352 | { |
|
354 | { | |
353 | Q_Q(QDateTimeAxis); |
|
355 | Q_Q(QDateTimeAxis); | |
354 | ChartAxisElement *axis(0); |
|
356 | ChartAxisElement *axis(0); | |
355 | if (m_chart->chartType() == QChart::ChartTypeCartesian) { |
|
357 | if (m_chart->chartType() == QChart::ChartTypeCartesian) { | |
356 | if (orientation() == Qt::Vertical) |
|
358 | if (orientation() == Qt::Vertical) | |
357 | axis = new ChartDateTimeAxisY(q,parent); |
|
359 | axis = new ChartDateTimeAxisY(q,parent); | |
358 | if (orientation() == Qt::Horizontal) |
|
360 | if (orientation() == Qt::Horizontal) | |
359 | axis = new ChartDateTimeAxisX(q,parent); |
|
361 | axis = new ChartDateTimeAxisX(q,parent); | |
360 | } |
|
362 | } | |
361 |
|
363 | |||
362 | if (m_chart->chartType() == QChart::ChartTypePolar) { |
|
364 | if (m_chart->chartType() == QChart::ChartTypePolar) { | |
363 | if (orientation() == Qt::Vertical) |
|
365 | if (orientation() == Qt::Vertical) | |
364 | axis = new PolarChartDateTimeAxisRadial(q, parent); |
|
366 | axis = new PolarChartDateTimeAxisRadial(q, parent); | |
365 | if (orientation() == Qt::Horizontal) |
|
367 | if (orientation() == Qt::Horizontal) | |
366 | axis = new PolarChartDateTimeAxisAngular(q, parent); |
|
368 | axis = new PolarChartDateTimeAxisAngular(q, parent); | |
367 | } |
|
369 | } | |
368 |
|
370 | |||
369 | m_item.reset(axis); |
|
371 | m_item.reset(axis); | |
370 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
372 | QAbstractAxisPrivate::initializeGraphics(parent); | |
371 | } |
|
373 | } | |
372 |
|
374 | |||
373 | void QDateTimeAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
375 | void QDateTimeAxisPrivate::initializeDomain(AbstractDomain *domain) | |
374 | { |
|
376 | { | |
375 | if (m_max == m_min) { |
|
377 | if (m_max == m_min) { | |
376 | if (orientation() == Qt::Vertical) |
|
378 | if (orientation() == Qt::Vertical) | |
377 | setRange(domain->minY(), domain->maxY()); |
|
379 | setRange(domain->minY(), domain->maxY()); | |
378 | else |
|
380 | else | |
379 | setRange(domain->minX(), domain->maxX()); |
|
381 | setRange(domain->minX(), domain->maxX()); | |
380 | } else { |
|
382 | } else { | |
381 | if (orientation() == Qt::Vertical) |
|
383 | if (orientation() == Qt::Vertical) | |
382 | domain->setRangeY(m_min, m_max); |
|
384 | domain->setRangeY(m_min, m_max); | |
383 | else |
|
385 | else | |
384 | domain->setRangeX(m_min, m_max); |
|
386 | domain->setRangeX(m_min, m_max); | |
385 | } |
|
387 | } | |
386 | } |
|
388 | } | |
387 |
|
389 | |||
388 | #include "moc_qdatetimeaxis.cpp" |
|
390 | #include "moc_qdatetimeaxis.cpp" | |
389 | #include "moc_qdatetimeaxis_p.cpp" |
|
391 | #include "moc_qdatetimeaxis_p.cpp" | |
390 |
|
392 | |||
391 | QTCOMMERCIALCHART_END_NAMESPACE |
|
393 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,501 +1,501 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2014 Digia Plc |
|
3 | ** Copyright (C) 2014 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Enterprise Charts Add-on. |
|
7 | ** This file is part of the Qt Enterprise Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
11 | ** accordance with the Qt Enterprise License Agreement provided with the |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 | #include "chartpresenter_p.h" |
|
20 | #include "chartpresenter_p.h" | |
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "chartitem_p.h" |
|
22 | #include "chartitem_p.h" | |
23 | #include "qchart_p.h" |
|
23 | #include "qchart_p.h" | |
24 | #include "qabstractaxis.h" |
|
24 | #include "qabstractaxis.h" | |
25 | #include "qabstractaxis_p.h" |
|
25 | #include "qabstractaxis_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include "chartanimation_p.h" |
|
27 | #include "chartanimation_p.h" | |
28 | #include "qabstractseries_p.h" |
|
28 | #include "qabstractseries_p.h" | |
29 | #include "qareaseries.h" |
|
29 | #include "qareaseries.h" | |
30 | #include "chartaxiselement_p.h" |
|
30 | #include "chartaxiselement_p.h" | |
31 | #include "chartbackground_p.h" |
|
31 | #include "chartbackground_p.h" | |
32 | #include "cartesianchartlayout_p.h" |
|
32 | #include "cartesianchartlayout_p.h" | |
33 | #include "polarchartlayout_p.h" |
|
33 | #include "polarchartlayout_p.h" | |
34 | #include "charttitle_p.h" |
|
34 | #include "charttitle_p.h" | |
35 | #include <QTimer> |
|
35 | #include <QTimer> | |
36 | #include <QTextDocument> |
|
36 | #include <QTextDocument> | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type) |
|
40 | ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type) | |
41 | : QObject(chart), |
|
41 | : QObject(chart), | |
42 | m_chart(chart), |
|
42 | m_chart(chart), | |
43 | m_options(QChart::NoAnimation), |
|
43 | m_options(QChart::NoAnimation), | |
44 | m_state(ShowState), |
|
44 | m_state(ShowState), | |
45 | m_background(0), |
|
45 | m_background(0), | |
46 | m_plotAreaBackground(0), |
|
46 | m_plotAreaBackground(0), | |
47 | m_title(0), |
|
47 | m_title(0), | |
48 |
m_localizeNumbers( |
|
48 | m_localizeNumbers(true) | |
49 | { |
|
49 | { | |
50 | if (type == QChart::ChartTypeCartesian) |
|
50 | if (type == QChart::ChartTypeCartesian) | |
51 | m_layout = new CartesianChartLayout(this); |
|
51 | m_layout = new CartesianChartLayout(this); | |
52 | else if (type == QChart::ChartTypePolar) |
|
52 | else if (type == QChart::ChartTypePolar) | |
53 | m_layout = new PolarChartLayout(this); |
|
53 | m_layout = new PolarChartLayout(this); | |
54 | Q_ASSERT(m_layout); |
|
54 | Q_ASSERT(m_layout); | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | ChartPresenter::~ChartPresenter() |
|
57 | ChartPresenter::~ChartPresenter() | |
58 | { |
|
58 | { | |
59 |
|
59 | |||
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | void ChartPresenter::setGeometry(const QRectF rect) |
|
62 | void ChartPresenter::setGeometry(const QRectF rect) | |
63 | { |
|
63 | { | |
64 | if (m_rect != rect) { |
|
64 | if (m_rect != rect) { | |
65 | m_rect = rect; |
|
65 | m_rect = rect; | |
66 | foreach (ChartItem *chart, m_chartItems) { |
|
66 | foreach (ChartItem *chart, m_chartItems) { | |
67 | chart->domain()->setSize(rect.size()); |
|
67 | chart->domain()->setSize(rect.size()); | |
68 | chart->setPos(rect.topLeft()); |
|
68 | chart->setPos(rect.topLeft()); | |
69 | } |
|
69 | } | |
70 | } |
|
70 | } | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | QRectF ChartPresenter::geometry() const |
|
73 | QRectF ChartPresenter::geometry() const | |
74 | { |
|
74 | { | |
75 | return m_rect; |
|
75 | return m_rect; | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void ChartPresenter::handleAxisAdded(QAbstractAxis *axis) |
|
78 | void ChartPresenter::handleAxisAdded(QAbstractAxis *axis) | |
79 | { |
|
79 | { | |
80 | axis->d_ptr->initializeGraphics(rootItem()); |
|
80 | axis->d_ptr->initializeGraphics(rootItem()); | |
81 | axis->d_ptr->initializeAnimations(m_options); |
|
81 | axis->d_ptr->initializeAnimations(m_options); | |
82 | ChartAxisElement *item = axis->d_ptr->axisItem(); |
|
82 | ChartAxisElement *item = axis->d_ptr->axisItem(); | |
83 | item->setPresenter(this); |
|
83 | item->setPresenter(this); | |
84 | item->setThemeManager(m_chart->d_ptr->m_themeManager); |
|
84 | item->setThemeManager(m_chart->d_ptr->m_themeManager); | |
85 | m_axisItems<<item; |
|
85 | m_axisItems<<item; | |
86 | m_axes<<axis; |
|
86 | m_axes<<axis; | |
87 | m_layout->invalidate(); |
|
87 | m_layout->invalidate(); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis) |
|
90 | void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis) | |
91 | { |
|
91 | { | |
92 | ChartAxisElement *item = axis->d_ptr->m_item.take(); |
|
92 | ChartAxisElement *item = axis->d_ptr->m_item.take(); | |
93 | item->hide(); |
|
93 | item->hide(); | |
94 | item->disconnect(); |
|
94 | item->disconnect(); | |
95 | item->deleteLater(); |
|
95 | item->deleteLater(); | |
96 | m_axisItems.removeAll(item); |
|
96 | m_axisItems.removeAll(item); | |
97 | m_axes.removeAll(axis); |
|
97 | m_axes.removeAll(axis); | |
98 | m_layout->invalidate(); |
|
98 | m_layout->invalidate(); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 |
|
101 | |||
102 | void ChartPresenter::handleSeriesAdded(QAbstractSeries *series) |
|
102 | void ChartPresenter::handleSeriesAdded(QAbstractSeries *series) | |
103 | { |
|
103 | { | |
104 | series->d_ptr->initializeGraphics(rootItem()); |
|
104 | series->d_ptr->initializeGraphics(rootItem()); | |
105 | series->d_ptr->initializeAnimations(m_options); |
|
105 | series->d_ptr->initializeAnimations(m_options); | |
106 | series->d_ptr->setPresenter(this); |
|
106 | series->d_ptr->setPresenter(this); | |
107 | ChartItem *chart = series->d_ptr->chartItem(); |
|
107 | ChartItem *chart = series->d_ptr->chartItem(); | |
108 | chart->setPresenter(this); |
|
108 | chart->setPresenter(this); | |
109 | chart->setThemeManager(m_chart->d_ptr->m_themeManager); |
|
109 | chart->setThemeManager(m_chart->d_ptr->m_themeManager); | |
110 | chart->domain()->setSize(m_rect.size()); |
|
110 | chart->domain()->setSize(m_rect.size()); | |
111 | chart->setPos(m_rect.topLeft()); |
|
111 | chart->setPos(m_rect.topLeft()); | |
112 | chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored |
|
112 | chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored | |
113 | m_chartItems<<chart; |
|
113 | m_chartItems<<chart; | |
114 | m_series<<series; |
|
114 | m_series<<series; | |
115 | m_layout->invalidate(); |
|
115 | m_layout->invalidate(); | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series) |
|
118 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series) | |
119 | { |
|
119 | { | |
120 | ChartItem *chart = series->d_ptr->m_item.take(); |
|
120 | ChartItem *chart = series->d_ptr->m_item.take(); | |
121 | chart->hide(); |
|
121 | chart->hide(); | |
122 | chart->disconnect(); |
|
122 | chart->disconnect(); | |
123 | chart->deleteLater(); |
|
123 | chart->deleteLater(); | |
124 | m_chartItems.removeAll(chart); |
|
124 | m_chartItems.removeAll(chart); | |
125 | m_series.removeAll(series); |
|
125 | m_series.removeAll(series); | |
126 | m_layout->invalidate(); |
|
126 | m_layout->invalidate(); | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
129 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
130 | { |
|
130 | { | |
131 | if (m_options != options) { |
|
131 | if (m_options != options) { | |
132 | QChart::AnimationOptions oldOptions = m_options; |
|
132 | QChart::AnimationOptions oldOptions = m_options; | |
133 | m_options = options; |
|
133 | m_options = options; | |
134 | if (options.testFlag(QChart::SeriesAnimations) != oldOptions.testFlag(QChart::SeriesAnimations)) { |
|
134 | if (options.testFlag(QChart::SeriesAnimations) != oldOptions.testFlag(QChart::SeriesAnimations)) { | |
135 | foreach (QAbstractSeries *series, m_series) |
|
135 | foreach (QAbstractSeries *series, m_series) | |
136 | series->d_ptr->initializeAnimations(m_options); |
|
136 | series->d_ptr->initializeAnimations(m_options); | |
137 | } |
|
137 | } | |
138 | if (options.testFlag(QChart::GridAxisAnimations) != oldOptions.testFlag(QChart::GridAxisAnimations)) { |
|
138 | if (options.testFlag(QChart::GridAxisAnimations) != oldOptions.testFlag(QChart::GridAxisAnimations)) { | |
139 | foreach (QAbstractAxis *axis, m_axes) |
|
139 | foreach (QAbstractAxis *axis, m_axes) | |
140 | axis->d_ptr->initializeAnimations(m_options); |
|
140 | axis->d_ptr->initializeAnimations(m_options); | |
141 | } |
|
141 | } | |
142 | m_layout->invalidate(); // So that existing animations don't just stop halfway |
|
142 | m_layout->invalidate(); // So that existing animations don't just stop halfway | |
143 | } |
|
143 | } | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | void ChartPresenter::setState(State state,QPointF point) |
|
146 | void ChartPresenter::setState(State state,QPointF point) | |
147 | { |
|
147 | { | |
148 | m_state=state; |
|
148 | m_state=state; | |
149 | m_statePoint=point; |
|
149 | m_statePoint=point; | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
152 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
153 | { |
|
153 | { | |
154 | return m_options; |
|
154 | return m_options; | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void ChartPresenter::createBackgroundItem() |
|
157 | void ChartPresenter::createBackgroundItem() | |
158 | { |
|
158 | { | |
159 | if (!m_background) { |
|
159 | if (!m_background) { | |
160 | m_background = new ChartBackground(rootItem()); |
|
160 | m_background = new ChartBackground(rootItem()); | |
161 | m_background->setPen(Qt::NoPen); // Theme doesn't touch pen so don't use default |
|
161 | m_background->setPen(Qt::NoPen); // Theme doesn't touch pen so don't use default | |
162 | m_background->setBrush(QChartPrivate::defaultBrush()); |
|
162 | m_background->setBrush(QChartPrivate::defaultBrush()); | |
163 | m_background->setZValue(ChartPresenter::BackgroundZValue); |
|
163 | m_background->setZValue(ChartPresenter::BackgroundZValue); | |
164 | } |
|
164 | } | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | void ChartPresenter::createPlotAreaBackgroundItem() |
|
167 | void ChartPresenter::createPlotAreaBackgroundItem() | |
168 | { |
|
168 | { | |
169 | if (!m_plotAreaBackground) { |
|
169 | if (!m_plotAreaBackground) { | |
170 | if (m_chart->chartType() == QChart::ChartTypeCartesian) |
|
170 | if (m_chart->chartType() == QChart::ChartTypeCartesian) | |
171 | m_plotAreaBackground = new QGraphicsRectItem(rootItem()); |
|
171 | m_plotAreaBackground = new QGraphicsRectItem(rootItem()); | |
172 | else |
|
172 | else | |
173 | m_plotAreaBackground = new QGraphicsEllipseItem(rootItem()); |
|
173 | m_plotAreaBackground = new QGraphicsEllipseItem(rootItem()); | |
174 | // Use transparent pen instead of Qt::NoPen, as Qt::NoPen causes |
|
174 | // Use transparent pen instead of Qt::NoPen, as Qt::NoPen causes | |
175 | // antialising artifacts with axis lines for some reason. |
|
175 | // antialising artifacts with axis lines for some reason. | |
176 | m_plotAreaBackground->setPen(QPen(Qt::transparent)); |
|
176 | m_plotAreaBackground->setPen(QPen(Qt::transparent)); | |
177 | m_plotAreaBackground->setBrush(Qt::NoBrush); |
|
177 | m_plotAreaBackground->setBrush(Qt::NoBrush); | |
178 | m_plotAreaBackground->setZValue(ChartPresenter::PlotAreaZValue); |
|
178 | m_plotAreaBackground->setZValue(ChartPresenter::PlotAreaZValue); | |
179 | m_plotAreaBackground->setVisible(false); |
|
179 | m_plotAreaBackground->setVisible(false); | |
180 | } |
|
180 | } | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | void ChartPresenter::createTitleItem() |
|
183 | void ChartPresenter::createTitleItem() | |
184 | { |
|
184 | { | |
185 | if (!m_title) { |
|
185 | if (!m_title) { | |
186 | m_title = new ChartTitle(rootItem()); |
|
186 | m_title = new ChartTitle(rootItem()); | |
187 | m_title->setZValue(ChartPresenter::BackgroundZValue); |
|
187 | m_title->setZValue(ChartPresenter::BackgroundZValue); | |
188 | } |
|
188 | } | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | void ChartPresenter::startAnimation(ChartAnimation *animation) |
|
191 | void ChartPresenter::startAnimation(ChartAnimation *animation) | |
192 | { |
|
192 | { | |
193 | animation->stop(); |
|
193 | animation->stop(); | |
194 | QTimer::singleShot(0, animation, SLOT(startChartAnimation())); |
|
194 | QTimer::singleShot(0, animation, SLOT(startChartAnimation())); | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | void ChartPresenter::setBackgroundBrush(const QBrush &brush) |
|
197 | void ChartPresenter::setBackgroundBrush(const QBrush &brush) | |
198 | { |
|
198 | { | |
199 | createBackgroundItem(); |
|
199 | createBackgroundItem(); | |
200 | m_background->setBrush(brush); |
|
200 | m_background->setBrush(brush); | |
201 | m_layout->invalidate(); |
|
201 | m_layout->invalidate(); | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | QBrush ChartPresenter::backgroundBrush() const |
|
204 | QBrush ChartPresenter::backgroundBrush() const | |
205 | { |
|
205 | { | |
206 | if (!m_background) |
|
206 | if (!m_background) | |
207 | return QBrush(); |
|
207 | return QBrush(); | |
208 | return m_background->brush(); |
|
208 | return m_background->brush(); | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | void ChartPresenter::setBackgroundPen(const QPen &pen) |
|
211 | void ChartPresenter::setBackgroundPen(const QPen &pen) | |
212 | { |
|
212 | { | |
213 | createBackgroundItem(); |
|
213 | createBackgroundItem(); | |
214 | m_background->setPen(pen); |
|
214 | m_background->setPen(pen); | |
215 | m_layout->invalidate(); |
|
215 | m_layout->invalidate(); | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | QPen ChartPresenter::backgroundPen() const |
|
218 | QPen ChartPresenter::backgroundPen() const | |
219 | { |
|
219 | { | |
220 | if (!m_background) |
|
220 | if (!m_background) | |
221 | return QPen(); |
|
221 | return QPen(); | |
222 | return m_background->pen(); |
|
222 | return m_background->pen(); | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | void ChartPresenter::setBackgroundRoundness(qreal diameter) |
|
225 | void ChartPresenter::setBackgroundRoundness(qreal diameter) | |
226 | { |
|
226 | { | |
227 | createBackgroundItem(); |
|
227 | createBackgroundItem(); | |
228 | m_background->setDiameter(diameter); |
|
228 | m_background->setDiameter(diameter); | |
229 | m_layout->invalidate(); |
|
229 | m_layout->invalidate(); | |
230 | } |
|
230 | } | |
231 |
|
231 | |||
232 | qreal ChartPresenter::backgroundRoundness() const |
|
232 | qreal ChartPresenter::backgroundRoundness() const | |
233 | { |
|
233 | { | |
234 | if (!m_background) |
|
234 | if (!m_background) | |
235 | return 0; |
|
235 | return 0; | |
236 | return m_background->diameter(); |
|
236 | return m_background->diameter(); | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | void ChartPresenter::setPlotAreaBackgroundBrush(const QBrush &brush) |
|
239 | void ChartPresenter::setPlotAreaBackgroundBrush(const QBrush &brush) | |
240 | { |
|
240 | { | |
241 | createPlotAreaBackgroundItem(); |
|
241 | createPlotAreaBackgroundItem(); | |
242 | m_plotAreaBackground->setBrush(brush); |
|
242 | m_plotAreaBackground->setBrush(brush); | |
243 | m_layout->invalidate(); |
|
243 | m_layout->invalidate(); | |
244 | } |
|
244 | } | |
245 |
|
245 | |||
246 | QBrush ChartPresenter::plotAreaBackgroundBrush() const |
|
246 | QBrush ChartPresenter::plotAreaBackgroundBrush() const | |
247 | { |
|
247 | { | |
248 | if (!m_plotAreaBackground) |
|
248 | if (!m_plotAreaBackground) | |
249 | return QBrush(); |
|
249 | return QBrush(); | |
250 | return m_plotAreaBackground->brush(); |
|
250 | return m_plotAreaBackground->brush(); | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | void ChartPresenter::setPlotAreaBackgroundPen(const QPen &pen) |
|
253 | void ChartPresenter::setPlotAreaBackgroundPen(const QPen &pen) | |
254 | { |
|
254 | { | |
255 | createPlotAreaBackgroundItem(); |
|
255 | createPlotAreaBackgroundItem(); | |
256 | m_plotAreaBackground->setPen(pen); |
|
256 | m_plotAreaBackground->setPen(pen); | |
257 | m_layout->invalidate(); |
|
257 | m_layout->invalidate(); | |
258 | } |
|
258 | } | |
259 |
|
259 | |||
260 | QPen ChartPresenter::plotAreaBackgroundPen() const |
|
260 | QPen ChartPresenter::plotAreaBackgroundPen() const | |
261 | { |
|
261 | { | |
262 | if (!m_plotAreaBackground) |
|
262 | if (!m_plotAreaBackground) | |
263 | return QPen(); |
|
263 | return QPen(); | |
264 | return m_plotAreaBackground->pen(); |
|
264 | return m_plotAreaBackground->pen(); | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | void ChartPresenter::setTitle(const QString &title) |
|
267 | void ChartPresenter::setTitle(const QString &title) | |
268 | { |
|
268 | { | |
269 | createTitleItem(); |
|
269 | createTitleItem(); | |
270 | m_title->setText(title); |
|
270 | m_title->setText(title); | |
271 | m_layout->invalidate(); |
|
271 | m_layout->invalidate(); | |
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 | QString ChartPresenter::title() const |
|
274 | QString ChartPresenter::title() const | |
275 | { |
|
275 | { | |
276 | if (!m_title) |
|
276 | if (!m_title) | |
277 | return QString(); |
|
277 | return QString(); | |
278 | return m_title->text(); |
|
278 | return m_title->text(); | |
279 | } |
|
279 | } | |
280 |
|
280 | |||
281 | void ChartPresenter::setTitleFont(const QFont &font) |
|
281 | void ChartPresenter::setTitleFont(const QFont &font) | |
282 | { |
|
282 | { | |
283 | createTitleItem(); |
|
283 | createTitleItem(); | |
284 | m_title->setFont(font); |
|
284 | m_title->setFont(font); | |
285 | m_layout->invalidate(); |
|
285 | m_layout->invalidate(); | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | QFont ChartPresenter::titleFont() const |
|
288 | QFont ChartPresenter::titleFont() const | |
289 | { |
|
289 | { | |
290 | if (!m_title) |
|
290 | if (!m_title) | |
291 | return QFont(); |
|
291 | return QFont(); | |
292 | return m_title->font(); |
|
292 | return m_title->font(); | |
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | void ChartPresenter::setTitleBrush(const QBrush &brush) |
|
295 | void ChartPresenter::setTitleBrush(const QBrush &brush) | |
296 | { |
|
296 | { | |
297 | createTitleItem(); |
|
297 | createTitleItem(); | |
298 | m_title->setDefaultTextColor(brush.color()); |
|
298 | m_title->setDefaultTextColor(brush.color()); | |
299 | m_layout->invalidate(); |
|
299 | m_layout->invalidate(); | |
300 | } |
|
300 | } | |
301 |
|
301 | |||
302 | QBrush ChartPresenter::titleBrush() const |
|
302 | QBrush ChartPresenter::titleBrush() const | |
303 | { |
|
303 | { | |
304 | if (!m_title) |
|
304 | if (!m_title) | |
305 | return QBrush(); |
|
305 | return QBrush(); | |
306 | return QBrush(m_title->defaultTextColor()); |
|
306 | return QBrush(m_title->defaultTextColor()); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | void ChartPresenter::setBackgroundVisible(bool visible) |
|
309 | void ChartPresenter::setBackgroundVisible(bool visible) | |
310 | { |
|
310 | { | |
311 | createBackgroundItem(); |
|
311 | createBackgroundItem(); | |
312 | m_background->setVisible(visible); |
|
312 | m_background->setVisible(visible); | |
313 | } |
|
313 | } | |
314 |
|
314 | |||
315 |
|
315 | |||
316 | bool ChartPresenter::isBackgroundVisible() const |
|
316 | bool ChartPresenter::isBackgroundVisible() const | |
317 | { |
|
317 | { | |
318 | if (!m_background) |
|
318 | if (!m_background) | |
319 | return false; |
|
319 | return false; | |
320 | return m_background->isVisible(); |
|
320 | return m_background->isVisible(); | |
321 | } |
|
321 | } | |
322 |
|
322 | |||
323 | void ChartPresenter::setPlotAreaBackgroundVisible(bool visible) |
|
323 | void ChartPresenter::setPlotAreaBackgroundVisible(bool visible) | |
324 | { |
|
324 | { | |
325 | createPlotAreaBackgroundItem(); |
|
325 | createPlotAreaBackgroundItem(); | |
326 | m_plotAreaBackground->setVisible(visible); |
|
326 | m_plotAreaBackground->setVisible(visible); | |
327 | } |
|
327 | } | |
328 |
|
328 | |||
329 | bool ChartPresenter::isPlotAreaBackgroundVisible() const |
|
329 | bool ChartPresenter::isPlotAreaBackgroundVisible() const | |
330 | { |
|
330 | { | |
331 | if (!m_plotAreaBackground) |
|
331 | if (!m_plotAreaBackground) | |
332 | return false; |
|
332 | return false; | |
333 | return m_plotAreaBackground->isVisible(); |
|
333 | return m_plotAreaBackground->isVisible(); | |
334 | } |
|
334 | } | |
335 |
|
335 | |||
336 | void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) |
|
336 | void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) | |
337 | { |
|
337 | { | |
338 | createBackgroundItem(); |
|
338 | createBackgroundItem(); | |
339 | m_background->setDropShadowEnabled(enabled); |
|
339 | m_background->setDropShadowEnabled(enabled); | |
340 | } |
|
340 | } | |
341 |
|
341 | |||
342 | bool ChartPresenter::isBackgroundDropShadowEnabled() const |
|
342 | bool ChartPresenter::isBackgroundDropShadowEnabled() const | |
343 | { |
|
343 | { | |
344 | if (!m_background) |
|
344 | if (!m_background) | |
345 | return false; |
|
345 | return false; | |
346 | return m_background->isDropShadowEnabled(); |
|
346 | return m_background->isDropShadowEnabled(); | |
347 | } |
|
347 | } | |
348 |
|
348 | |||
349 | void ChartPresenter::setLocalizeNumbers(bool localize) |
|
349 | void ChartPresenter::setLocalizeNumbers(bool localize) | |
350 | { |
|
350 | { | |
351 | m_localizeNumbers = localize; |
|
351 | m_localizeNumbers = localize; | |
352 | m_layout->invalidate(); |
|
352 | m_layout->invalidate(); | |
353 | } |
|
353 | } | |
354 |
|
354 | |||
355 | bool ChartPresenter::localizeNumbers() const |
|
355 | void ChartPresenter::setLocale(const QLocale &locale) | |
356 | { |
|
356 | { | |
357 | return m_localizeNumbers; |
|
357 | m_locale = locale; | |
|
358 | m_layout->invalidate(); | |||
358 | } |
|
359 | } | |
359 |
|
360 | |||
360 |
|
||||
361 | AbstractChartLayout *ChartPresenter::layout() |
|
361 | AbstractChartLayout *ChartPresenter::layout() | |
362 | { |
|
362 | { | |
363 | return m_layout; |
|
363 | return m_layout; | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 | QLegend *ChartPresenter::legend() |
|
366 | QLegend *ChartPresenter::legend() | |
367 | { |
|
367 | { | |
368 | return m_chart->legend(); |
|
368 | return m_chart->legend(); | |
369 | } |
|
369 | } | |
370 |
|
370 | |||
371 | void ChartPresenter::setVisible(bool visible) |
|
371 | void ChartPresenter::setVisible(bool visible) | |
372 | { |
|
372 | { | |
373 | m_chart->setVisible(visible); |
|
373 | m_chart->setVisible(visible); | |
374 | } |
|
374 | } | |
375 |
|
375 | |||
376 | ChartBackground *ChartPresenter::backgroundElement() |
|
376 | ChartBackground *ChartPresenter::backgroundElement() | |
377 | { |
|
377 | { | |
378 | return m_background; |
|
378 | return m_background; | |
379 | } |
|
379 | } | |
380 |
|
380 | |||
381 | QAbstractGraphicsShapeItem *ChartPresenter::plotAreaElement() |
|
381 | QAbstractGraphicsShapeItem *ChartPresenter::plotAreaElement() | |
382 | { |
|
382 | { | |
383 | return m_plotAreaBackground; |
|
383 | return m_plotAreaBackground; | |
384 | } |
|
384 | } | |
385 |
|
385 | |||
386 | QList<ChartAxisElement *> ChartPresenter::axisItems() const |
|
386 | QList<ChartAxisElement *> ChartPresenter::axisItems() const | |
387 | { |
|
387 | { | |
388 | return m_axisItems; |
|
388 | return m_axisItems; | |
389 | } |
|
389 | } | |
390 |
|
390 | |||
391 | QList<ChartItem *> ChartPresenter::chartItems() const |
|
391 | QList<ChartItem *> ChartPresenter::chartItems() const | |
392 | { |
|
392 | { | |
393 | return m_chartItems; |
|
393 | return m_chartItems; | |
394 | } |
|
394 | } | |
395 |
|
395 | |||
396 | ChartTitle *ChartPresenter::titleElement() |
|
396 | ChartTitle *ChartPresenter::titleElement() | |
397 | { |
|
397 | { | |
398 | return m_title; |
|
398 | return m_title; | |
399 | } |
|
399 | } | |
400 |
|
400 | |||
401 | QRectF ChartPresenter::textBoundingRect(const QFont &font, const QString &text, qreal angle) |
|
401 | QRectF ChartPresenter::textBoundingRect(const QFont &font, const QString &text, qreal angle) | |
402 | { |
|
402 | { | |
403 | static QGraphicsTextItem dummyTextItem; |
|
403 | static QGraphicsTextItem dummyTextItem; | |
404 | static bool initMargin = true; |
|
404 | static bool initMargin = true; | |
405 | if (initMargin) { |
|
405 | if (initMargin) { | |
406 | dummyTextItem.document()->setDocumentMargin(textMargin()); |
|
406 | dummyTextItem.document()->setDocumentMargin(textMargin()); | |
407 | initMargin = false; |
|
407 | initMargin = false; | |
408 | } |
|
408 | } | |
409 |
|
409 | |||
410 | dummyTextItem.setFont(font); |
|
410 | dummyTextItem.setFont(font); | |
411 | dummyTextItem.setHtml(text); |
|
411 | dummyTextItem.setHtml(text); | |
412 | QRectF boundingRect = dummyTextItem.boundingRect(); |
|
412 | QRectF boundingRect = dummyTextItem.boundingRect(); | |
413 |
|
413 | |||
414 | // Take rotation into account |
|
414 | // Take rotation into account | |
415 | if (angle) { |
|
415 | if (angle) { | |
416 | QTransform transform; |
|
416 | QTransform transform; | |
417 | transform.rotate(angle); |
|
417 | transform.rotate(angle); | |
418 | boundingRect = transform.mapRect(boundingRect); |
|
418 | boundingRect = transform.mapRect(boundingRect); | |
419 | } |
|
419 | } | |
420 |
|
420 | |||
421 | return boundingRect; |
|
421 | return boundingRect; | |
422 | } |
|
422 | } | |
423 |
|
423 | |||
424 | // boundingRect parameter returns the rotated bounding rect of the text |
|
424 | // boundingRect parameter returns the rotated bounding rect of the text | |
425 | QString ChartPresenter::truncatedText(const QFont &font, const QString &text, qreal angle, |
|
425 | QString ChartPresenter::truncatedText(const QFont &font, const QString &text, qreal angle, | |
426 | qreal maxWidth, qreal maxHeight, QRectF &boundingRect) |
|
426 | qreal maxWidth, qreal maxHeight, QRectF &boundingRect) | |
427 | { |
|
427 | { | |
428 | QString truncatedString(text); |
|
428 | QString truncatedString(text); | |
429 | boundingRect = textBoundingRect(font, truncatedString, angle); |
|
429 | boundingRect = textBoundingRect(font, truncatedString, angle); | |
430 | if (boundingRect.width() > maxWidth || boundingRect.height() > maxHeight) { |
|
430 | if (boundingRect.width() > maxWidth || boundingRect.height() > maxHeight) { | |
431 | // It can be assumed that almost any amount of string manipulation is faster |
|
431 | // It can be assumed that almost any amount of string manipulation is faster | |
432 | // than calculating one bounding rectangle, so first prepare a list of truncated strings |
|
432 | // than calculating one bounding rectangle, so first prepare a list of truncated strings | |
433 | // to try. |
|
433 | // to try. | |
434 | static const char *truncateMatchString = "&#?[0-9a-zA-Z]*;$"; |
|
434 | static const char *truncateMatchString = "&#?[0-9a-zA-Z]*;$"; | |
435 | static QRegExp truncateMatcher(truncateMatchString); |
|
435 | static QRegExp truncateMatcher(truncateMatchString); | |
436 |
|
436 | |||
437 | QVector<QString> testStrings(text.length()); |
|
437 | QVector<QString> testStrings(text.length()); | |
438 | int count(0); |
|
438 | int count(0); | |
439 | static QLatin1Char closeTag('>'); |
|
439 | static QLatin1Char closeTag('>'); | |
440 | static QLatin1Char openTag('<'); |
|
440 | static QLatin1Char openTag('<'); | |
441 | static QLatin1Char semiColon(';'); |
|
441 | static QLatin1Char semiColon(';'); | |
442 | static QLatin1String ellipsis("..."); |
|
442 | static QLatin1String ellipsis("..."); | |
443 | while (truncatedString.length() > 1) { |
|
443 | while (truncatedString.length() > 1) { | |
444 | int chopIndex(-1); |
|
444 | int chopIndex(-1); | |
445 | int chopCount(1); |
|
445 | int chopCount(1); | |
446 | QChar lastChar(truncatedString.at(truncatedString.length() - 1)); |
|
446 | QChar lastChar(truncatedString.at(truncatedString.length() - 1)); | |
447 |
|
447 | |||
448 | if (lastChar == closeTag) |
|
448 | if (lastChar == closeTag) | |
449 | chopIndex = truncatedString.lastIndexOf(openTag); |
|
449 | chopIndex = truncatedString.lastIndexOf(openTag); | |
450 | else if (lastChar == semiColon) |
|
450 | else if (lastChar == semiColon) | |
451 | chopIndex = truncateMatcher.indexIn(truncatedString, 0); |
|
451 | chopIndex = truncateMatcher.indexIn(truncatedString, 0); | |
452 |
|
452 | |||
453 | if (chopIndex != -1) |
|
453 | if (chopIndex != -1) | |
454 | chopCount = truncatedString.length() - chopIndex; |
|
454 | chopCount = truncatedString.length() - chopIndex; | |
455 | truncatedString.chop(chopCount); |
|
455 | truncatedString.chop(chopCount); | |
456 | testStrings[count] = truncatedString + ellipsis; |
|
456 | testStrings[count] = truncatedString + ellipsis; | |
457 | count++; |
|
457 | count++; | |
458 | } |
|
458 | } | |
459 |
|
459 | |||
460 | // Binary search for best fit |
|
460 | // Binary search for best fit | |
461 | int minIndex(0); |
|
461 | int minIndex(0); | |
462 | int maxIndex(count - 1); |
|
462 | int maxIndex(count - 1); | |
463 | int bestIndex(count); |
|
463 | int bestIndex(count); | |
464 | QRectF checkRect; |
|
464 | QRectF checkRect; | |
465 |
|
465 | |||
466 | while (maxIndex >= minIndex) { |
|
466 | while (maxIndex >= minIndex) { | |
467 | int mid = (maxIndex + minIndex) / 2; |
|
467 | int mid = (maxIndex + minIndex) / 2; | |
468 | checkRect = textBoundingRect(font, testStrings.at(mid), angle); |
|
468 | checkRect = textBoundingRect(font, testStrings.at(mid), angle); | |
469 | if (checkRect.width() > maxWidth || checkRect.height() > maxHeight) { |
|
469 | if (checkRect.width() > maxWidth || checkRect.height() > maxHeight) { | |
470 | // Checked index too large, all under this are also too large |
|
470 | // Checked index too large, all under this are also too large | |
471 | minIndex = mid + 1; |
|
471 | minIndex = mid + 1; | |
472 | } else { |
|
472 | } else { | |
473 | // Checked index fits, all over this also fit |
|
473 | // Checked index fits, all over this also fit | |
474 | maxIndex = mid - 1; |
|
474 | maxIndex = mid - 1; | |
475 | bestIndex = mid; |
|
475 | bestIndex = mid; | |
476 | boundingRect = checkRect; |
|
476 | boundingRect = checkRect; | |
477 | } |
|
477 | } | |
478 | } |
|
478 | } | |
479 | // Default to "..." if nothing fits |
|
479 | // Default to "..." if nothing fits | |
480 | if (bestIndex == count) { |
|
480 | if (bestIndex == count) { | |
481 | boundingRect = textBoundingRect(font, ellipsis, angle); |
|
481 | boundingRect = textBoundingRect(font, ellipsis, angle); | |
482 | truncatedString = ellipsis; |
|
482 | truncatedString = ellipsis; | |
483 | } else { |
|
483 | } else { | |
484 | truncatedString = testStrings.at(bestIndex); |
|
484 | truncatedString = testStrings.at(bestIndex); | |
485 | } |
|
485 | } | |
486 | } |
|
486 | } | |
487 |
|
487 | |||
488 | return truncatedString; |
|
488 | return truncatedString; | |
489 | } |
|
489 | } | |
490 |
|
490 | |||
491 | QString ChartPresenter::numberToString(double value, char f, int prec) |
|
491 | QString ChartPresenter::numberToString(double value, char f, int prec) | |
492 | { |
|
492 | { | |
493 | if (m_localizeNumbers) |
|
493 | if (m_localizeNumbers) | |
494 | return m_locale.toString(value, f, prec); |
|
494 | return m_locale.toString(value, f, prec); | |
495 | else |
|
495 | else | |
496 | return QString::number(value, f, prec); |
|
496 | return QString::number(value, f, prec); | |
497 | } |
|
497 | } | |
498 |
|
498 | |||
499 | #include "moc_chartpresenter_p.cpp" |
|
499 | #include "moc_chartpresenter_p.cpp" | |
500 |
|
500 | |||
501 | QTCOMMERCIALCHART_END_NAMESPACE |
|
501 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,190 +1,191 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2014 Digia Plc |
|
3 | ** Copyright (C) 2014 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Enterprise Charts Add-on. |
|
7 | ** This file is part of the Qt Enterprise Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
11 | ** accordance with the Qt Enterprise License Agreement provided with the |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the Qt Enterprise Chart API. It exists purely as an |
|
24 | // This file is not part of the Qt Enterprise Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTPRESENTER_H |
|
30 | #ifndef CHARTPRESENTER_H | |
31 | #define CHARTPRESENTER_H |
|
31 | #define CHARTPRESENTER_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "qchart.h" //because of QChart::ChartThemeId |
|
34 | #include "qchart.h" //because of QChart::ChartThemeId | |
35 | #include <QRectF> |
|
35 | #include <QRectF> | |
36 | #include <QMargins> |
|
36 | #include <QMargins> | |
37 | #include <QLocale> |
|
37 | #include <QLocale> | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | class ChartItem; |
|
41 | class ChartItem; | |
42 | class AxisItem; |
|
42 | class AxisItem; | |
43 | class QAbstractSeries; |
|
43 | class QAbstractSeries; | |
44 | class ChartDataSet; |
|
44 | class ChartDataSet; | |
45 | class AbstractDomain; |
|
45 | class AbstractDomain; | |
46 | class ChartAxisElement; |
|
46 | class ChartAxisElement; | |
47 | class ChartAnimator; |
|
47 | class ChartAnimator; | |
48 | class ChartBackground; |
|
48 | class ChartBackground; | |
49 | class ChartTitle; |
|
49 | class ChartTitle; | |
50 | class ChartAnimation; |
|
50 | class ChartAnimation; | |
51 | class AbstractChartLayout; |
|
51 | class AbstractChartLayout; | |
52 |
|
52 | |||
53 | class ChartPresenter: public QObject |
|
53 | class ChartPresenter: public QObject | |
54 | { |
|
54 | { | |
55 | Q_OBJECT |
|
55 | Q_OBJECT | |
56 | public: |
|
56 | public: | |
57 | enum ZValues { |
|
57 | enum ZValues { | |
58 | BackgroundZValue = -1, |
|
58 | BackgroundZValue = -1, | |
59 | PlotAreaZValue, |
|
59 | PlotAreaZValue, | |
60 | ShadesZValue, |
|
60 | ShadesZValue, | |
61 | GridZValue, |
|
61 | GridZValue, | |
62 | AxisZValue, |
|
62 | AxisZValue, | |
63 | SeriesZValue, |
|
63 | SeriesZValue, | |
64 | LineChartZValue = SeriesZValue, |
|
64 | LineChartZValue = SeriesZValue, | |
65 | SplineChartZValue = SeriesZValue, |
|
65 | SplineChartZValue = SeriesZValue, | |
66 | BarSeriesZValue = SeriesZValue, |
|
66 | BarSeriesZValue = SeriesZValue, | |
67 | ScatterSeriesZValue = SeriesZValue, |
|
67 | ScatterSeriesZValue = SeriesZValue, | |
68 | PieSeriesZValue = SeriesZValue, |
|
68 | PieSeriesZValue = SeriesZValue, | |
69 | BoxPlotSeriesZValue = SeriesZValue, |
|
69 | BoxPlotSeriesZValue = SeriesZValue, | |
70 | LegendZValue, |
|
70 | LegendZValue, | |
71 | TopMostZValue |
|
71 | TopMostZValue | |
72 | }; |
|
72 | }; | |
73 |
|
73 | |||
74 | enum State { |
|
74 | enum State { | |
75 | ShowState, |
|
75 | ShowState, | |
76 | ScrollUpState, |
|
76 | ScrollUpState, | |
77 | ScrollDownState, |
|
77 | ScrollDownState, | |
78 | ScrollLeftState, |
|
78 | ScrollLeftState, | |
79 | ScrollRightState, |
|
79 | ScrollRightState, | |
80 | ZoomInState, |
|
80 | ZoomInState, | |
81 | ZoomOutState |
|
81 | ZoomOutState | |
82 | }; |
|
82 | }; | |
83 |
|
83 | |||
84 | ChartPresenter(QChart *chart, QChart::ChartType type); |
|
84 | ChartPresenter(QChart *chart, QChart::ChartType type); | |
85 | virtual ~ChartPresenter(); |
|
85 | virtual ~ChartPresenter(); | |
86 |
|
86 | |||
87 |
|
87 | |||
88 | void setGeometry(QRectF rect); |
|
88 | void setGeometry(QRectF rect); | |
89 | QRectF geometry() const; |
|
89 | QRectF geometry() const; | |
90 |
|
90 | |||
91 | QGraphicsItem *rootItem(){ return m_chart; } |
|
91 | QGraphicsItem *rootItem(){ return m_chart; } | |
92 | ChartBackground *backgroundElement(); |
|
92 | ChartBackground *backgroundElement(); | |
93 | QAbstractGraphicsShapeItem *plotAreaElement(); |
|
93 | QAbstractGraphicsShapeItem *plotAreaElement(); | |
94 | ChartTitle *titleElement(); |
|
94 | ChartTitle *titleElement(); | |
95 | QList<ChartAxisElement *> axisItems() const; |
|
95 | QList<ChartAxisElement *> axisItems() const; | |
96 | QList<ChartItem *> chartItems() const; |
|
96 | QList<ChartItem *> chartItems() const; | |
97 |
|
97 | |||
98 | QLegend *legend(); |
|
98 | QLegend *legend(); | |
99 |
|
99 | |||
100 | void setBackgroundBrush(const QBrush &brush); |
|
100 | void setBackgroundBrush(const QBrush &brush); | |
101 | QBrush backgroundBrush() const; |
|
101 | QBrush backgroundBrush() const; | |
102 |
|
102 | |||
103 | void setBackgroundPen(const QPen &pen); |
|
103 | void setBackgroundPen(const QPen &pen); | |
104 | QPen backgroundPen() const; |
|
104 | QPen backgroundPen() const; | |
105 |
|
105 | |||
106 | void setBackgroundRoundness(qreal diameter); |
|
106 | void setBackgroundRoundness(qreal diameter); | |
107 | qreal backgroundRoundness() const; |
|
107 | qreal backgroundRoundness() const; | |
108 |
|
108 | |||
109 | void setPlotAreaBackgroundBrush(const QBrush &brush); |
|
109 | void setPlotAreaBackgroundBrush(const QBrush &brush); | |
110 | QBrush plotAreaBackgroundBrush() const; |
|
110 | QBrush plotAreaBackgroundBrush() const; | |
111 |
|
111 | |||
112 | void setPlotAreaBackgroundPen(const QPen &pen); |
|
112 | void setPlotAreaBackgroundPen(const QPen &pen); | |
113 | QPen plotAreaBackgroundPen() const; |
|
113 | QPen plotAreaBackgroundPen() const; | |
114 |
|
114 | |||
115 | void setTitle(const QString &title); |
|
115 | void setTitle(const QString &title); | |
116 | QString title() const; |
|
116 | QString title() const; | |
117 |
|
117 | |||
118 | void setTitleFont(const QFont &font); |
|
118 | void setTitleFont(const QFont &font); | |
119 | QFont titleFont() const; |
|
119 | QFont titleFont() const; | |
120 |
|
120 | |||
121 | void setTitleBrush(const QBrush &brush); |
|
121 | void setTitleBrush(const QBrush &brush); | |
122 | QBrush titleBrush() const; |
|
122 | QBrush titleBrush() const; | |
123 |
|
123 | |||
124 | void setBackgroundVisible(bool visible); |
|
124 | void setBackgroundVisible(bool visible); | |
125 | bool isBackgroundVisible() const; |
|
125 | bool isBackgroundVisible() const; | |
126 |
|
126 | |||
127 | void setPlotAreaBackgroundVisible(bool visible); |
|
127 | void setPlotAreaBackgroundVisible(bool visible); | |
128 | bool isPlotAreaBackgroundVisible() const; |
|
128 | bool isPlotAreaBackgroundVisible() const; | |
129 |
|
129 | |||
130 | void setBackgroundDropShadowEnabled(bool enabled); |
|
130 | void setBackgroundDropShadowEnabled(bool enabled); | |
131 | bool isBackgroundDropShadowEnabled() const; |
|
131 | bool isBackgroundDropShadowEnabled() const; | |
132 |
|
132 | |||
133 | void setLocalizeNumbers(bool localize); |
|
133 | void setLocalizeNumbers(bool localize); | |
134 | bool localizeNumbers() const; |
|
134 | inline bool localizeNumbers() const { return m_localizeNumbers; } | |
|
135 | void setLocale(const QLocale &locale); | |||
|
136 | inline const QLocale &locale() const { return m_locale; } | |||
135 |
|
137 | |||
136 | void setVisible(bool visible); |
|
138 | void setVisible(bool visible); | |
137 |
|
139 | |||
138 | void setAnimationOptions(QChart::AnimationOptions options); |
|
140 | void setAnimationOptions(QChart::AnimationOptions options); | |
139 | QChart::AnimationOptions animationOptions() const; |
|
141 | QChart::AnimationOptions animationOptions() const; | |
140 |
|
142 | |||
141 | void startAnimation(ChartAnimation *animation); |
|
143 | void startAnimation(ChartAnimation *animation); | |
142 |
|
144 | |||
143 | void setState(State state,QPointF point); |
|
145 | void setState(State state,QPointF point); | |
144 | State state() const { return m_state; } |
|
146 | State state() const { return m_state; } | |
145 | QPointF statePoint() const { return m_statePoint; } |
|
147 | QPointF statePoint() const { return m_statePoint; } | |
146 | AbstractChartLayout *layout(); |
|
148 | AbstractChartLayout *layout(); | |
147 |
|
149 | |||
148 | QChart::ChartType chartType() const { return m_chart->chartType(); } |
|
150 | QChart::ChartType chartType() const { return m_chart->chartType(); } | |
149 | QChart *chart() { return m_chart; } |
|
151 | QChart *chart() { return m_chart; } | |
150 |
|
152 | |||
151 | static QRectF textBoundingRect(const QFont &font, const QString &text, qreal angle = 0.0); |
|
153 | static QRectF textBoundingRect(const QFont &font, const QString &text, qreal angle = 0.0); | |
152 | static QString truncatedText(const QFont &font, const QString &text, qreal angle, |
|
154 | static QString truncatedText(const QFont &font, const QString &text, qreal angle, | |
153 | qreal maxWidth, qreal maxHeight, QRectF &boundingRect); |
|
155 | qreal maxWidth, qreal maxHeight, QRectF &boundingRect); | |
154 | inline static qreal textMargin() { return qreal(0.5); } |
|
156 | inline static qreal textMargin() { return qreal(0.5); } | |
155 |
|
157 | |||
156 | QString numberToString(double value, char f = 'g', int prec = 6); |
|
158 | QString numberToString(double value, char f = 'g', int prec = 6); | |
157 | inline const QLocale &locale() const { return m_locale; } |
|
|||
158 |
|
159 | |||
159 | private: |
|
160 | private: | |
160 | void createBackgroundItem(); |
|
161 | void createBackgroundItem(); | |
161 | void createPlotAreaBackgroundItem(); |
|
162 | void createPlotAreaBackgroundItem(); | |
162 | void createTitleItem(); |
|
163 | void createTitleItem(); | |
163 |
|
164 | |||
164 | public Q_SLOTS: |
|
165 | public Q_SLOTS: | |
165 | void handleSeriesAdded(QAbstractSeries *series); |
|
166 | void handleSeriesAdded(QAbstractSeries *series); | |
166 | void handleSeriesRemoved(QAbstractSeries *series); |
|
167 | void handleSeriesRemoved(QAbstractSeries *series); | |
167 | void handleAxisAdded(QAbstractAxis *axis); |
|
168 | void handleAxisAdded(QAbstractAxis *axis); | |
168 | void handleAxisRemoved(QAbstractAxis *axis); |
|
169 | void handleAxisRemoved(QAbstractAxis *axis); | |
169 |
|
170 | |||
170 | private: |
|
171 | private: | |
171 | QChart *m_chart; |
|
172 | QChart *m_chart; | |
172 | QList<ChartItem *> m_chartItems; |
|
173 | QList<ChartItem *> m_chartItems; | |
173 | QList<ChartAxisElement *> m_axisItems; |
|
174 | QList<ChartAxisElement *> m_axisItems; | |
174 | QList<QAbstractSeries *> m_series; |
|
175 | QList<QAbstractSeries *> m_series; | |
175 | QList<QAbstractAxis *> m_axes; |
|
176 | QList<QAbstractAxis *> m_axes; | |
176 | QChart::AnimationOptions m_options; |
|
177 | QChart::AnimationOptions m_options; | |
177 | State m_state; |
|
178 | State m_state; | |
178 | QPointF m_statePoint; |
|
179 | QPointF m_statePoint; | |
179 | AbstractChartLayout *m_layout; |
|
180 | AbstractChartLayout *m_layout; | |
180 | ChartBackground *m_background; |
|
181 | ChartBackground *m_background; | |
181 | QAbstractGraphicsShapeItem *m_plotAreaBackground; |
|
182 | QAbstractGraphicsShapeItem *m_plotAreaBackground; | |
182 | ChartTitle *m_title; |
|
183 | ChartTitle *m_title; | |
183 | QRectF m_rect; |
|
184 | QRectF m_rect; | |
184 | bool m_localizeNumbers; |
|
185 | bool m_localizeNumbers; | |
185 | QLocale m_locale; |
|
186 | QLocale m_locale; | |
186 | }; |
|
187 | }; | |
187 |
|
188 | |||
188 | QTCOMMERCIALCHART_END_NAMESPACE |
|
189 | QTCOMMERCIALCHART_END_NAMESPACE | |
189 |
|
190 | |||
190 | #endif /* CHARTPRESENTER_H */ |
|
191 | #endif /* CHARTPRESENTER_H */ |
@@ -1,847 +1,872 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2014 Digia Plc |
|
3 | ** Copyright (C) 2014 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Enterprise Charts Add-on. |
|
7 | ** This file is part of the Qt Enterprise Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
11 | ** accordance with the Qt Enterprise License Agreement provided with the |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "legendscroller_p.h" |
|
23 | #include "legendscroller_p.h" | |
24 | #include "qlegend_p.h" |
|
24 | #include "qlegend_p.h" | |
25 | #include "chartbackground_p.h" |
|
25 | #include "chartbackground_p.h" | |
26 | #include "qabstractaxis.h" |
|
26 | #include "qabstractaxis.h" | |
27 | #include "abstractchartlayout_p.h" |
|
27 | #include "abstractchartlayout_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartpresenter_p.h" |
|
29 | #include "chartpresenter_p.h" | |
30 | #include "chartdataset_p.h" |
|
30 | #include "chartdataset_p.h" | |
31 | #include <QGraphicsScene> |
|
31 | #include <QGraphicsScene> | |
32 | #include <QGraphicsSceneResizeEvent> |
|
32 | #include <QGraphicsSceneResizeEvent> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \enum QChart::ChartTheme |
|
37 | \enum QChart::ChartTheme | |
38 |
|
38 | |||
39 | This enum describes the theme used by the chart. |
|
39 | This enum describes the theme used by the chart. | |
40 |
|
40 | |||
41 | \value ChartThemeLight The default theme |
|
41 | \value ChartThemeLight The default theme | |
42 | \value ChartThemeBlueCerulean |
|
42 | \value ChartThemeBlueCerulean | |
43 | \value ChartThemeDark |
|
43 | \value ChartThemeDark | |
44 | \value ChartThemeBrownSand |
|
44 | \value ChartThemeBrownSand | |
45 | \value ChartThemeBlueNcs |
|
45 | \value ChartThemeBlueNcs | |
46 | \value ChartThemeHighContrast |
|
46 | \value ChartThemeHighContrast | |
47 | \value ChartThemeBlueIcy |
|
47 | \value ChartThemeBlueIcy | |
48 | \value ChartThemeQt |
|
48 | \value ChartThemeQt | |
49 | */ |
|
49 | */ | |
50 |
|
50 | |||
51 | /*! |
|
51 | /*! | |
52 | \enum QChart::AnimationOption |
|
52 | \enum QChart::AnimationOption | |
53 |
|
53 | |||
54 | For enabling/disabling animations. Defaults to NoAnimation. |
|
54 | For enabling/disabling animations. Defaults to NoAnimation. | |
55 |
|
55 | |||
56 | \value NoAnimation |
|
56 | \value NoAnimation | |
57 | \value GridAxisAnimations |
|
57 | \value GridAxisAnimations | |
58 | \value SeriesAnimations |
|
58 | \value SeriesAnimations | |
59 | \value AllAnimations |
|
59 | \value AllAnimations | |
60 | */ |
|
60 | */ | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | \enum QChart::ChartType |
|
63 | \enum QChart::ChartType | |
64 |
|
64 | |||
65 | This enum describes the chart type. |
|
65 | This enum describes the chart type. | |
66 |
|
66 | |||
67 | \value ChartTypeUndefined |
|
67 | \value ChartTypeUndefined | |
68 | \value ChartTypeCartesian |
|
68 | \value ChartTypeCartesian | |
69 | \value ChartTypePolar |
|
69 | \value ChartTypePolar | |
70 | */ |
|
70 | */ | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | \class QChart |
|
73 | \class QChart | |
74 | \inmodule Qt Charts |
|
74 | \inmodule Qt Charts | |
75 | \brief Main chart API for Qt Charts. |
|
75 | \brief Main chart API for Qt Charts. | |
76 |
|
76 | |||
77 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
77 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
78 | representation of different types of series and other chart related objects like legend and |
|
78 | representation of different types of series and other chart related objects like legend and | |
79 | axes. If you simply want to show a chart in a layout, you can use the |
|
79 | axes. If you simply want to show a chart in a layout, you can use the | |
80 | convenience class QChartView instead of QChart. |
|
80 | convenience class QChartView instead of QChart. | |
81 | \sa QChartView, QPolarChart |
|
81 | \sa QChartView, QPolarChart | |
82 | */ |
|
82 | */ | |
83 |
|
83 | |||
84 | /*! |
|
84 | /*! | |
85 | \property QChart::animationOptions |
|
85 | \property QChart::animationOptions | |
86 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
86 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | \property QChart::backgroundVisible |
|
90 | \property QChart::backgroundVisible | |
91 | Specifies whether the chart background is visible or not. |
|
91 | Specifies whether the chart background is visible or not. | |
92 | \sa setBackgroundBrush(), setBackgroundPen(), plotAreaBackgroundVisible |
|
92 | \sa setBackgroundBrush(), setBackgroundPen(), plotAreaBackgroundVisible | |
93 | */ |
|
93 | */ | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | \property QChart::dropShadowEnabled |
|
96 | \property QChart::dropShadowEnabled | |
97 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
97 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop | |
98 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
98 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. | |
99 | */ |
|
99 | */ | |
100 |
|
100 | |||
101 | /*! |
|
101 | /*! | |
102 | \property QChart::backgroundRoundness |
|
102 | \property QChart::backgroundRoundness | |
103 | The diameter of the rounding cirle at the corners of the chart background. |
|
103 | The diameter of the rounding cirle at the corners of the chart background. | |
104 | */ |
|
104 | */ | |
105 |
|
105 | |||
106 | /*! |
|
106 | /*! | |
107 | \property QChart::minimumMargins |
|
107 | \property QChart::minimumMargins | |
108 | Minimum margins between the plot area (axes) and the edge of the chart widget. |
|
108 | Minimum margins between the plot area (axes) and the edge of the chart widget. | |
109 | This property is deprecated; use margins property instead. |
|
109 | This property is deprecated; use margins property instead. | |
110 |
|
110 | |||
111 | \sa margins |
|
111 | \sa margins | |
112 | */ |
|
112 | */ | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | \property QChart::margins |
|
115 | \property QChart::margins | |
116 | Margins between the plot area (axes) and the edge of the chart widget. |
|
116 | Margins between the plot area (axes) and the edge of the chart widget. | |
117 | */ |
|
117 | */ | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | \property QChart::theme |
|
120 | \property QChart::theme | |
121 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
121 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, | |
122 | pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes demo} shows an example with a few |
|
122 | pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes demo} shows an example with a few | |
123 | different themes. |
|
123 | different themes. | |
124 | \note Changing the theme will overwrite all customizations previously applied to the series. |
|
124 | \note Changing the theme will overwrite all customizations previously applied to the series. | |
125 | */ |
|
125 | */ | |
126 |
|
126 | |||
127 | /*! |
|
127 | /*! | |
128 | \property QChart::title |
|
128 | \property QChart::title | |
129 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. Chart title supports html formatting. |
|
129 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. Chart title supports html formatting. | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \property QChart::chartType |
|
133 | \property QChart::chartType | |
134 | Chart type indicates if the chart is a cartesian chart or a polar chart. |
|
134 | Chart type indicates if the chart is a cartesian chart or a polar chart. | |
135 | This property is set internally and it is read only. |
|
135 | This property is set internally and it is read only. | |
136 | \sa QPolarChart |
|
136 | \sa QPolarChart | |
137 | */ |
|
137 | */ | |
138 |
|
138 | |||
139 | /*! |
|
139 | /*! | |
140 | \property QChart::plotAreaBackgroundVisible |
|
140 | \property QChart::plotAreaBackgroundVisible | |
141 | Specifies whether the chart plot area background is visible or not. |
|
141 | Specifies whether the chart plot area background is visible or not. | |
142 | \note By default the plot area background is not visible and the plot area uses |
|
142 | \note By default the plot area background is not visible and the plot area uses | |
143 | the general chart background. |
|
143 | the general chart background. | |
144 | \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible |
|
144 | \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible | |
145 | */ |
|
145 | */ | |
146 |
|
146 | |||
147 | /*! |
|
147 | /*! | |
148 | \property QChart::localizeNumbers |
|
148 | \property QChart::localizeNumbers | |
149 | \since QtCharts 2.0 |
|
149 | \since QtCharts 2.0 | |
150 | When \c{true}, all generated numbers appearing in various series and axis labels will be |
|
150 | When \c{true}, all generated numbers appearing in various series and axis labels will be | |
151 | localized using the default QLocale of the application, which defaults to the system locale. |
|
151 | localized using the QLocale set with the locale property. | |
152 | When \c{false}, the "C" locale is always used. |
|
152 | When \c{false}, the "C" locale is always used. | |
153 |
Defaults to \c{ |
|
153 | Defaults to \c{true}. | |
|
154 | \note This property doesn't affect QDateTimeAxis labels, which always use the QLocale set with | |||
|
155 | the locale property. | |||
|
156 | ||||
|
157 | \sa locale | |||
|
158 | */ | |||
|
159 | ||||
|
160 | /*! | |||
|
161 | \property QChart::locale | |||
|
162 | \since QtCharts 2.0 | |||
|
163 | Sets the locale used to format various chart labels when localizeNumbers is \c{true}. | |||
|
164 | This also determines the locale used to format QDateTimeAxis labels regardless of | |||
|
165 | localizeNumbers property. | |||
|
166 | Defaults to application default locale at the time the chart is constructed. | |||
|
167 | ||||
|
168 | \sa localizeNumbers | |||
154 | */ |
|
169 | */ | |
155 |
|
170 | |||
156 | /*! |
|
171 | /*! | |
157 | \internal |
|
172 | \internal | |
158 | Constructs a chart object of \a type which is a child of a \a parent. |
|
173 | Constructs a chart object of \a type which is a child of a \a parent. | |
159 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
174 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
160 | This constructor is called only by subclasses. |
|
175 | This constructor is called only by subclasses. | |
161 | */ |
|
176 | */ | |
162 | QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
177 | QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
163 | : QGraphicsWidget(parent, wFlags), |
|
178 | : QGraphicsWidget(parent, wFlags), | |
164 | d_ptr(new QChartPrivate(this, type)) |
|
179 | d_ptr(new QChartPrivate(this, type)) | |
165 | { |
|
180 | { | |
166 | d_ptr->init(); |
|
181 | d_ptr->init(); | |
167 | } |
|
182 | } | |
168 |
|
183 | |||
169 | /*! |
|
184 | /*! | |
170 | Constructs a chart object which is a child of a \a parent. |
|
185 | Constructs a chart object which is a child of a \a parent. | |
171 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
186 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
172 | */ |
|
187 | */ | |
173 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
188 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
174 | : QGraphicsWidget(parent, wFlags), |
|
189 | : QGraphicsWidget(parent, wFlags), | |
175 | d_ptr(new QChartPrivate(this, ChartTypeCartesian)) |
|
190 | d_ptr(new QChartPrivate(this, ChartTypeCartesian)) | |
176 | { |
|
191 | { | |
177 | d_ptr->init(); |
|
192 | d_ptr->init(); | |
178 | } |
|
193 | } | |
179 |
|
194 | |||
180 | /*! |
|
195 | /*! | |
181 | Destroys the chart object and its children, like series and axis objects added to it. |
|
196 | Destroys the chart object and its children, like series and axis objects added to it. | |
182 | */ |
|
197 | */ | |
183 | QChart::~QChart() |
|
198 | QChart::~QChart() | |
184 | { |
|
199 | { | |
185 | //start by deleting dataset, it will remove all series and axes |
|
200 | //start by deleting dataset, it will remove all series and axes | |
186 | delete d_ptr->m_dataset; |
|
201 | delete d_ptr->m_dataset; | |
187 | d_ptr->m_dataset = 0; |
|
202 | d_ptr->m_dataset = 0; | |
188 | } |
|
203 | } | |
189 |
|
204 | |||
190 | /*! |
|
205 | /*! | |
191 | Adds the \a series onto the chart and takes the ownership of it. |
|
206 | Adds the \a series onto the chart and takes the ownership of it. | |
192 |
|
207 | |||
193 | \note A newly added series is attached to no axes by default, including any axes that were created for the chart |
|
208 | \note A newly added series is attached to no axes by default, including any axes that were created for the chart | |
194 | using createDefaultAxes() before the series was added to the chart. If no axes are attached to |
|
209 | using createDefaultAxes() before the series was added to the chart. If no axes are attached to | |
195 | the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges |
|
210 | the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges | |
196 | that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other |
|
211 | that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other | |
197 | series that have properly attached axes, so always make sure you either call createDefaultAxes() after |
|
212 | series that have properly attached axes, so always make sure you either call createDefaultAxes() after | |
198 | a series has been added or explicitly attach axes for the series. |
|
213 | a series has been added or explicitly attach axes for the series. | |
199 |
|
214 | |||
200 | \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
215 | \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
201 | */ |
|
216 | */ | |
202 | void QChart::addSeries(QAbstractSeries *series) |
|
217 | void QChart::addSeries(QAbstractSeries *series) | |
203 | { |
|
218 | { | |
204 | Q_ASSERT(series); |
|
219 | Q_ASSERT(series); | |
205 | d_ptr->m_dataset->addSeries(series); |
|
220 | d_ptr->m_dataset->addSeries(series); | |
206 | } |
|
221 | } | |
207 |
|
222 | |||
208 | /*! |
|
223 | /*! | |
209 | Removes the \a series from the chart. |
|
224 | Removes the \a series from the chart. | |
210 | The chart releases its ownership of the specified \a series object. |
|
225 | The chart releases its ownership of the specified \a series object. | |
211 |
|
226 | |||
212 | \sa addSeries(), removeAllSeries() |
|
227 | \sa addSeries(), removeAllSeries() | |
213 | */ |
|
228 | */ | |
214 | void QChart::removeSeries(QAbstractSeries *series) |
|
229 | void QChart::removeSeries(QAbstractSeries *series) | |
215 | { |
|
230 | { | |
216 | Q_ASSERT(series); |
|
231 | Q_ASSERT(series); | |
217 | d_ptr->m_dataset->removeSeries(series); |
|
232 | d_ptr->m_dataset->removeSeries(series); | |
218 | } |
|
233 | } | |
219 |
|
234 | |||
220 | /*! |
|
235 | /*! | |
221 | Removes and deletes all series objects that have been added to the chart. |
|
236 | Removes and deletes all series objects that have been added to the chart. | |
222 |
|
237 | |||
223 | \sa addSeries(), removeSeries() |
|
238 | \sa addSeries(), removeSeries() | |
224 | */ |
|
239 | */ | |
225 | void QChart::removeAllSeries() |
|
240 | void QChart::removeAllSeries() | |
226 | { |
|
241 | { | |
227 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ |
|
242 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ | |
228 | removeSeries(s); |
|
243 | removeSeries(s); | |
229 | delete s; |
|
244 | delete s; | |
230 | } |
|
245 | } | |
231 | } |
|
246 | } | |
232 |
|
247 | |||
233 | /*! |
|
248 | /*! | |
234 | Sets the \a brush that is used for painting the background of the chart area. |
|
249 | Sets the \a brush that is used for painting the background of the chart area. | |
235 | */ |
|
250 | */ | |
236 | void QChart::setBackgroundBrush(const QBrush &brush) |
|
251 | void QChart::setBackgroundBrush(const QBrush &brush) | |
237 | { |
|
252 | { | |
238 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
253 | d_ptr->m_presenter->setBackgroundBrush(brush); | |
239 | } |
|
254 | } | |
240 |
|
255 | |||
241 | /*! |
|
256 | /*! | |
242 | Gets the brush that is used for painting the background of the chart area. |
|
257 | Gets the brush that is used for painting the background of the chart area. | |
243 | */ |
|
258 | */ | |
244 | QBrush QChart::backgroundBrush() const |
|
259 | QBrush QChart::backgroundBrush() const | |
245 | { |
|
260 | { | |
246 | return d_ptr->m_presenter->backgroundBrush(); |
|
261 | return d_ptr->m_presenter->backgroundBrush(); | |
247 | } |
|
262 | } | |
248 |
|
263 | |||
249 | /*! |
|
264 | /*! | |
250 | Sets the \a pen that is used for painting the background of the chart area. |
|
265 | Sets the \a pen that is used for painting the background of the chart area. | |
251 | */ |
|
266 | */ | |
252 | void QChart::setBackgroundPen(const QPen &pen) |
|
267 | void QChart::setBackgroundPen(const QPen &pen) | |
253 | { |
|
268 | { | |
254 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
269 | d_ptr->m_presenter->setBackgroundPen(pen); | |
255 | } |
|
270 | } | |
256 |
|
271 | |||
257 | /*! |
|
272 | /*! | |
258 | Gets the pen that is used for painting the background of the chart area. |
|
273 | Gets the pen that is used for painting the background of the chart area. | |
259 | */ |
|
274 | */ | |
260 | QPen QChart::backgroundPen() const |
|
275 | QPen QChart::backgroundPen() const | |
261 | { |
|
276 | { | |
262 | return d_ptr->m_presenter->backgroundPen(); |
|
277 | return d_ptr->m_presenter->backgroundPen(); | |
263 | } |
|
278 | } | |
264 |
|
279 | |||
265 | void QChart::setTitle(const QString &title) |
|
280 | void QChart::setTitle(const QString &title) | |
266 | { |
|
281 | { | |
267 | d_ptr->m_presenter->setTitle(title); |
|
282 | d_ptr->m_presenter->setTitle(title); | |
268 | } |
|
283 | } | |
269 |
|
284 | |||
270 | QString QChart::title() const |
|
285 | QString QChart::title() const | |
271 | { |
|
286 | { | |
272 | return d_ptr->m_presenter->title(); |
|
287 | return d_ptr->m_presenter->title(); | |
273 | } |
|
288 | } | |
274 |
|
289 | |||
275 | /*! |
|
290 | /*! | |
276 | Sets the \a font that is used for drawing the chart title. |
|
291 | Sets the \a font that is used for drawing the chart title. | |
277 | */ |
|
292 | */ | |
278 | void QChart::setTitleFont(const QFont &font) |
|
293 | void QChart::setTitleFont(const QFont &font) | |
279 | { |
|
294 | { | |
280 | d_ptr->m_presenter->setTitleFont(font); |
|
295 | d_ptr->m_presenter->setTitleFont(font); | |
281 | } |
|
296 | } | |
282 |
|
297 | |||
283 | /*! |
|
298 | /*! | |
284 | Gets the font that is used for drawing the chart title. |
|
299 | Gets the font that is used for drawing the chart title. | |
285 | */ |
|
300 | */ | |
286 | QFont QChart::titleFont() const |
|
301 | QFont QChart::titleFont() const | |
287 | { |
|
302 | { | |
288 | return d_ptr->m_presenter->titleFont(); |
|
303 | return d_ptr->m_presenter->titleFont(); | |
289 | } |
|
304 | } | |
290 |
|
305 | |||
291 | /*! |
|
306 | /*! | |
292 | Sets the \a brush used for drawing the title text. |
|
307 | Sets the \a brush used for drawing the title text. | |
293 | */ |
|
308 | */ | |
294 | void QChart::setTitleBrush(const QBrush &brush) |
|
309 | void QChart::setTitleBrush(const QBrush &brush) | |
295 | { |
|
310 | { | |
296 | d_ptr->m_presenter->setTitleBrush(brush); |
|
311 | d_ptr->m_presenter->setTitleBrush(brush); | |
297 | } |
|
312 | } | |
298 |
|
313 | |||
299 | /*! |
|
314 | /*! | |
300 | Returns the brush used for drawing the title text. |
|
315 | Returns the brush used for drawing the title text. | |
301 | */ |
|
316 | */ | |
302 | QBrush QChart::titleBrush() const |
|
317 | QBrush QChart::titleBrush() const | |
303 | { |
|
318 | { | |
304 | return d_ptr->m_presenter->titleBrush(); |
|
319 | return d_ptr->m_presenter->titleBrush(); | |
305 | } |
|
320 | } | |
306 |
|
321 | |||
307 | void QChart::setTheme(QChart::ChartTheme theme) |
|
322 | void QChart::setTheme(QChart::ChartTheme theme) | |
308 | { |
|
323 | { | |
309 | d_ptr->m_themeManager->setTheme(theme); |
|
324 | d_ptr->m_themeManager->setTheme(theme); | |
310 | } |
|
325 | } | |
311 |
|
326 | |||
312 | QChart::ChartTheme QChart::theme() const |
|
327 | QChart::ChartTheme QChart::theme() const | |
313 | { |
|
328 | { | |
314 | return d_ptr->m_themeManager->theme()->id(); |
|
329 | return d_ptr->m_themeManager->theme()->id(); | |
315 | } |
|
330 | } | |
316 |
|
331 | |||
317 | /*! |
|
332 | /*! | |
318 | Zooms in the view by a factor of two. |
|
333 | Zooms in the view by a factor of two. | |
319 | */ |
|
334 | */ | |
320 | void QChart::zoomIn() |
|
335 | void QChart::zoomIn() | |
321 | { |
|
336 | { | |
322 | d_ptr->zoomIn(2.0); |
|
337 | d_ptr->zoomIn(2.0); | |
323 | } |
|
338 | } | |
324 |
|
339 | |||
325 | /*! |
|
340 | /*! | |
326 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
341 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
327 | \note This is not supported for polar charts. |
|
342 | \note This is not supported for polar charts. | |
328 | */ |
|
343 | */ | |
329 | void QChart::zoomIn(const QRectF &rect) |
|
344 | void QChart::zoomIn(const QRectF &rect) | |
330 | { |
|
345 | { | |
331 | if (d_ptr->m_type == QChart::ChartTypePolar) |
|
346 | if (d_ptr->m_type == QChart::ChartTypePolar) | |
332 | return; |
|
347 | return; | |
333 | d_ptr->zoomIn(rect); |
|
348 | d_ptr->zoomIn(rect); | |
334 | } |
|
349 | } | |
335 |
|
350 | |||
336 | /*! |
|
351 | /*! | |
337 | Zooms out the view by a factor of two. |
|
352 | Zooms out the view by a factor of two. | |
338 | */ |
|
353 | */ | |
339 | void QChart::zoomOut() |
|
354 | void QChart::zoomOut() | |
340 | { |
|
355 | { | |
341 | d_ptr->zoomOut(2.0); |
|
356 | d_ptr->zoomOut(2.0); | |
342 | } |
|
357 | } | |
343 |
|
358 | |||
344 | /*! |
|
359 | /*! | |
345 | Zooms in the view by a custom \a factor. |
|
360 | Zooms in the view by a custom \a factor. | |
346 |
|
361 | |||
347 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
362 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. | |
348 | */ |
|
363 | */ | |
349 | void QChart::zoom(qreal factor) |
|
364 | void QChart::zoom(qreal factor) | |
350 | { |
|
365 | { | |
351 | if (qFuzzyCompare(factor, 0)) |
|
366 | if (qFuzzyCompare(factor, 0)) | |
352 | return; |
|
367 | return; | |
353 |
|
368 | |||
354 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
369 | if (qFuzzyCompare(factor, (qreal)1.0)) | |
355 | return; |
|
370 | return; | |
356 |
|
371 | |||
357 | if (factor < 0) |
|
372 | if (factor < 0) | |
358 | return; |
|
373 | return; | |
359 |
|
374 | |||
360 | if (factor > 1.0) |
|
375 | if (factor > 1.0) | |
361 | d_ptr->zoomIn(factor); |
|
376 | d_ptr->zoomIn(factor); | |
362 | else |
|
377 | else | |
363 | d_ptr->zoomOut(1.0 / factor); |
|
378 | d_ptr->zoomOut(1.0 / factor); | |
364 | } |
|
379 | } | |
365 |
|
380 | |||
366 |
|
381 | |||
367 | /*! |
|
382 | /*! | |
368 | Resets the series domains to what they were before any zoom method was called. |
|
383 | Resets the series domains to what they were before any zoom method was called. | |
369 | Note that this will also reset any scrolls and explicit axis range settings done between |
|
384 | Note that this will also reset any scrolls and explicit axis range settings done between | |
370 | the first zoom operation and calling this method. If no zoom operation has been |
|
385 | the first zoom operation and calling this method. If no zoom operation has been | |
371 | done, this method does nothing. |
|
386 | done, this method does nothing. | |
372 | */ |
|
387 | */ | |
373 | void QChart::zoomReset() |
|
388 | void QChart::zoomReset() | |
374 | { |
|
389 | { | |
375 | d_ptr->zoomReset(); |
|
390 | d_ptr->zoomReset(); | |
376 | } |
|
391 | } | |
377 |
|
392 | |||
378 | /*! |
|
393 | /*! | |
379 | Returns true if any series has a zoomed domain. |
|
394 | Returns true if any series has a zoomed domain. | |
380 | */ |
|
395 | */ | |
381 | bool QChart::isZoomed() |
|
396 | bool QChart::isZoomed() | |
382 | { |
|
397 | { | |
383 | return d_ptr->isZoomed(); |
|
398 | return d_ptr->isZoomed(); | |
384 | } |
|
399 | } | |
385 |
|
400 | |||
386 | /*! |
|
401 | /*! | |
387 | Returns a pointer to the horizontal axis attached to the specified \a series. |
|
402 | Returns a pointer to the horizontal axis attached to the specified \a series. | |
388 | If no \a series is specified, the first horizontal axis added to the chart is returned. |
|
403 | If no \a series is specified, the first horizontal axis added to the chart is returned. | |
389 |
|
404 | |||
390 | \sa addAxis(), QAbstractSeries::attachAxis() |
|
405 | \sa addAxis(), QAbstractSeries::attachAxis() | |
391 | */ |
|
406 | */ | |
392 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const |
|
407 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const | |
393 | { |
|
408 | { | |
394 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); |
|
409 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); | |
395 | if (axisList.count()) |
|
410 | if (axisList.count()) | |
396 | return axisList[0]; |
|
411 | return axisList[0]; | |
397 | return 0; |
|
412 | return 0; | |
398 | } |
|
413 | } | |
399 |
|
414 | |||
400 | /*! |
|
415 | /*! | |
401 | Returns a pointer to the vertical axis attached to the specified \a series. |
|
416 | Returns a pointer to the vertical axis attached to the specified \a series. | |
402 | If no \a series is specified, the first vertical axis added to the chart is returned. |
|
417 | If no \a series is specified, the first vertical axis added to the chart is returned. | |
403 |
|
418 | |||
404 | \sa addAxis(), QAbstractSeries::attachAxis() |
|
419 | \sa addAxis(), QAbstractSeries::attachAxis() | |
405 | */ |
|
420 | */ | |
406 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const |
|
421 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const | |
407 | { |
|
422 | { | |
408 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); |
|
423 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); | |
409 | if (axisList.count()) |
|
424 | if (axisList.count()) | |
410 | return axisList[0]; |
|
425 | return axisList[0]; | |
411 | return 0; |
|
426 | return 0; | |
412 | } |
|
427 | } | |
413 |
|
428 | |||
414 | /*! |
|
429 | /*! | |
415 | Returns the axes attached to the \a series with \a orientation. If no \a series is provided, |
|
430 | Returns the axes attached to the \a series with \a orientation. If no \a series is provided, | |
416 | then all axes added to the chart with the specified orientation are returned. |
|
431 | then all axes added to the chart with the specified orientation are returned. | |
417 | \sa addAxis(), createDefaultAxes() |
|
432 | \sa addAxis(), createDefaultAxes() | |
418 | */ |
|
433 | */ | |
419 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const |
|
434 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const | |
420 | { |
|
435 | { | |
421 | QList<QAbstractAxis *> result ; |
|
436 | QList<QAbstractAxis *> result ; | |
422 |
|
437 | |||
423 | if (series) { |
|
438 | if (series) { | |
424 | foreach (QAbstractAxis *axis, series->attachedAxes()){ |
|
439 | foreach (QAbstractAxis *axis, series->attachedAxes()){ | |
425 | if (orientation.testFlag(axis->orientation())) |
|
440 | if (orientation.testFlag(axis->orientation())) | |
426 | result << axis; |
|
441 | result << axis; | |
427 | } |
|
442 | } | |
428 | } else { |
|
443 | } else { | |
429 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ |
|
444 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ | |
430 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) |
|
445 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) | |
431 | result << axis; |
|
446 | result << axis; | |
432 | } |
|
447 | } | |
433 | } |
|
448 | } | |
434 |
|
449 | |||
435 | return result; |
|
450 | return result; | |
436 | } |
|
451 | } | |
437 |
|
452 | |||
438 | /*! |
|
453 | /*! | |
439 | Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to |
|
454 | Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to | |
440 | the chart will be deleted. |
|
455 | the chart will be deleted. | |
441 |
|
456 | |||
442 | \note This function has to be called after all series have been added to the chart. The axes created by this function |
|
457 | \note This function has to be called after all series have been added to the chart. The axes created by this function | |
443 | will NOT get automatically attached to any series added to the chart after this function has been called. |
|
458 | will NOT get automatically attached to any series added to the chart after this function has been called. | |
444 | A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing |
|
459 | A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing | |
445 | if there are other series with properly attached axes also present. |
|
460 | if there are other series with properly attached axes also present. | |
446 |
|
461 | |||
447 | \table |
|
462 | \table | |
448 | \header |
|
463 | \header | |
449 | \li Series type |
|
464 | \li Series type | |
450 | \li X-axis |
|
465 | \li X-axis | |
451 | \li Y-axis |
|
466 | \li Y-axis | |
452 | \row |
|
467 | \row | |
453 | \li QXYSeries |
|
468 | \li QXYSeries | |
454 | \li QValueAxis |
|
469 | \li QValueAxis | |
455 | \li QValueAxis |
|
470 | \li QValueAxis | |
456 | \row |
|
471 | \row | |
457 | \li QBarSeries |
|
472 | \li QBarSeries | |
458 | \li QBarCategoryAxis |
|
473 | \li QBarCategoryAxis | |
459 | \li QValueAxis |
|
474 | \li QValueAxis | |
460 | \row |
|
475 | \row | |
461 | \li QPieSeries |
|
476 | \li QPieSeries | |
462 | \li None |
|
477 | \li None | |
463 | \li None |
|
478 | \li None | |
464 | \endtable |
|
479 | \endtable | |
465 |
|
480 | |||
466 | If there are several QXYSeries derived series added to the chart and no series of other types have been added, then only one pair of axes is created. |
|
481 | If there are several QXYSeries derived series added to the chart and no series of other types have been added, then only one pair of axes is created. | |
467 | If there are several series of different types added to the chart, then each series gets its own axes pair. |
|
482 | If there are several series of different types added to the chart, then each series gets its own axes pair. | |
468 |
|
483 | |||
469 | The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call. |
|
484 | The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call. | |
470 | QPieSeries does not create any axes. |
|
485 | QPieSeries does not create any axes. | |
471 |
|
486 | |||
472 | \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis() |
|
487 | \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis() | |
473 | */ |
|
488 | */ | |
474 | void QChart::createDefaultAxes() |
|
489 | void QChart::createDefaultAxes() | |
475 | { |
|
490 | { | |
476 | d_ptr->m_dataset->createDefaultAxes(); |
|
491 | d_ptr->m_dataset->createDefaultAxes(); | |
477 | } |
|
492 | } | |
478 |
|
493 | |||
479 | /*! |
|
494 | /*! | |
480 | Returns the legend object of the chart. Ownership stays with the chart. |
|
495 | Returns the legend object of the chart. Ownership stays with the chart. | |
481 | */ |
|
496 | */ | |
482 | QLegend *QChart::legend() const |
|
497 | QLegend *QChart::legend() const | |
483 | { |
|
498 | { | |
484 | return d_ptr->m_legend; |
|
499 | return d_ptr->m_legend; | |
485 | } |
|
500 | } | |
486 |
|
501 | |||
487 | void QChart::setMinimumMargins(const QMargins &margins) |
|
502 | void QChart::setMinimumMargins(const QMargins &margins) | |
488 | { |
|
503 | { | |
489 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; |
|
504 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; | |
490 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
505 | d_ptr->m_presenter->layout()->setMargins(margins); | |
491 | } |
|
506 | } | |
492 |
|
507 | |||
493 | QMargins QChart::minimumMargins() const |
|
508 | QMargins QChart::minimumMargins() const | |
494 | { |
|
509 | { | |
495 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; |
|
510 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; | |
496 | return d_ptr->m_presenter->layout()->margins(); |
|
511 | return d_ptr->m_presenter->layout()->margins(); | |
497 | } |
|
512 | } | |
498 |
|
513 | |||
499 | void QChart::setMargins(const QMargins &margins) |
|
514 | void QChart::setMargins(const QMargins &margins) | |
500 | { |
|
515 | { | |
501 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
516 | d_ptr->m_presenter->layout()->setMargins(margins); | |
502 | } |
|
517 | } | |
503 |
|
518 | |||
504 | QMargins QChart::margins() const |
|
519 | QMargins QChart::margins() const | |
505 | { |
|
520 | { | |
506 | return d_ptr->m_presenter->layout()->margins(); |
|
521 | return d_ptr->m_presenter->layout()->margins(); | |
507 | } |
|
522 | } | |
508 |
|
523 | |||
509 | QChart::ChartType QChart::chartType() const |
|
524 | QChart::ChartType QChart::chartType() const | |
510 | { |
|
525 | { | |
511 | return d_ptr->m_type; |
|
526 | return d_ptr->m_type; | |
512 | } |
|
527 | } | |
513 |
|
528 | |||
514 | /*! |
|
529 | /*! | |
515 | Returns the the rectangle within which the drawing of the chart is done. |
|
530 | Returns the the rectangle within which the drawing of the chart is done. | |
516 | It does not include the area defined by margins. |
|
531 | It does not include the area defined by margins. | |
517 | */ |
|
532 | */ | |
518 | QRectF QChart::plotArea() const |
|
533 | QRectF QChart::plotArea() const | |
519 | { |
|
534 | { | |
520 | return d_ptr->m_presenter->geometry(); |
|
535 | return d_ptr->m_presenter->geometry(); | |
521 | } |
|
536 | } | |
522 |
|
537 | |||
523 | /*! |
|
538 | /*! | |
524 | Sets the \a brush for the background of the plot area of the chart. |
|
539 | Sets the \a brush for the background of the plot area of the chart. | |
525 |
|
540 | |||
526 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush() |
|
541 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush() | |
527 | */ |
|
542 | */ | |
528 | void QChart::setPlotAreaBackgroundBrush(const QBrush &brush) |
|
543 | void QChart::setPlotAreaBackgroundBrush(const QBrush &brush) | |
529 | { |
|
544 | { | |
530 | d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush); |
|
545 | d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush); | |
531 | } |
|
546 | } | |
532 |
|
547 | |||
533 | /*! |
|
548 | /*! | |
534 | Returns the brush for the background of the plot area of the chart. |
|
549 | Returns the brush for the background of the plot area of the chart. | |
535 |
|
550 | |||
536 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush() |
|
551 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush() | |
537 | */ |
|
552 | */ | |
538 | QBrush QChart::plotAreaBackgroundBrush() const |
|
553 | QBrush QChart::plotAreaBackgroundBrush() const | |
539 | { |
|
554 | { | |
540 | return d_ptr->m_presenter->plotAreaBackgroundBrush(); |
|
555 | return d_ptr->m_presenter->plotAreaBackgroundBrush(); | |
541 | } |
|
556 | } | |
542 |
|
557 | |||
543 | /*! |
|
558 | /*! | |
544 | Sets the \a pen for the background of the plot area of the chart. |
|
559 | Sets the \a pen for the background of the plot area of the chart. | |
545 |
|
560 | |||
546 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen() |
|
561 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen() | |
547 | */ |
|
562 | */ | |
548 | void QChart::setPlotAreaBackgroundPen(const QPen &pen) |
|
563 | void QChart::setPlotAreaBackgroundPen(const QPen &pen) | |
549 | { |
|
564 | { | |
550 | d_ptr->m_presenter->setPlotAreaBackgroundPen(pen); |
|
565 | d_ptr->m_presenter->setPlotAreaBackgroundPen(pen); | |
551 | } |
|
566 | } | |
552 |
|
567 | |||
553 | /*! |
|
568 | /*! | |
554 | Returns the pen for the background of the plot area of the chart. |
|
569 | Returns the pen for the background of the plot area of the chart. | |
555 |
|
570 | |||
556 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen() |
|
571 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen() | |
557 | */ |
|
572 | */ | |
558 | QPen QChart::plotAreaBackgroundPen() const |
|
573 | QPen QChart::plotAreaBackgroundPen() const | |
559 | { |
|
574 | { | |
560 | return d_ptr->m_presenter->plotAreaBackgroundPen(); |
|
575 | return d_ptr->m_presenter->plotAreaBackgroundPen(); | |
561 | } |
|
576 | } | |
562 |
|
577 | |||
563 | void QChart::setPlotAreaBackgroundVisible(bool visible) |
|
578 | void QChart::setPlotAreaBackgroundVisible(bool visible) | |
564 | { |
|
579 | { | |
565 | d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible); |
|
580 | d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible); | |
566 | } |
|
581 | } | |
567 |
|
582 | |||
568 | bool QChart::isPlotAreaBackgroundVisible() const |
|
583 | bool QChart::isPlotAreaBackgroundVisible() const | |
569 | { |
|
584 | { | |
570 | return d_ptr->m_presenter->isPlotAreaBackgroundVisible(); |
|
585 | return d_ptr->m_presenter->isPlotAreaBackgroundVisible(); | |
571 | } |
|
586 | } | |
572 |
|
587 | |||
573 | void QChart::setLocalizeNumbers(bool localize) |
|
588 | void QChart::setLocalizeNumbers(bool localize) | |
574 | { |
|
589 | { | |
575 | d_ptr->m_presenter->setLocalizeNumbers(localize); |
|
590 | d_ptr->m_presenter->setLocalizeNumbers(localize); | |
576 | } |
|
591 | } | |
577 |
|
592 | |||
578 | bool QChart::localizeNumbers() const |
|
593 | bool QChart::localizeNumbers() const | |
579 | { |
|
594 | { | |
580 | return d_ptr->m_presenter->localizeNumbers(); |
|
595 | return d_ptr->m_presenter->localizeNumbers(); | |
581 | } |
|
596 | } | |
582 |
|
597 | |||
|
598 | void QChart::setLocale(const QLocale &locale) | |||
|
599 | { | |||
|
600 | d_ptr->m_presenter->setLocale(locale); | |||
|
601 | } | |||
|
602 | ||||
|
603 | QLocale QChart::locale() const | |||
|
604 | { | |||
|
605 | return d_ptr->m_presenter->locale(); | |||
|
606 | } | |||
|
607 | ||||
583 | void QChart::setAnimationOptions(AnimationOptions options) |
|
608 | void QChart::setAnimationOptions(AnimationOptions options) | |
584 | { |
|
609 | { | |
585 | d_ptr->m_presenter->setAnimationOptions(options); |
|
610 | d_ptr->m_presenter->setAnimationOptions(options); | |
586 | } |
|
611 | } | |
587 |
|
612 | |||
588 | QChart::AnimationOptions QChart::animationOptions() const |
|
613 | QChart::AnimationOptions QChart::animationOptions() const | |
589 | { |
|
614 | { | |
590 | return d_ptr->m_presenter->animationOptions(); |
|
615 | return d_ptr->m_presenter->animationOptions(); | |
591 | } |
|
616 | } | |
592 |
|
617 | |||
593 | /*! |
|
618 | /*! | |
594 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
619 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. | |
595 |
|
620 | |||
596 | For polar charts, \a dx indicates the angle along angular axis instead of distance. |
|
621 | For polar charts, \a dx indicates the angle along angular axis instead of distance. | |
597 | */ |
|
622 | */ | |
598 | void QChart::scroll(qreal dx, qreal dy) |
|
623 | void QChart::scroll(qreal dx, qreal dy) | |
599 | { |
|
624 | { | |
600 | d_ptr->scroll(dx,dy); |
|
625 | d_ptr->scroll(dx,dy); | |
601 | } |
|
626 | } | |
602 |
|
627 | |||
603 | void QChart::setBackgroundVisible(bool visible) |
|
628 | void QChart::setBackgroundVisible(bool visible) | |
604 | { |
|
629 | { | |
605 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
630 | d_ptr->m_presenter->setBackgroundVisible(visible); | |
606 | } |
|
631 | } | |
607 |
|
632 | |||
608 | bool QChart::isBackgroundVisible() const |
|
633 | bool QChart::isBackgroundVisible() const | |
609 | { |
|
634 | { | |
610 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
635 | return d_ptr->m_presenter->isBackgroundVisible(); | |
611 | } |
|
636 | } | |
612 |
|
637 | |||
613 | void QChart::setDropShadowEnabled(bool enabled) |
|
638 | void QChart::setDropShadowEnabled(bool enabled) | |
614 | { |
|
639 | { | |
615 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
640 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); | |
616 | } |
|
641 | } | |
617 |
|
642 | |||
618 | bool QChart::isDropShadowEnabled() const |
|
643 | bool QChart::isDropShadowEnabled() const | |
619 | { |
|
644 | { | |
620 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
645 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); | |
621 | } |
|
646 | } | |
622 |
|
647 | |||
623 | void QChart::setBackgroundRoundness(qreal diameter) |
|
648 | void QChart::setBackgroundRoundness(qreal diameter) | |
624 | { |
|
649 | { | |
625 | d_ptr->m_presenter->setBackgroundRoundness(diameter); |
|
650 | d_ptr->m_presenter->setBackgroundRoundness(diameter); | |
626 | } |
|
651 | } | |
627 |
|
652 | |||
628 | qreal QChart::backgroundRoundness() const |
|
653 | qreal QChart::backgroundRoundness() const | |
629 | { |
|
654 | { | |
630 | return d_ptr->m_presenter->backgroundRoundness(); |
|
655 | return d_ptr->m_presenter->backgroundRoundness(); | |
631 | } |
|
656 | } | |
632 |
|
657 | |||
633 | /*! |
|
658 | /*! | |
634 | Returns all series that are added to the chart. |
|
659 | Returns all series that are added to the chart. | |
635 |
|
660 | |||
636 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
661 | \sa addSeries(), removeSeries(), removeAllSeries() | |
637 | */ |
|
662 | */ | |
638 | QList<QAbstractSeries *> QChart::series() const |
|
663 | QList<QAbstractSeries *> QChart::series() const | |
639 | { |
|
664 | { | |
640 | return d_ptr->m_dataset->series(); |
|
665 | return d_ptr->m_dataset->series(); | |
641 | } |
|
666 | } | |
642 |
|
667 | |||
643 | /*! |
|
668 | /*! | |
644 | Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis. |
|
669 | Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis. | |
645 | The chart takes ownership of both the \a axis and the \a series. |
|
670 | The chart takes ownership of both the \a axis and the \a series. | |
646 | Any horizontal axes previously attached to the \a series are deleted. |
|
671 | Any horizontal axes previously attached to the \a series are deleted. | |
647 |
|
672 | |||
648 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
673 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
649 | */ |
|
674 | */ | |
650 | void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series) |
|
675 | void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series) | |
651 | { |
|
676 | { | |
652 | QList<QAbstractAxis*> list = axes(Qt::Horizontal, series); |
|
677 | QList<QAbstractAxis*> list = axes(Qt::Horizontal, series); | |
653 |
|
678 | |||
654 | foreach (QAbstractAxis* a, list) { |
|
679 | foreach (QAbstractAxis* a, list) { | |
655 | d_ptr->m_dataset->removeAxis(a); |
|
680 | d_ptr->m_dataset->removeAxis(a); | |
656 | delete a; |
|
681 | delete a; | |
657 | } |
|
682 | } | |
658 |
|
683 | |||
659 | if (!d_ptr->m_dataset->axes().contains(axis)) |
|
684 | if (!d_ptr->m_dataset->axes().contains(axis)) | |
660 | d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom); |
|
685 | d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom); | |
661 | d_ptr->m_dataset->attachAxis(series, axis); |
|
686 | d_ptr->m_dataset->attachAxis(series, axis); | |
662 | } |
|
687 | } | |
663 |
|
688 | |||
664 | /*! |
|
689 | /*! | |
665 | Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis. |
|
690 | Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis. | |
666 | The chart takes ownership of both the \a axis and the \a series. |
|
691 | The chart takes ownership of both the \a axis and the \a series. | |
667 | Any vertical axes previously attached to the \a series are deleted. |
|
692 | Any vertical axes previously attached to the \a series are deleted. | |
668 |
|
693 | |||
669 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
694 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
670 | */ |
|
695 | */ | |
671 | void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series) |
|
696 | void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series) | |
672 | { |
|
697 | { | |
673 | QList<QAbstractAxis*> list = axes(Qt::Vertical, series); |
|
698 | QList<QAbstractAxis*> list = axes(Qt::Vertical, series); | |
674 |
|
699 | |||
675 | foreach (QAbstractAxis* a, list) { |
|
700 | foreach (QAbstractAxis* a, list) { | |
676 | d_ptr->m_dataset->removeAxis(a); |
|
701 | d_ptr->m_dataset->removeAxis(a); | |
677 | delete a; |
|
702 | delete a; | |
678 | } |
|
703 | } | |
679 |
|
704 | |||
680 | if (!d_ptr->m_dataset->axes().contains(axis)) |
|
705 | if (!d_ptr->m_dataset->axes().contains(axis)) | |
681 | d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft); |
|
706 | d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft); | |
682 | d_ptr->m_dataset->attachAxis(series, axis); |
|
707 | d_ptr->m_dataset->attachAxis(series, axis); | |
683 | } |
|
708 | } | |
684 |
|
709 | |||
685 | /*! |
|
710 | /*! | |
686 | Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis. |
|
711 | Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis. | |
687 |
|
712 | |||
688 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
713 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
689 | */ |
|
714 | */ | |
690 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) |
|
715 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) | |
691 | { |
|
716 | { | |
692 | d_ptr->m_dataset->addAxis(axis, alignment); |
|
717 | d_ptr->m_dataset->addAxis(axis, alignment); | |
693 | } |
|
718 | } | |
694 |
|
719 | |||
695 | /*! |
|
720 | /*! | |
696 | Removes the \a axis from the chart. |
|
721 | Removes the \a axis from the chart. | |
697 | The chart releases its ownership of the specified \a axis object. |
|
722 | The chart releases its ownership of the specified \a axis object. | |
698 |
|
723 | |||
699 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() |
|
724 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() | |
700 | */ |
|
725 | */ | |
701 | void QChart::removeAxis(QAbstractAxis *axis) |
|
726 | void QChart::removeAxis(QAbstractAxis *axis) | |
702 | { |
|
727 | { | |
703 | d_ptr->m_dataset->removeAxis(axis); |
|
728 | d_ptr->m_dataset->removeAxis(axis); | |
704 | } |
|
729 | } | |
705 |
|
730 | |||
706 | /*! |
|
731 | /*! | |
707 | Returns the value in the \a series domain that corresponds to the \a position relative to chart widget. |
|
732 | Returns the value in the \a series domain that corresponds to the \a position relative to chart widget. | |
708 | */ |
|
733 | */ | |
709 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
734 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) | |
710 | { |
|
735 | { | |
711 | return d_ptr->m_dataset->mapToValue(position, series); |
|
736 | return d_ptr->m_dataset->mapToValue(position, series); | |
712 | } |
|
737 | } | |
713 |
|
738 | |||
714 | /*! |
|
739 | /*! | |
715 | Returns the position on the chart widget that corresponds to the \a value in the \a series domain. |
|
740 | Returns the position on the chart widget that corresponds to the \a value in the \a series domain. | |
716 | */ |
|
741 | */ | |
717 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
742 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) | |
718 | { |
|
743 | { | |
719 | return d_ptr->m_dataset->mapToPosition(value, series); |
|
744 | return d_ptr->m_dataset->mapToPosition(value, series); | |
720 | } |
|
745 | } | |
721 |
|
746 | |||
722 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
747 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
723 |
|
748 | |||
724 | QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type): |
|
749 | QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type): | |
725 | q_ptr(q), |
|
750 | q_ptr(q), | |
726 | m_legend(0), |
|
751 | m_legend(0), | |
727 | m_dataset(new ChartDataSet(q)), |
|
752 | m_dataset(new ChartDataSet(q)), | |
728 | m_presenter(new ChartPresenter(q, type)), |
|
753 | m_presenter(new ChartPresenter(q, type)), | |
729 | m_themeManager(new ChartThemeManager(q)), |
|
754 | m_themeManager(new ChartThemeManager(q)), | |
730 | m_type(type) |
|
755 | m_type(type) | |
731 | { |
|
756 | { | |
732 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
757 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
733 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
758 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
734 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
759 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); | |
735 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
760 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
736 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
761 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
737 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
762 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
738 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
763 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); | |
739 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
764 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
740 | } |
|
765 | } | |
741 |
|
766 | |||
742 | QChartPrivate::~QChartPrivate() |
|
767 | QChartPrivate::~QChartPrivate() | |
743 | { |
|
768 | { | |
744 | } |
|
769 | } | |
745 |
|
770 | |||
746 | // Hackish solution to the problem of explicitly assigning the default pen/brush/font |
|
771 | // Hackish solution to the problem of explicitly assigning the default pen/brush/font | |
747 | // to a series or axis and having theme override it: |
|
772 | // to a series or axis and having theme override it: | |
748 | // Initialize pens, brushes, and fonts to something nobody is likely to ever use, |
|
773 | // Initialize pens, brushes, and fonts to something nobody is likely to ever use, | |
749 | // so that default theme initialization will always set these properly. |
|
774 | // so that default theme initialization will always set these properly. | |
750 | QPen &QChartPrivate::defaultPen() |
|
775 | QPen &QChartPrivate::defaultPen() | |
751 | { |
|
776 | { | |
752 | static QPen defaultPen(QColor(1, 2, 0), 0.93247536); |
|
777 | static QPen defaultPen(QColor(1, 2, 0), 0.93247536); | |
753 | return defaultPen; |
|
778 | return defaultPen; | |
754 | } |
|
779 | } | |
755 |
|
780 | |||
756 | QBrush &QChartPrivate::defaultBrush() |
|
781 | QBrush &QChartPrivate::defaultBrush() | |
757 | { |
|
782 | { | |
758 | static QBrush defaultBrush(QColor(1, 2, 0), Qt::Dense7Pattern); |
|
783 | static QBrush defaultBrush(QColor(1, 2, 0), Qt::Dense7Pattern); | |
759 | return defaultBrush; |
|
784 | return defaultBrush; | |
760 | } |
|
785 | } | |
761 |
|
786 | |||
762 | QFont &QChartPrivate::defaultFont() |
|
787 | QFont &QChartPrivate::defaultFont() | |
763 | { |
|
788 | { | |
764 | static bool defaultFontInitialized(false); |
|
789 | static bool defaultFontInitialized(false); | |
765 | static QFont defaultFont; |
|
790 | static QFont defaultFont; | |
766 | if (!defaultFontInitialized) { |
|
791 | if (!defaultFontInitialized) { | |
767 | defaultFont.setPointSizeF(8.34563465); |
|
792 | defaultFont.setPointSizeF(8.34563465); | |
768 | defaultFontInitialized = true; |
|
793 | defaultFontInitialized = true; | |
769 | } |
|
794 | } | |
770 | return defaultFont; |
|
795 | return defaultFont; | |
771 | } |
|
796 | } | |
772 |
|
797 | |||
773 | void QChartPrivate::init() |
|
798 | void QChartPrivate::init() | |
774 | { |
|
799 | { | |
775 | m_legend = new LegendScroller(q_ptr); |
|
800 | m_legend = new LegendScroller(q_ptr); | |
776 | q_ptr->setTheme(QChart::ChartThemeLight); |
|
801 | q_ptr->setTheme(QChart::ChartThemeLight); | |
777 | q_ptr->setLayout(m_presenter->layout()); |
|
802 | q_ptr->setLayout(m_presenter->layout()); | |
778 | } |
|
803 | } | |
779 |
|
804 | |||
780 | void QChartPrivate::zoomIn(qreal factor) |
|
805 | void QChartPrivate::zoomIn(qreal factor) | |
781 | { |
|
806 | { | |
782 | QRectF rect = m_presenter->geometry(); |
|
807 | QRectF rect = m_presenter->geometry(); | |
783 | rect.setWidth(rect.width() / factor); |
|
808 | rect.setWidth(rect.width() / factor); | |
784 | rect.setHeight(rect.height() / factor); |
|
809 | rect.setHeight(rect.height() / factor); | |
785 | rect.moveCenter(m_presenter->geometry().center()); |
|
810 | rect.moveCenter(m_presenter->geometry().center()); | |
786 | zoomIn(rect); |
|
811 | zoomIn(rect); | |
787 | } |
|
812 | } | |
788 |
|
813 | |||
789 | void QChartPrivate::zoomIn(const QRectF &rect) |
|
814 | void QChartPrivate::zoomIn(const QRectF &rect) | |
790 | { |
|
815 | { | |
791 | if (!rect.isValid()) |
|
816 | if (!rect.isValid()) | |
792 | return; |
|
817 | return; | |
793 |
|
818 | |||
794 | QRectF r = rect.normalized(); |
|
819 | QRectF r = rect.normalized(); | |
795 | const QRectF geometry = m_presenter->geometry(); |
|
820 | const QRectF geometry = m_presenter->geometry(); | |
796 | r.translate(-geometry.topLeft()); |
|
821 | r.translate(-geometry.topLeft()); | |
797 |
|
822 | |||
798 | if (!r.isValid()) |
|
823 | if (!r.isValid()) | |
799 | return; |
|
824 | return; | |
800 |
|
825 | |||
801 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
826 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |
802 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); |
|
827 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); | |
803 | m_dataset->zoomInDomain(r); |
|
828 | m_dataset->zoomInDomain(r); | |
804 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
829 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
805 |
|
830 | |||
806 | } |
|
831 | } | |
807 |
|
832 | |||
808 | void QChartPrivate::zoomReset() |
|
833 | void QChartPrivate::zoomReset() | |
809 | { |
|
834 | { | |
810 | m_dataset->zoomResetDomain(); |
|
835 | m_dataset->zoomResetDomain(); | |
811 | } |
|
836 | } | |
812 |
|
837 | |||
813 | bool QChartPrivate::isZoomed() |
|
838 | bool QChartPrivate::isZoomed() | |
814 | { |
|
839 | { | |
815 | return m_dataset->isZoomedDomain(); |
|
840 | return m_dataset->isZoomedDomain(); | |
816 | } |
|
841 | } | |
817 |
|
842 | |||
818 | void QChartPrivate::zoomOut(qreal factor) |
|
843 | void QChartPrivate::zoomOut(qreal factor) | |
819 | { |
|
844 | { | |
820 | const QRectF geometry = m_presenter->geometry(); |
|
845 | const QRectF geometry = m_presenter->geometry(); | |
821 |
|
846 | |||
822 | QRectF r; |
|
847 | QRectF r; | |
823 | r.setSize(geometry.size() / factor); |
|
848 | r.setSize(geometry.size() / factor); | |
824 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); |
|
849 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); | |
825 | if (!r.isValid()) |
|
850 | if (!r.isValid()) | |
826 | return; |
|
851 | return; | |
827 |
|
852 | |||
828 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
853 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |
829 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); |
|
854 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); | |
830 | m_dataset->zoomOutDomain(r); |
|
855 | m_dataset->zoomOutDomain(r); | |
831 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
856 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
832 | } |
|
857 | } | |
833 |
|
858 | |||
834 | void QChartPrivate::scroll(qreal dx, qreal dy) |
|
859 | void QChartPrivate::scroll(qreal dx, qreal dy) | |
835 | { |
|
860 | { | |
836 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); |
|
861 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); | |
837 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); |
|
862 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); | |
838 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); |
|
863 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); | |
839 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); |
|
864 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); | |
840 |
|
865 | |||
841 | m_dataset->scrollDomain(dx, dy); |
|
866 | m_dataset->scrollDomain(dx, dy); | |
842 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
867 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
843 | } |
|
868 | } | |
844 |
|
869 | |||
845 | #include "moc_qchart.cpp" |
|
870 | #include "moc_qchart.cpp" | |
846 |
|
871 | |||
847 | QTCOMMERCIALCHART_END_NAMESPACE |
|
872 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,180 +1,183 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2014 Digia Plc |
|
3 | ** Copyright (C) 2014 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Enterprise Charts Add-on. |
|
7 | ** This file is part of the Qt Enterprise Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
11 | ** accordance with the Qt Enterprise License Agreement provided with the |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QCHART_H |
|
21 | #ifndef QCHART_H | |
22 | #define QCHART_H |
|
22 | #define QCHART_H | |
23 |
|
23 | |||
24 | #include <QAbstractSeries> |
|
24 | #include <QAbstractSeries> | |
25 | #include <QLegend> |
|
25 | #include <QLegend> | |
26 | #include <QGraphicsWidget> |
|
26 | #include <QGraphicsWidget> | |
27 | #include <QMargins> |
|
27 | #include <QMargins> | |
28 |
|
28 | |||
29 | class QGraphicsSceneResizeEvent; |
|
29 | class QGraphicsSceneResizeEvent; | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | class QAbstractSeries; |
|
33 | class QAbstractSeries; | |
34 | class QAbstractAxis; |
|
34 | class QAbstractAxis; | |
35 | class QLegend; |
|
35 | class QLegend; | |
36 | class QChartPrivate; |
|
36 | class QChartPrivate; | |
37 | class QBoxPlotSeries; |
|
37 | class QBoxPlotSeries; | |
38 |
|
38 | |||
39 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
39 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
40 | { |
|
40 | { | |
41 | Q_OBJECT |
|
41 | Q_OBJECT | |
42 | Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme) |
|
42 | Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme) | |
43 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
43 | Q_PROPERTY(QString title READ title WRITE setTitle) | |
44 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible) |
|
44 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible) | |
45 | Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled) |
|
45 | Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled) | |
46 | Q_PROPERTY(qreal backgroundRoundness READ backgroundRoundness WRITE setBackgroundRoundness) |
|
46 | Q_PROPERTY(qreal backgroundRoundness READ backgroundRoundness WRITE setBackgroundRoundness) | |
47 | Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions) |
|
47 | Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions) | |
48 | Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins) |
|
48 | Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins) | |
49 | Q_PROPERTY(QMargins margins READ margins WRITE setMargins) |
|
49 | Q_PROPERTY(QMargins margins READ margins WRITE setMargins) | |
50 | Q_PROPERTY(QChart::ChartType chartType READ chartType) |
|
50 | Q_PROPERTY(QChart::ChartType chartType READ chartType) | |
51 | Q_PROPERTY(bool plotAreaBackgroundVisible READ isPlotAreaBackgroundVisible WRITE setPlotAreaBackgroundVisible) |
|
51 | Q_PROPERTY(bool plotAreaBackgroundVisible READ isPlotAreaBackgroundVisible WRITE setPlotAreaBackgroundVisible) | |
52 | Q_PROPERTY(bool localizeNumbers READ localizeNumbers WRITE setLocalizeNumbers) |
|
52 | Q_PROPERTY(bool localizeNumbers READ localizeNumbers WRITE setLocalizeNumbers) | |
|
53 | Q_PROPERTY(QLocale locale READ locale WRITE setLocale) | |||
53 | Q_ENUMS(ChartTheme) |
|
54 | Q_ENUMS(ChartTheme) | |
54 | Q_ENUMS(AnimationOption) |
|
55 | Q_ENUMS(AnimationOption) | |
55 | Q_ENUMS(ChartType) |
|
56 | Q_ENUMS(ChartType) | |
56 |
|
57 | |||
57 | public: |
|
58 | public: | |
58 | enum ChartType { |
|
59 | enum ChartType { | |
59 | ChartTypeUndefined = 0, |
|
60 | ChartTypeUndefined = 0, | |
60 | ChartTypeCartesian, |
|
61 | ChartTypeCartesian, | |
61 | ChartTypePolar |
|
62 | ChartTypePolar | |
62 | }; |
|
63 | }; | |
63 |
|
64 | |||
64 | enum ChartTheme { |
|
65 | enum ChartTheme { | |
65 | ChartThemeLight = 0, |
|
66 | ChartThemeLight = 0, | |
66 | ChartThemeBlueCerulean, |
|
67 | ChartThemeBlueCerulean, | |
67 | ChartThemeDark, |
|
68 | ChartThemeDark, | |
68 | ChartThemeBrownSand, |
|
69 | ChartThemeBrownSand, | |
69 | ChartThemeBlueNcs, |
|
70 | ChartThemeBlueNcs, | |
70 | ChartThemeHighContrast, |
|
71 | ChartThemeHighContrast, | |
71 | ChartThemeBlueIcy, |
|
72 | ChartThemeBlueIcy, | |
72 | ChartThemeQt |
|
73 | ChartThemeQt | |
73 | }; |
|
74 | }; | |
74 |
|
75 | |||
75 | enum AnimationOption { |
|
76 | enum AnimationOption { | |
76 | NoAnimation = 0x0, |
|
77 | NoAnimation = 0x0, | |
77 | GridAxisAnimations = 0x1, |
|
78 | GridAxisAnimations = 0x1, | |
78 | SeriesAnimations = 0x2, |
|
79 | SeriesAnimations = 0x2, | |
79 | AllAnimations = 0x3 |
|
80 | AllAnimations = 0x3 | |
80 | }; |
|
81 | }; | |
81 |
|
82 | |||
82 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
83 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) | |
83 |
|
84 | |||
84 | public: |
|
85 | public: | |
85 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
86 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
86 | ~QChart(); |
|
87 | ~QChart(); | |
87 |
|
88 | |||
88 | void addSeries(QAbstractSeries *series); |
|
89 | void addSeries(QAbstractSeries *series); | |
89 | void removeSeries(QAbstractSeries *series); |
|
90 | void removeSeries(QAbstractSeries *series); | |
90 | void removeAllSeries(); |
|
91 | void removeAllSeries(); | |
91 | QList<QAbstractSeries *> series() const; |
|
92 | QList<QAbstractSeries *> series() const; | |
92 |
|
93 | |||
93 | // *** deprecated *** |
|
94 | // *** deprecated *** | |
94 | void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
95 | void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); | |
95 | void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
96 | void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); | |
96 | QAbstractAxis *axisX(QAbstractSeries *series = 0) const; |
|
97 | QAbstractAxis *axisX(QAbstractSeries *series = 0) const; | |
97 | QAbstractAxis *axisY(QAbstractSeries *series = 0) const; |
|
98 | QAbstractAxis *axisY(QAbstractSeries *series = 0) const; | |
98 | // ****************** |
|
99 | // ****************** | |
99 |
|
100 | |||
100 | void addAxis(QAbstractAxis *axis, Qt::Alignment alignment); |
|
101 | void addAxis(QAbstractAxis *axis, Qt::Alignment alignment); | |
101 | void removeAxis(QAbstractAxis *axis); |
|
102 | void removeAxis(QAbstractAxis *axis); | |
102 | QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = 0) const; |
|
103 | QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = 0) const; | |
103 |
|
104 | |||
104 | void createDefaultAxes(); |
|
105 | void createDefaultAxes(); | |
105 |
|
106 | |||
106 | void setTheme(QChart::ChartTheme theme); |
|
107 | void setTheme(QChart::ChartTheme theme); | |
107 | QChart::ChartTheme theme() const; |
|
108 | QChart::ChartTheme theme() const; | |
108 |
|
109 | |||
109 | void setTitle(const QString &title); |
|
110 | void setTitle(const QString &title); | |
110 | QString title() const; |
|
111 | QString title() const; | |
111 | void setTitleFont(const QFont &font); |
|
112 | void setTitleFont(const QFont &font); | |
112 | QFont titleFont() const; |
|
113 | QFont titleFont() const; | |
113 | void setTitleBrush(const QBrush &brush); |
|
114 | void setTitleBrush(const QBrush &brush); | |
114 | QBrush titleBrush() const; |
|
115 | QBrush titleBrush() const; | |
115 |
|
116 | |||
116 | void setBackgroundBrush(const QBrush &brush); |
|
117 | void setBackgroundBrush(const QBrush &brush); | |
117 | QBrush backgroundBrush() const; |
|
118 | QBrush backgroundBrush() const; | |
118 | void setBackgroundPen(const QPen &pen); |
|
119 | void setBackgroundPen(const QPen &pen); | |
119 | QPen backgroundPen() const; |
|
120 | QPen backgroundPen() const; | |
120 | void setBackgroundVisible(bool visible = true); |
|
121 | void setBackgroundVisible(bool visible = true); | |
121 | bool isBackgroundVisible() const; |
|
122 | bool isBackgroundVisible() const; | |
122 |
|
123 | |||
123 | void setDropShadowEnabled(bool enabled = true); |
|
124 | void setDropShadowEnabled(bool enabled = true); | |
124 | bool isDropShadowEnabled() const; |
|
125 | bool isDropShadowEnabled() const; | |
125 | void setBackgroundRoundness(qreal diameter); |
|
126 | void setBackgroundRoundness(qreal diameter); | |
126 | qreal backgroundRoundness() const; |
|
127 | qreal backgroundRoundness() const; | |
127 | void setAnimationOptions(AnimationOptions options); |
|
128 | void setAnimationOptions(AnimationOptions options); | |
128 | AnimationOptions animationOptions() const; |
|
129 | AnimationOptions animationOptions() const; | |
129 |
|
130 | |||
130 | void zoomIn(); |
|
131 | void zoomIn(); | |
131 | void zoomOut(); |
|
132 | void zoomOut(); | |
132 |
|
133 | |||
133 | void zoomIn(const QRectF &rect); |
|
134 | void zoomIn(const QRectF &rect); | |
134 | void zoom(qreal factor); |
|
135 | void zoom(qreal factor); | |
135 | void zoomReset(); |
|
136 | void zoomReset(); | |
136 | bool isZoomed(); |
|
137 | bool isZoomed(); | |
137 |
|
138 | |||
138 | void scroll(qreal dx, qreal dy); |
|
139 | void scroll(qreal dx, qreal dy); | |
139 |
|
140 | |||
140 | QLegend *legend() const; |
|
141 | QLegend *legend() const; | |
141 |
|
142 | |||
142 | void setMinimumMargins(const QMargins& margins); |
|
143 | void setMinimumMargins(const QMargins& margins); | |
143 | QMargins minimumMargins() const; |
|
144 | QMargins minimumMargins() const; | |
144 |
|
145 | |||
145 | void setMargins(const QMargins &margins); |
|
146 | void setMargins(const QMargins &margins); | |
146 | QMargins margins() const; |
|
147 | QMargins margins() const; | |
147 |
|
148 | |||
148 | QRectF plotArea() const; |
|
149 | QRectF plotArea() const; | |
149 | void setPlotAreaBackgroundBrush(const QBrush &brush); |
|
150 | void setPlotAreaBackgroundBrush(const QBrush &brush); | |
150 | QBrush plotAreaBackgroundBrush() const; |
|
151 | QBrush plotAreaBackgroundBrush() const; | |
151 | void setPlotAreaBackgroundPen(const QPen &pen); |
|
152 | void setPlotAreaBackgroundPen(const QPen &pen); | |
152 | QPen plotAreaBackgroundPen() const; |
|
153 | QPen plotAreaBackgroundPen() const; | |
153 | void setPlotAreaBackgroundVisible(bool visible = true); |
|
154 | void setPlotAreaBackgroundVisible(bool visible = true); | |
154 | bool isPlotAreaBackgroundVisible() const; |
|
155 | bool isPlotAreaBackgroundVisible() const; | |
155 | void setLocalizeNumbers(bool localize); |
|
156 | void setLocalizeNumbers(bool localize); | |
156 | bool localizeNumbers() const; |
|
157 | bool localizeNumbers() const; | |
|
158 | void setLocale(const QLocale &locale); | |||
|
159 | QLocale locale() const; | |||
157 |
|
160 | |||
158 | QPointF mapToValue(const QPointF &position, QAbstractSeries *series = 0); |
|
161 | QPointF mapToValue(const QPointF &position, QAbstractSeries *series = 0); | |
159 | QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = 0); |
|
162 | QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = 0); | |
160 |
|
163 | |||
161 | ChartType chartType() const; |
|
164 | ChartType chartType() const; | |
162 |
|
165 | |||
163 | protected: |
|
166 | protected: | |
164 | explicit QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags); |
|
167 | explicit QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags); | |
165 | QScopedPointer<QChartPrivate> d_ptr; |
|
168 | QScopedPointer<QChartPrivate> d_ptr; | |
166 | friend class QLegend; |
|
169 | friend class QLegend; | |
167 | friend class DeclarativeChart; |
|
170 | friend class DeclarativeChart; | |
168 | friend class ChartDataSet; |
|
171 | friend class ChartDataSet; | |
169 | friend class ChartPresenter; |
|
172 | friend class ChartPresenter; | |
170 | friend class ChartThemeManager; |
|
173 | friend class ChartThemeManager; | |
171 | friend class QAbstractSeries; |
|
174 | friend class QAbstractSeries; | |
172 | friend class QBoxPlotSeriesPrivate; |
|
175 | friend class QBoxPlotSeriesPrivate; | |
173 | Q_DISABLE_COPY(QChart) |
|
176 | Q_DISABLE_COPY(QChart) | |
174 | }; |
|
177 | }; | |
175 |
|
178 | |||
176 | QTCOMMERCIALCHART_END_NAMESPACE |
|
179 | QTCOMMERCIALCHART_END_NAMESPACE | |
177 |
|
180 | |||
178 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
181 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) | |
179 |
|
182 | |||
180 | #endif // QCHART_H |
|
183 | #endif // QCHART_H |
General Comments 0
You need to be logged in to leave comments.
Login now