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