@@ -1,681 +1,698 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "legendscroller_p.h" |
|
23 | #include "legendscroller_p.h" | |
24 | #include "qlegend_p.h" |
|
24 | #include "qlegend_p.h" | |
25 | #include "chartbackground_p.h" |
|
25 | #include "chartbackground_p.h" | |
26 | #include "qabstractaxis.h" |
|
26 | #include "qabstractaxis.h" | |
27 | #include "chartlayout_p.h" |
|
27 | #include "chartlayout_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartpresenter_p.h" |
|
29 | #include "chartpresenter_p.h" | |
30 | #include "chartdataset_p.h" |
|
30 | #include "chartdataset_p.h" | |
31 | #include <QGraphicsScene> |
|
31 | #include <QGraphicsScene> | |
32 | #include <QGraphicsSceneResizeEvent> |
|
32 | #include <QGraphicsSceneResizeEvent> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \enum QChart::ChartTheme |
|
37 | \enum QChart::ChartTheme | |
38 |
|
38 | |||
39 | This enum describes the theme used by the chart. |
|
39 | This enum describes the theme used by the chart. | |
40 |
|
40 | |||
41 | \value ChartThemeLight The default theme |
|
41 | \value ChartThemeLight The default theme | |
42 | \value ChartThemeBlueCerulean |
|
42 | \value ChartThemeBlueCerulean | |
43 | \value ChartThemeDark |
|
43 | \value ChartThemeDark | |
44 | \value ChartThemeBrownSand |
|
44 | \value ChartThemeBrownSand | |
45 | \value ChartThemeBlueNcs |
|
45 | \value ChartThemeBlueNcs | |
46 | \value ChartThemeHighContrast |
|
46 | \value ChartThemeHighContrast | |
47 | \value ChartThemeBlueIcy |
|
47 | \value ChartThemeBlueIcy | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | \enum QChart::AnimationOption |
|
51 | \enum QChart::AnimationOption | |
52 |
|
52 | |||
53 | For enabling/disabling animations. Defaults to NoAnimation. |
|
53 | For enabling/disabling animations. Defaults to NoAnimation. | |
54 |
|
54 | |||
55 | \value NoAnimation |
|
55 | \value NoAnimation | |
56 | \value GridAxisAnimations |
|
56 | \value GridAxisAnimations | |
57 | \value SeriesAnimations |
|
57 | \value SeriesAnimations | |
58 | \value AllAnimations |
|
58 | \value AllAnimations | |
59 | */ |
|
59 | */ | |
60 |
|
60 | |||
61 | /*! |
|
61 | /*! | |
62 | \class QChart |
|
62 | \class QChart | |
63 | \brief QtCommercial chart API. |
|
63 | \brief QtCommercial chart API. | |
64 |
|
64 | |||
65 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
65 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
66 | representation of different types of series and other chart related objects like |
|
66 | representation of different types of series and other chart related objects like | |
67 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the |
|
67 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the | |
68 | convenience class QChartView instead of QChart. |
|
68 | convenience class QChartView instead of QChart. | |
69 | \sa QChartView |
|
69 | \sa QChartView | |
70 | */ |
|
70 | */ | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | \property QChart::animationOptions |
|
73 | \property QChart::animationOptions | |
74 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
74 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 | \property QChart::backgroundVisible |
|
78 | \property QChart::backgroundVisible | |
79 | Whether the chart background is visible or not. |
|
79 | Whether the chart background is visible or not. | |
80 | \sa setBackgroundBrush(), setBackgroundPen() |
|
80 | \sa setBackgroundBrush(), setBackgroundPen() | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \property QChart::dropShadowEnabled |
|
84 | \property QChart::dropShadowEnabled | |
85 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
85 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop | |
86 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
86 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | \property QChart::minimumMargins |
|
90 | \property QChart::minimumMargins | |
91 | Minimum margins between the plot area (axes) and the edge of the chart widget. |
|
91 | Minimum margins between the plot area (axes) and the edge of the chart widget. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
|
95 | \property QChart::margins | |||
|
96 | Minimum between the plot area (axes) and the edge of the chart widget. | |||
|
97 | */ | |||
|
98 | ||||
|
99 | /*! | |||
95 | \property QChart::theme |
|
100 | \property QChart::theme | |
96 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
101 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, | |
97 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few |
|
102 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few | |
98 | different themes. |
|
103 | different themes. | |
99 | Note: changing the theme will overwrite all customizations previously applied to the series. |
|
104 | Note: changing the theme will overwrite all customizations previously applied to the series. | |
100 | */ |
|
105 | */ | |
101 |
|
106 | |||
102 | /*! |
|
107 | /*! | |
103 | \property QChart::title |
|
108 | \property QChart::title | |
104 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. |
|
109 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. | |
105 | */ |
|
110 | */ | |
106 |
|
111 | |||
107 | /*! |
|
112 | /*! | |
108 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
113 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
109 | */ |
|
114 | */ | |
110 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
115 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
111 | : QGraphicsWidget(parent, wFlags), |
|
116 | : QGraphicsWidget(parent, wFlags), | |
112 | d_ptr(new QChartPrivate(this)) |
|
117 | d_ptr(new QChartPrivate(this)) | |
113 | { |
|
118 | { | |
114 | d_ptr->m_legend = new LegendScroller(this); |
|
119 | d_ptr->m_legend = new LegendScroller(this); | |
115 | setTheme(QChart::ChartThemeLight); |
|
120 | setTheme(QChart::ChartThemeLight); | |
116 | //TODO: what is that ? |
|
121 | //TODO: what is that ? | |
117 | //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF))); |
|
122 | //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF))); | |
118 | setLayout(d_ptr->m_presenter->layout()); |
|
123 | setLayout(d_ptr->m_presenter->layout()); | |
119 | } |
|
124 | } | |
120 |
|
125 | |||
121 | /*! |
|
126 | /*! | |
122 | Destroys the object and it's children, like series and axis objects added to it. |
|
127 | Destroys the object and it's children, like series and axis objects added to it. | |
123 | */ |
|
128 | */ | |
124 | QChart::~QChart() |
|
129 | QChart::~QChart() | |
125 | { |
|
130 | { | |
126 | //start by deleting dataset, it will remove all series and axes |
|
131 | //start by deleting dataset, it will remove all series and axes | |
127 | delete d_ptr->m_dataset; |
|
132 | delete d_ptr->m_dataset; | |
128 | d_ptr->m_dataset = 0; |
|
133 | d_ptr->m_dataset = 0; | |
129 | } |
|
134 | } | |
130 |
|
135 | |||
131 | /*! |
|
136 | /*! | |
132 | Adds the \a series onto the chart and takes the ownership of the object. |
|
137 | Adds the \a series onto the chart and takes the ownership of the object. | |
133 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
138 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
134 | the y axis). |
|
139 | the y axis). | |
135 |
|
140 | |||
136 | \sa removeSeries(), removeAllSeries() |
|
141 | \sa removeSeries(), removeAllSeries() | |
137 | */ |
|
142 | */ | |
138 | void QChart::addSeries(QAbstractSeries *series) |
|
143 | void QChart::addSeries(QAbstractSeries *series) | |
139 | { |
|
144 | { | |
140 | Q_ASSERT(series); |
|
145 | Q_ASSERT(series); | |
141 | d_ptr->m_dataset->addSeries(series); |
|
146 | d_ptr->m_dataset->addSeries(series); | |
142 | } |
|
147 | } | |
143 |
|
148 | |||
144 | /*! |
|
149 | /*! | |
145 | Removes the \a series specified in a perameter from the QChartView. |
|
150 | Removes the \a series specified in a perameter from the QChartView. | |
146 | It releses its ownership of the specified QChartSeries object. |
|
151 | It releses its ownership of the specified QChartSeries object. | |
147 | It does not delete the pointed QChartSeries data object |
|
152 | It does not delete the pointed QChartSeries data object | |
148 | \sa addSeries(), removeAllSeries() |
|
153 | \sa addSeries(), removeAllSeries() | |
149 | */ |
|
154 | */ | |
150 | void QChart::removeSeries(QAbstractSeries *series) |
|
155 | void QChart::removeSeries(QAbstractSeries *series) | |
151 | { |
|
156 | { | |
152 | Q_ASSERT(series); |
|
157 | Q_ASSERT(series); | |
153 | d_ptr->m_dataset->removeSeries(series); |
|
158 | d_ptr->m_dataset->removeSeries(series); | |
154 | } |
|
159 | } | |
155 |
|
160 | |||
156 | /*! |
|
161 | /*! | |
157 | Removes all the QChartSeries that have been added to the QChartView |
|
162 | Removes all the QChartSeries that have been added to the QChartView | |
158 | It also deletes the pointed QChartSeries data objects |
|
163 | It also deletes the pointed QChartSeries data objects | |
159 | \sa addSeries(), removeSeries() |
|
164 | \sa addSeries(), removeSeries() | |
160 | */ |
|
165 | */ | |
161 | void QChart::removeAllSeries() |
|
166 | void QChart::removeAllSeries() | |
162 | { |
|
167 | { | |
163 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ |
|
168 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ | |
164 | removeSeries(s); |
|
169 | removeSeries(s); | |
165 | delete s; |
|
170 | delete s; | |
166 | } |
|
171 | } | |
167 | } |
|
172 | } | |
168 |
|
173 | |||
169 | /*! |
|
174 | /*! | |
170 | Sets the \a brush that is used for painting the background of the chart area. |
|
175 | Sets the \a brush that is used for painting the background of the chart area. | |
171 | */ |
|
176 | */ | |
172 | void QChart::setBackgroundBrush(const QBrush &brush) |
|
177 | void QChart::setBackgroundBrush(const QBrush &brush) | |
173 | { |
|
178 | { | |
174 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
179 | d_ptr->m_presenter->setBackgroundBrush(brush); | |
175 | } |
|
180 | } | |
176 |
|
181 | |||
177 | /*! |
|
182 | /*! | |
178 | Gets the brush that is used for painting the background of the chart area. |
|
183 | Gets the brush that is used for painting the background of the chart area. | |
179 | */ |
|
184 | */ | |
180 | QBrush QChart::backgroundBrush() const |
|
185 | QBrush QChart::backgroundBrush() const | |
181 | { |
|
186 | { | |
182 | return d_ptr->m_presenter->backgroundBrush(); |
|
187 | return d_ptr->m_presenter->backgroundBrush(); | |
183 | } |
|
188 | } | |
184 |
|
189 | |||
185 | /*! |
|
190 | /*! | |
186 | Sets the \a pen that is used for painting the background of the chart area. |
|
191 | Sets the \a pen that is used for painting the background of the chart area. | |
187 | */ |
|
192 | */ | |
188 | void QChart::setBackgroundPen(const QPen &pen) |
|
193 | void QChart::setBackgroundPen(const QPen &pen) | |
189 | { |
|
194 | { | |
190 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
195 | d_ptr->m_presenter->setBackgroundPen(pen); | |
191 | } |
|
196 | } | |
192 |
|
197 | |||
193 | /*! |
|
198 | /*! | |
194 | Gets the pen that is used for painting the background of the chart area. |
|
199 | Gets the pen that is used for painting the background of the chart area. | |
195 | */ |
|
200 | */ | |
196 | QPen QChart::backgroundPen() const |
|
201 | QPen QChart::backgroundPen() const | |
197 | { |
|
202 | { | |
198 | return d_ptr->m_presenter->backgroundPen(); |
|
203 | return d_ptr->m_presenter->backgroundPen(); | |
199 | } |
|
204 | } | |
200 |
|
205 | |||
201 | /*! |
|
206 | /*! | |
202 | Sets the chart \a title. The description text that is drawn above the chart. |
|
207 | Sets the chart \a title. The description text that is drawn above the chart. | |
203 | */ |
|
208 | */ | |
204 | void QChart::setTitle(const QString &title) |
|
209 | void QChart::setTitle(const QString &title) | |
205 | { |
|
210 | { | |
206 | d_ptr->m_presenter->setTitle(title); |
|
211 | d_ptr->m_presenter->setTitle(title); | |
207 | } |
|
212 | } | |
208 |
|
213 | |||
209 | /*! |
|
214 | /*! | |
210 | Returns the chart title. The description text that is drawn above the chart. |
|
215 | Returns the chart title. The description text that is drawn above the chart. | |
211 | */ |
|
216 | */ | |
212 | QString QChart::title() const |
|
217 | QString QChart::title() const | |
213 | { |
|
218 | { | |
214 | return d_ptr->m_presenter->title(); |
|
219 | return d_ptr->m_presenter->title(); | |
215 | } |
|
220 | } | |
216 |
|
221 | |||
217 | /*! |
|
222 | /*! | |
218 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. |
|
223 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. | |
219 | */ |
|
224 | */ | |
220 | void QChart::setTitleFont(const QFont &font) |
|
225 | void QChart::setTitleFont(const QFont &font) | |
221 | { |
|
226 | { | |
222 | d_ptr->m_presenter->setTitleFont(font); |
|
227 | d_ptr->m_presenter->setTitleFont(font); | |
223 | } |
|
228 | } | |
224 |
|
229 | |||
225 | /*! |
|
230 | /*! | |
226 | Gets the font that is used for drawing the chart description text that is rendered above the chart. |
|
231 | Gets the font that is used for drawing the chart description text that is rendered above the chart. | |
227 | */ |
|
232 | */ | |
228 | QFont QChart::titleFont() const |
|
233 | QFont QChart::titleFont() const | |
229 | { |
|
234 | { | |
230 | return d_ptr->m_presenter->titleFont(); |
|
235 | return d_ptr->m_presenter->titleFont(); | |
231 | } |
|
236 | } | |
232 |
|
237 | |||
233 | /*! |
|
238 | /*! | |
234 | Sets the \a brush used for rendering the title text. |
|
239 | Sets the \a brush used for rendering the title text. | |
235 | */ |
|
240 | */ | |
236 | void QChart::setTitleBrush(const QBrush &brush) |
|
241 | void QChart::setTitleBrush(const QBrush &brush) | |
237 | { |
|
242 | { | |
238 | d_ptr->m_presenter->setTitleBrush(brush); |
|
243 | d_ptr->m_presenter->setTitleBrush(brush); | |
239 | } |
|
244 | } | |
240 |
|
245 | |||
241 | /*! |
|
246 | /*! | |
242 | Returns the brush used for rendering the title text. |
|
247 | Returns the brush used for rendering the title text. | |
243 | */ |
|
248 | */ | |
244 | QBrush QChart::titleBrush() const |
|
249 | QBrush QChart::titleBrush() const | |
245 | { |
|
250 | { | |
246 | return d_ptr->m_presenter->titleBrush(); |
|
251 | return d_ptr->m_presenter->titleBrush(); | |
247 | } |
|
252 | } | |
248 |
|
253 | |||
249 | void QChart::setTheme(QChart::ChartTheme theme) |
|
254 | void QChart::setTheme(QChart::ChartTheme theme) | |
250 | { |
|
255 | { | |
251 | d_ptr->m_themeManager->setTheme(theme); |
|
256 | d_ptr->m_themeManager->setTheme(theme); | |
252 | } |
|
257 | } | |
253 |
|
258 | |||
254 | QChart::ChartTheme QChart::theme() const |
|
259 | QChart::ChartTheme QChart::theme() const | |
255 | { |
|
260 | { | |
256 | return d_ptr->m_themeManager->theme()->id(); |
|
261 | return d_ptr->m_themeManager->theme()->id(); | |
257 | } |
|
262 | } | |
258 |
|
263 | |||
259 | /*! |
|
264 | /*! | |
260 | Zooms in the view by a factor of 2 |
|
265 | Zooms in the view by a factor of 2 | |
261 | */ |
|
266 | */ | |
262 | void QChart::zoomIn() |
|
267 | void QChart::zoomIn() | |
263 | { |
|
268 | { | |
264 | d_ptr->zoomIn(2.0); |
|
269 | d_ptr->zoomIn(2.0); | |
265 | } |
|
270 | } | |
266 |
|
271 | |||
267 | /*! |
|
272 | /*! | |
268 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
273 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
269 | */ |
|
274 | */ | |
270 | void QChart::zoomIn(const QRectF &rect) |
|
275 | void QChart::zoomIn(const QRectF &rect) | |
271 | { |
|
276 | { | |
272 | d_ptr->zoomIn(rect); |
|
277 | d_ptr->zoomIn(rect); | |
273 | } |
|
278 | } | |
274 |
|
279 | |||
275 | /*! |
|
280 | /*! | |
276 | Restores the view zoom level to the previous one. |
|
281 | Restores the view zoom level to the previous one. | |
277 | */ |
|
282 | */ | |
278 | void QChart::zoomOut() |
|
283 | void QChart::zoomOut() | |
279 | { |
|
284 | { | |
280 | d_ptr->zoomOut(2.0); |
|
285 | d_ptr->zoomOut(2.0); | |
281 | } |
|
286 | } | |
282 |
|
287 | |||
283 | /*! |
|
288 | /*! | |
284 | Zooms in the view by a \a factor. |
|
289 | Zooms in the view by a \a factor. | |
285 |
|
290 | |||
286 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
291 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. | |
287 | */ |
|
292 | */ | |
288 | void QChart::zoom(qreal factor) |
|
293 | void QChart::zoom(qreal factor) | |
289 | { |
|
294 | { | |
290 | if (qFuzzyCompare(factor, 0)) |
|
295 | if (qFuzzyCompare(factor, 0)) | |
291 | return; |
|
296 | return; | |
292 |
|
297 | |||
293 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
298 | if (qFuzzyCompare(factor, (qreal)1.0)) | |
294 | return; |
|
299 | return; | |
295 |
|
300 | |||
296 | if (factor < 0) |
|
301 | if (factor < 0) | |
297 | return; |
|
302 | return; | |
298 |
|
303 | |||
299 | if (factor > 1.0) |
|
304 | if (factor > 1.0) | |
300 | d_ptr->zoomIn(factor); |
|
305 | d_ptr->zoomIn(factor); | |
301 | else |
|
306 | else | |
302 | d_ptr->zoomOut(1.0 / factor); |
|
307 | d_ptr->zoomOut(1.0 / factor); | |
303 | } |
|
308 | } | |
304 |
|
309 | |||
305 | /*! |
|
310 | /*! | |
306 | Returns the pointer to the x axis object of the chart asociated with the specified \a series |
|
311 | Returns the pointer to the x axis object of the chart asociated with the specified \a series | |
307 | If no series is provided then pointer to currently visible axis is provided |
|
312 | If no series is provided then pointer to currently visible axis is provided | |
308 | */ |
|
313 | */ | |
309 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const |
|
314 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const | |
310 | { |
|
315 | { | |
311 | if(!series && d_ptr->m_dataset->series().size()>0){ |
|
316 | if(!series && d_ptr->m_dataset->series().size()>0){ | |
312 | series = d_ptr->m_dataset->series().first(); |
|
317 | series = d_ptr->m_dataset->series().first(); | |
313 | } |
|
318 | } | |
314 |
|
319 | |||
315 | QList<QAbstractAxis*> axes = series->attachedAxes(); |
|
320 | QList<QAbstractAxis*> axes = series->attachedAxes(); | |
316 | QAbstractAxis* bottom=0; |
|
321 | QAbstractAxis* bottom=0; | |
317 | QAbstractAxis* top=0; |
|
322 | QAbstractAxis* top=0; | |
318 |
|
323 | |||
319 | foreach(QAbstractAxis* axis, axes){ |
|
324 | foreach(QAbstractAxis* axis, axes){ | |
320 |
|
325 | |||
321 | if(axis->alignment()==Qt::AlignTop){ |
|
326 | if(axis->alignment()==Qt::AlignTop){ | |
322 | top=axis; |
|
327 | top=axis; | |
323 | } |
|
328 | } | |
324 |
|
329 | |||
325 | if(axis->alignment()==Qt::AlignBottom){ |
|
330 | if(axis->alignment()==Qt::AlignBottom){ | |
326 | bottom=axis; |
|
331 | bottom=axis; | |
327 | } |
|
332 | } | |
328 | } |
|
333 | } | |
329 | return bottom?bottom:top; |
|
334 | return bottom?bottom:top; | |
330 | } |
|
335 | } | |
331 |
|
336 | |||
332 | /*! |
|
337 | /*! | |
333 | Returns the pointer to the y axis object of the chart asociated with the specified \a series |
|
338 | Returns the pointer to the y axis object of the chart asociated with the specified \a series | |
334 | If no series is provided then pointer to currently visible axis is provided |
|
339 | If no series is provided then pointer to currently visible axis is provided | |
335 | */ |
|
340 | */ | |
336 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const |
|
341 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const | |
337 | { |
|
342 | { | |
338 | if(!series && d_ptr->m_dataset->series().size()>0) { |
|
343 | if(!series && d_ptr->m_dataset->series().size()>0) { | |
339 | series = d_ptr->m_dataset->series().first(); |
|
344 | series = d_ptr->m_dataset->series().first(); | |
340 | } |
|
345 | } | |
341 |
|
346 | |||
342 | QList<QAbstractAxis*> axes = series->attachedAxes(); |
|
347 | QList<QAbstractAxis*> axes = series->attachedAxes(); | |
343 |
|
348 | |||
344 | QAbstractAxis* left=0; |
|
349 | QAbstractAxis* left=0; | |
345 | QAbstractAxis* right=0; |
|
350 | QAbstractAxis* right=0; | |
346 |
|
351 | |||
347 | foreach(QAbstractAxis* axis, axes){ |
|
352 | foreach(QAbstractAxis* axis, axes){ | |
348 |
|
353 | |||
349 | if(axis->alignment()==Qt::AlignLeft){ |
|
354 | if(axis->alignment()==Qt::AlignLeft){ | |
350 | left=axis; |
|
355 | left=axis; | |
351 | } |
|
356 | } | |
352 |
|
357 | |||
353 | if(axis->alignment()==Qt::AlignRight){ |
|
358 | if(axis->alignment()==Qt::AlignRight){ | |
354 | right=axis; |
|
359 | right=axis; | |
355 | } |
|
360 | } | |
356 | } |
|
361 | } | |
357 |
|
362 | |||
358 | return left?left:right; |
|
363 | return left?left:right; | |
359 | } |
|
364 | } | |
360 |
|
365 | |||
|
366 | /*! | |||
|
367 | Returns the axes added for the \a series with \a orientation | |||
|
368 | \sa addAxis(), createDefaultAxes() | |||
|
369 | */ | |||
361 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const |
|
370 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const | |
362 | { |
|
371 | { | |
363 | QList<QAbstractAxis *> result ; |
|
372 | QList<QAbstractAxis *> result ; | |
364 |
|
373 | |||
365 | if (series) { |
|
374 | if (series) { | |
366 | foreach (QAbstractAxis *axis, series->attachedAxes()){ |
|
375 | foreach (QAbstractAxis *axis, series->attachedAxes()){ | |
367 | if (orientation.testFlag(axis->orientation())) |
|
376 | if (orientation.testFlag(axis->orientation())) | |
368 | result << axis; |
|
377 | result << axis; | |
369 | } |
|
378 | } | |
370 | } else { |
|
379 | } else { | |
371 | foreach (QAbstractSeries *s, QChart::series()) { |
|
380 | foreach (QAbstractSeries *s, QChart::series()) { | |
372 | foreach (QAbstractAxis *axis, s->attachedAxes()){ |
|
381 | foreach (QAbstractAxis *axis, s->attachedAxes()){ | |
373 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) |
|
382 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) | |
374 | result << axis; |
|
383 | result << axis; | |
375 | } |
|
384 | } | |
376 | } |
|
385 | } | |
377 | } |
|
386 | } | |
378 |
|
387 | |||
379 | return result; |
|
388 | return result; | |
380 | } |
|
389 | } | |
381 |
|
390 | |||
382 | /*! |
|
391 | /*! | |
383 | NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL. |
|
392 | NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL. | |
384 |
|
393 | |||
385 | Creates the axes for the chart based on the series that has already been added to the chart. |
|
394 | Creates the axes for the chart based on the series that has already been added to the chart. | |
386 |
|
395 | |||
387 | \table |
|
396 | \table | |
388 | \header |
|
397 | \header | |
389 | \o Series type |
|
398 | \o Series type | |
390 | \o X-axis |
|
399 | \o X-axis | |
391 | \o Y-axis |
|
400 | \o Y-axis | |
392 | \row |
|
401 | \row | |
393 | \o QXYSeries |
|
402 | \o QXYSeries | |
394 | \o QValueAxis |
|
403 | \o QValueAxis | |
395 | \o QValueAxis |
|
404 | \o QValueAxis | |
396 | \row |
|
405 | \row | |
397 | \o QBarSeries |
|
406 | \o QBarSeries | |
398 | \o QBarCategoryAxis |
|
407 | \o QBarCategoryAxis | |
399 | \o QValueAxis |
|
408 | \o QValueAxis | |
400 | \row |
|
409 | \row | |
401 | \o QPieSeries |
|
410 | \o QPieSeries | |
402 | \o None |
|
411 | \o None | |
403 | \o None |
|
412 | \o None | |
404 | \endtable |
|
413 | \endtable | |
405 |
|
414 | |||
406 | If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created. |
|
415 | If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created. | |
407 | If there are sevaral series added of different types then each series gets its own axes pair. |
|
416 | If there are sevaral series added of different types then each series gets its own axes pair. | |
408 |
|
417 | |||
409 | NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown. |
|
418 | NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown. | |
410 |
|
419 | |||
411 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. |
|
420 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. | |
412 | QPieSeries does not create any axes. |
|
421 | QPieSeries does not create any axes. | |
413 |
|
422 | |||
414 | \sa axisX(), axisY(), setAxisX(), setAxisY() |
|
423 | \sa axisX(), axisY(), setAxisX(), setAxisY() | |
415 | */ |
|
424 | */ | |
416 | void QChart::createDefaultAxes() |
|
425 | void QChart::createDefaultAxes() | |
417 | { |
|
426 | { | |
418 | d_ptr->m_dataset->createDefaultAxes(); |
|
427 | d_ptr->m_dataset->createDefaultAxes(); | |
419 | } |
|
428 | } | |
420 |
|
429 | |||
421 | /*! |
|
430 | /*! | |
422 | Returns the legend object of the chart. Ownership stays in chart. |
|
431 | Returns the legend object of the chart. Ownership stays in chart. | |
423 | */ |
|
432 | */ | |
424 | QLegend *QChart::legend() const |
|
433 | QLegend *QChart::legend() const | |
425 | { |
|
434 | { | |
426 | return d_ptr->m_legend; |
|
435 | return d_ptr->m_legend; | |
427 | } |
|
436 | } | |
428 |
|
437 | |||
429 | /*! |
|
438 | /*! | |
430 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
439 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. | |
431 | Deprecated. Use setMargins(). |
|
440 | Deprecated. Use setMargins(). | |
432 | */ |
|
441 | */ | |
433 | void QChart::setMinimumMargins(const QMargins &margins) |
|
442 | void QChart::setMinimumMargins(const QMargins &margins) | |
434 | { |
|
443 | { | |
435 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; |
|
444 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; | |
436 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
445 | d_ptr->m_presenter->layout()->setMargins(margins); | |
437 | } |
|
446 | } | |
438 |
|
447 | |||
439 | /*! |
|
448 | /*! | |
440 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
449 | Returns the rect that contains information about margins (distance between chart widget edge and axes). | |
441 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
450 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. | |
442 | Deprecated. Use margins(). |
|
451 | Deprecated. Use margins(). | |
443 | */ |
|
452 | */ | |
444 | QMargins QChart::minimumMargins() const |
|
453 | QMargins QChart::minimumMargins() const | |
445 | { |
|
454 | { | |
446 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; |
|
455 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; | |
447 | return d_ptr->m_presenter->layout()->margins(); |
|
456 | return d_ptr->m_presenter->layout()->margins(); | |
448 | } |
|
457 | } | |
449 |
|
458 | |||
450 | /*! |
|
459 | /*! | |
451 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
460 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. | |
452 | */ |
|
461 | */ | |
453 | void QChart::setMargins(const QMargins &margins) |
|
462 | void QChart::setMargins(const QMargins &margins) | |
454 | { |
|
463 | { | |
455 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
464 | d_ptr->m_presenter->layout()->setMargins(margins); | |
456 | } |
|
465 | } | |
457 |
|
466 | |||
458 | /*! |
|
467 | /*! | |
459 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
468 | Returns the rect that contains information about margins (distance between chart widget edge and axes). | |
460 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
469 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. | |
461 | */ |
|
470 | */ | |
462 | QMargins QChart::margins() const |
|
471 | QMargins QChart::margins() const | |
463 | { |
|
472 | { | |
464 | return d_ptr->m_presenter->layout()->margins(); |
|
473 | return d_ptr->m_presenter->layout()->margins(); | |
465 | } |
|
474 | } | |
466 |
|
475 | |||
467 | /*! |
|
476 | /*! | |
468 | Returns the the rect within which the drawing of the chart is done. |
|
477 | Returns the the rect within which the drawing of the chart is done. | |
469 | It does not include the area defines by margins. |
|
478 | It does not include the area defines by margins. | |
470 | */ |
|
479 | */ | |
471 | QRectF QChart::plotArea() const |
|
480 | QRectF QChart::plotArea() const | |
472 | { |
|
481 | { | |
473 | return d_ptr->m_presenter->geometry(); |
|
482 | return d_ptr->m_presenter->geometry(); | |
474 | } |
|
483 | } | |
475 |
|
484 | |||
476 | ///*! |
|
485 | ///*! | |
477 | // TODO: Dummy. |
|
486 | // TODO: Dummy. | |
478 | // Adjest the ranges of the axes so that all the data of the specified \a series is visible |
|
487 | // Adjest the ranges of the axes so that all the data of the specified \a series is visible | |
479 | // */ |
|
488 | // */ | |
480 | //void QChart::adjustViewToSeries(QAbstractSeries* series) |
|
489 | //void QChart::adjustViewToSeries(QAbstractSeries* series) | |
481 | //{ |
|
490 | //{ | |
482 | // // |
|
491 | // // | |
483 | //} |
|
492 | //} | |
484 |
|
493 | |||
485 | /*! |
|
494 | /*! | |
486 | Sets animation \a options for the chart |
|
495 | Sets animation \a options for the chart | |
487 | */ |
|
496 | */ | |
488 | void QChart::setAnimationOptions(AnimationOptions options) |
|
497 | void QChart::setAnimationOptions(AnimationOptions options) | |
489 | { |
|
498 | { | |
490 | d_ptr->m_presenter->setAnimationOptions(options); |
|
499 | d_ptr->m_presenter->setAnimationOptions(options); | |
491 | } |
|
500 | } | |
492 |
|
501 | |||
493 | QChart::AnimationOptions QChart::animationOptions() const |
|
502 | QChart::AnimationOptions QChart::animationOptions() const | |
494 | { |
|
503 | { | |
495 | return d_ptr->m_presenter->animationOptions(); |
|
504 | return d_ptr->m_presenter->animationOptions(); | |
496 | } |
|
505 | } | |
497 |
|
506 | |||
498 | /*! |
|
507 | /*! | |
499 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
508 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. | |
500 | */ |
|
509 | */ | |
501 | void QChart::scroll(qreal dx, qreal dy) |
|
510 | void QChart::scroll(qreal dx, qreal dy) | |
502 | { |
|
511 | { | |
503 | d_ptr->scroll(dx,dy); |
|
512 | d_ptr->scroll(dx,dy); | |
504 | } |
|
513 | } | |
505 |
|
514 | |||
506 | void QChart::setBackgroundVisible(bool visible) |
|
515 | void QChart::setBackgroundVisible(bool visible) | |
507 | { |
|
516 | { | |
508 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
517 | d_ptr->m_presenter->setBackgroundVisible(visible); | |
509 | } |
|
518 | } | |
510 |
|
519 | |||
511 | bool QChart::isBackgroundVisible() const |
|
520 | bool QChart::isBackgroundVisible() const | |
512 | { |
|
521 | { | |
513 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
522 | return d_ptr->m_presenter->isBackgroundVisible(); | |
514 | } |
|
523 | } | |
515 |
|
524 | |||
516 | void QChart::setDropShadowEnabled(bool enabled) |
|
525 | void QChart::setDropShadowEnabled(bool enabled) | |
517 | { |
|
526 | { | |
518 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
527 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); | |
519 | } |
|
528 | } | |
520 |
|
529 | |||
521 | bool QChart::isDropShadowEnabled() const |
|
530 | bool QChart::isDropShadowEnabled() const | |
522 | { |
|
531 | { | |
523 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
532 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); | |
524 | } |
|
533 | } | |
525 |
|
534 | |||
526 | /*! |
|
535 | /*! | |
527 | Returns all the series that are added to the chart. |
|
536 | Returns all the series that are added to the chart. | |
528 |
|
537 | |||
529 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
538 | \sa addSeries(), removeSeries(), removeAllSeries() | |
530 | */ |
|
539 | */ | |
531 | QList<QAbstractSeries *> QChart::series() const |
|
540 | QList<QAbstractSeries *> QChart::series() const | |
532 | { |
|
541 | { | |
533 | return d_ptr->m_dataset->series(); |
|
542 | return d_ptr->m_dataset->series(); | |
534 | } |
|
543 | } | |
535 |
|
544 | |||
536 | /*! |
|
545 | /*! | |
537 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
546 | Sets \a axis to the chart, which will control the presentation of the \a series | |
538 |
|
547 | |||
539 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() |
|
548 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() | |
540 | */ |
|
549 | */ | |
541 | void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series) |
|
550 | void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series) | |
542 | { |
|
551 | { | |
543 | QList<QAbstractAxis*> list = axes(Qt::Horizontal,series); |
|
552 | QList<QAbstractAxis*> list = axes(Qt::Horizontal,series); | |
544 |
|
553 | |||
545 | foreach(QAbstractAxis* a, list){ |
|
554 | foreach(QAbstractAxis* a, list){ | |
546 | d_ptr->m_dataset->removeAxis(a); |
|
555 | d_ptr->m_dataset->removeAxis(a); | |
547 | delete a; |
|
556 | delete a; | |
548 | } |
|
557 | } | |
549 |
|
558 | |||
550 | if(!d_ptr->m_dataset->axes().contains(axis)) |
|
559 | if(!d_ptr->m_dataset->axes().contains(axis)) | |
551 | d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom); |
|
560 | d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom); | |
552 | d_ptr->m_dataset->attachAxis(series,axis); |
|
561 | d_ptr->m_dataset->attachAxis(series,axis); | |
553 | } |
|
562 | } | |
554 |
|
563 | |||
555 | /*! |
|
564 | /*! | |
556 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
565 | Sets \a axis to the chart, which will control the presentation of the \a series | |
557 |
|
566 | |||
558 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() |
|
567 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() | |
559 | */ |
|
568 | */ | |
560 | void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series) |
|
569 | void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series) | |
561 | { |
|
570 | { | |
562 | QList<QAbstractAxis*> list = axes(Qt::Vertical,series); |
|
571 | QList<QAbstractAxis*> list = axes(Qt::Vertical,series); | |
563 |
|
572 | |||
564 | foreach(QAbstractAxis* a, list) { |
|
573 | foreach(QAbstractAxis* a, list) { | |
565 | d_ptr->m_dataset->removeAxis(a); |
|
574 | d_ptr->m_dataset->removeAxis(a); | |
566 | delete a; |
|
575 | delete a; | |
567 | } |
|
576 | } | |
568 |
|
577 | |||
569 | if(!d_ptr->m_dataset->axes().contains(axis)) |
|
578 | if(!d_ptr->m_dataset->axes().contains(axis)) | |
570 | d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft); |
|
579 | d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft); | |
571 | d_ptr->m_dataset->attachAxis(series,axis); |
|
580 | d_ptr->m_dataset->attachAxis(series,axis); | |
572 | } |
|
581 | } | |
573 |
|
582 | |||
574 | void QChart::addAxis(QAbstractAxis *axis,Qt::Alignment aligment) |
|
583 | /*! | |
|
584 | Adds \a axis to the chart with \a alignment. The chart takes the ownership of the axis. | |||
|
585 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() | |||
|
586 | */ | |||
|
587 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) | |||
575 | { |
|
588 | { | |
576 | d_ptr->m_dataset->addAxis(axis,aligment); |
|
589 | d_ptr->m_dataset->addAxis(axis, alignment); | |
577 | } |
|
590 | } | |
578 |
|
591 | |||
|
592 | /*! | |||
|
593 | Removes \a axis from the chart. The ownership is returned to the caller. | |||
|
594 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() | |||
|
595 | */ | |||
579 | void QChart::removeAxis(QAbstractAxis *axis) |
|
596 | void QChart::removeAxis(QAbstractAxis *axis) | |
580 | { |
|
597 | { | |
581 | d_ptr->m_dataset->removeAxis(axis); |
|
598 | d_ptr->m_dataset->removeAxis(axis); | |
582 | } |
|
599 | } | |
583 |
|
600 | |||
584 | /*! |
|
601 | /*! | |
585 | Returns the value in the \a series domain that coresponds to the charts widget point defines by \a position. |
|
602 | Returns the value in the \a series domain that coresponds to the charts widget point defines by \a position. | |
586 | */ |
|
603 | */ | |
587 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
604 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) | |
588 | { |
|
605 | { | |
589 | return d_ptr->m_dataset->mapToValue(position, series); |
|
606 | return d_ptr->m_dataset->mapToValue(position, series); | |
590 | } |
|
607 | } | |
591 |
|
608 | |||
592 | /*! |
|
609 | /*! | |
593 | Returns the position on the charts widget that coresponds to the \a value in the \a series domain. |
|
610 | Returns the position on the charts widget that coresponds to the \a value in the \a series domain. | |
594 | */ |
|
611 | */ | |
595 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
612 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) | |
596 | { |
|
613 | { | |
597 | return d_ptr->m_dataset->mapToPosition(value, series); |
|
614 | return d_ptr->m_dataset->mapToPosition(value, series); | |
598 | } |
|
615 | } | |
599 |
|
616 | |||
600 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
617 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
601 |
|
618 | |||
602 | QChartPrivate::QChartPrivate(QChart *q): |
|
619 | QChartPrivate::QChartPrivate(QChart *q): | |
603 | q_ptr(q), |
|
620 | q_ptr(q), | |
604 | m_legend(0), |
|
621 | m_legend(0), | |
605 | m_dataset(new ChartDataSet(q)), |
|
622 | m_dataset(new ChartDataSet(q)), | |
606 | m_presenter(new ChartPresenter(q)), |
|
623 | m_presenter(new ChartPresenter(q)), | |
607 | m_themeManager(new ChartThemeManager(q)) |
|
624 | m_themeManager(new ChartThemeManager(q)) | |
608 | { |
|
625 | { | |
609 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
626 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
610 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
627 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
611 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
628 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); | |
612 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
629 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
613 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
630 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
614 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
631 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
615 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
632 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); | |
616 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
633 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
617 | } |
|
634 | } | |
618 |
|
635 | |||
619 | QChartPrivate::~QChartPrivate() |
|
636 | QChartPrivate::~QChartPrivate() | |
620 | { |
|
637 | { | |
621 |
|
638 | |||
622 | } |
|
639 | } | |
623 |
|
640 | |||
624 | void QChartPrivate::zoomIn(qreal factor) |
|
641 | void QChartPrivate::zoomIn(qreal factor) | |
625 | { |
|
642 | { | |
626 | QRectF rect = m_presenter->geometry(); |
|
643 | QRectF rect = m_presenter->geometry(); | |
627 | rect.setWidth(rect.width() / factor); |
|
644 | rect.setWidth(rect.width() / factor); | |
628 | rect.setHeight(rect.height() / factor); |
|
645 | rect.setHeight(rect.height() / factor); | |
629 | rect.moveCenter(m_presenter->geometry().center()); |
|
646 | rect.moveCenter(m_presenter->geometry().center()); | |
630 | zoomIn(rect); |
|
647 | zoomIn(rect); | |
631 | } |
|
648 | } | |
632 |
|
649 | |||
633 | void QChartPrivate::zoomIn(const QRectF &rect) |
|
650 | void QChartPrivate::zoomIn(const QRectF &rect) | |
634 | { |
|
651 | { | |
635 | if (!rect.isValid()) |
|
652 | if (!rect.isValid()) | |
636 | return; |
|
653 | return; | |
637 |
|
654 | |||
638 | QRectF r = rect.normalized(); |
|
655 | QRectF r = rect.normalized(); | |
639 | const QRectF geometry = m_presenter->geometry(); |
|
656 | const QRectF geometry = m_presenter->geometry(); | |
640 | r.translate(-geometry.topLeft()); |
|
657 | r.translate(-geometry.topLeft()); | |
641 |
|
658 | |||
642 | if (!r.isValid()) |
|
659 | if (!r.isValid()) | |
643 | return; |
|
660 | return; | |
644 |
|
661 | |||
645 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
662 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |
646 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); |
|
663 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); | |
647 | m_dataset->zoomInDomain(r); |
|
664 | m_dataset->zoomInDomain(r); | |
648 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
665 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
649 |
|
666 | |||
650 | } |
|
667 | } | |
651 |
|
668 | |||
652 | void QChartPrivate::zoomOut(qreal factor) |
|
669 | void QChartPrivate::zoomOut(qreal factor) | |
653 | { |
|
670 | { | |
654 | const QRectF geometry = m_presenter->geometry(); |
|
671 | const QRectF geometry = m_presenter->geometry(); | |
655 |
|
672 | |||
656 | QRectF r; |
|
673 | QRectF r; | |
657 | r.setSize(geometry.size() / factor); |
|
674 | r.setSize(geometry.size() / factor); | |
658 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); |
|
675 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); | |
659 | if (!r.isValid()) |
|
676 | if (!r.isValid()) | |
660 | return; |
|
677 | return; | |
661 |
|
678 | |||
662 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
679 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |
663 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); |
|
680 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); | |
664 | m_dataset->zoomOutDomain(r); |
|
681 | m_dataset->zoomOutDomain(r); | |
665 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
682 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
666 | } |
|
683 | } | |
667 |
|
684 | |||
668 | void QChartPrivate::scroll(qreal dx, qreal dy) |
|
685 | void QChartPrivate::scroll(qreal dx, qreal dy) | |
669 | { |
|
686 | { | |
670 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); |
|
687 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); | |
671 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); |
|
688 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); | |
672 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); |
|
689 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); | |
673 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); |
|
690 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); | |
674 |
|
691 | |||
675 | m_dataset->scrollDomain(dx, dy); |
|
692 | m_dataset->scrollDomain(dx, dy); | |
676 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
693 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
677 | } |
|
694 | } | |
678 |
|
695 | |||
679 | #include "moc_qchart.cpp" |
|
696 | #include "moc_qchart.cpp" | |
680 |
|
697 | |||
681 | QTCOMMERCIALCHART_END_NAMESPACE |
|
698 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,151 +1,150 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QCHART_H |
|
21 | #ifndef QCHART_H | |
22 | #define QCHART_H |
|
22 | #define QCHART_H | |
23 |
|
23 | |||
24 | #include <QAbstractSeries> |
|
24 | #include <QAbstractSeries> | |
25 | #include <QLegend> |
|
25 | #include <QLegend> | |
26 | #include <QGraphicsWidget> |
|
26 | #include <QGraphicsWidget> | |
27 | #include <QMargins> |
|
27 | #include <QMargins> | |
28 |
|
28 | |||
29 | class QGraphicsSceneResizeEvent; |
|
29 | class QGraphicsSceneResizeEvent; | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | class QAbstractSeries; |
|
33 | class QAbstractSeries; | |
34 | class QAbstractAxis; |
|
34 | class QAbstractAxis; | |
35 | class QLegend; |
|
35 | class QLegend; | |
36 | class QChartPrivate; |
|
36 | class QChartPrivate; | |
37 |
|
37 | |||
38 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
38 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme) |
|
41 | Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme) | |
42 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
42 | Q_PROPERTY(QString title READ title WRITE setTitle) | |
43 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible) |
|
43 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible) | |
44 | Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled) |
|
44 | Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled) | |
45 | Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions) |
|
45 | Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions) | |
46 | Q_PROPERTY(QMargins margins READ margins WRITE setMargins) |
|
46 | Q_PROPERTY(QMargins margins READ margins WRITE setMargins) | |
47 | Q_ENUMS(ChartTheme) |
|
47 | Q_ENUMS(ChartTheme) | |
48 | Q_ENUMS(AnimationOption) |
|
48 | Q_ENUMS(AnimationOption) | |
49 |
|
49 | |||
50 | public: |
|
50 | public: | |
51 | enum ChartTheme { |
|
51 | enum ChartTheme { | |
52 | ChartThemeLight = 0, |
|
52 | ChartThemeLight = 0, | |
53 | ChartThemeBlueCerulean, |
|
53 | ChartThemeBlueCerulean, | |
54 | ChartThemeDark, |
|
54 | ChartThemeDark, | |
55 | ChartThemeBrownSand, |
|
55 | ChartThemeBrownSand, | |
56 | ChartThemeBlueNcs, |
|
56 | ChartThemeBlueNcs, | |
57 | ChartThemeHighContrast, |
|
57 | ChartThemeHighContrast, | |
58 | ChartThemeBlueIcy |
|
58 | ChartThemeBlueIcy | |
59 | }; |
|
59 | }; | |
60 |
|
60 | |||
61 | enum AnimationOption { |
|
61 | enum AnimationOption { | |
62 | NoAnimation = 0x0, |
|
62 | NoAnimation = 0x0, | |
63 | GridAxisAnimations = 0x1, |
|
63 | GridAxisAnimations = 0x1, | |
64 | SeriesAnimations = 0x2, |
|
64 | SeriesAnimations = 0x2, | |
65 | AllAnimations = 0x3 |
|
65 | AllAnimations = 0x3 | |
66 | }; |
|
66 | }; | |
67 |
|
67 | |||
68 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
68 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) | |
69 |
|
69 | |||
70 | public: |
|
70 | public: | |
71 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
71 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
72 | ~QChart(); |
|
72 | ~QChart(); | |
73 |
|
73 | |||
74 | void addSeries(QAbstractSeries *series); |
|
74 | void addSeries(QAbstractSeries *series); | |
75 | void removeSeries(QAbstractSeries *series); |
|
75 | void removeSeries(QAbstractSeries *series); | |
76 | void removeAllSeries(); |
|
76 | void removeAllSeries(); | |
77 | QList<QAbstractSeries *> series() const; |
|
77 | QList<QAbstractSeries *> series() const; | |
78 |
|
78 | |||
79 | //depreciated shit//////////////////////////////////////////////////. |
|
79 | // *** deprecated *** | |
80 | void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
80 | void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); | |
81 | void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
81 | void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); | |
82 |
|
||||
83 | QAbstractAxis *axisX(QAbstractSeries *series = 0) const; |
|
82 | QAbstractAxis *axisX(QAbstractSeries *series = 0) const; | |
84 | QAbstractAxis *axisY(QAbstractSeries *series = 0) const; |
|
83 | QAbstractAxis *axisY(QAbstractSeries *series = 0) const; | |
85 | ///////////////////////////////////////////////////////////////////// |
|
84 | // ****************** | |
86 |
|
85 | |||
87 | void addAxis(QAbstractAxis *axis,Qt::Alignment aligment); |
|
86 | void addAxis(QAbstractAxis *axis,Qt::Alignment alignment); | |
88 | void removeAxis(QAbstractAxis *axis); |
|
87 | void removeAxis(QAbstractAxis *axis); | |
89 | QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = 0) const; |
|
88 | QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = 0) const; | |
90 |
|
89 | |||
91 | void createDefaultAxes(); |
|
90 | void createDefaultAxes(); | |
92 |
|
91 | |||
93 | void setTheme(QChart::ChartTheme theme); |
|
92 | void setTheme(QChart::ChartTheme theme); | |
94 | QChart::ChartTheme theme() const; |
|
93 | QChart::ChartTheme theme() const; | |
95 |
|
94 | |||
96 | void setTitle(const QString &title); |
|
95 | void setTitle(const QString &title); | |
97 | QString title() const; |
|
96 | QString title() const; | |
98 | void setTitleFont(const QFont &font); |
|
97 | void setTitleFont(const QFont &font); | |
99 | QFont titleFont() const; |
|
98 | QFont titleFont() const; | |
100 | void setTitleBrush(const QBrush &brush); |
|
99 | void setTitleBrush(const QBrush &brush); | |
101 | QBrush titleBrush() const; |
|
100 | QBrush titleBrush() const; | |
102 |
|
101 | |||
103 | void setBackgroundBrush(const QBrush &brush); |
|
102 | void setBackgroundBrush(const QBrush &brush); | |
104 | QBrush backgroundBrush() const; |
|
103 | QBrush backgroundBrush() const; | |
105 | void setBackgroundPen(const QPen &pen); |
|
104 | void setBackgroundPen(const QPen &pen); | |
106 | QPen backgroundPen() const; |
|
105 | QPen backgroundPen() const; | |
107 | void setBackgroundVisible(bool visible = true); |
|
106 | void setBackgroundVisible(bool visible = true); | |
108 | bool isBackgroundVisible() const; |
|
107 | bool isBackgroundVisible() const; | |
109 |
|
108 | |||
110 | void setDropShadowEnabled(bool enabled = true); |
|
109 | void setDropShadowEnabled(bool enabled = true); | |
111 | bool isDropShadowEnabled() const; |
|
110 | bool isDropShadowEnabled() const; | |
112 | void setAnimationOptions(AnimationOptions options); |
|
111 | void setAnimationOptions(AnimationOptions options); | |
113 | AnimationOptions animationOptions() const; |
|
112 | AnimationOptions animationOptions() const; | |
114 |
|
113 | |||
115 | void zoomIn(); |
|
114 | void zoomIn(); | |
116 | void zoomOut(); |
|
115 | void zoomOut(); | |
117 |
|
116 | |||
118 | void zoomIn(const QRectF &rect); |
|
117 | void zoomIn(const QRectF &rect); | |
119 | void zoom(qreal factor); |
|
118 | void zoom(qreal factor); | |
120 |
|
119 | |||
121 | void scroll(qreal dx, qreal dy); |
|
120 | void scroll(qreal dx, qreal dy); | |
122 |
|
121 | |||
123 | QLegend *legend() const; |
|
122 | QLegend *legend() const; | |
124 |
|
123 | |||
125 | void setMinimumMargins(const QMargins& margins); |
|
124 | void setMinimumMargins(const QMargins& margins); | |
126 | QMargins minimumMargins() const; |
|
125 | QMargins minimumMargins() const; | |
127 |
|
126 | |||
128 | void setMargins(const QMargins &margins); |
|
127 | void setMargins(const QMargins &margins); | |
129 | QMargins margins() const; |
|
128 | QMargins margins() const; | |
130 |
|
129 | |||
131 | QRectF plotArea() const; |
|
130 | QRectF plotArea() const; | |
132 |
|
131 | |||
133 | QPointF mapToValue(const QPointF &position, QAbstractSeries *series = 0); |
|
132 | QPointF mapToValue(const QPointF &position, QAbstractSeries *series = 0); | |
134 | QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = 0); |
|
133 | QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = 0); | |
135 |
|
134 | |||
136 | protected: |
|
135 | protected: | |
137 | QScopedPointer<QChartPrivate> d_ptr; |
|
136 | QScopedPointer<QChartPrivate> d_ptr; | |
138 | friend class QLegend; |
|
137 | friend class QLegend; | |
139 | friend class DeclarativeChart; |
|
138 | friend class DeclarativeChart; | |
140 | friend class ChartDataSet; |
|
139 | friend class ChartDataSet; | |
141 | friend class ChartPresenter; |
|
140 | friend class ChartPresenter; | |
142 | friend class ChartThemeManager; |
|
141 | friend class ChartThemeManager; | |
143 | friend class QAbstractSeries; |
|
142 | friend class QAbstractSeries; | |
144 | Q_DISABLE_COPY(QChart) |
|
143 | Q_DISABLE_COPY(QChart) | |
145 | }; |
|
144 | }; | |
146 |
|
145 | |||
147 | QTCOMMERCIALCHART_END_NAMESPACE |
|
146 | QTCOMMERCIALCHART_END_NAMESPACE | |
148 |
|
147 | |||
149 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
148 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) | |
150 |
|
149 | |||
151 | #endif // QCHART_H |
|
150 | #endif // QCHART_H |
General Comments 0
You need to be logged in to leave comments.
Login now