@@ -1,698 +1,665 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "legendscroller_p.h" |
|
23 | #include "legendscroller_p.h" | |
24 | #include "qlegend_p.h" |
|
24 | #include "qlegend_p.h" | |
25 | #include "chartbackground_p.h" |
|
25 | #include "chartbackground_p.h" | |
26 | #include "qabstractaxis.h" |
|
26 | #include "qabstractaxis.h" | |
27 | #include "chartlayout_p.h" |
|
27 | #include "chartlayout_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartpresenter_p.h" |
|
29 | #include "chartpresenter_p.h" | |
30 | #include "chartdataset_p.h" |
|
30 | #include "chartdataset_p.h" | |
31 | #include <QGraphicsScene> |
|
31 | #include <QGraphicsScene> | |
32 | #include <QGraphicsSceneResizeEvent> |
|
32 | #include <QGraphicsSceneResizeEvent> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \enum QChart::ChartTheme |
|
37 | \enum QChart::ChartTheme | |
38 |
|
38 | |||
39 | This enum describes the theme used by the chart. |
|
39 | This enum describes the theme used by the chart. | |
40 |
|
40 | |||
41 | \value ChartThemeLight The default theme |
|
41 | \value ChartThemeLight The default theme | |
42 | \value ChartThemeBlueCerulean |
|
42 | \value ChartThemeBlueCerulean | |
43 | \value ChartThemeDark |
|
43 | \value ChartThemeDark | |
44 | \value ChartThemeBrownSand |
|
44 | \value ChartThemeBrownSand | |
45 | \value ChartThemeBlueNcs |
|
45 | \value ChartThemeBlueNcs | |
46 | \value ChartThemeHighContrast |
|
46 | \value ChartThemeHighContrast | |
47 | \value ChartThemeBlueIcy |
|
47 | \value ChartThemeBlueIcy | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | \enum QChart::AnimationOption |
|
51 | \enum QChart::AnimationOption | |
52 |
|
52 | |||
53 | For enabling/disabling animations. Defaults to NoAnimation. |
|
53 | For enabling/disabling animations. Defaults to NoAnimation. | |
54 |
|
54 | |||
55 | \value NoAnimation |
|
55 | \value NoAnimation | |
56 | \value GridAxisAnimations |
|
56 | \value GridAxisAnimations | |
57 | \value SeriesAnimations |
|
57 | \value SeriesAnimations | |
58 | \value AllAnimations |
|
58 | \value AllAnimations | |
59 | */ |
|
59 | */ | |
60 |
|
60 | |||
61 | /*! |
|
61 | /*! | |
62 | \class QChart |
|
62 | \class QChart | |
63 | \brief QtCommercial chart API. |
|
63 | \brief QtCommercial chart API. | |
64 |
|
64 | |||
65 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
65 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
66 | representation of different types of series and other chart related objects like |
|
66 | representation of different types of series and other chart related objects like | |
67 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the |
|
67 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the | |
68 | convenience class QChartView instead of QChart. |
|
68 | convenience class QChartView instead of QChart. | |
69 | \sa QChartView |
|
69 | \sa QChartView | |
70 | */ |
|
70 | */ | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | \property QChart::animationOptions |
|
73 | \property QChart::animationOptions | |
74 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
74 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 | \property QChart::backgroundVisible |
|
78 | \property QChart::backgroundVisible | |
79 | Whether the chart background is visible or not. |
|
79 | Whether the chart background is visible or not. | |
80 | \sa setBackgroundBrush(), setBackgroundPen() |
|
80 | \sa setBackgroundBrush(), setBackgroundPen() | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \property QChart::dropShadowEnabled |
|
84 | \property QChart::dropShadowEnabled | |
85 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
85 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop | |
86 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
86 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | \property QChart::minimumMargins |
|
90 | \property QChart::minimumMargins | |
91 | Minimum margins between the plot area (axes) and the edge of the chart widget. |
|
91 | Minimum margins between the plot area (axes) and the edge of the chart widget. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \property QChart::margins |
|
95 | \property QChart::margins | |
96 | Minimum between the plot area (axes) and the edge of the chart widget. |
|
96 | Minimum between the plot area (axes) and the edge of the chart widget. | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | \property QChart::theme |
|
100 | \property QChart::theme | |
101 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
101 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, | |
102 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few |
|
102 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few | |
103 | different themes. |
|
103 | different themes. | |
104 | Note: changing the theme will overwrite all customizations previously applied to the series. |
|
104 | Note: changing the theme will overwrite all customizations previously applied to the series. | |
105 | */ |
|
105 | */ | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \property QChart::title |
|
108 | \property QChart::title | |
109 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. |
|
109 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
113 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
114 | */ |
|
114 | */ | |
115 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
115 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
116 | : QGraphicsWidget(parent, wFlags), |
|
116 | : QGraphicsWidget(parent, wFlags), | |
117 | d_ptr(new QChartPrivate(this)) |
|
117 | d_ptr(new QChartPrivate(this)) | |
118 | { |
|
118 | { | |
119 | d_ptr->m_legend = new LegendScroller(this); |
|
119 | d_ptr->m_legend = new LegendScroller(this); | |
120 | setTheme(QChart::ChartThemeLight); |
|
120 | setTheme(QChart::ChartThemeLight); | |
121 | //TODO: what is that ? |
|
121 | //TODO: what is that ? | |
122 | //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF))); |
|
122 | //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF))); | |
123 | setLayout(d_ptr->m_presenter->layout()); |
|
123 | setLayout(d_ptr->m_presenter->layout()); | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | /*! |
|
126 | /*! | |
127 | Destroys the object and it's children, like series and axis objects added to it. |
|
127 | Destroys the object and it's children, like series and axis objects added to it. | |
128 | */ |
|
128 | */ | |
129 | QChart::~QChart() |
|
129 | QChart::~QChart() | |
130 | { |
|
130 | { | |
131 | //start by deleting dataset, it will remove all series and axes |
|
131 | //start by deleting dataset, it will remove all series and axes | |
132 | delete d_ptr->m_dataset; |
|
132 | delete d_ptr->m_dataset; | |
133 | d_ptr->m_dataset = 0; |
|
133 | d_ptr->m_dataset = 0; | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | Adds the \a series onto the chart and takes the ownership of the object. |
|
137 | Adds the \a series onto the chart and takes the ownership of the object. | |
138 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
138 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
139 | the y axis). |
|
139 | the y axis). | |
140 |
|
140 | |||
141 | \sa removeSeries(), removeAllSeries() |
|
141 | \sa removeSeries(), removeAllSeries() | |
142 | */ |
|
142 | */ | |
143 | void QChart::addSeries(QAbstractSeries *series) |
|
143 | void QChart::addSeries(QAbstractSeries *series) | |
144 | { |
|
144 | { | |
145 | Q_ASSERT(series); |
|
145 | Q_ASSERT(series); | |
146 | d_ptr->m_dataset->addSeries(series); |
|
146 | d_ptr->m_dataset->addSeries(series); | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | Removes the \a series specified in a perameter from the QChartView. |
|
150 | Removes the \a series specified in a perameter from the QChartView. | |
151 | It releses its ownership of the specified QChartSeries object. |
|
151 | It releses its ownership of the specified QChartSeries object. | |
152 | It does not delete the pointed QChartSeries data object |
|
152 | It does not delete the pointed QChartSeries data object | |
153 | \sa addSeries(), removeAllSeries() |
|
153 | \sa addSeries(), removeAllSeries() | |
154 | */ |
|
154 | */ | |
155 | void QChart::removeSeries(QAbstractSeries *series) |
|
155 | void QChart::removeSeries(QAbstractSeries *series) | |
156 | { |
|
156 | { | |
157 | Q_ASSERT(series); |
|
157 | Q_ASSERT(series); | |
158 | d_ptr->m_dataset->removeSeries(series); |
|
158 | d_ptr->m_dataset->removeSeries(series); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | Removes all the QChartSeries that have been added to the QChartView |
|
162 | Removes all the QChartSeries that have been added to the QChartView | |
163 | It also deletes the pointed QChartSeries data objects |
|
163 | It also deletes the pointed QChartSeries data objects | |
164 | \sa addSeries(), removeSeries() |
|
164 | \sa addSeries(), removeSeries() | |
165 | */ |
|
165 | */ | |
166 | void QChart::removeAllSeries() |
|
166 | void QChart::removeAllSeries() | |
167 | { |
|
167 | { | |
168 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ |
|
168 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ | |
169 | removeSeries(s); |
|
169 | removeSeries(s); | |
170 | delete s; |
|
170 | delete s; | |
171 | } |
|
171 | } | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | /*! |
|
174 | /*! | |
175 | Sets the \a brush that is used for painting the background of the chart area. |
|
175 | Sets the \a brush that is used for painting the background of the chart area. | |
176 | */ |
|
176 | */ | |
177 | void QChart::setBackgroundBrush(const QBrush &brush) |
|
177 | void QChart::setBackgroundBrush(const QBrush &brush) | |
178 | { |
|
178 | { | |
179 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
179 | d_ptr->m_presenter->setBackgroundBrush(brush); | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | /*! |
|
182 | /*! | |
183 | Gets the brush that is used for painting the background of the chart area. |
|
183 | Gets the brush that is used for painting the background of the chart area. | |
184 | */ |
|
184 | */ | |
185 | QBrush QChart::backgroundBrush() const |
|
185 | QBrush QChart::backgroundBrush() const | |
186 | { |
|
186 | { | |
187 | return d_ptr->m_presenter->backgroundBrush(); |
|
187 | return d_ptr->m_presenter->backgroundBrush(); | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | /*! |
|
190 | /*! | |
191 | Sets the \a pen that is used for painting the background of the chart area. |
|
191 | Sets the \a pen that is used for painting the background of the chart area. | |
192 | */ |
|
192 | */ | |
193 | void QChart::setBackgroundPen(const QPen &pen) |
|
193 | void QChart::setBackgroundPen(const QPen &pen) | |
194 | { |
|
194 | { | |
195 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
195 | d_ptr->m_presenter->setBackgroundPen(pen); | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | /*! |
|
198 | /*! | |
199 | Gets the pen that is used for painting the background of the chart area. |
|
199 | Gets the pen that is used for painting the background of the chart area. | |
200 | */ |
|
200 | */ | |
201 | QPen QChart::backgroundPen() const |
|
201 | QPen QChart::backgroundPen() const | |
202 | { |
|
202 | { | |
203 | return d_ptr->m_presenter->backgroundPen(); |
|
203 | return d_ptr->m_presenter->backgroundPen(); | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | /*! |
|
206 | /*! | |
207 | Sets the chart \a title. The description text that is drawn above the chart. |
|
207 | Sets the chart \a title. The description text that is drawn above the chart. | |
208 | */ |
|
208 | */ | |
209 | void QChart::setTitle(const QString &title) |
|
209 | void QChart::setTitle(const QString &title) | |
210 | { |
|
210 | { | |
211 | d_ptr->m_presenter->setTitle(title); |
|
211 | d_ptr->m_presenter->setTitle(title); | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | /*! |
|
214 | /*! | |
215 | Returns the chart title. The description text that is drawn above the chart. |
|
215 | Returns the chart title. The description text that is drawn above the chart. | |
216 | */ |
|
216 | */ | |
217 | QString QChart::title() const |
|
217 | QString QChart::title() const | |
218 | { |
|
218 | { | |
219 | return d_ptr->m_presenter->title(); |
|
219 | return d_ptr->m_presenter->title(); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | /*! |
|
222 | /*! | |
223 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. |
|
223 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. | |
224 | */ |
|
224 | */ | |
225 | void QChart::setTitleFont(const QFont &font) |
|
225 | void QChart::setTitleFont(const QFont &font) | |
226 | { |
|
226 | { | |
227 | d_ptr->m_presenter->setTitleFont(font); |
|
227 | d_ptr->m_presenter->setTitleFont(font); | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | /*! |
|
230 | /*! | |
231 | Gets the font that is used for drawing the chart description text that is rendered above the chart. |
|
231 | Gets the font that is used for drawing the chart description text that is rendered above the chart. | |
232 | */ |
|
232 | */ | |
233 | QFont QChart::titleFont() const |
|
233 | QFont QChart::titleFont() const | |
234 | { |
|
234 | { | |
235 | return d_ptr->m_presenter->titleFont(); |
|
235 | return d_ptr->m_presenter->titleFont(); | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | /*! |
|
238 | /*! | |
239 | Sets the \a brush used for rendering the title text. |
|
239 | Sets the \a brush used for rendering the title text. | |
240 | */ |
|
240 | */ | |
241 | void QChart::setTitleBrush(const QBrush &brush) |
|
241 | void QChart::setTitleBrush(const QBrush &brush) | |
242 | { |
|
242 | { | |
243 | d_ptr->m_presenter->setTitleBrush(brush); |
|
243 | d_ptr->m_presenter->setTitleBrush(brush); | |
244 | } |
|
244 | } | |
245 |
|
245 | |||
246 | /*! |
|
246 | /*! | |
247 | Returns the brush used for rendering the title text. |
|
247 | Returns the brush used for rendering the title text. | |
248 | */ |
|
248 | */ | |
249 | QBrush QChart::titleBrush() const |
|
249 | QBrush QChart::titleBrush() const | |
250 | { |
|
250 | { | |
251 | return d_ptr->m_presenter->titleBrush(); |
|
251 | return d_ptr->m_presenter->titleBrush(); | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | void QChart::setTheme(QChart::ChartTheme theme) |
|
254 | void QChart::setTheme(QChart::ChartTheme theme) | |
255 | { |
|
255 | { | |
256 | d_ptr->m_themeManager->setTheme(theme); |
|
256 | d_ptr->m_themeManager->setTheme(theme); | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | QChart::ChartTheme QChart::theme() const |
|
259 | QChart::ChartTheme QChart::theme() const | |
260 | { |
|
260 | { | |
261 | return d_ptr->m_themeManager->theme()->id(); |
|
261 | return d_ptr->m_themeManager->theme()->id(); | |
262 | } |
|
262 | } | |
263 |
|
263 | |||
264 | /*! |
|
264 | /*! | |
265 | Zooms in the view by a factor of 2 |
|
265 | Zooms in the view by a factor of 2 | |
266 | */ |
|
266 | */ | |
267 | void QChart::zoomIn() |
|
267 | void QChart::zoomIn() | |
268 | { |
|
268 | { | |
269 | d_ptr->zoomIn(2.0); |
|
269 | d_ptr->zoomIn(2.0); | |
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 | /*! |
|
272 | /*! | |
273 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
273 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
274 | */ |
|
274 | */ | |
275 | void QChart::zoomIn(const QRectF &rect) |
|
275 | void QChart::zoomIn(const QRectF &rect) | |
276 | { |
|
276 | { | |
277 | d_ptr->zoomIn(rect); |
|
277 | d_ptr->zoomIn(rect); | |
278 | } |
|
278 | } | |
279 |
|
279 | |||
280 | /*! |
|
280 | /*! | |
281 | Restores the view zoom level to the previous one. |
|
281 | Restores the view zoom level to the previous one. | |
282 | */ |
|
282 | */ | |
283 | void QChart::zoomOut() |
|
283 | void QChart::zoomOut() | |
284 | { |
|
284 | { | |
285 | d_ptr->zoomOut(2.0); |
|
285 | d_ptr->zoomOut(2.0); | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | /*! |
|
288 | /*! | |
289 | Zooms in the view by a \a factor. |
|
289 | Zooms in the view by a \a factor. | |
290 |
|
290 | |||
291 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
291 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. | |
292 | */ |
|
292 | */ | |
293 | void QChart::zoom(qreal factor) |
|
293 | void QChart::zoom(qreal factor) | |
294 | { |
|
294 | { | |
295 | if (qFuzzyCompare(factor, 0)) |
|
295 | if (qFuzzyCompare(factor, 0)) | |
296 | return; |
|
296 | return; | |
297 |
|
297 | |||
298 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
298 | if (qFuzzyCompare(factor, (qreal)1.0)) | |
299 | return; |
|
299 | return; | |
300 |
|
300 | |||
301 | if (factor < 0) |
|
301 | if (factor < 0) | |
302 | return; |
|
302 | return; | |
303 |
|
303 | |||
304 | if (factor > 1.0) |
|
304 | if (factor > 1.0) | |
305 | d_ptr->zoomIn(factor); |
|
305 | d_ptr->zoomIn(factor); | |
306 | else |
|
306 | else | |
307 | d_ptr->zoomOut(1.0 / factor); |
|
307 | d_ptr->zoomOut(1.0 / factor); | |
308 | } |
|
308 | } | |
309 |
|
309 | |||
310 | /*! |
|
310 | /*! | |
311 | Returns the pointer to the x axis object of the chart asociated with the specified \a series |
|
311 | Returns the pointer to the x axis object of the chart asociated with the specified \a series | |
312 | If no series is provided then pointer to currently visible axis is provided |
|
312 | If no series is provided then pointer to currently visible axis is provided | |
313 | */ |
|
313 | */ | |
314 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const |
|
314 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const | |
315 | { |
|
315 | { | |
316 | if(!series && d_ptr->m_dataset->series().size()>0){ |
|
316 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); | |
317 | series = d_ptr->m_dataset->series().first(); |
|
317 | if (axisList.count()) | |
318 | } |
|
318 | return axisList[0]; | |
319 |
|
319 | return 0; | ||
320 | QList<QAbstractAxis*> axes = series->attachedAxes(); |
|
|||
321 | QAbstractAxis* bottom=0; |
|
|||
322 | QAbstractAxis* top=0; |
|
|||
323 |
|
||||
324 | foreach(QAbstractAxis* axis, axes){ |
|
|||
325 |
|
||||
326 | if(axis->alignment()==Qt::AlignTop){ |
|
|||
327 | top=axis; |
|
|||
328 | } |
|
|||
329 |
|
||||
330 | if(axis->alignment()==Qt::AlignBottom){ |
|
|||
331 | bottom=axis; |
|
|||
332 | } |
|
|||
333 | } |
|
|||
334 | return bottom?bottom:top; |
|
|||
335 | } |
|
320 | } | |
336 |
|
321 | |||
337 | /*! |
|
322 | /*! | |
338 | Returns the pointer to the y axis object of the chart asociated with the specified \a series |
|
323 | Returns the pointer to the y axis object of the chart asociated with the specified \a series | |
339 | If no series is provided then pointer to currently visible axis is provided |
|
324 | If no series is provided then pointer to currently visible axis is provided | |
340 | */ |
|
325 | */ | |
341 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const |
|
326 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const | |
342 | { |
|
327 | { | |
343 | if(!series && d_ptr->m_dataset->series().size()>0) { |
|
328 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); | |
344 | series = d_ptr->m_dataset->series().first(); |
|
329 | if (axisList.count()) | |
345 | } |
|
330 | return axisList[0]; | |
346 |
|
331 | return 0; | ||
347 | QList<QAbstractAxis*> axes = series->attachedAxes(); |
|
|||
348 |
|
||||
349 | QAbstractAxis* left=0; |
|
|||
350 | QAbstractAxis* right=0; |
|
|||
351 |
|
||||
352 | foreach(QAbstractAxis* axis, axes){ |
|
|||
353 |
|
||||
354 | if(axis->alignment()==Qt::AlignLeft){ |
|
|||
355 | left=axis; |
|
|||
356 | } |
|
|||
357 |
|
||||
358 | if(axis->alignment()==Qt::AlignRight){ |
|
|||
359 | right=axis; |
|
|||
360 | } |
|
|||
361 | } |
|
|||
362 |
|
||||
363 | return left?left:right; |
|
|||
364 | } |
|
332 | } | |
365 |
|
333 | |||
366 | /*! |
|
334 | /*! | |
367 | Returns the axes added for the \a series with \a orientation |
|
335 | Returns the axes added for the \a series with \a orientation. If no series is provided, then all axes with the | |
|
336 | specified orientation are returned. | |||
368 | \sa addAxis(), createDefaultAxes() |
|
337 | \sa addAxis(), createDefaultAxes() | |
369 | */ |
|
338 | */ | |
370 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const |
|
339 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const | |
371 | { |
|
340 | { | |
372 | QList<QAbstractAxis *> result ; |
|
341 | QList<QAbstractAxis *> result ; | |
373 |
|
342 | |||
374 | if (series) { |
|
343 | if (series) { | |
375 | foreach (QAbstractAxis *axis, series->attachedAxes()){ |
|
344 | foreach (QAbstractAxis *axis, series->attachedAxes()){ | |
376 | if (orientation.testFlag(axis->orientation())) |
|
345 | if (orientation.testFlag(axis->orientation())) | |
377 | result << axis; |
|
346 | result << axis; | |
378 | } |
|
347 | } | |
379 | } else { |
|
348 | } else { | |
380 |
foreach (QAbstract |
|
349 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ | |
381 | foreach (QAbstractAxis *axis, s->attachedAxes()){ |
|
350 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) | |
382 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) |
|
351 | result << axis; | |
383 | result << axis; |
|
|||
384 | } |
|
|||
385 | } |
|
352 | } | |
386 | } |
|
353 | } | |
387 |
|
354 | |||
388 | return result; |
|
355 | return result; | |
389 | } |
|
356 | } | |
390 |
|
357 | |||
391 | /*! |
|
358 | /*! | |
392 | NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL. |
|
359 | NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL. | |
393 |
|
360 | |||
394 | Creates the axes for the chart based on the series that has already been added to the chart. |
|
361 | Creates the axes for the chart based on the series that has already been added to the chart. | |
395 |
|
362 | |||
396 | \table |
|
363 | \table | |
397 | \header |
|
364 | \header | |
398 | \o Series type |
|
365 | \o Series type | |
399 | \o X-axis |
|
366 | \o X-axis | |
400 | \o Y-axis |
|
367 | \o Y-axis | |
401 | \row |
|
368 | \row | |
402 | \o QXYSeries |
|
369 | \o QXYSeries | |
403 | \o QValueAxis |
|
370 | \o QValueAxis | |
404 | \o QValueAxis |
|
371 | \o QValueAxis | |
405 | \row |
|
372 | \row | |
406 | \o QBarSeries |
|
373 | \o QBarSeries | |
407 | \o QBarCategoryAxis |
|
374 | \o QBarCategoryAxis | |
408 | \o QValueAxis |
|
375 | \o QValueAxis | |
409 | \row |
|
376 | \row | |
410 | \o QPieSeries |
|
377 | \o QPieSeries | |
411 | \o None |
|
378 | \o None | |
412 | \o None |
|
379 | \o None | |
413 | \endtable |
|
380 | \endtable | |
414 |
|
381 | |||
415 | If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created. |
|
382 | If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created. | |
416 | If there are sevaral series added of different types then each series gets its own axes pair. |
|
383 | If there are sevaral series added of different types then each series gets its own axes pair. | |
417 |
|
384 | |||
418 | NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown. |
|
385 | NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown. | |
419 |
|
386 | |||
420 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. |
|
387 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. | |
421 | QPieSeries does not create any axes. |
|
388 | QPieSeries does not create any axes. | |
422 |
|
389 | |||
423 | \sa axisX(), axisY(), setAxisX(), setAxisY() |
|
390 | \sa axisX(), axisY(), setAxisX(), setAxisY() | |
424 | */ |
|
391 | */ | |
425 | void QChart::createDefaultAxes() |
|
392 | void QChart::createDefaultAxes() | |
426 | { |
|
393 | { | |
427 | d_ptr->m_dataset->createDefaultAxes(); |
|
394 | d_ptr->m_dataset->createDefaultAxes(); | |
428 | } |
|
395 | } | |
429 |
|
396 | |||
430 | /*! |
|
397 | /*! | |
431 | Returns the legend object of the chart. Ownership stays in chart. |
|
398 | Returns the legend object of the chart. Ownership stays in chart. | |
432 | */ |
|
399 | */ | |
433 | QLegend *QChart::legend() const |
|
400 | QLegend *QChart::legend() const | |
434 | { |
|
401 | { | |
435 | return d_ptr->m_legend; |
|
402 | return d_ptr->m_legend; | |
436 | } |
|
403 | } | |
437 |
|
404 | |||
438 | /*! |
|
405 | /*! | |
439 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
406 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. | |
440 | Deprecated. Use setMargins(). |
|
407 | Deprecated. Use setMargins(). | |
441 | */ |
|
408 | */ | |
442 | void QChart::setMinimumMargins(const QMargins &margins) |
|
409 | void QChart::setMinimumMargins(const QMargins &margins) | |
443 | { |
|
410 | { | |
444 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; |
|
411 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; | |
445 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
412 | d_ptr->m_presenter->layout()->setMargins(margins); | |
446 | } |
|
413 | } | |
447 |
|
414 | |||
448 | /*! |
|
415 | /*! | |
449 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
416 | Returns the rect that contains information about margins (distance between chart widget edge and axes). | |
450 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
417 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. | |
451 | Deprecated. Use margins(). |
|
418 | Deprecated. Use margins(). | |
452 | */ |
|
419 | */ | |
453 | QMargins QChart::minimumMargins() const |
|
420 | QMargins QChart::minimumMargins() const | |
454 | { |
|
421 | { | |
455 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; |
|
422 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; | |
456 | return d_ptr->m_presenter->layout()->margins(); |
|
423 | return d_ptr->m_presenter->layout()->margins(); | |
457 | } |
|
424 | } | |
458 |
|
425 | |||
459 | /*! |
|
426 | /*! | |
460 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
427 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. | |
461 | */ |
|
428 | */ | |
462 | void QChart::setMargins(const QMargins &margins) |
|
429 | void QChart::setMargins(const QMargins &margins) | |
463 | { |
|
430 | { | |
464 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
431 | d_ptr->m_presenter->layout()->setMargins(margins); | |
465 | } |
|
432 | } | |
466 |
|
433 | |||
467 | /*! |
|
434 | /*! | |
468 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
435 | Returns the rect that contains information about margins (distance between chart widget edge and axes). | |
469 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
436 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. | |
470 | */ |
|
437 | */ | |
471 | QMargins QChart::margins() const |
|
438 | QMargins QChart::margins() const | |
472 | { |
|
439 | { | |
473 | return d_ptr->m_presenter->layout()->margins(); |
|
440 | return d_ptr->m_presenter->layout()->margins(); | |
474 | } |
|
441 | } | |
475 |
|
442 | |||
476 | /*! |
|
443 | /*! | |
477 | Returns the the rect within which the drawing of the chart is done. |
|
444 | Returns the the rect within which the drawing of the chart is done. | |
478 | It does not include the area defines by margins. |
|
445 | It does not include the area defines by margins. | |
479 | */ |
|
446 | */ | |
480 | QRectF QChart::plotArea() const |
|
447 | QRectF QChart::plotArea() const | |
481 | { |
|
448 | { | |
482 | return d_ptr->m_presenter->geometry(); |
|
449 | return d_ptr->m_presenter->geometry(); | |
483 | } |
|
450 | } | |
484 |
|
451 | |||
485 | ///*! |
|
452 | ///*! | |
486 | // TODO: Dummy. |
|
453 | // TODO: Dummy. | |
487 | // Adjest the ranges of the axes so that all the data of the specified \a series is visible |
|
454 | // Adjest the ranges of the axes so that all the data of the specified \a series is visible | |
488 | // */ |
|
455 | // */ | |
489 | //void QChart::adjustViewToSeries(QAbstractSeries* series) |
|
456 | //void QChart::adjustViewToSeries(QAbstractSeries* series) | |
490 | //{ |
|
457 | //{ | |
491 | // // |
|
458 | // // | |
492 | //} |
|
459 | //} | |
493 |
|
460 | |||
494 | /*! |
|
461 | /*! | |
495 | Sets animation \a options for the chart |
|
462 | Sets animation \a options for the chart | |
496 | */ |
|
463 | */ | |
497 | void QChart::setAnimationOptions(AnimationOptions options) |
|
464 | void QChart::setAnimationOptions(AnimationOptions options) | |
498 | { |
|
465 | { | |
499 | d_ptr->m_presenter->setAnimationOptions(options); |
|
466 | d_ptr->m_presenter->setAnimationOptions(options); | |
500 | } |
|
467 | } | |
501 |
|
468 | |||
502 | QChart::AnimationOptions QChart::animationOptions() const |
|
469 | QChart::AnimationOptions QChart::animationOptions() const | |
503 | { |
|
470 | { | |
504 | return d_ptr->m_presenter->animationOptions(); |
|
471 | return d_ptr->m_presenter->animationOptions(); | |
505 | } |
|
472 | } | |
506 |
|
473 | |||
507 | /*! |
|
474 | /*! | |
508 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
475 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. | |
509 | */ |
|
476 | */ | |
510 | void QChart::scroll(qreal dx, qreal dy) |
|
477 | void QChart::scroll(qreal dx, qreal dy) | |
511 | { |
|
478 | { | |
512 | d_ptr->scroll(dx,dy); |
|
479 | d_ptr->scroll(dx,dy); | |
513 | } |
|
480 | } | |
514 |
|
481 | |||
515 | void QChart::setBackgroundVisible(bool visible) |
|
482 | void QChart::setBackgroundVisible(bool visible) | |
516 | { |
|
483 | { | |
517 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
484 | d_ptr->m_presenter->setBackgroundVisible(visible); | |
518 | } |
|
485 | } | |
519 |
|
486 | |||
520 | bool QChart::isBackgroundVisible() const |
|
487 | bool QChart::isBackgroundVisible() const | |
521 | { |
|
488 | { | |
522 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
489 | return d_ptr->m_presenter->isBackgroundVisible(); | |
523 | } |
|
490 | } | |
524 |
|
491 | |||
525 | void QChart::setDropShadowEnabled(bool enabled) |
|
492 | void QChart::setDropShadowEnabled(bool enabled) | |
526 | { |
|
493 | { | |
527 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
494 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); | |
528 | } |
|
495 | } | |
529 |
|
496 | |||
530 | bool QChart::isDropShadowEnabled() const |
|
497 | bool QChart::isDropShadowEnabled() const | |
531 | { |
|
498 | { | |
532 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
499 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); | |
533 | } |
|
500 | } | |
534 |
|
501 | |||
535 | /*! |
|
502 | /*! | |
536 | Returns all the series that are added to the chart. |
|
503 | Returns all the series that are added to the chart. | |
537 |
|
504 | |||
538 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
505 | \sa addSeries(), removeSeries(), removeAllSeries() | |
539 | */ |
|
506 | */ | |
540 | QList<QAbstractSeries *> QChart::series() const |
|
507 | QList<QAbstractSeries *> QChart::series() const | |
541 | { |
|
508 | { | |
542 | return d_ptr->m_dataset->series(); |
|
509 | return d_ptr->m_dataset->series(); | |
543 | } |
|
510 | } | |
544 |
|
511 | |||
545 | /*! |
|
512 | /*! | |
546 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
513 | Sets \a axis to the chart, which will control the presentation of the \a series | |
547 |
|
514 | |||
548 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() |
|
515 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() | |
549 | */ |
|
516 | */ | |
550 | void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series) |
|
517 | void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series) | |
551 | { |
|
518 | { | |
552 | QList<QAbstractAxis*> list = axes(Qt::Horizontal,series); |
|
519 | QList<QAbstractAxis*> list = axes(Qt::Horizontal,series); | |
553 |
|
520 | |||
554 | foreach(QAbstractAxis* a, list){ |
|
521 | foreach(QAbstractAxis* a, list){ | |
555 | d_ptr->m_dataset->removeAxis(a); |
|
522 | d_ptr->m_dataset->removeAxis(a); | |
556 | delete a; |
|
523 | delete a; | |
557 | } |
|
524 | } | |
558 |
|
525 | |||
559 | if(!d_ptr->m_dataset->axes().contains(axis)) |
|
526 | if(!d_ptr->m_dataset->axes().contains(axis)) | |
560 | d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom); |
|
527 | d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom); | |
561 | d_ptr->m_dataset->attachAxis(series,axis); |
|
528 | d_ptr->m_dataset->attachAxis(series,axis); | |
562 | } |
|
529 | } | |
563 |
|
530 | |||
564 | /*! |
|
531 | /*! | |
565 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
532 | Sets \a axis to the chart, which will control the presentation of the \a series | |
566 |
|
533 | |||
567 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() |
|
534 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() | |
568 | */ |
|
535 | */ | |
569 | void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series) |
|
536 | void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series) | |
570 | { |
|
537 | { | |
571 | QList<QAbstractAxis*> list = axes(Qt::Vertical,series); |
|
538 | QList<QAbstractAxis*> list = axes(Qt::Vertical,series); | |
572 |
|
539 | |||
573 | foreach(QAbstractAxis* a, list) { |
|
540 | foreach(QAbstractAxis* a, list) { | |
574 | d_ptr->m_dataset->removeAxis(a); |
|
541 | d_ptr->m_dataset->removeAxis(a); | |
575 | delete a; |
|
542 | delete a; | |
576 | } |
|
543 | } | |
577 |
|
544 | |||
578 | if(!d_ptr->m_dataset->axes().contains(axis)) |
|
545 | if(!d_ptr->m_dataset->axes().contains(axis)) | |
579 | d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft); |
|
546 | d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft); | |
580 | d_ptr->m_dataset->attachAxis(series,axis); |
|
547 | d_ptr->m_dataset->attachAxis(series,axis); | |
581 | } |
|
548 | } | |
582 |
|
549 | |||
583 | /*! |
|
550 | /*! | |
584 | Adds \a axis to the chart with \a alignment. The chart takes the ownership of the axis. |
|
551 | Adds \a axis to the chart with \a alignment. The chart takes the ownership of the axis. | |
585 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
552 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
586 | */ |
|
553 | */ | |
587 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) |
|
554 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) | |
588 | { |
|
555 | { | |
589 | d_ptr->m_dataset->addAxis(axis, alignment); |
|
556 | d_ptr->m_dataset->addAxis(axis, alignment); | |
590 | } |
|
557 | } | |
591 |
|
558 | |||
592 | /*! |
|
559 | /*! | |
593 | Removes \a axis from the chart. The ownership is returned to the caller. |
|
560 | Removes \a axis from the chart. The ownership is returned to the caller. | |
594 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() |
|
561 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() | |
595 | */ |
|
562 | */ | |
596 | void QChart::removeAxis(QAbstractAxis *axis) |
|
563 | void QChart::removeAxis(QAbstractAxis *axis) | |
597 | { |
|
564 | { | |
598 | d_ptr->m_dataset->removeAxis(axis); |
|
565 | d_ptr->m_dataset->removeAxis(axis); | |
599 | } |
|
566 | } | |
600 |
|
567 | |||
601 | /*! |
|
568 | /*! | |
602 | Returns the value in the \a series domain that coresponds to the charts widget point defines by \a position. |
|
569 | Returns the value in the \a series domain that coresponds to the charts widget point defines by \a position. | |
603 | */ |
|
570 | */ | |
604 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
571 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) | |
605 | { |
|
572 | { | |
606 | return d_ptr->m_dataset->mapToValue(position, series); |
|
573 | return d_ptr->m_dataset->mapToValue(position, series); | |
607 | } |
|
574 | } | |
608 |
|
575 | |||
609 | /*! |
|
576 | /*! | |
610 | Returns the position on the charts widget that coresponds to the \a value in the \a series domain. |
|
577 | Returns the position on the charts widget that coresponds to the \a value in the \a series domain. | |
611 | */ |
|
578 | */ | |
612 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
579 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) | |
613 | { |
|
580 | { | |
614 | return d_ptr->m_dataset->mapToPosition(value, series); |
|
581 | return d_ptr->m_dataset->mapToPosition(value, series); | |
615 | } |
|
582 | } | |
616 |
|
583 | |||
617 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
584 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
618 |
|
585 | |||
619 | QChartPrivate::QChartPrivate(QChart *q): |
|
586 | QChartPrivate::QChartPrivate(QChart *q): | |
620 | q_ptr(q), |
|
587 | q_ptr(q), | |
621 | m_legend(0), |
|
588 | m_legend(0), | |
622 | m_dataset(new ChartDataSet(q)), |
|
589 | m_dataset(new ChartDataSet(q)), | |
623 | m_presenter(new ChartPresenter(q)), |
|
590 | m_presenter(new ChartPresenter(q)), | |
624 | m_themeManager(new ChartThemeManager(q)) |
|
591 | m_themeManager(new ChartThemeManager(q)) | |
625 | { |
|
592 | { | |
626 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
593 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
627 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
594 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
628 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
595 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); | |
629 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
596 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
630 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
597 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
631 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
598 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
632 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
599 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); | |
633 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
600 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
634 | } |
|
601 | } | |
635 |
|
602 | |||
636 | QChartPrivate::~QChartPrivate() |
|
603 | QChartPrivate::~QChartPrivate() | |
637 | { |
|
604 | { | |
638 |
|
605 | |||
639 | } |
|
606 | } | |
640 |
|
607 | |||
641 | void QChartPrivate::zoomIn(qreal factor) |
|
608 | void QChartPrivate::zoomIn(qreal factor) | |
642 | { |
|
609 | { | |
643 | QRectF rect = m_presenter->geometry(); |
|
610 | QRectF rect = m_presenter->geometry(); | |
644 | rect.setWidth(rect.width() / factor); |
|
611 | rect.setWidth(rect.width() / factor); | |
645 | rect.setHeight(rect.height() / factor); |
|
612 | rect.setHeight(rect.height() / factor); | |
646 | rect.moveCenter(m_presenter->geometry().center()); |
|
613 | rect.moveCenter(m_presenter->geometry().center()); | |
647 | zoomIn(rect); |
|
614 | zoomIn(rect); | |
648 | } |
|
615 | } | |
649 |
|
616 | |||
650 | void QChartPrivate::zoomIn(const QRectF &rect) |
|
617 | void QChartPrivate::zoomIn(const QRectF &rect) | |
651 | { |
|
618 | { | |
652 | if (!rect.isValid()) |
|
619 | if (!rect.isValid()) | |
653 | return; |
|
620 | return; | |
654 |
|
621 | |||
655 | QRectF r = rect.normalized(); |
|
622 | QRectF r = rect.normalized(); | |
656 | const QRectF geometry = m_presenter->geometry(); |
|
623 | const QRectF geometry = m_presenter->geometry(); | |
657 | r.translate(-geometry.topLeft()); |
|
624 | r.translate(-geometry.topLeft()); | |
658 |
|
625 | |||
659 | if (!r.isValid()) |
|
626 | if (!r.isValid()) | |
660 | return; |
|
627 | return; | |
661 |
|
628 | |||
662 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
629 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |
663 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); |
|
630 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); | |
664 | m_dataset->zoomInDomain(r); |
|
631 | m_dataset->zoomInDomain(r); | |
665 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
632 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
666 |
|
633 | |||
667 | } |
|
634 | } | |
668 |
|
635 | |||
669 | void QChartPrivate::zoomOut(qreal factor) |
|
636 | void QChartPrivate::zoomOut(qreal factor) | |
670 | { |
|
637 | { | |
671 | const QRectF geometry = m_presenter->geometry(); |
|
638 | const QRectF geometry = m_presenter->geometry(); | |
672 |
|
639 | |||
673 | QRectF r; |
|
640 | QRectF r; | |
674 | r.setSize(geometry.size() / factor); |
|
641 | r.setSize(geometry.size() / factor); | |
675 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); |
|
642 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); | |
676 | if (!r.isValid()) |
|
643 | if (!r.isValid()) | |
677 | return; |
|
644 | return; | |
678 |
|
645 | |||
679 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
646 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |
680 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); |
|
647 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); | |
681 | m_dataset->zoomOutDomain(r); |
|
648 | m_dataset->zoomOutDomain(r); | |
682 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
649 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
683 | } |
|
650 | } | |
684 |
|
651 | |||
685 | void QChartPrivate::scroll(qreal dx, qreal dy) |
|
652 | void QChartPrivate::scroll(qreal dx, qreal dy) | |
686 | { |
|
653 | { | |
687 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); |
|
654 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); | |
688 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); |
|
655 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); | |
689 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); |
|
656 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); | |
690 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); |
|
657 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); | |
691 |
|
658 | |||
692 | m_dataset->scrollDomain(dx, dy); |
|
659 | m_dataset->scrollDomain(dx, dy); | |
693 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
660 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
694 | } |
|
661 | } | |
695 |
|
662 | |||
696 | #include "moc_qchart.cpp" |
|
663 | #include "moc_qchart.cpp" | |
697 |
|
664 | |||
698 | QTCOMMERCIALCHART_END_NAMESPACE |
|
665 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,402 +1,403 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 | #ifndef BUILD_PRIVATE_UNIT_TESTS |
|
20 | #ifndef BUILD_PRIVATE_UNIT_TESTS | |
21 | #include <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 |
|
22 | |||
23 | class tst_ChartDataSet: public QObject { |
|
23 | class tst_ChartDataSet: public QObject { | |
24 |
|
24 | |||
25 | Q_OBJECT |
|
25 | Q_OBJECT | |
26 |
|
26 | |||
27 | private Q_SLOTS: |
|
27 | private Q_SLOTS: | |
28 | void skip(); |
|
28 | void skip(); | |
29 |
|
29 | |||
30 | }; |
|
30 | }; | |
31 |
|
31 | |||
32 | void tst_ChartDataSet::skip() |
|
32 | void tst_ChartDataSet::skip() | |
33 | { |
|
33 | { | |
34 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
|
34 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) | |
35 | QSKIP("This test requires the debug version of library"); |
|
35 | QSKIP("This test requires the debug version of library"); | |
36 | #else |
|
36 | #else | |
37 | QSKIP("This test requires the debug version of library", SkipAll); |
|
37 | QSKIP("This test requires the debug version of library", SkipAll); | |
38 | #endif |
|
38 | #endif | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | QTEST_MAIN(tst_ChartDataSet) |
|
41 | QTEST_MAIN(tst_ChartDataSet) | |
42 | #include "tst_chartdataset.moc" |
|
42 | #include "tst_chartdataset.moc" | |
43 |
|
43 | |||
44 | #else |
|
44 | #else | |
45 |
|
45 | |||
46 | #include <QtTest/QtTest> |
|
46 | #include <QtTest/QtTest> | |
47 | #include <qabstractaxis.h> |
|
47 | #include <qabstractaxis.h> | |
48 | #include <qvalueaxis.h> |
|
48 | #include <qvalueaxis.h> | |
49 | #include <qbarcategoryaxis.h> |
|
49 | #include <qbarcategoryaxis.h> | |
50 | #include <qcategoryaxis.h> |
|
50 | #include <qcategoryaxis.h> | |
51 | #include <qdatetimeaxis.h> |
|
51 | #include <qdatetimeaxis.h> | |
52 | #include <qlineseries.h> |
|
52 | #include <qlineseries.h> | |
53 | #include <qareaseries.h> |
|
53 | #include <qareaseries.h> | |
54 | #include <qscatterseries.h> |
|
54 | #include <qscatterseries.h> | |
55 | #include <qsplineseries.h> |
|
55 | #include <qsplineseries.h> | |
56 | #include <qpieseries.h> |
|
56 | #include <qpieseries.h> | |
57 | #include <qbarseries.h> |
|
57 | #include <qbarseries.h> | |
58 | #include <qpercentbarseries.h> |
|
58 | #include <qpercentbarseries.h> | |
59 | #include <qstackedbarseries.h> |
|
59 | #include <qstackedbarseries.h> | |
60 | #include <private/chartdataset_p.h> |
|
60 | #include <private/chartdataset_p.h> | |
61 | #include <private/abstractdomain_p.h> |
|
61 | #include <private/abstractdomain_p.h> | |
62 | #include <tst_definitions.h> |
|
62 | #include <tst_definitions.h> | |
63 |
|
63 | |||
64 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
64 | QTCOMMERCIALCHART_USE_NAMESPACE | |
65 |
|
65 | |||
66 | Q_DECLARE_METATYPE(AbstractDomain *) |
|
66 | Q_DECLARE_METATYPE(AbstractDomain *) | |
67 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
67 | Q_DECLARE_METATYPE(QAbstractAxis *) | |
68 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
68 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
69 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) |
|
69 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) | |
70 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) |
|
70 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) | |
71 | Q_DECLARE_METATYPE(Qt::Alignment) |
|
71 | Q_DECLARE_METATYPE(Qt::Alignment) | |
72 | Q_DECLARE_METATYPE(QList<Qt::Alignment>) |
|
72 | Q_DECLARE_METATYPE(QList<Qt::Alignment>) | |
73 | Q_DECLARE_METATYPE(QLineSeries *) |
|
73 | Q_DECLARE_METATYPE(QLineSeries *) | |
74 |
|
74 | |||
75 | class tst_ChartDataSet: public QObject { |
|
75 | class tst_ChartDataSet: public QObject { | |
76 |
|
76 | |||
77 | Q_OBJECT |
|
77 | Q_OBJECT | |
78 | public: |
|
78 | public: | |
79 | tst_ChartDataSet():m_dataset(0){}; |
|
79 | tst_ChartDataSet():m_dataset(0){}; | |
80 |
|
80 | |||
81 | public Q_SLOTS: |
|
81 | public Q_SLOTS: | |
82 | void initTestCase(); |
|
82 | void initTestCase(); | |
83 | void cleanupTestCase(); |
|
83 | void cleanupTestCase(); | |
84 | void init(); |
|
84 | void init(); | |
85 | void cleanup(); |
|
85 | void cleanup(); | |
86 |
|
86 | |||
87 | private Q_SLOTS: |
|
87 | private Q_SLOTS: | |
88 | void chartdataset_data(); |
|
88 | void chartdataset_data(); | |
89 | void chartdataset(); |
|
89 | void chartdataset(); | |
90 | void addSeries_data(); |
|
90 | void addSeries_data(); | |
91 | void addSeries(); |
|
91 | void addSeries(); | |
92 | void removeSeries_data(); |
|
92 | void removeSeries_data(); | |
93 | void removeSeries(); |
|
93 | void removeSeries(); | |
94 | void addAxis_data(); |
|
94 | void addAxis_data(); | |
95 | void addAxis(); |
|
95 | void addAxis(); | |
96 | void removeAxis_data(); |
|
96 | void removeAxis_data(); | |
97 | void removeAxis(); |
|
97 | void removeAxis(); | |
98 | void attachAxis_data(); |
|
98 | void attachAxis_data(); | |
99 | void attachAxis(); |
|
99 | void attachAxis(); | |
100 | void detachAxis_data(); |
|
100 | void detachAxis_data(); | |
101 | void detachAxis(); |
|
101 | void detachAxis(); | |
102 |
|
102 | |||
103 | private: |
|
103 | private: | |
104 | ChartDataSet* m_dataset; |
|
104 | ChartDataSet* m_dataset; | |
105 | }; |
|
105 | }; | |
106 |
|
106 | |||
107 | void tst_ChartDataSet::initTestCase() |
|
107 | void tst_ChartDataSet::initTestCase() | |
108 | { |
|
108 | { | |
109 | qRegisterMetaType<AbstractDomain*>(); |
|
109 | qRegisterMetaType<AbstractDomain*>(); | |
110 | qRegisterMetaType<QAbstractAxis*>(); |
|
110 | qRegisterMetaType<QAbstractAxis*>(); | |
111 | qRegisterMetaType<QAbstractSeries*>(); |
|
111 | qRegisterMetaType<QAbstractSeries*>(); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | void tst_ChartDataSet::cleanupTestCase() |
|
114 | void tst_ChartDataSet::cleanupTestCase() | |
115 | { |
|
115 | { | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | void tst_ChartDataSet::init() |
|
118 | void tst_ChartDataSet::init() | |
119 | { |
|
119 | { | |
120 | Q_ASSERT(!m_dataset); |
|
120 | Q_ASSERT(!m_dataset); | |
121 | m_dataset = new ChartDataSet(0); |
|
121 | m_dataset = new ChartDataSet(0); | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 |
|
124 | |||
125 | void tst_ChartDataSet::cleanup() |
|
125 | void tst_ChartDataSet::cleanup() | |
126 | { |
|
126 | { | |
127 | delete m_dataset; |
|
127 | delete m_dataset; | |
128 | m_dataset=0; |
|
128 | m_dataset=0; | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | void tst_ChartDataSet::chartdataset_data() |
|
131 | void tst_ChartDataSet::chartdataset_data() | |
132 | { |
|
132 | { | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | void tst_ChartDataSet::chartdataset() |
|
135 | void tst_ChartDataSet::chartdataset() | |
136 | { |
|
136 | { | |
137 | QVERIFY(m_dataset->axes().isEmpty()); |
|
137 | QVERIFY(m_dataset->axes().isEmpty()); | |
138 | QVERIFY(m_dataset->series().isEmpty()); |
|
138 | QVERIFY(m_dataset->series().isEmpty()); | |
139 | m_dataset->createDefaultAxes(); |
|
139 | m_dataset->createDefaultAxes(); | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 |
|
142 | |||
143 | void tst_ChartDataSet::addSeries_data() |
|
143 | void tst_ChartDataSet::addSeries_data() | |
144 | { |
|
144 | { | |
145 | QTest::addColumn<QAbstractSeries*>("series"); |
|
145 | QTest::addColumn<QAbstractSeries*>("series"); | |
146 |
|
146 | |||
147 | QAbstractSeries* line = new QLineSeries(this); |
|
147 | QAbstractSeries* line = new QLineSeries(this); | |
148 | QTest::newRow("line") << line; |
|
148 | QTest::newRow("line") << line; | |
149 |
|
149 | |||
150 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(new QLineSeries(this))); |
|
150 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(new QLineSeries(this))); | |
151 | QTest::newRow("area") << area; |
|
151 | QTest::newRow("area") << area; | |
152 |
|
152 | |||
153 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
153 | QAbstractSeries* scatter = new QScatterSeries(this); | |
154 | QTest::newRow("scatter") << scatter; |
|
154 | QTest::newRow("scatter") << scatter; | |
155 |
|
155 | |||
156 | QAbstractSeries* spline = new QSplineSeries(this); |
|
156 | QAbstractSeries* spline = new QSplineSeries(this); | |
157 | QTest::newRow("spline") << spline; |
|
157 | QTest::newRow("spline") << spline; | |
158 |
|
158 | |||
159 | QAbstractSeries* pie = new QPieSeries(this); |
|
159 | QAbstractSeries* pie = new QPieSeries(this); | |
160 | QTest::newRow("pie") << pie; |
|
160 | QTest::newRow("pie") << pie; | |
161 |
|
161 | |||
162 | QAbstractSeries* bar = new QBarSeries(this); |
|
162 | QAbstractSeries* bar = new QBarSeries(this); | |
163 | QTest::newRow("bar") << bar; |
|
163 | QTest::newRow("bar") << bar; | |
164 |
|
164 | |||
165 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
165 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
166 | QTest::newRow("percent") << percent; |
|
166 | QTest::newRow("percent") << percent; | |
167 |
|
167 | |||
168 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
168 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
169 | QTest::newRow("stacked") << stacked; |
|
169 | QTest::newRow("stacked") << stacked; | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | void tst_ChartDataSet::addSeries() |
|
172 | void tst_ChartDataSet::addSeries() | |
173 | { |
|
173 | { | |
174 | QFETCH(QAbstractSeries*, series); |
|
174 | QFETCH(QAbstractSeries*, series); | |
175 | QVERIFY(m_dataset->series().isEmpty()); |
|
175 | QVERIFY(m_dataset->series().isEmpty()); | |
176 |
|
176 | |||
177 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
177 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
178 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
178 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
179 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
179 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
180 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
180 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
181 |
|
181 | |||
182 | m_dataset->addSeries(series); |
|
182 | m_dataset->addSeries(series); | |
183 |
|
183 | |||
184 | QCOMPARE(m_dataset->series().count(),1); |
|
184 | QCOMPARE(m_dataset->series().count(),1); | |
185 | TRY_COMPARE(spy0.count(), 0); |
|
185 | TRY_COMPARE(spy0.count(), 0); | |
186 | TRY_COMPARE(spy1.count(), 0); |
|
186 | TRY_COMPARE(spy1.count(), 0); | |
187 | TRY_COMPARE(spy2.count(), 1); |
|
187 | TRY_COMPARE(spy2.count(), 1); | |
188 | TRY_COMPARE(spy3.count(), 0); |
|
188 | TRY_COMPARE(spy3.count(), 0); | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | void tst_ChartDataSet::removeSeries_data() |
|
191 | void tst_ChartDataSet::removeSeries_data() | |
192 | { |
|
192 | { | |
193 | addSeries_data(); |
|
193 | addSeries_data(); | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | void tst_ChartDataSet::removeSeries() |
|
196 | void tst_ChartDataSet::removeSeries() | |
197 | { |
|
197 | { | |
198 | QFETCH(QAbstractSeries*, series); |
|
198 | QFETCH(QAbstractSeries*, series); | |
199 | QVERIFY(m_dataset->series().isEmpty()); |
|
199 | QVERIFY(m_dataset->series().isEmpty()); | |
200 | m_dataset->addSeries(series); |
|
200 | m_dataset->addSeries(series); | |
201 |
|
201 | |||
202 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
202 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
203 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
203 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
204 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
204 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
205 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
205 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
206 |
|
206 | |||
207 | m_dataset->removeSeries(series); |
|
207 | m_dataset->removeSeries(series); | |
208 |
|
208 | |||
209 | QCOMPARE(m_dataset->series().count(),0); |
|
209 | QCOMPARE(m_dataset->series().count(),0); | |
210 | TRY_COMPARE(spy0.count(), 0); |
|
210 | TRY_COMPARE(spy0.count(), 0); | |
211 | TRY_COMPARE(spy1.count(), 0); |
|
211 | TRY_COMPARE(spy1.count(), 0); | |
212 | TRY_COMPARE(spy2.count(), 0); |
|
212 | TRY_COMPARE(spy2.count(), 0); | |
213 | TRY_COMPARE(spy3.count(), 1); |
|
213 | TRY_COMPARE(spy3.count(), 1); | |
214 | } |
|
214 | } | |
215 |
|
215 | |||
216 | void tst_ChartDataSet::addAxis_data() |
|
216 | void tst_ChartDataSet::addAxis_data() | |
217 | { |
|
217 | { | |
218 | QTest::addColumn<QAbstractAxis*>("axis"); |
|
218 | QTest::addColumn<QAbstractAxis*>("axis"); | |
219 | QAbstractAxis* value = new QValueAxis(this); |
|
219 | QAbstractAxis* value = new QValueAxis(this); | |
220 | QAbstractAxis* category = new QCategoryAxis(this); |
|
220 | QAbstractAxis* category = new QCategoryAxis(this); | |
221 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); |
|
221 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); | |
222 | QAbstractAxis* datetime = new QDateTimeAxis(this); |
|
222 | QAbstractAxis* datetime = new QDateTimeAxis(this); | |
223 |
|
223 | |||
224 | QTest::newRow("value") << value; |
|
224 | QTest::newRow("value") << value; | |
225 | QTest::newRow("category") << category; |
|
225 | QTest::newRow("category") << category; | |
226 | QTest::newRow("barcategory") << barcategory; |
|
226 | QTest::newRow("barcategory") << barcategory; | |
227 | QTest::newRow("datetime") << datetime; |
|
227 | QTest::newRow("datetime") << datetime; | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | void tst_ChartDataSet::addAxis() |
|
230 | void tst_ChartDataSet::addAxis() | |
231 | { |
|
231 | { | |
232 | QFETCH(QAbstractAxis*, axis); |
|
232 | QFETCH(QAbstractAxis*, axis); | |
233 | QVERIFY(m_dataset->axes().isEmpty()); |
|
233 | QVERIFY(m_dataset->axes().isEmpty()); | |
234 |
|
234 | |||
235 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
235 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
236 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
236 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
237 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
237 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
238 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
238 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
239 |
|
239 | |||
240 | m_dataset->addAxis(axis,Qt::AlignBottom); |
|
240 | m_dataset->addAxis(axis,Qt::AlignBottom); | |
241 |
|
241 | |||
242 | QCOMPARE(m_dataset->axes().count(),1); |
|
242 | QCOMPARE(m_dataset->axes().count(),1); | |
243 | TRY_COMPARE(spy0.count(), 1); |
|
243 | TRY_COMPARE(spy0.count(), 1); | |
244 | TRY_COMPARE(spy1.count(), 0); |
|
244 | TRY_COMPARE(spy1.count(), 0); | |
245 | TRY_COMPARE(spy2.count(), 0); |
|
245 | TRY_COMPARE(spy2.count(), 0); | |
246 | TRY_COMPARE(spy3.count(), 0); |
|
246 | TRY_COMPARE(spy3.count(), 0); | |
247 | } |
|
247 | } | |
248 |
|
248 | |||
249 | void tst_ChartDataSet::removeAxis_data() |
|
249 | void tst_ChartDataSet::removeAxis_data() | |
250 | { |
|
250 | { | |
251 | addAxis_data(); |
|
251 | addAxis_data(); | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | void tst_ChartDataSet::removeAxis() |
|
254 | void tst_ChartDataSet::removeAxis() | |
255 | { |
|
255 | { | |
256 | QFETCH(QAbstractAxis*, axis); |
|
256 | QFETCH(QAbstractAxis*, axis); | |
257 | QVERIFY(m_dataset->series().isEmpty()); |
|
257 | QVERIFY(m_dataset->series().isEmpty()); | |
258 | m_dataset->addAxis(axis,Qt::AlignBottom); |
|
258 | m_dataset->addAxis(axis,Qt::AlignBottom); | |
259 |
|
259 | |||
260 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
260 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
261 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
261 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
262 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
262 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
263 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
263 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
264 |
|
264 | |||
265 | m_dataset->removeAxis(axis); |
|
265 | m_dataset->removeAxis(axis); | |
266 |
|
266 | |||
|
267 | QCOMPARE(m_dataset->axes().count(),0); | |||
267 | QCOMPARE(m_dataset->series().count(),0); |
|
268 | QCOMPARE(m_dataset->series().count(),0); | |
268 | TRY_COMPARE(spy0.count(), 0); |
|
269 | TRY_COMPARE(spy0.count(), 0); | |
269 | TRY_COMPARE(spy1.count(), 1); |
|
270 | TRY_COMPARE(spy1.count(), 1); | |
270 | TRY_COMPARE(spy2.count(), 0); |
|
271 | TRY_COMPARE(spy2.count(), 0); | |
271 | TRY_COMPARE(spy3.count(), 0); |
|
272 | TRY_COMPARE(spy3.count(), 0); | |
272 | } |
|
273 | } | |
273 |
|
274 | |||
274 | void tst_ChartDataSet::attachAxis_data() |
|
275 | void tst_ChartDataSet::attachAxis_data() | |
275 | { |
|
276 | { | |
276 |
|
277 | |||
277 | QTest::addColumn<QList<QAbstractSeries*> >("series"); |
|
278 | QTest::addColumn<QList<QAbstractSeries*> >("series"); | |
278 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); |
|
279 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); | |
279 | QTest::addColumn<QList<Qt::Alignment> >("alignment"); |
|
280 | QTest::addColumn<QList<Qt::Alignment> >("alignment"); | |
280 | QTest::addColumn<QAbstractSeries*>("attachSeries"); |
|
281 | QTest::addColumn<QAbstractSeries*>("attachSeries"); | |
281 | QTest::addColumn<QAbstractAxis*>("attachAxis"); |
|
282 | QTest::addColumn<QAbstractAxis*>("attachAxis"); | |
282 | QTest::addColumn<bool>("success"); |
|
283 | QTest::addColumn<bool>("success"); | |
283 |
|
284 | |||
284 | //QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
285 | //QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
285 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
286 | QAbstractSeries* scatter = new QScatterSeries(this); | |
286 | QAbstractSeries* spline = new QSplineSeries(this); |
|
287 | QAbstractSeries* spline = new QSplineSeries(this); | |
287 | QAbstractSeries* pie = new QPieSeries(this); |
|
288 | QAbstractSeries* pie = new QPieSeries(this); | |
288 | QAbstractSeries* bar = new QBarSeries(this); |
|
289 | QAbstractSeries* bar = new QBarSeries(this); | |
289 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
290 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
290 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
291 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
291 |
|
292 | |||
292 | QAbstractAxis* category = new QCategoryAxis(this); |
|
293 | QAbstractAxis* category = new QCategoryAxis(this); | |
293 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); |
|
294 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); | |
294 | QAbstractAxis* datetime = new QDateTimeAxis(this); |
|
295 | QAbstractAxis* datetime = new QDateTimeAxis(this); | |
295 |
|
296 | |||
296 | { |
|
297 | { | |
297 | QList<QAbstractSeries*> series; |
|
298 | QList<QAbstractSeries*> series; | |
298 | QList<QAbstractAxis*> axes; |
|
299 | QList<QAbstractAxis*> axes; | |
299 | QList<Qt::Alignment> alignment; |
|
300 | QList<Qt::Alignment> alignment; | |
300 | QAbstractSeries* line = new QLineSeries(this); |
|
301 | QAbstractSeries* line = new QLineSeries(this); | |
301 | QAbstractAxis* value1 = new QValueAxis(this); |
|
302 | QAbstractAxis* value1 = new QValueAxis(this); | |
302 | QAbstractAxis* value2 = new QValueAxis(this); |
|
303 | QAbstractAxis* value2 = new QValueAxis(this); | |
303 | series << line << 0; |
|
304 | series << line << 0; | |
304 | axes << value1 << value2; |
|
305 | axes << value1 << value2; | |
305 | alignment << Qt::AlignBottom << Qt::AlignLeft; |
|
306 | alignment << Qt::AlignBottom << Qt::AlignLeft; | |
306 | QTest::newRow("first") << series << axes << alignment << line << value2 << true ; |
|
307 | QTest::newRow("first") << series << axes << alignment << line << value2 << true ; | |
307 | } |
|
308 | } | |
308 |
|
309 | |||
309 | { |
|
310 | { | |
310 | QList<QAbstractSeries*> series; |
|
311 | QList<QAbstractSeries*> series; | |
311 | QList<QAbstractAxis*> axes; |
|
312 | QList<QAbstractAxis*> axes; | |
312 | QList<Qt::Alignment> alignment; |
|
313 | QList<Qt::Alignment> alignment; | |
313 | QAbstractSeries* line = new QLineSeries(this); |
|
314 | QAbstractSeries* line = new QLineSeries(this); | |
314 | QAbstractAxis* value1 = new QValueAxis(this); |
|
315 | QAbstractAxis* value1 = new QValueAxis(this); | |
315 | QAbstractAxis* value2 = new QValueAxis(this); |
|
316 | QAbstractAxis* value2 = new QValueAxis(this); | |
316 | series << 0 << line; |
|
317 | series << 0 << line; | |
317 | axes << value1 << value2; |
|
318 | axes << value1 << value2; | |
318 | alignment << Qt::AlignBottom << Qt::AlignLeft; |
|
319 | alignment << Qt::AlignBottom << Qt::AlignLeft; | |
319 | QTest::newRow("second") << series << axes << alignment << line << value1 << true; |
|
320 | QTest::newRow("second") << series << axes << alignment << line << value1 << true; | |
320 | } |
|
321 | } | |
321 |
|
322 | |||
322 | } |
|
323 | } | |
323 |
|
324 | |||
324 | void tst_ChartDataSet::attachAxis() |
|
325 | void tst_ChartDataSet::attachAxis() | |
325 | { |
|
326 | { | |
326 | QFETCH(QList<QAbstractSeries*>, series); |
|
327 | QFETCH(QList<QAbstractSeries*>, series); | |
327 | QFETCH(QList<QAbstractAxis*>, axis); |
|
328 | QFETCH(QList<QAbstractAxis*>, axis); | |
328 | QFETCH(QList<Qt::Alignment>, alignment); |
|
329 | QFETCH(QList<Qt::Alignment>, alignment); | |
329 | QFETCH(QAbstractSeries*, attachSeries); |
|
330 | QFETCH(QAbstractSeries*, attachSeries); | |
330 | QFETCH(QAbstractAxis*, attachAxis); |
|
331 | QFETCH(QAbstractAxis*, attachAxis); | |
331 | QFETCH(bool, success); |
|
332 | QFETCH(bool, success); | |
332 |
|
333 | |||
333 | Q_ASSERT(series.count() == axis.count()); |
|
334 | Q_ASSERT(series.count() == axis.count()); | |
334 | Q_ASSERT(series.count() == alignment.count()); |
|
335 | Q_ASSERT(series.count() == alignment.count()); | |
335 |
|
336 | |||
336 | QVERIFY(m_dataset->series().isEmpty()); |
|
337 | QVERIFY(m_dataset->series().isEmpty()); | |
337 | QVERIFY(m_dataset->axes().isEmpty()); |
|
338 | QVERIFY(m_dataset->axes().isEmpty()); | |
338 |
|
339 | |||
339 | for(int i = 0 ; i < series.count() ; i++){ |
|
340 | for(int i = 0 ; i < series.count() ; i++){ | |
340 | if(series[i]) m_dataset->addSeries(series[i]); |
|
341 | if(series[i]) m_dataset->addSeries(series[i]); | |
341 | if(axis[i]) m_dataset->addAxis(axis[i],alignment[i]); |
|
342 | if(axis[i]) m_dataset->addAxis(axis[i],alignment[i]); | |
342 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); |
|
343 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); | |
343 | } |
|
344 | } | |
344 |
|
345 | |||
345 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
346 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
346 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
347 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
347 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
348 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
348 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
349 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
349 |
|
350 | |||
350 | QCOMPARE(m_dataset->attachAxis(attachSeries,attachAxis),success); |
|
351 | QCOMPARE(m_dataset->attachAxis(attachSeries,attachAxis),success); | |
351 |
|
352 | |||
352 | } |
|
353 | } | |
353 |
|
354 | |||
354 | void tst_ChartDataSet::detachAxis_data() |
|
355 | void tst_ChartDataSet::detachAxis_data() | |
355 | { |
|
356 | { | |
356 | QTest::addColumn<QList<QAbstractSeries*> >("series"); |
|
357 | QTest::addColumn<QList<QAbstractSeries*> >("series"); | |
357 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); |
|
358 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); | |
358 | QTest::addColumn<QAbstractSeries*>("detachSeries"); |
|
359 | QTest::addColumn<QAbstractSeries*>("detachSeries"); | |
359 | QTest::addColumn<QAbstractAxis*>("detachAxis"); |
|
360 | QTest::addColumn<QAbstractAxis*>("detachAxis"); | |
360 | QTest::addColumn<bool>("success"); |
|
361 | QTest::addColumn<bool>("success"); | |
361 |
|
362 | |||
362 | { |
|
363 | { | |
363 | QList<QAbstractSeries*> series; |
|
364 | QList<QAbstractSeries*> series; | |
364 | QList<QAbstractAxis*> axes; |
|
365 | QList<QAbstractAxis*> axes; | |
365 | QAbstractSeries* line = new QLineSeries(this); |
|
366 | QAbstractSeries* line = new QLineSeries(this); | |
366 | QAbstractAxis* value = new QValueAxis(this); |
|
367 | QAbstractAxis* value = new QValueAxis(this); | |
367 | series << line; |
|
368 | series << line; | |
368 | axes << value; |
|
369 | axes << value; | |
369 | QTest::newRow("first") << series << axes << line << value << true; |
|
370 | QTest::newRow("first") << series << axes << line << value << true; | |
370 | } |
|
371 | } | |
371 | } |
|
372 | } | |
372 |
|
373 | |||
373 | void tst_ChartDataSet::detachAxis() |
|
374 | void tst_ChartDataSet::detachAxis() | |
374 | { |
|
375 | { | |
375 | QFETCH(QList<QAbstractSeries*>, series); |
|
376 | QFETCH(QList<QAbstractSeries*>, series); | |
376 | QFETCH(QList<QAbstractAxis*>, axis); |
|
377 | QFETCH(QList<QAbstractAxis*>, axis); | |
377 | QFETCH(QAbstractSeries*, detachSeries); |
|
378 | QFETCH(QAbstractSeries*, detachSeries); | |
378 | QFETCH(QAbstractAxis*, detachAxis); |
|
379 | QFETCH(QAbstractAxis*, detachAxis); | |
379 | QFETCH(bool, success); |
|
380 | QFETCH(bool, success); | |
380 |
|
381 | |||
381 | Q_ASSERT(series.count() == axis.count()); |
|
382 | Q_ASSERT(series.count() == axis.count()); | |
382 |
|
383 | |||
383 | QVERIFY(m_dataset->series().isEmpty()); |
|
384 | QVERIFY(m_dataset->series().isEmpty()); | |
384 | QVERIFY(m_dataset->axes().isEmpty()); |
|
385 | QVERIFY(m_dataset->axes().isEmpty()); | |
385 |
|
386 | |||
386 | for(int i = 0; i < series.count(); i++) { |
|
387 | for(int i = 0; i < series.count(); i++) { | |
387 | if(series[i]) m_dataset->addSeries(series[i]); |
|
388 | if(series[i]) m_dataset->addSeries(series[i]); | |
388 | if(axis[i]) m_dataset->addAxis(axis[i],Qt::AlignBottom); |
|
389 | if(axis[i]) m_dataset->addAxis(axis[i],Qt::AlignBottom); | |
389 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); |
|
390 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); | |
390 | } |
|
391 | } | |
391 |
|
392 | |||
392 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
393 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
393 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
394 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
394 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
395 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
395 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
396 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
396 |
|
397 | |||
397 | QCOMPARE(m_dataset->detachAxis(detachSeries,detachAxis),success); |
|
398 | QCOMPARE(m_dataset->detachAxis(detachSeries,detachAxis),success); | |
398 | } |
|
399 | } | |
399 |
|
400 | |||
400 | QTEST_MAIN(tst_ChartDataSet) |
|
401 | QTEST_MAIN(tst_ChartDataSet) | |
401 | #include "tst_chartdataset.moc" |
|
402 | #include "tst_chartdataset.moc" | |
402 | #endif |
|
403 | #endif |
@@ -1,795 +1,798 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qchartview.h> |
|
22 | #include <qchartview.h> | |
23 | #include <qlineseries.h> |
|
23 | #include <qlineseries.h> | |
24 | #include <qareaseries.h> |
|
24 | #include <qareaseries.h> | |
25 | #include <qscatterseries.h> |
|
25 | #include <qscatterseries.h> | |
26 | #include <qsplineseries.h> |
|
26 | #include <qsplineseries.h> | |
27 | #include <qpieseries.h> |
|
27 | #include <qpieseries.h> | |
28 | #include <qabstractbarseries.h> |
|
28 | #include <qabstractbarseries.h> | |
29 | #include <qbarseries.h> |
|
29 | #include <qbarseries.h> | |
30 | #include <qpercentbarseries.h> |
|
30 | #include <qpercentbarseries.h> | |
31 | #include <qstackedbarseries.h> |
|
31 | #include <qstackedbarseries.h> | |
32 | #include <qvalueaxis.h> |
|
32 | #include <qvalueaxis.h> | |
33 | #include <qbarcategoryaxis.h> |
|
33 | #include <qbarcategoryaxis.h> | |
34 | #include "tst_definitions.h" |
|
34 | #include "tst_definitions.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
36 | QTCOMMERCIALCHART_USE_NAMESPACE | |
37 |
|
37 | |||
38 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
38 | Q_DECLARE_METATYPE(QAbstractAxis *) | |
39 | Q_DECLARE_METATYPE(QValueAxis *) |
|
39 | Q_DECLARE_METATYPE(QValueAxis *) | |
40 | Q_DECLARE_METATYPE(QBarCategoryAxis *) |
|
40 | Q_DECLARE_METATYPE(QBarCategoryAxis *) | |
41 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
41 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
42 | Q_DECLARE_METATYPE(QChart::AnimationOption) |
|
42 | Q_DECLARE_METATYPE(QChart::AnimationOption) | |
43 | Q_DECLARE_METATYPE(QBrush) |
|
43 | Q_DECLARE_METATYPE(QBrush) | |
44 | Q_DECLARE_METATYPE(QPen) |
|
44 | Q_DECLARE_METATYPE(QPen) | |
45 | Q_DECLARE_METATYPE(QChart::ChartTheme) |
|
45 | Q_DECLARE_METATYPE(QChart::ChartTheme) | |
46 |
|
46 | |||
47 | class tst_QChart : public QObject |
|
47 | class tst_QChart : public QObject | |
48 | { |
|
48 | { | |
49 | Q_OBJECT |
|
49 | Q_OBJECT | |
50 |
|
50 | |||
51 | public slots: |
|
51 | public slots: | |
52 | void initTestCase(); |
|
52 | void initTestCase(); | |
53 | void cleanupTestCase(); |
|
53 | void cleanupTestCase(); | |
54 | void init(); |
|
54 | void init(); | |
55 | void cleanup(); |
|
55 | void cleanup(); | |
56 |
|
56 | |||
57 | private slots: |
|
57 | private slots: | |
58 | void qchart_data(); |
|
58 | void qchart_data(); | |
59 | void qchart(); |
|
59 | void qchart(); | |
60 | void addSeries_data(); |
|
60 | void addSeries_data(); | |
61 | void addSeries(); |
|
61 | void addSeries(); | |
62 | void animationOptions_data(); |
|
62 | void animationOptions_data(); | |
63 | void animationOptions(); |
|
63 | void animationOptions(); | |
64 | void axisX_data(); |
|
64 | void axisX_data(); | |
65 | void axisX(); |
|
65 | void axisX(); | |
66 | void axisY_data(); |
|
66 | void axisY_data(); | |
67 | void axisY(); |
|
67 | void axisY(); | |
68 | void backgroundBrush_data(); |
|
68 | void backgroundBrush_data(); | |
69 | void backgroundBrush(); |
|
69 | void backgroundBrush(); | |
70 | void backgroundPen_data(); |
|
70 | void backgroundPen_data(); | |
71 | void backgroundPen(); |
|
71 | void backgroundPen(); | |
72 | void isBackgroundVisible_data(); |
|
72 | void isBackgroundVisible_data(); | |
73 | void isBackgroundVisible(); |
|
73 | void isBackgroundVisible(); | |
74 | void legend_data(); |
|
74 | void legend_data(); | |
75 | void legend(); |
|
75 | void legend(); | |
76 | void plotArea_data(); |
|
76 | void plotArea_data(); | |
77 | void plotArea(); |
|
77 | void plotArea(); | |
78 | void removeAllSeries_data(); |
|
78 | void removeAllSeries_data(); | |
79 | void removeAllSeries(); |
|
79 | void removeAllSeries(); | |
80 | void removeSeries_data(); |
|
80 | void removeSeries_data(); | |
81 | void removeSeries(); |
|
81 | void removeSeries(); | |
82 | void scroll_right_data(); |
|
82 | void scroll_right_data(); | |
83 | void scroll_right(); |
|
83 | void scroll_right(); | |
84 | void scroll_left_data(); |
|
84 | void scroll_left_data(); | |
85 | void scroll_left(); |
|
85 | void scroll_left(); | |
86 | void scroll_up_data(); |
|
86 | void scroll_up_data(); | |
87 | void scroll_up(); |
|
87 | void scroll_up(); | |
88 | void scroll_down_data(); |
|
88 | void scroll_down_data(); | |
89 | void scroll_down(); |
|
89 | void scroll_down(); | |
90 | void theme_data(); |
|
90 | void theme_data(); | |
91 | void theme(); |
|
91 | void theme(); | |
92 | void title_data(); |
|
92 | void title_data(); | |
93 | void title(); |
|
93 | void title(); | |
94 | void titleBrush_data(); |
|
94 | void titleBrush_data(); | |
95 | void titleBrush(); |
|
95 | void titleBrush(); | |
96 | void titleFont_data(); |
|
96 | void titleFont_data(); | |
97 | void titleFont(); |
|
97 | void titleFont(); | |
98 | void zoomIn_data(); |
|
98 | void zoomIn_data(); | |
99 | void zoomIn(); |
|
99 | void zoomIn(); | |
100 | void zoomOut_data(); |
|
100 | void zoomOut_data(); | |
101 | void zoomOut(); |
|
101 | void zoomOut(); | |
102 |
|
102 | |||
103 | private: |
|
103 | private: | |
104 | void createTestData(); |
|
104 | void createTestData(); | |
105 |
|
105 | |||
106 | private: |
|
106 | private: | |
107 | QChartView* m_view; |
|
107 | QChartView* m_view; | |
108 | QChart* m_chart; |
|
108 | QChart* m_chart; | |
109 | }; |
|
109 | }; | |
110 |
|
110 | |||
111 | void tst_QChart::initTestCase() |
|
111 | void tst_QChart::initTestCase() | |
112 | { |
|
112 | { | |
113 |
|
113 | |||
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | void tst_QChart::cleanupTestCase() |
|
116 | void tst_QChart::cleanupTestCase() | |
117 | { |
|
117 | { | |
118 |
|
118 | |||
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | void tst_QChart::init() |
|
121 | void tst_QChart::init() | |
122 | { |
|
122 | { | |
123 | m_view = new QChartView(new QChart()); |
|
123 | m_view = new QChartView(new QChart()); | |
124 | m_chart = m_view->chart(); |
|
124 | m_chart = m_view->chart(); | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | void tst_QChart::cleanup() |
|
127 | void tst_QChart::cleanup() | |
128 | { |
|
128 | { | |
129 | delete m_view; |
|
129 | delete m_view; | |
130 | m_view = 0; |
|
130 | m_view = 0; | |
131 | m_chart = 0; |
|
131 | m_chart = 0; | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 |
|
134 | |||
135 | void tst_QChart::createTestData() |
|
135 | void tst_QChart::createTestData() | |
136 | { |
|
136 | { | |
137 | QLineSeries* series0 = new QLineSeries(this); |
|
137 | QLineSeries* series0 = new QLineSeries(this); | |
138 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
138 | *series0 << QPointF(0, 0) << QPointF(100, 100); | |
139 | m_chart->addSeries(series0); |
|
139 | m_chart->addSeries(series0); | |
140 | m_view->show(); |
|
140 | m_view->show(); | |
141 | QTest::qWaitForWindowShown(m_view); |
|
141 | QTest::qWaitForWindowShown(m_view); | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | void tst_QChart::qchart_data() |
|
144 | void tst_QChart::qchart_data() | |
145 | { |
|
145 | { | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | void tst_QChart::qchart() |
|
148 | void tst_QChart::qchart() | |
149 | { |
|
149 | { | |
150 | QVERIFY(m_chart); |
|
150 | QVERIFY(m_chart); | |
151 | QVERIFY(m_chart->legend()); |
|
151 | QVERIFY(m_chart->legend()); | |
152 | QVERIFY(m_chart->legend()->isVisible()); |
|
152 | QVERIFY(m_chart->legend()->isVisible()); | |
153 |
|
153 | |||
154 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); |
|
154 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); | |
155 | QVERIFY(!m_chart->axisX()); |
|
155 | QVERIFY(!m_chart->axisX()); | |
156 | QVERIFY(!m_chart->axisY()); |
|
156 | QVERIFY(!m_chart->axisY()); | |
157 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); |
|
157 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); | |
158 | QVERIFY(m_chart->backgroundPen()!=QPen()); |
|
158 | QVERIFY(m_chart->backgroundPen()!=QPen()); | |
159 | QCOMPARE(m_chart->isBackgroundVisible(), true); |
|
159 | QCOMPARE(m_chart->isBackgroundVisible(), true); | |
160 | QVERIFY(m_chart->plotArea().top()==0); |
|
160 | QVERIFY(m_chart->plotArea().top()==0); | |
161 | QVERIFY(m_chart->plotArea().left()==0); |
|
161 | QVERIFY(m_chart->plotArea().left()==0); | |
162 | QVERIFY(m_chart->plotArea().right()==0); |
|
162 | QVERIFY(m_chart->plotArea().right()==0); | |
163 | QVERIFY(m_chart->plotArea().bottom()==0); |
|
163 | QVERIFY(m_chart->plotArea().bottom()==0); | |
164 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); |
|
164 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); | |
165 | QCOMPARE(m_chart->title(), QString()); |
|
165 | QCOMPARE(m_chart->title(), QString()); | |
166 |
|
166 | |||
167 | //QCOMPARE(m_chart->titleBrush(),QBrush()); |
|
167 | //QCOMPARE(m_chart->titleBrush(),QBrush()); | |
168 | //QCOMPARE(m_chart->titleFont(),QFont()); |
|
168 | //QCOMPARE(m_chart->titleFont(),QFont()); | |
169 |
|
169 | |||
170 | m_chart->removeAllSeries(); |
|
170 | m_chart->removeAllSeries(); | |
171 | m_chart->scroll(0,0); |
|
171 | m_chart->scroll(0,0); | |
172 |
|
172 | |||
173 | m_chart->zoomIn(); |
|
173 | m_chart->zoomIn(); | |
174 | m_chart->zoomIn(QRectF()); |
|
174 | m_chart->zoomIn(QRectF()); | |
175 | m_chart->zoomOut(); |
|
175 | m_chart->zoomOut(); | |
176 |
|
176 | |||
177 | m_view->show(); |
|
177 | m_view->show(); | |
178 |
|
178 | |||
179 | QVERIFY(m_chart->plotArea().top()>0); |
|
179 | QVERIFY(m_chart->plotArea().top()>0); | |
180 | QVERIFY(m_chart->plotArea().left()>0); |
|
180 | QVERIFY(m_chart->plotArea().left()>0); | |
181 | QVERIFY(m_chart->plotArea().right()>0); |
|
181 | QVERIFY(m_chart->plotArea().right()>0); | |
182 | QVERIFY(m_chart->plotArea().bottom()>0); |
|
182 | QVERIFY(m_chart->plotArea().bottom()>0); | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | void tst_QChart::addSeries_data() |
|
185 | void tst_QChart::addSeries_data() | |
186 | { |
|
186 | { | |
187 | QTest::addColumn<QAbstractSeries *>("series"); |
|
187 | QTest::addColumn<QAbstractSeries *>("series"); | |
188 |
|
188 | |||
189 | QAbstractSeries* line = new QLineSeries(this); |
|
189 | QAbstractSeries* line = new QLineSeries(this); | |
190 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
190 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
191 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
191 | QAbstractSeries* scatter = new QScatterSeries(this); | |
192 | QAbstractSeries* spline = new QSplineSeries(this); |
|
192 | QAbstractSeries* spline = new QSplineSeries(this); | |
193 | QAbstractSeries* pie = new QPieSeries(this); |
|
193 | QAbstractSeries* pie = new QPieSeries(this); | |
194 | QAbstractSeries* bar = new QBarSeries(this); |
|
194 | QAbstractSeries* bar = new QBarSeries(this); | |
195 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
195 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
196 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
196 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
197 |
|
197 | |||
198 | QTest::newRow("lineSeries") << line; |
|
198 | QTest::newRow("lineSeries") << line; | |
199 | QTest::newRow("areaSeries") << area; |
|
199 | QTest::newRow("areaSeries") << area; | |
200 | QTest::newRow("scatterSeries") << scatter; |
|
200 | QTest::newRow("scatterSeries") << scatter; | |
201 | QTest::newRow("splineSeries") << spline; |
|
201 | QTest::newRow("splineSeries") << spline; | |
202 | QTest::newRow("pieSeries") << pie; |
|
202 | QTest::newRow("pieSeries") << pie; | |
203 | QTest::newRow("barSeries") << bar; |
|
203 | QTest::newRow("barSeries") << bar; | |
204 | QTest::newRow("percentBarSeries") << percent; |
|
204 | QTest::newRow("percentBarSeries") << percent; | |
205 | QTest::newRow("stackedBarSeries") << stacked; |
|
205 | QTest::newRow("stackedBarSeries") << stacked; | |
206 |
|
206 | |||
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | void tst_QChart::addSeries() |
|
209 | void tst_QChart::addSeries() | |
210 | { |
|
210 | { | |
211 | QFETCH(QAbstractSeries *, series); |
|
211 | QFETCH(QAbstractSeries *, series); | |
212 | m_view->show(); |
|
212 | m_view->show(); | |
213 | QTest::qWaitForWindowShown(m_view); |
|
213 | QTest::qWaitForWindowShown(m_view); | |
214 | QVERIFY(!series->chart()); |
|
214 | QVERIFY(!series->chart()); | |
215 | QCOMPARE(m_chart->series().count(), 0); |
|
215 | QCOMPARE(m_chart->series().count(), 0); | |
216 | m_chart->addSeries(series); |
|
216 | m_chart->addSeries(series); | |
217 | QCOMPARE(m_chart->series().count(), 1); |
|
217 | QCOMPARE(m_chart->series().count(), 1); | |
218 | QCOMPARE(m_chart->series().first(), series); |
|
218 | QCOMPARE(m_chart->series().first(), series); | |
219 | QVERIFY(series->chart() == m_chart); |
|
219 | QVERIFY(series->chart() == m_chart); | |
220 | m_chart->createDefaultAxes(); |
|
220 | m_chart->createDefaultAxes(); | |
221 | if(series->type()!=QAbstractSeries::SeriesTypePie){ |
|
221 | if(series->type()!=QAbstractSeries::SeriesTypePie){ | |
222 | QVERIFY(m_chart->axisY(series)); |
|
222 | QVERIFY(m_chart->axisY(series)); | |
223 | QVERIFY(m_chart->axisX(series)); |
|
223 | QVERIFY(m_chart->axisX(series)); | |
224 | }else{ |
|
224 | }else{ | |
225 | QVERIFY(!m_chart->axisY(series)); |
|
225 | QVERIFY(!m_chart->axisY(series)); | |
226 | QVERIFY(!m_chart->axisX(series)); |
|
226 | QVERIFY(!m_chart->axisX(series)); | |
227 | } |
|
227 | } | |
228 | m_chart->removeSeries(series); |
|
228 | m_chart->removeSeries(series); | |
229 | QVERIFY(!series->chart()); |
|
229 | QVERIFY(!series->chart()); | |
230 | QCOMPARE(m_chart->series().count(), 0); |
|
230 | QCOMPARE(m_chart->series().count(), 0); | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | void tst_QChart::animationOptions_data() |
|
233 | void tst_QChart::animationOptions_data() | |
234 | { |
|
234 | { | |
235 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); |
|
235 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); | |
236 | QTest::newRow("AllAnimations") << QChart::AllAnimations; |
|
236 | QTest::newRow("AllAnimations") << QChart::AllAnimations; | |
237 | QTest::newRow("NoAnimation") << QChart::NoAnimation; |
|
237 | QTest::newRow("NoAnimation") << QChart::NoAnimation; | |
238 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; |
|
238 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; | |
239 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; |
|
239 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; | |
240 | } |
|
240 | } | |
241 |
|
241 | |||
242 | void tst_QChart::animationOptions() |
|
242 | void tst_QChart::animationOptions() | |
243 | { |
|
243 | { | |
244 | createTestData(); |
|
244 | createTestData(); | |
245 | QFETCH(QChart::AnimationOption, animationOptions); |
|
245 | QFETCH(QChart::AnimationOption, animationOptions); | |
246 | m_chart->setAnimationOptions(animationOptions); |
|
246 | m_chart->setAnimationOptions(animationOptions); | |
247 | QCOMPARE(m_chart->animationOptions(), animationOptions); |
|
247 | QCOMPARE(m_chart->animationOptions(), animationOptions); | |
248 | } |
|
248 | } | |
249 |
|
249 | |||
250 | void tst_QChart::axisX_data() |
|
250 | void tst_QChart::axisX_data() | |
251 | { |
|
251 | { | |
252 |
|
252 | |||
253 | QTest::addColumn<QAbstractAxis*>("axis"); |
|
253 | QTest::addColumn<QAbstractAxis*>("axis"); | |
254 | QTest::addColumn<QAbstractSeries *>("series"); |
|
254 | QTest::addColumn<QAbstractSeries *>("series"); | |
255 |
|
255 | |||
256 | QTest::newRow("categories,lineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QLineSeries(this); |
|
256 | QTest::newRow("categories,lineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QLineSeries(this); | |
257 | QTest::newRow("categories,areaSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); |
|
257 | QTest::newRow("categories,areaSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); | |
258 | QTest::newRow("categories,scatterSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QScatterSeries(this); |
|
258 | QTest::newRow("categories,scatterSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QScatterSeries(this); | |
259 | QTest::newRow("categories,splineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QSplineSeries(this); |
|
259 | QTest::newRow("categories,splineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QSplineSeries(this); | |
260 | QTest::newRow("categories,pieSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPieSeries(this); |
|
260 | QTest::newRow("categories,pieSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPieSeries(this); | |
261 | QTest::newRow("categories,barSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QBarSeries(this); |
|
261 | QTest::newRow("categories,barSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QBarSeries(this); | |
262 | QTest::newRow("categories,percentBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPercentBarSeries(this); |
|
262 | QTest::newRow("categories,percentBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPercentBarSeries(this); | |
263 | QTest::newRow("categories,stackedBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QStackedBarSeries(this); |
|
263 | QTest::newRow("categories,stackedBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QStackedBarSeries(this); | |
264 |
|
264 | |||
265 | QTest::newRow("value,lineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QLineSeries(this); |
|
265 | QTest::newRow("value,lineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QLineSeries(this); | |
266 | QTest::newRow("value,areaSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); |
|
266 | QTest::newRow("value,areaSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); | |
267 | QTest::newRow("value,scatterSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QScatterSeries(this); |
|
267 | QTest::newRow("value,scatterSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QScatterSeries(this); | |
268 | QTest::newRow("value,splineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QSplineSeries(this); |
|
268 | QTest::newRow("value,splineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QSplineSeries(this); | |
269 | QTest::newRow("value,pieSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPieSeries(this); |
|
269 | QTest::newRow("value,pieSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPieSeries(this); | |
270 | QTest::newRow("value,barSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QBarSeries(this); |
|
270 | QTest::newRow("value,barSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QBarSeries(this); | |
271 | QTest::newRow("value,percentBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPercentBarSeries(this); |
|
271 | QTest::newRow("value,percentBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPercentBarSeries(this); | |
272 | QTest::newRow("value,stackedBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QStackedBarSeries(this); |
|
272 | QTest::newRow("value,stackedBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QStackedBarSeries(this); | |
273 |
|
273 | |||
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | void tst_QChart::axisX() |
|
276 | void tst_QChart::axisX() | |
277 | { |
|
277 | { | |
278 | QFETCH(QAbstractAxis*, axis); |
|
278 | QFETCH(QAbstractAxis*, axis); | |
279 | QFETCH(QAbstractSeries*, series); |
|
279 | QFETCH(QAbstractSeries*, series); | |
280 | QVERIFY(!m_chart->axisX()); |
|
280 | QVERIFY(!m_chart->axisX()); | |
281 | m_view->show(); |
|
281 | m_view->show(); | |
282 | QTest::qWaitForWindowShown(m_view); |
|
282 | QTest::qWaitForWindowShown(m_view); | |
283 | m_chart->addSeries(series); |
|
283 | m_chart->addSeries(series); | |
284 | m_chart->setAxisX(axis,series); |
|
284 | m_chart->setAxisX(axis,series); | |
285 | QVERIFY(m_chart->axisX(series)==axis); |
|
285 | QVERIFY(m_chart->axisX(series)==axis); | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | void tst_QChart::axisY_data() |
|
288 | void tst_QChart::axisY_data() | |
289 | { |
|
289 | { | |
290 | axisX_data(); |
|
290 | axisX_data(); | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 |
|
293 | |||
294 | void tst_QChart::axisY() |
|
294 | void tst_QChart::axisY() | |
295 | { |
|
295 | { | |
296 | QFETCH(QAbstractAxis*, axis); |
|
296 | QFETCH(QAbstractAxis*, axis); | |
297 | QFETCH(QAbstractSeries*, series); |
|
297 | QFETCH(QAbstractSeries*, series); | |
298 | QVERIFY(!m_chart->axisY()); |
|
298 | QVERIFY(!m_chart->axisY()); | |
299 | m_view->show(); |
|
299 | m_view->show(); | |
300 | QTest::qWaitForWindowShown(m_view); |
|
300 | QTest::qWaitForWindowShown(m_view); | |
301 | m_chart->addSeries(series); |
|
301 | m_chart->addSeries(series); | |
302 | m_chart->setAxisY(axis,series); |
|
302 | m_chart->setAxisY(axis,series); | |
303 | QVERIFY(m_chart->axisY(series)==axis); |
|
303 | QVERIFY(m_chart->axisY(series)==axis); | |
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 | void tst_QChart::backgroundBrush_data() |
|
306 | void tst_QChart::backgroundBrush_data() | |
307 | { |
|
307 | { | |
308 | QTest::addColumn<QBrush>("backgroundBrush"); |
|
308 | QTest::addColumn<QBrush>("backgroundBrush"); | |
309 | QTest::newRow("null") << QBrush(); |
|
309 | QTest::newRow("null") << QBrush(); | |
310 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
310 | QTest::newRow("blue") << QBrush(Qt::blue); | |
311 | QTest::newRow("white") << QBrush(Qt::white); |
|
311 | QTest::newRow("white") << QBrush(Qt::white); | |
312 | QTest::newRow("black") << QBrush(Qt::black); |
|
312 | QTest::newRow("black") << QBrush(Qt::black); | |
313 | } |
|
313 | } | |
314 |
|
314 | |||
315 | void tst_QChart::backgroundBrush() |
|
315 | void tst_QChart::backgroundBrush() | |
316 | { |
|
316 | { | |
317 | QFETCH(QBrush, backgroundBrush); |
|
317 | QFETCH(QBrush, backgroundBrush); | |
318 | m_chart->setBackgroundBrush(backgroundBrush); |
|
318 | m_chart->setBackgroundBrush(backgroundBrush); | |
319 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); |
|
319 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); | |
320 | } |
|
320 | } | |
321 |
|
321 | |||
322 | void tst_QChart::backgroundPen_data() |
|
322 | void tst_QChart::backgroundPen_data() | |
323 | { |
|
323 | { | |
324 | QTest::addColumn<QPen>("backgroundPen"); |
|
324 | QTest::addColumn<QPen>("backgroundPen"); | |
325 | QTest::newRow("null") << QPen(); |
|
325 | QTest::newRow("null") << QPen(); | |
326 | QTest::newRow("blue") << QPen(Qt::blue); |
|
326 | QTest::newRow("blue") << QPen(Qt::blue); | |
327 | QTest::newRow("white") << QPen(Qt::white); |
|
327 | QTest::newRow("white") << QPen(Qt::white); | |
328 | QTest::newRow("black") << QPen(Qt::black); |
|
328 | QTest::newRow("black") << QPen(Qt::black); | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 |
|
331 | |||
332 | void tst_QChart::backgroundPen() |
|
332 | void tst_QChart::backgroundPen() | |
333 | { |
|
333 | { | |
334 | QFETCH(QPen, backgroundPen); |
|
334 | QFETCH(QPen, backgroundPen); | |
335 | m_chart->setBackgroundPen(backgroundPen); |
|
335 | m_chart->setBackgroundPen(backgroundPen); | |
336 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); |
|
336 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); | |
337 | } |
|
337 | } | |
338 |
|
338 | |||
339 | void tst_QChart::isBackgroundVisible_data() |
|
339 | void tst_QChart::isBackgroundVisible_data() | |
340 | { |
|
340 | { | |
341 | QTest::addColumn<bool>("isBackgroundVisible"); |
|
341 | QTest::addColumn<bool>("isBackgroundVisible"); | |
342 | QTest::newRow("true") << true; |
|
342 | QTest::newRow("true") << true; | |
343 | QTest::newRow("false") << false; |
|
343 | QTest::newRow("false") << false; | |
344 | } |
|
344 | } | |
345 |
|
345 | |||
346 | void tst_QChart::isBackgroundVisible() |
|
346 | void tst_QChart::isBackgroundVisible() | |
347 | { |
|
347 | { | |
348 | QFETCH(bool, isBackgroundVisible); |
|
348 | QFETCH(bool, isBackgroundVisible); | |
349 | m_chart->setBackgroundVisible(isBackgroundVisible); |
|
349 | m_chart->setBackgroundVisible(isBackgroundVisible); | |
350 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); |
|
350 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); | |
351 | } |
|
351 | } | |
352 |
|
352 | |||
353 | void tst_QChart::legend_data() |
|
353 | void tst_QChart::legend_data() | |
354 | { |
|
354 | { | |
355 |
|
355 | |||
356 | } |
|
356 | } | |
357 |
|
357 | |||
358 | void tst_QChart::legend() |
|
358 | void tst_QChart::legend() | |
359 | { |
|
359 | { | |
360 | QLegend *legend = m_chart->legend(); |
|
360 | QLegend *legend = m_chart->legend(); | |
361 | QVERIFY(legend); |
|
361 | QVERIFY(legend); | |
362 |
|
362 | |||
363 | // Colors related signals |
|
363 | // Colors related signals | |
364 | QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor))); |
|
364 | QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor))); | |
365 | QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor))); |
|
365 | QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor))); | |
366 | QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor))); |
|
366 | QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor))); | |
367 |
|
367 | |||
368 | // colorChanged |
|
368 | // colorChanged | |
369 | legend->setColor(QColor("aliceblue")); |
|
369 | legend->setColor(QColor("aliceblue")); | |
370 | QCOMPARE(colorSpy.count(), 1); |
|
370 | QCOMPARE(colorSpy.count(), 1); | |
371 | QBrush b = legend->brush(); |
|
371 | QBrush b = legend->brush(); | |
372 | b.setColor(QColor("aqua")); |
|
372 | b.setColor(QColor("aqua")); | |
373 | legend->setBrush(b); |
|
373 | legend->setBrush(b); | |
374 | QCOMPARE(colorSpy.count(), 2); |
|
374 | QCOMPARE(colorSpy.count(), 2); | |
375 |
|
375 | |||
376 | // borderColorChanged |
|
376 | // borderColorChanged | |
377 | legend->setBorderColor(QColor("aliceblue")); |
|
377 | legend->setBorderColor(QColor("aliceblue")); | |
378 | QCOMPARE(borderColorSpy.count(), 1); |
|
378 | QCOMPARE(borderColorSpy.count(), 1); | |
379 | QPen p = legend->pen(); |
|
379 | QPen p = legend->pen(); | |
380 | p.setColor(QColor("aqua")); |
|
380 | p.setColor(QColor("aqua")); | |
381 | legend->setPen(p); |
|
381 | legend->setPen(p); | |
382 | QCOMPARE(borderColorSpy.count(), 2); |
|
382 | QCOMPARE(borderColorSpy.count(), 2); | |
383 |
|
383 | |||
384 | // labelColorChanged |
|
384 | // labelColorChanged | |
385 | legend->setLabelColor(QColor("lightsalmon")); |
|
385 | legend->setLabelColor(QColor("lightsalmon")); | |
386 | QCOMPARE(labelColorSpy.count(), 1); |
|
386 | QCOMPARE(labelColorSpy.count(), 1); | |
387 | b = legend->labelBrush(); |
|
387 | b = legend->labelBrush(); | |
388 | b.setColor(QColor("lightseagreen")); |
|
388 | b.setColor(QColor("lightseagreen")); | |
389 | legend->setLabelBrush(b); |
|
389 | legend->setLabelBrush(b); | |
390 | QCOMPARE(labelColorSpy.count(), 2); |
|
390 | QCOMPARE(labelColorSpy.count(), 2); | |
391 |
|
391 | |||
392 | // fontChanged |
|
392 | // fontChanged | |
393 | QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont))); |
|
393 | QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont))); | |
394 | QFont f = legend->font(); |
|
394 | QFont f = legend->font(); | |
395 | f.setBold(!f.bold()); |
|
395 | f.setBold(!f.bold()); | |
396 | legend->setFont(f); |
|
396 | legend->setFont(f); | |
397 | QCOMPARE(fontSpy.count(), 1); |
|
397 | QCOMPARE(fontSpy.count(), 1); | |
398 | } |
|
398 | } | |
399 |
|
399 | |||
400 | void tst_QChart::plotArea_data() |
|
400 | void tst_QChart::plotArea_data() | |
401 | { |
|
401 | { | |
402 |
|
402 | |||
403 | } |
|
403 | } | |
404 |
|
404 | |||
405 | void tst_QChart::plotArea() |
|
405 | void tst_QChart::plotArea() | |
406 | { |
|
406 | { | |
407 | createTestData(); |
|
407 | createTestData(); | |
408 | QRectF rect = m_chart->geometry(); |
|
408 | QRectF rect = m_chart->geometry(); | |
409 | QVERIFY(m_chart->plotArea().isValid()); |
|
409 | QVERIFY(m_chart->plotArea().isValid()); | |
410 | QVERIFY(m_chart->plotArea().height() < rect.height()); |
|
410 | QVERIFY(m_chart->plotArea().height() < rect.height()); | |
411 | QVERIFY(m_chart->plotArea().width() < rect.width()); |
|
411 | QVERIFY(m_chart->plotArea().width() < rect.width()); | |
412 | } |
|
412 | } | |
413 |
|
413 | |||
414 | void tst_QChart::removeAllSeries_data() |
|
414 | void tst_QChart::removeAllSeries_data() | |
415 | { |
|
415 | { | |
416 |
|
416 | |||
417 | } |
|
417 | } | |
418 |
|
418 | |||
419 | void tst_QChart::removeAllSeries() |
|
419 | void tst_QChart::removeAllSeries() | |
420 | { |
|
420 | { | |
421 | QLineSeries* series0 = new QLineSeries(this); |
|
421 | QLineSeries* series0 = new QLineSeries(this); | |
422 | QLineSeries* series1 = new QLineSeries(this); |
|
422 | QLineSeries* series1 = new QLineSeries(this); | |
423 | QLineSeries* series2 = new QLineSeries(this); |
|
423 | QLineSeries* series2 = new QLineSeries(this); | |
424 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); |
|
424 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); | |
425 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); |
|
425 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); | |
426 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); |
|
426 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); | |
427 |
|
427 | |||
428 | m_chart->addSeries(series0); |
|
428 | m_chart->addSeries(series0); | |
429 | m_chart->addSeries(series1); |
|
429 | m_chart->addSeries(series1); | |
430 | m_chart->addSeries(series2); |
|
430 | m_chart->addSeries(series2); | |
431 | m_view->show(); |
|
431 | m_view->show(); | |
432 | QTest::qWaitForWindowShown(m_view); |
|
432 | QTest::qWaitForWindowShown(m_view); | |
433 | m_chart->createDefaultAxes(); |
|
433 | m_chart->createDefaultAxes(); | |
|
434 | QCOMPARE(m_chart->axes().count(), 2); | |||
434 | QVERIFY(m_chart->axisY(series0)!=0); |
|
435 | QVERIFY(m_chart->axisY(series0)!=0); | |
435 | QVERIFY(m_chart->axisY(series1)!=0); |
|
436 | QVERIFY(m_chart->axisY(series1)!=0); | |
436 | QVERIFY(m_chart->axisY(series2)!=0); |
|
437 | QVERIFY(m_chart->axisY(series2)!=0); | |
437 |
|
438 | |||
438 | m_chart->removeAllSeries(); |
|
439 | m_chart->removeAllSeries(); | |
439 | QVERIFY(m_chart->axisY(series0)==0); |
|
440 | QCOMPARE(m_chart->axes().count(), 2); | |
440 |
QVERIFY(m_chart->axis |
|
441 | QVERIFY(m_chart->axisX() != 0); | |
441 |
QVERIFY(m_chart->axisY( |
|
442 | QVERIFY(m_chart->axisY() != 0); | |
442 | QCOMPARE(deleteSpy1.count(), 1); |
|
443 | QCOMPARE(deleteSpy1.count(), 1); | |
443 | QCOMPARE(deleteSpy2.count(), 1); |
|
444 | QCOMPARE(deleteSpy2.count(), 1); | |
444 | QCOMPARE(deleteSpy3.count(), 1); |
|
445 | QCOMPARE(deleteSpy3.count(), 1); | |
445 | } |
|
446 | } | |
446 |
|
447 | |||
447 | void tst_QChart::removeSeries_data() |
|
448 | void tst_QChart::removeSeries_data() | |
448 | { |
|
449 | { | |
449 | axisX_data(); |
|
450 | axisX_data(); | |
450 | } |
|
451 | } | |
451 |
|
452 | |||
452 | void tst_QChart::removeSeries() |
|
453 | void tst_QChart::removeSeries() | |
453 | { |
|
454 | { | |
454 | QFETCH(QAbstractAxis *, axis); |
|
455 | QFETCH(QAbstractAxis *, axis); | |
455 | QFETCH(QAbstractSeries *, series); |
|
456 | QFETCH(QAbstractSeries *, series); | |
456 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); |
|
457 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); | |
457 | m_view->show(); |
|
458 | m_view->show(); | |
458 | QTest::qWaitForWindowShown(m_view); |
|
459 | QTest::qWaitForWindowShown(m_view); | |
459 | if(!axis) axis = m_chart->axisY(); |
|
460 | if(!axis) axis = m_chart->axisY(); | |
460 | m_chart->addSeries(series); |
|
461 | m_chart->addSeries(series); | |
461 | m_chart->setAxisY(axis,series); |
|
462 | m_chart->setAxisY(axis,series); | |
462 | QCOMPARE(m_chart->axisY(series),axis); |
|
463 | QCOMPARE(m_chart->axisY(series),axis); | |
463 | m_chart->removeSeries(series); |
|
464 | m_chart->removeSeries(series); | |
|
465 | QCOMPARE(m_chart->axes().count(), 1); | |||
|
466 | QVERIFY(m_chart->axisY() != 0); | |||
464 | QVERIFY(m_chart->axisY(series)==0); |
|
467 | QVERIFY(m_chart->axisY(series)==0); | |
465 | QCOMPARE(deleteSpy.count(), 0); |
|
468 | QCOMPARE(deleteSpy.count(), 0); | |
466 | } |
|
469 | } | |
467 |
|
470 | |||
468 | void tst_QChart::scroll_right_data() |
|
471 | void tst_QChart::scroll_right_data() | |
469 | { |
|
472 | { | |
470 | QTest::addColumn<QAbstractSeries *>("series"); |
|
473 | QTest::addColumn<QAbstractSeries *>("series"); | |
471 |
|
474 | |||
472 | QLineSeries* series0 = new QLineSeries(this); |
|
475 | QLineSeries* series0 = new QLineSeries(this); | |
473 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
476 | *series0 << QPointF(0, 0) << QPointF(100, 100); | |
474 |
|
477 | |||
475 | QTest::newRow("lineSeries") << (QAbstractSeries*) series0; |
|
478 | QTest::newRow("lineSeries") << (QAbstractSeries*) series0; | |
476 |
|
479 | |||
477 |
|
480 | |||
478 | } |
|
481 | } | |
479 |
|
482 | |||
480 | void tst_QChart::scroll_right() |
|
483 | void tst_QChart::scroll_right() | |
481 | { |
|
484 | { | |
482 | QFETCH(QAbstractSeries *, series); |
|
485 | QFETCH(QAbstractSeries *, series); | |
483 | m_chart->addSeries(series); |
|
486 | m_chart->addSeries(series); | |
484 | m_chart->createDefaultAxes(); |
|
487 | m_chart->createDefaultAxes(); | |
485 | m_view->show(); |
|
488 | m_view->show(); | |
486 | QTest::qWaitForWindowShown(m_view); |
|
489 | QTest::qWaitForWindowShown(m_view); | |
487 | QAbstractAxis * axis = m_chart->axisX(); |
|
490 | QAbstractAxis * axis = m_chart->axisX(); | |
488 | QVERIFY(axis!=0); |
|
491 | QVERIFY(axis!=0); | |
489 |
|
492 | |||
490 | switch(axis->type()) |
|
493 | switch(axis->type()) | |
491 | { |
|
494 | { | |
492 | case QAbstractAxis::AxisTypeValue:{ |
|
495 | case QAbstractAxis::AxisTypeValue:{ | |
493 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
496 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); | |
494 | QVERIFY(vaxis!=0); |
|
497 | QVERIFY(vaxis!=0); | |
495 | qreal min = vaxis->min(); |
|
498 | qreal min = vaxis->min(); | |
496 | qreal max = vaxis->max(); |
|
499 | qreal max = vaxis->max(); | |
497 | QVERIFY(max>min); |
|
500 | QVERIFY(max>min); | |
498 | m_chart->scroll(50, 0); |
|
501 | m_chart->scroll(50, 0); | |
499 | QVERIFY(min<vaxis->min()); |
|
502 | QVERIFY(min<vaxis->min()); | |
500 | QVERIFY(max<vaxis->max()); |
|
503 | QVERIFY(max<vaxis->max()); | |
501 | break; |
|
504 | break; | |
502 | } |
|
505 | } | |
503 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
506 | case QAbstractAxis::AxisTypeBarCategory:{ | |
504 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
507 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); | |
505 | QVERIFY(caxis!=0); |
|
508 | QVERIFY(caxis!=0); | |
506 | qreal min = caxis->min().toDouble(); |
|
509 | qreal min = caxis->min().toDouble(); | |
507 | qreal max = caxis->max().toDouble(); |
|
510 | qreal max = caxis->max().toDouble(); | |
508 | m_chart->scroll(50, 0); |
|
511 | m_chart->scroll(50, 0); | |
509 | QVERIFY(min<caxis->min().toDouble()); |
|
512 | QVERIFY(min<caxis->min().toDouble()); | |
510 | QVERIFY(max<caxis->max().toDouble()); |
|
513 | QVERIFY(max<caxis->max().toDouble()); | |
511 | break; |
|
514 | break; | |
512 | } |
|
515 | } | |
513 | default: |
|
516 | default: | |
514 | qFatal("Unsupported type"); |
|
517 | qFatal("Unsupported type"); | |
515 | break; |
|
518 | break; | |
516 | } |
|
519 | } | |
517 | } |
|
520 | } | |
518 |
|
521 | |||
519 | void tst_QChart::scroll_left_data() |
|
522 | void tst_QChart::scroll_left_data() | |
520 | { |
|
523 | { | |
521 | scroll_right_data(); |
|
524 | scroll_right_data(); | |
522 | } |
|
525 | } | |
523 |
|
526 | |||
524 | void tst_QChart::scroll_left() |
|
527 | void tst_QChart::scroll_left() | |
525 | { |
|
528 | { | |
526 | QFETCH(QAbstractSeries *, series); |
|
529 | QFETCH(QAbstractSeries *, series); | |
527 | m_chart->addSeries(series); |
|
530 | m_chart->addSeries(series); | |
528 | m_chart->createDefaultAxes(); |
|
531 | m_chart->createDefaultAxes(); | |
529 | m_view->show(); |
|
532 | m_view->show(); | |
530 | QTest::qWaitForWindowShown(m_view); |
|
533 | QTest::qWaitForWindowShown(m_view); | |
531 | QAbstractAxis * axis = m_chart->axisX(); |
|
534 | QAbstractAxis * axis = m_chart->axisX(); | |
532 | QVERIFY(axis!=0); |
|
535 | QVERIFY(axis!=0); | |
533 |
|
536 | |||
534 | switch(axis->type()) |
|
537 | switch(axis->type()) | |
535 | { |
|
538 | { | |
536 | case QAbstractAxis::AxisTypeValue:{ |
|
539 | case QAbstractAxis::AxisTypeValue:{ | |
537 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
540 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); | |
538 | QVERIFY(vaxis!=0); |
|
541 | QVERIFY(vaxis!=0); | |
539 | qreal min = vaxis->min(); |
|
542 | qreal min = vaxis->min(); | |
540 | qreal max = vaxis->max(); |
|
543 | qreal max = vaxis->max(); | |
541 | m_chart->scroll(-50, 0); |
|
544 | m_chart->scroll(-50, 0); | |
542 | QVERIFY(min>vaxis->min()); |
|
545 | QVERIFY(min>vaxis->min()); | |
543 | QVERIFY(max>vaxis->max()); |
|
546 | QVERIFY(max>vaxis->max()); | |
544 | break; |
|
547 | break; | |
545 | } |
|
548 | } | |
546 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
549 | case QAbstractAxis::AxisTypeBarCategory:{ | |
547 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
550 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); | |
548 | QVERIFY(caxis!=0); |
|
551 | QVERIFY(caxis!=0); | |
549 | qreal min = caxis->min().toDouble(); |
|
552 | qreal min = caxis->min().toDouble(); | |
550 | qreal max = caxis->max().toDouble(); |
|
553 | qreal max = caxis->max().toDouble(); | |
551 | m_chart->scroll(-50, 0); |
|
554 | m_chart->scroll(-50, 0); | |
552 | QVERIFY(min>caxis->min().toDouble()); |
|
555 | QVERIFY(min>caxis->min().toDouble()); | |
553 | QVERIFY(max>caxis->max().toDouble()); |
|
556 | QVERIFY(max>caxis->max().toDouble()); | |
554 | break; |
|
557 | break; | |
555 | } |
|
558 | } | |
556 | default: |
|
559 | default: | |
557 | qFatal("Unsupported type"); |
|
560 | qFatal("Unsupported type"); | |
558 | break; |
|
561 | break; | |
559 | } |
|
562 | } | |
560 | } |
|
563 | } | |
561 |
|
564 | |||
562 | void tst_QChart::scroll_up_data() |
|
565 | void tst_QChart::scroll_up_data() | |
563 | { |
|
566 | { | |
564 | scroll_right_data(); |
|
567 | scroll_right_data(); | |
565 | } |
|
568 | } | |
566 |
|
569 | |||
567 | void tst_QChart::scroll_up() |
|
570 | void tst_QChart::scroll_up() | |
568 | { |
|
571 | { | |
569 | QFETCH(QAbstractSeries *, series); |
|
572 | QFETCH(QAbstractSeries *, series); | |
570 | m_chart->addSeries(series); |
|
573 | m_chart->addSeries(series); | |
571 | m_chart->createDefaultAxes(); |
|
574 | m_chart->createDefaultAxes(); | |
572 | m_view->show(); |
|
575 | m_view->show(); | |
573 | QTest::qWaitForWindowShown(m_view); |
|
576 | QTest::qWaitForWindowShown(m_view); | |
574 | QAbstractAxis * axis = m_chart->axisY(); |
|
577 | QAbstractAxis * axis = m_chart->axisY(); | |
575 | QVERIFY(axis!=0); |
|
578 | QVERIFY(axis!=0); | |
576 |
|
579 | |||
577 | switch(axis->type()) |
|
580 | switch(axis->type()) | |
578 | { |
|
581 | { | |
579 | case QAbstractAxis::AxisTypeValue:{ |
|
582 | case QAbstractAxis::AxisTypeValue:{ | |
580 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
583 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); | |
581 | QVERIFY(vaxis!=0); |
|
584 | QVERIFY(vaxis!=0); | |
582 | qreal min = vaxis->min(); |
|
585 | qreal min = vaxis->min(); | |
583 | qreal max = vaxis->max(); |
|
586 | qreal max = vaxis->max(); | |
584 | m_chart->scroll(0, 50); |
|
587 | m_chart->scroll(0, 50); | |
585 | QVERIFY(min<vaxis->min()); |
|
588 | QVERIFY(min<vaxis->min()); | |
586 | QVERIFY(max<vaxis->max()); |
|
589 | QVERIFY(max<vaxis->max()); | |
587 | break; |
|
590 | break; | |
588 | } |
|
591 | } | |
589 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
592 | case QAbstractAxis::AxisTypeBarCategory:{ | |
590 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
593 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); | |
591 | QVERIFY(caxis!=0); |
|
594 | QVERIFY(caxis!=0); | |
592 | qreal min = caxis->min().toDouble(); |
|
595 | qreal min = caxis->min().toDouble(); | |
593 | qreal max = caxis->max().toDouble(); |
|
596 | qreal max = caxis->max().toDouble(); | |
594 | m_chart->scroll(0, 50); |
|
597 | m_chart->scroll(0, 50); | |
595 | QVERIFY(min<caxis->min().toDouble()); |
|
598 | QVERIFY(min<caxis->min().toDouble()); | |
596 | QVERIFY(max<caxis->max().toDouble()); |
|
599 | QVERIFY(max<caxis->max().toDouble()); | |
597 | break; |
|
600 | break; | |
598 | } |
|
601 | } | |
599 | default: |
|
602 | default: | |
600 | qFatal("Unsupported type"); |
|
603 | qFatal("Unsupported type"); | |
601 | break; |
|
604 | break; | |
602 | } |
|
605 | } | |
603 | } |
|
606 | } | |
604 |
|
607 | |||
605 | void tst_QChart::scroll_down_data() |
|
608 | void tst_QChart::scroll_down_data() | |
606 | { |
|
609 | { | |
607 | scroll_right_data(); |
|
610 | scroll_right_data(); | |
608 | } |
|
611 | } | |
609 |
|
612 | |||
610 | void tst_QChart::scroll_down() |
|
613 | void tst_QChart::scroll_down() | |
611 | { |
|
614 | { | |
612 | QFETCH(QAbstractSeries *, series); |
|
615 | QFETCH(QAbstractSeries *, series); | |
613 | m_chart->addSeries(series); |
|
616 | m_chart->addSeries(series); | |
614 | m_chart->createDefaultAxes(); |
|
617 | m_chart->createDefaultAxes(); | |
615 | m_view->show(); |
|
618 | m_view->show(); | |
616 | QTest::qWaitForWindowShown(m_view); |
|
619 | QTest::qWaitForWindowShown(m_view); | |
617 | QAbstractAxis * axis = m_chart->axisY(); |
|
620 | QAbstractAxis * axis = m_chart->axisY(); | |
618 | QVERIFY(axis!=0); |
|
621 | QVERIFY(axis!=0); | |
619 |
|
622 | |||
620 | switch(axis->type()) |
|
623 | switch(axis->type()) | |
621 | { |
|
624 | { | |
622 | case QAbstractAxis::AxisTypeValue:{ |
|
625 | case QAbstractAxis::AxisTypeValue:{ | |
623 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
626 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); | |
624 | QVERIFY(vaxis!=0); |
|
627 | QVERIFY(vaxis!=0); | |
625 | qreal min = vaxis->min(); |
|
628 | qreal min = vaxis->min(); | |
626 | qreal max = vaxis->max(); |
|
629 | qreal max = vaxis->max(); | |
627 | m_chart->scroll(0, -50); |
|
630 | m_chart->scroll(0, -50); | |
628 | QVERIFY(min>vaxis->min()); |
|
631 | QVERIFY(min>vaxis->min()); | |
629 | QVERIFY(max>vaxis->max()); |
|
632 | QVERIFY(max>vaxis->max()); | |
630 | break; |
|
633 | break; | |
631 | } |
|
634 | } | |
632 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
635 | case QAbstractAxis::AxisTypeBarCategory:{ | |
633 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
636 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); | |
634 | QVERIFY(caxis!=0); |
|
637 | QVERIFY(caxis!=0); | |
635 | qreal min = caxis->min().toDouble(); |
|
638 | qreal min = caxis->min().toDouble(); | |
636 | qreal max = caxis->max().toDouble(); |
|
639 | qreal max = caxis->max().toDouble(); | |
637 | m_chart->scroll(0, -50); |
|
640 | m_chart->scroll(0, -50); | |
638 | QVERIFY(min>caxis->min().toDouble()); |
|
641 | QVERIFY(min>caxis->min().toDouble()); | |
639 | QVERIFY(max>caxis->max().toDouble()); |
|
642 | QVERIFY(max>caxis->max().toDouble()); | |
640 | break; |
|
643 | break; | |
641 | } |
|
644 | } | |
642 | default: |
|
645 | default: | |
643 | qFatal("Unsupported type"); |
|
646 | qFatal("Unsupported type"); | |
644 | break; |
|
647 | break; | |
645 | } |
|
648 | } | |
646 | } |
|
649 | } | |
647 |
|
650 | |||
648 | void tst_QChart::theme_data() |
|
651 | void tst_QChart::theme_data() | |
649 | { |
|
652 | { | |
650 | QTest::addColumn<QChart::ChartTheme>("theme"); |
|
653 | QTest::addColumn<QChart::ChartTheme>("theme"); | |
651 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; |
|
654 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; | |
652 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; |
|
655 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; | |
653 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; |
|
656 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; | |
654 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; |
|
657 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; | |
655 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; |
|
658 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; | |
656 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; |
|
659 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; | |
657 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; |
|
660 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; | |
658 | } |
|
661 | } | |
659 |
|
662 | |||
660 | void tst_QChart::theme() |
|
663 | void tst_QChart::theme() | |
661 | { |
|
664 | { | |
662 | QFETCH(QChart::ChartTheme, theme); |
|
665 | QFETCH(QChart::ChartTheme, theme); | |
663 | createTestData(); |
|
666 | createTestData(); | |
664 | m_chart->setTheme(theme); |
|
667 | m_chart->setTheme(theme); | |
665 | QVERIFY(m_chart->theme()==theme); |
|
668 | QVERIFY(m_chart->theme()==theme); | |
666 | } |
|
669 | } | |
667 |
|
670 | |||
668 | void tst_QChart::title_data() |
|
671 | void tst_QChart::title_data() | |
669 | { |
|
672 | { | |
670 | QTest::addColumn<QString>("title"); |
|
673 | QTest::addColumn<QString>("title"); | |
671 | QTest::newRow("null") << QString(); |
|
674 | QTest::newRow("null") << QString(); | |
672 | QTest::newRow("foo") << QString("foo"); |
|
675 | QTest::newRow("foo") << QString("foo"); | |
673 | } |
|
676 | } | |
674 |
|
677 | |||
675 | void tst_QChart::title() |
|
678 | void tst_QChart::title() | |
676 | { |
|
679 | { | |
677 | QFETCH(QString, title); |
|
680 | QFETCH(QString, title); | |
678 | m_chart->setTitle(title); |
|
681 | m_chart->setTitle(title); | |
679 | QCOMPARE(m_chart->title(), title); |
|
682 | QCOMPARE(m_chart->title(), title); | |
680 | } |
|
683 | } | |
681 |
|
684 | |||
682 | void tst_QChart::titleBrush_data() |
|
685 | void tst_QChart::titleBrush_data() | |
683 | { |
|
686 | { | |
684 | QTest::addColumn<QBrush>("titleBrush"); |
|
687 | QTest::addColumn<QBrush>("titleBrush"); | |
685 | QTest::newRow("null") << QBrush(); |
|
688 | QTest::newRow("null") << QBrush(); | |
686 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
689 | QTest::newRow("blue") << QBrush(Qt::blue); | |
687 | QTest::newRow("white") << QBrush(Qt::white); |
|
690 | QTest::newRow("white") << QBrush(Qt::white); | |
688 | QTest::newRow("black") << QBrush(Qt::black); |
|
691 | QTest::newRow("black") << QBrush(Qt::black); | |
689 | } |
|
692 | } | |
690 |
|
693 | |||
691 | void tst_QChart::titleBrush() |
|
694 | void tst_QChart::titleBrush() | |
692 | { |
|
695 | { | |
693 | QFETCH(QBrush, titleBrush); |
|
696 | QFETCH(QBrush, titleBrush); | |
694 | m_chart->setTitleBrush(titleBrush); |
|
697 | m_chart->setTitleBrush(titleBrush); | |
695 | QCOMPARE(m_chart->titleBrush(), titleBrush); |
|
698 | QCOMPARE(m_chart->titleBrush(), titleBrush); | |
696 | } |
|
699 | } | |
697 |
|
700 | |||
698 | void tst_QChart::titleFont_data() |
|
701 | void tst_QChart::titleFont_data() | |
699 | { |
|
702 | { | |
700 | QTest::addColumn<QFont>("titleFont"); |
|
703 | QTest::addColumn<QFont>("titleFont"); | |
701 | QTest::newRow("null") << QFont(); |
|
704 | QTest::newRow("null") << QFont(); | |
702 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); |
|
705 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); | |
703 | } |
|
706 | } | |
704 |
|
707 | |||
705 | void tst_QChart::titleFont() |
|
708 | void tst_QChart::titleFont() | |
706 | { |
|
709 | { | |
707 | QFETCH(QFont, titleFont); |
|
710 | QFETCH(QFont, titleFont); | |
708 | m_chart->setTitleFont(titleFont); |
|
711 | m_chart->setTitleFont(titleFont); | |
709 | QCOMPARE(m_chart->titleFont(), titleFont); |
|
712 | QCOMPARE(m_chart->titleFont(), titleFont); | |
710 | } |
|
713 | } | |
711 |
|
714 | |||
712 | void tst_QChart::zoomIn_data() |
|
715 | void tst_QChart::zoomIn_data() | |
713 | { |
|
716 | { | |
714 | QTest::addColumn<QRectF>("rect"); |
|
717 | QTest::addColumn<QRectF>("rect"); | |
715 | QTest::newRow("null") << QRectF(); |
|
718 | QTest::newRow("null") << QRectF(); | |
716 | QTest::newRow("100x100") << QRectF(10,10,100,100); |
|
719 | QTest::newRow("100x100") << QRectF(10,10,100,100); | |
717 | QTest::newRow("200x200") << QRectF(10,10,200,200); |
|
720 | QTest::newRow("200x200") << QRectF(10,10,200,200); | |
718 | } |
|
721 | } | |
719 |
|
722 | |||
720 |
|
723 | |||
721 | void tst_QChart::zoomIn() |
|
724 | void tst_QChart::zoomIn() | |
722 | { |
|
725 | { | |
723 |
|
726 | |||
724 | QFETCH(QRectF, rect); |
|
727 | QFETCH(QRectF, rect); | |
725 | createTestData(); |
|
728 | createTestData(); | |
726 | m_chart->createDefaultAxes(); |
|
729 | m_chart->createDefaultAxes(); | |
727 | QRectF marigns = m_chart->plotArea(); |
|
730 | QRectF marigns = m_chart->plotArea(); | |
728 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); |
|
731 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); | |
729 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); |
|
732 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); | |
730 | QVERIFY(axisX!=0); |
|
733 | QVERIFY(axisX!=0); | |
731 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); |
|
734 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); | |
732 | QVERIFY(axisY!=0); |
|
735 | QVERIFY(axisY!=0); | |
733 | qreal minX = axisX->min(); |
|
736 | qreal minX = axisX->min(); | |
734 | qreal minY = axisY->min(); |
|
737 | qreal minY = axisY->min(); | |
735 | qreal maxX = axisX->max(); |
|
738 | qreal maxX = axisX->max(); | |
736 | qreal maxY = axisY->max(); |
|
739 | qreal maxY = axisY->max(); | |
737 | m_chart->zoomIn(rect); |
|
740 | m_chart->zoomIn(rect); | |
738 | if(rect.isValid()){ |
|
741 | if(rect.isValid()){ | |
739 | QVERIFY(minX<axisX->min()); |
|
742 | QVERIFY(minX<axisX->min()); | |
740 | QVERIFY(maxX>axisX->max()); |
|
743 | QVERIFY(maxX>axisX->max()); | |
741 | QVERIFY(minY<axisY->min()); |
|
744 | QVERIFY(minY<axisY->min()); | |
742 | QVERIFY(maxY>axisY->max()); |
|
745 | QVERIFY(maxY>axisY->max()); | |
743 | } |
|
746 | } | |
744 |
|
747 | |||
745 | } |
|
748 | } | |
746 |
|
749 | |||
747 | void tst_QChart::zoomOut_data() |
|
750 | void tst_QChart::zoomOut_data() | |
748 | { |
|
751 | { | |
749 |
|
752 | |||
750 | } |
|
753 | } | |
751 |
|
754 | |||
752 | void tst_QChart::zoomOut() |
|
755 | void tst_QChart::zoomOut() | |
753 | { |
|
756 | { | |
754 | createTestData(); |
|
757 | createTestData(); | |
755 | m_chart->createDefaultAxes(); |
|
758 | m_chart->createDefaultAxes(); | |
756 |
|
759 | |||
757 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); |
|
760 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); | |
758 | QVERIFY(axisX!=0); |
|
761 | QVERIFY(axisX!=0); | |
759 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); |
|
762 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); | |
760 | QVERIFY(axisY!=0); |
|
763 | QVERIFY(axisY!=0); | |
761 |
|
764 | |||
762 | qreal minX = axisX->min(); |
|
765 | qreal minX = axisX->min(); | |
763 | qreal minY = axisY->min(); |
|
766 | qreal minY = axisY->min(); | |
764 | qreal maxX = axisX->max(); |
|
767 | qreal maxX = axisX->max(); | |
765 | qreal maxY = axisY->max(); |
|
768 | qreal maxY = axisY->max(); | |
766 |
|
769 | |||
767 | m_chart->zoomIn(); |
|
770 | m_chart->zoomIn(); | |
768 |
|
771 | |||
769 | QVERIFY(minX < axisX->min()); |
|
772 | QVERIFY(minX < axisX->min()); | |
770 | QVERIFY(maxX > axisX->max()); |
|
773 | QVERIFY(maxX > axisX->max()); | |
771 | QVERIFY(minY < axisY->min()); |
|
774 | QVERIFY(minY < axisY->min()); | |
772 | QVERIFY(maxY > axisY->max()); |
|
775 | QVERIFY(maxY > axisY->max()); | |
773 |
|
776 | |||
774 | m_chart->zoomOut(); |
|
777 | m_chart->zoomOut(); | |
775 |
|
778 | |||
776 | // min x may be a zero value |
|
779 | // min x may be a zero value | |
777 | if (qFuzzyIsNull(minX)) |
|
780 | if (qFuzzyIsNull(minX)) | |
778 | QVERIFY(qFuzzyIsNull(axisX->min())); |
|
781 | QVERIFY(qFuzzyIsNull(axisX->min())); | |
779 | else |
|
782 | else | |
780 | QCOMPARE(minX, axisX->min()); |
|
783 | QCOMPARE(minX, axisX->min()); | |
781 |
|
784 | |||
782 | // min y may be a zero value |
|
785 | // min y may be a zero value | |
783 | if (qFuzzyIsNull(minY)) |
|
786 | if (qFuzzyIsNull(minY)) | |
784 | QVERIFY(qFuzzyIsNull(axisY->min())); |
|
787 | QVERIFY(qFuzzyIsNull(axisY->min())); | |
785 | else |
|
788 | else | |
786 | QCOMPARE(minY, axisY->min()); |
|
789 | QCOMPARE(minY, axisY->min()); | |
787 |
|
790 | |||
788 | QVERIFY(maxX == axisX->max()); |
|
791 | QVERIFY(maxX == axisX->max()); | |
789 | QVERIFY(maxY == axisY->max()); |
|
792 | QVERIFY(maxY == axisY->max()); | |
790 |
|
793 | |||
791 | } |
|
794 | } | |
792 |
|
795 | |||
793 | QTEST_MAIN(tst_QChart) |
|
796 | QTEST_MAIN(tst_QChart) | |
794 | #include "tst_qchart.moc" |
|
797 | #include "tst_qchart.moc" | |
795 |
|
798 |
General Comments 0
You need to be logged in to leave comments.
Login now