@@ -1,472 +1,479 | |||||
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 "qaxis.h" |
|
26 | #include "qaxis.h" | |
27 | #include <QGraphicsScene> |
|
27 | #include <QGraphicsScene> | |
28 | #include <QGraphicsSceneResizeEvent> |
|
28 | #include <QGraphicsSceneResizeEvent> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | \enum QChart::ChartTheme |
|
33 | \enum QChart::ChartTheme | |
34 |
|
34 | |||
35 | This enum describes the theme used by the chart. |
|
35 | This enum describes the theme used by the chart. | |
36 |
|
36 | |||
37 | \value ChartThemeLight The default theme |
|
37 | \value ChartThemeLight The default theme | |
38 | \value ChartThemeBlueCerulean |
|
38 | \value ChartThemeBlueCerulean | |
39 | \value ChartThemeDark |
|
39 | \value ChartThemeDark | |
40 | \value ChartThemeBrownSand |
|
40 | \value ChartThemeBrownSand | |
41 | \value ChartThemeBlueNcs |
|
41 | \value ChartThemeBlueNcs | |
42 | \value ChartThemeHighContrast |
|
42 | \value ChartThemeHighContrast | |
43 | \value ChartThemeBlueIcy |
|
43 | \value ChartThemeBlueIcy | |
44 | */ |
|
44 | */ | |
45 |
|
45 | |||
46 | /*! |
|
46 | /*! | |
47 | \enum QChart::AnimationOption |
|
47 | \enum QChart::AnimationOption | |
48 |
|
48 | |||
49 | For enabling/disabling animations. Defaults to NoAnimation. |
|
49 | For enabling/disabling animations. Defaults to NoAnimation. | |
50 |
|
50 | |||
51 | \value NoAnimation |
|
51 | \value NoAnimation | |
52 | \value GridAxisAnimations |
|
52 | \value GridAxisAnimations | |
53 | \value SeriesAnimations |
|
53 | \value SeriesAnimations | |
54 | \value AllAnimations |
|
54 | \value AllAnimations | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | \class QChart |
|
58 | \class QChart | |
59 | \brief QtCommercial chart API. |
|
59 | \brief QtCommercial chart API. | |
60 |
|
60 | |||
61 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
61 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
62 | representation of different types of series and other chart related objects like |
|
62 | representation of different types of series and other chart related objects like | |
63 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the |
|
63 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the | |
64 | convenience class QChartView instead of QChart. |
|
64 | convenience class QChartView instead of QChart. | |
65 | \sa QChartView |
|
65 | \sa QChartView | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
69 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
70 | */ |
|
70 | */ | |
71 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
71 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
72 | d_ptr(new QChartPrivate()) |
|
72 | d_ptr(new QChartPrivate()) | |
73 | { |
|
73 | { | |
74 | d_ptr->m_dataset = new ChartDataSet(this); |
|
74 | d_ptr->m_dataset = new ChartDataSet(this); | |
75 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
75 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); | |
76 | d_ptr->createConnections(); |
|
76 | d_ptr->createConnections(); | |
77 | d_ptr->m_legend = new LegendScroller(this); |
|
77 | d_ptr->m_legend = new LegendScroller(this); | |
78 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); |
|
78 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 | Destroys the object and it's children, like series and axis objects added to it. |
|
82 | Destroys the object and it's children, like series and axis objects added to it. | |
83 | */ |
|
83 | */ | |
84 | QChart::~QChart() |
|
84 | QChart::~QChart() | |
85 | { |
|
85 | { | |
86 | //delete first presenter , since this is a root of all the graphical items |
|
86 | //delete first presenter , since this is a root of all the graphical items | |
87 | delete d_ptr->m_presenter; |
|
87 | delete d_ptr->m_presenter; | |
88 | d_ptr->m_presenter=0; |
|
88 | d_ptr->m_presenter=0; | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | /*! |
|
91 | /*! | |
92 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
92 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
93 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
93 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
94 | the y axis). |
|
94 | the y axis). | |
|
95 | ||||
|
96 | \sa removeSeries(), removeAllSeries() | |||
95 | */ |
|
97 | */ | |
96 | void QChart::addSeries(QAbstractSeries *series, QAxis *axisY) |
|
98 | void QChart::addSeries(QAbstractSeries *series, QAxis *axisY) | |
97 | { |
|
99 | { | |
98 | Q_ASSERT(series); |
|
100 | Q_ASSERT(series); | |
99 | d_ptr->m_dataset->addSeries(series, axisY); |
|
101 | d_ptr->m_dataset->addSeries(series, axisY); | |
100 | } |
|
102 | } | |
101 |
|
103 | |||
102 | /*! |
|
104 | /*! | |
103 | Removes the \a series specified in a perameter from the QChartView. |
|
105 | Removes the \a series specified in a perameter from the QChartView. | |
104 | It releses its ownership of the specified QChartSeries object. |
|
106 | It releses its ownership of the specified QChartSeries object. | |
105 | It does not delete the pointed QChartSeries data object |
|
107 | It does not delete the pointed QChartSeries data object | |
106 | \sa addSeries(), removeAllSeries() |
|
108 | \sa addSeries(), removeAllSeries() | |
107 | */ |
|
109 | */ | |
108 | void QChart::removeSeries(QAbstractSeries *series) |
|
110 | void QChart::removeSeries(QAbstractSeries *series) | |
109 | { |
|
111 | { | |
110 | Q_ASSERT(series); |
|
112 | Q_ASSERT(series); | |
111 | d_ptr->m_dataset->removeSeries(series); |
|
113 | d_ptr->m_dataset->removeSeries(series); | |
112 | } |
|
114 | } | |
113 |
|
115 | |||
114 | /*! |
|
116 | /*! | |
115 | Removes all the QChartSeries that have been added to the QChartView |
|
117 | Removes all the QChartSeries that have been added to the QChartView | |
116 | It also deletes the pointed QChartSeries data objects |
|
118 | It also deletes the pointed QChartSeries data objects | |
117 | \sa addSeries(), removeSeries() |
|
119 | \sa addSeries(), removeSeries() | |
118 | */ |
|
120 | */ | |
119 | void QChart::removeAllSeries() |
|
121 | void QChart::removeAllSeries() | |
120 | { |
|
122 | { | |
121 | d_ptr->m_dataset->removeAllSeries(); |
|
123 | d_ptr->m_dataset->removeAllSeries(); | |
122 | } |
|
124 | } | |
123 |
|
125 | |||
124 | /*! |
|
126 | /*! | |
125 | Sets the \a brush that is used for painting the background of the chart area. |
|
127 | Sets the \a brush that is used for painting the background of the chart area. | |
126 | */ |
|
128 | */ | |
127 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
129 | void QChart::setBackgroundBrush(const QBrush& brush) | |
128 | { |
|
130 | { | |
129 | //TODO: refactor me |
|
131 | //TODO: refactor me | |
130 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
132 | d_ptr->m_presenter->createChartBackgroundItem(); | |
131 | d_ptr->m_presenter->m_backgroundItem->setBrush(brush); |
|
133 | d_ptr->m_presenter->m_backgroundItem->setBrush(brush); | |
132 | d_ptr->m_presenter->m_backgroundItem->update(); |
|
134 | d_ptr->m_presenter->m_backgroundItem->update(); | |
133 | } |
|
135 | } | |
134 |
|
136 | |||
135 | /*! |
|
137 | /*! | |
136 | Gets the brush that is used for painting the background of the chart area. |
|
138 | Gets the brush that is used for painting the background of the chart area. | |
137 | */ |
|
139 | */ | |
138 | QBrush QChart::backgroundBrush() const |
|
140 | QBrush QChart::backgroundBrush() const | |
139 | { |
|
141 | { | |
140 | //TODO: refactor me |
|
142 | //TODO: refactor me | |
141 | if (!d_ptr->m_presenter->m_backgroundItem) return QBrush(); |
|
143 | if (!d_ptr->m_presenter->m_backgroundItem) return QBrush(); | |
142 | return (d_ptr->m_presenter->m_backgroundItem)->brush(); |
|
144 | return (d_ptr->m_presenter->m_backgroundItem)->brush(); | |
143 | } |
|
145 | } | |
144 |
|
146 | |||
145 | /*! |
|
147 | /*! | |
146 | Sets the \a pen that is used for painting the background of the chart area. |
|
148 | Sets the \a pen that is used for painting the background of the chart area. | |
147 | */ |
|
149 | */ | |
148 | void QChart::setBackgroundPen(const QPen& pen) |
|
150 | void QChart::setBackgroundPen(const QPen& pen) | |
149 | { |
|
151 | { | |
150 | //TODO: refactor me |
|
152 | //TODO: refactor me | |
151 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
153 | d_ptr->m_presenter->createChartBackgroundItem(); | |
152 | d_ptr->m_presenter->m_backgroundItem->setPen(pen); |
|
154 | d_ptr->m_presenter->m_backgroundItem->setPen(pen); | |
153 | d_ptr->m_presenter->m_backgroundItem->update(); |
|
155 | d_ptr->m_presenter->m_backgroundItem->update(); | |
154 | } |
|
156 | } | |
155 |
|
157 | |||
156 | /*! |
|
158 | /*! | |
157 | Gets the pen that is used for painting the background of the chart area. |
|
159 | Gets the pen that is used for painting the background of the chart area. | |
158 | */ |
|
160 | */ | |
159 | QPen QChart::backgroundPen() const |
|
161 | QPen QChart::backgroundPen() const | |
160 | { |
|
162 | { | |
161 | //TODO: refactor me |
|
163 | //TODO: refactor me | |
162 | if (!d_ptr->m_presenter->m_backgroundItem) return QPen(); |
|
164 | if (!d_ptr->m_presenter->m_backgroundItem) return QPen(); | |
163 | return d_ptr->m_presenter->m_backgroundItem->pen(); |
|
165 | return d_ptr->m_presenter->m_backgroundItem->pen(); | |
164 | } |
|
166 | } | |
165 |
|
167 | |||
166 | /*! |
|
168 | /*! | |
167 | Sets the chart \a title. The description text that is drawn above the chart. |
|
169 | Sets the chart \a title. The description text that is drawn above the chart. | |
168 | */ |
|
170 | */ | |
169 | void QChart::setTitle(const QString& title) |
|
171 | void QChart::setTitle(const QString& title) | |
170 | { |
|
172 | { | |
171 | //TODO: refactor me |
|
173 | //TODO: refactor me | |
172 | d_ptr->m_presenter->createChartTitleItem(); |
|
174 | d_ptr->m_presenter->createChartTitleItem(); | |
173 | d_ptr->m_presenter->m_titleItem->setText(title); |
|
175 | d_ptr->m_presenter->m_titleItem->setText(title); | |
174 | d_ptr->m_presenter->updateLayout(); |
|
176 | d_ptr->m_presenter->updateLayout(); | |
175 | } |
|
177 | } | |
176 |
|
178 | |||
177 | /*! |
|
179 | /*! | |
178 | Returns the chart title. The description text that is drawn above the chart. |
|
180 | Returns the chart title. The description text that is drawn above the chart. | |
179 | */ |
|
181 | */ | |
180 | QString QChart::title() const |
|
182 | QString QChart::title() const | |
181 | { |
|
183 | { | |
182 | //TODO: refactor me |
|
184 | //TODO: refactor me | |
183 | if (d_ptr->m_presenter->m_titleItem) |
|
185 | if (d_ptr->m_presenter->m_titleItem) | |
184 | return d_ptr->m_presenter->m_titleItem->text(); |
|
186 | return d_ptr->m_presenter->m_titleItem->text(); | |
185 | else |
|
187 | else | |
186 | return QString(); |
|
188 | return QString(); | |
187 | } |
|
189 | } | |
188 |
|
190 | |||
189 | /*! |
|
191 | /*! | |
190 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. |
|
192 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. | |
191 | */ |
|
193 | */ | |
192 | void QChart::setTitleFont(const QFont& font) |
|
194 | void QChart::setTitleFont(const QFont& font) | |
193 | { |
|
195 | { | |
194 | //TODO: refactor me |
|
196 | //TODO: refactor me | |
195 | d_ptr->m_presenter->createChartTitleItem(); |
|
197 | d_ptr->m_presenter->createChartTitleItem(); | |
196 | d_ptr->m_presenter->m_titleItem->setFont(font); |
|
198 | d_ptr->m_presenter->m_titleItem->setFont(font); | |
197 | d_ptr->m_presenter->updateLayout(); |
|
199 | d_ptr->m_presenter->updateLayout(); | |
198 | } |
|
200 | } | |
199 |
|
201 | |||
200 | /*! |
|
202 | /*! | |
201 | Gets the font that is used for drawing the chart description text that is rendered above the chart. |
|
203 | Gets the font that is used for drawing the chart description text that is rendered above the chart. | |
202 | */ |
|
204 | */ | |
203 | QFont QChart::titleFont() const |
|
205 | QFont QChart::titleFont() const | |
204 | { |
|
206 | { | |
205 | if (d_ptr->m_presenter->m_titleItem) |
|
207 | if (d_ptr->m_presenter->m_titleItem) | |
206 | return d_ptr->m_presenter->m_titleItem->font(); |
|
208 | return d_ptr->m_presenter->m_titleItem->font(); | |
207 | else |
|
209 | else | |
208 | return QFont(); |
|
210 | return QFont(); | |
209 | } |
|
211 | } | |
210 |
|
212 | |||
211 | /*! |
|
213 | /*! | |
212 | Sets the \a brush used for rendering the title text. |
|
214 | Sets the \a brush used for rendering the title text. | |
213 | */ |
|
215 | */ | |
214 | void QChart::setTitleBrush(const QBrush &brush) |
|
216 | void QChart::setTitleBrush(const QBrush &brush) | |
215 | { |
|
217 | { | |
216 | //TODO: refactor me |
|
218 | //TODO: refactor me | |
217 | d_ptr->m_presenter->createChartTitleItem(); |
|
219 | d_ptr->m_presenter->createChartTitleItem(); | |
218 | d_ptr->m_presenter->m_titleItem->setBrush(brush); |
|
220 | d_ptr->m_presenter->m_titleItem->setBrush(brush); | |
219 | d_ptr->m_presenter->updateLayout(); |
|
221 | d_ptr->m_presenter->updateLayout(); | |
220 | } |
|
222 | } | |
221 |
|
223 | |||
222 | /*! |
|
224 | /*! | |
223 | Returns the brush used for rendering the title text. |
|
225 | Returns the brush used for rendering the title text. | |
224 | */ |
|
226 | */ | |
225 | QBrush QChart::titleBrush() const |
|
227 | QBrush QChart::titleBrush() const | |
226 | { |
|
228 | { | |
227 | //TODO: refactor me |
|
229 | //TODO: refactor me | |
228 | if (!d_ptr->m_presenter->m_titleItem) return QBrush(); |
|
230 | if (!d_ptr->m_presenter->m_titleItem) return QBrush(); | |
229 | return d_ptr->m_presenter->m_titleItem->brush(); |
|
231 | return d_ptr->m_presenter->m_titleItem->brush(); | |
230 | } |
|
232 | } | |
231 |
|
233 | |||
232 | /*! |
|
234 | /*! | |
233 | Sets the \a theme used by the chart for rendering the graphical representation of the data. |
|
235 | Sets the \a theme used by the chart for rendering the graphical representation of the data. | |
234 |
|
236 | |||
235 | Note: changing the theme will overwrite all customizations (pen, brush, font, ect.) done to the series. |
|
237 | Note: changing the theme will overwrite all customizations (pen, brush, font, ect.) done to the series. | |
236 | \sa theme() |
|
238 | \sa theme() | |
237 | */ |
|
239 | */ | |
238 | void QChart::setTheme(QChart::ChartTheme theme) |
|
240 | void QChart::setTheme(QChart::ChartTheme theme) | |
239 | { |
|
241 | { | |
240 | d_ptr->m_presenter->setTheme(theme); |
|
242 | d_ptr->m_presenter->setTheme(theme); | |
241 | } |
|
243 | } | |
242 |
|
244 | |||
243 | /*! |
|
245 | /*! | |
244 | Returns the theme enum used by the chart. |
|
246 | Returns the theme enum used by the chart. | |
245 | \sa ChartTheme, setTheme() |
|
247 | \sa ChartTheme, setTheme() | |
246 | */ |
|
248 | */ | |
247 | QChart::ChartTheme QChart::theme() const |
|
249 | QChart::ChartTheme QChart::theme() const | |
248 | { |
|
250 | { | |
249 | return d_ptr->m_presenter->theme(); |
|
251 | return d_ptr->m_presenter->theme(); | |
250 | } |
|
252 | } | |
251 |
|
253 | |||
252 | /*! |
|
254 | /*! | |
253 | Zooms in the view by a factor of 2 |
|
255 | Zooms in the view by a factor of 2 | |
254 | */ |
|
256 | */ | |
255 | void QChart::zoomIn() |
|
257 | void QChart::zoomIn() | |
256 | { |
|
258 | { | |
257 | d_ptr->m_presenter->zoomIn(2.0); |
|
259 | d_ptr->m_presenter->zoomIn(2.0); | |
258 | } |
|
260 | } | |
259 |
|
261 | |||
260 | /*! |
|
262 | /*! | |
261 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
263 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
262 | */ |
|
264 | */ | |
263 | void QChart::zoomIn(const QRectF& rect) |
|
265 | void QChart::zoomIn(const QRectF& rect) | |
264 | { |
|
266 | { | |
265 | if (!rect.isValid()) return; |
|
267 | if (!rect.isValid()) return; | |
266 | d_ptr->m_presenter->zoomIn(rect); |
|
268 | d_ptr->m_presenter->zoomIn(rect); | |
267 | } |
|
269 | } | |
268 |
|
270 | |||
269 | /*! |
|
271 | /*! | |
270 | Restores the view zoom level to the previous one. |
|
272 | Restores the view zoom level to the previous one. | |
271 | */ |
|
273 | */ | |
272 | void QChart::zoomOut() |
|
274 | void QChart::zoomOut() | |
273 | { |
|
275 | { | |
274 | d_ptr->m_presenter->zoomOut(2.0); |
|
276 | d_ptr->m_presenter->zoomOut(2.0); | |
275 | } |
|
277 | } | |
276 |
|
278 | |||
277 | /*! |
|
279 | /*! | |
278 | Zooms in the view by a \a factor. |
|
280 | Zooms in the view by a \a factor. | |
279 |
|
281 | |||
280 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
282 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. | |
281 | */ |
|
283 | */ | |
282 | void QChart::zoom(qreal factor) |
|
284 | void QChart::zoom(qreal factor) | |
283 | { |
|
285 | { | |
284 | if (qFuzzyIsNull(factor)) |
|
286 | if (qFuzzyIsNull(factor)) | |
285 | return; |
|
287 | return; | |
286 |
|
288 | |||
287 | if (qFuzzyCompare(factor, 1.0)) |
|
289 | if (qFuzzyCompare(factor, 1.0)) | |
288 | return; |
|
290 | return; | |
289 |
|
291 | |||
290 | if (factor < 0) |
|
292 | if (factor < 0) | |
291 | return; |
|
293 | return; | |
292 |
|
294 | |||
293 | if (factor > 1.0) |
|
295 | if (factor > 1.0) | |
294 | d_ptr->m_presenter->zoomIn(factor); |
|
296 | d_ptr->m_presenter->zoomIn(factor); | |
295 | else |
|
297 | else | |
296 | d_ptr->m_presenter->zoomOut(1.0 / factor); |
|
298 | d_ptr->m_presenter->zoomOut(1.0 / factor); | |
297 | } |
|
299 | } | |
298 |
|
300 | |||
299 | /*! |
|
301 | /*! | |
300 | Returns the pointer to the x axis object of the chart |
|
302 | Returns the pointer to the x axis object of the chart | |
301 | */ |
|
303 | */ | |
302 | QAxis* QChart::axisX() const |
|
304 | QAxis* QChart::axisX() const | |
303 | { |
|
305 | { | |
304 | return d_ptr->m_dataset->axisX(); |
|
306 | return d_ptr->m_dataset->axisX(); | |
305 | } |
|
307 | } | |
306 |
|
308 | |||
307 | /*! |
|
309 | /*! | |
308 | Returns the pointer to the y axis object of the \a series |
|
310 | Returns the pointer to the y axis object of the \a series | |
309 | If no \a series is provided then default Y axis of the chart is returned. |
|
311 | If no \a series is provided then default Y axis of the chart is returned. | |
310 | */ |
|
312 | */ | |
311 | QAxis* QChart::axisY(QAbstractSeries *series) const |
|
313 | QAxis* QChart::axisY(QAbstractSeries *series) const | |
312 | { |
|
314 | { | |
313 | return d_ptr->m_dataset->axisY(series); |
|
315 | return d_ptr->m_dataset->axisY(series); | |
314 | } |
|
316 | } | |
315 |
|
317 | |||
316 | /*! |
|
318 | /*! | |
317 | Returns the legend object of the chart. Ownership stays in chart. |
|
319 | Returns the legend object of the chart. Ownership stays in chart. | |
318 | */ |
|
320 | */ | |
319 | QLegend* QChart::legend() const |
|
321 | QLegend* QChart::legend() const | |
320 | { |
|
322 | { | |
321 | return d_ptr->m_legend; |
|
323 | return d_ptr->m_legend; | |
322 | } |
|
324 | } | |
323 |
|
325 | |||
324 | /*! |
|
326 | /*! | |
325 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
327 | Returns the rect that contains information about margins (distance between chart widget edge and axes). | |
326 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
328 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. | |
327 | */ |
|
329 | */ | |
328 | QRectF QChart::margins() const |
|
330 | QRectF QChart::margins() const | |
329 | { |
|
331 | { | |
330 | return d_ptr->m_presenter->margins(); |
|
332 | return d_ptr->m_presenter->margins(); | |
331 | } |
|
333 | } | |
332 |
|
334 | |||
333 |
|
335 | |||
334 | /*! |
|
336 | /*! | |
335 | Resizes and updates the chart area using the \a event data |
|
337 | Resizes and updates the chart area using the \a event data | |
336 | */ |
|
338 | */ | |
337 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
339 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
338 | { |
|
340 | { | |
339 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
341 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); | |
340 | QGraphicsWidget::resizeEvent(event); |
|
342 | QGraphicsWidget::resizeEvent(event); | |
341 | d_ptr->m_presenter->setGeometry(d_ptr->m_rect); |
|
343 | d_ptr->m_presenter->setGeometry(d_ptr->m_rect); | |
342 | } |
|
344 | } | |
343 |
|
345 | |||
344 | /*! |
|
346 | /*! | |
345 | Sets animation \a options for the chart |
|
347 | Sets animation \a options for the chart | |
346 | */ |
|
348 | */ | |
347 | void QChart::setAnimationOptions(AnimationOptions options) |
|
349 | void QChart::setAnimationOptions(AnimationOptions options) | |
348 | { |
|
350 | { | |
349 | d_ptr->m_presenter->setAnimationOptions(options); |
|
351 | d_ptr->m_presenter->setAnimationOptions(options); | |
350 | } |
|
352 | } | |
351 |
|
353 | |||
352 | /*! |
|
354 | /*! | |
353 | Returns animation options for the chart |
|
355 | Returns animation options for the chart | |
354 | */ |
|
356 | */ | |
355 | QChart::AnimationOptions QChart::animationOptions() const |
|
357 | QChart::AnimationOptions QChart::animationOptions() const | |
356 | { |
|
358 | { | |
357 | return d_ptr->m_presenter->animationOptions(); |
|
359 | return d_ptr->m_presenter->animationOptions(); | |
358 | } |
|
360 | } | |
359 |
|
361 | |||
360 | /*! |
|
362 | /*! | |
361 | Scrolls the visible area of the chart to the left by the distance between two x axis ticks |
|
363 | Scrolls the visible area of the chart to the left by the distance between two x axis ticks | |
362 | */ |
|
364 | */ | |
363 | void QChart::scrollLeft() |
|
365 | void QChart::scrollLeft() | |
364 | { |
|
366 | { | |
365 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); |
|
367 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); | |
366 | } |
|
368 | } | |
367 |
|
369 | |||
368 | /*! |
|
370 | /*! | |
369 | Scrolls the visible area of the chart to the right by the distance between two x axis ticks |
|
371 | Scrolls the visible area of the chart to the right by the distance between two x axis ticks | |
370 | */ |
|
372 | */ | |
371 | void QChart::scrollRight() |
|
373 | void QChart::scrollRight() | |
372 | { |
|
374 | { | |
373 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); |
|
375 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); | |
374 | } |
|
376 | } | |
375 |
|
377 | |||
376 | /*! |
|
378 | /*! | |
377 | Scrolls the visible area of the chart up by the distance between two y axis ticks |
|
379 | Scrolls the visible area of the chart up by the distance between two y axis ticks | |
378 | */ |
|
380 | */ | |
379 | void QChart::scrollUp() |
|
381 | void QChart::scrollUp() | |
380 | { |
|
382 | { | |
381 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); |
|
383 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); | |
382 | } |
|
384 | } | |
383 |
|
385 | |||
384 | /*! |
|
386 | /*! | |
385 | Scrolls the visible area of the chart down by the distance between two y axis ticks |
|
387 | Scrolls the visible area of the chart down by the distance between two y axis ticks | |
386 | */ |
|
388 | */ | |
387 | void QChart::scrollDown() |
|
389 | void QChart::scrollDown() | |
388 | { |
|
390 | { | |
389 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); |
|
391 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); | |
390 | } |
|
392 | } | |
391 |
|
393 | |||
392 | /*! |
|
394 | /*! | |
393 | Scrolls the visible area of the chart by the distance defined in the \a delta. |
|
395 | Scrolls the visible area of the chart by the distance defined in the \a delta. | |
394 | */ |
|
396 | */ | |
395 | void QChart::scroll(const QPointF &delta) |
|
397 | void QChart::scroll(const QPointF &delta) | |
396 | { |
|
398 | { | |
397 | d_ptr->m_presenter->scroll(-delta.x(), delta.y()); |
|
399 | d_ptr->m_presenter->scroll(-delta.x(), delta.y()); | |
398 | } |
|
400 | } | |
399 |
|
401 | |||
400 | /*! |
|
402 | /*! | |
401 | Sets the chart background visibility state to \a visible |
|
403 | Sets the chart background visibility state to \a visible | |
402 | */ |
|
404 | */ | |
403 | void QChart::setBackgroundVisible(bool visible) |
|
405 | void QChart::setBackgroundVisible(bool visible) | |
404 | { |
|
406 | { | |
405 | //TODO: refactor me |
|
407 | //TODO: refactor me | |
406 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
408 | d_ptr->m_presenter->createChartBackgroundItem(); | |
407 | d_ptr->m_presenter->m_backgroundItem->setVisible(visible); |
|
409 | d_ptr->m_presenter->m_backgroundItem->setVisible(visible); | |
408 | } |
|
410 | } | |
409 |
|
411 | |||
410 | /*! |
|
412 | /*! | |
411 | Returns the chart's background visibility state |
|
413 | Returns the chart's background visibility state | |
412 | */ |
|
414 | */ | |
413 | bool QChart::isBackgroundVisible() const |
|
415 | bool QChart::isBackgroundVisible() const | |
414 | { |
|
416 | { | |
415 | //TODO: refactor me |
|
417 | //TODO: refactor me | |
416 | if (!d_ptr->m_presenter->m_backgroundItem) |
|
418 | if (!d_ptr->m_presenter->m_backgroundItem) | |
417 | return false; |
|
419 | return false; | |
418 |
|
420 | |||
419 | return d_ptr->m_presenter->m_backgroundItem->isVisible(); |
|
421 | return d_ptr->m_presenter->m_backgroundItem->isVisible(); | |
420 | } |
|
422 | } | |
421 |
|
423 | |||
422 | /*! |
|
424 | /*! | |
423 | Sets the background drop shadow effect state to \a enabled. |
|
425 | Sets the background drop shadow effect state to \a enabled. | |
424 | */ |
|
426 | */ | |
425 | void QChart::setBackgroundDropShadowEnabled(bool enabled) |
|
427 | void QChart::setBackgroundDropShadowEnabled(bool enabled) | |
426 | { |
|
428 | { | |
427 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
429 | d_ptr->m_presenter->createChartBackgroundItem(); | |
428 | d_ptr->m_presenter->m_backgroundItem->setDropShadowEnabled(enabled); |
|
430 | d_ptr->m_presenter->m_backgroundItem->setDropShadowEnabled(enabled); | |
429 | } |
|
431 | } | |
430 |
|
432 | |||
431 | /*! |
|
433 | /*! | |
432 | Returns true if the drop shadow effect is enabled for the chart background. |
|
434 | Returns true if the drop shadow effect is enabled for the chart background. | |
433 | */ |
|
435 | */ | |
434 | bool QChart::isBackgroundDropShadowEnabled() const |
|
436 | bool QChart::isBackgroundDropShadowEnabled() const | |
435 | { |
|
437 | { | |
436 | if (!d_ptr->m_presenter->m_backgroundItem) |
|
438 | if (!d_ptr->m_presenter->m_backgroundItem) | |
437 | return false; |
|
439 | return false; | |
438 |
|
440 | |||
439 | return d_ptr->m_presenter->m_backgroundItem->isDropShadowEnabled(); |
|
441 | return d_ptr->m_presenter->m_backgroundItem->isDropShadowEnabled(); | |
440 | } |
|
442 | } | |
441 |
|
443 | |||
|
444 | /*! | |||
|
445 | Returns all the series that are added to the chart. | |||
|
446 | ||||
|
447 | \sa addSeries(), removeSeries(), removeAllSeries() | |||
|
448 | */ | |||
442 | QList<QAbstractSeries*> QChart::series() const |
|
449 | QList<QAbstractSeries*> QChart::series() const | |
443 | { |
|
450 | { | |
444 | return d_ptr->m_dataset->series(); |
|
451 | return d_ptr->m_dataset->series(); | |
445 | } |
|
452 | } | |
446 |
|
453 | |||
447 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
454 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
448 |
|
455 | |||
449 | QChartPrivate::QChartPrivate(): |
|
456 | QChartPrivate::QChartPrivate(): | |
450 | m_legend(0), |
|
457 | m_legend(0), | |
451 | m_dataset(0), |
|
458 | m_dataset(0), | |
452 | m_presenter(0) |
|
459 | m_presenter(0) | |
453 | { |
|
460 | { | |
454 |
|
461 | |||
455 | } |
|
462 | } | |
456 |
|
463 | |||
457 | QChartPrivate::~QChartPrivate() |
|
464 | QChartPrivate::~QChartPrivate() | |
458 | { |
|
465 | { | |
459 |
|
466 | |||
460 | } |
|
467 | } | |
461 |
|
468 | |||
462 | void QChartPrivate::createConnections() |
|
469 | void QChartPrivate::createConnections() | |
463 | { |
|
470 | { | |
464 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
471 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); | |
465 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
472 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
466 | QObject::connect(m_dataset,SIGNAL(axisAdded(QAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAxis*,Domain*))); |
|
473 | QObject::connect(m_dataset,SIGNAL(axisAdded(QAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAxis*,Domain*))); | |
467 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QAxis*)),m_presenter,SLOT(handleAxisRemoved(QAxis*))); |
|
474 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QAxis*)),m_presenter,SLOT(handleAxisRemoved(QAxis*))); | |
468 | } |
|
475 | } | |
469 |
|
476 | |||
470 | #include "moc_qchart.cpp" |
|
477 | #include "moc_qchart.cpp" | |
471 |
|
478 | |||
472 | QTCOMMERCIALCHART_END_NAMESPACE |
|
479 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,594 +1,598 | |||||
1 | #include <QtTest/QtTest> |
|
1 | #include <QtTest/QtTest> | |
2 | #include <qchartview.h> |
|
2 | #include <qchartview.h> | |
3 | #include <qlineseries.h> |
|
3 | #include <qlineseries.h> | |
4 | #include <qareaseries.h> |
|
4 | #include <qareaseries.h> | |
5 | #include <qscatterseries.h> |
|
5 | #include <qscatterseries.h> | |
6 | #include <qsplineseries.h> |
|
6 | #include <qsplineseries.h> | |
7 | #include <qpieseries.h> |
|
7 | #include <qpieseries.h> | |
8 | #include <qbarseries.h> |
|
8 | #include <qbarseries.h> | |
9 | #include <qpercentbarseries.h> |
|
9 | #include <qpercentbarseries.h> | |
10 | #include <qstackedbarseries.h> |
|
10 | #include <qstackedbarseries.h> | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
12 | QTCOMMERCIALCHART_USE_NAMESPACE | |
13 |
|
13 | |||
14 | Q_DECLARE_METATYPE(QAxis *) |
|
14 | Q_DECLARE_METATYPE(QAxis *) | |
15 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
15 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
16 | Q_DECLARE_METATYPE(QChart::AnimationOption) |
|
16 | Q_DECLARE_METATYPE(QChart::AnimationOption) | |
17 | Q_DECLARE_METATYPE(QBrush) |
|
17 | Q_DECLARE_METATYPE(QBrush) | |
18 | Q_DECLARE_METATYPE(QPen) |
|
18 | Q_DECLARE_METATYPE(QPen) | |
19 | Q_DECLARE_METATYPE(QChart::ChartTheme) |
|
19 | Q_DECLARE_METATYPE(QChart::ChartTheme) | |
20 |
|
20 | |||
21 | class tst_QChart : public QObject |
|
21 | class tst_QChart : public QObject | |
22 | { |
|
22 | { | |
23 | Q_OBJECT |
|
23 | Q_OBJECT | |
24 |
|
24 | |||
25 | public slots: |
|
25 | public slots: | |
26 | void initTestCase(); |
|
26 | void initTestCase(); | |
27 | void cleanupTestCase(); |
|
27 | void cleanupTestCase(); | |
28 | void init(); |
|
28 | void init(); | |
29 | void cleanup(); |
|
29 | void cleanup(); | |
30 |
|
30 | |||
31 | private slots: |
|
31 | private slots: | |
32 | void qchart_data(); |
|
32 | void qchart_data(); | |
33 | void qchart(); |
|
33 | void qchart(); | |
34 |
|
34 | |||
35 | void addSeries_data(); |
|
35 | void addSeries_data(); | |
36 | void addSeries(); |
|
36 | void addSeries(); | |
37 | void animationOptions_data(); |
|
37 | void animationOptions_data(); | |
38 | void animationOptions(); |
|
38 | void animationOptions(); | |
39 | void axisX_data(); |
|
39 | void axisX_data(); | |
40 | void axisX(); |
|
40 | void axisX(); | |
41 | void axisY_data(); |
|
41 | void axisY_data(); | |
42 | void axisY(); |
|
42 | void axisY(); | |
43 | void backgroundBrush_data(); |
|
43 | void backgroundBrush_data(); | |
44 | void backgroundBrush(); |
|
44 | void backgroundBrush(); | |
45 | void backgroundPen_data(); |
|
45 | void backgroundPen_data(); | |
46 | void backgroundPen(); |
|
46 | void backgroundPen(); | |
47 | void isBackgroundVisible_data(); |
|
47 | void isBackgroundVisible_data(); | |
48 | void isBackgroundVisible(); |
|
48 | void isBackgroundVisible(); | |
49 | void legend_data(); |
|
49 | void legend_data(); | |
50 | void legend(); |
|
50 | void legend(); | |
51 | void margins_data(); |
|
51 | void margins_data(); | |
52 | void margins(); |
|
52 | void margins(); | |
53 | void removeAllSeries_data(); |
|
53 | void removeAllSeries_data(); | |
54 | void removeAllSeries(); |
|
54 | void removeAllSeries(); | |
55 | void removeSeries_data(); |
|
55 | void removeSeries_data(); | |
56 | void removeSeries(); |
|
56 | void removeSeries(); | |
57 | void scrollDown_data(); |
|
57 | void scrollDown_data(); | |
58 | void scrollDown(); |
|
58 | void scrollDown(); | |
59 | void scrollLeft_data(); |
|
59 | void scrollLeft_data(); | |
60 | void scrollLeft(); |
|
60 | void scrollLeft(); | |
61 | void scrollRight_data(); |
|
61 | void scrollRight_data(); | |
62 | void scrollRight(); |
|
62 | void scrollRight(); | |
63 | void scrollUp_data(); |
|
63 | void scrollUp_data(); | |
64 | void scrollUp(); |
|
64 | void scrollUp(); | |
65 | void theme_data(); |
|
65 | void theme_data(); | |
66 | void theme(); |
|
66 | void theme(); | |
67 | void title_data(); |
|
67 | void title_data(); | |
68 | void title(); |
|
68 | void title(); | |
69 | void titleBrush_data(); |
|
69 | void titleBrush_data(); | |
70 | void titleBrush(); |
|
70 | void titleBrush(); | |
71 | void titleFont_data(); |
|
71 | void titleFont_data(); | |
72 | void titleFont(); |
|
72 | void titleFont(); | |
73 | void zoomIn_data(); |
|
73 | void zoomIn_data(); | |
74 | void zoomIn(); |
|
74 | void zoomIn(); | |
75 | void zoomOut_data(); |
|
75 | void zoomOut_data(); | |
76 | void zoomOut(); |
|
76 | void zoomOut(); | |
77 |
|
77 | |||
78 | private: |
|
78 | private: | |
79 | void createTestData(); |
|
79 | void createTestData(); | |
80 |
|
80 | |||
81 | private: |
|
81 | private: | |
82 | QChartView* m_view; |
|
82 | QChartView* m_view; | |
83 | QChart* m_chart; |
|
83 | QChart* m_chart; | |
84 | }; |
|
84 | }; | |
85 |
|
85 | |||
86 | void tst_QChart::initTestCase() |
|
86 | void tst_QChart::initTestCase() | |
87 | { |
|
87 | { | |
88 |
|
88 | |||
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | void tst_QChart::cleanupTestCase() |
|
91 | void tst_QChart::cleanupTestCase() | |
92 | { |
|
92 | { | |
93 |
|
93 | |||
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | void tst_QChart::init() |
|
96 | void tst_QChart::init() | |
97 | { |
|
97 | { | |
98 | m_view = new QChartView(new QChart()); |
|
98 | m_view = new QChartView(new QChart()); | |
99 | m_chart = m_view->chart(); |
|
99 | m_chart = m_view->chart(); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | void tst_QChart::createTestData() |
|
102 | void tst_QChart::createTestData() | |
103 | { |
|
103 | { | |
104 | QLineSeries* series0 = new QLineSeries(this); |
|
104 | QLineSeries* series0 = new QLineSeries(this); | |
105 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
105 | *series0 << QPointF(0, 0) << QPointF(100, 100); | |
106 | m_chart->addSeries(series0); |
|
106 | m_chart->addSeries(series0); | |
107 | m_view->show(); |
|
107 | m_view->show(); | |
108 | QTest::qWaitForWindowShown(m_view); |
|
108 | QTest::qWaitForWindowShown(m_view); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | void tst_QChart::cleanup() |
|
111 | void tst_QChart::cleanup() | |
112 | { |
|
112 | { | |
113 | delete m_view; |
|
113 | delete m_view; | |
114 | m_view = 0; |
|
114 | m_view = 0; | |
115 | m_chart = 0; |
|
115 | m_chart = 0; | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | void tst_QChart::qchart_data() |
|
118 | void tst_QChart::qchart_data() | |
119 | { |
|
119 | { | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | void tst_QChart::qchart() |
|
122 | void tst_QChart::qchart() | |
123 | { |
|
123 | { | |
124 | QVERIFY(m_chart); |
|
124 | QVERIFY(m_chart); | |
125 | QVERIFY(m_chart->legend()); |
|
125 | QVERIFY(m_chart->legend()); | |
126 | QVERIFY(m_chart->legend()->isVisible()); |
|
126 | QVERIFY(m_chart->legend()->isVisible()); | |
127 |
|
127 | |||
128 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); |
|
128 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); | |
129 | QVERIFY(m_chart->axisX()); |
|
129 | QVERIFY(m_chart->axisX()); | |
130 | QVERIFY(m_chart->axisY()); |
|
130 | QVERIFY(m_chart->axisY()); | |
131 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); |
|
131 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); | |
132 | QVERIFY(m_chart->backgroundPen()!=QPen()); |
|
132 | QVERIFY(m_chart->backgroundPen()!=QPen()); | |
133 | QCOMPARE(m_chart->isBackgroundVisible(), true); |
|
133 | QCOMPARE(m_chart->isBackgroundVisible(), true); | |
134 |
|
134 | |||
135 | QVERIFY(m_chart->margins().top()>0); |
|
135 | QVERIFY(m_chart->margins().top()>0); | |
136 | QVERIFY(m_chart->margins().left()>0); |
|
136 | QVERIFY(m_chart->margins().left()>0); | |
137 | QVERIFY(m_chart->margins().right()>0); |
|
137 | QVERIFY(m_chart->margins().right()>0); | |
138 | QVERIFY(m_chart->margins().bottom()>0); |
|
138 | QVERIFY(m_chart->margins().bottom()>0); | |
139 |
|
139 | |||
140 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); |
|
140 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); | |
141 | QCOMPARE(m_chart->title(), QString()); |
|
141 | QCOMPARE(m_chart->title(), QString()); | |
142 |
|
142 | |||
143 | //QCOMPARE(m_chart->titleBrush(),QBrush()); |
|
143 | //QCOMPARE(m_chart->titleBrush(),QBrush()); | |
144 | //QCOMPARE(m_chart->titleFont(),QFont()); |
|
144 | //QCOMPARE(m_chart->titleFont(),QFont()); | |
145 |
|
145 | |||
146 | m_chart->removeAllSeries(); |
|
146 | m_chart->removeAllSeries(); | |
147 | m_chart->scrollDown(); |
|
147 | m_chart->scrollDown(); | |
148 | m_chart->scrollLeft(); |
|
148 | m_chart->scrollLeft(); | |
149 | m_chart->scrollRight(); |
|
149 | m_chart->scrollRight(); | |
150 | m_chart->scrollUp(); |
|
150 | m_chart->scrollUp(); | |
151 |
|
151 | |||
152 | m_chart->zoomIn(); |
|
152 | m_chart->zoomIn(); | |
153 | m_chart->zoomIn(QRectF()); |
|
153 | m_chart->zoomIn(QRectF()); | |
154 | m_chart->zoomOut(); |
|
154 | m_chart->zoomOut(); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void tst_QChart::addSeries_data() |
|
157 | void tst_QChart::addSeries_data() | |
158 | { |
|
158 | { | |
159 | QTest::addColumn<QAbstractSeries *>("series"); |
|
159 | QTest::addColumn<QAbstractSeries *>("series"); | |
160 | QTest::addColumn<QAxis *>("axis"); |
|
160 | QTest::addColumn<QAxis *>("axis"); | |
161 |
|
161 | |||
162 | QAbstractSeries* series0 = new QLineSeries(this); |
|
162 | QAbstractSeries* series0 = new QLineSeries(this); | |
163 | QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0)); |
|
163 | QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0)); | |
164 | QAbstractSeries* series2 = new QScatterSeries(this); |
|
164 | QAbstractSeries* series2 = new QScatterSeries(this); | |
165 | QAbstractSeries* series3 = new QSplineSeries(this); |
|
165 | QAbstractSeries* series3 = new QSplineSeries(this); | |
166 | QAbstractSeries* series4 = new QPieSeries(this); |
|
166 | QAbstractSeries* series4 = new QPieSeries(this); | |
167 | QAbstractSeries* series5 = new QBarSeries(this); |
|
167 | QAbstractSeries* series5 = new QBarSeries(this); | |
168 | QAbstractSeries* series6 = new QPercentBarSeries(this); |
|
168 | QAbstractSeries* series6 = new QPercentBarSeries(this); | |
169 | QAbstractSeries* series7 = new QStackedBarSeries(this); |
|
169 | QAbstractSeries* series7 = new QStackedBarSeries(this); | |
170 |
|
170 | |||
171 | QBarSeries* s5 = static_cast<QBarSeries*> (series5); |
|
171 | QBarSeries* s5 = static_cast<QBarSeries*> (series5); | |
172 | s5->setCategories(QBarCategories()); |
|
172 | s5->setCategories(QBarCategories()); | |
173 | QPercentBarSeries* s6 = static_cast<QPercentBarSeries*> (series6); |
|
173 | QPercentBarSeries* s6 = static_cast<QPercentBarSeries*> (series6); | |
174 | s6->setCategories(QBarCategories()); |
|
174 | s6->setCategories(QBarCategories()); | |
175 | QStackedBarSeries* s7 = static_cast<QStackedBarSeries*> (series7); |
|
175 | QStackedBarSeries* s7 = static_cast<QStackedBarSeries*> (series7); | |
176 | s7->setCategories(QBarCategories()); |
|
176 | s7->setCategories(QBarCategories()); | |
177 |
|
177 | |||
178 | QAxis* axis = new QAxis(this); |
|
178 | QAxis* axis = new QAxis(this); | |
179 |
|
179 | |||
180 | QTest::newRow("default axis: lineSeries") << series0 << (QAxis*) 0; |
|
180 | QTest::newRow("default axis: lineSeries") << series0 << (QAxis*) 0; | |
181 | QTest::newRow("axis0: lineSeries") << series0 << axis; |
|
181 | QTest::newRow("axis0: lineSeries") << series0 << axis; | |
182 | QTest::newRow("default axis: areaSeries") << series1 << (QAxis*) 0; |
|
182 | QTest::newRow("default axis: areaSeries") << series1 << (QAxis*) 0; | |
183 | QTest::newRow("axis: areaSeries") << series1 << axis; |
|
183 | QTest::newRow("axis: areaSeries") << series1 << axis; | |
184 | QTest::newRow("default axis: scatterSeries") << series2 << (QAxis*) 0; |
|
184 | QTest::newRow("default axis: scatterSeries") << series2 << (QAxis*) 0; | |
185 | QTest::newRow("axis1: scatterSeries") << series2 << axis; |
|
185 | QTest::newRow("axis1: scatterSeries") << series2 << axis; | |
186 | QTest::newRow("default axis: splineSeries") << series3 << (QAxis*) 0; |
|
186 | QTest::newRow("default axis: splineSeries") << series3 << (QAxis*) 0; | |
187 | QTest::newRow("axis: splineSeries") << series3 << axis; |
|
187 | QTest::newRow("axis: splineSeries") << series3 << axis; | |
188 | QTest::newRow("default axis: pieSeries") << series4 << (QAxis*) 0; |
|
188 | QTest::newRow("default axis: pieSeries") << series4 << (QAxis*) 0; | |
189 | QTest::newRow("axis: pieSeries") << series4 << axis; |
|
189 | QTest::newRow("axis: pieSeries") << series4 << axis; | |
190 | QTest::newRow("default axis: barSeries") << series5 << (QAxis*) 0; |
|
190 | QTest::newRow("default axis: barSeries") << series5 << (QAxis*) 0; | |
191 | QTest::newRow("axis: barSeries") << series5 << axis; |
|
191 | QTest::newRow("axis: barSeries") << series5 << axis; | |
192 | QTest::newRow("default axis: percentBarSeries") << series6 << (QAxis*) 0; |
|
192 | QTest::newRow("default axis: percentBarSeries") << series6 << (QAxis*) 0; | |
193 | QTest::newRow("axis: barSeries") << series6 << axis; |
|
193 | QTest::newRow("axis: barSeries") << series6 << axis; | |
194 | QTest::newRow("default axis: stackedBarSeries") << series7 << (QAxis*) 0; |
|
194 | QTest::newRow("default axis: stackedBarSeries") << series7 << (QAxis*) 0; | |
195 | QTest::newRow("axis: barSeries") << series7 << axis; |
|
195 | QTest::newRow("axis: barSeries") << series7 << axis; | |
196 |
|
196 | |||
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | void tst_QChart::addSeries() |
|
199 | void tst_QChart::addSeries() | |
200 | { |
|
200 | { | |
201 | QFETCH(QAbstractSeries *, series); |
|
201 | QFETCH(QAbstractSeries *, series); | |
202 | QFETCH(QAxis *, axis); |
|
202 | QFETCH(QAxis *, axis); | |
203 | m_view->show(); |
|
203 | m_view->show(); | |
204 | QTest::qWaitForWindowShown(m_view); |
|
204 | QTest::qWaitForWindowShown(m_view); | |
205 | if(!axis) axis = m_chart->axisY(); |
|
205 | if(!axis) axis = m_chart->axisY(); | |
206 | QVERIFY(!series->chart()); |
|
206 | QVERIFY(!series->chart()); | |
|
207 | QCOMPARE(m_chart->series().count(), 0); | |||
207 | m_chart->addSeries(series,axis); |
|
208 | m_chart->addSeries(series,axis); | |
|
209 | QCOMPARE(m_chart->series().count(), 1); | |||
|
210 | QCOMPARE(m_chart->series().first(), series); | |||
208 | QVERIFY(series->chart() == m_chart); |
|
211 | QVERIFY(series->chart() == m_chart); | |
209 | QCOMPARE(m_chart->axisY(series),axis); |
|
212 | QCOMPARE(m_chart->axisY(series),axis); | |
210 | m_chart->removeSeries(series); |
|
213 | m_chart->removeSeries(series); | |
211 | QVERIFY(!series->chart()); |
|
214 | QVERIFY(!series->chart()); | |
|
215 | QCOMPARE(m_chart->series().count(), 0); | |||
212 | } |
|
216 | } | |
213 |
|
217 | |||
214 | void tst_QChart::animationOptions_data() |
|
218 | void tst_QChart::animationOptions_data() | |
215 | { |
|
219 | { | |
216 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); |
|
220 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); | |
217 | QTest::newRow("AllAnimations") << QChart::AllAnimations; |
|
221 | QTest::newRow("AllAnimations") << QChart::AllAnimations; | |
218 | QTest::newRow("NoAnimation") << QChart::NoAnimation; |
|
222 | QTest::newRow("NoAnimation") << QChart::NoAnimation; | |
219 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; |
|
223 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; | |
220 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; |
|
224 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; | |
221 | } |
|
225 | } | |
222 |
|
226 | |||
223 | void tst_QChart::animationOptions() |
|
227 | void tst_QChart::animationOptions() | |
224 | { |
|
228 | { | |
225 | createTestData(); |
|
229 | createTestData(); | |
226 | QFETCH(QChart::AnimationOption, animationOptions); |
|
230 | QFETCH(QChart::AnimationOption, animationOptions); | |
227 | m_chart->setAnimationOptions(animationOptions); |
|
231 | m_chart->setAnimationOptions(animationOptions); | |
228 | QCOMPARE(m_chart->animationOptions(), animationOptions); |
|
232 | QCOMPARE(m_chart->animationOptions(), animationOptions); | |
229 | } |
|
233 | } | |
230 |
|
234 | |||
231 | void tst_QChart::axisX_data() |
|
235 | void tst_QChart::axisX_data() | |
232 | { |
|
236 | { | |
233 |
|
237 | |||
234 | } |
|
238 | } | |
235 |
|
239 | |||
236 | void tst_QChart::axisX() |
|
240 | void tst_QChart::axisX() | |
237 | { |
|
241 | { | |
238 | QVERIFY(m_chart->axisX()); |
|
242 | QVERIFY(m_chart->axisX()); | |
239 | QAxis* axis = m_chart->axisX(); |
|
243 | QAxis* axis = m_chart->axisX(); | |
240 | createTestData(); |
|
244 | createTestData(); | |
241 | //it should be the same axis |
|
245 | //it should be the same axis | |
242 | QCOMPARE(axis,m_chart->axisX()); |
|
246 | QCOMPARE(axis,m_chart->axisX()); | |
243 | } |
|
247 | } | |
244 |
|
248 | |||
245 | void tst_QChart::axisY_data() |
|
249 | void tst_QChart::axisY_data() | |
246 | { |
|
250 | { | |
247 | QTest::addColumn<QAxis*>("axis0"); |
|
251 | QTest::addColumn<QAxis*>("axis0"); | |
248 | QTest::addColumn<QAxis*>("axis1"); |
|
252 | QTest::addColumn<QAxis*>("axis1"); | |
249 | QTest::addColumn<QAxis*>("axis2"); |
|
253 | QTest::addColumn<QAxis*>("axis2"); | |
250 | QTest::newRow("1 defualt, 2 optional") << (QAxis*)0 << new QAxis() << new QAxis(); |
|
254 | QTest::newRow("1 defualt, 2 optional") << (QAxis*)0 << new QAxis() << new QAxis(); | |
251 | QTest::newRow("3 optional") << new QAxis() << new QAxis() << new QAxis(); |
|
255 | QTest::newRow("3 optional") << new QAxis() << new QAxis() << new QAxis(); | |
252 | } |
|
256 | } | |
253 |
|
257 | |||
254 |
|
258 | |||
255 | void tst_QChart::axisY() |
|
259 | void tst_QChart::axisY() | |
256 | { |
|
260 | { | |
257 | QFETCH(QAxis*, axis0); |
|
261 | QFETCH(QAxis*, axis0); | |
258 | QFETCH(QAxis*, axis1); |
|
262 | QFETCH(QAxis*, axis1); | |
259 | QFETCH(QAxis*, axis2); |
|
263 | QFETCH(QAxis*, axis2); | |
260 |
|
264 | |||
261 | QAxis* defaultAxisY = m_chart->axisY(); |
|
265 | QAxis* defaultAxisY = m_chart->axisY(); | |
262 |
|
266 | |||
263 | QVERIFY2(defaultAxisY, "Missing axisY."); |
|
267 | QVERIFY2(defaultAxisY, "Missing axisY."); | |
264 |
|
268 | |||
265 | QLineSeries* series0 = new QLineSeries(); |
|
269 | QLineSeries* series0 = new QLineSeries(); | |
266 | m_chart->addSeries(series0, axis0); |
|
270 | m_chart->addSeries(series0, axis0); | |
267 |
|
271 | |||
268 | QLineSeries* series1 = new QLineSeries(); |
|
272 | QLineSeries* series1 = new QLineSeries(); | |
269 | m_chart->addSeries(series1, axis1); |
|
273 | m_chart->addSeries(series1, axis1); | |
270 |
|
274 | |||
271 | QLineSeries* series2 = new QLineSeries(); |
|
275 | QLineSeries* series2 = new QLineSeries(); | |
272 | m_chart->addSeries(series2, axis2); |
|
276 | m_chart->addSeries(series2, axis2); | |
273 |
|
277 | |||
274 | if (!axis0) |
|
278 | if (!axis0) | |
275 | axis0 = defaultAxisY; |
|
279 | axis0 = defaultAxisY; | |
276 | if (!axis1) |
|
280 | if (!axis1) | |
277 | axis1 = defaultAxisY; |
|
281 | axis1 = defaultAxisY; | |
278 | if (!axis2) |
|
282 | if (!axis2) | |
279 | axis2 = defaultAxisY; |
|
283 | axis2 = defaultAxisY; | |
280 |
|
284 | |||
281 | QVERIFY(m_chart->axisY(series0) == axis0); |
|
285 | QVERIFY(m_chart->axisY(series0) == axis0); | |
282 | QVERIFY(m_chart->axisY(series1) == axis1); |
|
286 | QVERIFY(m_chart->axisY(series1) == axis1); | |
283 | QVERIFY(m_chart->axisY(series2) == axis2); |
|
287 | QVERIFY(m_chart->axisY(series2) == axis2); | |
284 | } |
|
288 | } | |
285 |
|
289 | |||
286 | void tst_QChart::backgroundBrush_data() |
|
290 | void tst_QChart::backgroundBrush_data() | |
287 | { |
|
291 | { | |
288 | QTest::addColumn<QBrush>("backgroundBrush"); |
|
292 | QTest::addColumn<QBrush>("backgroundBrush"); | |
289 | QTest::newRow("null") << QBrush(); |
|
293 | QTest::newRow("null") << QBrush(); | |
290 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
294 | QTest::newRow("blue") << QBrush(Qt::blue); | |
291 | QTest::newRow("white") << QBrush(Qt::white); |
|
295 | QTest::newRow("white") << QBrush(Qt::white); | |
292 | QTest::newRow("black") << QBrush(Qt::black); |
|
296 | QTest::newRow("black") << QBrush(Qt::black); | |
293 | } |
|
297 | } | |
294 |
|
298 | |||
295 | void tst_QChart::backgroundBrush() |
|
299 | void tst_QChart::backgroundBrush() | |
296 | { |
|
300 | { | |
297 | QFETCH(QBrush, backgroundBrush); |
|
301 | QFETCH(QBrush, backgroundBrush); | |
298 | m_chart->setBackgroundBrush(backgroundBrush); |
|
302 | m_chart->setBackgroundBrush(backgroundBrush); | |
299 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); |
|
303 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); | |
300 | } |
|
304 | } | |
301 |
|
305 | |||
302 | void tst_QChart::backgroundPen_data() |
|
306 | void tst_QChart::backgroundPen_data() | |
303 | { |
|
307 | { | |
304 | QTest::addColumn<QPen>("backgroundPen"); |
|
308 | QTest::addColumn<QPen>("backgroundPen"); | |
305 | QTest::newRow("null") << QPen(); |
|
309 | QTest::newRow("null") << QPen(); | |
306 | QTest::newRow("blue") << QPen(Qt::blue); |
|
310 | QTest::newRow("blue") << QPen(Qt::blue); | |
307 | QTest::newRow("white") << QPen(Qt::white); |
|
311 | QTest::newRow("white") << QPen(Qt::white); | |
308 | QTest::newRow("black") << QPen(Qt::black); |
|
312 | QTest::newRow("black") << QPen(Qt::black); | |
309 | } |
|
313 | } | |
310 |
|
314 | |||
311 |
|
315 | |||
312 | void tst_QChart::backgroundPen() |
|
316 | void tst_QChart::backgroundPen() | |
313 | { |
|
317 | { | |
314 | QFETCH(QPen, backgroundPen); |
|
318 | QFETCH(QPen, backgroundPen); | |
315 | m_chart->setBackgroundPen(backgroundPen); |
|
319 | m_chart->setBackgroundPen(backgroundPen); | |
316 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); |
|
320 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); | |
317 | } |
|
321 | } | |
318 |
|
322 | |||
319 | void tst_QChart::isBackgroundVisible_data() |
|
323 | void tst_QChart::isBackgroundVisible_data() | |
320 | { |
|
324 | { | |
321 | QTest::addColumn<bool>("isBackgroundVisible"); |
|
325 | QTest::addColumn<bool>("isBackgroundVisible"); | |
322 | QTest::newRow("true") << true; |
|
326 | QTest::newRow("true") << true; | |
323 | QTest::newRow("false") << false; |
|
327 | QTest::newRow("false") << false; | |
324 | } |
|
328 | } | |
325 |
|
329 | |||
326 | void tst_QChart::isBackgroundVisible() |
|
330 | void tst_QChart::isBackgroundVisible() | |
327 | { |
|
331 | { | |
328 | QFETCH(bool, isBackgroundVisible); |
|
332 | QFETCH(bool, isBackgroundVisible); | |
329 | m_chart->setBackgroundVisible(isBackgroundVisible); |
|
333 | m_chart->setBackgroundVisible(isBackgroundVisible); | |
330 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); |
|
334 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); | |
331 | } |
|
335 | } | |
332 |
|
336 | |||
333 | void tst_QChart::legend_data() |
|
337 | void tst_QChart::legend_data() | |
334 | { |
|
338 | { | |
335 |
|
339 | |||
336 | } |
|
340 | } | |
337 |
|
341 | |||
338 | void tst_QChart::legend() |
|
342 | void tst_QChart::legend() | |
339 | { |
|
343 | { | |
340 | QVERIFY(m_chart->legend()); |
|
344 | QVERIFY(m_chart->legend()); | |
341 | } |
|
345 | } | |
342 |
|
346 | |||
343 | void tst_QChart::margins_data() |
|
347 | void tst_QChart::margins_data() | |
344 | { |
|
348 | { | |
345 |
|
349 | |||
346 | } |
|
350 | } | |
347 |
|
351 | |||
348 | void tst_QChart::margins() |
|
352 | void tst_QChart::margins() | |
349 | { |
|
353 | { | |
350 | createTestData(); |
|
354 | createTestData(); | |
351 | QRectF rect = m_chart->geometry(); |
|
355 | QRectF rect = m_chart->geometry(); | |
352 |
|
356 | |||
353 | QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); |
|
357 | QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); | |
354 | QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); |
|
358 | QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); | |
355 | } |
|
359 | } | |
356 |
|
360 | |||
357 | void tst_QChart::removeAllSeries_data() |
|
361 | void tst_QChart::removeAllSeries_data() | |
358 | { |
|
362 | { | |
359 |
|
363 | |||
360 | } |
|
364 | } | |
361 |
|
365 | |||
362 | void tst_QChart::removeAllSeries() |
|
366 | void tst_QChart::removeAllSeries() | |
363 | { |
|
367 | { | |
364 | QLineSeries* series0 = new QLineSeries(this); |
|
368 | QLineSeries* series0 = new QLineSeries(this); | |
365 | QLineSeries* series1 = new QLineSeries(this); |
|
369 | QLineSeries* series1 = new QLineSeries(this); | |
366 | QLineSeries* series2 = new QLineSeries(this); |
|
370 | QLineSeries* series2 = new QLineSeries(this); | |
367 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); |
|
371 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); | |
368 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); |
|
372 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); | |
369 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); |
|
373 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); | |
370 |
|
374 | |||
371 | m_chart->addSeries(series0); |
|
375 | m_chart->addSeries(series0); | |
372 | m_chart->addSeries(series1); |
|
376 | m_chart->addSeries(series1); | |
373 | m_chart->addSeries(series2); |
|
377 | m_chart->addSeries(series2); | |
374 | m_view->show(); |
|
378 | m_view->show(); | |
375 | QTest::qWaitForWindowShown(m_view); |
|
379 | QTest::qWaitForWindowShown(m_view); | |
376 |
|
380 | |||
377 | QVERIFY(m_chart->axisY(series0)!=0); |
|
381 | QVERIFY(m_chart->axisY(series0)!=0); | |
378 | QVERIFY(m_chart->axisY(series1)!=0); |
|
382 | QVERIFY(m_chart->axisY(series1)!=0); | |
379 | QVERIFY(m_chart->axisY(series2)!=0); |
|
383 | QVERIFY(m_chart->axisY(series2)!=0); | |
380 |
|
384 | |||
381 | m_chart->removeAllSeries(); |
|
385 | m_chart->removeAllSeries(); | |
382 | QVERIFY(m_chart->axisY(series0)==0); |
|
386 | QVERIFY(m_chart->axisY(series0)==0); | |
383 | QVERIFY(m_chart->axisY(series1)==0); |
|
387 | QVERIFY(m_chart->axisY(series1)==0); | |
384 | QVERIFY(m_chart->axisY(series2)==0); |
|
388 | QVERIFY(m_chart->axisY(series2)==0); | |
385 | QCOMPARE(deleteSpy1.count(), 1); |
|
389 | QCOMPARE(deleteSpy1.count(), 1); | |
386 | QCOMPARE(deleteSpy2.count(), 1); |
|
390 | QCOMPARE(deleteSpy2.count(), 1); | |
387 | QCOMPARE(deleteSpy3.count(), 1); |
|
391 | QCOMPARE(deleteSpy3.count(), 1); | |
388 | } |
|
392 | } | |
389 |
|
393 | |||
390 | void tst_QChart::removeSeries_data() |
|
394 | void tst_QChart::removeSeries_data() | |
391 | { |
|
395 | { | |
392 | addSeries_data(); |
|
396 | addSeries_data(); | |
393 | } |
|
397 | } | |
394 |
|
398 | |||
395 | void tst_QChart::removeSeries() |
|
399 | void tst_QChart::removeSeries() | |
396 | { |
|
400 | { | |
397 | QFETCH(QAbstractSeries *, series); |
|
401 | QFETCH(QAbstractSeries *, series); | |
398 | QFETCH(QAxis *, axis); |
|
402 | QFETCH(QAxis *, axis); | |
399 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); |
|
403 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); | |
400 | m_view->show(); |
|
404 | m_view->show(); | |
401 | QTest::qWaitForWindowShown(m_view); |
|
405 | QTest::qWaitForWindowShown(m_view); | |
402 | if(!axis) axis = m_chart->axisY(); |
|
406 | if(!axis) axis = m_chart->axisY(); | |
403 | m_chart->addSeries(series,axis); |
|
407 | m_chart->addSeries(series,axis); | |
404 | QCOMPARE(m_chart->axisY(series),axis); |
|
408 | QCOMPARE(m_chart->axisY(series),axis); | |
405 | m_chart->removeSeries(series); |
|
409 | m_chart->removeSeries(series); | |
406 | QVERIFY(m_chart->axisY(series)==0); |
|
410 | QVERIFY(m_chart->axisY(series)==0); | |
407 | QCOMPARE(deleteSpy.count(), 0); |
|
411 | QCOMPARE(deleteSpy.count(), 0); | |
408 | } |
|
412 | } | |
409 |
|
413 | |||
410 | void tst_QChart::scrollDown_data() |
|
414 | void tst_QChart::scrollDown_data() | |
411 | { |
|
415 | { | |
412 |
|
416 | |||
413 | } |
|
417 | } | |
414 |
|
418 | |||
415 | void tst_QChart::scrollDown() |
|
419 | void tst_QChart::scrollDown() | |
416 | { |
|
420 | { | |
417 | createTestData(); |
|
421 | createTestData(); | |
418 | qreal min = m_chart->axisY()->min(); |
|
422 | qreal min = m_chart->axisY()->min(); | |
419 | m_chart->scrollDown(); |
|
423 | m_chart->scrollDown(); | |
420 | QVERIFY(m_chart->axisY()->min()<min); |
|
424 | QVERIFY(m_chart->axisY()->min()<min); | |
421 | } |
|
425 | } | |
422 |
|
426 | |||
423 | void tst_QChart::scrollLeft_data() |
|
427 | void tst_QChart::scrollLeft_data() | |
424 | { |
|
428 | { | |
425 |
|
429 | |||
426 | } |
|
430 | } | |
427 |
|
431 | |||
428 | void tst_QChart::scrollLeft() |
|
432 | void tst_QChart::scrollLeft() | |
429 | { |
|
433 | { | |
430 | createTestData(); |
|
434 | createTestData(); | |
431 | qreal min = m_chart->axisX()->min(); |
|
435 | qreal min = m_chart->axisX()->min(); | |
432 | m_chart->scrollLeft(); |
|
436 | m_chart->scrollLeft(); | |
433 | QVERIFY(m_chart->axisX()->min()<min); |
|
437 | QVERIFY(m_chart->axisX()->min()<min); | |
434 | } |
|
438 | } | |
435 |
|
439 | |||
436 | void tst_QChart::scrollRight_data() |
|
440 | void tst_QChart::scrollRight_data() | |
437 | { |
|
441 | { | |
438 |
|
442 | |||
439 | } |
|
443 | } | |
440 |
|
444 | |||
441 | void tst_QChart::scrollRight() |
|
445 | void tst_QChart::scrollRight() | |
442 | { |
|
446 | { | |
443 | createTestData(); |
|
447 | createTestData(); | |
444 | qreal min = m_chart->axisX()->min(); |
|
448 | qreal min = m_chart->axisX()->min(); | |
445 | m_chart->scrollRight(); |
|
449 | m_chart->scrollRight(); | |
446 | QVERIFY(m_chart->axisX()->min()>min); |
|
450 | QVERIFY(m_chart->axisX()->min()>min); | |
447 | } |
|
451 | } | |
448 |
|
452 | |||
449 | void tst_QChart::scrollUp_data() |
|
453 | void tst_QChart::scrollUp_data() | |
450 | { |
|
454 | { | |
451 |
|
455 | |||
452 | } |
|
456 | } | |
453 |
|
457 | |||
454 | void tst_QChart::scrollUp() |
|
458 | void tst_QChart::scrollUp() | |
455 | { |
|
459 | { | |
456 | createTestData(); |
|
460 | createTestData(); | |
457 | qreal min = m_chart->axisY()->min(); |
|
461 | qreal min = m_chart->axisY()->min(); | |
458 | m_chart->scrollUp(); |
|
462 | m_chart->scrollUp(); | |
459 | QVERIFY(m_chart->axisY()->min()>min); |
|
463 | QVERIFY(m_chart->axisY()->min()>min); | |
460 | } |
|
464 | } | |
461 |
|
465 | |||
462 | void tst_QChart::theme_data() |
|
466 | void tst_QChart::theme_data() | |
463 | { |
|
467 | { | |
464 | QTest::addColumn<QChart::ChartTheme>("theme"); |
|
468 | QTest::addColumn<QChart::ChartTheme>("theme"); | |
465 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; |
|
469 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; | |
466 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; |
|
470 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; | |
467 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; |
|
471 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; | |
468 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; |
|
472 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; | |
469 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; |
|
473 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; | |
470 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; |
|
474 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; | |
471 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; |
|
475 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; | |
472 | } |
|
476 | } | |
473 |
|
477 | |||
474 | void tst_QChart::theme() |
|
478 | void tst_QChart::theme() | |
475 | { |
|
479 | { | |
476 | QFETCH(QChart::ChartTheme, theme); |
|
480 | QFETCH(QChart::ChartTheme, theme); | |
477 | createTestData(); |
|
481 | createTestData(); | |
478 | m_chart->setTheme(theme); |
|
482 | m_chart->setTheme(theme); | |
479 | QVERIFY(m_chart->theme()==theme); |
|
483 | QVERIFY(m_chart->theme()==theme); | |
480 | } |
|
484 | } | |
481 |
|
485 | |||
482 | void tst_QChart::title_data() |
|
486 | void tst_QChart::title_data() | |
483 | { |
|
487 | { | |
484 | QTest::addColumn<QString>("title"); |
|
488 | QTest::addColumn<QString>("title"); | |
485 | QTest::newRow("null") << QString(); |
|
489 | QTest::newRow("null") << QString(); | |
486 | QTest::newRow("foo") << QString("foo"); |
|
490 | QTest::newRow("foo") << QString("foo"); | |
487 | } |
|
491 | } | |
488 |
|
492 | |||
489 | void tst_QChart::title() |
|
493 | void tst_QChart::title() | |
490 | { |
|
494 | { | |
491 | QFETCH(QString, title); |
|
495 | QFETCH(QString, title); | |
492 | m_chart->setTitle(title); |
|
496 | m_chart->setTitle(title); | |
493 | QCOMPARE(m_chart->title(), title); |
|
497 | QCOMPARE(m_chart->title(), title); | |
494 | } |
|
498 | } | |
495 |
|
499 | |||
496 | void tst_QChart::titleBrush_data() |
|
500 | void tst_QChart::titleBrush_data() | |
497 | { |
|
501 | { | |
498 | QTest::addColumn<QBrush>("titleBrush"); |
|
502 | QTest::addColumn<QBrush>("titleBrush"); | |
499 | QTest::newRow("null") << QBrush(); |
|
503 | QTest::newRow("null") << QBrush(); | |
500 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
504 | QTest::newRow("blue") << QBrush(Qt::blue); | |
501 | QTest::newRow("white") << QBrush(Qt::white); |
|
505 | QTest::newRow("white") << QBrush(Qt::white); | |
502 | QTest::newRow("black") << QBrush(Qt::black); |
|
506 | QTest::newRow("black") << QBrush(Qt::black); | |
503 | } |
|
507 | } | |
504 |
|
508 | |||
505 | void tst_QChart::titleBrush() |
|
509 | void tst_QChart::titleBrush() | |
506 | { |
|
510 | { | |
507 | QFETCH(QBrush, titleBrush); |
|
511 | QFETCH(QBrush, titleBrush); | |
508 | m_chart->setTitleBrush(titleBrush); |
|
512 | m_chart->setTitleBrush(titleBrush); | |
509 | QCOMPARE(m_chart->titleBrush(), titleBrush); |
|
513 | QCOMPARE(m_chart->titleBrush(), titleBrush); | |
510 | } |
|
514 | } | |
511 |
|
515 | |||
512 | void tst_QChart::titleFont_data() |
|
516 | void tst_QChart::titleFont_data() | |
513 | { |
|
517 | { | |
514 | QTest::addColumn<QFont>("titleFont"); |
|
518 | QTest::addColumn<QFont>("titleFont"); | |
515 | QTest::newRow("null") << QFont(); |
|
519 | QTest::newRow("null") << QFont(); | |
516 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); |
|
520 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); | |
517 | } |
|
521 | } | |
518 |
|
522 | |||
519 | void tst_QChart::titleFont() |
|
523 | void tst_QChart::titleFont() | |
520 | { |
|
524 | { | |
521 | QFETCH(QFont, titleFont); |
|
525 | QFETCH(QFont, titleFont); | |
522 | m_chart->setTitleFont(titleFont); |
|
526 | m_chart->setTitleFont(titleFont); | |
523 | QCOMPARE(m_chart->titleFont(), titleFont); |
|
527 | QCOMPARE(m_chart->titleFont(), titleFont); | |
524 | } |
|
528 | } | |
525 |
|
529 | |||
526 | void tst_QChart::zoomIn_data() |
|
530 | void tst_QChart::zoomIn_data() | |
527 | { |
|
531 | { | |
528 | QTest::addColumn<QRectF>("rect"); |
|
532 | QTest::addColumn<QRectF>("rect"); | |
529 | QTest::newRow("null") << QRectF(); |
|
533 | QTest::newRow("null") << QRectF(); | |
530 | QTest::newRow("100x100") << QRectF(10,10,100,100); |
|
534 | QTest::newRow("100x100") << QRectF(10,10,100,100); | |
531 | QTest::newRow("200x200") << QRectF(10,10,200,200); |
|
535 | QTest::newRow("200x200") << QRectF(10,10,200,200); | |
532 | } |
|
536 | } | |
533 |
|
537 | |||
534 |
|
538 | |||
535 | void tst_QChart::zoomIn() |
|
539 | void tst_QChart::zoomIn() | |
536 | { |
|
540 | { | |
537 | QFETCH(QRectF, rect); |
|
541 | QFETCH(QRectF, rect); | |
538 | createTestData(); |
|
542 | createTestData(); | |
539 | QRectF marigns = m_chart->margins(); |
|
543 | QRectF marigns = m_chart->margins(); | |
540 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); |
|
544 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); | |
541 | qreal minX = m_chart->axisX()->min(); |
|
545 | qreal minX = m_chart->axisX()->min(); | |
542 | qreal minY = m_chart->axisY()->min(); |
|
546 | qreal minY = m_chart->axisY()->min(); | |
543 | qreal maxX = m_chart->axisX()->max(); |
|
547 | qreal maxX = m_chart->axisX()->max(); | |
544 | qreal maxY = m_chart->axisY()->max(); |
|
548 | qreal maxY = m_chart->axisY()->max(); | |
545 | m_chart->zoomIn(rect); |
|
549 | m_chart->zoomIn(rect); | |
546 | if(rect.isValid()){ |
|
550 | if(rect.isValid()){ | |
547 | QVERIFY(minX<m_chart->axisX()->min()); |
|
551 | QVERIFY(minX<m_chart->axisX()->min()); | |
548 | QVERIFY(maxX>m_chart->axisX()->max()); |
|
552 | QVERIFY(maxX>m_chart->axisX()->max()); | |
549 | QVERIFY(minY<m_chart->axisY()->min()); |
|
553 | QVERIFY(minY<m_chart->axisY()->min()); | |
550 | QVERIFY(maxY>m_chart->axisY()->max()); |
|
554 | QVERIFY(maxY>m_chart->axisY()->max()); | |
551 | } |
|
555 | } | |
552 | } |
|
556 | } | |
553 |
|
557 | |||
554 | void tst_QChart::zoomOut_data() |
|
558 | void tst_QChart::zoomOut_data() | |
555 | { |
|
559 | { | |
556 |
|
560 | |||
557 | } |
|
561 | } | |
558 |
|
562 | |||
559 | void tst_QChart::zoomOut() |
|
563 | void tst_QChart::zoomOut() | |
560 | { |
|
564 | { | |
561 | createTestData(); |
|
565 | createTestData(); | |
562 | qreal minX = m_chart->axisX()->min(); |
|
566 | qreal minX = m_chart->axisX()->min(); | |
563 | qreal minY = m_chart->axisY()->min(); |
|
567 | qreal minY = m_chart->axisY()->min(); | |
564 | qreal maxX = m_chart->axisX()->max(); |
|
568 | qreal maxX = m_chart->axisX()->max(); | |
565 | qreal maxY = m_chart->axisY()->max(); |
|
569 | qreal maxY = m_chart->axisY()->max(); | |
566 |
|
570 | |||
567 | m_chart->zoomIn(); |
|
571 | m_chart->zoomIn(); | |
568 |
|
572 | |||
569 | QVERIFY(minX < m_chart->axisX()->min()); |
|
573 | QVERIFY(minX < m_chart->axisX()->min()); | |
570 | QVERIFY(maxX > m_chart->axisX()->max()); |
|
574 | QVERIFY(maxX > m_chart->axisX()->max()); | |
571 | QVERIFY(minY < m_chart->axisY()->min()); |
|
575 | QVERIFY(minY < m_chart->axisY()->min()); | |
572 | QVERIFY(maxY > m_chart->axisY()->max()); |
|
576 | QVERIFY(maxY > m_chart->axisY()->max()); | |
573 |
|
577 | |||
574 | m_chart->zoomOut(); |
|
578 | m_chart->zoomOut(); | |
575 |
|
579 | |||
576 | // min x may be a zero value |
|
580 | // min x may be a zero value | |
577 | if (qFuzzyIsNull(minX)) |
|
581 | if (qFuzzyIsNull(minX)) | |
578 | QVERIFY(qFuzzyIsNull(m_chart->axisX()->min())); |
|
582 | QVERIFY(qFuzzyIsNull(m_chart->axisX()->min())); | |
579 | else |
|
583 | else | |
580 | QCOMPARE(minX, m_chart->axisX()->min()); |
|
584 | QCOMPARE(minX, m_chart->axisX()->min()); | |
581 |
|
585 | |||
582 | // min y may be a zero value |
|
586 | // min y may be a zero value | |
583 | if (qFuzzyIsNull(minY)) |
|
587 | if (qFuzzyIsNull(minY)) | |
584 | QVERIFY(qFuzzyIsNull(m_chart->axisY()->min())); |
|
588 | QVERIFY(qFuzzyIsNull(m_chart->axisY()->min())); | |
585 | else |
|
589 | else | |
586 | QCOMPARE(minY, m_chart->axisY()->min()); |
|
590 | QCOMPARE(minY, m_chart->axisY()->min()); | |
587 |
|
591 | |||
588 | QVERIFY(maxX == m_chart->axisX()->max()); |
|
592 | QVERIFY(maxX == m_chart->axisX()->max()); | |
589 | QVERIFY(maxY == m_chart->axisY()->max()); |
|
593 | QVERIFY(maxY == m_chart->axisY()->max()); | |
590 | } |
|
594 | } | |
591 |
|
595 | |||
592 | QTEST_MAIN(tst_QChart) |
|
596 | QTEST_MAIN(tst_QChart) | |
593 | #include "tst_qchart.moc" |
|
597 | #include "tst_qchart.moc" | |
594 |
|
598 |
General Comments 0
You need to be logged in to leave comments.
Login now