@@ -1,754 +1,754 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "legendscroller_p.h" |
|
23 | #include "legendscroller_p.h" | |
24 | #include "qlegend_p.h" |
|
24 | #include "qlegend_p.h" | |
25 | #include "chartbackground_p.h" |
|
25 | #include "chartbackground_p.h" | |
26 | #include "qabstractaxis.h" |
|
26 | #include "qabstractaxis.h" | |
27 | #include "abstractchartlayout_p.h" |
|
27 | #include "abstractchartlayout_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartpresenter_p.h" |
|
29 | #include "chartpresenter_p.h" | |
30 | #include "chartdataset_p.h" |
|
30 | #include "chartdataset_p.h" | |
31 | #include <QGraphicsScene> |
|
31 | #include <QGraphicsScene> | |
32 | #include <QGraphicsSceneResizeEvent> |
|
32 | #include <QGraphicsSceneResizeEvent> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \enum QChart::ChartTheme |
|
37 | \enum QChart::ChartTheme | |
38 |
|
38 | |||
39 | This enum describes the theme used by the chart. |
|
39 | This enum describes the theme used by the chart. | |
40 |
|
40 | |||
41 | \value ChartThemeLight The default theme |
|
41 | \value ChartThemeLight The default theme | |
42 | \value ChartThemeBlueCerulean |
|
42 | \value ChartThemeBlueCerulean | |
43 | \value ChartThemeDark |
|
43 | \value ChartThemeDark | |
44 | \value ChartThemeBrownSand |
|
44 | \value ChartThemeBrownSand | |
45 | \value ChartThemeBlueNcs |
|
45 | \value ChartThemeBlueNcs | |
46 | \value ChartThemeHighContrast |
|
46 | \value ChartThemeHighContrast | |
47 | \value ChartThemeBlueIcy |
|
47 | \value ChartThemeBlueIcy | |
48 | */ |
|
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 | \enum QChart::ChartType |
|
62 | \enum QChart::ChartType | |
63 |
|
63 | |||
64 | This enum describes the chart type. |
|
64 | This enum describes the chart type. | |
65 |
|
65 | |||
66 | \value ChartTypeUndefined |
|
66 | \value ChartTypeUndefined | |
67 | \value ChartTypeCartesian |
|
67 | \value ChartTypeCartesian | |
68 | \value ChartTypePolar |
|
68 | \value ChartTypePolar | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \class QChart |
|
72 | \class QChart | |
73 | \brief QtCommercial chart API. |
|
73 | \brief QtCommercial chart API. | |
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::minimumMargins |
|
100 | \property QChart::minimumMargins | |
101 | Minimum margins between the plot area (axes) and the edge of the chart widget. |
|
101 | Minimum margins between the plot area (axes) and the edge of the chart widget. | |
102 | This property is deprecated; use margins property instead. |
|
102 | This property is deprecated; use margins property instead. | |
103 |
|
103 | |||
104 | \sa margins |
|
104 | \sa margins | |
105 | */ |
|
105 | */ | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \property QChart::margins |
|
108 | \property QChart::margins | |
109 | Margins between the plot area (axes) and the edge of the chart widget. |
|
109 | Margins between the plot area (axes) and the edge of the chart widget. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | \property QChart::theme |
|
113 | \property QChart::theme | |
114 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
114 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, | |
115 | pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes demo} shows an example with a few |
|
115 | pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes demo} shows an example with a few | |
116 | different themes. |
|
116 | different themes. | |
117 | \note Changing the theme will overwrite all customizations previously applied to the series. |
|
117 | \note Changing the theme will overwrite all customizations previously applied to the series. | |
118 | */ |
|
118 | */ | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | \property QChart::title |
|
121 | \property QChart::title | |
122 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. |
|
122 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. | |
123 | */ |
|
123 | */ | |
124 |
|
124 | |||
125 | /*! |
|
125 | /*! | |
126 | \property QChart::chartType |
|
126 | \property QChart::chartType | |
127 | Chart type indicates if the chart is a cartesian chart or a polar chart. |
|
127 | Chart type indicates if the chart is a cartesian chart or a polar chart. | |
128 | This property is set internally and it is read only. |
|
128 | This property is set internally and it is read only. | |
129 | \sa QPolarChart |
|
129 | \sa QPolarChart | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \property QChart::plotAreaBackgroundVisible |
|
133 | \property QChart::plotAreaBackgroundVisible | |
134 | Specifies whether the chart plot area background is visible or not. |
|
134 | Specifies whether the chart plot area background is visible or not. | |
135 | \note By default the plot area background is not visible and the plot area uses |
|
135 | \note By default the plot area background is not visible and the plot area uses | |
136 | the general chart background. |
|
136 | the general chart background. | |
137 | \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible |
|
137 | \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible | |
138 | */ |
|
138 | */ | |
139 |
|
139 | |||
140 | /*! |
|
140 | /*! | |
141 | \internal |
|
141 | \internal | |
142 | Constructs a chart object of \a type which is a child of a \a parent. |
|
142 | Constructs a chart object of \a type which is a child of a \a parent. | |
143 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
143 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
144 | This constructor is called only by subclasses. |
|
144 | This constructor is called only by subclasses. | |
145 | */ |
|
145 | */ | |
146 | QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
146 | QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
147 | : QGraphicsWidget(parent, wFlags), |
|
147 | : QGraphicsWidget(parent, wFlags), | |
148 | d_ptr(new QChartPrivate(this, type)) |
|
148 | d_ptr(new QChartPrivate(this, type)) | |
149 | { |
|
149 | { | |
150 | d_ptr->init(); |
|
150 | d_ptr->init(); | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | /*! |
|
153 | /*! | |
154 | Constructs a chart object which is a child of a \a parent. |
|
154 | Constructs a chart object which is a child of a \a parent. | |
155 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
155 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
156 | */ |
|
156 | */ | |
157 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
157 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
158 | : QGraphicsWidget(parent, wFlags), |
|
158 | : QGraphicsWidget(parent, wFlags), | |
159 | d_ptr(new QChartPrivate(this, ChartTypeCartesian)) |
|
159 | d_ptr(new QChartPrivate(this, ChartTypeCartesian)) | |
160 | { |
|
160 | { | |
161 | d_ptr->init(); |
|
161 | d_ptr->init(); | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | /*! |
|
164 | /*! | |
165 | Destroys the chart object and its children, like series and axis objects added to it. |
|
165 | Destroys the chart object and its children, like series and axis objects added to it. | |
166 | */ |
|
166 | */ | |
167 | QChart::~QChart() |
|
167 | QChart::~QChart() | |
168 | { |
|
168 | { | |
169 | //start by deleting dataset, it will remove all series and axes |
|
169 | //start by deleting dataset, it will remove all series and axes | |
170 | delete d_ptr->m_dataset; |
|
170 | delete d_ptr->m_dataset; | |
171 | d_ptr->m_dataset = 0; |
|
171 | d_ptr->m_dataset = 0; | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | /*! |
|
174 | /*! | |
175 | Adds the \a series onto the chart and takes the ownership of it. |
|
175 | Adds the \a series onto the chart and takes the ownership of it. | |
176 |
|
176 | |||
177 | \note A newly added series is attached to no axes by default, including any axes that were created for the chart |
|
177 | \note A newly added series is attached to no axes by default, including any axes that were created for the chart | |
178 | using createDefaultAxes() before the series was added to the chart. If no axes are attached to |
|
178 | using createDefaultAxes() before the series was added to the chart. If no axes are attached to | |
179 | the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges |
|
179 | the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges | |
180 | that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other |
|
180 | that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other | |
181 | series that have properly attached axes, so always make sure you either call createDefaultAxes() after |
|
181 | series that have properly attached axes, so always make sure you either call createDefaultAxes() after | |
182 | a series has been added or explicitly attach axes for the series. |
|
182 | a series has been added or explicitly attach axes for the series. | |
183 |
|
183 | |||
184 | \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
184 | \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
185 | */ |
|
185 | */ | |
186 | void QChart::addSeries(QAbstractSeries *series) |
|
186 | void QChart::addSeries(QAbstractSeries *series) | |
187 | { |
|
187 | { | |
188 | Q_ASSERT(series); |
|
188 | Q_ASSERT(series); | |
189 | d_ptr->m_dataset->addSeries(series); |
|
189 | d_ptr->m_dataset->addSeries(series); | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | /*! |
|
192 | /*! | |
193 | Removes the \a series from the chart. |
|
193 | Removes the \a series from the chart. | |
194 | The chart releases its ownership of the specified \a series object. |
|
194 | The chart releases its ownership of the specified \a series object. | |
195 |
|
195 | |||
196 | \sa addSeries(), removeAllSeries() |
|
196 | \sa addSeries(), removeAllSeries() | |
197 | */ |
|
197 | */ | |
198 | void QChart::removeSeries(QAbstractSeries *series) |
|
198 | void QChart::removeSeries(QAbstractSeries *series) | |
199 | { |
|
199 | { | |
200 | Q_ASSERT(series); |
|
200 | Q_ASSERT(series); | |
201 | d_ptr->m_dataset->removeSeries(series); |
|
201 | d_ptr->m_dataset->removeSeries(series); | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | /*! |
|
204 | /*! | |
205 | Removes and deletes all series objects that have been added to the chart. |
|
205 | Removes and deletes all series objects that have been added to the chart. | |
206 |
|
206 | |||
207 | \sa addSeries(), removeSeries() |
|
207 | \sa addSeries(), removeSeries() | |
208 | */ |
|
208 | */ | |
209 | void QChart::removeAllSeries() |
|
209 | void QChart::removeAllSeries() | |
210 | { |
|
210 | { | |
211 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ |
|
211 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ | |
212 | removeSeries(s); |
|
212 | removeSeries(s); | |
213 | delete s; |
|
213 | delete s; | |
214 | } |
|
214 | } | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | /*! |
|
217 | /*! | |
218 | Sets the \a brush that is used for painting the background of the chart area. |
|
218 | Sets the \a brush that is used for painting the background of the chart area. | |
219 | */ |
|
219 | */ | |
220 | void QChart::setBackgroundBrush(const QBrush &brush) |
|
220 | void QChart::setBackgroundBrush(const QBrush &brush) | |
221 | { |
|
221 | { | |
222 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
222 | d_ptr->m_presenter->setBackgroundBrush(brush); | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | /*! |
|
225 | /*! | |
226 | Gets the brush that is used for painting the background of the chart area. |
|
226 | Gets the brush that is used for painting the background of the chart area. | |
227 | */ |
|
227 | */ | |
228 | QBrush QChart::backgroundBrush() const |
|
228 | QBrush QChart::backgroundBrush() const | |
229 | { |
|
229 | { | |
230 | return d_ptr->m_presenter->backgroundBrush(); |
|
230 | return d_ptr->m_presenter->backgroundBrush(); | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | /*! |
|
233 | /*! | |
234 | Sets the \a pen that is used for painting the background of the chart area. |
|
234 | Sets the \a pen that is used for painting the background of the chart area. | |
235 | */ |
|
235 | */ | |
236 | void QChart::setBackgroundPen(const QPen &pen) |
|
236 | void QChart::setBackgroundPen(const QPen &pen) | |
237 | { |
|
237 | { | |
238 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
238 | d_ptr->m_presenter->setBackgroundPen(pen); | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | /*! |
|
241 | /*! | |
242 | Gets the pen that is used for painting the background of the chart area. |
|
242 | Gets the pen that is used for painting the background of the chart area. | |
243 | */ |
|
243 | */ | |
244 | QPen QChart::backgroundPen() const |
|
244 | QPen QChart::backgroundPen() const | |
245 | { |
|
245 | { | |
246 | return d_ptr->m_presenter->backgroundPen(); |
|
246 | return d_ptr->m_presenter->backgroundPen(); | |
247 | } |
|
247 | } | |
248 |
|
248 | |||
249 | void QChart::setTitle(const QString &title) |
|
249 | void QChart::setTitle(const QString &title) | |
250 | { |
|
250 | { | |
251 | d_ptr->m_presenter->setTitle(title); |
|
251 | d_ptr->m_presenter->setTitle(title); | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | QString QChart::title() const |
|
254 | QString QChart::title() const | |
255 | { |
|
255 | { | |
256 | return d_ptr->m_presenter->title(); |
|
256 | return d_ptr->m_presenter->title(); | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | /*! |
|
259 | /*! | |
260 | Sets the \a font that is used for drawing the chart title. |
|
260 | Sets the \a font that is used for drawing the chart title. | |
261 | */ |
|
261 | */ | |
262 | void QChart::setTitleFont(const QFont &font) |
|
262 | void QChart::setTitleFont(const QFont &font) | |
263 | { |
|
263 | { | |
264 | d_ptr->m_presenter->setTitleFont(font); |
|
264 | d_ptr->m_presenter->setTitleFont(font); | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | /*! |
|
267 | /*! | |
268 | Gets the font that is used for drawing the chart title. |
|
268 | Gets the font that is used for drawing the chart title. | |
269 | */ |
|
269 | */ | |
270 | QFont QChart::titleFont() const |
|
270 | QFont QChart::titleFont() const | |
271 | { |
|
271 | { | |
272 | return d_ptr->m_presenter->titleFont(); |
|
272 | return d_ptr->m_presenter->titleFont(); | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | /*! |
|
275 | /*! | |
276 | Sets the \a brush used for drawing the title text. |
|
276 | Sets the \a brush used for drawing the title text. | |
277 | */ |
|
277 | */ | |
278 | void QChart::setTitleBrush(const QBrush &brush) |
|
278 | void QChart::setTitleBrush(const QBrush &brush) | |
279 | { |
|
279 | { | |
280 | d_ptr->m_presenter->setTitleBrush(brush); |
|
280 | d_ptr->m_presenter->setTitleBrush(brush); | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | /*! |
|
283 | /*! | |
284 | Returns the brush used for drawing the title text. |
|
284 | Returns the brush used for drawing the title text. | |
285 | */ |
|
285 | */ | |
286 | QBrush QChart::titleBrush() const |
|
286 | QBrush QChart::titleBrush() const | |
287 | { |
|
287 | { | |
288 | return d_ptr->m_presenter->titleBrush(); |
|
288 | return d_ptr->m_presenter->titleBrush(); | |
289 | } |
|
289 | } | |
290 |
|
290 | |||
291 | void QChart::setTheme(QChart::ChartTheme theme) |
|
291 | void QChart::setTheme(QChart::ChartTheme theme) | |
292 | { |
|
292 | { | |
293 | d_ptr->m_themeManager->setTheme(theme); |
|
293 | d_ptr->m_themeManager->setTheme(theme); | |
294 | } |
|
294 | } | |
295 |
|
295 | |||
296 | QChart::ChartTheme QChart::theme() const |
|
296 | QChart::ChartTheme QChart::theme() const | |
297 | { |
|
297 | { | |
298 | return d_ptr->m_themeManager->theme()->id(); |
|
298 | return d_ptr->m_themeManager->theme()->id(); | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | /*! |
|
301 | /*! | |
302 | Zooms in the view by a factor of two. |
|
302 | Zooms in the view by a factor of two. | |
303 | */ |
|
303 | */ | |
304 | void QChart::zoomIn() |
|
304 | void QChart::zoomIn() | |
305 | { |
|
305 | { | |
306 | d_ptr->zoomIn(2.0); |
|
306 | d_ptr->zoomIn(2.0); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | /*! |
|
309 | /*! | |
310 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
310 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
311 | \note This is not supported for polar charts. |
|
311 | \note This is not supported for polar charts. | |
312 | */ |
|
312 | */ | |
313 | void QChart::zoomIn(const QRectF &rect) |
|
313 | void QChart::zoomIn(const QRectF &rect) | |
314 | { |
|
314 | { | |
315 | if (d_ptr->m_type == QChart::ChartTypePolar) |
|
315 | if (d_ptr->m_type == QChart::ChartTypePolar) | |
316 | return; |
|
316 | return; | |
317 | d_ptr->zoomIn(rect); |
|
317 | d_ptr->zoomIn(rect); | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | /*! |
|
320 | /*! | |
321 | Zooms out the view by a factor of two. |
|
321 | Zooms out the view by a factor of two. | |
322 | */ |
|
322 | */ | |
323 | void QChart::zoomOut() |
|
323 | void QChart::zoomOut() | |
324 | { |
|
324 | { | |
325 | d_ptr->zoomOut(2.0); |
|
325 | d_ptr->zoomOut(2.0); | |
326 | } |
|
326 | } | |
327 |
|
327 | |||
328 | /*! |
|
328 | /*! | |
329 | Zooms in the view by a custom \a factor. |
|
329 | Zooms in the view by a custom \a factor. | |
330 |
|
330 | |||
331 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
331 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. | |
332 | */ |
|
332 | */ | |
333 | void QChart::zoom(qreal factor) |
|
333 | void QChart::zoom(qreal factor) | |
334 | { |
|
334 | { | |
335 | if (qFuzzyCompare(factor, 0)) |
|
335 | if (qFuzzyCompare(factor, 0)) | |
336 | return; |
|
336 | return; | |
337 |
|
337 | |||
338 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
338 | if (qFuzzyCompare(factor, (qreal)1.0)) | |
339 | return; |
|
339 | return; | |
340 |
|
340 | |||
341 | if (factor < 0) |
|
341 | if (factor < 0) | |
342 | return; |
|
342 | return; | |
343 |
|
343 | |||
344 | if (factor > 1.0) |
|
344 | if (factor > 1.0) | |
345 | d_ptr->zoomIn(factor); |
|
345 | d_ptr->zoomIn(factor); | |
346 | else |
|
346 | else | |
347 | d_ptr->zoomOut(1.0 / factor); |
|
347 | d_ptr->zoomOut(1.0 / factor); | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | /*! |
|
350 | /*! | |
351 | Returns a pointer to the horizontal axis attached to the specified \a series. |
|
351 | Returns a pointer to the horizontal axis attached to the specified \a series. | |
352 | If no \a series is specified, the first horizontal axis added to the chart is returned. |
|
352 | If no \a series is specified, the first horizontal axis added to the chart is returned. | |
353 |
|
353 | |||
354 | \sa addAxis(), QAbstractSeries::attachAxis() |
|
354 | \sa addAxis(), QAbstractSeries::attachAxis() | |
355 | */ |
|
355 | */ | |
356 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const |
|
356 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const | |
357 | { |
|
357 | { | |
358 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); |
|
358 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); | |
359 | if (axisList.count()) |
|
359 | if (axisList.count()) | |
360 | return axisList[0]; |
|
360 | return axisList[0]; | |
361 | return 0; |
|
361 | return 0; | |
362 | } |
|
362 | } | |
363 |
|
363 | |||
364 | /*! |
|
364 | /*! | |
365 | Returns a pointer to the vertical axis attached to the specified \a series. |
|
365 | Returns a pointer to the vertical axis attached to the specified \a series. | |
366 | If no \a series is specified, the first vertical axis added to the chart is returned. |
|
366 | If no \a series is specified, the first vertical axis added to the chart is returned. | |
367 |
|
367 | |||
368 | \sa addAxis(), QAbstractSeries::attachAxis() |
|
368 | \sa addAxis(), QAbstractSeries::attachAxis() | |
369 | */ |
|
369 | */ | |
370 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const |
|
370 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const | |
371 | { |
|
371 | { | |
372 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); |
|
372 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); | |
373 | if (axisList.count()) |
|
373 | if (axisList.count()) | |
374 | return axisList[0]; |
|
374 | return axisList[0]; | |
375 | return 0; |
|
375 | return 0; | |
376 | } |
|
376 | } | |
377 |
|
377 | |||
378 | /*! |
|
378 | /*! | |
379 | Returns the axes attached to the \a series with \a orientation. If no \a series is provided, |
|
379 | Returns the axes attached to the \a series with \a orientation. If no \a series is provided, | |
380 | then all axes added to the chart with the specified orientation are returned. |
|
380 | then all axes added to the chart with the specified orientation are returned. | |
381 | \sa addAxis(), createDefaultAxes() |
|
381 | \sa addAxis(), createDefaultAxes() | |
382 | */ |
|
382 | */ | |
383 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const |
|
383 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const | |
384 | { |
|
384 | { | |
385 | QList<QAbstractAxis *> result ; |
|
385 | QList<QAbstractAxis *> result ; | |
386 |
|
386 | |||
387 | if (series) { |
|
387 | if (series) { | |
388 | foreach (QAbstractAxis *axis, series->attachedAxes()){ |
|
388 | foreach (QAbstractAxis *axis, series->attachedAxes()){ | |
389 | if (orientation.testFlag(axis->orientation())) |
|
389 | if (orientation.testFlag(axis->orientation())) | |
390 | result << axis; |
|
390 | result << axis; | |
391 | } |
|
391 | } | |
392 | } else { |
|
392 | } else { | |
393 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ |
|
393 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ | |
394 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) |
|
394 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) | |
395 | result << axis; |
|
395 | result << axis; | |
396 | } |
|
396 | } | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | return result; |
|
399 | return result; | |
400 | } |
|
400 | } | |
401 |
|
401 | |||
402 | /*! |
|
402 | /*! | |
403 | Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to |
|
403 | Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to | |
404 | the chart will be deleted. |
|
404 | the chart will be deleted. | |
405 |
|
405 | |||
406 | \note This function has to be called after all series have been added to the chart. The axes created by this function |
|
406 | \note This function has to be called after all series have been added to the chart. The axes created by this function | |
407 | will NOT get automatically attached to any series added to the chart after this function has been called. |
|
407 | will NOT get automatically attached to any series added to the chart after this function has been called. | |
408 | A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing |
|
408 | A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing | |
409 | if there are other series with properly attached axes also present. |
|
409 | if there are other series with properly attached axes also present. | |
410 |
|
410 | |||
411 | \table |
|
411 | \table | |
412 | \header |
|
412 | \header | |
413 | \o Series type |
|
413 | \o Series type | |
414 | \o X-axis |
|
414 | \o X-axis | |
415 | \o Y-axis |
|
415 | \o Y-axis | |
416 | \row |
|
416 | \row | |
417 | \o QXYSeries |
|
417 | \o QXYSeries | |
418 | \o QValueAxis |
|
418 | \o QValueAxis | |
419 | \o QValueAxis |
|
419 | \o QValueAxis | |
420 | \row |
|
420 | \row | |
421 | \o QBarSeries |
|
421 | \o QBarSeries | |
422 | \o QBarCategoryAxis |
|
422 | \o QBarCategoryAxis | |
423 | \o QValueAxis |
|
423 | \o QValueAxis | |
424 | \row |
|
424 | \row | |
425 | \o QPieSeries |
|
425 | \o QPieSeries | |
426 | \o None |
|
426 | \o None | |
427 | \o None |
|
427 | \o None | |
428 | \endtable |
|
428 | \endtable | |
429 |
|
429 | |||
430 | 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. |
|
430 | 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. | |
431 | If there are several series of different types added to the chart, then each series gets its own axes pair. |
|
431 | If there are several series of different types added to the chart, then each series gets its own axes pair. | |
432 |
|
432 | |||
433 | The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call. |
|
433 | The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call. | |
434 | QPieSeries does not create any axes. |
|
434 | QPieSeries does not create any axes. | |
435 |
|
435 | |||
436 | \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis() |
|
436 | \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis() | |
437 | */ |
|
437 | */ | |
438 | void QChart::createDefaultAxes() |
|
438 | void QChart::createDefaultAxes() | |
439 | { |
|
439 | { | |
440 | d_ptr->m_dataset->createDefaultAxes(); |
|
440 | d_ptr->m_dataset->createDefaultAxes(); | |
441 | } |
|
441 | } | |
442 |
|
442 | |||
443 | /*! |
|
443 | /*! | |
444 | Returns the legend object of the chart. Ownership stays with the chart. |
|
444 | Returns the legend object of the chart. Ownership stays with the chart. | |
445 | */ |
|
445 | */ | |
446 | QLegend *QChart::legend() const |
|
446 | QLegend *QChart::legend() const | |
447 | { |
|
447 | { | |
448 | return d_ptr->m_legend; |
|
448 | return d_ptr->m_legend; | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | void QChart::setMinimumMargins(const QMargins &margins) |
|
451 | void QChart::setMinimumMargins(const QMargins &margins) | |
452 | { |
|
452 | { | |
453 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; |
|
453 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; | |
454 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
454 | d_ptr->m_presenter->layout()->setMargins(margins); | |
455 | } |
|
455 | } | |
456 |
|
456 | |||
457 | QMargins QChart::minimumMargins() const |
|
457 | QMargins QChart::minimumMargins() const | |
458 | { |
|
458 | { | |
459 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; |
|
459 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; | |
460 | return d_ptr->m_presenter->layout()->margins(); |
|
460 | return d_ptr->m_presenter->layout()->margins(); | |
461 | } |
|
461 | } | |
462 |
|
462 | |||
463 | void QChart::setMargins(const QMargins &margins) |
|
463 | void QChart::setMargins(const QMargins &margins) | |
464 | { |
|
464 | { | |
465 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
465 | d_ptr->m_presenter->layout()->setMargins(margins); | |
466 | } |
|
466 | } | |
467 |
|
467 | |||
468 | QMargins QChart::margins() const |
|
468 | QMargins QChart::margins() const | |
469 | { |
|
469 | { | |
470 | return d_ptr->m_presenter->layout()->margins(); |
|
470 | return d_ptr->m_presenter->layout()->margins(); | |
471 | } |
|
471 | } | |
472 |
|
472 | |||
473 | QChart::ChartType QChart::chartType() const |
|
473 | QChart::ChartType QChart::chartType() const | |
474 | { |
|
474 | { | |
475 | return d_ptr->m_type; |
|
475 | return d_ptr->m_type; | |
476 | } |
|
476 | } | |
477 |
|
477 | |||
478 | /*! |
|
478 | /*! | |
479 | Returns the the rectangle within which the drawing of the chart is done. |
|
479 | Returns the the rectangle within which the drawing of the chart is done. | |
480 | It does not include the area defined by margins. |
|
480 | It does not include the area defined by margins. | |
481 | */ |
|
481 | */ | |
482 | QRectF QChart::plotArea() const |
|
482 | QRectF QChart::plotArea() const | |
483 | { |
|
483 | { | |
484 | return d_ptr->m_presenter->geometry(); |
|
484 | return d_ptr->m_presenter->geometry(); | |
485 | } |
|
485 | } | |
486 |
|
486 | |||
487 | /*! |
|
487 | /*! | |
488 | Sets the \a brush for the background of the plot area of the chart. |
|
488 | Sets the \a brush for the background of the plot area of the chart. | |
489 |
|
489 | |||
490 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush() |
|
490 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush() | |
491 | */ |
|
491 | */ | |
492 | void QChart::setPlotAreaBackgroundBrush(const QBrush &brush) |
|
492 | void QChart::setPlotAreaBackgroundBrush(const QBrush &brush) | |
493 | { |
|
493 | { | |
494 | d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush); |
|
494 | d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush); | |
495 | } |
|
495 | } | |
496 |
|
496 | |||
497 | /*! |
|
497 | /*! | |
498 | Returns the brush for the background of the plot area of the chart. |
|
498 | Returns the brush for the background of the plot area of the chart. | |
499 |
|
499 | |||
500 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush() |
|
500 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush() | |
501 | */ |
|
501 | */ | |
502 | QBrush QChart::plotAreaBackgroundBrush() const |
|
502 | QBrush QChart::plotAreaBackgroundBrush() const | |
503 | { |
|
503 | { | |
504 | return d_ptr->m_presenter->plotAreaBackgroundBrush(); |
|
504 | return d_ptr->m_presenter->plotAreaBackgroundBrush(); | |
505 | } |
|
505 | } | |
506 |
|
506 | |||
507 | /*! |
|
507 | /*! | |
508 | Sets the \a pen for the background of the plot area of the chart. |
|
508 | Sets the \a pen for the background of the plot area of the chart. | |
509 |
|
509 | |||
510 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen() |
|
510 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen() | |
511 | */ |
|
511 | */ | |
512 | void QChart::setPlotAreaBackgroundPen(const QPen &pen) |
|
512 | void QChart::setPlotAreaBackgroundPen(const QPen &pen) | |
513 | { |
|
513 | { | |
514 | d_ptr->m_presenter->setPlotAreaBackgroundPen(pen); |
|
514 | d_ptr->m_presenter->setPlotAreaBackgroundPen(pen); | |
515 | } |
|
515 | } | |
516 |
|
516 | |||
517 | /*! |
|
517 | /*! | |
518 |
Returns the |
|
518 | Returns the pen for the background of the plot area of the chart. | |
519 |
|
519 | |||
520 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen() |
|
520 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen() | |
521 | */ |
|
521 | */ | |
522 | QPen QChart::plotAreaBackgroundPen() const |
|
522 | QPen QChart::plotAreaBackgroundPen() const | |
523 | { |
|
523 | { | |
524 | return d_ptr->m_presenter->plotAreaBackgroundPen(); |
|
524 | return d_ptr->m_presenter->plotAreaBackgroundPen(); | |
525 | } |
|
525 | } | |
526 |
|
526 | |||
527 | void QChart::setPlotAreaBackgroundVisible(bool visible) |
|
527 | void QChart::setPlotAreaBackgroundVisible(bool visible) | |
528 | { |
|
528 | { | |
529 | d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible); |
|
529 | d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible); | |
530 | } |
|
530 | } | |
531 |
|
531 | |||
532 | bool QChart::isPlotAreaBackgroundVisible() const |
|
532 | bool QChart::isPlotAreaBackgroundVisible() const | |
533 | { |
|
533 | { | |
534 | return d_ptr->m_presenter->isPlotAreaBackgroundVisible(); |
|
534 | return d_ptr->m_presenter->isPlotAreaBackgroundVisible(); | |
535 | } |
|
535 | } | |
536 |
|
536 | |||
537 | void QChart::setAnimationOptions(AnimationOptions options) |
|
537 | void QChart::setAnimationOptions(AnimationOptions options) | |
538 | { |
|
538 | { | |
539 | d_ptr->m_presenter->setAnimationOptions(options); |
|
539 | d_ptr->m_presenter->setAnimationOptions(options); | |
540 | } |
|
540 | } | |
541 |
|
541 | |||
542 | QChart::AnimationOptions QChart::animationOptions() const |
|
542 | QChart::AnimationOptions QChart::animationOptions() const | |
543 | { |
|
543 | { | |
544 | return d_ptr->m_presenter->animationOptions(); |
|
544 | return d_ptr->m_presenter->animationOptions(); | |
545 | } |
|
545 | } | |
546 |
|
546 | |||
547 | /*! |
|
547 | /*! | |
548 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
548 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. | |
549 |
|
549 | |||
550 | For polar charts, \a dx indicates the angle along angular axis instead of distance. |
|
550 | For polar charts, \a dx indicates the angle along angular axis instead of distance. | |
551 | */ |
|
551 | */ | |
552 | void QChart::scroll(qreal dx, qreal dy) |
|
552 | void QChart::scroll(qreal dx, qreal dy) | |
553 | { |
|
553 | { | |
554 | d_ptr->scroll(dx,dy); |
|
554 | d_ptr->scroll(dx,dy); | |
555 | } |
|
555 | } | |
556 |
|
556 | |||
557 | void QChart::setBackgroundVisible(bool visible) |
|
557 | void QChart::setBackgroundVisible(bool visible) | |
558 | { |
|
558 | { | |
559 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
559 | d_ptr->m_presenter->setBackgroundVisible(visible); | |
560 | } |
|
560 | } | |
561 |
|
561 | |||
562 | bool QChart::isBackgroundVisible() const |
|
562 | bool QChart::isBackgroundVisible() const | |
563 | { |
|
563 | { | |
564 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
564 | return d_ptr->m_presenter->isBackgroundVisible(); | |
565 | } |
|
565 | } | |
566 |
|
566 | |||
567 | void QChart::setDropShadowEnabled(bool enabled) |
|
567 | void QChart::setDropShadowEnabled(bool enabled) | |
568 | { |
|
568 | { | |
569 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
569 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); | |
570 | } |
|
570 | } | |
571 |
|
571 | |||
572 | bool QChart::isDropShadowEnabled() const |
|
572 | bool QChart::isDropShadowEnabled() const | |
573 | { |
|
573 | { | |
574 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
574 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); | |
575 | } |
|
575 | } | |
576 |
|
576 | |||
577 | /*! |
|
577 | /*! | |
578 | Returns all series that are added to the chart. |
|
578 | Returns all series that are added to the chart. | |
579 |
|
579 | |||
580 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
580 | \sa addSeries(), removeSeries(), removeAllSeries() | |
581 | */ |
|
581 | */ | |
582 | QList<QAbstractSeries *> QChart::series() const |
|
582 | QList<QAbstractSeries *> QChart::series() const | |
583 | { |
|
583 | { | |
584 | return d_ptr->m_dataset->series(); |
|
584 | return d_ptr->m_dataset->series(); | |
585 | } |
|
585 | } | |
586 |
|
586 | |||
587 | /*! |
|
587 | /*! | |
588 | Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis. |
|
588 | Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis. | |
589 | The chart takes ownership of both the \a axis and the \a series. |
|
589 | The chart takes ownership of both the \a axis and the \a series. | |
590 | Any horizontal axes previously attached to the \a series are deleted. |
|
590 | Any horizontal axes previously attached to the \a series are deleted. | |
591 |
|
591 | |||
592 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
592 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
593 | */ |
|
593 | */ | |
594 | void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series) |
|
594 | void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series) | |
595 | { |
|
595 | { | |
596 | QList<QAbstractAxis*> list = axes(Qt::Horizontal, series); |
|
596 | QList<QAbstractAxis*> list = axes(Qt::Horizontal, series); | |
597 |
|
597 | |||
598 | foreach (QAbstractAxis* a, list) { |
|
598 | foreach (QAbstractAxis* a, list) { | |
599 | d_ptr->m_dataset->removeAxis(a); |
|
599 | d_ptr->m_dataset->removeAxis(a); | |
600 | delete a; |
|
600 | delete a; | |
601 | } |
|
601 | } | |
602 |
|
602 | |||
603 | if (!d_ptr->m_dataset->axes().contains(axis)) |
|
603 | if (!d_ptr->m_dataset->axes().contains(axis)) | |
604 | d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom); |
|
604 | d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom); | |
605 | d_ptr->m_dataset->attachAxis(series, axis); |
|
605 | d_ptr->m_dataset->attachAxis(series, axis); | |
606 | } |
|
606 | } | |
607 |
|
607 | |||
608 | /*! |
|
608 | /*! | |
609 | Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis. |
|
609 | Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis. | |
610 | The chart takes ownership of both the \a axis and the \a series. |
|
610 | The chart takes ownership of both the \a axis and the \a series. | |
611 | Any vertical axes previously attached to the \a series are deleted. |
|
611 | Any vertical axes previously attached to the \a series are deleted. | |
612 |
|
612 | |||
613 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
613 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
614 | */ |
|
614 | */ | |
615 | void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series) |
|
615 | void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series) | |
616 | { |
|
616 | { | |
617 | QList<QAbstractAxis*> list = axes(Qt::Vertical, series); |
|
617 | QList<QAbstractAxis*> list = axes(Qt::Vertical, series); | |
618 |
|
618 | |||
619 | foreach (QAbstractAxis* a, list) { |
|
619 | foreach (QAbstractAxis* a, list) { | |
620 | d_ptr->m_dataset->removeAxis(a); |
|
620 | d_ptr->m_dataset->removeAxis(a); | |
621 | delete a; |
|
621 | delete a; | |
622 | } |
|
622 | } | |
623 |
|
623 | |||
624 | if (!d_ptr->m_dataset->axes().contains(axis)) |
|
624 | if (!d_ptr->m_dataset->axes().contains(axis)) | |
625 | d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft); |
|
625 | d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft); | |
626 | d_ptr->m_dataset->attachAxis(series, axis); |
|
626 | d_ptr->m_dataset->attachAxis(series, axis); | |
627 | } |
|
627 | } | |
628 |
|
628 | |||
629 | /*! |
|
629 | /*! | |
630 | Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis. |
|
630 | Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis. | |
631 |
|
631 | |||
632 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
632 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
633 | */ |
|
633 | */ | |
634 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) |
|
634 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) | |
635 | { |
|
635 | { | |
636 | d_ptr->m_dataset->addAxis(axis, alignment); |
|
636 | d_ptr->m_dataset->addAxis(axis, alignment); | |
637 | } |
|
637 | } | |
638 |
|
638 | |||
639 | /*! |
|
639 | /*! | |
640 | Removes the \a axis from the chart. |
|
640 | Removes the \a axis from the chart. | |
641 | The chart releases its ownership of the specified \a axis object. |
|
641 | The chart releases its ownership of the specified \a axis object. | |
642 |
|
642 | |||
643 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() |
|
643 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() | |
644 | */ |
|
644 | */ | |
645 | void QChart::removeAxis(QAbstractAxis *axis) |
|
645 | void QChart::removeAxis(QAbstractAxis *axis) | |
646 | { |
|
646 | { | |
647 | d_ptr->m_dataset->removeAxis(axis); |
|
647 | d_ptr->m_dataset->removeAxis(axis); | |
648 | } |
|
648 | } | |
649 |
|
649 | |||
650 | /*! |
|
650 | /*! | |
651 | Returns the value in the \a series domain that corresponds to the \a position relative to chart widget. |
|
651 | Returns the value in the \a series domain that corresponds to the \a position relative to chart widget. | |
652 | */ |
|
652 | */ | |
653 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
653 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) | |
654 | { |
|
654 | { | |
655 | return d_ptr->m_dataset->mapToValue(position, series); |
|
655 | return d_ptr->m_dataset->mapToValue(position, series); | |
656 | } |
|
656 | } | |
657 |
|
657 | |||
658 | /*! |
|
658 | /*! | |
659 | Returns the position on the chart widget that corresponds to the \a value in the \a series domain. |
|
659 | Returns the position on the chart widget that corresponds to the \a value in the \a series domain. | |
660 | */ |
|
660 | */ | |
661 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
661 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) | |
662 | { |
|
662 | { | |
663 | return d_ptr->m_dataset->mapToPosition(value, series); |
|
663 | return d_ptr->m_dataset->mapToPosition(value, series); | |
664 | } |
|
664 | } | |
665 |
|
665 | |||
666 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
666 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
667 |
|
667 | |||
668 | QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type): |
|
668 | QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type): | |
669 | q_ptr(q), |
|
669 | q_ptr(q), | |
670 | m_type(type), |
|
670 | m_type(type), | |
671 | m_legend(0), |
|
671 | m_legend(0), | |
672 | m_dataset(new ChartDataSet(q)), |
|
672 | m_dataset(new ChartDataSet(q)), | |
673 | m_presenter(new ChartPresenter(q, type)), |
|
673 | m_presenter(new ChartPresenter(q, type)), | |
674 | m_themeManager(new ChartThemeManager(q)) |
|
674 | m_themeManager(new ChartThemeManager(q)) | |
675 | { |
|
675 | { | |
676 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
676 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
677 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
677 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
678 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
678 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); | |
679 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
679 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
680 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
680 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
681 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
681 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
682 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
682 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); | |
683 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
683 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
684 | } |
|
684 | } | |
685 |
|
685 | |||
686 | QChartPrivate::~QChartPrivate() |
|
686 | QChartPrivate::~QChartPrivate() | |
687 | { |
|
687 | { | |
688 | } |
|
688 | } | |
689 |
|
689 | |||
690 | void QChartPrivate::init() |
|
690 | void QChartPrivate::init() | |
691 | { |
|
691 | { | |
692 | m_legend = new LegendScroller(q_ptr); |
|
692 | m_legend = new LegendScroller(q_ptr); | |
693 | q_ptr->setTheme(QChart::ChartThemeLight); |
|
693 | q_ptr->setTheme(QChart::ChartThemeLight); | |
694 | q_ptr->setLayout(m_presenter->layout()); |
|
694 | q_ptr->setLayout(m_presenter->layout()); | |
695 | } |
|
695 | } | |
696 |
|
696 | |||
697 | void QChartPrivate::zoomIn(qreal factor) |
|
697 | void QChartPrivate::zoomIn(qreal factor) | |
698 | { |
|
698 | { | |
699 | QRectF rect = m_presenter->geometry(); |
|
699 | QRectF rect = m_presenter->geometry(); | |
700 | rect.setWidth(rect.width() / factor); |
|
700 | rect.setWidth(rect.width() / factor); | |
701 | rect.setHeight(rect.height() / factor); |
|
701 | rect.setHeight(rect.height() / factor); | |
702 | rect.moveCenter(m_presenter->geometry().center()); |
|
702 | rect.moveCenter(m_presenter->geometry().center()); | |
703 | zoomIn(rect); |
|
703 | zoomIn(rect); | |
704 | } |
|
704 | } | |
705 |
|
705 | |||
706 | void QChartPrivate::zoomIn(const QRectF &rect) |
|
706 | void QChartPrivate::zoomIn(const QRectF &rect) | |
707 | { |
|
707 | { | |
708 | if (!rect.isValid()) |
|
708 | if (!rect.isValid()) | |
709 | return; |
|
709 | return; | |
710 |
|
710 | |||
711 | QRectF r = rect.normalized(); |
|
711 | QRectF r = rect.normalized(); | |
712 | const QRectF geometry = m_presenter->geometry(); |
|
712 | const QRectF geometry = m_presenter->geometry(); | |
713 | r.translate(-geometry.topLeft()); |
|
713 | r.translate(-geometry.topLeft()); | |
714 |
|
714 | |||
715 | if (!r.isValid()) |
|
715 | if (!r.isValid()) | |
716 | return; |
|
716 | return; | |
717 |
|
717 | |||
718 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
718 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |
719 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); |
|
719 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); | |
720 | m_dataset->zoomInDomain(r); |
|
720 | m_dataset->zoomInDomain(r); | |
721 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
721 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
722 |
|
722 | |||
723 | } |
|
723 | } | |
724 |
|
724 | |||
725 | void QChartPrivate::zoomOut(qreal factor) |
|
725 | void QChartPrivate::zoomOut(qreal factor) | |
726 | { |
|
726 | { | |
727 | const QRectF geometry = m_presenter->geometry(); |
|
727 | const QRectF geometry = m_presenter->geometry(); | |
728 |
|
728 | |||
729 | QRectF r; |
|
729 | QRectF r; | |
730 | r.setSize(geometry.size() / factor); |
|
730 | r.setSize(geometry.size() / factor); | |
731 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); |
|
731 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); | |
732 | if (!r.isValid()) |
|
732 | if (!r.isValid()) | |
733 | return; |
|
733 | return; | |
734 |
|
734 | |||
735 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
735 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |
736 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); |
|
736 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); | |
737 | m_dataset->zoomOutDomain(r); |
|
737 | m_dataset->zoomOutDomain(r); | |
738 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
738 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
739 | } |
|
739 | } | |
740 |
|
740 | |||
741 | void QChartPrivate::scroll(qreal dx, qreal dy) |
|
741 | void QChartPrivate::scroll(qreal dx, qreal dy) | |
742 | { |
|
742 | { | |
743 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); |
|
743 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); | |
744 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); |
|
744 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); | |
745 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); |
|
745 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); | |
746 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); |
|
746 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); | |
747 |
|
747 | |||
748 | m_dataset->scrollDomain(dx, dy); |
|
748 | m_dataset->scrollDomain(dx, dy); | |
749 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
749 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
750 | } |
|
750 | } | |
751 |
|
751 | |||
752 | #include "moc_qchart.cpp" |
|
752 | #include "moc_qchart.cpp" | |
753 |
|
753 | |||
754 | QTCOMMERCIALCHART_END_NAMESPACE |
|
754 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,576 +1,587 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qxyseries.h" |
|
21 | #include "qxyseries.h" | |
22 | #include "qxyseries_p.h" |
|
22 | #include "qxyseries_p.h" | |
23 | #include "abstractdomain_p.h" |
|
23 | #include "abstractdomain_p.h" | |
24 | #include "qvalueaxis.h" |
|
24 | #include "qvalueaxis.h" | |
25 | #include "xychart_p.h" |
|
25 | #include "xychart_p.h" | |
26 | #include "qxylegendmarker.h" |
|
26 | #include "qxylegendmarker.h" | |
27 | #include "charthelpers_p.h" |
|
27 | #include "charthelpers_p.h" | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | /*! |
|
31 | /*! | |
32 | \class QXYSeries |
|
32 | \class QXYSeries | |
33 | \brief The QXYSeries class is a base class for line, spline and scatter series. |
|
33 | \brief The QXYSeries class is a base class for line, spline and scatter series. | |
34 | */ |
|
34 | */ | |
35 | /*! |
|
35 | /*! | |
36 | \qmlclass XYSeries |
|
36 | \qmlclass XYSeries | |
37 | \inherits AbstractSeries |
|
37 | \inherits AbstractSeries | |
38 | The XYSeries class is a base class for line, spline and scatter series. |
|
38 | The XYSeries class is a base class for line, spline and scatter series. | |
39 |
|
39 | |||
40 | The class cannot be instantiated directly. |
|
40 | The class cannot be instantiated directly. | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \qmlproperty AbstractAxis XYSeries::axisX |
|
44 | \qmlproperty AbstractAxis XYSeries::axisX | |
45 | The x axis used for the series. If you leave both axisX and axisXTop undefined, a ValueAxis is created for |
|
45 | The x axis used for the series. If you leave both axisX and axisXTop undefined, a ValueAxis is created for | |
46 | the series. |
|
46 | the series. | |
47 | \sa axisXTop |
|
47 | \sa axisXTop | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | \qmlproperty AbstractAxis XYSeries::axisY |
|
51 | \qmlproperty AbstractAxis XYSeries::axisY | |
52 | The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for |
|
52 | The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for | |
53 | the series. |
|
53 | the series. | |
54 | \sa axisYRight |
|
54 | \sa axisYRight | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | \qmlproperty AbstractAxis XYSeries::axisXTop |
|
58 | \qmlproperty AbstractAxis XYSeries::axisXTop | |
59 | The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or |
|
59 | The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or | |
60 | axisXTop, but not both. |
|
60 | axisXTop, but not both. | |
61 | \sa axisX |
|
61 | \sa axisX | |
62 | */ |
|
62 | */ | |
63 |
|
63 | |||
64 | /*! |
|
64 | /*! | |
65 | \qmlproperty AbstractAxis XYSeries::axisYRight |
|
65 | \qmlproperty AbstractAxis XYSeries::axisYRight | |
66 | The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY |
|
66 | The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY | |
67 | or axisYRight, but not both. |
|
67 | or axisYRight, but not both. | |
68 | \sa axisY |
|
68 | \sa axisY | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \qmlproperty AbstractAxis XYSeries::axisAngular |
|
72 | \qmlproperty AbstractAxis XYSeries::axisAngular | |
73 | The angular axis used for the series, drawn around the polar chart view. |
|
73 | The angular axis used for the series, drawn around the polar chart view. | |
74 | \sa axisX |
|
74 | \sa axisX | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 | \qmlproperty AbstractAxis XYSeries::axisRadial |
|
78 | \qmlproperty AbstractAxis XYSeries::axisRadial | |
79 | The radial axis used for the series, drawn inside the polar chart view. |
|
79 | The radial axis used for the series, drawn inside the polar chart view. | |
80 | \sa axisY |
|
80 | \sa axisY | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \property QXYSeries::pointsVisible |
|
84 | \property QXYSeries::pointsVisible | |
85 | Controls if the data points are visible and should be drawn. |
|
85 | Controls if the data points are visible and should be drawn. | |
86 | */ |
|
86 | */ | |
87 | /*! |
|
87 | /*! | |
88 | \qmlproperty bool XYSeries::pointsVisible |
|
88 | \qmlproperty bool XYSeries::pointsVisible | |
89 | Controls if the data points are visible and should be drawn. |
|
89 | Controls if the data points are visible and should be drawn. | |
90 | */ |
|
90 | */ | |
91 |
|
91 | |||
92 | /*! |
|
92 | /*! | |
93 | \fn QPen QXYSeries::pen() const |
|
93 | \fn QPen QXYSeries::pen() const | |
94 | \brief Returns pen used to draw points for series. |
|
94 | \brief Returns pen used to draw points for series. | |
95 | \sa setPen() |
|
95 | \sa setPen() | |
96 | */ |
|
96 | */ | |
97 |
|
97 | |||
98 | /*! |
|
98 | /*! | |
99 | \fn QBrush QXYSeries::brush() const |
|
99 | \fn QBrush QXYSeries::brush() const | |
100 | \brief Returns brush used to draw points for series. |
|
100 | \brief Returns brush used to draw points for series. | |
101 | \sa setBrush() |
|
101 | \sa setBrush() | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | \property QXYSeries::color |
|
105 | \property QXYSeries::color | |
106 | The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and |
|
106 | The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and | |
107 | fill (brush) color in case of QScatterSeries or QAreaSeries. |
|
107 | fill (brush) color in case of QScatterSeries or QAreaSeries. | |
108 | \sa QXYSeries::pen(), QXYSeries::brush() |
|
108 | \sa QXYSeries::pen(), QXYSeries::brush() | |
109 | */ |
|
109 | */ | |
110 | /*! |
|
110 | /*! | |
111 | \qmlproperty color XYSeries::color |
|
111 | \qmlproperty color XYSeries::color | |
112 | The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and |
|
112 | The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and | |
113 | fill (brush) color in case of ScatterSeries or AreaSeries. |
|
113 | fill (brush) color in case of ScatterSeries or AreaSeries. | |
114 | */ |
|
114 | */ | |
115 |
|
115 | |||
116 | /*! |
|
116 | /*! | |
117 | \fn void QXYSeries::clicked(const QPointF& point) |
|
117 | \fn void QXYSeries::clicked(const QPointF& point) | |
118 | \brief Signal is emitted when user clicks the \a point on chart. |
|
118 | \brief Signal is emitted when user clicks the \a point on chart. | |
119 | */ |
|
119 | */ | |
120 | /*! |
|
120 | /*! | |
121 | \qmlsignal XYSeries::onClicked(QPointF point) |
|
121 | \qmlsignal XYSeries::onClicked(QPointF point) | |
122 | Signal is emitted when user clicks the \a point on chart. For example: |
|
122 | Signal is emitted when user clicks the \a point on chart. For example: | |
123 | \code |
|
123 | \code | |
124 | LineSeries { |
|
124 | LineSeries { | |
125 | XYPoint { x: 0; y: 0 } |
|
125 | XYPoint { x: 0; y: 0 } | |
126 | XYPoint { x: 1.1; y: 2.1 } |
|
126 | XYPoint { x: 1.1; y: 2.1 } | |
127 | onClicked: console.log("onClicked: " + point.x + ", " + point.y); |
|
127 | onClicked: console.log("onClicked: " + point.x + ", " + point.y); | |
128 | } |
|
128 | } | |
129 | \endcode |
|
129 | \endcode | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \fn void QXYSeries::hovered(const QPointF &point, bool state) |
|
133 | \fn void QXYSeries::hovered(const QPointF &point, bool state) | |
134 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) |
|
134 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) | |
135 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from |
|
135 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from | |
136 | the series. |
|
136 | the series. | |
137 | */ |
|
137 | */ | |
138 | /*! |
|
138 | /*! | |
139 | \qmlsignal XYSeries::onHovered(point point, bool state) |
|
139 | \qmlsignal XYSeries::onHovered(point point, bool state) | |
140 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) |
|
140 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) | |
141 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from |
|
141 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from | |
142 | the series. |
|
142 | the series. | |
143 | */ |
|
143 | */ | |
144 |
|
144 | |||
145 | /*! |
|
145 | /*! | |
146 | \fn void QXYSeries::pointReplaced(int index) |
|
146 | \fn void QXYSeries::pointReplaced(int index) | |
147 | Signal is emitted when a point has been replaced at \a index. |
|
147 | Signal is emitted when a point has been replaced at \a index. | |
148 | \sa replace() |
|
148 | \sa replace() | |
149 | */ |
|
149 | */ | |
150 | /*! |
|
150 | /*! | |
151 | \qmlsignal XYSeries::onPointReplaced(int index) |
|
151 | \qmlsignal XYSeries::onPointReplaced(int index) | |
152 | Signal is emitted when a point has been replaced at \a index. |
|
152 | Signal is emitted when a point has been replaced at \a index. | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \fn void QXYSeries::pointsReplaced() |
|
156 | \fn void QXYSeries::pointsReplaced() | |
157 | Signal is emitted when all points have been replaced with other points. |
|
157 | Signal is emitted when all points have been replaced with other points. | |
158 | \sa replace() |
|
158 | \sa replace() | |
159 | */ |
|
159 | */ | |
160 | /*! |
|
160 | /*! | |
161 | \qmlsignal XYSeries::onPointsReplaced() |
|
161 | \qmlsignal XYSeries::onPointsReplaced() | |
162 | */ |
|
162 | */ | |
163 |
|
163 | |||
164 | /*! |
|
164 | /*! | |
165 | \fn void QXYSeries::pointAdded(int index) |
|
165 | \fn void QXYSeries::pointAdded(int index) | |
166 | Signal is emitted when a point has been added at \a index. |
|
166 | Signal is emitted when a point has been added at \a index. | |
167 | \sa append(), insert() |
|
167 | \sa append(), insert() | |
168 | */ |
|
168 | */ | |
169 | /*! |
|
169 | /*! | |
170 | \qmlsignal XYSeries::onPointAdded(int index) |
|
170 | \qmlsignal XYSeries::onPointAdded(int index) | |
171 | Signal is emitted when a point has been added at \a index. |
|
171 | Signal is emitted when a point has been added at \a index. | |
172 | */ |
|
172 | */ | |
173 |
|
173 | |||
174 | /*! |
|
174 | /*! | |
175 | \fn void QXYSeries::pointRemoved(int index) |
|
175 | \fn void QXYSeries::pointRemoved(int index) | |
176 | Signal is emitted when a point has been removed from \a index. |
|
176 | Signal is emitted when a point has been removed from \a index. | |
177 | \sa remove() |
|
177 | \sa remove() | |
178 | */ |
|
178 | */ | |
179 | /*! |
|
179 | /*! | |
180 | \qmlsignal XYSeries::onPointRemoved(int index) |
|
180 | \qmlsignal XYSeries::onPointRemoved(int index) | |
181 | Signal is emitted when a point has been removed from \a index. |
|
181 | Signal is emitted when a point has been removed from \a index. | |
182 | */ |
|
182 | */ | |
183 |
|
183 | |||
184 | /*! |
|
184 | /*! | |
185 | \fn void QXYSeries::colorChanged(QColor color) |
|
185 | \fn void QXYSeries::colorChanged(QColor color) | |
186 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
186 | \brief Signal is emitted when the line (pen) color has changed to \a color. | |
187 | */ |
|
187 | */ | |
188 | /*! |
|
188 | /*! | |
189 | \qmlsignal XYSeries::onColorChanged(color color) |
|
189 | \qmlsignal XYSeries::onColorChanged(color color) | |
190 | Signal is emitted when the line (pen) color has changed to \a color. |
|
190 | Signal is emitted when the line (pen) color has changed to \a color. | |
191 | */ |
|
191 | */ | |
192 |
|
192 | |||
193 | /*! |
|
193 | /*! | |
194 | \fn void QXYSeriesPrivate::updated() |
|
194 | \fn void QXYSeriesPrivate::updated() | |
195 | \brief \internal |
|
195 | \brief \internal | |
196 | */ |
|
196 | */ | |
197 |
|
197 | |||
198 | /*! |
|
198 | /*! | |
199 | \qmlmethod XYSeries::append(real x, real y) |
|
199 | \qmlmethod XYSeries::append(real x, real y) | |
200 | Append point (\a x, \a y) to the series |
|
200 | Append point (\a x, \a y) to the series | |
201 | */ |
|
201 | */ | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY) |
|
204 | \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY) | |
205 | Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not |
|
205 | Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not | |
206 | exist. |
|
206 | exist. | |
207 | */ |
|
207 | */ | |
208 |
|
208 | |||
209 | /*! |
|
209 | /*! | |
210 | \qmlmethod XYSeries::remove(real x, real y) |
|
210 | \qmlmethod XYSeries::remove(real x, real y) | |
211 | Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist. |
|
211 | Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist. | |
212 | */ |
|
212 | */ | |
213 |
|
213 | |||
214 | /*! |
|
214 | /*! | |
215 | \qmlmethod XYSeries::insert(int index, real x, real y) |
|
215 | \qmlmethod XYSeries::insert(int index, real x, real y) | |
216 | Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of |
|
216 | Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of | |
217 | points. If index is the same as or bigger than count, the point is appended to the list of points. |
|
217 | points. If index is the same as or bigger than count, the point is appended to the list of points. | |
218 | */ |
|
218 | */ | |
219 |
|
219 | |||
220 | /*! |
|
220 | /*! | |
221 | \qmlmethod QPointF XYSeries::at(int index) |
|
221 | \qmlmethod QPointF XYSeries::at(int index) | |
222 | Returns point at \a index. Returns (0, 0) if the index is not valid. |
|
222 | Returns point at \a index. Returns (0, 0) if the index is not valid. | |
223 | */ |
|
223 | */ | |
224 |
|
224 | |||
225 | /*! |
|
225 | /*! | |
226 | \internal |
|
226 | \internal | |
227 |
|
227 | |||
228 | Constructs empty series object which is a child of \a parent. |
|
228 | Constructs empty series object which is a child of \a parent. | |
229 | When series object is added to QChart instance ownerships is transferred. |
|
229 | When series object is added to QChart instance ownerships is transferred. | |
230 | */ |
|
230 | */ | |
231 | QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent) |
|
231 | QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent) | |
232 | : QAbstractSeries(d, parent) |
|
232 | : QAbstractSeries(d, parent) | |
233 | { |
|
233 | { | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | /*! |
|
236 | /*! | |
237 | Destroys the object. Series added to QChart instances are owned by those, |
|
237 | Destroys the object. Series added to QChart instances are owned by those, | |
238 | and are destroyed when QChart instances are destroyed. |
|
238 | and are destroyed when QChart instances are destroyed. | |
239 | */ |
|
239 | */ | |
240 | QXYSeries::~QXYSeries() |
|
240 | QXYSeries::~QXYSeries() | |
241 | { |
|
241 | { | |
242 | } |
|
242 | } | |
243 |
|
243 | |||
244 | /*! |
|
244 | /*! | |
245 | Adds data point (\a x, \a y) to the series. |
|
245 | Adds data point (\a x, \a y) to the series. | |
246 | */ |
|
246 | */ | |
247 | void QXYSeries::append(qreal x, qreal y) |
|
247 | void QXYSeries::append(qreal x, qreal y) | |
248 | { |
|
248 | { | |
249 | append(QPointF(x, y)); |
|
249 | append(QPointF(x, y)); | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | /*! |
|
252 | /*! | |
253 | This is an overloaded function. |
|
253 | This is an overloaded function. | |
254 | Adds data \a point to the series. |
|
254 | Adds data \a point to the series. | |
255 | */ |
|
255 | */ | |
256 | void QXYSeries::append(const QPointF &point) |
|
256 | void QXYSeries::append(const QPointF &point) | |
257 | { |
|
257 | { | |
258 | Q_D(QXYSeries); |
|
258 | Q_D(QXYSeries); | |
259 |
|
259 | |||
260 | if (isValidValue(point)) { |
|
260 | if (isValidValue(point)) { | |
261 | d->m_points << point; |
|
261 | d->m_points << point; | |
262 | emit pointAdded(d->m_points.count() - 1); |
|
262 | emit pointAdded(d->m_points.count() - 1); | |
263 | } |
|
263 | } | |
264 | } |
|
264 | } | |
265 |
|
265 | |||
266 | /*! |
|
266 | /*! | |
267 | This is an overloaded function. |
|
267 | This is an overloaded function. | |
268 | Adds list of data \a points to the series. |
|
268 | Adds list of data \a points to the series. | |
269 | */ |
|
269 | */ | |
270 | void QXYSeries::append(const QList<QPointF> &points) |
|
270 | void QXYSeries::append(const QList<QPointF> &points) | |
271 | { |
|
271 | { | |
272 | foreach (const QPointF &point , points) |
|
272 | foreach (const QPointF &point , points) | |
273 | append(point); |
|
273 | append(point); | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | /*! |
|
276 | /*! | |
277 | Replaces data point (\a oldX, \a oldY) with data point (\a newX, \a newY). |
|
277 | Replaces data point (\a oldX, \a oldY) with data point (\a newX, \a newY). | |
278 | \sa QXYSeries::pointReplaced() |
|
278 | \sa QXYSeries::pointReplaced() | |
279 | */ |
|
279 | */ | |
280 | void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY) |
|
280 | void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY) | |
281 | { |
|
281 | { | |
282 | replace(QPointF(oldX, oldY), QPointF(newX, newY)); |
|
282 | replace(QPointF(oldX, oldY), QPointF(newX, newY)); | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | /*! |
|
285 | /*! | |
286 | Replaces \a oldPoint with \a newPoint. |
|
286 | Replaces \a oldPoint with \a newPoint. | |
287 | \sa QXYSeries::pointReplaced() |
|
287 | \sa QXYSeries::pointReplaced() | |
288 | */ |
|
288 | */ | |
289 | void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint) |
|
289 | void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint) | |
290 | { |
|
290 | { | |
291 | Q_D(QXYSeries); |
|
291 | Q_D(QXYSeries); | |
292 | int index = d->m_points.indexOf(oldPoint); |
|
292 | int index = d->m_points.indexOf(oldPoint); | |
293 | if (index == -1) |
|
293 | if (index == -1) | |
294 | return; |
|
294 | return; | |
295 | replace(index, newPoint); |
|
295 | replace(index, newPoint); | |
296 | } |
|
296 | } | |
297 |
|
297 | |||
|
298 | /*! | |||
|
299 | Replaces the point at \a index with data point (\a newX, \a newY). | |||
|
300 | \sa QXYSeries::pointReplaced() | |||
|
301 | */ | |||
298 | void QXYSeries::replace(int index, qreal newX, qreal newY) |
|
302 | void QXYSeries::replace(int index, qreal newX, qreal newY) | |
299 | { |
|
303 | { | |
300 | replace(index, QPointF(newX, newY)); |
|
304 | replace(index, QPointF(newX, newY)); | |
301 | } |
|
305 | } | |
302 |
|
306 | |||
|
307 | /*! | |||
|
308 | Replaces the point at \a index with \a newPoint. | |||
|
309 | \sa QXYSeries::pointReplaced() | |||
|
310 | */ | |||
303 | void QXYSeries::replace(int index, const QPointF &newPoint) |
|
311 | void QXYSeries::replace(int index, const QPointF &newPoint) | |
304 | { |
|
312 | { | |
305 | Q_D(QXYSeries); |
|
313 | Q_D(QXYSeries); | |
306 | if (isValidValue(newPoint)) { |
|
314 | if (isValidValue(newPoint)) { | |
307 | d->m_points[index] = newPoint; |
|
315 | d->m_points[index] = newPoint; | |
308 | emit pointReplaced(index); |
|
316 | emit pointReplaced(index); | |
309 | } |
|
317 | } | |
310 | } |
|
318 | } | |
311 |
|
319 | |||
312 | /*! |
|
320 | /*! | |
313 | Replaces the current points with \a points. |
|
321 | Replaces the current points with \a points. | |
314 | \note This is much faster than replacing data points one by one, |
|
322 | \note This is much faster than replacing data points one by one, | |
315 | or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced() |
|
323 | or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced() | |
316 | when the points have been replaced. |
|
324 | when the points have been replaced. | |
317 | \sa QXYSeries::pointsReplaced() |
|
325 | \sa QXYSeries::pointsReplaced() | |
318 | */ |
|
326 | */ | |
319 | void QXYSeries::replace(QList<QPointF> points) |
|
327 | void QXYSeries::replace(QList<QPointF> points) | |
320 | { |
|
328 | { | |
321 | Q_D(QXYSeries); |
|
329 | Q_D(QXYSeries); | |
322 | d->m_points = points.toVector(); |
|
330 | d->m_points = points.toVector(); | |
323 | emit pointsReplaced(); |
|
331 | emit pointsReplaced(); | |
324 | } |
|
332 | } | |
325 |
|
333 | |||
326 | /*! |
|
334 | /*! | |
327 | Removes the point (\a x, \a y) from the series. |
|
335 | Removes the point (\a x, \a y) from the series. | |
328 | */ |
|
336 | */ | |
329 | void QXYSeries::remove(qreal x, qreal y) |
|
337 | void QXYSeries::remove(qreal x, qreal y) | |
330 | { |
|
338 | { | |
331 | remove(QPointF(x, y)); |
|
339 | remove(QPointF(x, y)); | |
332 | } |
|
340 | } | |
333 |
|
341 | |||
334 | /*! |
|
342 | /*! | |
335 | Removes the \a point from the series. |
|
343 | Removes the \a point from the series. | |
336 | */ |
|
344 | */ | |
337 | void QXYSeries::remove(const QPointF &point) |
|
345 | void QXYSeries::remove(const QPointF &point) | |
338 | { |
|
346 | { | |
339 | Q_D(QXYSeries); |
|
347 | Q_D(QXYSeries); | |
340 | int index = d->m_points.indexOf(point); |
|
348 | int index = d->m_points.indexOf(point); | |
341 | if (index == -1) |
|
349 | if (index == -1) | |
342 | return; |
|
350 | return; | |
343 | remove(index); |
|
351 | remove(index); | |
344 | } |
|
352 | } | |
345 |
|
353 | |||
|
354 | /*! | |||
|
355 | Removes the point at \a index from the series. | |||
|
356 | */ | |||
346 | void QXYSeries::remove(int index) |
|
357 | void QXYSeries::remove(int index) | |
347 | { |
|
358 | { | |
348 | Q_D(QXYSeries); |
|
359 | Q_D(QXYSeries); | |
349 | d->m_points.remove(index); |
|
360 | d->m_points.remove(index); | |
350 | emit pointRemoved(index); |
|
361 | emit pointRemoved(index); | |
351 | } |
|
362 | } | |
352 |
|
363 | |||
353 | /*! |
|
364 | /*! | |
354 | Inserts a \a point in the series at \a index position. |
|
365 | Inserts a \a point in the series at \a index position. | |
355 | */ |
|
366 | */ | |
356 | void QXYSeries::insert(int index, const QPointF &point) |
|
367 | void QXYSeries::insert(int index, const QPointF &point) | |
357 | { |
|
368 | { | |
358 | Q_D(QXYSeries); |
|
369 | Q_D(QXYSeries); | |
359 | if (isValidValue(point)) { |
|
370 | if (isValidValue(point)) { | |
360 | d->m_points.insert(index, point); |
|
371 | d->m_points.insert(index, point); | |
361 | emit pointAdded(index); |
|
372 | emit pointAdded(index); | |
362 | } |
|
373 | } | |
363 | } |
|
374 | } | |
364 |
|
375 | |||
365 | /*! |
|
376 | /*! | |
366 | Removes all points from the series. |
|
377 | Removes all points from the series. | |
367 | */ |
|
378 | */ | |
368 | void QXYSeries::clear() |
|
379 | void QXYSeries::clear() | |
369 | { |
|
380 | { | |
370 | Q_D(QXYSeries); |
|
381 | Q_D(QXYSeries); | |
371 | for (int i = d->m_points.size() - 1; i >= 0; i--) |
|
382 | for (int i = d->m_points.size() - 1; i >= 0; i--) | |
372 | remove(d->m_points.at(i)); |
|
383 | remove(d->m_points.at(i)); | |
373 | } |
|
384 | } | |
374 |
|
385 | |||
375 | /*! |
|
386 | /*! | |
376 | Returns list of points in the series. |
|
387 | Returns list of points in the series. | |
377 | */ |
|
388 | */ | |
378 | QList<QPointF> QXYSeries::points() const |
|
389 | QList<QPointF> QXYSeries::points() const | |
379 | { |
|
390 | { | |
380 | Q_D(const QXYSeries); |
|
391 | Q_D(const QXYSeries); | |
381 | return d->m_points.toList(); |
|
392 | return d->m_points.toList(); | |
382 | } |
|
393 | } | |
383 |
|
394 | |||
384 | /*! |
|
395 | /*! | |
385 | Returns point at \a index in internal points vector. |
|
396 | Returns point at \a index in internal points vector. | |
386 | */ |
|
397 | */ | |
387 | const QPointF &QXYSeries::at(int index) const |
|
398 | const QPointF &QXYSeries::at(int index) const | |
388 | { |
|
399 | { | |
389 | Q_D(const QXYSeries); |
|
400 | Q_D(const QXYSeries); | |
390 | return d->m_points.at(index); |
|
401 | return d->m_points.at(index); | |
391 | } |
|
402 | } | |
392 |
|
403 | |||
393 | /*! |
|
404 | /*! | |
394 | Returns number of data points within series. |
|
405 | Returns number of data points within series. | |
395 | */ |
|
406 | */ | |
396 | int QXYSeries::count() const |
|
407 | int QXYSeries::count() const | |
397 | { |
|
408 | { | |
398 | Q_D(const QXYSeries); |
|
409 | Q_D(const QXYSeries); | |
399 | return d->m_points.count(); |
|
410 | return d->m_points.count(); | |
400 | } |
|
411 | } | |
401 |
|
412 | |||
402 |
|
413 | |||
403 | /*! |
|
414 | /*! | |
404 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
415 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the | |
405 | pen from chart theme is used. |
|
416 | pen from chart theme is used. | |
406 | \sa QChart::setTheme() |
|
417 | \sa QChart::setTheme() | |
407 | */ |
|
418 | */ | |
408 | void QXYSeries::setPen(const QPen &pen) |
|
419 | void QXYSeries::setPen(const QPen &pen) | |
409 | { |
|
420 | { | |
410 | Q_D(QXYSeries); |
|
421 | Q_D(QXYSeries); | |
411 | if (d->m_pen != pen) { |
|
422 | if (d->m_pen != pen) { | |
412 | bool emitColorChanged = d->m_pen.color() != pen.color(); |
|
423 | bool emitColorChanged = d->m_pen.color() != pen.color(); | |
413 | d->m_pen = pen; |
|
424 | d->m_pen = pen; | |
414 | emit d->updated(); |
|
425 | emit d->updated(); | |
415 | if (emitColorChanged) |
|
426 | if (emitColorChanged) | |
416 | emit colorChanged(pen.color()); |
|
427 | emit colorChanged(pen.color()); | |
417 | } |
|
428 | } | |
418 | } |
|
429 | } | |
419 |
|
430 | |||
420 | QPen QXYSeries::pen() const |
|
431 | QPen QXYSeries::pen() const | |
421 | { |
|
432 | { | |
422 | Q_D(const QXYSeries); |
|
433 | Q_D(const QXYSeries); | |
423 | return d->m_pen; |
|
434 | return d->m_pen; | |
424 | } |
|
435 | } | |
425 |
|
436 | |||
426 | /*! |
|
437 | /*! | |
427 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
438 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush | |
428 | from chart theme setting is used. |
|
439 | from chart theme setting is used. | |
429 | \sa QChart::setTheme() |
|
440 | \sa QChart::setTheme() | |
430 | */ |
|
441 | */ | |
431 | void QXYSeries::setBrush(const QBrush &brush) |
|
442 | void QXYSeries::setBrush(const QBrush &brush) | |
432 | { |
|
443 | { | |
433 | Q_D(QXYSeries); |
|
444 | Q_D(QXYSeries); | |
434 | if (d->m_brush != brush) { |
|
445 | if (d->m_brush != brush) { | |
435 | d->m_brush = brush; |
|
446 | d->m_brush = brush; | |
436 | emit d->updated(); |
|
447 | emit d->updated(); | |
437 | } |
|
448 | } | |
438 | } |
|
449 | } | |
439 |
|
450 | |||
440 | QBrush QXYSeries::brush() const |
|
451 | QBrush QXYSeries::brush() const | |
441 | { |
|
452 | { | |
442 | Q_D(const QXYSeries); |
|
453 | Q_D(const QXYSeries); | |
443 | return d->m_brush; |
|
454 | return d->m_brush; | |
444 | } |
|
455 | } | |
445 |
|
456 | |||
446 | void QXYSeries::setColor(const QColor &color) |
|
457 | void QXYSeries::setColor(const QColor &color) | |
447 | { |
|
458 | { | |
448 | QPen p = pen(); |
|
459 | QPen p = pen(); | |
449 | if (p.color() != color) { |
|
460 | if (p.color() != color) { | |
450 | p.setColor(color); |
|
461 | p.setColor(color); | |
451 | setPen(p); |
|
462 | setPen(p); | |
452 | } |
|
463 | } | |
453 | } |
|
464 | } | |
454 |
|
465 | |||
455 | QColor QXYSeries::color() const |
|
466 | QColor QXYSeries::color() const | |
456 | { |
|
467 | { | |
457 | return pen().color(); |
|
468 | return pen().color(); | |
458 | } |
|
469 | } | |
459 |
|
470 | |||
460 | void QXYSeries::setPointsVisible(bool visible) |
|
471 | void QXYSeries::setPointsVisible(bool visible) | |
461 | { |
|
472 | { | |
462 | Q_D(QXYSeries); |
|
473 | Q_D(QXYSeries); | |
463 | if (d->m_pointsVisible != visible) { |
|
474 | if (d->m_pointsVisible != visible) { | |
464 | d->m_pointsVisible = visible; |
|
475 | d->m_pointsVisible = visible; | |
465 | emit d->updated(); |
|
476 | emit d->updated(); | |
466 | } |
|
477 | } | |
467 | } |
|
478 | } | |
468 |
|
479 | |||
469 | bool QXYSeries::pointsVisible() const |
|
480 | bool QXYSeries::pointsVisible() const | |
470 | { |
|
481 | { | |
471 | Q_D(const QXYSeries); |
|
482 | Q_D(const QXYSeries); | |
472 | return d->m_pointsVisible; |
|
483 | return d->m_pointsVisible; | |
473 | } |
|
484 | } | |
474 |
|
485 | |||
475 |
|
486 | |||
476 | /*! |
|
487 | /*! | |
477 | Stream operator for adding a data \a point to the series. |
|
488 | Stream operator for adding a data \a point to the series. | |
478 | \sa append() |
|
489 | \sa append() | |
479 | */ |
|
490 | */ | |
480 | QXYSeries &QXYSeries::operator<< (const QPointF &point) |
|
491 | QXYSeries &QXYSeries::operator<< (const QPointF &point) | |
481 | { |
|
492 | { | |
482 | append(point); |
|
493 | append(point); | |
483 | return *this; |
|
494 | return *this; | |
484 | } |
|
495 | } | |
485 |
|
496 | |||
486 |
|
497 | |||
487 | /*! |
|
498 | /*! | |
488 | Stream operator for adding a list of \a points to the series. |
|
499 | Stream operator for adding a list of \a points to the series. | |
489 | \sa append() |
|
500 | \sa append() | |
490 | */ |
|
501 | */ | |
491 |
|
502 | |||
492 | QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points) |
|
503 | QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points) | |
493 | { |
|
504 | { | |
494 | append(points); |
|
505 | append(points); | |
495 | return *this; |
|
506 | return *this; | |
496 | } |
|
507 | } | |
497 |
|
508 | |||
498 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
509 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
499 |
|
510 | |||
500 |
|
511 | |||
501 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) |
|
512 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) | |
502 | : QAbstractSeriesPrivate(q), |
|
513 | : QAbstractSeriesPrivate(q), | |
503 | m_pointsVisible(false) |
|
514 | m_pointsVisible(false) | |
504 | { |
|
515 | { | |
505 | } |
|
516 | } | |
506 |
|
517 | |||
507 | void QXYSeriesPrivate::initializeDomain() |
|
518 | void QXYSeriesPrivate::initializeDomain() | |
508 | { |
|
519 | { | |
509 | qreal minX(0); |
|
520 | qreal minX(0); | |
510 | qreal minY(0); |
|
521 | qreal minY(0); | |
511 | qreal maxX(1); |
|
522 | qreal maxX(1); | |
512 | qreal maxY(1); |
|
523 | qreal maxY(1); | |
513 |
|
524 | |||
514 | Q_Q(QXYSeries); |
|
525 | Q_Q(QXYSeries); | |
515 |
|
526 | |||
516 | const QList<QPointF>& points = q->points(); |
|
527 | const QList<QPointF>& points = q->points(); | |
517 |
|
528 | |||
518 | if (!points.isEmpty()) { |
|
529 | if (!points.isEmpty()) { | |
519 | minX = points[0].x(); |
|
530 | minX = points[0].x(); | |
520 | minY = points[0].y(); |
|
531 | minY = points[0].y(); | |
521 | maxX = minX; |
|
532 | maxX = minX; | |
522 | maxY = minY; |
|
533 | maxY = minY; | |
523 |
|
534 | |||
524 | for (int i = 0; i < points.count(); i++) { |
|
535 | for (int i = 0; i < points.count(); i++) { | |
525 | qreal x = points[i].x(); |
|
536 | qreal x = points[i].x(); | |
526 | qreal y = points[i].y(); |
|
537 | qreal y = points[i].y(); | |
527 | minX = qMin(minX, x); |
|
538 | minX = qMin(minX, x); | |
528 | minY = qMin(minY, y); |
|
539 | minY = qMin(minY, y); | |
529 | maxX = qMax(maxX, x); |
|
540 | maxX = qMax(maxX, x); | |
530 | maxY = qMax(maxY, y); |
|
541 | maxY = qMax(maxY, y); | |
531 | } |
|
542 | } | |
532 | } |
|
543 | } | |
533 |
|
544 | |||
534 | domain()->setRange(minX, maxX, minY, maxY); |
|
545 | domain()->setRange(minX, maxX, minY, maxY); | |
535 | } |
|
546 | } | |
536 |
|
547 | |||
537 | QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
548 | QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend) | |
538 | { |
|
549 | { | |
539 | Q_Q(QXYSeries); |
|
550 | Q_Q(QXYSeries); | |
540 | QList<QLegendMarker*> list; |
|
551 | QList<QLegendMarker*> list; | |
541 | return list << new QXYLegendMarker(q,legend); |
|
552 | return list << new QXYLegendMarker(q,legend); | |
542 | } |
|
553 | } | |
543 |
|
554 | |||
544 | void QXYSeriesPrivate::initializeAxes() |
|
555 | void QXYSeriesPrivate::initializeAxes() | |
545 | { |
|
556 | { | |
546 |
|
557 | |||
547 | } |
|
558 | } | |
548 |
|
559 | |||
549 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
560 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
550 | { |
|
561 | { | |
551 | Q_UNUSED(orientation); |
|
562 | Q_UNUSED(orientation); | |
552 | return QAbstractAxis::AxisTypeValue; |
|
563 | return QAbstractAxis::AxisTypeValue; | |
553 | } |
|
564 | } | |
554 |
|
565 | |||
555 | QAbstractAxis* QXYSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
566 | QAbstractAxis* QXYSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const | |
556 | { |
|
567 | { | |
557 | Q_UNUSED(orientation); |
|
568 | Q_UNUSED(orientation); | |
558 | return 0; |
|
569 | return 0; | |
559 | } |
|
570 | } | |
560 |
|
571 | |||
561 | void QXYSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) |
|
572 | void QXYSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) | |
562 | { |
|
573 | { | |
563 | XYChart *item = static_cast<XYChart *>(m_item.data()); |
|
574 | XYChart *item = static_cast<XYChart *>(m_item.data()); | |
564 | Q_ASSERT(item); |
|
575 | Q_ASSERT(item); | |
565 | if (options.testFlag(QChart::SeriesAnimations)) { |
|
576 | if (options.testFlag(QChart::SeriesAnimations)) { | |
566 | item->setAnimation(new XYAnimation(item)); |
|
577 | item->setAnimation(new XYAnimation(item)); | |
567 | }else{ |
|
578 | }else{ | |
568 | item->setAnimation(0); |
|
579 | item->setAnimation(0); | |
569 | } |
|
580 | } | |
570 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
581 | QAbstractSeriesPrivate::initializeAnimations(options); | |
571 | } |
|
582 | } | |
572 |
|
583 | |||
573 | #include "moc_qxyseries.cpp" |
|
584 | #include "moc_qxyseries.cpp" | |
574 | #include "moc_qxyseries_p.cpp" |
|
585 | #include "moc_qxyseries_p.cpp" | |
575 |
|
586 | |||
576 | QTCOMMERCIALCHART_END_NAMESPACE |
|
587 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now