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