@@ -1,501 +1,498 | |||
|
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 "declarativechart.h" |
|
22 | 22 | #include <QPainter> |
|
23 | 23 | #include "declarativelineseries.h" |
|
24 | 24 | #include "declarativeareaseries.h" |
|
25 | 25 | #include "declarativebarseries.h" |
|
26 | 26 | #include "declarativepieseries.h" |
|
27 | 27 | #include "declarativesplineseries.h" |
|
28 | 28 | #include "declarativescatterseries.h" |
|
29 | 29 | #include "qcategoriesaxis.h" |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | |
|
33 | 33 | /*! |
|
34 | 34 | \qmlclass ChartView DeclarativeChart |
|
35 | 35 | |
|
36 | 36 | ChartView element is the parent that is responsible for showing different chart series types. |
|
37 | 37 | |
|
38 | 38 | The following QML shows how to create a simple chart with one pie series: |
|
39 | 39 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
40 | 40 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
41 | 41 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
42 | 42 | |
|
43 | 43 | \beginfloatleft |
|
44 | 44 | \image examples_qmlpiechart.png |
|
45 | 45 | \endfloat |
|
46 | 46 | \clearfloat |
|
47 | 47 | */ |
|
48 | 48 | |
|
49 | 49 | /*! |
|
50 | 50 | \qmlproperty Theme ChartView::theme |
|
51 | 51 | Theme defines the visual appearance of the chart, including for example colors, fonts, line |
|
52 | 52 | widths and chart background. |
|
53 | 53 | */ |
|
54 | 54 | |
|
55 | 55 | /*! |
|
56 | 56 | \qmlproperty Animation ChartView::animation |
|
57 | 57 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, |
|
58 | 58 | ChartView.SeriesAnimations or ChartView.AllAnimations. |
|
59 | 59 | */ |
|
60 | 60 | |
|
61 | 61 | /*! |
|
62 | 62 | \qmlproperty Font ChartView::titleFont |
|
63 | 63 | The title font of the chart |
|
64 | 64 | |
|
65 | 65 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
66 | 66 | */ |
|
67 | 67 | |
|
68 | 68 | /*! |
|
69 | 69 | \qmlproperty string ChartView::title |
|
70 | 70 | The title of the chart, shown on top of the chart. |
|
71 | 71 | \sa ChartView::titleColor |
|
72 | 72 | */ |
|
73 | 73 | |
|
74 | 74 | /*! |
|
75 | 75 | \qmlproperty string ChartView::titleColor |
|
76 | 76 | The color of the title text. |
|
77 | 77 | */ |
|
78 | 78 | |
|
79 | 79 | /*! |
|
80 | 80 | \qmlproperty Axis ChartView::axisX |
|
81 | 81 | The x-axis of the chart. |
|
82 | 82 | */ |
|
83 | 83 | |
|
84 | 84 | /*! |
|
85 | 85 | \qmlproperty Axis ChartView::axisY |
|
86 | 86 | The default y-axis of the chart. |
|
87 | 87 | */ |
|
88 | 88 | |
|
89 | 89 | /*! |
|
90 | 90 | \qmlproperty Legend ChartView::legend |
|
91 | 91 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \qmlproperty int ChartView::count |
|
96 | 96 | The count of series added to the chart. |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \qmlproperty color ChartView::backgroundColor |
|
101 | 101 | The color of the chart's background. By default background color is defined by chart theme. |
|
102 | 102 | \sa ChartView::theme |
|
103 | 103 | */ |
|
104 | 104 | |
|
105 | 105 | /*! |
|
106 | 106 | \qmlproperty bool ChartView::dropShadowEnabled |
|
107 | 107 | The chart's border drop shadow. Set to true to enable drop shadow. |
|
108 | 108 | */ |
|
109 | 109 | |
|
110 | 110 | /*! |
|
111 | 111 | \qmlproperty real ChartView::topMargin |
|
112 | 112 | The space between the top of chart view and the top of the plot area. The title (if non-empty) is drawn on top margin |
|
113 | 113 | area of the chart view. Top margin area is also used by legend, if aligned to top. |
|
114 | 114 | */ |
|
115 | 115 | |
|
116 | 116 | /*! |
|
117 | 117 | \qmlproperty real ChartView::bottomMargin |
|
118 | 118 | The space between the bottom of chart view and the bottom of the plot area. The bottom margin area may be used by |
|
119 | 119 | legend (if aligned to bottom), x-axis, x-axis labels and x-axis tick marks. |
|
120 | 120 | */ |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | \qmlproperty real ChartView::leftMargin |
|
124 | 124 | The space between the left side of chart view and the left side of the plot area. The left margin area may be used by |
|
125 | 125 | legend (if aligned to left), y-axis, y-axis labels and y-axis tick marks. |
|
126 | 126 | */ |
|
127 | 127 | |
|
128 | 128 | /*! |
|
129 | 129 | \qmlproperty real ChartView::rightMargin |
|
130 | 130 | The space between the right side of chart view and the right side of the plot area. The right margin area may be used |
|
131 | 131 | by legend (if aligned to right). |
|
132 | 132 | */ |
|
133 | 133 | |
|
134 | 134 | /*! |
|
135 | 135 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
136 | 136 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
137 | 137 | the count property of the chart. |
|
138 | 138 | */ |
|
139 | 139 | |
|
140 | 140 | /*! |
|
141 | 141 | \qmlmethod AbstractSeries ChartView::series(string name) |
|
142 | 142 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. |
|
143 | 143 | */ |
|
144 | 144 | |
|
145 | 145 | /*! |
|
146 | 146 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name) |
|
147 | 147 | Creates a series object of \a type to the chart. For example: |
|
148 | 148 | \code |
|
149 | 149 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series"); |
|
150 | 150 | scatter.markerSize = 22; |
|
151 | 151 | scatter.append(1.1, 2.0); |
|
152 | 152 | \endcode |
|
153 | 153 | */ |
|
154 | 154 | |
|
155 | 155 | /*! |
|
156 | 156 | \qmlmethod Axis ChartView::axisY(QAbstractSeries *series) |
|
157 | 157 | The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported. |
|
158 | 158 | */ |
|
159 | 159 | |
|
160 | 160 | /*! |
|
161 | 161 | \qmlmethod ChartView::zoomY(real factor) |
|
162 | 162 | Zooms in by \a factor on the center of the chart. |
|
163 | 163 | */ |
|
164 | 164 | |
|
165 | 165 | /*! |
|
166 | 166 | \qmlmethod ChartView::scrollLeft(real pixels) |
|
167 | 167 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. |
|
168 | 168 | \sa Axis::min, Axis::max |
|
169 | 169 | */ |
|
170 | 170 | |
|
171 | 171 | /*! |
|
172 | 172 | \qmlmethod ChartView::scrollRight(real pixels) |
|
173 | 173 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. |
|
174 | 174 | \sa Axis::min, Axis::max |
|
175 | 175 | */ |
|
176 | 176 | |
|
177 | 177 | /*! |
|
178 | 178 | \qmlmethod ChartView::scrollUp(real pixels) |
|
179 | 179 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. |
|
180 | 180 | \sa Axis::min, Axis::max |
|
181 | 181 | */ |
|
182 | 182 | |
|
183 | 183 | /*! |
|
184 | 184 | \qmlmethod ChartView::scrollDown(real pixels) |
|
185 | 185 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. |
|
186 | 186 | \sa Axis::min, Axis::max |
|
187 | 187 | */ |
|
188 | 188 | |
|
189 | 189 | /*! |
|
190 | 190 | \qmlsignal ChartView::onTopMarginChanged(real margin) |
|
191 | 191 | The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
192 | 192 | related properties of the legend or chart title. |
|
193 | 193 | */ |
|
194 | 194 | |
|
195 | 195 | /*! |
|
196 | 196 | \qmlsignal ChartView::onBottomMarginChanged(real margin) |
|
197 | 197 | The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
198 | 198 | related properties of the legend or chart title. |
|
199 | 199 | */ |
|
200 | 200 | |
|
201 | 201 | /*! |
|
202 | 202 | \qmlsignal ChartView::onLeftMarginChanged(real margin) |
|
203 | 203 | The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
204 | 204 | related properties of the legend or chart title. |
|
205 | 205 | */ |
|
206 | 206 | |
|
207 | 207 | /*! |
|
208 | 208 | \qmlsignal ChartView::onRightMarginChanged(real margin) |
|
209 | 209 | The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
210 | 210 | related properties of the legend or chart title. |
|
211 | 211 | */ |
|
212 | 212 | |
|
213 | 213 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
214 | 214 | : QDeclarativeItem(parent), |
|
215 | 215 | m_chart(new QChart(this)) |
|
216 | 216 | { |
|
217 | 217 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
218 | 218 | // m_chart->axisX()->setNiceNumbersEnabled(false); |
|
219 | 219 | m_chartMargins = m_chart->margins(); |
|
220 | 220 | connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF))); |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | 223 | void DeclarativeChart::handleMarginsChanged(QRectF newMargins) |
|
224 | 224 | { |
|
225 | 225 | if (m_chartMargins.top() != newMargins.top()) |
|
226 | 226 | topMarginChanged(m_chart->margins().top()); |
|
227 | 227 | if (m_chartMargins.bottom() != newMargins.bottom()) |
|
228 | 228 | bottomMarginChanged(m_chart->margins().bottom()); |
|
229 | 229 | if (m_chartMargins.left() != newMargins.left()) |
|
230 | 230 | leftMarginChanged(m_chart->margins().left()); |
|
231 | 231 | if (m_chartMargins.right() != newMargins.right()) |
|
232 | 232 | rightMarginChanged(m_chart->margins().right()); |
|
233 | 233 | |
|
234 | 234 | m_chartMargins = m_chart->margins(); |
|
235 | 235 | } |
|
236 | 236 | |
|
237 | 237 | DeclarativeChart::~DeclarativeChart() |
|
238 | 238 | { |
|
239 | 239 | delete m_chart; |
|
240 | 240 | } |
|
241 | 241 | |
|
242 | 242 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
243 | 243 | { |
|
244 | 244 | if (event->type() == QEvent::ChildAdded) { |
|
245 | 245 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
246 | 246 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
247 | 247 | } |
|
248 | 248 | } |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | void DeclarativeChart::componentComplete() |
|
252 | 252 | { |
|
253 | 253 | foreach(QObject *child, children()) { |
|
254 | 254 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
255 | 255 | // qDebug() << "DeclarativeChart::componentComplete(), add: " << child; |
|
256 | 256 | // TODO: how about optional y-axis? |
|
257 | 257 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(child)); |
|
258 | 258 | } |
|
259 | 259 | } |
|
260 | 260 | QDeclarativeItem::componentComplete(); |
|
261 | 261 | } |
|
262 | 262 | |
|
263 | 263 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
264 | 264 | { |
|
265 | 265 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); |
|
266 | 266 | if (newGeometry.isValid()) { |
|
267 | 267 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
268 | 268 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
269 | 269 | } |
|
270 | 270 | } |
|
271 | 271 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); |
|
272 | 272 | } |
|
273 | 273 | |
|
274 | 274 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
275 | 275 | { |
|
276 | 276 | Q_UNUSED(option) |
|
277 | 277 | Q_UNUSED(widget) |
|
278 | 278 | |
|
279 | 279 | // TODO: optimized? |
|
280 | 280 | painter->setRenderHint(QPainter::Antialiasing, true); |
|
281 | 281 | } |
|
282 | 282 | |
|
283 | 283 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
284 | 284 | { |
|
285 | 285 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
286 | 286 | if (chartTheme != m_chart->theme()) |
|
287 | 287 | m_chart->setTheme(chartTheme); |
|
288 | 288 | } |
|
289 | 289 | |
|
290 | 290 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
291 | 291 | { |
|
292 | 292 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
293 | 293 | } |
|
294 | 294 | |
|
295 | 295 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
296 | 296 | { |
|
297 | 297 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
298 | 298 | if (animationOptions != m_chart->animationOptions()) |
|
299 | 299 | m_chart->setAnimationOptions(animationOptions); |
|
300 | 300 | } |
|
301 | 301 | |
|
302 | 302 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
303 | 303 | { |
|
304 | 304 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
305 | 305 | return DeclarativeChart::AllAnimations; |
|
306 | 306 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
307 | 307 | return DeclarativeChart::GridAxisAnimations; |
|
308 | 308 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
309 | 309 | return DeclarativeChart::SeriesAnimations; |
|
310 | 310 | else |
|
311 | 311 | return DeclarativeChart::NoAnimation; |
|
312 | 312 | } |
|
313 | 313 | |
|
314 | 314 | void DeclarativeChart::setTitle(QString title) |
|
315 | 315 | { |
|
316 | 316 | if (title != m_chart->title()) |
|
317 | 317 | m_chart->setTitle(title); |
|
318 | 318 | } |
|
319 | 319 | QString DeclarativeChart::title() |
|
320 | 320 | { |
|
321 | 321 | return m_chart->title(); |
|
322 | 322 | } |
|
323 | 323 | |
|
324 | 324 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) |
|
325 | 325 | { |
|
326 | 326 | return m_chart->axisX(series); |
|
327 | 327 | } |
|
328 | 328 | |
|
329 | 329 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
330 | 330 | { |
|
331 | 331 | return m_chart->axisY(series); |
|
332 | 332 | } |
|
333 | 333 | |
|
334 | 334 | QLegend *DeclarativeChart::legend() |
|
335 | 335 | { |
|
336 | 336 | return m_chart->legend(); |
|
337 | 337 | } |
|
338 | 338 | |
|
339 | 339 | void DeclarativeChart::setTitleColor(QColor color) |
|
340 | 340 | { |
|
341 | 341 | QBrush b = m_chart->titleBrush(); |
|
342 | 342 | if (color != b.color()) { |
|
343 | 343 | b.setColor(color); |
|
344 | 344 | m_chart->setTitleBrush(b); |
|
345 | 345 | emit titleColorChanged(color); |
|
346 | 346 | } |
|
347 | 347 | } |
|
348 | 348 | |
|
349 | 349 | QFont DeclarativeChart::titleFont() const |
|
350 | 350 | { |
|
351 | 351 | return m_chart->titleFont(); |
|
352 | 352 | } |
|
353 | 353 | |
|
354 | 354 | void DeclarativeChart::setTitleFont(const QFont& font) |
|
355 | 355 | { |
|
356 | 356 | m_chart->setTitleFont(font); |
|
357 | 357 | } |
|
358 | 358 | |
|
359 | 359 | QColor DeclarativeChart::titleColor() |
|
360 | 360 | { |
|
361 | 361 | return m_chart->titleBrush().color(); |
|
362 | 362 | } |
|
363 | 363 | |
|
364 | 364 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
365 | 365 | { |
|
366 | 366 | QBrush b = m_chart->backgroundBrush(); |
|
367 | 367 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
368 | 368 | b.setStyle(Qt::SolidPattern); |
|
369 | 369 | b.setColor(color); |
|
370 | 370 | m_chart->setBackgroundBrush(b); |
|
371 | 371 | emit backgroundColorChanged(); |
|
372 | 372 | } |
|
373 | 373 | } |
|
374 | 374 | |
|
375 | 375 | QColor DeclarativeChart::backgroundColor() |
|
376 | 376 | { |
|
377 | 377 | return m_chart->backgroundBrush().color(); |
|
378 | 378 | } |
|
379 | 379 | |
|
380 | 380 | int DeclarativeChart::count() |
|
381 | 381 | { |
|
382 | 382 | return m_chart->series().count(); |
|
383 | 383 | } |
|
384 | 384 | |
|
385 | 385 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
386 | 386 | { |
|
387 | 387 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
388 | 388 | m_chart->setDropShadowEnabled(enabled); |
|
389 | 389 | dropShadowEnabledChanged(enabled); |
|
390 | 390 | } |
|
391 | 391 | } |
|
392 | 392 | |
|
393 | 393 | bool DeclarativeChart::dropShadowEnabled() |
|
394 | 394 | { |
|
395 | 395 | return m_chart->isDropShadowEnabled(); |
|
396 | 396 | } |
|
397 | 397 | |
|
398 | 398 | qreal DeclarativeChart::topMargin() |
|
399 | 399 | { |
|
400 | 400 | return m_chart->margins().top(); |
|
401 | 401 | } |
|
402 | 402 | |
|
403 | 403 | qreal DeclarativeChart::bottomMargin() |
|
404 | 404 | { |
|
405 | 405 | return m_chart->margins().bottom(); |
|
406 | 406 | } |
|
407 | 407 | |
|
408 | 408 | qreal DeclarativeChart::leftMargin() |
|
409 | 409 | { |
|
410 | 410 | return m_chart->margins().left(); |
|
411 | 411 | } |
|
412 | 412 | |
|
413 | 413 | qreal DeclarativeChart::rightMargin() |
|
414 | 414 | { |
|
415 | 415 | return m_chart->margins().right(); |
|
416 | 416 | } |
|
417 | 417 | |
|
418 | 418 | void DeclarativeChart::zoom(qreal factor) |
|
419 | 419 | { |
|
420 | 420 | m_chart->zoom(factor); |
|
421 | 421 | } |
|
422 | 422 | |
|
423 | 423 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
424 | 424 | { |
|
425 | 425 | m_chart->scroll(pixels, 0); |
|
426 | 426 | } |
|
427 | 427 | |
|
428 | 428 | void DeclarativeChart::scrollRight(qreal pixels) |
|
429 | 429 | { |
|
430 | 430 | m_chart->scroll(-pixels, 0); |
|
431 | 431 | } |
|
432 | 432 | |
|
433 | 433 | void DeclarativeChart::scrollUp(qreal pixels) |
|
434 | 434 | { |
|
435 | 435 | m_chart->scroll(0, pixels); |
|
436 | 436 | } |
|
437 | 437 | |
|
438 | 438 | void DeclarativeChart::scrollDown(qreal pixels) |
|
439 | 439 | { |
|
440 | 440 | m_chart->scroll(0, -pixels); |
|
441 | 441 | } |
|
442 | 442 | |
|
443 | 443 | QAbstractSeries *DeclarativeChart::series(int index) |
|
444 | 444 | { |
|
445 | 445 | if (index < m_chart->series().count()) { |
|
446 | 446 | return m_chart->series().at(index); |
|
447 | 447 | } |
|
448 | 448 | return 0; |
|
449 | 449 | } |
|
450 | 450 | |
|
451 | 451 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
452 | 452 | { |
|
453 | 453 | foreach(QAbstractSeries *series, m_chart->series()) { |
|
454 | 454 | if (series->name() == seriesName) |
|
455 | 455 | return series; |
|
456 | 456 | } |
|
457 | 457 | return 0; |
|
458 | 458 | } |
|
459 | 459 | |
|
460 | 460 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) |
|
461 | 461 | { |
|
462 | 462 | QAbstractSeries *series = 0; |
|
463 | 463 | switch (type) { |
|
464 | 464 | case DeclarativeChart::SeriesTypeLine: |
|
465 | 465 | series = new DeclarativeLineSeries(); |
|
466 | 466 | break; |
|
467 | 467 | case DeclarativeChart::SeriesTypeArea: |
|
468 | 468 | series = new DeclarativeAreaSeries(); |
|
469 | 469 | break; |
|
470 | case DeclarativeChart::SeriesTypeBar: | |
|
471 | series = new DeclarativeBarSeries(); | |
|
472 | break; | |
|
473 | 470 | case DeclarativeChart::SeriesTypeStackedBar: |
|
474 | 471 | // TODO |
|
475 | 472 | break; |
|
476 | 473 | case DeclarativeChart::SeriesTypePercentBar: |
|
477 | 474 | // TODO |
|
478 | 475 | break; |
|
479 | 476 | case DeclarativeChart::SeriesTypeGroupedBar: |
|
480 | 477 | series = new DeclarativeGroupedBarSeries(); |
|
481 | 478 | break; |
|
482 | 479 | case DeclarativeChart::SeriesTypePie: |
|
483 | 480 | series = new DeclarativePieSeries(); |
|
484 | 481 | break; |
|
485 | 482 | case DeclarativeChart::SeriesTypeScatter: |
|
486 | 483 | series = new DeclarativeScatterSeries(); |
|
487 | 484 | break; |
|
488 | 485 | case DeclarativeChart::SeriesTypeSpline: |
|
489 | 486 | series = new DeclarativeSplineSeries(); |
|
490 | 487 | break; |
|
491 | 488 | default: |
|
492 | 489 | qWarning() << "Illegal series type"; |
|
493 | 490 | } |
|
494 | 491 | series->setName(name); |
|
495 | 492 | m_chart->addSeries(series); |
|
496 | 493 | return series; |
|
497 | 494 | } |
|
498 | 495 | |
|
499 | 496 | #include "moc_declarativechart.cpp" |
|
500 | 497 | |
|
501 | 498 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,109 +1,108 | |||
|
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 <QtDeclarative/qdeclarativeextensionplugin.h> |
|
22 | 22 | #include <QtDeclarative/qdeclarative.h> |
|
23 | 23 | #include "qchart.h" |
|
24 | 24 | #include "qabstractaxis.h" |
|
25 | 25 | #include "qvaluesaxis.h" |
|
26 | 26 | #include "qcategoriesaxis.h" |
|
27 | 27 | #include "declarativechart.h" |
|
28 | 28 | #include "declarativexypoint.h" |
|
29 | 29 | #include "declarativelineseries.h" |
|
30 | 30 | #include "declarativesplineseries.h" |
|
31 | 31 | #include "declarativeareaseries.h" |
|
32 | 32 | #include "declarativescatterseries.h" |
|
33 | 33 | #include "declarativebarseries.h" |
|
34 | 34 | #include "declarativepieseries.h" |
|
35 | 35 | #include <QVXYModelMapper> |
|
36 | 36 | #include <QHXYModelMapper> |
|
37 | 37 | #include <QHPieModelMapper> |
|
38 | 38 | #include <QVPieModelMapper> |
|
39 | 39 | #include <QHBarModelMapper> |
|
40 | 40 | #include <QVBarModelMapper> |
|
41 | 41 | |
|
42 | 42 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
43 | 43 | |
|
44 | 44 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin |
|
45 | 45 | { |
|
46 | 46 | Q_OBJECT |
|
47 | 47 | public: |
|
48 | 48 | virtual void registerTypes(const char *uri) |
|
49 | 49 | { |
|
50 | 50 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); |
|
51 | 51 | |
|
52 | 52 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); |
|
53 | 53 | qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint"); |
|
54 | 54 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); |
|
55 | 55 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); |
|
56 | 56 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); |
|
57 | 57 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); |
|
58 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); | |
|
59 | 58 | qmlRegisterType<DeclarativeGroupedBarSeries>(uri, 1, 0, "GroupedBarSeries"); |
|
60 | 59 | qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries"); |
|
61 | 60 | qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries"); |
|
62 | 61 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); |
|
63 | 62 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); |
|
64 | 63 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); |
|
65 | 64 | qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper"); |
|
66 | 65 | qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper"); |
|
67 | 66 | qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper"); |
|
68 | 67 | qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper"); |
|
69 | 68 | qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper"); |
|
70 | 69 | qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper"); |
|
71 | 70 | qmlRegisterType<QValuesAxis>(uri, 1, 0, "ValuesAxis"); |
|
72 | 71 | qmlRegisterType<QCategoriesAxis>(uri, 1, 0, "CategoriesAxis"); |
|
73 | 72 | |
|
74 | 73 | qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend", |
|
75 | 74 | QLatin1String("Trying to create uncreatable: Legend.")); |
|
76 | 75 | qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries", |
|
77 | 76 | QLatin1String("Trying to create uncreatable: XYSeries.")); |
|
78 | 77 | qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries", |
|
79 | 78 | QLatin1String("Trying to create uncreatable: QScatterSeries.")); |
|
80 | 79 | qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries", |
|
81 | 80 | QLatin1String("Trying to create uncreatable: QPieSeries.")); |
|
82 | 81 | qmlRegisterUncreatableType<QBarSet>(uri, 1, 0, "QBarSet", |
|
83 | 82 | QLatin1String("Trying to create uncreatable: QBarSet.")); |
|
84 | 83 | qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", |
|
85 | 84 | QLatin1String("Trying to create uncreatable: AbstractItemModel.")); |
|
86 | 85 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", |
|
87 | 86 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); |
|
88 | 87 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
89 | 88 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
90 | 89 | qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper", |
|
91 | 90 | QLatin1String("Trying to create uncreatable: BarModelMapper.")); |
|
92 | 91 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries", |
|
93 | 92 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); |
|
94 | 93 | qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis", |
|
95 | 94 | QLatin1String("Trying to create uncreatable: AbstractAxis.")); |
|
96 | 95 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
97 | 96 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
98 | 97 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", |
|
99 | 98 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); |
|
100 | 99 | } |
|
101 | 100 | }; |
|
102 | 101 | |
|
103 | 102 | #include "plugin.moc" |
|
104 | 103 | |
|
105 | 104 | QTCOMMERCIALCHART_END_NAMESPACE |
|
106 | 105 | |
|
107 | 106 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
108 | 107 | |
|
109 | 108 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
@@ -1,732 +1,724 | |||
|
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 "qabstractbarseries.h" |
|
22 | 22 | #include "qabstractbarseries_p.h" |
|
23 | 23 | #include "qbarset.h" |
|
24 | 24 | #include "qbarset_p.h" |
|
25 | 25 | #include "domain_p.h" |
|
26 | 26 | #include "legendmarker_p.h" |
|
27 | 27 | #include "chartdataset_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | #include "chartanimator_p.h" |
|
30 | 30 | #include "qvaluesaxis.h" |
|
31 | 31 | #include "qcategoriesaxis.h" |
|
32 | 32 | |
|
33 | 33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | 34 | |
|
35 | 35 | /*! |
|
36 | 36 | \class QAbstractBarSeries |
|
37 | 37 | \brief Series for creating a bar chart |
|
38 | 38 | \mainclass |
|
39 | 39 | |
|
40 | 40 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
41 | 41 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
42 | 42 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
43 | 43 | shows the x-values. |
|
44 | 44 | |
|
45 | 45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
46 | 46 | \image examples_barchart.png |
|
47 | 47 | |
|
48 | 48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
49 | 49 | */ |
|
50 | 50 | /*! |
|
51 | 51 | \qmlclass BarSeries QAbstractBarSeries |
|
52 | 52 | \inherits AbstractSeries |
|
53 | 53 | |
|
54 | 54 | The following QML shows how to create a simple bar chart: |
|
55 | 55 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
56 | 56 | |
|
57 | 57 | \beginfloatleft |
|
58 | 58 | \image demos_qmlchart6.png |
|
59 | 59 | \endfloat |
|
60 | 60 | \clearfloat |
|
61 | 61 | */ |
|
62 | 62 | |
|
63 | 63 | /*! |
|
64 | 64 | \property QAbstractBarSeries::barWidth |
|
65 | 65 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
66 | 66 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
67 | 67 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
68 | 68 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
69 | 69 | \sa QGroupedBarSeries |
|
70 | 70 | */ |
|
71 | 71 | /*! |
|
72 | 72 | \qmlproperty real BarSeries::barWidth |
|
73 | 73 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
74 | 74 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
75 | 75 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
76 | 76 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
77 | 77 | */ |
|
78 | 78 | |
|
79 | 79 | /*! |
|
80 | 80 | \property QAbstractBarSeries::count |
|
81 | 81 | Holds the number of sets in series. |
|
82 | 82 | */ |
|
83 | 83 | /*! |
|
84 | 84 | \qmlproperty int BarSeries::count |
|
85 | 85 | Holds the number of sets in series. |
|
86 | 86 | */ |
|
87 | 87 | |
|
88 | 88 | /*! |
|
89 | 89 | \property QAbstractBarSeries::labelsVisible |
|
90 | 90 | Defines the visibility of the labels in series |
|
91 | 91 | */ |
|
92 | 92 | /*! |
|
93 | 93 | \qmlproperty bool BarSeries::labelsVisible |
|
94 | 94 | Defines the visibility of the labels in series |
|
95 | 95 | */ |
|
96 | 96 | |
|
97 | 97 | /*! |
|
98 | 98 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) |
|
99 | 99 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
100 | 100 | Clicked bar inside set is indexed by \a index |
|
101 | 101 | */ |
|
102 | 102 | /*! |
|
103 | 103 | \qmlsignal BarSeries::onClicked(int index, BarSet barset) |
|
104 | 104 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
105 | 105 | Clicked bar inside set is indexed by \a index |
|
106 | 106 | */ |
|
107 | 107 | |
|
108 | 108 | /*! |
|
109 | 109 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) |
|
110 | 110 | |
|
111 | 111 | The signal is emitted if mouse is hovered on top of series. |
|
112 | 112 | Parameter \a barset is the pointer of barset, where hover happened. |
|
113 | 113 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
114 | 114 | */ |
|
115 | 115 | /*! |
|
116 | 116 | \qmlsignal BarSeries::onHovered(bool status, BarSet barset) |
|
117 | 117 | |
|
118 | 118 | The signal is emitted if mouse is hovered on top of series. |
|
119 | 119 | Parameter \a barset is the pointer of barset, where hover happened. |
|
120 | 120 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
121 | 121 | */ |
|
122 | 122 | |
|
123 | 123 | /*! |
|
124 | 124 | \fn void QAbstractBarSeries::countChanged() |
|
125 | 125 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
126 | 126 | */ |
|
127 | 127 | /*! |
|
128 | 128 | \qmlsignal BarSeries::onCountChanged() |
|
129 | 129 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
130 | 130 | */ |
|
131 | 131 | |
|
132 | 132 | /*! |
|
133 | 133 | \fn void QAbstractBarSeries::labelsVisibleChanged() |
|
134 | 134 | This signal is emitted when labels visibility have changed. |
|
135 | 135 | \sa isLabelsVisible(), setLabelsVisible() |
|
136 | 136 | */ |
|
137 | 137 | |
|
138 | 138 | /*! |
|
139 | 139 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
140 | 140 | This signal is emitted when \a sets have been added to the series. |
|
141 | 141 | \sa append(), insert() |
|
142 | 142 | */ |
|
143 | 143 | /*! |
|
144 | 144 | \qmlsignal BarSeries::onAdded(BarSet barset) |
|
145 | 145 | Emitted when \a barset has been added to the series. |
|
146 | 146 | */ |
|
147 | 147 | |
|
148 | 148 | /*! |
|
149 | 149 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
150 | 150 | This signal is emitted when \a sets have been removed from the series. |
|
151 | 151 | \sa remove() |
|
152 | 152 | */ |
|
153 | 153 | /*! |
|
154 | 154 | \qmlsignal BarSeries::onRemoved(BarSet barset) |
|
155 | 155 | Emitted when \a barset has been removed from the series. |
|
156 | 156 | */ |
|
157 | 157 | |
|
158 | 158 | /*! |
|
159 | 159 | \qmlmethod BarSet BarSeries::at(int index) |
|
160 | 160 | Returns bar set at \a index. Returns null if the index is not valid. |
|
161 | 161 | */ |
|
162 | 162 | |
|
163 | 163 | /*! |
|
164 | 164 | \qmlmethod BarSet BarSeries::append(string label, VariantList values) |
|
165 | 165 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
166 | 166 | For example: |
|
167 | 167 | \code |
|
168 | 168 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
169 | 169 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); |
|
170 | 170 | \endcode |
|
171 | 171 | */ |
|
172 | 172 | |
|
173 | 173 | /*! |
|
174 | 174 | \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values) |
|
175 | 175 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
176 | 176 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
177 | 177 | appended. |
|
178 | 178 | \sa BarSeries::append() |
|
179 | 179 | */ |
|
180 | 180 | |
|
181 | 181 | /*! |
|
182 | 182 | \qmlmethod bool BarSeries::remove(BarSet barset) |
|
183 | 183 | Removes the barset from the series. Returns true if successfull, false otherwise. |
|
184 | 184 | */ |
|
185 | 185 | |
|
186 | 186 | /*! |
|
187 | 187 | \qmlmethod BarSeries::clear() |
|
188 | 188 | Removes all barsets from the series. |
|
189 | 189 | */ |
|
190 | 190 | |
|
191 | 191 | /*! |
|
192 | 192 | Constructs empty QAbstractBarSeries. |
|
193 | 193 | QAbstractBarSeries is QObject which is a child of a \a parent. |
|
194 | 194 | */ |
|
195 | 195 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : |
|
196 | 196 | QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent) |
|
197 | 197 | { |
|
198 | 198 | } |
|
199 | 199 | |
|
200 | 200 | /*! |
|
201 | 201 | Destructs barseries and owned barsets. |
|
202 | 202 | */ |
|
203 | 203 | QAbstractBarSeries::~QAbstractBarSeries() |
|
204 | 204 | { |
|
205 | 205 | Q_D(QAbstractBarSeries); |
|
206 | 206 | if(d->m_dataset){ |
|
207 | 207 | d->m_dataset->removeSeries(this); |
|
208 | 208 | } |
|
209 | 209 | } |
|
210 | 210 | |
|
211 | 211 | /*! |
|
212 | 212 | \internal |
|
213 | 213 | */ |
|
214 | 214 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : |
|
215 | 215 | QAbstractSeries(d,parent) |
|
216 | 216 | { |
|
217 | 217 | } |
|
218 | 218 | |
|
219 | 219 | /*! |
|
220 | Returns the type of series. Derived classes override this. | |
|
221 | */ | |
|
222 | QAbstractSeries::SeriesType QAbstractBarSeries::type() const | |
|
223 | { | |
|
224 | return QAbstractSeries::SeriesTypeBar; | |
|
225 | } | |
|
226 | ||
|
227 | /*! | |
|
228 | 220 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
229 | 221 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
230 | 222 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
231 | 223 | Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
232 | 224 | */ |
|
233 | 225 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
234 | 226 | { |
|
235 | 227 | Q_D(QAbstractBarSeries); |
|
236 | 228 | d->setBarWidth(width); |
|
237 | 229 | } |
|
238 | 230 | |
|
239 | 231 | /*! |
|
240 | 232 | Returns the width of the bars of the series. |
|
241 | 233 | \sa setBarWidth() |
|
242 | 234 | */ |
|
243 | 235 | qreal QAbstractBarSeries::barWidth() const |
|
244 | 236 | { |
|
245 | 237 | Q_D(const QAbstractBarSeries); |
|
246 | 238 | return d->barWidth(); |
|
247 | 239 | } |
|
248 | 240 | |
|
249 | 241 | /*! |
|
250 | 242 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
251 | 243 | Returns true, if appending succeeded. |
|
252 | 244 | */ |
|
253 | 245 | bool QAbstractBarSeries::append(QBarSet *set) |
|
254 | 246 | { |
|
255 | 247 | Q_D(QAbstractBarSeries); |
|
256 | 248 | bool success = d->append(set); |
|
257 | 249 | if (success) { |
|
258 | 250 | QList<QBarSet*> sets; |
|
259 | 251 | sets.append(set); |
|
260 | 252 | emit barsetsAdded(sets); |
|
261 | 253 | emit countChanged(); |
|
262 | 254 | } |
|
263 | 255 | return success; |
|
264 | 256 | } |
|
265 | 257 | |
|
266 | 258 | /*! |
|
267 | 259 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
268 | 260 | Returns true, if set was removed. |
|
269 | 261 | */ |
|
270 | 262 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
271 | 263 | { |
|
272 | 264 | Q_D(QAbstractBarSeries); |
|
273 | 265 | bool success = d->remove(set); |
|
274 | 266 | if (success) { |
|
275 | 267 | QList<QBarSet*> sets; |
|
276 | 268 | sets.append(set); |
|
277 | 269 | emit barsetsRemoved(sets); |
|
278 | 270 | emit countChanged(); |
|
279 | 271 | } |
|
280 | 272 | return success; |
|
281 | 273 | } |
|
282 | 274 | |
|
283 | 275 | /*! |
|
284 | 276 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
285 | 277 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
286 | 278 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
287 | 279 | and function returns false. |
|
288 | 280 | */ |
|
289 | 281 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) |
|
290 | 282 | { |
|
291 | 283 | Q_D(QAbstractBarSeries); |
|
292 | 284 | bool success = d->append(sets); |
|
293 | 285 | if (success) { |
|
294 | 286 | emit barsetsAdded(sets); |
|
295 | 287 | emit countChanged(); |
|
296 | 288 | } |
|
297 | 289 | return success; |
|
298 | 290 | } |
|
299 | 291 | |
|
300 | 292 | /*! |
|
301 | 293 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
302 | 294 | Returns true, if inserting succeeded. |
|
303 | 295 | |
|
304 | 296 | */ |
|
305 | 297 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
306 | 298 | { |
|
307 | 299 | Q_D(QAbstractBarSeries); |
|
308 | 300 | bool success = d->insert(index, set); |
|
309 | 301 | if (success) { |
|
310 | 302 | QList<QBarSet*> sets; |
|
311 | 303 | sets.append(set); |
|
312 | 304 | emit barsetsAdded(sets); |
|
313 | 305 | emit countChanged(); |
|
314 | 306 | } |
|
315 | 307 | return success; |
|
316 | 308 | } |
|
317 | 309 | |
|
318 | 310 | /*! |
|
319 | 311 | Removes all of the bar sets from the series |
|
320 | 312 | */ |
|
321 | 313 | void QAbstractBarSeries::clear() |
|
322 | 314 | { |
|
323 | 315 | Q_D(QAbstractBarSeries); |
|
324 | 316 | QList<QBarSet *> sets = barSets(); |
|
325 | 317 | bool success = d->remove(sets); |
|
326 | 318 | if (success) { |
|
327 | 319 | emit barsetsRemoved(sets); |
|
328 | 320 | emit countChanged(); |
|
329 | 321 | } |
|
330 | 322 | } |
|
331 | 323 | |
|
332 | 324 | /*! |
|
333 | 325 | Returns number of sets in series. |
|
334 | 326 | */ |
|
335 | 327 | int QAbstractBarSeries::count() const |
|
336 | 328 | { |
|
337 | 329 | Q_D(const QAbstractBarSeries); |
|
338 | 330 | return d->m_barSets.count(); |
|
339 | 331 | } |
|
340 | 332 | |
|
341 | 333 | /*! |
|
342 | 334 | Returns a list of sets in series. Keeps ownership of sets. |
|
343 | 335 | */ |
|
344 | 336 | QList<QBarSet*> QAbstractBarSeries::barSets() const |
|
345 | 337 | { |
|
346 | 338 | Q_D(const QAbstractBarSeries); |
|
347 | 339 | return d->m_barSets; |
|
348 | 340 | } |
|
349 | 341 | |
|
350 | 342 | /*! |
|
351 | 343 | Sets the visibility of labels in series to \a visible |
|
352 | 344 | */ |
|
353 | 345 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
354 | 346 | { |
|
355 | 347 | Q_D(QAbstractBarSeries); |
|
356 | 348 | if (d->m_labelsVisible != visible) { |
|
357 | 349 | d->setLabelsVisible(visible); |
|
358 | 350 | emit labelsVisibleChanged(); |
|
359 | 351 | } |
|
360 | 352 | } |
|
361 | 353 | |
|
362 | 354 | /*! |
|
363 | 355 | Returns the visibility of labels |
|
364 | 356 | */ |
|
365 | 357 | bool QAbstractBarSeries::isLabelsVisible() const |
|
366 | 358 | { |
|
367 | 359 | Q_D(const QAbstractBarSeries); |
|
368 | 360 | return d->m_labelsVisible; |
|
369 | 361 | } |
|
370 | 362 | |
|
371 | 363 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
372 | 364 | |
|
373 | 365 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
374 | 366 | QAbstractSeriesPrivate(q), |
|
375 | 367 | m_barWidth(0.5), // Default value is 50% of category width |
|
376 | 368 | m_labelsVisible(false), |
|
377 | 369 | m_visible(true) |
|
378 | 370 | { |
|
379 | 371 | } |
|
380 | 372 | |
|
381 | 373 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
382 | 374 | { |
|
383 | 375 | // No categories defined. return count of longest set. |
|
384 | 376 | int count = 0; |
|
385 | 377 | for (int i=0; i<m_barSets.count(); i++) { |
|
386 | 378 | if (m_barSets.at(i)->count() > count) { |
|
387 | 379 | count = m_barSets.at(i)->count(); |
|
388 | 380 | } |
|
389 | 381 | } |
|
390 | 382 | |
|
391 | 383 | return count; |
|
392 | 384 | } |
|
393 | 385 | |
|
394 | 386 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
395 | 387 | { |
|
396 | 388 | if (width < 0.0) { |
|
397 | 389 | width = 0.0; |
|
398 | 390 | } |
|
399 | 391 | m_barWidth = width; |
|
400 | 392 | emit updatedBars(); |
|
401 | 393 | } |
|
402 | 394 | |
|
403 | 395 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
404 | 396 | { |
|
405 | 397 | return m_barWidth; |
|
406 | 398 | } |
|
407 | 399 | |
|
408 | 400 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) |
|
409 | 401 | { |
|
410 | 402 | return m_barSets.at(index); |
|
411 | 403 | } |
|
412 | 404 | |
|
413 | 405 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
414 | 406 | { |
|
415 | 407 | m_visible = visible; |
|
416 | 408 | emit updatedBars(); |
|
417 | 409 | } |
|
418 | 410 | |
|
419 | 411 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
420 | 412 | { |
|
421 | 413 | m_labelsVisible = visible; |
|
422 | 414 | emit labelsVisibleChanged(visible); |
|
423 | 415 | } |
|
424 | 416 | |
|
425 | 417 | qreal QAbstractBarSeriesPrivate::min() |
|
426 | 418 | { |
|
427 | 419 | if (m_barSets.count() <= 0) { |
|
428 | 420 | return 0; |
|
429 | 421 | } |
|
430 | 422 | qreal min = INT_MAX; |
|
431 | 423 | |
|
432 | 424 | for (int i = 0; i < m_barSets.count(); i++) { |
|
433 | 425 | int categoryCount = m_barSets.at(i)->count(); |
|
434 | 426 | for (int j = 0; j < categoryCount; j++) { |
|
435 | 427 | qreal temp = m_barSets.at(i)->at(j); |
|
436 | 428 | if (temp < min) |
|
437 | 429 | min = temp; |
|
438 | 430 | } |
|
439 | 431 | } |
|
440 | 432 | return min; |
|
441 | 433 | } |
|
442 | 434 | |
|
443 | 435 | qreal QAbstractBarSeriesPrivate::max() |
|
444 | 436 | { |
|
445 | 437 | if (m_barSets.count() <= 0) { |
|
446 | 438 | return 0; |
|
447 | 439 | } |
|
448 | 440 | qreal max = INT_MIN; |
|
449 | 441 | |
|
450 | 442 | for (int i = 0; i < m_barSets.count(); i++) { |
|
451 | 443 | int categoryCount = m_barSets.at(i)->count(); |
|
452 | 444 | for (int j = 0; j < categoryCount; j++) { |
|
453 | 445 | qreal temp = m_barSets.at(i)->at(j); |
|
454 | 446 | if (temp > max) |
|
455 | 447 | max = temp; |
|
456 | 448 | } |
|
457 | 449 | } |
|
458 | 450 | |
|
459 | 451 | return max; |
|
460 | 452 | } |
|
461 | 453 | |
|
462 | 454 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
463 | 455 | { |
|
464 | 456 | if ((set < 0) || (set >= m_barSets.count())) { |
|
465 | 457 | // No set, no value. |
|
466 | 458 | return 0; |
|
467 | 459 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
468 | 460 | // No category, no value. |
|
469 | 461 | return 0; |
|
470 | 462 | } |
|
471 | 463 | |
|
472 | 464 | return m_barSets.at(set)->at(category); |
|
473 | 465 | } |
|
474 | 466 | |
|
475 | 467 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
476 | 468 | { |
|
477 | 469 | if ((set < 0) || (set >= m_barSets.count())) { |
|
478 | 470 | // No set, no value. |
|
479 | 471 | return 0; |
|
480 | 472 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
481 | 473 | // No category, no value. |
|
482 | 474 | return 0; |
|
483 | 475 | } |
|
484 | 476 | |
|
485 | 477 | qreal value = m_barSets.at(set)->at(category); |
|
486 | 478 | qreal sum = categorySum(category); |
|
487 | 479 | if ( qFuzzyIsNull(sum) ) { |
|
488 | 480 | return 0; |
|
489 | 481 | } |
|
490 | 482 | |
|
491 | 483 | return value / sum; |
|
492 | 484 | } |
|
493 | 485 | |
|
494 | 486 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
495 | 487 | { |
|
496 | 488 | qreal sum(0); |
|
497 | 489 | int count = m_barSets.count(); // Count sets |
|
498 | 490 | for (int set = 0; set < count; set++) { |
|
499 | 491 | if (category < m_barSets.at(set)->count()) |
|
500 | 492 | sum += m_barSets.at(set)->at(category); |
|
501 | 493 | } |
|
502 | 494 | return sum; |
|
503 | 495 | } |
|
504 | 496 | |
|
505 | 497 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
506 | 498 | { |
|
507 | 499 | qreal sum(0); |
|
508 | 500 | int count = m_barSets.count(); // Count sets |
|
509 | 501 | for (int set = 0; set < count; set++) { |
|
510 | 502 | if (category < m_barSets.at(set)->count()) |
|
511 | 503 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
512 | 504 | } |
|
513 | 505 | return sum; |
|
514 | 506 | } |
|
515 | 507 | |
|
516 | 508 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
517 | 509 | { |
|
518 | 510 | qreal max = INT_MIN; |
|
519 | 511 | int count = categoryCount(); |
|
520 | 512 | for (int i = 0; i < count; i++) { |
|
521 | 513 | qreal sum = categorySum(i); |
|
522 | 514 | if (sum > max) |
|
523 | 515 | max = sum; |
|
524 | 516 | } |
|
525 | 517 | return max; |
|
526 | 518 | } |
|
527 | 519 | |
|
528 | 520 | qreal QAbstractBarSeriesPrivate::minX() |
|
529 | 521 | { |
|
530 | 522 | if (m_barSets.count() <= 0) { |
|
531 | 523 | return 0; |
|
532 | 524 | } |
|
533 | 525 | qreal min = INT_MAX; |
|
534 | 526 | |
|
535 | 527 | for (int i = 0; i < m_barSets.count(); i++) { |
|
536 | 528 | int categoryCount = m_barSets.at(i)->count(); |
|
537 | 529 | for (int j = 0; j < categoryCount; j++) { |
|
538 | 530 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
539 | 531 | if (temp < min) |
|
540 | 532 | min = temp; |
|
541 | 533 | } |
|
542 | 534 | } |
|
543 | 535 | return min; |
|
544 | 536 | } |
|
545 | 537 | |
|
546 | 538 | qreal QAbstractBarSeriesPrivate::maxX() |
|
547 | 539 | { |
|
548 | 540 | if (m_barSets.count() <= 0) { |
|
549 | 541 | return 0; |
|
550 | 542 | } |
|
551 | 543 | qreal max = INT_MIN; |
|
552 | 544 | |
|
553 | 545 | for (int i = 0; i < m_barSets.count(); i++) { |
|
554 | 546 | int categoryCount = m_barSets.at(i)->count(); |
|
555 | 547 | for (int j = 0; j < categoryCount; j++) { |
|
556 | 548 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
557 | 549 | if (temp > max) |
|
558 | 550 | max = temp; |
|
559 | 551 | } |
|
560 | 552 | } |
|
561 | 553 | |
|
562 | 554 | return max; |
|
563 | 555 | } |
|
564 | 556 | |
|
565 | 557 | |
|
566 | 558 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) |
|
567 | 559 | { |
|
568 | 560 | qreal minX(domain.minX()); |
|
569 | 561 | qreal minY(domain.minY()); |
|
570 | 562 | qreal maxX(domain.maxX()); |
|
571 | 563 | qreal maxY(domain.maxY()); |
|
572 | 564 | int tickXCount(domain.tickXCount()); |
|
573 | 565 | int tickYCount(domain.tickYCount()); |
|
574 | 566 | |
|
575 | 567 | qreal seriesMinX = this->minX(); |
|
576 | 568 | qreal seriesMaxX = this->maxX(); |
|
577 | 569 | qreal y = max(); |
|
578 | 570 | minX = qMin(minX, seriesMinX - 0.5); |
|
579 | 571 | minY = qMin(minY, y); |
|
580 | 572 | maxX = qMax(maxX, seriesMaxX + 0.5); |
|
581 | 573 | maxY = qMax(maxY, y); |
|
582 | 574 | tickXCount = categoryCount()+1; |
|
583 | 575 | |
|
584 | 576 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
585 | 577 | } |
|
586 | 578 | |
|
587 | 579 | Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
588 | 580 | { |
|
589 | 581 | Q_Q(QAbstractBarSeries); |
|
590 | 582 | |
|
591 | 583 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
592 | 584 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
593 | 585 | presenter->animator()->addAnimation(bar); |
|
594 | 586 | } |
|
595 | 587 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
596 | 588 | return bar; |
|
597 | 589 | |
|
598 | 590 | } |
|
599 | 591 | |
|
600 | 592 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
601 | 593 | { |
|
602 | 594 | Q_Q(QAbstractBarSeries); |
|
603 | 595 | QList<LegendMarker*> markers; |
|
604 | 596 | foreach(QBarSet* set, q->barSets()) { |
|
605 | 597 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
606 | 598 | markers << marker; |
|
607 | 599 | } |
|
608 | 600 | |
|
609 | 601 | return markers; |
|
610 | 602 | } |
|
611 | 603 | |
|
612 | 604 | QAbstractAxis* QAbstractBarSeriesPrivate::createAxisX(QObject* parent) |
|
613 | 605 | { |
|
614 | 606 | return new QCategoriesAxis(parent); |
|
615 | 607 | } |
|
616 | 608 | |
|
617 | 609 | QAbstractAxis* QAbstractBarSeriesPrivate::createAxisY(QObject* parent) |
|
618 | 610 | { |
|
619 | 611 | return new QValuesAxis(parent); |
|
620 | 612 | } |
|
621 | 613 | |
|
622 | 614 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
623 | 615 | { |
|
624 | 616 | Q_Q(QAbstractBarSeries); |
|
625 | 617 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
626 | 618 | // Fail if set is already in list or set is null. |
|
627 | 619 | return false; |
|
628 | 620 | } |
|
629 | 621 | m_barSets.append(set); |
|
630 | 622 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
631 | 623 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
632 | 624 | emit restructuredBars(); // this notifies barchartitem |
|
633 | 625 | if (m_dataset) { |
|
634 | 626 | m_dataset->updateSeries(q); // this notifies legend |
|
635 | 627 | } |
|
636 | 628 | return true; |
|
637 | 629 | } |
|
638 | 630 | |
|
639 | 631 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
640 | 632 | { |
|
641 | 633 | Q_Q(QAbstractBarSeries); |
|
642 | 634 | if (!m_barSets.contains(set)) { |
|
643 | 635 | // Fail if set is not in list |
|
644 | 636 | return false; |
|
645 | 637 | } |
|
646 | 638 | m_barSets.removeOne(set); |
|
647 | 639 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
648 | 640 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
649 | 641 | emit restructuredBars(); // this notifies barchartitem |
|
650 | 642 | if (m_dataset) { |
|
651 | 643 | m_dataset->updateSeries(q); // this notifies legend |
|
652 | 644 | } |
|
653 | 645 | return true; |
|
654 | 646 | } |
|
655 | 647 | |
|
656 | 648 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
657 | 649 | { |
|
658 | 650 | Q_Q(QAbstractBarSeries); |
|
659 | 651 | foreach (QBarSet* set, sets) { |
|
660 | 652 | if ((set == 0) || (m_barSets.contains(set))) { |
|
661 | 653 | // Fail if any of the sets is null or is already appended. |
|
662 | 654 | return false; |
|
663 | 655 | } |
|
664 | 656 | if (sets.count(set) != 1) { |
|
665 | 657 | // Also fail if same set is more than once in given list. |
|
666 | 658 | return false; |
|
667 | 659 | } |
|
668 | 660 | } |
|
669 | 661 | |
|
670 | 662 | foreach (QBarSet* set, sets) { |
|
671 | 663 | m_barSets.append(set); |
|
672 | 664 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
673 | 665 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
674 | 666 | } |
|
675 | 667 | emit restructuredBars(); // this notifies barchartitem |
|
676 | 668 | if (m_dataset) { |
|
677 | 669 | m_dataset->updateSeries(q); // this notifies legend |
|
678 | 670 | } |
|
679 | 671 | return true; |
|
680 | 672 | } |
|
681 | 673 | |
|
682 | 674 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
683 | 675 | { |
|
684 | 676 | Q_Q(QAbstractBarSeries); |
|
685 | 677 | if (sets.count() == 0) { |
|
686 | 678 | return false; |
|
687 | 679 | } |
|
688 | 680 | foreach (QBarSet* set, sets) { |
|
689 | 681 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
690 | 682 | // Fail if any of the sets is null or is not in series |
|
691 | 683 | return false; |
|
692 | 684 | } |
|
693 | 685 | if (sets.count(set) != 1) { |
|
694 | 686 | // Also fail if same set is more than once in given list. |
|
695 | 687 | return false; |
|
696 | 688 | } |
|
697 | 689 | } |
|
698 | 690 | |
|
699 | 691 | foreach (QBarSet* set, sets) { |
|
700 | 692 | m_barSets.removeOne(set); |
|
701 | 693 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
702 | 694 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
703 | 695 | } |
|
704 | 696 | |
|
705 | 697 | emit restructuredBars(); // this notifies barchartitem |
|
706 | 698 | if (m_dataset) { |
|
707 | 699 | m_dataset->updateSeries(q); // this notifies legend |
|
708 | 700 | } |
|
709 | 701 | return true; |
|
710 | 702 | } |
|
711 | 703 | |
|
712 | 704 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
713 | 705 | { |
|
714 | 706 | Q_Q(QAbstractBarSeries); |
|
715 | 707 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
716 | 708 | // Fail if set is already in list or set is null. |
|
717 | 709 | return false; |
|
718 | 710 | } |
|
719 | 711 | m_barSets.insert(index, set); |
|
720 | 712 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
721 | 713 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
722 | 714 | emit restructuredBars(); // this notifies barchartitem |
|
723 | 715 | if (m_dataset) { |
|
724 | 716 | m_dataset->updateSeries(q); // this notifies legend |
|
725 | 717 | } |
|
726 | 718 | return true; |
|
727 | 719 | } |
|
728 | 720 | |
|
729 | 721 | #include "moc_qabstractbarseries.cpp" |
|
730 | 722 | #include "moc_qabstractbarseries_p.cpp" |
|
731 | 723 | |
|
732 | 724 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,82 +1,84 | |||
|
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 | #ifndef BARSERIES_H |
|
22 | 22 | #define BARSERIES_H |
|
23 | 23 | |
|
24 | 24 | #include <qabstractseries.h> |
|
25 | 25 | #include <QStringList> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | class QBarSet; |
|
30 | 30 | class QAbstractBarSeriesPrivate; |
|
31 | 31 | |
|
32 | 32 | // Container for series |
|
33 | 33 | class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries |
|
34 | 34 | { |
|
35 | 35 | Q_OBJECT |
|
36 | 36 | Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth) |
|
37 | 37 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
|
38 | 38 | Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
39 | 39 | |
|
40 | public: | |
|
40 | protected: | |
|
41 | 41 | explicit QAbstractBarSeries(QObject *parent = 0); |
|
42 | ||
|
43 | public: | |
|
42 | 44 | virtual ~QAbstractBarSeries(); |
|
43 | 45 | |
|
44 | QAbstractSeries::SeriesType type() const; | |
|
46 | virtual QAbstractSeries::SeriesType type() const = 0; | |
|
45 | 47 | |
|
46 | 48 | void setBarWidth(qreal width); |
|
47 | 49 | qreal barWidth() const; |
|
48 | 50 | |
|
49 | 51 | bool append(QBarSet *set); |
|
50 | 52 | bool remove(QBarSet *set); |
|
51 | 53 | bool append(QList<QBarSet* > sets); |
|
52 | 54 | bool insert(int index, QBarSet *set); |
|
53 | 55 | int count() const; |
|
54 | 56 | QList<QBarSet*> barSets() const; |
|
55 | 57 | void clear(); |
|
56 | 58 | |
|
57 | 59 | void setLabelsVisible(bool visible = true); |
|
58 | 60 | bool isLabelsVisible() const; |
|
59 | 61 | |
|
60 | 62 | protected: |
|
61 | 63 | explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d,QObject *parent = 0); |
|
62 | 64 | |
|
63 | 65 | Q_SIGNALS: |
|
64 | 66 | void clicked(int index, QBarSet *barset); |
|
65 | 67 | void hovered(bool status, QBarSet *barset); |
|
66 | 68 | void countChanged(); |
|
67 | 69 | void labelsVisibleChanged(); |
|
68 | 70 | |
|
69 | 71 | void barsetsAdded(QList<QBarSet*> sets); |
|
70 | 72 | void barsetsRemoved(QList<QBarSet*> sets); |
|
71 | 73 | |
|
72 | 74 | protected: |
|
73 | 75 | Q_DECLARE_PRIVATE(QAbstractBarSeries) |
|
74 | 76 | friend class BarChartItem; |
|
75 | 77 | friend class PercentBarChartItem; |
|
76 | 78 | friend class StackedBarChartItem; |
|
77 | 79 | friend class GroupedBarChartItem; |
|
78 | 80 | }; |
|
79 | 81 | |
|
80 | 82 | QTCOMMERCIALCHART_END_NAMESPACE |
|
81 | 83 | |
|
82 | 84 | #endif // BARSERIES_H |
@@ -1,634 +1,634 | |||
|
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 <QtTest/QtTest> |
|
22 | 22 | #include <qabstractaxis.h> |
|
23 | 23 | #include <qvaluesaxis.h> |
|
24 | 24 | #include <qcategoriesaxis.h> |
|
25 | 25 | #include <qlineseries.h> |
|
26 | 26 | #include <qareaseries.h> |
|
27 | 27 | #include <qscatterseries.h> |
|
28 | 28 | #include <qsplineseries.h> |
|
29 | 29 | #include <qpieseries.h> |
|
30 |
#include <q |
|
|
30 | #include <qgroupedbarseries.h> | |
|
31 | 31 | #include <qpercentbarseries.h> |
|
32 | 32 | #include <qstackedbarseries.h> |
|
33 | 33 | #include <private/chartdataset_p.h> |
|
34 | 34 | #include <private/domain_p.h> |
|
35 | 35 | #include <tst_definitions.h> |
|
36 | 36 | |
|
37 | 37 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | Q_DECLARE_METATYPE(Domain *) |
|
40 | 40 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
41 | 41 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
42 | 42 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) |
|
43 | 43 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) |
|
44 | 44 | Q_DECLARE_METATYPE(QLineSeries *) |
|
45 | 45 | |
|
46 | 46 | class tst_ChartDataSet: public QObject { |
|
47 | 47 | |
|
48 | 48 | Q_OBJECT |
|
49 | 49 | |
|
50 | 50 | public Q_SLOTS: |
|
51 | 51 | void initTestCase(); |
|
52 | 52 | void cleanupTestCase(); |
|
53 | 53 | void init(); |
|
54 | 54 | void cleanup(); |
|
55 | 55 | |
|
56 | 56 | private Q_SLOTS: |
|
57 | 57 | void chartdataset_data(); |
|
58 | 58 | void chartdataset(); |
|
59 | 59 | void addSeries_data(); |
|
60 | 60 | void addSeries(); |
|
61 | 61 | void setAxisX_data(); |
|
62 | 62 | void setAxisX(); |
|
63 | 63 | void setAxisY_data(); |
|
64 | 64 | void setAxisY(); |
|
65 | 65 | void removeSeries_data(); |
|
66 | 66 | void removeSeries(); |
|
67 | 67 | void removeAllSeries_data(); |
|
68 | 68 | void removeAllSeries(); |
|
69 | 69 | void seriesCount_data(); |
|
70 | 70 | void seriesCount(); |
|
71 | 71 | void seriesIndex_data(); |
|
72 | 72 | void seriesIndex(); |
|
73 | 73 | void domain_data(); |
|
74 | 74 | void domain(); |
|
75 | 75 | void zoomInDomain_data(); |
|
76 | 76 | void zoomInDomain(); |
|
77 | 77 | /* |
|
78 | 78 | void zoomOutDomain_data(); |
|
79 | 79 | void zoomOutDomain(); |
|
80 | 80 | void scrollDomain_data(); |
|
81 | 81 | void scrollDomain(); |
|
82 | 82 | */ |
|
83 | 83 | private: |
|
84 | 84 | ChartDataSet* m_dataset; |
|
85 | 85 | }; |
|
86 | 86 | |
|
87 | 87 | void tst_ChartDataSet::initTestCase() |
|
88 | 88 | { |
|
89 | 89 | qRegisterMetaType<Domain*>(); |
|
90 | 90 | qRegisterMetaType<QAbstractAxis*>(); |
|
91 | 91 | qRegisterMetaType<QAbstractSeries*>(); |
|
92 | 92 | } |
|
93 | 93 | |
|
94 | 94 | void tst_ChartDataSet::cleanupTestCase() |
|
95 | 95 | { |
|
96 | 96 | } |
|
97 | 97 | |
|
98 | 98 | void tst_ChartDataSet::init() |
|
99 | 99 | { |
|
100 | 100 | m_dataset = new ChartDataSet(); |
|
101 | 101 | } |
|
102 | 102 | |
|
103 | 103 | |
|
104 | 104 | void tst_ChartDataSet::cleanup() |
|
105 | 105 | { |
|
106 | 106 | QList<QAbstractSeries*> series = m_dataset->series(); |
|
107 | 107 | foreach(QAbstractSeries* serie, series) |
|
108 | 108 | { |
|
109 | 109 | m_dataset->removeSeries(serie); |
|
110 | 110 | } |
|
111 | 111 | } |
|
112 | 112 | |
|
113 | 113 | void tst_ChartDataSet::chartdataset_data() |
|
114 | 114 | { |
|
115 | 115 | } |
|
116 | 116 | |
|
117 | 117 | void tst_ChartDataSet::chartdataset() |
|
118 | 118 | { |
|
119 | 119 | QVERIFY(m_dataset->axisX(0) == 0); |
|
120 | 120 | QVERIFY(m_dataset->axisY(0) == 0); |
|
121 | 121 | QLineSeries* series = new QLineSeries(this); |
|
122 | 122 | QCOMPARE(m_dataset->seriesIndex(series),-1); |
|
123 | 123 | QVERIFY(m_dataset->domain(series) == 0); |
|
124 | 124 | QVERIFY(m_dataset->axisX(series) == 0); |
|
125 | 125 | QVERIFY(m_dataset->axisY(series) == 0); |
|
126 | 126 | m_dataset->createDefaultAxes(); |
|
127 | 127 | } |
|
128 | 128 | |
|
129 | 129 | |
|
130 | 130 | void tst_ChartDataSet::addSeries_data() |
|
131 | 131 | { |
|
132 | 132 | QTest::addColumn<QAbstractSeries*>("series"); |
|
133 | 133 | |
|
134 | 134 | QAbstractSeries* line = new QLineSeries(this); |
|
135 | 135 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
136 | 136 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
137 | 137 | QAbstractSeries* spline = new QSplineSeries(this); |
|
138 | 138 | QAbstractSeries* pie = new QPieSeries(this); |
|
139 |
QAbstractSeries* bar = new Q |
|
|
139 | QAbstractSeries* bar = new QGroupedBarSeries(this); | |
|
140 | 140 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
141 | 141 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
142 | 142 | |
|
143 | 143 | QTest::newRow("line") << line; |
|
144 | 144 | QTest::newRow("area") << area; |
|
145 | 145 | QTest::newRow("scatter") << scatter; |
|
146 | 146 | QTest::newRow("spline") << spline; |
|
147 | 147 | QTest::newRow("pie") << pie; |
|
148 | 148 | QTest::newRow("bar") << bar; |
|
149 | 149 | QTest::newRow("percent") << percent; |
|
150 | 150 | QTest::newRow("stacked") << stacked; |
|
151 | 151 | } |
|
152 | 152 | |
|
153 | 153 | void tst_ChartDataSet::addSeries() |
|
154 | 154 | { |
|
155 | 155 | |
|
156 | 156 | QFETCH(QAbstractSeries*, series); |
|
157 | 157 | |
|
158 | 158 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); |
|
159 | 159 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
160 | 160 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
161 | 161 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
162 | 162 | |
|
163 | 163 | m_dataset->addSeries(series); |
|
164 | 164 | m_dataset->createDefaultAxes(); |
|
165 | 165 | if(series->type()==QAbstractSeries::SeriesTypePie){ |
|
166 | 166 | TRY_COMPARE(spy0.count(), 0); |
|
167 | 167 | }else{ |
|
168 | 168 | TRY_COMPARE(spy0.count(), 2); |
|
169 | 169 | } |
|
170 | 170 | TRY_COMPARE(spy1.count(), 0); |
|
171 | 171 | TRY_COMPARE(spy2.count(), 1); |
|
172 | 172 | TRY_COMPARE(spy3.count(), 0); |
|
173 | 173 | } |
|
174 | 174 | |
|
175 | 175 | |
|
176 | 176 | void tst_ChartDataSet::setAxisX_data() |
|
177 | 177 | { |
|
178 | 178 | |
|
179 | 179 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
180 | 180 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
181 | 181 | QTest::addColumn<int>("axisCount"); |
|
182 | 182 | |
|
183 | 183 | QAbstractSeries* line = new QLineSeries(this); |
|
184 | 184 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
185 | 185 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
186 | 186 | QAbstractSeries* spline = new QSplineSeries(this); |
|
187 | 187 | QAbstractSeries* pie = new QPieSeries(this); |
|
188 |
QAbstractSeries* bar = new Q |
|
|
188 | QAbstractSeries* bar = new QGroupedBarSeries(this); | |
|
189 | 189 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
190 | 190 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
191 | 191 | |
|
192 | 192 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") |
|
193 | 193 | << (QList<QAbstractSeries*>() << line << spline << scatter) |
|
194 | 194 | << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) << new QValuesAxis(this)) << 3; |
|
195 | 195 | |
|
196 | 196 | QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area) |
|
197 | 197 | << (QList<QAbstractAxis*>() << new QValuesAxis(this)) << 1; |
|
198 | 198 | |
|
199 | 199 | QList<QAbstractAxis*> axes0; |
|
200 | 200 | axes0 << new QValuesAxis(this) << new QValuesAxis(this); |
|
201 | 201 | axes0 << axes0.last(); |
|
202 | 202 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1") |
|
203 | 203 | << (QList<QAbstractSeries*>() << line << spline << scatter) |
|
204 | 204 | << axes0 << 2; |
|
205 | 205 | //TODO: add more test cases |
|
206 | 206 | } |
|
207 | 207 | |
|
208 | 208 | void tst_ChartDataSet::setAxisX() |
|
209 | 209 | { |
|
210 | 210 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
211 | 211 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
212 | 212 | QFETCH(int, axisCount); |
|
213 | 213 | |
|
214 | 214 | Q_ASSERT(seriesList.count() == axisList.count()); |
|
215 | 215 | |
|
216 | 216 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); |
|
217 | 217 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
218 | 218 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
219 | 219 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
220 | 220 | |
|
221 | 221 | foreach(QAbstractSeries* series, seriesList){ |
|
222 | 222 | m_dataset->addSeries(series); |
|
223 | 223 | } |
|
224 | 224 | |
|
225 | 225 | TRY_COMPARE(spy0.count(), 0); |
|
226 | 226 | TRY_COMPARE(spy1.count(), 0); |
|
227 | 227 | TRY_COMPARE(spy2.count(), seriesList.count()); |
|
228 | 228 | TRY_COMPARE(spy3.count(), 0); |
|
229 | 229 | |
|
230 | 230 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
231 | 231 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
232 | 232 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
233 | 233 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
234 | 234 | |
|
235 | 235 | for(int i=0 ; i < seriesList.count(); i++){ |
|
236 | 236 | m_dataset->setAxisX(seriesList.at(i),axisList.at(i)); |
|
237 | 237 | } |
|
238 | 238 | |
|
239 | 239 | TRY_COMPARE(spy4.count(), axisCount); |
|
240 | 240 | TRY_COMPARE(spy5.count(), 0); |
|
241 | 241 | TRY_COMPARE(spy6.count(), 0); |
|
242 | 242 | TRY_COMPARE(spy7.count(), 0); |
|
243 | 243 | |
|
244 | 244 | for(int i=0 ; i < seriesList.count(); i++){ |
|
245 | 245 | QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i)); |
|
246 | 246 | } |
|
247 | 247 | } |
|
248 | 248 | |
|
249 | 249 | void tst_ChartDataSet::setAxisY_data() |
|
250 | 250 | { |
|
251 | 251 | setAxisX_data(); |
|
252 | 252 | } |
|
253 | 253 | |
|
254 | 254 | void tst_ChartDataSet::setAxisY() |
|
255 | 255 | { |
|
256 | 256 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
257 | 257 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
258 | 258 | QFETCH(int, axisCount); |
|
259 | 259 | |
|
260 | 260 | Q_ASSERT(seriesList.count() == axisList.count()); |
|
261 | 261 | |
|
262 | 262 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
263 | 263 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
264 | 264 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
265 | 265 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
266 | 266 | |
|
267 | 267 | foreach(QAbstractSeries* series, seriesList){ |
|
268 | 268 | m_dataset->addSeries(series); |
|
269 | 269 | } |
|
270 | 270 | |
|
271 | 271 | TRY_COMPARE(spy0.count(), 0); |
|
272 | 272 | TRY_COMPARE(spy1.count(), 0); |
|
273 | 273 | TRY_COMPARE(spy2.count(), seriesList.count()); |
|
274 | 274 | TRY_COMPARE(spy3.count(), 0); |
|
275 | 275 | |
|
276 | 276 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
277 | 277 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
278 | 278 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
279 | 279 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
280 | 280 | |
|
281 | 281 | for(int i=0 ; i < seriesList.count(); i++){ |
|
282 | 282 | m_dataset->setAxisY(seriesList.at(i),axisList.at(i)); |
|
283 | 283 | } |
|
284 | 284 | |
|
285 | 285 | TRY_COMPARE(spy4.count(), axisCount); |
|
286 | 286 | TRY_COMPARE(spy5.count(), 0); |
|
287 | 287 | TRY_COMPARE(spy6.count(), 0); |
|
288 | 288 | TRY_COMPARE(spy7.count(), 0); |
|
289 | 289 | |
|
290 | 290 | for(int i=0 ; i < seriesList.count(); i++){ |
|
291 | 291 | QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i)); |
|
292 | 292 | } |
|
293 | 293 | } |
|
294 | 294 | |
|
295 | 295 | void tst_ChartDataSet::removeSeries_data() |
|
296 | 296 | { |
|
297 | 297 | addSeries_data(); |
|
298 | 298 | } |
|
299 | 299 | |
|
300 | 300 | void tst_ChartDataSet::removeSeries() |
|
301 | 301 | { |
|
302 | 302 | QFETCH(QAbstractSeries*, series); |
|
303 | 303 | |
|
304 | 304 | m_dataset->addSeries(series); |
|
305 | 305 | m_dataset->createDefaultAxes(); |
|
306 | 306 | |
|
307 | 307 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); |
|
308 | 308 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
309 | 309 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
310 | 310 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
311 | 311 | |
|
312 | 312 | m_dataset->removeSeries(series); |
|
313 | 313 | |
|
314 | 314 | TRY_COMPARE(spy0.count(), 0); |
|
315 | 315 | if (series->type() == QAbstractSeries::SeriesTypePie) { |
|
316 | 316 | TRY_COMPARE(spy1.count(), 0); |
|
317 | 317 | } |
|
318 | 318 | else { |
|
319 | 319 | TRY_COMPARE(spy1.count(), 2); |
|
320 | 320 | } |
|
321 | 321 | TRY_COMPARE(spy2.count(), 0); |
|
322 | 322 | TRY_COMPARE(spy3.count(), 1); |
|
323 | 323 | } |
|
324 | 324 | |
|
325 | 325 | void tst_ChartDataSet::removeAllSeries_data() |
|
326 | 326 | { |
|
327 | 327 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
328 | 328 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
329 | 329 | QTest::addColumn<int>("axisCount"); |
|
330 | 330 | |
|
331 | 331 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") |
|
332 | 332 | << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this) |
|
333 | 333 | << new QScatterSeries(this)) |
|
334 | 334 | << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) |
|
335 | 335 | << new QValuesAxis(this)) << 3; |
|
336 | 336 | //TODO: |
|
337 | 337 | } |
|
338 | 338 | |
|
339 | 339 | void tst_ChartDataSet::removeAllSeries() |
|
340 | 340 | { |
|
341 | 341 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
342 | 342 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
343 | 343 | QFETCH(int, axisCount); |
|
344 | 344 | |
|
345 | 345 | foreach(QAbstractSeries* series, seriesList) { |
|
346 | 346 | m_dataset->addSeries(series); |
|
347 | 347 | } |
|
348 | 348 | |
|
349 | 349 | for (int i = 0; i < seriesList.count(); i++) { |
|
350 | 350 | m_dataset->setAxisX(seriesList.at(i), axisList.at(i)); |
|
351 | 351 | } |
|
352 | 352 | |
|
353 | 353 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
354 | 354 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
355 | 355 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
356 | 356 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
357 | 357 | |
|
358 | 358 | m_dataset->removeAllSeries(); |
|
359 | 359 | |
|
360 | 360 | TRY_COMPARE(spy0.count(), 0); |
|
361 | 361 | TRY_COMPARE(spy1.count(), axisCount); |
|
362 | 362 | TRY_COMPARE(spy2.count(), 0); |
|
363 | 363 | TRY_COMPARE(spy3.count(), seriesList.count()); |
|
364 | 364 | } |
|
365 | 365 | |
|
366 | 366 | |
|
367 | 367 | void tst_ChartDataSet::seriesCount_data() |
|
368 | 368 | { |
|
369 | 369 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
370 | 370 | QTest::addColumn<int>("seriesCount"); |
|
371 | 371 | |
|
372 | 372 | QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3; |
|
373 | 373 | QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2; |
|
374 | 374 | } |
|
375 | 375 | |
|
376 | 376 | void tst_ChartDataSet::seriesCount() |
|
377 | 377 | { |
|
378 | 378 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
379 | 379 | QFETCH(int, seriesCount); |
|
380 | 380 | |
|
381 | 381 | foreach(QAbstractSeries* series, seriesList){ |
|
382 | 382 | m_dataset->addSeries(series); |
|
383 | 383 | } |
|
384 | 384 | |
|
385 | 385 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
386 | 386 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
387 | 387 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
388 | 388 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
389 | 389 | |
|
390 | 390 | QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount); |
|
391 | 391 | TRY_COMPARE(spy0.count(), 0); |
|
392 | 392 | TRY_COMPARE(spy1.count(), 0); |
|
393 | 393 | TRY_COMPARE(spy2.count(), 0); |
|
394 | 394 | TRY_COMPARE(spy3.count(), 0); |
|
395 | 395 | } |
|
396 | 396 | |
|
397 | 397 | void tst_ChartDataSet::seriesIndex_data() |
|
398 | 398 | { |
|
399 | 399 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
400 | 400 | |
|
401 | 401 | QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
402 | 402 | QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ); |
|
403 | 403 | } |
|
404 | 404 | |
|
405 | 405 | void tst_ChartDataSet::seriesIndex() |
|
406 | 406 | { |
|
407 | 407 | |
|
408 | 408 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
409 | 409 | |
|
410 | 410 | foreach(QAbstractSeries* series, seriesList) { |
|
411 | 411 | m_dataset->addSeries(series); |
|
412 | 412 | } |
|
413 | 413 | |
|
414 | 414 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); |
|
415 | 415 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
416 | 416 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); |
|
417 | 417 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
418 | 418 | |
|
419 | 419 | for (int i = 0; i < seriesList.count(); i++) { |
|
420 | 420 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
421 | 421 | } |
|
422 | 422 | |
|
423 | 423 | TRY_COMPARE(spy0.count(), 0); |
|
424 | 424 | TRY_COMPARE(spy1.count(), 0); |
|
425 | 425 | TRY_COMPARE(spy2.count(), 0); |
|
426 | 426 | TRY_COMPARE(spy3.count(), 0); |
|
427 | 427 | |
|
428 | 428 | foreach(QAbstractSeries* series, seriesList) { |
|
429 | 429 | m_dataset->removeSeries(series); |
|
430 | 430 | } |
|
431 | 431 | |
|
432 | 432 | for (int i = 0; i < seriesList.count(); i++) { |
|
433 | 433 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
434 | 434 | } |
|
435 | 435 | |
|
436 | 436 | foreach(QAbstractSeries* series, seriesList) { |
|
437 | 437 | m_dataset->addSeries(series); |
|
438 | 438 | } |
|
439 | 439 | |
|
440 | 440 | for (int i = 0; i < seriesList.count(); i++) { |
|
441 | 441 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
442 | 442 | } |
|
443 | 443 | |
|
444 | 444 | m_dataset->removeSeries(seriesList.at(1)); |
|
445 | 445 | |
|
446 | 446 | for (int i = 0; i < seriesList.count(); i++) { |
|
447 | 447 | if (i != 1) |
|
448 | 448 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
449 | 449 | else |
|
450 | 450 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
451 | 451 | } |
|
452 | 452 | |
|
453 | 453 | m_dataset->addSeries(seriesList.at(1)); |
|
454 | 454 | |
|
455 | 455 | for (int i = 0; i < seriesList.count(); i++) { |
|
456 | 456 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
457 | 457 | } |
|
458 | 458 | |
|
459 | 459 | m_dataset->removeSeries(seriesList.at(2)); |
|
460 | 460 | |
|
461 | 461 | for (int i = 0; i < seriesList.count(); i++) { |
|
462 | 462 | if (i != 2) |
|
463 | 463 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
464 | 464 | else |
|
465 | 465 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
466 | 466 | } |
|
467 | 467 | |
|
468 | 468 | m_dataset->removeSeries(seriesList.at(0)); |
|
469 | 469 | |
|
470 | 470 | for (int i = 0; i < seriesList.count(); i++) { |
|
471 | 471 | if (i != 2 && i != 0) |
|
472 | 472 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
473 | 473 | else |
|
474 | 474 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
475 | 475 | } |
|
476 | 476 | |
|
477 | 477 | m_dataset->addSeries(seriesList.at(2)); |
|
478 | 478 | m_dataset->addSeries(seriesList.at(0)); |
|
479 | 479 | |
|
480 | 480 | for (int i = 0; i < seriesList.count(); i++) { |
|
481 | 481 | if (i == 2) |
|
482 | 482 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0); |
|
483 | 483 | else if (i == 0) |
|
484 | 484 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2); |
|
485 | 485 | else |
|
486 | 486 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
487 | 487 | } |
|
488 | 488 | |
|
489 | 489 | } |
|
490 | 490 | |
|
491 | 491 | void tst_ChartDataSet::domain_data() |
|
492 | 492 | { |
|
493 | 493 | addSeries_data(); |
|
494 | 494 | } |
|
495 | 495 | |
|
496 | 496 | void tst_ChartDataSet::domain() |
|
497 | 497 | { |
|
498 | 498 | QFETCH(QAbstractSeries*, series); |
|
499 | 499 | |
|
500 | 500 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
501 | 501 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
502 | 502 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
503 | 503 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
504 | 504 | |
|
505 | 505 | m_dataset->addSeries(series); |
|
506 | 506 | QVERIFY(m_dataset->domain(series)); |
|
507 | 507 | |
|
508 | 508 | |
|
509 | 509 | TRY_COMPARE(spy0.count(), 0); |
|
510 | 510 | TRY_COMPARE(spy1.count(), 0); |
|
511 | 511 | TRY_COMPARE(spy2.count(), 1); |
|
512 | 512 | |
|
513 | 513 | QList<QVariant> arguments = spy2.takeFirst(); |
|
514 | 514 | Domain *domain = (Domain *) arguments.at(1).value<Domain *>(); |
|
515 | 515 | QVERIFY(m_dataset->domain(series) == domain); |
|
516 | 516 | |
|
517 | 517 | TRY_COMPARE(spy3.count(), 0); |
|
518 | 518 | |
|
519 | 519 | } |
|
520 | 520 | |
|
521 | 521 | void tst_ChartDataSet::zoomInDomain_data() |
|
522 | 522 | { |
|
523 | 523 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
524 | 524 | QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
525 | 525 | } |
|
526 | 526 | |
|
527 | 527 | void tst_ChartDataSet::zoomInDomain() |
|
528 | 528 | { |
|
529 | 529 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
530 | 530 | |
|
531 | 531 | foreach(QAbstractSeries* series, seriesList) { |
|
532 | 532 | m_dataset->addSeries(series); |
|
533 | 533 | } |
|
534 | 534 | |
|
535 | 535 | /* |
|
536 | 536 | QValuesAxis* axis = new QValuesAxis(); |
|
537 | 537 | |
|
538 | 538 | for (int i = 0; i < seriesList.count(); i++) { |
|
539 | 539 | m_dataset->setAxisX(seriesList.at(i), axis); |
|
540 | 540 | } |
|
541 | 541 | */ |
|
542 | 542 | m_dataset->createDefaultAxes(); |
|
543 | 543 | |
|
544 | 544 | QList<QSignalSpy*> spyList; |
|
545 | 545 | |
|
546 | 546 | foreach(QAbstractSeries* series, seriesList) { |
|
547 | 547 | spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
548 | 548 | } |
|
549 | 549 | |
|
550 | 550 | m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); |
|
551 | 551 | |
|
552 | 552 | foreach(QSignalSpy* spy, spyList) { |
|
553 | 553 | TRY_COMPARE(spy->count(), 1); |
|
554 | 554 | } |
|
555 | 555 | |
|
556 | 556 | qDeleteAll(spyList); |
|
557 | 557 | } |
|
558 | 558 | |
|
559 | 559 | /* |
|
560 | 560 | void tst_ChartDataSet::zoomOutDomain_data() |
|
561 | 561 | { |
|
562 | 562 | addSeries_data(); |
|
563 | 563 | } |
|
564 | 564 | |
|
565 | 565 | void tst_ChartDataSet::zoomOutDomain() |
|
566 | 566 | { |
|
567 | 567 | QFETCH(QLineSeries*, series0); |
|
568 | 568 | QFETCH(QAxis*, axis0); |
|
569 | 569 | QFETCH(QLineSeries*, series1); |
|
570 | 570 | QFETCH(QAxis*, axis1); |
|
571 | 571 | QFETCH(QLineSeries*, series2); |
|
572 | 572 | QFETCH(QAxis*, axis2); |
|
573 | 573 | QFETCH(int, axisCount); |
|
574 | 574 | |
|
575 | 575 | Q_UNUSED(axisCount); |
|
576 | 576 | |
|
577 | 577 | m_dataset->addSeries(series0, axis0); |
|
578 | 578 | m_dataset->addSeries(series1, axis1); |
|
579 | 579 | m_dataset->addSeries(series2, axis2); |
|
580 | 580 | |
|
581 | 581 | Domain* domain0 = m_dataset->domain(series0); |
|
582 | 582 | Domain* domain1 = m_dataset->domain(series1); |
|
583 | 583 | Domain* domain2 = m_dataset->domain(series2); |
|
584 | 584 | |
|
585 | 585 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
586 | 586 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
587 | 587 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
588 | 588 | |
|
589 | 589 | m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); |
|
590 | 590 | |
|
591 | 591 | TRY_COMPARE(spy0.count(), 1); |
|
592 | 592 | TRY_COMPARE(spy1.count(), 1); |
|
593 | 593 | TRY_COMPARE(spy2.count(), 1); |
|
594 | 594 | } |
|
595 | 595 | |
|
596 | 596 | void tst_ChartDataSet::scrollDomain_data() |
|
597 | 597 | { |
|
598 | 598 | addSeries_data(); |
|
599 | 599 | } |
|
600 | 600 | |
|
601 | 601 | void tst_ChartDataSet::scrollDomain() |
|
602 | 602 | { |
|
603 | 603 | QFETCH(QLineSeries*, series0); |
|
604 | 604 | QFETCH(QAxis*, axis0); |
|
605 | 605 | QFETCH(QLineSeries*, series1); |
|
606 | 606 | QFETCH(QAxis*, axis1); |
|
607 | 607 | QFETCH(QLineSeries*, series2); |
|
608 | 608 | QFETCH(QAxis*, axis2); |
|
609 | 609 | QFETCH(int, axisCount); |
|
610 | 610 | |
|
611 | 611 | Q_UNUSED(axisCount); |
|
612 | 612 | |
|
613 | 613 | m_dataset->addSeries(series0, axis0); |
|
614 | 614 | m_dataset->addSeries(series1, axis1); |
|
615 | 615 | m_dataset->addSeries(series2, axis2); |
|
616 | 616 | |
|
617 | 617 | Domain* domain0 = m_dataset->domain(series0); |
|
618 | 618 | Domain* domain1 = m_dataset->domain(series1); |
|
619 | 619 | Domain* domain2 = m_dataset->domain(series2); |
|
620 | 620 | |
|
621 | 621 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
622 | 622 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
623 | 623 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
624 | 624 | |
|
625 | 625 | m_dataset->scrollDomain(10,10,QSize(1000,1000)); |
|
626 | 626 | |
|
627 | 627 | TRY_COMPARE(spy0.count(), 1); |
|
628 | 628 | TRY_COMPARE(spy1.count(), 1); |
|
629 | 629 | TRY_COMPARE(spy2.count(), 1); |
|
630 | 630 | } |
|
631 | 631 | */ |
|
632 | 632 | QTEST_MAIN(tst_ChartDataSet) |
|
633 | 633 | #include "tst_chartdataset.moc" |
|
634 | 634 |
@@ -1,577 +1,571 | |||
|
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 <QtTest/QtTest> |
|
22 |
#include <q |
|
|
22 | #include <qgroupedbarseries.h> | |
|
23 | 23 | #include <qbarset.h> |
|
24 | 24 | #include <qchartview.h> |
|
25 | 25 | #include <qchart.h> |
|
26 | 26 | #include "tst_definitions.h" |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | Q_DECLARE_METATYPE(QBarSet*) |
|
31 | 31 | |
|
32 | 32 | class tst_QBarSeries : public QObject |
|
33 | 33 | { |
|
34 | 34 | Q_OBJECT |
|
35 | 35 | |
|
36 | 36 | public slots: |
|
37 | 37 | void initTestCase(); |
|
38 | 38 | void cleanupTestCase(); |
|
39 | 39 | void init(); |
|
40 | 40 | void cleanup(); |
|
41 | 41 | |
|
42 | 42 | private slots: |
|
43 | 43 | void qbarseries_data(); |
|
44 | 44 | void qbarseries(); |
|
45 | 45 | void type_data(); |
|
46 | 46 | void type(); |
|
47 | 47 | void append_data(); |
|
48 | 48 | void append(); |
|
49 | 49 | void remove_data(); |
|
50 | 50 | void remove(); |
|
51 | 51 | void appendList_data(); |
|
52 | 52 | void appendList(); |
|
53 | 53 | void count_data(); |
|
54 | 54 | void count(); |
|
55 | 55 | void barSets_data(); |
|
56 | 56 | void barSets(); |
|
57 | 57 | void setLabelsVisible_data(); |
|
58 | 58 | void setLabelsVisible(); |
|
59 | 59 | void mouseclicked_data(); |
|
60 | 60 | void mouseclicked(); |
|
61 | 61 | void mousehovered_data(); |
|
62 | 62 | void mousehovered(); |
|
63 | 63 | void clearWithAnimations(); |
|
64 | 64 | |
|
65 | 65 | private: |
|
66 |
Q |
|
|
67 |
Q |
|
|
66 | QGroupedBarSeries* m_barseries; | |
|
67 | QGroupedBarSeries* m_barseries_with_sets; | |
|
68 | 68 | |
|
69 | 69 | QList<QBarSet*> m_testSets; |
|
70 | 70 | |
|
71 | 71 | }; |
|
72 | 72 | |
|
73 | 73 | void tst_QBarSeries::initTestCase() |
|
74 | 74 | { |
|
75 | 75 | qRegisterMetaType<QBarSet*>("QBarSet*"); |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | void tst_QBarSeries::cleanupTestCase() |
|
79 | 79 | { |
|
80 | 80 | } |
|
81 | 81 | |
|
82 | 82 | void tst_QBarSeries::init() |
|
83 | 83 | { |
|
84 |
m_barseries = new Q |
|
|
85 |
m_barseries_with_sets = new Q |
|
|
84 | m_barseries = new QGroupedBarSeries(); | |
|
85 | m_barseries_with_sets = new QGroupedBarSeries(); | |
|
86 | 86 | |
|
87 | 87 | for (int i=0; i<5; i++) { |
|
88 | 88 | m_testSets.append(new QBarSet("testset")); |
|
89 | 89 | m_barseries_with_sets->append(m_testSets.at(i)); |
|
90 | 90 | } |
|
91 | 91 | } |
|
92 | 92 | |
|
93 | 93 | void tst_QBarSeries::cleanup() |
|
94 | 94 | { |
|
95 | 95 | foreach(QBarSet* s, m_testSets) { |
|
96 | 96 | m_barseries_with_sets->remove(s); |
|
97 | 97 | delete s; |
|
98 | 98 | } |
|
99 | 99 | m_testSets.clear(); |
|
100 | 100 | |
|
101 | 101 | delete m_barseries; |
|
102 | 102 | m_barseries = 0; |
|
103 | 103 | delete m_barseries_with_sets; |
|
104 | 104 | m_barseries_with_sets = 0; |
|
105 | 105 | } |
|
106 | 106 | |
|
107 | 107 | void tst_QBarSeries::qbarseries_data() |
|
108 | 108 | { |
|
109 | 109 | } |
|
110 | 110 | |
|
111 | 111 | void tst_QBarSeries::qbarseries() |
|
112 | 112 | { |
|
113 |
Q |
|
|
113 | QGroupedBarSeries *barseries = new QGroupedBarSeries(); | |
|
114 | 114 | QVERIFY(barseries != 0); |
|
115 | 115 | } |
|
116 | 116 | |
|
117 | 117 | void tst_QBarSeries::type_data() |
|
118 | 118 | { |
|
119 | 119 | |
|
120 | 120 | } |
|
121 | 121 | |
|
122 | 122 | void tst_QBarSeries::type() |
|
123 | 123 | { |
|
124 | 124 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); |
|
125 | 125 | } |
|
126 | 126 | |
|
127 | 127 | void tst_QBarSeries::append_data() |
|
128 | 128 | { |
|
129 | 129 | } |
|
130 | 130 | |
|
131 | 131 | void tst_QBarSeries::append() |
|
132 | 132 | { |
|
133 | 133 | QVERIFY(m_barseries->count() == 0); |
|
134 | 134 | |
|
135 | 135 | bool ret = false; |
|
136 | 136 | |
|
137 | 137 | // Try adding barset |
|
138 | 138 | QBarSet *barset = new QBarSet("testset"); |
|
139 | 139 | ret = m_barseries->append(barset); |
|
140 | 140 | |
|
141 | 141 | QVERIFY(ret == true); |
|
142 | 142 | QVERIFY(m_barseries->count() == 1); |
|
143 | 143 | |
|
144 | 144 | // Try adding another set |
|
145 | 145 | QBarSet *barset2 = new QBarSet("testset2"); |
|
146 | 146 | ret = m_barseries->append(barset2); |
|
147 | 147 | |
|
148 | 148 | QVERIFY(ret == true); |
|
149 | 149 | QVERIFY(m_barseries->count() == 2); |
|
150 | 150 | |
|
151 | 151 | // Try adding same set again |
|
152 | 152 | ret = m_barseries->append(barset2); |
|
153 | 153 | QVERIFY(ret == false); |
|
154 | 154 | QVERIFY(m_barseries->count() == 2); |
|
155 | 155 | |
|
156 | 156 | // Try adding null set |
|
157 | 157 | ret = m_barseries->append(0); |
|
158 | 158 | QVERIFY(ret == false); |
|
159 | 159 | QVERIFY(m_barseries->count() == 2); |
|
160 | 160 | |
|
161 | 161 | } |
|
162 | 162 | |
|
163 | 163 | void tst_QBarSeries::remove_data() |
|
164 | 164 | { |
|
165 | 165 | } |
|
166 | 166 | |
|
167 | 167 | void tst_QBarSeries::remove() |
|
168 | 168 | { |
|
169 | 169 | int count = m_testSets.count(); |
|
170 | 170 | QVERIFY(m_barseries_with_sets->count() == count); |
|
171 | 171 | |
|
172 | 172 | // Try to remove null pointer (should not remove, should not crash) |
|
173 | 173 | bool ret = false; |
|
174 | 174 | ret = m_barseries_with_sets->remove(0); |
|
175 | 175 | QVERIFY(ret == false); |
|
176 | 176 | QVERIFY(m_barseries_with_sets->count() == count); |
|
177 | 177 | |
|
178 | 178 | // Try to remove invalid pointer (should not remove, should not crash) |
|
179 | 179 | ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) ); |
|
180 | 180 | QVERIFY(ret == false); |
|
181 | 181 | QVERIFY(m_barseries_with_sets->count() == count); |
|
182 | 182 | |
|
183 | 183 | // remove some sets |
|
184 | 184 | ret = m_barseries_with_sets->remove(m_testSets.at(2)); |
|
185 | 185 | QVERIFY(ret == true); |
|
186 | 186 | ret = m_barseries_with_sets->remove(m_testSets.at(3)); |
|
187 | 187 | QVERIFY(ret == true); |
|
188 | 188 | ret = m_barseries_with_sets->remove(m_testSets.at(4)); |
|
189 | 189 | QVERIFY(ret == true); |
|
190 | 190 | |
|
191 | 191 | QVERIFY(m_barseries_with_sets->count() == 2); |
|
192 | 192 | |
|
193 | 193 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); |
|
194 | 194 | |
|
195 | 195 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); |
|
196 | 196 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); |
|
197 | 197 | |
|
198 | 198 | // Try removing all sets again (should be ok, even if some sets have already been removed) |
|
199 | 199 | ret = false; |
|
200 | 200 | for (int i=0; i<count; i++) { |
|
201 | 201 | ret |= m_barseries_with_sets->remove(m_testSets.at(i)); |
|
202 | 202 | } |
|
203 | 203 | |
|
204 | 204 | QVERIFY(ret == true); |
|
205 | 205 | QVERIFY(m_barseries_with_sets->count() == 0); |
|
206 | 206 | } |
|
207 | 207 | |
|
208 | 208 | void tst_QBarSeries::appendList_data() |
|
209 | 209 | { |
|
210 | 210 | |
|
211 | 211 | } |
|
212 | 212 | |
|
213 | 213 | void tst_QBarSeries::appendList() |
|
214 | 214 | { |
|
215 | 215 | int count = 5; |
|
216 | 216 | QVERIFY(m_barseries->count() == 0); |
|
217 | 217 | |
|
218 | 218 | QList<QBarSet*> sets; |
|
219 | 219 | for (int i=0; i<count; i++) { |
|
220 | 220 | sets.append(new QBarSet("testset")); |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | 223 | // Append new sets (should succeed, count should match the count of sets) |
|
224 | 224 | bool ret = false; |
|
225 | 225 | ret = m_barseries->append(sets); |
|
226 | 226 | QVERIFY(ret == true); |
|
227 | 227 | QVERIFY(m_barseries->count() == count); |
|
228 | 228 | |
|
229 | 229 | // Append same sets again (should fail, count should remain same) |
|
230 | 230 | ret = m_barseries->append(sets); |
|
231 | 231 | QVERIFY(ret == false); |
|
232 | 232 | QVERIFY(m_barseries->count() == count); |
|
233 | 233 | |
|
234 | 234 | // Try append empty list (should succeed, but count should remain same) |
|
235 | 235 | QList<QBarSet*> invalidList; |
|
236 | 236 | ret = m_barseries->append(invalidList); |
|
237 | 237 | QVERIFY(ret == true); |
|
238 | 238 | QVERIFY(m_barseries->count() == count); |
|
239 | 239 | |
|
240 | 240 | // Try append list with one new and one existing set (should fail, count remains same) |
|
241 | 241 | invalidList.append(new QBarSet("ok set")); |
|
242 | 242 | invalidList.append(sets.at(0)); |
|
243 | 243 | ret = m_barseries->append(invalidList); |
|
244 | 244 | QVERIFY(ret == false); |
|
245 | 245 | QVERIFY(m_barseries->count() == count); |
|
246 | 246 | |
|
247 | 247 | // Try append list with null pointers (should fail, count remains same) |
|
248 | 248 | QList<QBarSet*> invalidList2; |
|
249 | 249 | invalidList2.append(0); |
|
250 | 250 | invalidList2.append(0); |
|
251 | 251 | invalidList2.append(0); |
|
252 | 252 | ret = m_barseries->append(invalidList2); |
|
253 | 253 | QVERIFY(ret == false); |
|
254 | 254 | QVERIFY(m_barseries->count() == count); |
|
255 | 255 | } |
|
256 | 256 | |
|
257 | 257 | void tst_QBarSeries::count_data() |
|
258 | 258 | { |
|
259 | 259 | |
|
260 | 260 | } |
|
261 | 261 | |
|
262 | 262 | void tst_QBarSeries::count() |
|
263 | 263 | { |
|
264 | 264 | QVERIFY(m_barseries->count() == 0); |
|
265 | 265 | QVERIFY(m_barseries_with_sets->count() == m_testSets.count()); |
|
266 | 266 | } |
|
267 | 267 | |
|
268 | 268 | void tst_QBarSeries::barSets_data() |
|
269 | 269 | { |
|
270 | 270 | |
|
271 | 271 | } |
|
272 | 272 | |
|
273 | 273 | void tst_QBarSeries::barSets() |
|
274 | 274 | { |
|
275 | 275 | QVERIFY(m_barseries->barSets().count() == 0); |
|
276 | 276 | |
|
277 | 277 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); |
|
278 | 278 | QVERIFY(sets.count() == m_testSets.count()); |
|
279 | 279 | |
|
280 | 280 | for (int i=0; i<m_testSets.count(); i++) { |
|
281 | 281 | QVERIFY(sets.at(i) == m_testSets.at(i)); |
|
282 | 282 | } |
|
283 | 283 | } |
|
284 | 284 | |
|
285 | 285 | void tst_QBarSeries::setLabelsVisible_data() |
|
286 | 286 | { |
|
287 | 287 | |
|
288 | 288 | } |
|
289 | 289 | |
|
290 | 290 | void tst_QBarSeries::setLabelsVisible() |
|
291 | 291 | { |
|
292 | 292 | // labels should be invisible by default |
|
293 | 293 | QVERIFY(m_barseries->isLabelsVisible() == false); |
|
294 | 294 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); |
|
295 | 295 | |
|
296 | 296 | // turn labels to visible |
|
297 | 297 | m_barseries_with_sets->setLabelsVisible(true); |
|
298 | 298 | // TODO: test the signal |
|
299 | 299 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); |
|
300 | 300 | |
|
301 | 301 | // turn labels to invisible |
|
302 | 302 | m_barseries_with_sets->setLabelsVisible(false); |
|
303 | 303 | // TODO: test the signal |
|
304 | 304 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); |
|
305 | 305 | |
|
306 | 306 | // without parameter, should turn labels to visible |
|
307 | 307 | m_barseries_with_sets->setLabelsVisible(); |
|
308 | 308 | // TODO: test the signal |
|
309 | 309 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); |
|
310 | 310 | } |
|
311 | 311 | |
|
312 | 312 | void tst_QBarSeries::mouseclicked_data() |
|
313 | 313 | { |
|
314 | 314 | |
|
315 | 315 | } |
|
316 | 316 | |
|
317 | 317 | void tst_QBarSeries::mouseclicked() |
|
318 | 318 | { |
|
319 |
Q |
|
|
319 | QGroupedBarSeries* series = new QGroupedBarSeries(); | |
|
320 | 320 | |
|
321 | 321 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
322 | // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); | |
|
323 | 322 | *set1 << 10 << 10 << 10; |
|
324 | 323 | series->append(set1); |
|
325 | 324 | |
|
326 | 325 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
327 | // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
|
328 | 326 | *set2 << 10 << 10 << 10; |
|
329 | 327 | series->append(set2); |
|
330 | 328 | |
|
331 | 329 | QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*))); |
|
332 | 330 | QSignalSpy setSpy1(set1, SIGNAL(clicked(int))); |
|
333 | 331 | QSignalSpy setSpy2(set2, SIGNAL(clicked(int))); |
|
334 | 332 | |
|
335 | 333 | QChartView view(new QChart()); |
|
336 | 334 | view.resize(400,300); |
|
337 | 335 | view.chart()->addSeries(series); |
|
338 | 336 | view.show(); |
|
339 | 337 | QTest::qWaitForWindowShown(&view); |
|
340 | 338 | |
|
341 | 339 | //==================================================================================== |
|
342 | 340 | // barset 1, bar 0 |
|
343 | 341 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(102,142)); |
|
344 | 342 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
345 | 343 | |
|
346 | 344 | QCOMPARE(seriesSpy.count(), 1); |
|
347 | 345 | QCOMPARE(setSpy1.count(), 1); |
|
348 | 346 | QCOMPARE(setSpy2.count(), 0); |
|
349 | 347 | |
|
350 | 348 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
351 | 349 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
352 | 350 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
353 | 351 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); |
|
354 | 352 | |
|
355 | 353 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); |
|
356 | 354 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
357 | 355 | QVERIFY(setSpyArg.at(0).toInt() == 0); |
|
358 | 356 | |
|
359 | 357 | //==================================================================================== |
|
360 | 358 | // barset 1, bar 1 |
|
361 | 359 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,142)); |
|
362 | 360 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
363 | 361 | |
|
364 | 362 | QCOMPARE(seriesSpy.count(), 1); |
|
365 | 363 | QCOMPARE(setSpy1.count(), 1); |
|
366 | 364 | QCOMPARE(setSpy2.count(), 0); |
|
367 | 365 | |
|
368 | 366 | seriesSpyArg = seriesSpy.takeFirst(); |
|
369 | 367 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
370 | 368 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
371 | 369 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); |
|
372 | 370 | |
|
373 | 371 | setSpyArg = setSpy1.takeFirst(); |
|
374 | 372 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
375 | 373 | QVERIFY(setSpyArg.at(0).toInt() == 1); |
|
376 | 374 | |
|
377 | 375 | //==================================================================================== |
|
378 | 376 | // barset 1, bar 2 |
|
379 | 377 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(271,142)); |
|
380 | 378 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
381 | 379 | |
|
382 | 380 | QCOMPARE(seriesSpy.count(), 1); |
|
383 | 381 | QCOMPARE(setSpy1.count(), 1); |
|
384 | 382 | QCOMPARE(setSpy2.count(), 0); |
|
385 | 383 | |
|
386 | 384 | seriesSpyArg = seriesSpy.takeFirst(); |
|
387 | 385 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
388 | 386 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
389 | 387 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); |
|
390 | 388 | |
|
391 | 389 | setSpyArg = setSpy1.takeFirst(); |
|
392 | 390 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
393 | 391 | QVERIFY(setSpyArg.at(0).toInt() == 2); |
|
394 | 392 | |
|
395 | 393 | //==================================================================================== |
|
396 | 394 | // barset 2, bar 0 |
|
397 | 395 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(127,142)); |
|
398 | 396 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
399 | 397 | |
|
400 | 398 | QCOMPARE(seriesSpy.count(), 1); |
|
401 | 399 | QCOMPARE(setSpy1.count(), 0); |
|
402 | 400 | QCOMPARE(setSpy2.count(), 1); |
|
403 | 401 | |
|
404 | 402 | seriesSpyArg = seriesSpy.takeFirst(); |
|
405 | 403 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
406 | 404 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
407 | 405 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); |
|
408 | 406 | |
|
409 | 407 | setSpyArg = setSpy2.takeFirst(); |
|
410 | 408 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
411 | 409 | QVERIFY(setSpyArg.at(0).toInt() == 0); |
|
412 | 410 | |
|
413 | 411 | //==================================================================================== |
|
414 | 412 | // barset 2, bar 1 |
|
415 | 413 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(212,142)); |
|
416 | 414 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
417 | 415 | |
|
418 | 416 | QCOMPARE(seriesSpy.count(), 1); |
|
419 | 417 | QCOMPARE(setSpy1.count(), 0); |
|
420 | 418 | QCOMPARE(setSpy2.count(), 1); |
|
421 | 419 | |
|
422 | 420 | seriesSpyArg = seriesSpy.takeFirst(); |
|
423 | 421 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
424 | 422 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
425 | 423 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); |
|
426 | 424 | |
|
427 | 425 | setSpyArg = setSpy2.takeFirst(); |
|
428 | 426 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
429 | 427 | QVERIFY(setSpyArg.at(0).toInt() == 1); |
|
430 | 428 | |
|
431 | 429 | //==================================================================================== |
|
432 | 430 | // barset 2, bar 2 |
|
433 | 431 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(296,142)); |
|
434 | 432 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
435 | 433 | |
|
436 | 434 | QCOMPARE(seriesSpy.count(), 1); |
|
437 | 435 | QCOMPARE(setSpy1.count(), 0); |
|
438 | 436 | QCOMPARE(setSpy2.count(), 1); |
|
439 | 437 | |
|
440 | 438 | seriesSpyArg = seriesSpy.takeFirst(); |
|
441 | 439 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
442 | 440 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
443 | 441 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); |
|
444 | 442 | |
|
445 | 443 | setSpyArg = setSpy2.takeFirst(); |
|
446 | 444 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
447 | 445 | QVERIFY(setSpyArg.at(0).toInt() == 2); |
|
448 | 446 | } |
|
449 | 447 | |
|
450 | 448 | void tst_QBarSeries::mousehovered_data() |
|
451 | 449 | { |
|
452 | 450 | |
|
453 | 451 | } |
|
454 | 452 | |
|
455 | 453 | void tst_QBarSeries::mousehovered() |
|
456 | 454 | { |
|
457 |
Q |
|
|
455 | QGroupedBarSeries* series = new QGroupedBarSeries(); | |
|
458 | 456 | |
|
459 | 457 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
460 | // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); | |
|
461 | 458 | *set1 << 10 << 10 << 10; |
|
462 | 459 | series->append(set1); |
|
463 | 460 | |
|
464 | 461 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
465 | // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
|
466 | 462 | *set2 << 10 << 10 << 10; |
|
467 | 463 | series->append(set2); |
|
468 | 464 | |
|
469 | 465 | QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*))); |
|
470 | 466 | QSignalSpy setSpy1(set1, SIGNAL(hovered(bool))); |
|
471 | 467 | QSignalSpy setSpy2(set2, SIGNAL(hovered(bool))); |
|
472 | 468 | |
|
473 | 469 | QChartView view(new QChart()); |
|
474 | 470 | view.resize(400,300); |
|
475 | 471 | view.chart()->addSeries(series); |
|
476 | 472 | view.show(); |
|
477 | 473 | QTest::qWaitForWindowShown(&view); |
|
478 | 474 | |
|
479 | 475 | //this is hack since view does not get events otherwise |
|
480 | 476 | view.setMouseTracking(true); |
|
481 | 477 | |
|
482 | 478 | //======================================================================= |
|
483 | 479 | // move mouse to left border |
|
484 | 480 | QTest::mouseMove(view.viewport(), QPoint(0, 142)); |
|
485 | 481 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); |
|
486 | 482 | TRY_COMPARE(seriesSpy.count(), 0); |
|
487 | 483 | TRY_COMPARE(setSpy1.count(), 0); |
|
488 | 484 | TRY_COMPARE(setSpy2.count(), 0); |
|
489 | 485 | |
|
490 | 486 | //======================================================================= |
|
491 | 487 | // move mouse on top of set1 |
|
492 | 488 | QTest::mouseMove(view.viewport(), QPoint(102,142)); |
|
493 | 489 | TRY_COMPARE(seriesSpy.count(), 1); |
|
494 | 490 | TRY_COMPARE(setSpy1.count(), 1); |
|
495 | 491 | TRY_COMPARE(setSpy2.count(), 0); |
|
496 | 492 | |
|
497 | 493 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
498 | 494 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
499 | 495 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
500 | 496 | QVERIFY(seriesSpyArg.at(0).toBool() == true); |
|
501 | 497 | |
|
502 | 498 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); |
|
503 | 499 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
504 | 500 | QVERIFY(setSpyArg.at(0).toBool() == true); |
|
505 | 501 | |
|
506 | 502 | //======================================================================= |
|
507 | 503 | // move mouse from top of set1 to top of set2 |
|
508 | 504 | QTest::mouseMove(view.viewport(), QPoint(127,142)); |
|
509 | 505 | TRY_COMPARE(seriesSpy.count(), 2); |
|
510 | 506 | TRY_COMPARE(setSpy1.count(), 1); |
|
511 | 507 | TRY_COMPARE(setSpy2.count(), 1); |
|
512 | 508 | |
|
513 | 509 | // should leave set1 |
|
514 | 510 | seriesSpyArg = seriesSpy.takeFirst(); |
|
515 | 511 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
516 | 512 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
517 | 513 | QVERIFY(seriesSpyArg.at(0).toBool() == false); |
|
518 | 514 | |
|
519 | 515 | setSpyArg = setSpy1.takeFirst(); |
|
520 | 516 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
521 | 517 | QVERIFY(setSpyArg.at(0).toBool() == false); |
|
522 | 518 | |
|
523 | 519 | // should enter set2 |
|
524 | 520 | seriesSpyArg = seriesSpy.takeFirst(); |
|
525 | 521 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
526 | 522 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
527 | 523 | QVERIFY(seriesSpyArg.at(0).toBool() == true); |
|
528 | 524 | |
|
529 | 525 | setSpyArg = setSpy2.takeFirst(); |
|
530 | 526 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
531 | 527 | QVERIFY(setSpyArg.at(0).toBool() == true); |
|
532 | 528 | |
|
533 | 529 | //======================================================================= |
|
534 | 530 | // move mouse from top of set2 to background |
|
535 | 531 | QTest::mouseMove(view.viewport(), QPoint(127,0)); |
|
536 | 532 | TRY_COMPARE(seriesSpy.count(), 1); |
|
537 | 533 | TRY_COMPARE(setSpy1.count(), 0); |
|
538 | 534 | TRY_COMPARE(setSpy2.count(), 1); |
|
539 | 535 | |
|
540 | 536 | // should leave set2 |
|
541 | 537 | seriesSpyArg = seriesSpy.takeFirst(); |
|
542 | 538 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
543 | 539 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
544 | 540 | QVERIFY(seriesSpyArg.at(0).toBool() == false); |
|
545 | 541 | |
|
546 | 542 | setSpyArg = setSpy2.takeFirst(); |
|
547 | 543 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
548 | 544 | QVERIFY(setSpyArg.at(0).toBool() == false); |
|
549 | 545 | } |
|
550 | 546 | |
|
551 | 547 | void tst_QBarSeries::clearWithAnimations() |
|
552 | 548 | { |
|
553 |
Q |
|
|
549 | QGroupedBarSeries* series = new QGroupedBarSeries(); | |
|
554 | 550 | |
|
555 | 551 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
556 | // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); | |
|
557 | 552 | *set1 << 10 << 10 << 10; |
|
558 | 553 | series->append(set1); |
|
559 | 554 | |
|
560 | 555 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
561 | // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
|
562 | 556 | *set2 << 10 << 10 << 10; |
|
563 | 557 | series->append(set2); |
|
564 | 558 | |
|
565 | 559 | QChartView view(new QChart()); |
|
566 | 560 | view.resize(400,300); |
|
567 | 561 | view.chart()->setAnimationOptions(QChart::SeriesAnimations); |
|
568 | 562 | view.chart()->addSeries(series); |
|
569 | 563 | view.show(); |
|
570 | 564 | |
|
571 | 565 | series->clear(); |
|
572 | 566 | } |
|
573 | 567 | |
|
574 | 568 | QTEST_MAIN(tst_QBarSeries) |
|
575 | 569 | |
|
576 | 570 | #include "tst_qbarseries.moc" |
|
577 | 571 |
@@ -1,614 +1,615 | |||
|
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 <QtTest/QtTest> |
|
22 | 22 | #include <qchartview.h> |
|
23 | 23 | #include <qlineseries.h> |
|
24 | 24 | #include <qareaseries.h> |
|
25 | 25 | #include <qscatterseries.h> |
|
26 | 26 | #include <qsplineseries.h> |
|
27 | 27 | #include <qpieseries.h> |
|
28 | 28 | #include <qabstractbarseries.h> |
|
29 | #include <qgroupedbarseries.h> | |
|
29 | 30 | #include <qpercentbarseries.h> |
|
30 | 31 | #include <qstackedbarseries.h> |
|
31 | 32 | #include <qvaluesaxis.h> |
|
32 | 33 | |
|
33 | 34 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
34 | 35 | |
|
35 | 36 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
36 | 37 | Q_DECLARE_METATYPE(QValuesAxis *) |
|
37 | 38 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
38 | 39 | Q_DECLARE_METATYPE(QChart::AnimationOption) |
|
39 | 40 | Q_DECLARE_METATYPE(QBrush) |
|
40 | 41 | Q_DECLARE_METATYPE(QPen) |
|
41 | 42 | Q_DECLARE_METATYPE(QChart::ChartTheme) |
|
42 | 43 | |
|
43 | 44 | class tst_QChart : public QObject |
|
44 | 45 | { |
|
45 | 46 | Q_OBJECT |
|
46 | 47 | |
|
47 | 48 | public slots: |
|
48 | 49 | void initTestCase(); |
|
49 | 50 | void cleanupTestCase(); |
|
50 | 51 | void init(); |
|
51 | 52 | void cleanup(); |
|
52 | 53 | |
|
53 | 54 | private slots: |
|
54 | 55 | void qchart_data(); |
|
55 | 56 | void qchart(); |
|
56 | 57 | |
|
57 | 58 | void addSeries_data(); |
|
58 | 59 | void addSeries(); |
|
59 | 60 | void animationOptions_data(); |
|
60 | 61 | void animationOptions(); |
|
61 | 62 | void axisX_data(); |
|
62 | 63 | void axisX(); |
|
63 | 64 | void axisY_data(); |
|
64 | 65 | void axisY(); |
|
65 | 66 | void backgroundBrush_data(); |
|
66 | 67 | void backgroundBrush(); |
|
67 | 68 | void backgroundPen_data(); |
|
68 | 69 | void backgroundPen(); |
|
69 | 70 | void isBackgroundVisible_data(); |
|
70 | 71 | void isBackgroundVisible(); |
|
71 | 72 | void legend_data(); |
|
72 | 73 | void legend(); |
|
73 | 74 | void margins_data(); |
|
74 | 75 | void margins(); |
|
75 | 76 | void removeAllSeries_data(); |
|
76 | 77 | void removeAllSeries(); |
|
77 | 78 | void removeSeries_data(); |
|
78 | 79 | void removeSeries(); |
|
79 | 80 | void scroll_data(); |
|
80 | 81 | void scroll(); |
|
81 | 82 | void theme_data(); |
|
82 | 83 | void theme(); |
|
83 | 84 | void title_data(); |
|
84 | 85 | void title(); |
|
85 | 86 | void titleBrush_data(); |
|
86 | 87 | void titleBrush(); |
|
87 | 88 | void titleFont_data(); |
|
88 | 89 | void titleFont(); |
|
89 | 90 | void zoomIn_data(); |
|
90 | 91 | void zoomIn(); |
|
91 | 92 | void zoomOut_data(); |
|
92 | 93 | void zoomOut(); |
|
93 | 94 | |
|
94 | 95 | private: |
|
95 | 96 | void createTestData(); |
|
96 | 97 | |
|
97 | 98 | private: |
|
98 | 99 | QChartView* m_view; |
|
99 | 100 | QChart* m_chart; |
|
100 | 101 | }; |
|
101 | 102 | |
|
102 | 103 | void tst_QChart::initTestCase() |
|
103 | 104 | { |
|
104 | 105 | |
|
105 | 106 | } |
|
106 | 107 | |
|
107 | 108 | void tst_QChart::cleanupTestCase() |
|
108 | 109 | { |
|
109 | 110 | |
|
110 | 111 | } |
|
111 | 112 | |
|
112 | 113 | void tst_QChart::init() |
|
113 | 114 | { |
|
114 | 115 | m_view = new QChartView(new QChart()); |
|
115 | 116 | m_chart = m_view->chart(); |
|
116 | 117 | } |
|
117 | 118 | |
|
118 | 119 | void tst_QChart::createTestData() |
|
119 | 120 | { |
|
120 | 121 | QLineSeries* series0 = new QLineSeries(this); |
|
121 | 122 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
122 | 123 | m_chart->addSeries(series0); |
|
123 | 124 | m_view->show(); |
|
124 | 125 | QTest::qWaitForWindowShown(m_view); |
|
125 | 126 | } |
|
126 | 127 | |
|
127 | 128 | void tst_QChart::cleanup() |
|
128 | 129 | { |
|
129 | 130 | delete m_view; |
|
130 | 131 | m_view = 0; |
|
131 | 132 | m_chart = 0; |
|
132 | 133 | } |
|
133 | 134 | |
|
134 | 135 | void tst_QChart::qchart_data() |
|
135 | 136 | { |
|
136 | 137 | } |
|
137 | 138 | |
|
138 | 139 | void tst_QChart::qchart() |
|
139 | 140 | { |
|
140 | 141 | QVERIFY(m_chart); |
|
141 | 142 | QVERIFY(m_chart->legend()); |
|
142 | 143 | QVERIFY(m_chart->legend()->isVisible()); |
|
143 | 144 | |
|
144 | 145 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); |
|
145 | 146 | QVERIFY(m_chart->axisX()); |
|
146 | 147 | QVERIFY(m_chart->axisY()); |
|
147 | 148 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); |
|
148 | 149 | QVERIFY(m_chart->backgroundPen()!=QPen()); |
|
149 | 150 | QCOMPARE(m_chart->isBackgroundVisible(), true); |
|
150 | 151 | |
|
151 | 152 | QVERIFY(m_chart->margins().top()>0); |
|
152 | 153 | QVERIFY(m_chart->margins().left()>0); |
|
153 | 154 | QVERIFY(m_chart->margins().right()>0); |
|
154 | 155 | QVERIFY(m_chart->margins().bottom()>0); |
|
155 | 156 | |
|
156 | 157 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); |
|
157 | 158 | QCOMPARE(m_chart->title(), QString()); |
|
158 | 159 | |
|
159 | 160 | //QCOMPARE(m_chart->titleBrush(),QBrush()); |
|
160 | 161 | //QCOMPARE(m_chart->titleFont(),QFont()); |
|
161 | 162 | |
|
162 | 163 | m_chart->removeAllSeries(); |
|
163 | 164 | m_chart->scroll(0,0); |
|
164 | 165 | |
|
165 | 166 | m_chart->zoomIn(); |
|
166 | 167 | m_chart->zoomIn(QRectF()); |
|
167 | 168 | m_chart->zoomOut(); |
|
168 | 169 | } |
|
169 | 170 | |
|
170 | 171 | void tst_QChart::addSeries_data() |
|
171 | 172 | { |
|
172 | 173 | QTest::addColumn<QAbstractSeries *>("series"); |
|
173 | 174 | QTest::addColumn<QAbstractAxis *>("axis"); |
|
174 | 175 | |
|
175 | 176 | QAbstractSeries* series0 = new QLineSeries(this); |
|
176 | 177 | QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0)); |
|
177 | 178 | QAbstractSeries* series2 = new QScatterSeries(this); |
|
178 | 179 | QAbstractSeries* series3 = new QSplineSeries(this); |
|
179 | 180 | QAbstractSeries* series4 = new QPieSeries(this); |
|
180 |
QAbstractSeries* series5 = new Q |
|
|
181 | QAbstractSeries* series5 = new QGroupedBarSeries(this); | |
|
181 | 182 | QAbstractSeries* series6 = new QPercentBarSeries(this); |
|
182 | 183 | QAbstractSeries* series7 = new QStackedBarSeries(this); |
|
183 | 184 | |
|
184 | 185 | QValuesAxis* axis = new QValuesAxis(this); |
|
185 | 186 | |
|
186 | 187 | QTest::newRow("default axis: lineSeries") << series0 << (QAbstractAxis*) 0; |
|
187 | 188 | QTest::newRow("axis0: lineSeries") << series0 << axis; |
|
188 | 189 | QTest::newRow("default axis: areaSeries") << series1 << (QAbstractAxis*) 0; |
|
189 | 190 | QTest::newRow("axis: areaSeries") << series1 << axis; |
|
190 | 191 | QTest::newRow("default axis: scatterSeries") << series2 << (QAbstractAxis*) 0; |
|
191 | 192 | QTest::newRow("axis1: scatterSeries") << series2 << axis; |
|
192 | 193 | QTest::newRow("default axis: splineSeries") << series3 << (QAbstractAxis*) 0; |
|
193 | 194 | QTest::newRow("axis: splineSeries") << series3 << axis; |
|
194 | 195 | QTest::newRow("default axis: pieSeries") << series4 << (QAbstractAxis*) 0; |
|
195 | 196 | QTest::newRow("axis: pieSeries") << series4 << axis; |
|
196 | 197 | QTest::newRow("default axis: barSeries") << series5 << (QAbstractAxis*) 0; |
|
197 | 198 | QTest::newRow("axis: barSeries") << series5 << axis; |
|
198 | 199 | QTest::newRow("default axis: percentBarSeries") << series6 << (QAbstractAxis*) 0; |
|
199 | 200 | QTest::newRow("axis: barSeries") << series6 << axis; |
|
200 | 201 | QTest::newRow("default axis: stackedBarSeries") << series7 << (QAbstractAxis*) 0; |
|
201 | 202 | QTest::newRow("axis: barSeries") << series7 << axis; |
|
202 | 203 | |
|
203 | 204 | } |
|
204 | 205 | |
|
205 | 206 | void tst_QChart::addSeries() |
|
206 | 207 | { |
|
207 | 208 | QFETCH(QAbstractSeries *, series); |
|
208 | 209 | QFETCH(QAbstractAxis *, axis); |
|
209 | 210 | m_view->show(); |
|
210 | 211 | QTest::qWaitForWindowShown(m_view); |
|
211 | 212 | if(!axis) axis = m_chart->axisY(); |
|
212 | 213 | QVERIFY(!series->chart()); |
|
213 | 214 | QCOMPARE(m_chart->series().count(), 0); |
|
214 | 215 | m_chart->addSeries(series); |
|
215 | 216 | m_chart->setAxisY(axis,series); |
|
216 | 217 | QCOMPARE(m_chart->series().count(), 1); |
|
217 | 218 | QCOMPARE(m_chart->series().first(), series); |
|
218 | 219 | QVERIFY(series->chart() == m_chart); |
|
219 | 220 | QCOMPARE(m_chart->axisY(series),axis); |
|
220 | 221 | m_chart->removeSeries(series); |
|
221 | 222 | QVERIFY(!series->chart()); |
|
222 | 223 | QCOMPARE(m_chart->series().count(), 0); |
|
223 | 224 | } |
|
224 | 225 | |
|
225 | 226 | void tst_QChart::animationOptions_data() |
|
226 | 227 | { |
|
227 | 228 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); |
|
228 | 229 | QTest::newRow("AllAnimations") << QChart::AllAnimations; |
|
229 | 230 | QTest::newRow("NoAnimation") << QChart::NoAnimation; |
|
230 | 231 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; |
|
231 | 232 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; |
|
232 | 233 | } |
|
233 | 234 | |
|
234 | 235 | void tst_QChart::animationOptions() |
|
235 | 236 | { |
|
236 | 237 | createTestData(); |
|
237 | 238 | QFETCH(QChart::AnimationOption, animationOptions); |
|
238 | 239 | m_chart->setAnimationOptions(animationOptions); |
|
239 | 240 | QCOMPARE(m_chart->animationOptions(), animationOptions); |
|
240 | 241 | } |
|
241 | 242 | |
|
242 | 243 | void tst_QChart::axisX_data() |
|
243 | 244 | { |
|
244 | 245 | |
|
245 | 246 | } |
|
246 | 247 | |
|
247 | 248 | void tst_QChart::axisX() |
|
248 | 249 | { |
|
249 | 250 | QVERIFY(m_chart->axisX()); |
|
250 | 251 | QAbstractAxis* axis = m_chart->axisX(); |
|
251 | 252 | createTestData(); |
|
252 | 253 | //it should be the same axis |
|
253 | 254 | QCOMPARE(axis,m_chart->axisX()); |
|
254 | 255 | } |
|
255 | 256 | |
|
256 | 257 | void tst_QChart::axisY_data() |
|
257 | 258 | { |
|
258 | 259 | QTest::addColumn<QAbstractAxis*>("axis0"); |
|
259 | 260 | QTest::addColumn<QAbstractAxis*>("axis1"); |
|
260 | 261 | QTest::addColumn<QAbstractAxis*>("axis2"); |
|
261 | 262 | QTest::newRow("1 defualt, 2 optional") << (QAbstractAxis*)0 << new QValuesAxis() << new QValuesAxis(); |
|
262 | 263 | QTest::newRow("3 optional") << new QValuesAxis() << new QValuesAxis() << new QValuesAxis(); |
|
263 | 264 | } |
|
264 | 265 | |
|
265 | 266 | |
|
266 | 267 | void tst_QChart::axisY() |
|
267 | 268 | { |
|
268 | 269 | QFETCH(QAbstractAxis*, axis0); |
|
269 | 270 | QFETCH(QAbstractAxis*, axis1); |
|
270 | 271 | QFETCH(QAbstractAxis*, axis2); |
|
271 | 272 | |
|
272 | 273 | QAbstractAxis* defaultAxisY = m_chart->axisY(); |
|
273 | 274 | |
|
274 | 275 | QVERIFY2(defaultAxisY, "Missing axisY."); |
|
275 | 276 | |
|
276 | 277 | QLineSeries* series0 = new QLineSeries(); |
|
277 | 278 | m_chart->addSeries(series0); |
|
278 | 279 | m_chart->setAxisY(axis0,series0); |
|
279 | 280 | |
|
280 | 281 | QLineSeries* series1 = new QLineSeries(); |
|
281 | 282 | m_chart->addSeries(series1); |
|
282 | 283 | m_chart->setAxisY(axis1,series1); |
|
283 | 284 | |
|
284 | 285 | QLineSeries* series2 = new QLineSeries(); |
|
285 | 286 | m_chart->addSeries(series2); |
|
286 | 287 | m_chart->setAxisY(axis2,series2); |
|
287 | 288 | |
|
288 | 289 | if (!axis0) |
|
289 | 290 | axis0 = defaultAxisY; |
|
290 | 291 | if (!axis1) |
|
291 | 292 | axis1 = defaultAxisY; |
|
292 | 293 | if (!axis2) |
|
293 | 294 | axis2 = defaultAxisY; |
|
294 | 295 | |
|
295 | 296 | QVERIFY(m_chart->axisY(series0) == axis0); |
|
296 | 297 | QVERIFY(m_chart->axisY(series1) == axis1); |
|
297 | 298 | QVERIFY(m_chart->axisY(series2) == axis2); |
|
298 | 299 | } |
|
299 | 300 | |
|
300 | 301 | void tst_QChart::backgroundBrush_data() |
|
301 | 302 | { |
|
302 | 303 | QTest::addColumn<QBrush>("backgroundBrush"); |
|
303 | 304 | QTest::newRow("null") << QBrush(); |
|
304 | 305 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
305 | 306 | QTest::newRow("white") << QBrush(Qt::white); |
|
306 | 307 | QTest::newRow("black") << QBrush(Qt::black); |
|
307 | 308 | } |
|
308 | 309 | |
|
309 | 310 | void tst_QChart::backgroundBrush() |
|
310 | 311 | { |
|
311 | 312 | QFETCH(QBrush, backgroundBrush); |
|
312 | 313 | m_chart->setBackgroundBrush(backgroundBrush); |
|
313 | 314 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); |
|
314 | 315 | } |
|
315 | 316 | |
|
316 | 317 | void tst_QChart::backgroundPen_data() |
|
317 | 318 | { |
|
318 | 319 | QTest::addColumn<QPen>("backgroundPen"); |
|
319 | 320 | QTest::newRow("null") << QPen(); |
|
320 | 321 | QTest::newRow("blue") << QPen(Qt::blue); |
|
321 | 322 | QTest::newRow("white") << QPen(Qt::white); |
|
322 | 323 | QTest::newRow("black") << QPen(Qt::black); |
|
323 | 324 | } |
|
324 | 325 | |
|
325 | 326 | |
|
326 | 327 | void tst_QChart::backgroundPen() |
|
327 | 328 | { |
|
328 | 329 | QFETCH(QPen, backgroundPen); |
|
329 | 330 | m_chart->setBackgroundPen(backgroundPen); |
|
330 | 331 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); |
|
331 | 332 | } |
|
332 | 333 | |
|
333 | 334 | void tst_QChart::isBackgroundVisible_data() |
|
334 | 335 | { |
|
335 | 336 | QTest::addColumn<bool>("isBackgroundVisible"); |
|
336 | 337 | QTest::newRow("true") << true; |
|
337 | 338 | QTest::newRow("false") << false; |
|
338 | 339 | } |
|
339 | 340 | |
|
340 | 341 | void tst_QChart::isBackgroundVisible() |
|
341 | 342 | { |
|
342 | 343 | QFETCH(bool, isBackgroundVisible); |
|
343 | 344 | m_chart->setBackgroundVisible(isBackgroundVisible); |
|
344 | 345 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); |
|
345 | 346 | } |
|
346 | 347 | |
|
347 | 348 | void tst_QChart::legend_data() |
|
348 | 349 | { |
|
349 | 350 | |
|
350 | 351 | } |
|
351 | 352 | |
|
352 | 353 | void tst_QChart::legend() |
|
353 | 354 | { |
|
354 | 355 | QLegend *legend = m_chart->legend(); |
|
355 | 356 | QVERIFY(legend); |
|
356 | 357 | |
|
357 | 358 | // Colors related signals |
|
358 | 359 | QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor))); |
|
359 | 360 | QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor))); |
|
360 | 361 | QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor))); |
|
361 | 362 | |
|
362 | 363 | // colorChanged |
|
363 | 364 | legend->setColor(QColor("aliceblue")); |
|
364 | 365 | QCOMPARE(colorSpy.count(), 1); |
|
365 | 366 | QBrush b = legend->brush(); |
|
366 | 367 | b.setColor(QColor("aqua")); |
|
367 | 368 | legend->setBrush(b); |
|
368 | 369 | QCOMPARE(colorSpy.count(), 2); |
|
369 | 370 | |
|
370 | 371 | // borderColorChanged |
|
371 | 372 | legend->setBorderColor(QColor("aliceblue")); |
|
372 | 373 | QCOMPARE(borderColorSpy.count(), 1); |
|
373 | 374 | QPen p = legend->pen(); |
|
374 | 375 | p.setColor(QColor("aqua")); |
|
375 | 376 | legend->setPen(p); |
|
376 | 377 | QCOMPARE(borderColorSpy.count(), 2); |
|
377 | 378 | |
|
378 | 379 | // labelColorChanged |
|
379 | 380 | legend->setLabelColor(QColor("lightsalmon")); |
|
380 | 381 | QCOMPARE(labelColorSpy.count(), 1); |
|
381 | 382 | b = legend->labelBrush(); |
|
382 | 383 | b.setColor(QColor("lightseagreen")); |
|
383 | 384 | legend->setLabelBrush(b); |
|
384 | 385 | QCOMPARE(labelColorSpy.count(), 2); |
|
385 | 386 | |
|
386 | 387 | // fontChanged |
|
387 | 388 | QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont))); |
|
388 | 389 | QFont f = legend->font(); |
|
389 | 390 | f.setBold(!f.bold()); |
|
390 | 391 | legend->setFont(f); |
|
391 | 392 | QCOMPARE(fontSpy.count(), 1); |
|
392 | 393 | } |
|
393 | 394 | |
|
394 | 395 | void tst_QChart::margins_data() |
|
395 | 396 | { |
|
396 | 397 | |
|
397 | 398 | } |
|
398 | 399 | |
|
399 | 400 | void tst_QChart::margins() |
|
400 | 401 | { |
|
401 | 402 | createTestData(); |
|
402 | 403 | QRectF rect = m_chart->geometry(); |
|
403 | 404 | |
|
404 | 405 | QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); |
|
405 | 406 | QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); |
|
406 | 407 | } |
|
407 | 408 | |
|
408 | 409 | void tst_QChart::removeAllSeries_data() |
|
409 | 410 | { |
|
410 | 411 | |
|
411 | 412 | } |
|
412 | 413 | |
|
413 | 414 | void tst_QChart::removeAllSeries() |
|
414 | 415 | { |
|
415 | 416 | QLineSeries* series0 = new QLineSeries(this); |
|
416 | 417 | QLineSeries* series1 = new QLineSeries(this); |
|
417 | 418 | QLineSeries* series2 = new QLineSeries(this); |
|
418 | 419 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); |
|
419 | 420 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); |
|
420 | 421 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); |
|
421 | 422 | |
|
422 | 423 | m_chart->addSeries(series0); |
|
423 | 424 | m_chart->addSeries(series1); |
|
424 | 425 | m_chart->addSeries(series2); |
|
425 | 426 | m_view->show(); |
|
426 | 427 | QTest::qWaitForWindowShown(m_view); |
|
427 | 428 | |
|
428 | 429 | QVERIFY(m_chart->axisY(series0)!=0); |
|
429 | 430 | QVERIFY(m_chart->axisY(series1)!=0); |
|
430 | 431 | QVERIFY(m_chart->axisY(series2)!=0); |
|
431 | 432 | |
|
432 | 433 | m_chart->removeAllSeries(); |
|
433 | 434 | QVERIFY(m_chart->axisY(series0)==0); |
|
434 | 435 | QVERIFY(m_chart->axisY(series1)==0); |
|
435 | 436 | QVERIFY(m_chart->axisY(series2)==0); |
|
436 | 437 | QCOMPARE(deleteSpy1.count(), 1); |
|
437 | 438 | QCOMPARE(deleteSpy2.count(), 1); |
|
438 | 439 | QCOMPARE(deleteSpy3.count(), 1); |
|
439 | 440 | } |
|
440 | 441 | |
|
441 | 442 | void tst_QChart::removeSeries_data() |
|
442 | 443 | { |
|
443 | 444 | addSeries_data(); |
|
444 | 445 | } |
|
445 | 446 | |
|
446 | 447 | void tst_QChart::removeSeries() |
|
447 | 448 | { |
|
448 | 449 | QFETCH(QAbstractSeries *, series); |
|
449 | 450 | QFETCH(QAbstractAxis *, axis); |
|
450 | 451 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); |
|
451 | 452 | m_view->show(); |
|
452 | 453 | QTest::qWaitForWindowShown(m_view); |
|
453 | 454 | if(!axis) axis = m_chart->axisY(); |
|
454 | 455 | m_chart->addSeries(series); |
|
455 | 456 | m_chart->setAxisY(axis,series); |
|
456 | 457 | QCOMPARE(m_chart->axisY(series),axis); |
|
457 | 458 | m_chart->removeSeries(series); |
|
458 | 459 | QVERIFY(m_chart->axisY(series)==0); |
|
459 | 460 | QCOMPARE(deleteSpy.count(), 0); |
|
460 | 461 | } |
|
461 | 462 | |
|
462 | 463 | void tst_QChart::scroll_data() |
|
463 | 464 | { |
|
464 | 465 | |
|
465 | 466 | } |
|
466 | 467 | |
|
467 | 468 | void tst_QChart::scroll() |
|
468 | 469 | { |
|
469 | 470 | qFatal("implement me"); |
|
470 | 471 | createTestData(); |
|
471 | 472 | //TODO qreal min = m_chart->axisY()->min(); |
|
472 | 473 | m_chart->scroll(0,0); |
|
473 | 474 | //TODO QVERIFY(m_chart->axisY()->min()<min); |
|
474 | 475 | } |
|
475 | 476 | |
|
476 | 477 | void tst_QChart::theme_data() |
|
477 | 478 | { |
|
478 | 479 | QTest::addColumn<QChart::ChartTheme>("theme"); |
|
479 | 480 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; |
|
480 | 481 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; |
|
481 | 482 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; |
|
482 | 483 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; |
|
483 | 484 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; |
|
484 | 485 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; |
|
485 | 486 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; |
|
486 | 487 | } |
|
487 | 488 | |
|
488 | 489 | void tst_QChart::theme() |
|
489 | 490 | { |
|
490 | 491 | QFETCH(QChart::ChartTheme, theme); |
|
491 | 492 | createTestData(); |
|
492 | 493 | m_chart->setTheme(theme); |
|
493 | 494 | QVERIFY(m_chart->theme()==theme); |
|
494 | 495 | } |
|
495 | 496 | |
|
496 | 497 | void tst_QChart::title_data() |
|
497 | 498 | { |
|
498 | 499 | QTest::addColumn<QString>("title"); |
|
499 | 500 | QTest::newRow("null") << QString(); |
|
500 | 501 | QTest::newRow("foo") << QString("foo"); |
|
501 | 502 | } |
|
502 | 503 | |
|
503 | 504 | void tst_QChart::title() |
|
504 | 505 | { |
|
505 | 506 | QFETCH(QString, title); |
|
506 | 507 | m_chart->setTitle(title); |
|
507 | 508 | QCOMPARE(m_chart->title(), title); |
|
508 | 509 | } |
|
509 | 510 | |
|
510 | 511 | void tst_QChart::titleBrush_data() |
|
511 | 512 | { |
|
512 | 513 | QTest::addColumn<QBrush>("titleBrush"); |
|
513 | 514 | QTest::newRow("null") << QBrush(); |
|
514 | 515 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
515 | 516 | QTest::newRow("white") << QBrush(Qt::white); |
|
516 | 517 | QTest::newRow("black") << QBrush(Qt::black); |
|
517 | 518 | } |
|
518 | 519 | |
|
519 | 520 | void tst_QChart::titleBrush() |
|
520 | 521 | { |
|
521 | 522 | QFETCH(QBrush, titleBrush); |
|
522 | 523 | m_chart->setTitleBrush(titleBrush); |
|
523 | 524 | QCOMPARE(m_chart->titleBrush(), titleBrush); |
|
524 | 525 | } |
|
525 | 526 | |
|
526 | 527 | void tst_QChart::titleFont_data() |
|
527 | 528 | { |
|
528 | 529 | QTest::addColumn<QFont>("titleFont"); |
|
529 | 530 | QTest::newRow("null") << QFont(); |
|
530 | 531 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); |
|
531 | 532 | } |
|
532 | 533 | |
|
533 | 534 | void tst_QChart::titleFont() |
|
534 | 535 | { |
|
535 | 536 | QFETCH(QFont, titleFont); |
|
536 | 537 | m_chart->setTitleFont(titleFont); |
|
537 | 538 | QCOMPARE(m_chart->titleFont(), titleFont); |
|
538 | 539 | } |
|
539 | 540 | |
|
540 | 541 | void tst_QChart::zoomIn_data() |
|
541 | 542 | { |
|
542 | 543 | QTest::addColumn<QRectF>("rect"); |
|
543 | 544 | QTest::newRow("null") << QRectF(); |
|
544 | 545 | QTest::newRow("100x100") << QRectF(10,10,100,100); |
|
545 | 546 | QTest::newRow("200x200") << QRectF(10,10,200,200); |
|
546 | 547 | } |
|
547 | 548 | |
|
548 | 549 | |
|
549 | 550 | void tst_QChart::zoomIn() |
|
550 | 551 | { |
|
551 | 552 | qFatal("implement me"); |
|
552 | 553 | /* |
|
553 | 554 | QFETCH(QRectF, rect); |
|
554 | 555 | createTestData(); |
|
555 | 556 | QRectF marigns = m_chart->margins(); |
|
556 | 557 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); |
|
557 | 558 | qreal minX = m_chart->axisX()->min(); |
|
558 | 559 | qreal minY = m_chart->axisY()->min(); |
|
559 | 560 | qreal maxX = m_chart->axisX()->max(); |
|
560 | 561 | qreal maxY = m_chart->axisY()->max(); |
|
561 | 562 | m_chart->zoomIn(rect); |
|
562 | 563 | if(rect.isValid()){ |
|
563 | 564 | QVERIFY(minX<m_chart->axisX()->min()); |
|
564 | 565 | QVERIFY(maxX>m_chart->axisX()->max()); |
|
565 | 566 | QVERIFY(minY<m_chart->axisY()->min()); |
|
566 | 567 | QVERIFY(maxY>m_chart->axisY()->max()); |
|
567 | 568 | } |
|
568 | 569 | */ |
|
569 | 570 | } |
|
570 | 571 | |
|
571 | 572 | void tst_QChart::zoomOut_data() |
|
572 | 573 | { |
|
573 | 574 | |
|
574 | 575 | } |
|
575 | 576 | |
|
576 | 577 | void tst_QChart::zoomOut() |
|
577 | 578 | { |
|
578 | 579 | qFatal("implement me"); |
|
579 | 580 | createTestData(); |
|
580 | 581 | /* |
|
581 | 582 | qreal minX = m_chart->axisX()->min(); |
|
582 | 583 | qreal minY = m_chart->axisY()->min(); |
|
583 | 584 | qreal maxX = m_chart->axisX()->max(); |
|
584 | 585 | qreal maxY = m_chart->axisY()->max(); |
|
585 | 586 | |
|
586 | 587 | m_chart->zoomIn(); |
|
587 | 588 | |
|
588 | 589 | QVERIFY(minX < m_chart->axisX()->min()); |
|
589 | 590 | QVERIFY(maxX > m_chart->axisX()->max()); |
|
590 | 591 | QVERIFY(minY < m_chart->axisY()->min()); |
|
591 | 592 | QVERIFY(maxY > m_chart->axisY()->max()); |
|
592 | 593 | |
|
593 | 594 | m_chart->zoomOut(); |
|
594 | 595 | |
|
595 | 596 | // min x may be a zero value |
|
596 | 597 | if (qFuzzyIsNull(minX)) |
|
597 | 598 | QVERIFY(qFuzzyIsNull(m_chart->axisX()->min())); |
|
598 | 599 | else |
|
599 | 600 | QCOMPARE(minX, m_chart->axisX()->min()); |
|
600 | 601 | |
|
601 | 602 | // min y may be a zero value |
|
602 | 603 | if (qFuzzyIsNull(minY)) |
|
603 | 604 | QVERIFY(qFuzzyIsNull(m_chart->axisY()->min())); |
|
604 | 605 | else |
|
605 | 606 | QCOMPARE(minY, m_chart->axisY()->min()); |
|
606 | 607 | |
|
607 | 608 | QVERIFY(maxX == m_chart->axisX()->max()); |
|
608 | 609 | QVERIFY(maxY == m_chart->axisY()->max()); |
|
609 | 610 | */ |
|
610 | 611 | } |
|
611 | 612 | |
|
612 | 613 | QTEST_MAIN(tst_QChart) |
|
613 | 614 | #include "tst_qchart.moc" |
|
614 | 615 |
@@ -1,190 +1,189 | |||
|
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 "dataseriedialog.h" |
|
22 | 22 | #include <QDialogButtonBox> |
|
23 | 23 | #include <QGridLayout> |
|
24 | 24 | #include <QCheckBox> |
|
25 | 25 | #include <QPushButton> |
|
26 | 26 | #include <QGroupBox> |
|
27 | 27 | #include <QRadioButton> |
|
28 | 28 | #include <QLabel> |
|
29 | 29 | #include <QDebug> |
|
30 | 30 | |
|
31 | 31 | DataSerieDialog::DataSerieDialog(QWidget *parent) : |
|
32 | 32 | QDialog(parent) |
|
33 | 33 | { |
|
34 | 34 | QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal); |
|
35 | 35 | QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok); |
|
36 | 36 | connect(b, SIGNAL(clicked()), this, SLOT(accept())); |
|
37 | 37 | b = addSeriesBox->addButton(QDialogButtonBox::Cancel); |
|
38 | 38 | connect(b, SIGNAL(clicked()), this, SLOT(reject())); |
|
39 | 39 | |
|
40 | 40 | QGridLayout *grid = new QGridLayout(); |
|
41 | 41 | |
|
42 | 42 | m_seriesTypeSelector = seriesTypeSelector(); |
|
43 | 43 | m_columnCountSelector = columnCountSelector(); |
|
44 | 44 | m_rowCountSelector = rowCountSelector(); |
|
45 | 45 | m_dataCharacteristicsSelector = dataCharacteristicsSelector(); |
|
46 | 46 | |
|
47 | 47 | grid->addWidget(m_seriesTypeSelector, 0, 0); |
|
48 | 48 | grid->addWidget(m_columnCountSelector, 0, 1); |
|
49 | 49 | grid->addWidget(m_rowCountSelector, 1, 1); |
|
50 | 50 | grid->addWidget(m_dataCharacteristicsSelector, 1, 0); |
|
51 | 51 | m_labelsSelector = new QCheckBox("Labels defined"); |
|
52 | 52 | m_labelsSelector->setChecked(true); |
|
53 | 53 | grid->addWidget(m_labelsSelector, 2, 0); |
|
54 | 54 | grid->addWidget(addSeriesBox, 3, 1); |
|
55 | 55 | |
|
56 | 56 | setLayout(grid); |
|
57 | 57 | } |
|
58 | 58 | |
|
59 | 59 | QGroupBox *DataSerieDialog::seriesTypeSelector() |
|
60 | 60 | { |
|
61 | 61 | QVBoxLayout *layout = new QVBoxLayout(); |
|
62 | 62 | |
|
63 | 63 | QRadioButton *line = new QRadioButton("Line"); |
|
64 | 64 | line->setChecked(true); |
|
65 | 65 | layout->addWidget(line); |
|
66 | 66 | layout->addWidget(new QRadioButton("Area")); |
|
67 | 67 | layout->addWidget(new QRadioButton("Pie")); |
|
68 | layout->addWidget(new QRadioButton("Bar")); | |
|
69 | 68 | layout->addWidget(new QRadioButton("Grouped bar")); |
|
70 | 69 | layout->addWidget(new QRadioButton("Stacked bar")); |
|
71 | 70 | layout->addWidget(new QRadioButton("Percent bar")); |
|
72 | 71 | layout->addWidget(new QRadioButton("Scatter")); |
|
73 | 72 | layout->addWidget(new QRadioButton("Spline")); |
|
74 | 73 | |
|
75 | 74 | QGroupBox *groupBox = new QGroupBox("Series type"); |
|
76 | 75 | groupBox->setLayout(layout); |
|
77 | 76 | selectRadio(groupBox, 0); |
|
78 | 77 | |
|
79 | 78 | return groupBox; |
|
80 | 79 | } |
|
81 | 80 | |
|
82 | 81 | QGroupBox *DataSerieDialog::columnCountSelector() |
|
83 | 82 | { |
|
84 | 83 | QVBoxLayout *layout = new QVBoxLayout(); |
|
85 | 84 | |
|
86 | 85 | QRadioButton *radio = new QRadioButton("1"); |
|
87 | 86 | radio->setChecked(true); |
|
88 | 87 | layout->addWidget(radio); |
|
89 | 88 | layout->addWidget(new QRadioButton("2")); |
|
90 | 89 | layout->addWidget(new QRadioButton("3")); |
|
91 | 90 | layout->addWidget(new QRadioButton("4")); |
|
92 | 91 | layout->addWidget(new QRadioButton("5")); |
|
93 | 92 | layout->addWidget(new QRadioButton("8")); |
|
94 | 93 | layout->addWidget(new QRadioButton("10")); |
|
95 | 94 | layout->addWidget(new QRadioButton("100")); |
|
96 | 95 | |
|
97 | 96 | QGroupBox *groupBox = new QGroupBox("Column count"); |
|
98 | 97 | groupBox->setLayout(layout); |
|
99 | 98 | selectRadio(groupBox, 0); |
|
100 | 99 | |
|
101 | 100 | return groupBox; |
|
102 | 101 | } |
|
103 | 102 | |
|
104 | 103 | QGroupBox *DataSerieDialog::rowCountSelector() |
|
105 | 104 | { |
|
106 | 105 | QVBoxLayout *layout = new QVBoxLayout(); |
|
107 | 106 | |
|
108 | 107 | layout->addWidget(new QRadioButton("1")); |
|
109 | 108 | QRadioButton *radio = new QRadioButton("10"); |
|
110 | 109 | radio->setChecked(true); |
|
111 | 110 | layout->addWidget(radio); |
|
112 | 111 | layout->addWidget(new QRadioButton("50")); |
|
113 | 112 | layout->addWidget(new QRadioButton("100")); |
|
114 | 113 | layout->addWidget(new QRadioButton("1000")); |
|
115 | 114 | layout->addWidget(new QRadioButton("10000")); |
|
116 | 115 | layout->addWidget(new QRadioButton("100000")); |
|
117 | 116 | layout->addWidget(new QRadioButton("1000000")); |
|
118 | 117 | |
|
119 | 118 | QGroupBox *groupBox = new QGroupBox("Row count"); |
|
120 | 119 | groupBox->setLayout(layout); |
|
121 | 120 | selectRadio(groupBox, 0); |
|
122 | 121 | |
|
123 | 122 | return groupBox; |
|
124 | 123 | } |
|
125 | 124 | |
|
126 | 125 | QGroupBox *DataSerieDialog::dataCharacteristicsSelector() |
|
127 | 126 | { |
|
128 | 127 | QVBoxLayout *layout = new QVBoxLayout(); |
|
129 | 128 | |
|
130 | 129 | layout->addWidget(new QRadioButton("Linear")); |
|
131 | 130 | layout->addWidget(new QRadioButton("Constant")); |
|
132 | 131 | layout->addWidget(new QRadioButton("Random")); |
|
133 | 132 | layout->addWidget(new QRadioButton("Sin")); |
|
134 | 133 | layout->addWidget(new QRadioButton("Sin + random")); |
|
135 | 134 | |
|
136 | 135 | QGroupBox *groupBox = new QGroupBox("Data Characteristics"); |
|
137 | 136 | groupBox->setLayout(layout); |
|
138 | 137 | selectRadio(groupBox, 0); |
|
139 | 138 | |
|
140 | 139 | return groupBox; |
|
141 | 140 | } |
|
142 | 141 | |
|
143 | 142 | void DataSerieDialog::accept() |
|
144 | 143 | { |
|
145 | 144 | accepted(radioSelection(m_seriesTypeSelector), |
|
146 | 145 | radioSelection(m_columnCountSelector).toInt(), |
|
147 | 146 | radioSelection(m_rowCountSelector).toInt(), |
|
148 | 147 | radioSelection(m_dataCharacteristicsSelector), |
|
149 | 148 | m_labelsSelector->isChecked()); |
|
150 | 149 | QDialog::accept(); |
|
151 | 150 | } |
|
152 | 151 | |
|
153 | 152 | void DataSerieDialog::selectRadio(QGroupBox *groupBox, int defaultSelection) |
|
154 | 153 | { |
|
155 | 154 | QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout()); |
|
156 | 155 | Q_ASSERT(layout); |
|
157 | 156 | Q_ASSERT(layout->count()); |
|
158 | 157 | |
|
159 | 158 | QLayoutItem *item = 0; |
|
160 | 159 | if (defaultSelection == -1) { |
|
161 | 160 | item = layout->itemAt(0); |
|
162 | 161 | } else if (layout->count() > defaultSelection) { |
|
163 | 162 | item = layout->itemAt(defaultSelection); |
|
164 | 163 | } |
|
165 | 164 | Q_ASSERT(item); |
|
166 | 165 | QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget()); |
|
167 | 166 | Q_ASSERT(radio); |
|
168 | 167 | radio->setChecked(true); |
|
169 | 168 | } |
|
170 | 169 | |
|
171 | 170 | QString DataSerieDialog::radioSelection(QGroupBox *groupBox) |
|
172 | 171 | { |
|
173 | 172 | QString selection; |
|
174 | 173 | QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout()); |
|
175 | 174 | Q_ASSERT(layout); |
|
176 | 175 | |
|
177 | 176 | for (int i(0); i < layout->count(); i++) { |
|
178 | 177 | QLayoutItem *item = layout->itemAt(i); |
|
179 | 178 | Q_ASSERT(item); |
|
180 | 179 | QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget()); |
|
181 | 180 | Q_ASSERT(radio); |
|
182 | 181 | if (radio->isChecked()) { |
|
183 | 182 | selection = radio->text(); |
|
184 | 183 | break; |
|
185 | 184 | } |
|
186 | 185 | } |
|
187 | 186 | |
|
188 | 187 | qDebug() << "radioSelection: " << selection; |
|
189 | 188 | return selection; |
|
190 | 189 | } |
@@ -1,364 +1,357 | |||
|
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 "mainwidget.h" |
|
22 | 22 | #include "dataseriedialog.h" |
|
23 | 23 | #include "qchartview.h" |
|
24 | 24 | #include "qpieseries.h" |
|
25 | 25 | #include "qscatterseries.h" |
|
26 | 26 | #include "qlineseries.h" |
|
27 | 27 | #include <qareaseries.h> |
|
28 | 28 | #include <qsplineseries.h> |
|
29 | 29 | #include <qbarset.h> |
|
30 | #include <qabstractbarseries.h> | |
|
31 | 30 | #include <qgroupedbarseries.h> |
|
32 | 31 | #include <qstackedbarseries.h> |
|
33 | 32 | #include <qpercentbarseries.h> |
|
34 | 33 | #include <QPushButton> |
|
35 | 34 | #include <QComboBox> |
|
36 | 35 | #include <QSpinBox> |
|
37 | 36 | #include <QCheckBox> |
|
38 | 37 | #include <QGridLayout> |
|
39 | 38 | #include <QHBoxLayout> |
|
40 | 39 | #include <QLabel> |
|
41 | 40 | #include <QSpacerItem> |
|
42 | 41 | #include <QMessageBox> |
|
43 | 42 | #include <cmath> |
|
44 | 43 | #include <QDebug> |
|
45 | 44 | #include <QStandardItemModel> |
|
46 | 45 | #include <QCategoriesAxis> |
|
47 | 46 | |
|
48 | 47 | |
|
49 | 48 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
50 | 49 | |
|
51 | 50 | MainWidget::MainWidget(QWidget *parent) : |
|
52 | 51 | QWidget(parent), |
|
53 | 52 | m_addSerieDialog(0), |
|
54 | 53 | m_chart(0) |
|
55 | 54 | { |
|
56 | 55 | m_chart = new QChart(); |
|
57 | 56 | |
|
58 | 57 | // Grid layout for the controls for configuring the chart widget |
|
59 | 58 | QGridLayout *grid = new QGridLayout(); |
|
60 | 59 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
61 | 60 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
62 | 61 | grid->addWidget(addSeriesButton, 0, 1); |
|
63 | 62 | initBackroundCombo(grid); |
|
64 | 63 | initScaleControls(grid); |
|
65 | 64 | initThemeCombo(grid); |
|
66 | 65 | initCheckboxes(grid); |
|
67 | 66 | |
|
68 | 67 | // add row with empty label to make all the other rows static |
|
69 | 68 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
70 | 69 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
71 | 70 | |
|
72 | 71 | // Create chart view with the chart |
|
73 | 72 | m_chartView = new QChartView(m_chart, this); |
|
74 | 73 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); |
|
75 | 74 | |
|
76 | 75 | // Another grid layout as a main layout |
|
77 | 76 | QGridLayout *mainLayout = new QGridLayout(); |
|
78 | 77 | mainLayout->addLayout(grid, 0, 0); |
|
79 | 78 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
80 | 79 | setLayout(mainLayout); |
|
81 | 80 | } |
|
82 | 81 | |
|
83 | 82 | // Combo box for selecting the chart's background |
|
84 | 83 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
85 | 84 | { |
|
86 | 85 | QComboBox *backgroundCombo = new QComboBox(this); |
|
87 | 86 | backgroundCombo->addItem("Color"); |
|
88 | 87 | backgroundCombo->addItem("Gradient"); |
|
89 | 88 | backgroundCombo->addItem("Image"); |
|
90 | 89 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
91 | 90 | this, SLOT(backgroundChanged(int))); |
|
92 | 91 | |
|
93 | 92 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
94 | 93 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
95 | 94 | } |
|
96 | 95 | |
|
97 | 96 | // Scale related controls (auto-scale vs. manual min-max values) |
|
98 | 97 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
99 | 98 | { |
|
100 | 99 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
101 | 100 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
102 | 101 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
103 | 102 | m_xMinSpin = new QSpinBox(); |
|
104 | 103 | m_xMinSpin->setMinimum(INT_MIN); |
|
105 | 104 | m_xMinSpin->setMaximum(INT_MAX); |
|
106 | 105 | m_xMinSpin->setValue(0); |
|
107 | 106 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
108 | 107 | m_xMaxSpin = new QSpinBox(); |
|
109 | 108 | m_xMaxSpin->setMinimum(INT_MIN); |
|
110 | 109 | m_xMaxSpin->setMaximum(INT_MAX); |
|
111 | 110 | m_xMaxSpin->setValue(10); |
|
112 | 111 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
113 | 112 | m_yMinSpin = new QSpinBox(); |
|
114 | 113 | m_yMinSpin->setMinimum(INT_MIN); |
|
115 | 114 | m_yMinSpin->setMaximum(INT_MAX); |
|
116 | 115 | m_yMinSpin->setValue(0); |
|
117 | 116 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
118 | 117 | m_yMaxSpin = new QSpinBox(); |
|
119 | 118 | m_yMaxSpin->setMinimum(INT_MIN); |
|
120 | 119 | m_yMaxSpin->setMaximum(INT_MAX); |
|
121 | 120 | m_yMaxSpin->setValue(10); |
|
122 | 121 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
123 | 122 | |
|
124 | 123 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
125 | 124 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
126 | 125 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
127 | 126 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
128 | 127 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
129 | 128 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
130 | 129 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
131 | 130 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
132 | 131 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
133 | 132 | |
|
134 | 133 | m_autoScaleCheck->setChecked(true); |
|
135 | 134 | } |
|
136 | 135 | |
|
137 | 136 | // Combo box for selecting theme |
|
138 | 137 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
139 | 138 | { |
|
140 | 139 | QComboBox *chartTheme = new QComboBox(); |
|
141 | 140 | chartTheme->addItem("Default"); |
|
142 | 141 | chartTheme->addItem("Light"); |
|
143 | 142 | chartTheme->addItem("Blue Cerulean"); |
|
144 | 143 | chartTheme->addItem("Dark"); |
|
145 | 144 | chartTheme->addItem("Brown Sand"); |
|
146 | 145 | chartTheme->addItem("Blue NCS"); |
|
147 | 146 | chartTheme->addItem("High Contrast"); |
|
148 | 147 | chartTheme->addItem("Blue Icy"); |
|
149 | 148 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
150 | 149 | this, SLOT(changeChartTheme(int))); |
|
151 | 150 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
152 | 151 | grid->addWidget(chartTheme, 8, 1); |
|
153 | 152 | } |
|
154 | 153 | |
|
155 | 154 | // Different check boxes for customizing chart |
|
156 | 155 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
157 | 156 | { |
|
158 | 157 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off |
|
159 | 158 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
160 | 159 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); |
|
161 | 160 | zoomCheckBox->setChecked(true); |
|
162 | 161 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
163 | 162 | |
|
164 | 163 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); |
|
165 | 164 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); |
|
166 | 165 | aliasCheckBox->setChecked(false); |
|
167 | 166 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); |
|
168 | 167 | } |
|
169 | 168 | |
|
170 | 169 | void MainWidget::antiAliasToggled(bool enabled) |
|
171 | 170 | { |
|
172 | 171 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); |
|
173 | 172 | } |
|
174 | 173 | |
|
175 | 174 | void MainWidget::addSeries() |
|
176 | 175 | { |
|
177 | 176 | if (!m_addSerieDialog) { |
|
178 | 177 | m_addSerieDialog = new DataSerieDialog(this); |
|
179 | 178 | connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), |
|
180 | 179 | this, SLOT(addSeries(QString,int,int,QString,bool))); |
|
181 | 180 | } |
|
182 | 181 | m_addSerieDialog->exec(); |
|
183 | 182 | } |
|
184 | 183 | |
|
185 | 184 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) |
|
186 | 185 | { |
|
187 | 186 | // TODO: dataCharacteristics |
|
188 | 187 | QList<RealList> testData; |
|
189 | 188 | for (int j(0); j < columnCount; j++) { |
|
190 | 189 | QList <qreal> newColumn; |
|
191 | 190 | for (int i(0); i < rowCount; i++) { |
|
192 | 191 | if (dataCharacteristics == "Sin") { |
|
193 | 192 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
194 | 193 | } else if (dataCharacteristics == "Sin + random") { |
|
195 | 194 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
196 | 195 | } else if (dataCharacteristics == "Random") { |
|
197 | 196 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); |
|
198 | 197 | } else if (dataCharacteristics == "Linear") { |
|
199 | 198 | //newColumn.append(i * (j + 1.0)); |
|
200 | 199 | // TODO: temporary hack to make pie work; prevent zero values: |
|
201 | 200 | newColumn.append(i * (j + 1.0) + 0.1); |
|
202 | 201 | } else { // "constant" |
|
203 | 202 | newColumn.append((j + 1.0)); |
|
204 | 203 | } |
|
205 | 204 | } |
|
206 | 205 | testData.append(newColumn); |
|
207 | 206 | } |
|
208 | 207 | return testData; |
|
209 | 208 | } |
|
210 | 209 | |
|
211 | 210 | QStringList MainWidget::generateLabels(int count) |
|
212 | 211 | { |
|
213 | 212 | QStringList result; |
|
214 | 213 | for (int i(0); i < count; i++) |
|
215 | 214 | result.append("label" + QString::number(i)); |
|
216 | 215 | return result; |
|
217 | 216 | } |
|
218 | 217 | |
|
219 | 218 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) |
|
220 | 219 | { |
|
221 | 220 | qDebug() << "addSeries: " << seriesName |
|
222 | 221 | << " columnCount: " << columnCount |
|
223 | 222 | << " rowCount: " << rowCount |
|
224 | 223 | << " dataCharacteristics: " << dataCharacteristics |
|
225 | 224 | << " labels enabled: " << labelsEnabled; |
|
226 | 225 | m_defaultSeriesName = seriesName; |
|
227 | 226 | |
|
228 | 227 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); |
|
229 | 228 | |
|
230 | 229 | // Line series and scatter series use similar data |
|
231 | 230 | if (seriesName == "Line") { |
|
232 | 231 | for (int j(0); j < data.count(); j ++) { |
|
233 | 232 | QList<qreal> column = data.at(j); |
|
234 | 233 | QLineSeries *series = new QLineSeries(); |
|
235 | 234 | series->setName("line" + QString::number(j)); |
|
236 | 235 | for (int i(0); i < column.count(); i++) |
|
237 | 236 | series->append(i, column.at(i)); |
|
238 | 237 | m_chart->addSeries(series); |
|
239 | 238 | } |
|
240 | 239 | } else if (seriesName == "Area") { |
|
241 | 240 | // TODO: lower series for the area? |
|
242 | 241 | for (int j(0); j < data.count(); j ++) { |
|
243 | 242 | QList<qreal> column = data.at(j); |
|
244 | 243 | QLineSeries *lineSeries = new QLineSeries(); |
|
245 | 244 | for (int i(0); i < column.count(); i++) |
|
246 | 245 | lineSeries->append(i, column.at(i)); |
|
247 | 246 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); |
|
248 | 247 | areaSeries->setName("area" + QString::number(j)); |
|
249 | 248 | m_chart->addSeries(areaSeries); |
|
250 | 249 | } |
|
251 | 250 | } else if (seriesName == "Scatter") { |
|
252 | 251 | for (int j(0); j < data.count(); j++) { |
|
253 | 252 | QList<qreal> column = data.at(j); |
|
254 | 253 | QScatterSeries *series = new QScatterSeries(); |
|
255 | 254 | series->setName("scatter" + QString::number(j)); |
|
256 | 255 | for (int i(0); i < column.count(); i++) |
|
257 | 256 | series->append(i, column.at(i)); |
|
258 | 257 | m_chart->addSeries(series); |
|
259 | 258 | } |
|
260 | 259 | } else if (seriesName == "Pie") { |
|
261 | 260 | QStringList labels = generateLabels(rowCount); |
|
262 | 261 | for (int j(0); j < data.count(); j++) { |
|
263 | 262 | QPieSeries *series = new QPieSeries(); |
|
264 | 263 | QList<qreal> column = data.at(j); |
|
265 | 264 | for (int i(0); i < column.count(); i++) |
|
266 | 265 | series->append(labels.at(i), column.at(i)); |
|
267 | 266 | m_chart->addSeries(series); |
|
268 | 267 | } |
|
269 |
} else if (seriesName == " |
|
|
270 | || seriesName == "Grouped bar" | |
|
268 | } else if (seriesName == "Grouped bar" | |
|
271 | 269 | || seriesName == "Stacked bar" |
|
272 | 270 | || seriesName == "Percent bar") { |
|
273 | 271 | QStringList category; |
|
274 | 272 | QStringList labels = generateLabels(rowCount); |
|
275 | 273 | foreach(QString label, labels) |
|
276 | 274 | category << label; |
|
277 | 275 | QAbstractBarSeries* series = 0; |
|
278 |
if (seriesName == " |
|
|
279 | series = new QAbstractBarSeries(this); | |
|
280 | QCategoriesAxis* axis = new QCategoriesAxis(); | |
|
281 | axis->append(category); | |
|
282 | m_chart->setAxisX(axis,series); | |
|
283 | } else if (seriesName == "Grouped bar") { | |
|
276 | if (seriesName == "Grouped bar") { | |
|
284 | 277 | series = new QGroupedBarSeries(this); |
|
285 | 278 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
286 | 279 | axis->append(category); |
|
287 | 280 | m_chart->setAxisX(axis,series); |
|
288 | 281 | } else if (seriesName == "Stacked bar") { |
|
289 | 282 | series = new QStackedBarSeries(this); |
|
290 | 283 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
291 | 284 | axis->append(category); |
|
292 | 285 | m_chart->setAxisX(axis,series); |
|
293 | 286 | } else { |
|
294 | 287 | series = new QPercentBarSeries(this); |
|
295 | 288 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
296 | 289 | axis->append(category); |
|
297 | 290 | m_chart->setAxisX(axis,series); |
|
298 | 291 | } |
|
299 | 292 | |
|
300 | 293 | for (int j(0); j < data.count(); j++) { |
|
301 | 294 | QList<qreal> column = data.at(j); |
|
302 | 295 | QBarSet *set = new QBarSet("set" + QString::number(j)); |
|
303 | 296 | for (int i(0); i < column.count(); i++) |
|
304 | 297 | *set << column.at(i); |
|
305 | 298 | series->append(set); |
|
306 | 299 | } |
|
307 | 300 | |
|
308 | 301 | m_chart->addSeries(series); |
|
309 | 302 | } else if (seriesName == "Spline") { |
|
310 | 303 | for (int j(0); j < data.count(); j ++) { |
|
311 | 304 | QList<qreal> column = data.at(j); |
|
312 | 305 | QSplineSeries *series = new QSplineSeries(); |
|
313 | 306 | for (int i(0); i < column.count(); i++) |
|
314 | 307 | series->append(i, column.at(i)); |
|
315 | 308 | m_chart->addSeries(series); |
|
316 | 309 | } |
|
317 | 310 | } |
|
318 | 311 | m_chart->createDefaultAxes(); |
|
319 | 312 | } |
|
320 | 313 | |
|
321 | 314 | void MainWidget::backgroundChanged(int itemIndex) |
|
322 | 315 | { |
|
323 | 316 | qDebug() << "backgroundChanged: " << itemIndex; |
|
324 | 317 | } |
|
325 | 318 | |
|
326 | 319 | void MainWidget::autoScaleChanged(int value) |
|
327 | 320 | { |
|
328 | 321 | if (value) { |
|
329 | 322 | // TODO: enable auto scaling |
|
330 | 323 | } else { |
|
331 | 324 | // TODO: set scaling manually (and disable auto scaling) |
|
332 | 325 | } |
|
333 | 326 | |
|
334 | 327 | m_xMinSpin->setEnabled(!value); |
|
335 | 328 | m_xMaxSpin->setEnabled(!value); |
|
336 | 329 | m_yMinSpin->setEnabled(!value); |
|
337 | 330 | m_yMaxSpin->setEnabled(!value); |
|
338 | 331 | } |
|
339 | 332 | |
|
340 | 333 | void MainWidget::xMinChanged(int value) |
|
341 | 334 | { |
|
342 | 335 | qDebug() << "xMinChanged: " << value; |
|
343 | 336 | } |
|
344 | 337 | |
|
345 | 338 | void MainWidget::xMaxChanged(int value) |
|
346 | 339 | { |
|
347 | 340 | qDebug() << "xMaxChanged: " << value; |
|
348 | 341 | } |
|
349 | 342 | |
|
350 | 343 | void MainWidget::yMinChanged(int value) |
|
351 | 344 | { |
|
352 | 345 | qDebug() << "yMinChanged: " << value; |
|
353 | 346 | } |
|
354 | 347 | |
|
355 | 348 | void MainWidget::yMaxChanged(int value) |
|
356 | 349 | { |
|
357 | 350 | qDebug() << "yMaxChanged: " << value; |
|
358 | 351 | } |
|
359 | 352 | |
|
360 | 353 | void MainWidget::changeChartTheme(int themeIndex) |
|
361 | 354 | { |
|
362 | 355 | qDebug() << "changeChartTheme: " << themeIndex; |
|
363 | 356 | m_chart->setTheme((QChart::ChartTheme) themeIndex); |
|
364 | 357 | } |
General Comments 0
You need to be logged in to leave comments.
Login now