@@ -1,868 +1,869 | |||
|
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 "qabstractaxis.h" |
|
22 | 22 | #include "qabstractaxis_p.h" |
|
23 | 23 | #include "chartdataset_p.h" |
|
24 | 24 | #include "charttheme_p.h" |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | /*! |
|
29 | 29 | \class QAbstractAxis |
|
30 | 30 | \brief The QAbstractAxis class is used for manipulating chart's axis. |
|
31 | 31 | \mainclass |
|
32 | 32 | |
|
33 | 33 | There is only one x Axis visible at the time, however there can be multiple y axes. |
|
34 | 34 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
35 | 35 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
36 | 36 | */ |
|
37 | 37 | |
|
38 | 38 | /*! |
|
39 | 39 | \qmlclass AbstractAxis QAbstractAxis |
|
40 | 40 | \brief The Axis element is used for manipulating chart's axes |
|
41 | 41 | |
|
42 | 42 | There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView. |
|
43 | 43 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
44 | 44 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
45 | 45 | |
|
46 | 46 | To access Axes you can use ChartView API. For example: |
|
47 | 47 | \code |
|
48 | 48 | ChartView { |
|
49 | 49 | axisX.min: 0 |
|
50 | 50 | axisX.max: 3 |
|
51 | 51 | axisX.ticksCount: 4 |
|
52 | 52 | axisY.min: 0 |
|
53 | 53 | axisY.max: 4 |
|
54 | 54 | // Add a few series... |
|
55 | 55 | } |
|
56 | 56 | \endcode |
|
57 | 57 | */ |
|
58 | 58 | |
|
59 | 59 | /*! |
|
60 | 60 | \enum QAbstractAxis::AxisType |
|
61 | 61 | |
|
62 | 62 | The type of the series object. |
|
63 | 63 | |
|
64 | 64 | \value AxisTypeNoAxis |
|
65 | 65 | \value AxisTypeValue |
|
66 | 66 | \value AxisTypeBarCategory |
|
67 | 67 | \value AxisTypeCategory |
|
68 | 68 | \value AxisTypeDateTime |
|
69 | 69 | */ |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | *\fn void QAbstractAxis::type() const |
|
73 | 73 | Returns the type of the axis |
|
74 | 74 | */ |
|
75 | 75 | |
|
76 | 76 | /*! |
|
77 | 77 | \property QAbstractAxis::lineVisible |
|
78 | 78 | The visibility of the axis line |
|
79 | 79 | */ |
|
80 | 80 | /*! |
|
81 | 81 | \qmlproperty bool AbstractAxis::lineVisible |
|
82 | 82 | The visibility of the axis line |
|
83 | 83 | */ |
|
84 | 84 | |
|
85 | 85 | /*! |
|
86 | 86 | \property QAbstractAxis::labelsVisible |
|
87 | 87 | Defines if axis labels are visible. |
|
88 | 88 | */ |
|
89 | 89 | /*! |
|
90 | 90 | \qmlproperty bool AbstractAxis::labelsVisible |
|
91 | 91 | Defines if axis labels are visible. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \property QAbstractAxis::visible |
|
96 | 96 | The visibility of the axis. |
|
97 | 97 | */ |
|
98 | 98 | /*! |
|
99 | 99 | \qmlproperty bool AbstractAxis::visible |
|
100 | 100 | The visibility of the axis. |
|
101 | 101 | */ |
|
102 | 102 | |
|
103 | 103 | /*! |
|
104 | 104 | \property QAbstractAxis::gridVisible |
|
105 | 105 | The visibility of the grid lines. |
|
106 | 106 | */ |
|
107 | 107 | /*! |
|
108 | 108 | \qmlproperty bool AbstractAxis::gridVisible |
|
109 | 109 | The visibility of the grid lines. |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | \property QAbstractAxis::color |
|
114 | 114 | The color of the axis and ticks. |
|
115 | 115 | */ |
|
116 | 116 | /*! |
|
117 | 117 | \qmlproperty color AbstractAxis::color |
|
118 | 118 | The color of the axis and ticks. |
|
119 | 119 | */ |
|
120 | 120 | |
|
121 | 121 | /*! |
|
122 | 122 | \property QAbstractAxis::labelsFont |
|
123 | 123 | The font of the axis labels. |
|
124 | 124 | */ |
|
125 | 125 | |
|
126 | 126 | /*! |
|
127 | 127 | \qmlproperty Font AbstractAxis::labelsFont |
|
128 | 128 | The font of the axis labels. |
|
129 | 129 | |
|
130 | 130 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
131 | 131 | */ |
|
132 | 132 | |
|
133 | 133 | /*! |
|
134 | 134 | \property QAbstractAxis::labelsColor |
|
135 | 135 | The color of the axis labels. |
|
136 | 136 | */ |
|
137 | 137 | /*! |
|
138 | 138 | \qmlproperty color AbstractAxis::labelsColor |
|
139 | 139 | The color of the axis labels. |
|
140 | 140 | */ |
|
141 | 141 | |
|
142 | 142 | /*! |
|
143 | 143 | \property QAbstractAxis::labelsAngle |
|
144 | 144 | The angle of the axis labels in degrees. |
|
145 | 145 | */ |
|
146 | 146 | /*! |
|
147 | 147 | \qmlproperty int AbstractAxis::labelsAngle |
|
148 | 148 | The angle of the axis labels in degrees. |
|
149 | 149 | */ |
|
150 | 150 | |
|
151 | 151 | /*! |
|
152 | 152 | \property QAbstractAxis::shadesVisible |
|
153 | 153 | The visibility of the axis shades. |
|
154 | 154 | */ |
|
155 | 155 | /*! |
|
156 | 156 | \qmlproperty bool AbstractAxis::shadesVisible |
|
157 | 157 | The visibility of the axis shades. |
|
158 | 158 | */ |
|
159 | 159 | |
|
160 | 160 | /*! |
|
161 | 161 | \property QAbstractAxis::shadesColor |
|
162 | 162 | The fill (brush) color of the axis shades. |
|
163 | 163 | */ |
|
164 | 164 | /*! |
|
165 | 165 | \qmlproperty color AbstractAxis::shadesColor |
|
166 | 166 | The fill (brush) color of the axis shades. |
|
167 | 167 | */ |
|
168 | 168 | |
|
169 | 169 | /*! |
|
170 | 170 | \property QAbstractAxis::shadesBorderColor |
|
171 | 171 | The border (pen) color of the axis shades. |
|
172 | 172 | */ |
|
173 | 173 | /*! |
|
174 | 174 | \qmlproperty color AbstractAxis::shadesBorderColor |
|
175 | 175 | The border (pen) color of the axis shades. |
|
176 | 176 | */ |
|
177 | 177 | |
|
178 | 178 | /*! |
|
179 | 179 | \property QAbstractAxis::titleVisible |
|
180 | 180 | The visibility of the axis title. By default the value is true. |
|
181 | 181 | */ |
|
182 | 182 | /*! |
|
183 | 183 | \qmlproperty bool AbstractAxis::titleVisible |
|
184 | 184 | The visibility of the axis title. By default the value is true. |
|
185 | 185 | */ |
|
186 | 186 | |
|
187 | 187 | /*! |
|
188 | 188 | \property QAbstractAxis::titleFont |
|
189 | 189 | The font of the title of the axis. |
|
190 | 190 | */ |
|
191 | 191 | /*! |
|
192 | 192 | \qmlproperty Font AbstractAxis::title |
|
193 | 193 | The font of the title of the axis. |
|
194 | 194 | */ |
|
195 | 195 | |
|
196 | 196 | /*! |
|
197 | 197 | \property QAbstractAxis::title |
|
198 | 198 | The title of the axis. Empty by default. |
|
199 | 199 | */ |
|
200 | 200 | /*! |
|
201 | 201 | \qmlproperty string AbstractAxis::title |
|
202 | 202 | The title of the axis. Empty string by default. |
|
203 | 203 | */ |
|
204 | 204 | |
|
205 | 205 | /*! |
|
206 | 206 | \property QAbstractAxis::alignment |
|
207 | 207 | The alignment of the axis. Either Qt::AlignLeft or Qt::AlignBottom. |
|
208 | 208 | */ |
|
209 | 209 | /*! |
|
210 | 210 | \qmlproperty alignment AbstractAxis::alignment |
|
211 | 211 | The alignment of the axis. Either Qt.AlignLeft or Qt.AlignBottom. |
|
212 | 212 | */ |
|
213 | 213 | |
|
214 | 214 | /*! |
|
215 | 215 | \fn void QAbstractAxis::visibleChanged(bool visible) |
|
216 | 216 | Visibility of the axis has changed to \a visible. |
|
217 | 217 | */ |
|
218 | 218 | /*! |
|
219 | 219 | \qmlsignal AbstractAxis::onVisibleChanged(bool visible) |
|
220 | 220 | Visibility of the axis has changed to \a visible. |
|
221 | 221 | */ |
|
222 | 222 | |
|
223 | 223 | /*! |
|
224 | 224 | \fn void QAbstractAxis::lineVisibleChanged(bool visible) |
|
225 | 225 | Visibility of the axis line has changed to \a visible. |
|
226 | 226 | */ |
|
227 | 227 | /*! |
|
228 | 228 | \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible) |
|
229 | 229 | Visibility of the axis line has changed to \a visible. |
|
230 | 230 | */ |
|
231 | 231 | |
|
232 | 232 | /*! |
|
233 | 233 | \fn void QAbstractAxis::labelsVisibleChanged(bool visible) |
|
234 | 234 | Visibility of the labels of the axis has changed to \a visible. |
|
235 | 235 | */ |
|
236 | 236 | /*! |
|
237 | 237 | \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible) |
|
238 | 238 | Visibility of the labels of the axis has changed to \a visible. |
|
239 | 239 | */ |
|
240 | 240 | |
|
241 | 241 | /*! |
|
242 | 242 | \fn void QAbstractAxis::gridVisibleChanged(bool visible) |
|
243 | 243 | Visibility of the grid lines of the axis has changed to \a visible. |
|
244 | 244 | */ |
|
245 | 245 | /*! |
|
246 | 246 | \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible) |
|
247 | 247 | Visibility of the grid lines of the axis has changed to \a visible. |
|
248 | 248 | */ |
|
249 | 249 | |
|
250 | 250 | /*! |
|
251 | 251 | \fn void QAbstractAxis::colorChanged(QColor color) |
|
252 | 252 | Emitted if the \a color of the axis is changed. |
|
253 | 253 | */ |
|
254 | 254 | /*! |
|
255 | 255 | \qmlsignal AbstractAxis::onColorChanged(QColor color) |
|
256 | 256 | Emitted if the \a color of the axis is changed. |
|
257 | 257 | */ |
|
258 | 258 | |
|
259 | 259 | /*! |
|
260 | 260 | \fn void QAbstractAxis::labelsColorChanged(QColor color) |
|
261 | 261 | Emitted if the \a color of the axis labels is changed. |
|
262 | 262 | */ |
|
263 | 263 | /*! |
|
264 | 264 | \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color) |
|
265 | 265 | Emitted if the \a color of the axis labels is changed. |
|
266 | 266 | */ |
|
267 | 267 | |
|
268 | 268 | /*! |
|
269 | 269 | \fn void QAbstractAxis::shadesVisibleChanged(bool) |
|
270 | 270 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
271 | 271 | */ |
|
272 | 272 | /*! |
|
273 | 273 | \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible) |
|
274 | 274 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
275 | 275 | */ |
|
276 | 276 | |
|
277 | 277 | /*! |
|
278 | 278 | \fn void QAbstractAxis::shadesColorChanged(QColor color) |
|
279 | 279 | Emitted if the \a color of the axis shades is changed. |
|
280 | 280 | */ |
|
281 | 281 | /*! |
|
282 | 282 | \qmlsignal AbstractAxis::onShadesColorChanged(QColor color) |
|
283 | 283 | Emitted if the \a color of the axis shades is changed. |
|
284 | 284 | */ |
|
285 | 285 | |
|
286 | 286 | /*! |
|
287 | 287 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) |
|
288 | 288 | Emitted if the border \a color of the axis shades is changed. |
|
289 | 289 | */ |
|
290 | 290 | /*! |
|
291 | 291 | \qmlsignal AbstractAxis::onBorderColorChanged(QColor color) |
|
292 | 292 | Emitted if the border \a color of the axis shades is changed. |
|
293 | 293 | */ |
|
294 | 294 | |
|
295 | 295 | /*! |
|
296 | 296 | \internal |
|
297 | 297 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
298 | 298 | QChart when axis added. |
|
299 | 299 | */ |
|
300 | 300 | |
|
301 | 301 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) |
|
302 | 302 | : QObject(parent), |
|
303 | 303 | d_ptr(&d) |
|
304 | 304 | { |
|
305 | 305 | } |
|
306 | 306 | |
|
307 | 307 | /*! |
|
308 | 308 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
309 | 309 | */ |
|
310 | 310 | |
|
311 | 311 | QAbstractAxis::~QAbstractAxis() |
|
312 | 312 | { |
|
313 | 313 | if (d_ptr->m_chart) |
|
314 | 314 | qFatal("Still binded axis detected !"); |
|
315 | 315 | } |
|
316 | 316 | |
|
317 | 317 | /*! |
|
318 | 318 | Sets \a pen used to draw axis line and ticks. |
|
319 | 319 | */ |
|
320 | 320 | void QAbstractAxis::setLinePen(const QPen &pen) |
|
321 | 321 | { |
|
322 | 322 | if (d_ptr->m_axisPen != pen) { |
|
323 | 323 | d_ptr->m_axisPen = pen; |
|
324 | 324 | emit linePenChanged(pen); |
|
325 | 325 | } |
|
326 | 326 | } |
|
327 | 327 | |
|
328 | 328 | /*! |
|
329 | 329 | Returns pen used to draw axis and ticks. |
|
330 | 330 | */ |
|
331 | 331 | QPen QAbstractAxis::linePen() const |
|
332 | 332 | { |
|
333 | 333 | return d_ptr->m_axisPen; |
|
334 | 334 | } |
|
335 | 335 | |
|
336 | 336 | //TODO: remove me |
|
337 | 337 | void QAbstractAxis::setLinePenColor(QColor color) |
|
338 | 338 | { |
|
339 | 339 | QPen p = d_ptr->m_axisPen; |
|
340 | 340 | if (p.color() != color) { |
|
341 | 341 | p.setColor(color); |
|
342 | 342 | setLinePen(p); |
|
343 | 343 | emit colorChanged(color); |
|
344 | 344 | } |
|
345 | 345 | } |
|
346 | 346 | |
|
347 | 347 | QColor QAbstractAxis::linePenColor() const |
|
348 | 348 | { |
|
349 | 349 | return d_ptr->m_axisPen.color(); |
|
350 | 350 | } |
|
351 | 351 | |
|
352 | 352 | /*! |
|
353 | 353 | Sets if axis and ticks are \a visible. |
|
354 | 354 | */ |
|
355 | 355 | void QAbstractAxis::setLineVisible(bool visible) |
|
356 | 356 | { |
|
357 | 357 | if (d_ptr->m_arrowVisible != visible) { |
|
358 | 358 | d_ptr->m_arrowVisible = visible; |
|
359 | 359 | emit lineVisibleChanged(visible); |
|
360 | 360 | } |
|
361 | 361 | } |
|
362 | 362 | |
|
363 | 363 | bool QAbstractAxis::isLineVisible() const |
|
364 | 364 | { |
|
365 | 365 | return d_ptr->m_arrowVisible; |
|
366 | 366 | } |
|
367 | 367 | |
|
368 | 368 | void QAbstractAxis::setGridLineVisible(bool visible) |
|
369 | 369 | { |
|
370 | 370 | if (d_ptr->m_gridLineVisible != visible) { |
|
371 | 371 | d_ptr->m_gridLineVisible = visible; |
|
372 | 372 | emit gridVisibleChanged(visible); |
|
373 | 373 | } |
|
374 | 374 | } |
|
375 | 375 | |
|
376 | 376 | bool QAbstractAxis::isGridLineVisible() const |
|
377 | 377 | { |
|
378 | 378 | return d_ptr->m_gridLineVisible; |
|
379 | 379 | } |
|
380 | 380 | |
|
381 | 381 | /*! |
|
382 | 382 | Sets \a pen used to draw grid line. |
|
383 | 383 | */ |
|
384 | 384 | void QAbstractAxis::setGridLinePen(const QPen &pen) |
|
385 | 385 | { |
|
386 | 386 | if (d_ptr->m_gridLinePen != pen) { |
|
387 | 387 | d_ptr->m_gridLinePen = pen; |
|
388 | 388 | emit gridLinePenChanged(pen); |
|
389 | 389 | } |
|
390 | 390 | } |
|
391 | 391 | |
|
392 | 392 | /*! |
|
393 | 393 | Returns pen used to draw grid. |
|
394 | 394 | */ |
|
395 | 395 | QPen QAbstractAxis::gridLinePen() const |
|
396 | 396 | { |
|
397 | 397 | return d_ptr->m_gridLinePen; |
|
398 | 398 | } |
|
399 | 399 | |
|
400 | 400 | void QAbstractAxis::setLabelsVisible(bool visible) |
|
401 | 401 | { |
|
402 | 402 | if (d_ptr->m_labelsVisible != visible) { |
|
403 | 403 | d_ptr->m_labelsVisible = visible; |
|
404 | 404 | emit labelsVisibleChanged(visible); |
|
405 | 405 | } |
|
406 | 406 | } |
|
407 | 407 | |
|
408 | 408 | bool QAbstractAxis::labelsVisible() const |
|
409 | 409 | { |
|
410 | 410 | return d_ptr->m_labelsVisible; |
|
411 | 411 | } |
|
412 | 412 | |
|
413 | 413 | /*! |
|
414 | 414 | Sets \a pen used to draw labels. |
|
415 | 415 | */ |
|
416 | 416 | void QAbstractAxis::setLabelsPen(const QPen &pen) |
|
417 | 417 | { |
|
418 | 418 | if (d_ptr->m_labelsPen != pen) { |
|
419 | 419 | d_ptr->m_labelsPen = pen; |
|
420 | 420 | emit labelsPenChanged(pen); |
|
421 | 421 | } |
|
422 | 422 | } |
|
423 | 423 | |
|
424 | 424 | /*! |
|
425 | 425 | Returns the pen used to labels. |
|
426 | 426 | */ |
|
427 | 427 | QPen QAbstractAxis::labelsPen() const |
|
428 | 428 | { |
|
429 | 429 | return d_ptr->m_labelsPen; |
|
430 | 430 | } |
|
431 | 431 | |
|
432 | 432 | /*! |
|
433 | 433 | Sets \a brush used to draw labels. |
|
434 | 434 | */ |
|
435 | 435 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) |
|
436 | 436 | { |
|
437 | 437 | if (d_ptr->m_labelsBrush != brush) { |
|
438 | 438 | d_ptr->m_labelsBrush = brush; |
|
439 | 439 | emit labelsBrushChanged(brush); |
|
440 | 440 | } |
|
441 | 441 | } |
|
442 | 442 | |
|
443 | 443 | /*! |
|
444 | 444 | Returns brush used to draw labels. |
|
445 | 445 | */ |
|
446 | 446 | QBrush QAbstractAxis::labelsBrush() const |
|
447 | 447 | { |
|
448 | 448 | return d_ptr->m_labelsBrush; |
|
449 | 449 | } |
|
450 | 450 | |
|
451 | 451 | /*! |
|
452 | 452 | Sets \a font used to draw labels. |
|
453 | 453 | */ |
|
454 | 454 | void QAbstractAxis::setLabelsFont(const QFont &font) |
|
455 | 455 | { |
|
456 | 456 | if (d_ptr->m_labelsFont != font) { |
|
457 | 457 | d_ptr->m_labelsFont = font; |
|
458 | 458 | emit labelsFontChanged(font); |
|
459 | 459 | } |
|
460 | 460 | } |
|
461 | 461 | |
|
462 | 462 | /*! |
|
463 | 463 | Returns font used to draw labels. |
|
464 | 464 | */ |
|
465 | 465 | QFont QAbstractAxis::labelsFont() const |
|
466 | 466 | { |
|
467 | 467 | return d_ptr->m_labelsFont; |
|
468 | 468 | } |
|
469 | 469 | |
|
470 | 470 | void QAbstractAxis::setLabelsAngle(int angle) |
|
471 | 471 | { |
|
472 | 472 | if (d_ptr->m_labelsAngle != angle) { |
|
473 | 473 | d_ptr->m_labelsAngle = angle; |
|
474 | 474 | emit labelsAngleChanged(angle); |
|
475 | 475 | } |
|
476 | 476 | } |
|
477 | 477 | |
|
478 | 478 | int QAbstractAxis::labelsAngle() const |
|
479 | 479 | { |
|
480 | 480 | return d_ptr->m_labelsAngle; |
|
481 | 481 | } |
|
482 | 482 | //TODO: remove me |
|
483 | 483 | void QAbstractAxis::setLabelsColor(QColor color) |
|
484 | 484 | { |
|
485 | 485 | QBrush b = d_ptr->m_labelsBrush; |
|
486 | 486 | if (b.color() != color) { |
|
487 | 487 | b.setColor(color); |
|
488 | 488 | setLabelsBrush(b); |
|
489 | 489 | emit labelsColorChanged(color); |
|
490 | 490 | } |
|
491 | 491 | } |
|
492 | 492 | |
|
493 | 493 | QColor QAbstractAxis::labelsColor() const |
|
494 | 494 | { |
|
495 | 495 | return d_ptr->m_labelsBrush.color(); |
|
496 | 496 | } |
|
497 | 497 | |
|
498 | 498 | void QAbstractAxis::setTitleVisible(bool visible) |
|
499 | 499 | { |
|
500 | 500 | if (d_ptr->m_titleVisible != visible) { |
|
501 | 501 | d_ptr->m_titleVisible = visible; |
|
502 | 502 | emit labelsVisibleChanged(visible); |
|
503 | 503 | } |
|
504 | 504 | } |
|
505 | 505 | |
|
506 | 506 | bool QAbstractAxis::titleVisible() const |
|
507 | 507 | { |
|
508 | 508 | return d_ptr->m_titleVisible; |
|
509 | 509 | } |
|
510 | 510 | |
|
511 | 511 | /*! |
|
512 | 512 | Sets \a pen used to draw title. |
|
513 | 513 | */ |
|
514 | 514 | void QAbstractAxis::setTitlePen(const QPen &pen) |
|
515 | 515 | { |
|
516 | 516 | if (d_ptr->m_titlePen != pen) { |
|
517 | 517 | d_ptr->m_titlePen = pen; |
|
518 | 518 | emit titlePenChanged(pen); |
|
519 | 519 | } |
|
520 | 520 | } |
|
521 | 521 | |
|
522 | 522 | /*! |
|
523 | 523 | Returns the pen used to title. |
|
524 | 524 | */ |
|
525 | 525 | QPen QAbstractAxis::titlePen() const |
|
526 | 526 | { |
|
527 | 527 | return d_ptr->m_titlePen; |
|
528 | 528 | } |
|
529 | 529 | |
|
530 | 530 | /*! |
|
531 | 531 | Sets \a brush used to draw title. |
|
532 | 532 | */ |
|
533 | 533 | void QAbstractAxis::setTitleBrush(const QBrush &brush) |
|
534 | 534 | { |
|
535 | 535 | if (d_ptr->m_titleBrush != brush) { |
|
536 | 536 | d_ptr->m_titleBrush = brush; |
|
537 | 537 | emit titleBrushChanged(brush); |
|
538 | 538 | } |
|
539 | 539 | } |
|
540 | 540 | |
|
541 | 541 | /*! |
|
542 | 542 | Returns brush used to draw title. |
|
543 | 543 | */ |
|
544 | 544 | QBrush QAbstractAxis::titleBrush() const |
|
545 | 545 | { |
|
546 | 546 | return d_ptr->m_titleBrush; |
|
547 | 547 | } |
|
548 | 548 | |
|
549 | 549 | /*! |
|
550 | 550 | Sets \a font used to draw title. |
|
551 | 551 | */ |
|
552 | 552 | void QAbstractAxis::setTitleFont(const QFont &font) |
|
553 | 553 | { |
|
554 | 554 | if (d_ptr->m_titleFont != font) { |
|
555 | 555 | d_ptr->m_titleFont = font; |
|
556 | 556 | emit titleFontChanged(font); |
|
557 | 557 | } |
|
558 | 558 | } |
|
559 | 559 | |
|
560 | 560 | /*! |
|
561 | 561 | Returns font used to draw title. |
|
562 | 562 | */ |
|
563 | 563 | QFont QAbstractAxis::titleFont() const |
|
564 | 564 | { |
|
565 | 565 | return d_ptr->m_titleFont; |
|
566 | 566 | } |
|
567 | 567 | |
|
568 | 568 | void QAbstractAxis::setTitleText(const QString &title) |
|
569 | 569 | { |
|
570 | 570 | if (d_ptr->m_title != title) { |
|
571 | 571 | d_ptr->m_title = title; |
|
572 | 572 | emit titleTextChanged(title); |
|
573 | 573 | } |
|
574 | 574 | } |
|
575 | 575 | |
|
576 | 576 | QString QAbstractAxis::titleText() const |
|
577 | 577 | { |
|
578 | 578 | return d_ptr->m_title; |
|
579 | 579 | } |
|
580 | 580 | |
|
581 | 581 | |
|
582 | 582 | void QAbstractAxis::setShadesVisible(bool visible) |
|
583 | 583 | { |
|
584 | 584 | if (d_ptr->m_shadesVisible != visible) { |
|
585 | 585 | d_ptr->m_shadesVisible = visible; |
|
586 | 586 | emit shadesVisibleChanged(visible); |
|
587 | 587 | } |
|
588 | 588 | } |
|
589 | 589 | |
|
590 | 590 | bool QAbstractAxis::shadesVisible() const |
|
591 | 591 | { |
|
592 | 592 | return d_ptr->m_shadesVisible; |
|
593 | 593 | } |
|
594 | 594 | |
|
595 | 595 | /*! |
|
596 | 596 | Sets \a pen used to draw shades. |
|
597 | 597 | */ |
|
598 | 598 | void QAbstractAxis::setShadesPen(const QPen &pen) |
|
599 | 599 | { |
|
600 | 600 | if (d_ptr->m_shadesPen != pen) { |
|
601 | 601 | d_ptr->m_shadesPen = pen; |
|
602 | 602 | emit shadesPenChanged(pen); |
|
603 | 603 | } |
|
604 | 604 | } |
|
605 | 605 | |
|
606 | 606 | /*! |
|
607 | 607 | Returns pen used to draw shades. |
|
608 | 608 | */ |
|
609 | 609 | QPen QAbstractAxis::shadesPen() const |
|
610 | 610 | { |
|
611 | 611 | return d_ptr->m_shadesPen; |
|
612 | 612 | } |
|
613 | 613 | |
|
614 | 614 | /*! |
|
615 | 615 | Sets \a brush used to draw shades. |
|
616 | 616 | */ |
|
617 | 617 | void QAbstractAxis::setShadesBrush(const QBrush &brush) |
|
618 | 618 | { |
|
619 | 619 | if (d_ptr->m_shadesBrush != brush) { |
|
620 | 620 | d_ptr->m_shadesBrush = brush; |
|
621 | 621 | emit shadesBrushChanged(brush); |
|
622 | 622 | } |
|
623 | 623 | } |
|
624 | 624 | |
|
625 | 625 | /*! |
|
626 | 626 | Returns brush used to draw shades. |
|
627 | 627 | */ |
|
628 | 628 | QBrush QAbstractAxis::shadesBrush() const |
|
629 | 629 | { |
|
630 | 630 | return d_ptr->m_shadesBrush; |
|
631 | 631 | } |
|
632 | 632 | |
|
633 | 633 | void QAbstractAxis::setShadesColor(QColor color) |
|
634 | 634 | { |
|
635 | 635 | QBrush b = d_ptr->m_shadesBrush; |
|
636 | 636 | if (b.color() != color) { |
|
637 | 637 | b.setColor(color); |
|
638 | 638 | setShadesBrush(b); |
|
639 | 639 | emit shadesColorChanged(color); |
|
640 | 640 | } |
|
641 | 641 | } |
|
642 | 642 | |
|
643 | 643 | QColor QAbstractAxis::shadesColor() const |
|
644 | 644 | { |
|
645 | 645 | return d_ptr->m_shadesBrush.color(); |
|
646 | 646 | } |
|
647 | 647 | |
|
648 | 648 | void QAbstractAxis::setShadesBorderColor(QColor color) |
|
649 | 649 | { |
|
650 | 650 | QPen p = d_ptr->m_shadesPen; |
|
651 | 651 | if (p.color() != color) { |
|
652 | 652 | p.setColor(color); |
|
653 | 653 | setShadesPen(p); |
|
654 | 654 | emit shadesColorChanged(color); |
|
655 | 655 | } |
|
656 | 656 | } |
|
657 | 657 | |
|
658 | 658 | QColor QAbstractAxis::shadesBorderColor() const |
|
659 | 659 | { |
|
660 | 660 | return d_ptr->m_shadesPen.color(); |
|
661 | 661 | } |
|
662 | 662 | |
|
663 | 663 | |
|
664 | 664 | bool QAbstractAxis::isVisible() const |
|
665 | 665 | { |
|
666 | 666 | return d_ptr->m_visible; |
|
667 | 667 | } |
|
668 | 668 | |
|
669 | 669 | /*! |
|
670 | 670 | Sets axis, shades, labels and grid lines to be visible. |
|
671 | 671 | */ |
|
672 | 672 | void QAbstractAxis::setVisible(bool visible) |
|
673 | 673 | { |
|
674 | 674 | if (d_ptr->m_visible != visible) { |
|
675 | 675 | d_ptr->m_visible = visible; |
|
676 | 676 | emit visibleChanged(visible); |
|
677 | 677 | } |
|
678 | 678 | } |
|
679 | 679 | |
|
680 | 680 | |
|
681 | 681 | /*! |
|
682 | 682 | Sets axis, shades, labels and grid lines to be visible. |
|
683 | 683 | */ |
|
684 | 684 | void QAbstractAxis::show() |
|
685 | 685 | { |
|
686 | 686 | setVisible(true); |
|
687 | 687 | } |
|
688 | 688 | |
|
689 | 689 | /*! |
|
690 | 690 | Sets axis, shades, labels and grid lines to not be visible. |
|
691 | 691 | */ |
|
692 | 692 | void QAbstractAxis::hide() |
|
693 | 693 | { |
|
694 | 694 | setVisible(false); |
|
695 | 695 | } |
|
696 | 696 | |
|
697 | 697 | /*! |
|
698 | 698 | Sets the minimum value shown on the axis. |
|
699 | 699 | Depending on the actual axis type the \a min parameter is converted to appropriate type. |
|
700 | 700 | If the conversion is impossible then the function call does nothing |
|
701 | 701 | */ |
|
702 | 702 | void QAbstractAxis::setMin(const QVariant &min) |
|
703 | 703 | { |
|
704 | 704 | d_ptr->setMin(min); |
|
705 | 705 | } |
|
706 | 706 | |
|
707 | 707 | /*! |
|
708 | 708 | Sets the maximum value shown on the axis. |
|
709 | 709 | Depending on the actual axis type the \a max parameter is converted to appropriate type. |
|
710 | 710 | If the conversion is impossible then the function call does nothing |
|
711 | 711 | */ |
|
712 | 712 | void QAbstractAxis::setMax(const QVariant &max) |
|
713 | 713 | { |
|
714 | 714 | d_ptr->setMax(max); |
|
715 | 715 | } |
|
716 | 716 | |
|
717 | 717 | /*! |
|
718 | 718 | Sets the range shown on the axis. |
|
719 | 719 | Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types. |
|
720 | 720 | If the conversion is impossible then the function call does nothing. |
|
721 | 721 | */ |
|
722 | 722 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) |
|
723 | 723 | { |
|
724 | 724 | d_ptr->setRange(min, max); |
|
725 | 725 | } |
|
726 | 726 | |
|
727 | 727 | |
|
728 | 728 | /*! |
|
729 | 729 | Returns the orientation in which the axis is being used (Vertical or Horizontal) |
|
730 | 730 | */ |
|
731 | 731 | // NOTE: should have const but it breaks BC: |
|
732 | 732 | // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function |
|
733 | 733 | Qt::Orientation QAbstractAxis::orientation() |
|
734 | 734 | { |
|
735 | 735 | return d_ptr->orientation(); |
|
736 | 736 | } |
|
737 | 737 | |
|
738 | 738 | Qt::Alignment QAbstractAxis::alignment() const |
|
739 | 739 | { |
|
740 | 740 | return d_ptr->alignment(); |
|
741 | 741 | } |
|
742 | 742 | |
|
743 | 743 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
744 | 744 | |
|
745 | 745 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q) |
|
746 | 746 | : q_ptr(q), |
|
747 | 747 | m_chart(0), |
|
748 | 748 | m_orientation(Qt::Orientation(0)), |
|
749 | 749 | m_alignment(0), |
|
750 | 750 | m_visible(true), |
|
751 | 751 | m_arrowVisible(true), |
|
752 | 752 | m_gridLineVisible(true), |
|
753 | 753 | m_labelsVisible(true), |
|
754 | 754 | m_labelsAngle(0), |
|
755 | 755 | m_shadesVisible(false), |
|
756 | 756 | m_shadesBrush(Qt::SolidPattern), |
|
757 | 757 | m_shadesOpacity(1.0), |
|
758 | 758 | m_dirty(false) |
|
759 | 759 | { |
|
760 | 760 | |
|
761 | 761 | } |
|
762 | 762 | |
|
763 | 763 | QAbstractAxisPrivate::~QAbstractAxisPrivate() |
|
764 | 764 | { |
|
765 | 765 | } |
|
766 | 766 | |
|
767 | 767 | void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment) |
|
768 | 768 | { |
|
769 | 769 | switch(alignment) { |
|
770 | 770 | case Qt::AlignTop: |
|
771 | 771 | case Qt::AlignBottom: |
|
772 | 772 | m_orientation = Qt::Horizontal; |
|
773 | 773 | break; |
|
774 | 774 | case Qt::AlignLeft: |
|
775 | 775 | case Qt::AlignRight: |
|
776 | 776 | m_orientation = Qt::Vertical; |
|
777 | 777 | break; |
|
778 | 778 | default: |
|
779 | 779 | qWarning()<<"No alignment specified !"; |
|
780 | 780 | break; |
|
781 | 781 | }; |
|
782 | 782 | m_alignment=alignment; |
|
783 | 783 | } |
|
784 | 784 | |
|
785 | 785 | void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced) |
|
786 | 786 | { |
|
787 | 787 | QPen pen; |
|
788 | 788 | QBrush brush; |
|
789 | 789 | QFont font; |
|
790 | 790 | |
|
791 | 791 | bool axisX = m_orientation == Qt::Horizontal; |
|
792 | 792 | |
|
793 | 793 | if (m_arrowVisible) { |
|
794 | 794 | |
|
795 | 795 | if (forced || brush == m_labelsBrush){ |
|
796 | 796 | q_ptr->setLabelsBrush(theme->labelBrush()); |
|
797 | 797 | } |
|
798 | 798 | //TODO: introduce axis brush |
|
799 | 799 | if (forced || brush == m_titleBrush){ |
|
800 | 800 | q_ptr->setTitleBrush(theme->labelBrush()); |
|
801 | 801 | } |
|
802 | 802 | if (forced || pen == m_labelsPen){ |
|
803 | 803 | q_ptr->setLabelsPen(Qt::NoPen);// NoPen for performance reasons |
|
804 | 804 | } |
|
805 | 805 | if (forced || pen == m_titlePen){ |
|
806 | 806 | q_ptr->setTitlePen(Qt::NoPen);// Noen for performance reasons |
|
807 | 807 | } |
|
808 | 808 | if (forced || m_shadesVisible) { |
|
809 | 809 | |
|
810 | 810 | if (forced || brush == m_shadesBrush){ |
|
811 | 811 | q_ptr->setShadesBrush(theme->backgroundShadesBrush()); |
|
812 | 812 | } |
|
813 | 813 | if (forced || pen == m_shadesPen){ |
|
814 | 814 | q_ptr->setShadesPen(theme->backgroundShadesPen()); |
|
815 | 815 | } |
|
816 | 816 | if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth |
|
817 | 817 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX) |
|
818 | 818 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) { |
|
819 | 819 | q_ptr->setShadesVisible(true); |
|
820 | 820 | } |
|
821 | 821 | } |
|
822 | 822 | |
|
823 | 823 | if (forced || pen == m_axisPen) { |
|
824 | 824 | q_ptr->setLinePen(theme->axisLinePen()); |
|
825 | 825 | } |
|
826 | 826 | |
|
827 | 827 | if (forced || pen == m_gridLinePen) { |
|
828 | 828 | q_ptr->setGridLinePen(theme->girdLinePen()); |
|
829 | 829 | } |
|
830 | 830 | |
|
831 | 831 | if (forced || font == m_labelsFont){ |
|
832 | 832 | q_ptr->setLabelsFont(theme->labelFont()); |
|
833 | 833 | } |
|
834 | 834 | //TODO: discuss with Tero |
|
835 | 835 | if (forced || font == m_titleFont){ |
|
836 | 836 | QFont font(m_labelsFont); |
|
837 | 837 | font.setBold(true); |
|
838 | 838 | q_ptr->setTitleFont(font); |
|
839 | 839 | } |
|
840 | 840 | } |
|
841 | 841 | } |
|
842 | 842 | |
|
843 | 843 | void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max) |
|
844 | 844 | { |
|
845 | 845 | setRange(min,max); |
|
846 | 846 | } |
|
847 | 847 | |
|
848 | 848 | void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
849 | 849 | { |
|
850 | 850 | Q_UNUSED(parent); |
|
851 | 851 | } |
|
852 | 852 | |
|
853 | 853 | void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
854 | 854 | { |
|
855 | 855 | ChartAxis* axis = m_item.data(); |
|
856 | 856 | Q_ASSERT(axis); |
|
857 | 857 | if(options.testFlag(QChart::GridAxisAnimations)) { |
|
858 | 858 | axis->setAnimation(new AxisAnimation(axis)); |
|
859 | 859 | }else{ |
|
860 | 860 | axis->setAnimation(0); |
|
861 | 861 | } |
|
862 | 862 | } |
|
863 | 863 | |
|
864 | 864 | |
|
865 | ||
|
865 | 866 | #include "moc_qabstractaxis.cpp" |
|
866 | 867 | #include "moc_qabstractaxis_p.cpp" |
|
867 | 868 | |
|
868 | 869 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,196 +1,197 | |||
|
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 QABSTRACTAXIS_H |
|
22 | 22 | #define QABSTRACTAXIS_H |
|
23 | 23 | |
|
24 | 24 | #include <qchartglobal.h> |
|
25 | 25 | #include <QPen> |
|
26 | 26 | #include <QFont> |
|
27 | 27 | #include <QVariant> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class QAbstractAxisPrivate; |
|
32 | 32 | |
|
33 | 33 | class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject |
|
34 | 34 | { |
|
35 | 35 | Q_OBJECT |
|
36 | 36 | //visibility |
|
37 | 37 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) |
|
38 | 38 | //arrow |
|
39 | 39 | Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged) |
|
40 | 40 | Q_PROPERTY(QPen linePen READ linePen WRITE setLinePen NOTIFY linePenChanged) |
|
41 | 41 | //TODO: make wrapping of color for qml |
|
42 | 42 | Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged) |
|
43 | 43 | //labels |
|
44 | 44 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
45 | 45 | Q_PROPERTY(QPen lablesPen READ labelsPen WRITE setLabelsPen NOTIFY labelsPenChanged) |
|
46 | 46 | Q_PROPERTY(QBrush lablesBrush READ labelsBrush WRITE setLabelsBrush NOTIFY labelsBrushChanged) |
|
47 | 47 | //TODO: fix labels angles to work with layout |
|
48 | 48 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle NOTIFY labelsAngleChanged) |
|
49 | 49 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont NOTIFY labelsFontChanged) |
|
50 | 50 | //TODO: make wrapping of color for qml |
|
51 | 51 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) |
|
52 | 52 | //grid |
|
53 | 53 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) |
|
54 | 54 | Q_PROPERTY(QPen girdLinePen READ gridLinePen WRITE setGridLinePen NOTIFY gridLinePenChanged) |
|
55 | 55 | //shades |
|
56 | 56 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) |
|
57 | 57 | //TODO: make wrapping of color for qml |
|
58 | 58 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) |
|
59 | 59 | //TODO: make wrapping of border for qml |
|
60 | 60 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) |
|
61 | 61 | Q_PROPERTY(QPen shadesPen READ shadesPen WRITE setShadesPen NOTIFY shadesPenChanged) |
|
62 | 62 | Q_PROPERTY(QBrush shadesBrush READ shadesBrush WRITE setShadesBrush NOTIFY shadesBrushChanged) |
|
63 | 63 | //title |
|
64 | 64 | Q_PROPERTY(QString titleText READ titleText WRITE setTitleText NOTIFY titleTextChanged) |
|
65 | 65 | Q_PROPERTY(QPen titlePen READ titlePen WRITE setTitlePen NOTIFY titlePenChanged) |
|
66 | 66 | Q_PROPERTY(QBrush titleBrush READ titleBrush WRITE setTitleBrush NOTIFY titleBrushChanged) |
|
67 | 67 | Q_PROPERTY(bool titleVisible READ titleVisible WRITE setTitleVisible) |
|
68 | 68 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) |
|
69 | 69 | //orientation |
|
70 | 70 | Q_PROPERTY(Qt::Orientation orinetation READ orientation) |
|
71 | 71 | //aligment |
|
72 | 72 | Q_PROPERTY(Qt::Alignment alignment READ alignment) |
|
73 | 73 | |
|
74 | 74 | public: |
|
75 | 75 | |
|
76 | 76 | enum AxisType { |
|
77 | 77 | AxisTypeNoAxis = 0x0, |
|
78 | 78 | AxisTypeValue = 0x1, |
|
79 | 79 | AxisTypeBarCategory = 0x2, |
|
80 | 80 | AxisTypeCategory = 0x3, |
|
81 | 81 | AxisTypeDateTime = 0x4, |
|
82 | 82 | AxisTypeLogValue = 0x5 |
|
83 | 83 | }; |
|
84 | 84 | |
|
85 | 85 | Q_DECLARE_FLAGS(AxisTypes, AxisType) |
|
86 | 86 | |
|
87 | 87 | protected: |
|
88 | 88 | explicit QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent = 0); |
|
89 | 89 | |
|
90 | 90 | public: |
|
91 | 91 | ~QAbstractAxis(); |
|
92 | 92 | |
|
93 | 93 | virtual AxisType type() const = 0; |
|
94 | 94 | |
|
95 | 95 | //visibility handling |
|
96 | 96 | bool isVisible() const; |
|
97 | 97 | void setVisible(bool visible = true); |
|
98 | 98 | void show(); |
|
99 | 99 | void hide(); |
|
100 | 100 | |
|
101 | 101 | //arrow handling |
|
102 | 102 | bool isLineVisible() const; |
|
103 | 103 | void setLineVisible(bool visible = true); |
|
104 | 104 | void setLinePen(const QPen &pen); |
|
105 | 105 | QPen linePen() const; |
|
106 | 106 | void setLinePenColor(QColor color); |
|
107 | 107 | QColor linePenColor() const; |
|
108 | 108 | |
|
109 | 109 | //grid handling |
|
110 | 110 | bool isGridLineVisible() const; |
|
111 | 111 | void setGridLineVisible(bool visible = true); |
|
112 | 112 | void setGridLinePen(const QPen &pen); |
|
113 | 113 | QPen gridLinePen() const; |
|
114 | 114 | |
|
115 | 115 | //labels handling |
|
116 | 116 | bool labelsVisible() const; |
|
117 | 117 | void setLabelsVisible(bool visible = true); |
|
118 | 118 | void setLabelsPen(const QPen &pen); |
|
119 | 119 | QPen labelsPen() const; |
|
120 | 120 | void setLabelsBrush(const QBrush &brush); |
|
121 | 121 | QBrush labelsBrush() const; |
|
122 | 122 | void setLabelsFont(const QFont &font); |
|
123 | 123 | QFont labelsFont() const; |
|
124 | 124 | void setLabelsAngle(int angle); |
|
125 | 125 | int labelsAngle() const; |
|
126 | 126 | void setLabelsColor(QColor color); |
|
127 | 127 | QColor labelsColor() const; |
|
128 | 128 | |
|
129 | 129 | //title handling |
|
130 | 130 | bool titleVisible() const; |
|
131 | 131 | void setTitleVisible(bool visible = true); |
|
132 | 132 | void setTitlePen(const QPen &pen); |
|
133 | 133 | QPen titlePen() const; |
|
134 | 134 | void setTitleBrush(const QBrush &brush); |
|
135 | 135 | QBrush titleBrush() const; |
|
136 | 136 | void setTitleFont(const QFont &font); |
|
137 | 137 | QFont titleFont() const; |
|
138 | 138 | void setTitleText(const QString &title); |
|
139 | 139 | QString titleText() const; |
|
140 | 140 | |
|
141 | 141 | //shades handling |
|
142 | 142 | bool shadesVisible() const; |
|
143 | 143 | void setShadesVisible(bool visible = true); |
|
144 | 144 | void setShadesPen(const QPen &pen); |
|
145 | 145 | QPen shadesPen() const; |
|
146 | 146 | void setShadesBrush(const QBrush &brush); |
|
147 | 147 | QBrush shadesBrush() const; |
|
148 | 148 | void setShadesColor(QColor color); |
|
149 | 149 | QColor shadesColor() const; |
|
150 | 150 | void setShadesBorderColor(QColor color); |
|
151 | 151 | QColor shadesBorderColor() const; |
|
152 | 152 | |
|
153 | 153 | Qt::Orientation orientation(); //TODO: missing const <- BC |
|
154 | 154 | Qt::Alignment alignment() const; |
|
155 | 155 | |
|
156 | 156 | //range handling |
|
157 | 157 | void setMin(const QVariant &min); |
|
158 | 158 | void setMax(const QVariant &max); |
|
159 | 159 | void setRange(const QVariant &min, const QVariant &max); |
|
160 | 160 | |
|
161 | 161 | Q_SIGNALS: |
|
162 | 162 | void visibleChanged(bool visible); |
|
163 | 163 | void linePenChanged(const QPen& pen); |
|
164 | 164 | void lineVisibleChanged(bool visible); |
|
165 | 165 | void labelsVisibleChanged(bool visible); |
|
166 | 166 | void labelsPenChanged(const QPen& pen); |
|
167 | 167 | void labelsBrushChanged(const QBrush& brush); |
|
168 | 168 | void labelsFontChanged(const QFont& pen); |
|
169 | 169 | void labelsAngleChanged(int angle); |
|
170 | 170 | void gridLinePenChanged(const QPen& pen); |
|
171 | 171 | void gridVisibleChanged(bool visible); |
|
172 | 172 | void colorChanged(QColor color); |
|
173 | 173 | void labelsColorChanged(QColor color); |
|
174 | 174 | void titleTextChanged(const QString& title); |
|
175 | 175 | void titlePenChanged(const QPen& pen); |
|
176 | 176 | void titleBrushChanged(const QBrush brush); |
|
177 | 177 | void titleVisibleChanged(bool visible); |
|
178 | 178 | void titleFontChanged(const QFont& font); |
|
179 | 179 | void shadesVisibleChanged(bool visible); |
|
180 | 180 | void shadesColorChanged(QColor color); |
|
181 | 181 | void shadesBorderColorChanged(QColor color); |
|
182 | 182 | void shadesPenChanged(const QPen& pen); |
|
183 | 183 | void shadesBrushChanged(const QBrush brush); |
|
184 | 184 | |
|
185 | 185 | protected: |
|
186 | 186 | QScopedPointer<QAbstractAxisPrivate> d_ptr; |
|
187 | 187 | Q_DISABLE_COPY(QAbstractAxis) |
|
188 | 188 | friend class ChartDataSet; |
|
189 | 189 | friend class ChartAxis; |
|
190 | 190 | friend class ChartPresenter; |
|
191 | 191 | friend class ChartThemeManager; |
|
192 | friend class AbstractDomain; | |
|
192 | 193 | }; |
|
193 | 194 | |
|
194 | 195 | QTCOMMERCIALCHART_END_NAMESPACE |
|
195 | 196 | |
|
196 | 197 | #endif // QABSTRACTAXIS_H |
@@ -1,410 +1,471 | |||
|
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 "chartdataset_p.h" |
|
22 | 22 | #include "chartpresenter_p.h" |
|
23 | 23 | #include "qchart.h" |
|
24 | 24 | #include "qchart_p.h" |
|
25 | 25 | #include "qvalueaxis.h" |
|
26 | 26 | #include "qbarcategoryaxis.h" |
|
27 | 27 | #include "qvalueaxis_p.h" |
|
28 | 28 | #include "qcategoryaxis.h" |
|
29 | 29 | #include "qabstractseries_p.h" |
|
30 | 30 | #include "qabstractbarseries.h" |
|
31 | 31 | #include "qstackedbarseries.h" |
|
32 | 32 | #include "qpercentbarseries.h" |
|
33 | 33 | #include "qpieseries.h" |
|
34 | 34 | #include "chartitem_p.h" |
|
35 | 35 | #include "xydomain_p.h" |
|
36 | 36 | #include "xlogydomain_p.h" |
|
37 | 37 | #include "logxydomain_p.h" |
|
38 | 38 | #include "logxlogydomain_p.h" |
|
39 | 39 | |
|
40 | 40 | #ifndef QT_ON_ARM |
|
41 | 41 | #include "qdatetimeaxis.h" |
|
42 | 42 | #endif |
|
43 | 43 | |
|
44 | 44 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
45 | 45 | |
|
46 | 46 | ChartDataSet::ChartDataSet(QChart *chart) |
|
47 | 47 | : QObject(chart), |
|
48 | 48 | m_chart(chart) |
|
49 | 49 | { |
|
50 | 50 | |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | ChartDataSet::~ChartDataSet() |
|
54 | 54 | { |
|
55 |
|
|
|
56 |
|
|
|
55 | deleteAllSeries(); | |
|
56 | deleteAllAxes(); | |
|
57 | 57 | } |
|
58 | 58 | |
|
59 | 59 | /* |
|
60 | 60 | * This method adds series to chartdataset, series ownership is taken from caller. |
|
61 | 61 | */ |
|
62 | 62 | void ChartDataSet::addSeries(QAbstractSeries *series) |
|
63 | 63 | { |
|
64 | 64 | if (m_seriesList.contains(series)) { |
|
65 | 65 | qWarning() << QObject::tr("Can not add series. Series already on the chart."); |
|
66 | 66 | return; |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | 69 | series->d_ptr->initializeDomain(); |
|
70 | 70 | m_seriesList.append(series); |
|
71 | 71 | |
|
72 | 72 | series->setParent(this); // take ownership |
|
73 | 73 | series->d_ptr->m_chart = m_chart; |
|
74 | 74 | |
|
75 | 75 | emit seriesAdded(series); |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | /* |
|
79 | 79 | * This method adds axis to chartdataset, axis ownership is taken from caller. |
|
80 | 80 | */ |
|
81 | 81 | void ChartDataSet::addAxis(QAbstractAxis *axis,Qt::Alignment aligment) |
|
82 | 82 | { |
|
83 | 83 | if (m_axisList.contains(axis)) { |
|
84 | 84 | qWarning() << QObject::tr("Can not add axis. Axis already on the chart."); |
|
85 | 85 | return; |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | axis->d_ptr->setAlignment(aligment); |
|
89 | 89 | |
|
90 | 90 | if(!axis->alignment()) { |
|
91 | 91 | qWarning()<< QObject::tr("No alignment specified !"); |
|
92 | 92 | return; |
|
93 | 93 | }; |
|
94 | 94 | |
|
95 | 95 | QSharedPointer<AbstractDomain> domain(new XYDomain()); |
|
96 | 96 | axis->d_ptr->initializeDomain(domain.data()); |
|
97 | 97 | |
|
98 | 98 | axis->setParent(this); |
|
99 | 99 | axis->d_ptr->m_chart = m_chart; |
|
100 | 100 | m_axisList.append(axis); |
|
101 | 101 | |
|
102 | 102 | emit axisAdded(axis); |
|
103 | 103 | } |
|
104 | 104 | |
|
105 | 105 | /* |
|
106 | 106 | * This method removes series form chartdataset, series ownership is passed back to caller. |
|
107 | 107 | */ |
|
108 | 108 | void ChartDataSet::removeSeries(QAbstractSeries *series) |
|
109 | 109 | { |
|
110 | 110 | |
|
111 | 111 | if (! m_seriesList.contains(series)) { |
|
112 | 112 | qWarning() << QObject::tr("Can not remove series. Series not found on the chart."); |
|
113 | 113 | return; |
|
114 | 114 | } |
|
115 | 115 | |
|
116 | 116 | emit seriesRemoved(series); |
|
117 | 117 | m_seriesList.removeAll(series); |
|
118 | 118 | |
|
119 | 119 | series->setParent(0); |
|
120 | 120 | series->d_ptr->m_chart = 0; |
|
121 | 121 | series->d_ptr->m_domain.clear(); |
|
122 | 122 | |
|
123 | 123 | QList<QAbstractAxis*> axes = series->d_ptr->m_axes; |
|
124 | 124 | |
|
125 | 125 | foreach(QAbstractAxis* axis, axes) { |
|
126 | 126 | axis->d_ptr->m_series.removeAll(series); |
|
127 | 127 | series->d_ptr->m_axes.removeAll(axis); |
|
128 | 128 | } |
|
129 | ||
|
129 | 130 | } |
|
130 | 131 | |
|
131 | 132 | /* |
|
132 | 133 | * This method removes axis form chartdataset, series ownership is passed back to caller. |
|
133 | 134 | */ |
|
134 | 135 | void ChartDataSet::removeAxis(QAbstractAxis *axis) |
|
135 | 136 | { |
|
136 | 137 | if (! m_axisList.contains(axis)) { |
|
137 | 138 | qWarning() << QObject::tr("Can not remove axis. Axis not found on the chart."); |
|
138 | 139 | return; |
|
139 | 140 | } |
|
140 | 141 | |
|
141 | 142 | emit axisRemoved(axis); |
|
142 | 143 | m_axisList.removeAll(axis); |
|
143 | 144 | |
|
144 | 145 | axis->setParent(0); |
|
145 | 146 | axis->d_ptr->m_chart = 0; |
|
146 | 147 | |
|
147 | 148 | QList<QAbstractSeries*> series = axis->d_ptr->m_series; |
|
148 | 149 | |
|
149 | 150 | foreach(QAbstractSeries* s, series) { |
|
150 | 151 | s->d_ptr->m_axes.removeAll(axis); |
|
151 | 152 | axis->d_ptr->m_series.removeAll(s); |
|
152 | 153 | } |
|
153 | 154 | } |
|
154 | 155 | |
|
155 | 156 | /* |
|
156 | * This method attach axis to series, return true if success. | |
|
157 | * This method attaches axis to series, return true if success. | |
|
157 | 158 | */ |
|
158 | 159 | bool ChartDataSet::attachAxis(QAbstractSeries* series,QAbstractAxis *axis) |
|
159 | 160 | { |
|
160 | 161 | Q_ASSERT(series); |
|
161 | 162 | Q_ASSERT(axis); |
|
162 | 163 | |
|
163 | 164 | QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series; |
|
164 | 165 | QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes; |
|
165 | QSharedPointer<AbstractDomain> domain = series->d_ptr->m_domain; | |
|
166 | 166 | |
|
167 | 167 | if (!m_seriesList.contains(series)) { |
|
168 | 168 | qWarning() << QObject::tr("Can not find series on the chart."); |
|
169 | 169 | return false; |
|
170 | 170 | } |
|
171 | 171 | |
|
172 | 172 | if (axis && !m_axisList.contains(axis)) { |
|
173 | 173 | qWarning() << QObject::tr("Can not find axis on the chart."); |
|
174 | 174 | return false; |
|
175 | 175 | } |
|
176 | 176 | |
|
177 | 177 | if (attachedAxisList.contains(axis)) { |
|
178 | 178 | qWarning() << QObject::tr("Axis already attached to series."); |
|
179 | 179 | return false; |
|
180 | 180 | } |
|
181 | 181 | |
|
182 |
|
|
|
183 | Q_ASSERT(!domain.isNull()); | |
|
182 | if (attachedSeriesList.contains(series)) { | |
|
183 | qWarning() << QObject::tr("Axis already attached to series."); | |
|
184 | return false; | |
|
185 | } | |
|
186 | ||
|
187 | QSharedPointer<AbstractDomain> domain = series->d_ptr->domain(); | |
|
188 | AbstractDomain::DomainType type = selectDomain(attachedAxisList<<axis); | |
|
189 | ||
|
190 | if(type == AbstractDomain::UndefinedDomain) return false; | |
|
184 | 191 | |
|
185 | if(attachedSeriesList.isEmpty()){ | |
|
186 | 192 | |
|
187 | }else{ | |
|
188 | domain = attachedSeriesList.first()->d_ptr->domain(); | |
|
189 | Q_ASSERT(!domain.isNull()); | |
|
190 | series->d_ptr->setDomain(domain); | |
|
193 | if(domain->type()!=type){ | |
|
194 | domain = QSharedPointer<AbstractDomain>(createDomain(type)); | |
|
191 | 195 | } |
|
192 | 196 | |
|
197 | if(domain.isNull()) return false; | |
|
198 | ||
|
199 | if(!domain->attachAxis(axis)) return false; | |
|
200 | ||
|
193 | 201 | series->d_ptr->m_axes<<axis; |
|
194 | 202 | axis->d_ptr->m_series<<series; |
|
195 | 203 | |
|
204 | series->d_ptr->setDomain(domain); | |
|
205 | series->d_ptr->initializeDomain(); | |
|
196 | 206 | series->d_ptr->initializeAxes(); |
|
197 | 207 | axis->d_ptr->initializeDomain(domain.data()); |
|
198 | 208 | |
|
199 | if(axis->orientation()==Qt::Vertical){ | |
|
200 | QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), domain.data(), SLOT(handleVerticalAxisRangeChanged(qreal,qreal))); | |
|
201 | QObject::connect(domain.data(), SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); | |
|
202 | } | |
|
203 | ||
|
204 | if(axis->orientation()==Qt::Horizontal){ | |
|
205 | QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), domain.data(), SLOT(handleHorizontalAxisRangeChanged(qreal,qreal))); | |
|
206 | QObject::connect(domain.data(), SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); | |
|
209 | if(attachedSeriesList.count()>0 && attachedAxisList.count()>0){ | |
|
210 | //TODO optimatization: joinDomain(attachedAxisList, attachedSeriesList); | |
|
207 | 211 | } |
|
208 | 212 | |
|
209 | 213 | return true; |
|
210 | 214 | } |
|
211 | 215 | |
|
212 | 216 | /* |
|
213 | * This method detach axis to series, return true if success. | |
|
217 | * This method detaches axis to series, return true if success. | |
|
214 | 218 | */ |
|
215 | 219 | bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis) |
|
216 | 220 | { |
|
217 | 221 | Q_ASSERT(series); |
|
218 | 222 | Q_ASSERT(axis); |
|
219 | 223 | |
|
220 | 224 | QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series; |
|
221 | 225 | QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes; |
|
222 | 226 | QSharedPointer<AbstractDomain> domain = series->d_ptr->m_domain; |
|
223 | 227 | |
|
224 | 228 | if (!m_seriesList.contains(series)) { |
|
225 | 229 | qWarning() << QObject::tr("Can not find series on the chart."); |
|
226 | 230 | return false; |
|
227 | 231 | } |
|
228 | 232 | |
|
229 | 233 | if (axis && !m_axisList.contains(axis)) { |
|
230 | 234 | qWarning() << QObject::tr("Can not find axis on the chart."); |
|
231 | 235 | return false; |
|
232 | 236 | } |
|
233 | 237 | |
|
234 | 238 | if (!attachedAxisList.contains(axis)) { |
|
235 | 239 | qWarning() << QObject::tr("Axis not attached to series."); |
|
236 | 240 | return false; |
|
237 | 241 | } |
|
238 | 242 | |
|
239 | 243 | Q_ASSERT(axis->d_ptr->m_series.contains(series)); |
|
240 | 244 | |
|
245 | domain->detachAxis(axis); | |
|
241 | 246 | series->d_ptr->m_axes.removeAll(axis); |
|
242 | 247 | axis->d_ptr->m_series.removeAll(series); |
|
243 | 248 | |
|
244 | if(axis->orientation()==Qt::Vertical){ | |
|
245 | QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), domain.data(), SLOT(handleVerticalAxisRangeChanged(qreal,qreal))); | |
|
246 | QObject::disconnect(domain.data(), SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); | |
|
247 | } | |
|
248 | ||
|
249 | if(axis->orientation()==Qt::Horizontal){ | |
|
250 | QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), domain.data(), SLOT(handleHorizontalAxisRangeChanged(qreal,qreal))); | |
|
251 | QObject::disconnect(domain.data(), SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); | |
|
252 | } | |
|
253 | ||
|
254 | 249 | return true; |
|
255 | 250 | } |
|
256 | 251 | |
|
257 | 252 | void ChartDataSet::createDefaultAxes() |
|
258 | 253 | { |
|
259 | 254 | if (m_seriesList.isEmpty()) |
|
260 | 255 | return; |
|
261 | 256 | |
|
262 | 257 | QAbstractAxis::AxisTypes typeX(0); |
|
263 | 258 | QAbstractAxis::AxisTypes typeY(0); |
|
264 | 259 | |
|
265 | 260 | // Remove possibly existing axes |
|
266 |
|
|
|
261 | deleteAllAxes(); | |
|
267 | 262 | |
|
268 | 263 | Q_ASSERT(m_axisList.isEmpty()); |
|
269 | 264 | |
|
270 | 265 | // Select the required axis x and axis y types based on the types of the current series |
|
271 | 266 | foreach(QAbstractSeries* s, m_seriesList) { |
|
272 | 267 | typeX |= s->d_ptr->defaultAxisType(Qt::Horizontal); |
|
273 | 268 | typeY |= s->d_ptr->defaultAxisType(Qt::Vertical); |
|
274 | 269 | } |
|
275 | 270 | |
|
276 | 271 | // Create the axes of the types selected |
|
277 | 272 | createAxes(typeX, Qt::Horizontal); |
|
278 | 273 | createAxes(typeY, Qt::Vertical); |
|
279 | 274 | |
|
280 | 275 | } |
|
281 | 276 | |
|
282 | 277 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation) |
|
283 | 278 | { |
|
284 | 279 | QAbstractAxis *axis = 0; |
|
285 | 280 | //decide what axis should be created |
|
286 | 281 | |
|
287 | 282 | switch (type) { |
|
288 | 283 | case QAbstractAxis::AxisTypeValue: |
|
289 | 284 | axis = new QValueAxis(this); |
|
290 | 285 | break; |
|
291 | 286 | case QAbstractAxis::AxisTypeBarCategory: |
|
292 | 287 | axis = new QBarCategoryAxis(this); |
|
293 | 288 | break; |
|
294 | 289 | case QAbstractAxis::AxisTypeCategory: |
|
295 | 290 | axis = new QCategoryAxis(this); |
|
296 | 291 | break; |
|
297 | 292 | #ifndef Q_WS_QWS |
|
298 | 293 | case QAbstractAxis::AxisTypeDateTime: |
|
299 | 294 | axis = new QDateTimeAxis(this); |
|
300 | 295 | break; |
|
301 | 296 | #endif |
|
302 | 297 | default: |
|
303 | 298 | axis = 0; |
|
304 | 299 | break; |
|
305 | 300 | } |
|
306 | 301 | |
|
307 | 302 | if (axis) { |
|
308 | 303 | //create one axis for all |
|
309 | 304 | |
|
310 | 305 | addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft); |
|
311 | 306 | |
|
312 | 307 | foreach(QAbstractSeries *s, m_seriesList) { |
|
313 | 308 | attachAxis(s,axis); |
|
314 | 309 | } |
|
315 | 310 | |
|
316 | 311 | } |
|
317 | 312 | else if (!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { |
|
318 | 313 | //create separate axis |
|
319 | 314 | foreach(QAbstractSeries *s, m_seriesList) { |
|
320 | 315 | QAbstractAxis *axis = s->d_ptr->createDefaultAxis(orientation); |
|
321 | 316 | if(axis) { |
|
322 | 317 | addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft); |
|
323 | 318 | attachAxis(s,axis); |
|
324 | 319 | } |
|
325 | 320 | } |
|
326 | 321 | } |
|
327 | 322 | } |
|
328 | 323 | |
|
329 |
void ChartDataSet:: |
|
|
324 | void ChartDataSet::deleteAllSeries() | |
|
330 | 325 | { |
|
331 | foreach (QAbstractSeries *s , m_seriesList) | |
|
326 | foreach (QAbstractSeries *s , m_seriesList){ | |
|
332 | 327 | removeSeries(s); |
|
333 | ||
|
328 | delete s; | |
|
329 | } | |
|
334 | 330 | Q_ASSERT(m_seriesList.count() == 0); |
|
335 | qDeleteAll(m_seriesList); | |
|
336 | 331 | } |
|
337 | 332 | |
|
338 |
void ChartDataSet:: |
|
|
333 | void ChartDataSet::deleteAllAxes() | |
|
339 | 334 | { |
|
340 | foreach (QAbstractAxis *a , m_axisList) | |
|
335 | foreach (QAbstractAxis *a , m_axisList){ | |
|
341 | 336 | removeAxis(a); |
|
342 | ||
|
337 | delete a; | |
|
338 | } | |
|
343 | 339 | Q_ASSERT(m_axisList.count() == 0); |
|
344 | qDeleteAll(m_axisList); | |
|
345 | 340 | } |
|
346 | 341 | |
|
347 | 342 | void ChartDataSet::zoomInDomain(const QRectF &rect) |
|
348 | 343 | { |
|
349 | 344 | QList<AbstractDomain*> domains; |
|
350 | 345 | foreach(QAbstractSeries *s, m_seriesList) { |
|
351 | 346 | AbstractDomain* domain = s->d_ptr->m_domain.data(); |
|
352 | 347 | if(domains.contains(domain)) continue; |
|
353 | 348 | s->d_ptr->m_domain->blockAxisSignals(true); |
|
354 | 349 | domains<<domain; |
|
355 | 350 | } |
|
356 | 351 | |
|
357 | 352 | foreach(AbstractDomain *domain, domains) |
|
358 | 353 | domain->zoomIn(rect); |
|
359 | 354 | |
|
360 | 355 | foreach(AbstractDomain *domain, domains) |
|
361 | 356 | domain->blockAxisSignals(false); |
|
362 | 357 | } |
|
363 | 358 | |
|
364 | 359 | void ChartDataSet::zoomOutDomain(const QRectF &rect) |
|
365 | 360 | { |
|
366 | 361 | QList<AbstractDomain*> domains; |
|
367 | 362 | foreach(QAbstractSeries *s, m_seriesList) { |
|
368 | 363 | AbstractDomain* domain = s->d_ptr->m_domain.data(); |
|
369 | 364 | if(domains.contains(domain)) continue; |
|
370 | 365 | s->d_ptr->m_domain->blockAxisSignals(true); |
|
371 | 366 | domains<<domain; |
|
372 | 367 | } |
|
373 | 368 | |
|
374 | 369 | foreach(AbstractDomain *domain, domains) |
|
375 | 370 | domain->zoomOut(rect); |
|
376 | 371 | |
|
377 | 372 | foreach(AbstractDomain *domain, domains) |
|
378 | 373 | domain->blockAxisSignals(false); |
|
379 | 374 | } |
|
380 | 375 | |
|
381 | 376 | void ChartDataSet::scrollDomain(qreal dx, qreal dy) |
|
382 | 377 | { |
|
383 | 378 | QList<AbstractDomain*> domains; |
|
384 | 379 | foreach(QAbstractSeries *s, m_seriesList) { |
|
385 | 380 | AbstractDomain* domain = s->d_ptr->m_domain.data(); |
|
386 | 381 | if(domains.contains(domain)) continue; |
|
387 | 382 | s->d_ptr->m_domain->blockAxisSignals(true); |
|
388 | 383 | domains<<domain; |
|
389 | 384 | } |
|
390 | 385 | |
|
391 | 386 | foreach(AbstractDomain *domain, domains) |
|
392 | 387 | domain->move(dx, dy); |
|
393 | 388 | |
|
394 | 389 | foreach(AbstractDomain *domain, domains) |
|
395 | 390 | domain->blockAxisSignals(false); |
|
396 | 391 | } |
|
397 | 392 | |
|
398 | 393 | QList<QAbstractAxis*> ChartDataSet::axes() const |
|
399 | 394 | { |
|
400 | 395 | return m_axisList; |
|
401 | 396 | } |
|
402 | 397 | |
|
403 | 398 | QList<QAbstractSeries *> ChartDataSet::series() const |
|
404 | 399 | { |
|
405 | 400 | return m_seriesList; |
|
406 | 401 | } |
|
407 | 402 | |
|
403 | AbstractDomain::DomainType ChartDataSet::selectDomain(QList<QAbstractAxis*> axes) | |
|
404 | { | |
|
405 | enum Type { | |
|
406 | LogType = 0x1, | |
|
407 | ValueType = 0x2 | |
|
408 | }; | |
|
409 | ||
|
410 | int horizontal(ValueType); | |
|
411 | int vertical(ValueType); | |
|
412 | ||
|
413 | foreach(QAbstractAxis* axis, axes) | |
|
414 | { | |
|
415 | switch(axis->type()) { | |
|
416 | case QAbstractAxis::AxisTypeLogValue: | |
|
417 | axis->orientation()==Qt::Horizontal?horizontal:vertical|=LogType; | |
|
418 | break; | |
|
419 | case QAbstractAxis::AxisTypeValue: | |
|
420 | case QAbstractAxis::AxisTypeBarCategory: | |
|
421 | case QAbstractAxis::AxisTypeCategory: | |
|
422 | case QAbstractAxis::AxisTypeDateTime: | |
|
423 | axis->orientation()==Qt::Horizontal?horizontal:vertical|=ValueType; | |
|
424 | break; | |
|
425 | default: | |
|
426 | qWarning()<<"Undefined type"; | |
|
427 | break; | |
|
428 | } | |
|
429 | } | |
|
430 | ||
|
431 | if(vertical==ValueType && horizontal== ValueType) { | |
|
432 | return AbstractDomain::XYDomain; | |
|
433 | } | |
|
434 | ||
|
435 | if(vertical==LogType && horizontal== ValueType) { | |
|
436 | return AbstractDomain::XLogYDomain; | |
|
437 | } | |
|
438 | ||
|
439 | if(vertical==ValueType && horizontal== LogType) { | |
|
440 | return AbstractDomain::LogXYDomain; | |
|
441 | } | |
|
442 | ||
|
443 | if(vertical==LogType && horizontal== LogType) { | |
|
444 | return AbstractDomain::XLogYLogDomain; | |
|
445 | } | |
|
446 | ||
|
447 | return AbstractDomain::UndefinedDomain; | |
|
448 | } | |
|
449 | ||
|
450 | ||
|
451 | //refactor create factory | |
|
452 | AbstractDomain* ChartDataSet::createDomain(AbstractDomain::DomainType type) | |
|
453 | { | |
|
454 | switch(type) | |
|
455 | { | |
|
456 | case AbstractDomain::XLogYLogDomain: | |
|
457 | return 0; | |
|
458 | case AbstractDomain::XYDomain: | |
|
459 | return new XYDomain(); | |
|
460 | case AbstractDomain::XLogYDomain: | |
|
461 | return 0; | |
|
462 | case AbstractDomain::LogXYDomain: | |
|
463 | return 0; | |
|
464 | default: | |
|
465 | return 0; | |
|
466 | } | |
|
467 | } | |
|
468 | ||
|
408 | 469 | #include "moc_chartdataset_p.cpp" |
|
409 | 470 | |
|
410 | 471 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,87 +1,88 | |||
|
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 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef CHARTDATASET_P_H |
|
31 | 31 | #define CHARTDATASET_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qabstractseries.h" |
|
34 | 34 | #include "abstractdomain_p.h" |
|
35 | 35 | #include "qabstractaxis_p.h" |
|
36 | 36 | #include <QVector> |
|
37 | 37 | |
|
38 | 38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | 39 | |
|
40 | 40 | class QAbstractAxis; |
|
41 | 41 | class ChartPresenter; |
|
42 | 42 | |
|
43 | 43 | class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject |
|
44 | 44 | { |
|
45 | 45 | Q_OBJECT |
|
46 | 46 | public: |
|
47 | 47 | ChartDataSet(QChart *chart); |
|
48 | 48 | virtual ~ChartDataSet(); |
|
49 | 49 | |
|
50 | 50 | void addSeries(QAbstractSeries *series); |
|
51 | 51 | void removeSeries(QAbstractSeries *series); |
|
52 | 52 | QList<QAbstractSeries *> series() const; |
|
53 | void removeAllSeries(); | |
|
54 | 53 | |
|
55 | 54 | void addAxis(QAbstractAxis *axis,Qt::Alignment aligment); |
|
56 | 55 | void removeAxis(QAbstractAxis *axis); |
|
57 | 56 | QList<QAbstractAxis*> axes() const; |
|
58 | void removeAllAxes(); | |
|
59 | 57 | |
|
60 | 58 | bool attachAxis(QAbstractSeries* series,QAbstractAxis *axis); |
|
61 | 59 | bool detachAxis(QAbstractSeries* series,QAbstractAxis *axis); |
|
62 | 60 | |
|
63 | 61 | void createDefaultAxes(); |
|
64 | 62 | |
|
65 | 63 | void zoomInDomain(const QRectF &rect); |
|
66 | 64 | void zoomOutDomain(const QRectF &rect); |
|
67 | 65 | void scrollDomain(qreal dx, qreal dy); |
|
68 | 66 | |
|
69 | 67 | Q_SIGNALS: |
|
70 | 68 | void axisAdded(QAbstractAxis* axis); |
|
71 | 69 | void axisRemoved(QAbstractAxis* axis); |
|
72 | 70 | void seriesAdded(QAbstractSeries* series); |
|
73 | 71 | void seriesRemoved(QAbstractSeries* series); |
|
74 | 72 | |
|
75 | 73 | private: |
|
76 | 74 | void createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation); |
|
77 | 75 | QAbstractAxis *createAxis(QAbstractAxis::AxisType type, Qt::Orientation orientation); |
|
78 | ||
|
76 | AbstractDomain::DomainType selectDomain(QList<QAbstractAxis* > axes); | |
|
77 | AbstractDomain* createDomain(AbstractDomain::DomainType type); | |
|
78 | void deleteAllAxes(); | |
|
79 | void deleteAllSeries(); | |
|
79 | 80 | private: |
|
80 | 81 | QList<QAbstractSeries *> m_seriesList; |
|
81 | 82 | QList<QAbstractAxis *> m_axisList; |
|
82 | 83 | QChart* m_chart; |
|
83 | 84 | }; |
|
84 | 85 | |
|
85 | 86 | QTCOMMERCIALCHART_END_NAMESPACE |
|
86 | 87 | |
|
87 | 88 | #endif /* CHARTENGINE_P_H */ |
@@ -1,190 +1,219 | |||
|
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 "abstractdomain_p.h" |
|
22 | 22 | #include "qabstractaxis_p.h" |
|
23 | 23 | #include <qmath.h> |
|
24 | 24 | |
|
25 | 25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | 26 | |
|
27 | 27 | AbstractDomain::AbstractDomain(QObject *parent) |
|
28 | 28 | : QObject(parent), |
|
29 | 29 | m_minX(0), |
|
30 | 30 | m_maxX(0), |
|
31 | 31 | m_minY(0), |
|
32 | 32 | m_maxY(0), |
|
33 | 33 | m_axisSignalsBlocked(false) |
|
34 | 34 | { |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | AbstractDomain::~AbstractDomain() |
|
38 | 38 | { |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | void AbstractDomain::setSize(const QSizeF& size) |
|
42 | 42 | { |
|
43 | 43 | if(m_size!=size) |
|
44 | 44 | { |
|
45 | 45 | m_size=size; |
|
46 | 46 | emit updated(); |
|
47 | 47 | } |
|
48 | 48 | } |
|
49 | 49 | |
|
50 | 50 | QSizeF AbstractDomain::size() const |
|
51 | 51 | { |
|
52 | 52 | return m_size; |
|
53 | 53 | } |
|
54 | 54 | |
|
55 | 55 | void AbstractDomain::setRangeX(qreal min, qreal max) |
|
56 | 56 | { |
|
57 | 57 | setRange(min, max, m_minY, m_maxY); |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | void AbstractDomain::setRangeY(qreal min, qreal max) |
|
61 | 61 | { |
|
62 | 62 | setRange(m_minX, m_maxX, min, max); |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | void AbstractDomain::setMinX(qreal min) |
|
66 | 66 | { |
|
67 | 67 | setRange(min, m_maxX, m_minY, m_maxY); |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | void AbstractDomain::setMaxX(qreal max) |
|
71 | 71 | { |
|
72 | 72 | setRange(m_minX, max, m_minY, m_maxY); |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | void AbstractDomain::setMinY(qreal min) |
|
76 | 76 | { |
|
77 | 77 | setRange(m_minX, m_maxX, min, m_maxY); |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | 80 | void AbstractDomain::setMaxY(qreal max) |
|
81 | 81 | { |
|
82 | 82 | setRange(m_minX, m_maxX, m_minY, max); |
|
83 | 83 | } |
|
84 | 84 | |
|
85 | 85 | qreal AbstractDomain::spanX() const |
|
86 | 86 | { |
|
87 | 87 | Q_ASSERT(m_maxX >= m_minX); |
|
88 | 88 | return m_maxX - m_minX; |
|
89 | 89 | } |
|
90 | 90 | |
|
91 | 91 | qreal AbstractDomain::spanY() const |
|
92 | 92 | { |
|
93 | 93 | Q_ASSERT(m_maxY >= m_minY); |
|
94 | 94 | return m_maxY - m_minY; |
|
95 | 95 | } |
|
96 | 96 | |
|
97 | 97 | bool AbstractDomain::isEmpty() const |
|
98 | 98 | { |
|
99 | 99 | return qFuzzyIsNull(spanX()) || qFuzzyIsNull(spanY()) || m_size.isEmpty() ; |
|
100 | 100 | } |
|
101 | 101 | |
|
102 | 102 | QPointF AbstractDomain::calculateDomainPoint(const QPointF &point) const |
|
103 | 103 | { |
|
104 | 104 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
105 | 105 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
106 | 106 | qreal x = point.x() / deltaX + m_minX; |
|
107 | 107 | qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY; |
|
108 | 108 | return QPointF(x, y); |
|
109 | 109 | } |
|
110 | 110 | |
|
111 | 111 | // handlers |
|
112 | 112 | |
|
113 | 113 | void AbstractDomain::handleVerticalAxisRangeChanged(qreal min, qreal max) |
|
114 | 114 | { |
|
115 | 115 | if(!m_axisSignalsBlocked) |
|
116 | 116 | setRangeY(min, max); |
|
117 | 117 | } |
|
118 | 118 | |
|
119 | 119 | void AbstractDomain::handleHorizontalAxisRangeChanged(qreal min, qreal max) |
|
120 | 120 | { |
|
121 | 121 | if(!m_axisSignalsBlocked) |
|
122 | 122 | setRangeX(min, max); |
|
123 | 123 | } |
|
124 | 124 | |
|
125 | 125 | void AbstractDomain::blockAxisSignals(bool block) |
|
126 | 126 | { |
|
127 | 127 | m_axisSignalsBlocked=block; |
|
128 | 128 | } |
|
129 | 129 | |
|
130 | 130 | //algorithm defined by Paul S.Heckbert GraphicalGems I |
|
131 | 131 | |
|
132 | 132 | void AbstractDomain::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) |
|
133 | 133 | { |
|
134 | 134 | qreal range = niceNumber(max - min, true); //range with ceiling |
|
135 | 135 | qreal step = niceNumber(range / (ticksCount - 1), false); |
|
136 | 136 | min = qFloor(min / step); |
|
137 | 137 | max = qCeil(max / step); |
|
138 | 138 | ticksCount = int(max - min) + 1; |
|
139 | 139 | min *= step; |
|
140 | 140 | max *= step; |
|
141 | 141 | } |
|
142 | 142 | |
|
143 | 143 | //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n |
|
144 | 144 | |
|
145 | 145 | qreal AbstractDomain::niceNumber(qreal x, bool ceiling) |
|
146 | 146 | { |
|
147 | 147 | qreal z = qPow(10, qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x |
|
148 | 148 | qreal q = x / z; //q<10 && q>=1; |
|
149 | 149 | |
|
150 | 150 | if (ceiling) { |
|
151 | 151 | if (q <= 1.0) q = 1; |
|
152 | 152 | else if (q <= 2.0) q = 2; |
|
153 | 153 | else if (q <= 5.0) q = 5; |
|
154 | 154 | else q = 10; |
|
155 | 155 | } else { |
|
156 | 156 | if (q < 1.5) q = 1; |
|
157 | 157 | else if (q < 3.0) q = 2; |
|
158 | 158 | else if (q < 7.0) q = 5; |
|
159 | 159 | else q = 10; |
|
160 | 160 | } |
|
161 | 161 | return q * z; |
|
162 | 162 | } |
|
163 | 163 | |
|
164 | bool AbstractDomain::attachAxis(QAbstractAxis* axis) | |
|
165 | { | |
|
166 | if(axis->orientation()==Qt::Vertical) { | |
|
167 | QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleVerticalAxisRangeChanged(qreal,qreal))); | |
|
168 | QObject::connect(this, SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); | |
|
169 | } | |
|
170 | ||
|
171 | if(axis->orientation()==Qt::Horizontal) { | |
|
172 | QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleHorizontalAxisRangeChanged(qreal,qreal))); | |
|
173 | QObject::connect(this, SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); | |
|
174 | } | |
|
175 | ||
|
176 | return true; | |
|
177 | } | |
|
178 | ||
|
179 | bool AbstractDomain::detachAxis(QAbstractAxis* axis) | |
|
180 | { | |
|
181 | if(axis->orientation()==Qt::Vertical) { | |
|
182 | QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleVerticalAxisRangeChanged(qreal,qreal))); | |
|
183 | QObject::disconnect(this, SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); | |
|
184 | } | |
|
185 | ||
|
186 | if(axis->orientation()==Qt::Horizontal) { | |
|
187 | QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleHorizontalAxisRangeChanged(qreal,qreal))); | |
|
188 | QObject::disconnect(this, SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal))); | |
|
189 | } | |
|
190 | ||
|
191 | return true; | |
|
192 | } | |
|
164 | 193 | |
|
165 | 194 | // operators |
|
166 | 195 | |
|
167 | 196 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const AbstractDomain &domain1, const AbstractDomain &domain2) |
|
168 | 197 | { |
|
169 | 198 | return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) && |
|
170 | 199 | qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) && |
|
171 | 200 | qFuzzyIsNull(domain1.m_minX - domain2.m_minX) && |
|
172 | 201 | qFuzzyIsNull(domain1.m_minY - domain2.m_minY)); |
|
173 | 202 | } |
|
174 | 203 | |
|
175 | 204 | |
|
176 | 205 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const AbstractDomain &domain1, const AbstractDomain &domain2) |
|
177 | 206 | { |
|
178 | 207 | return !(domain1 == domain2); |
|
179 | 208 | } |
|
180 | 209 | |
|
181 | 210 | |
|
182 | 211 | QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const AbstractDomain &domain) |
|
183 | 212 | { |
|
184 | 213 | dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; |
|
185 | 214 | return dbg.maybeSpace(); |
|
186 | 215 | } |
|
187 | 216 | |
|
188 | 217 | #include "moc_abstractdomain_p.cpp" |
|
189 | 218 | |
|
190 | 219 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,106 +1,113 | |||
|
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 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef ABSTRACTDOMAIN_H |
|
31 | 31 | #define ABSTRACTDOMAIN_H |
|
32 | 32 | #include "qchartglobal.h" |
|
33 | 33 | #include <QRectF> |
|
34 | 34 | #include <QSizeF> |
|
35 | 35 | #include <QDebug> |
|
36 | 36 | |
|
37 | 37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | class QAbstractAxis; | |
|
40 | ||
|
39 | 41 | class QTCOMMERCIALCHART_AUTOTEST_EXPORT AbstractDomain: public QObject |
|
40 | 42 | { |
|
41 | 43 | Q_OBJECT |
|
42 | 44 | public: |
|
45 | enum DomainType { UndefinedDomain, XYDomain, XLogYDomain, LogXYDomain, XLogYLogDomain }; | |
|
46 | public: | |
|
43 | 47 | explicit AbstractDomain(QObject *object = 0); |
|
44 | 48 | virtual ~AbstractDomain(); |
|
45 | 49 | |
|
46 | 50 | void setSize(const QSizeF& size); |
|
47 | 51 | QSizeF size() const; |
|
48 | 52 | |
|
53 | virtual DomainType type() = 0; | |
|
54 | ||
|
49 | 55 | virtual void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) = 0; |
|
50 | 56 | void setRangeX(qreal min, qreal max); |
|
51 | 57 | void setRangeY(qreal min, qreal max); |
|
52 | 58 | void setMinX(qreal min); |
|
53 | 59 | void setMaxX(qreal max); |
|
54 | 60 | void setMinY(qreal min); |
|
55 | 61 | void setMaxY(qreal max); |
|
56 | 62 | |
|
57 | 63 | qreal minX() const { return m_minX; } |
|
58 | 64 | qreal maxX() const { return m_maxX; } |
|
59 | 65 | qreal minY() const { return m_minY; } |
|
60 | 66 | qreal maxY() const { return m_maxY; } |
|
61 | 67 | |
|
62 | 68 | qreal spanX() const; |
|
63 | 69 | qreal spanY() const; |
|
64 | 70 | bool isEmpty() const; |
|
65 | 71 | |
|
66 | ||
|
67 | 72 | void blockAxisSignals(bool block); |
|
68 | 73 | bool axisSignalsBlocked() const { return m_axisSignalsBlocked; } |
|
69 | 74 | |
|
70 | ||
|
71 | 75 | friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const AbstractDomain &domain1, const AbstractDomain &domain2); |
|
72 | 76 | friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const AbstractDomain &domain1, const AbstractDomain &domain2); |
|
73 | 77 | friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const AbstractDomain &domain); |
|
74 | 78 | |
|
75 | 79 | virtual void zoomIn(const QRectF &rect) = 0; |
|
76 | 80 | virtual void zoomOut(const QRectF &rect) = 0; |
|
77 | 81 | virtual void move(qreal dx, qreal dy) = 0; |
|
78 | 82 | |
|
79 | 83 | virtual QPointF calculateGeometryPoint(const QPointF &point) const = 0; |
|
80 | 84 | virtual QPointF calculateDomainPoint(const QPointF &point) const = 0; |
|
81 | 85 | virtual QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const = 0; |
|
82 | 86 | |
|
87 | virtual bool attachAxis(QAbstractAxis* axis); | |
|
88 | virtual bool detachAxis(QAbstractAxis* axis); | |
|
89 | ||
|
83 | 90 | static void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount); |
|
84 | 91 | static qreal niceNumber(qreal x, bool ceiling); |
|
85 | 92 | |
|
86 | 93 | Q_SIGNALS: |
|
87 | 94 | void updated(); |
|
88 | 95 | void rangeHorizontalChanged(qreal min, qreal max); |
|
89 | 96 | void rangeVerticalChanged(qreal min, qreal max); |
|
90 | 97 | |
|
91 | 98 | public Q_SLOTS: |
|
92 | 99 | void handleVerticalAxisRangeChanged(qreal min,qreal max); |
|
93 | 100 | void handleHorizontalAxisRangeChanged(qreal min,qreal max); |
|
94 | 101 | |
|
95 | 102 | protected: |
|
96 | 103 | qreal m_minX; |
|
97 | 104 | qreal m_maxX; |
|
98 | 105 | qreal m_minY; |
|
99 | 106 | qreal m_maxY; |
|
100 | 107 | QSizeF m_size; |
|
101 | 108 | bool m_axisSignalsBlocked; |
|
102 | 109 | }; |
|
103 | 110 | |
|
104 | 111 | QTCOMMERCIALCHART_END_NAMESPACE |
|
105 | 112 | |
|
106 | 113 | #endif // ABSTRACTDOMAIN_H |
@@ -1,62 +1,64 | |||
|
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 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef XYDOMAIN_H |
|
31 | 31 | #define XYDOMAIN_H |
|
32 | 32 | #include "abstractdomain_p.h" |
|
33 | 33 | #include <QRectF> |
|
34 | 34 | #include <QSizeF> |
|
35 | 35 | |
|
36 | 36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | class QTCOMMERCIALCHART_AUTOTEST_EXPORT XYDomain: public AbstractDomain |
|
39 | 39 | { |
|
40 | 40 | Q_OBJECT |
|
41 | 41 | public: |
|
42 | 42 | explicit XYDomain(QObject *object = 0); |
|
43 | 43 | virtual ~XYDomain(); |
|
44 | 44 | |
|
45 | DomainType type(){ return AbstractDomain::XYDomain;} | |
|
46 | ||
|
45 | 47 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
46 | 48 | |
|
47 | 49 | friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XYDomain &Domain1, const XYDomain &Domain2); |
|
48 | 50 | friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const XYDomain &Domain1, const XYDomain &Domain2); |
|
49 | 51 | friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const XYDomain &AbstractDomain); |
|
50 | 52 | |
|
51 | 53 | void zoomIn(const QRectF &rect); |
|
52 | 54 | void zoomOut(const QRectF &rect); |
|
53 | 55 | void move(qreal dx, qreal dy); |
|
54 | 56 | |
|
55 | 57 | QPointF calculateGeometryPoint(const QPointF &point) const; |
|
56 | 58 | QPointF calculateDomainPoint(const QPointF &point) const; |
|
57 | 59 | QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const; |
|
58 | 60 | }; |
|
59 | 61 | |
|
60 | 62 | QTCOMMERCIALCHART_END_NAMESPACE |
|
61 | 63 | |
|
62 | 64 | #endif // XYDOMAIN_H |
@@ -1,101 +1,100 | |||
|
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 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef QLEGEND_P_H |
|
31 | 31 | #define QLEGEND_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qlegend.h" |
|
34 | 34 | |
|
35 | 35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | class QChart; |
|
38 | 38 | class ChartPresenter; |
|
39 | 39 | class QAbstractSeries; |
|
40 | 40 | class LegendLayout; |
|
41 | class Domain; | |
|
42 | 41 | class QLegendMarker; |
|
43 | 42 | |
|
44 | 43 | class QLegendPrivate : public QObject |
|
45 | 44 | { |
|
46 | 45 | Q_OBJECT |
|
47 | 46 | public: |
|
48 | 47 | QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q); |
|
49 | 48 | ~QLegendPrivate(); |
|
50 | 49 | |
|
51 | 50 | void setOffset(const QPointF &offset); |
|
52 | 51 | QPointF offset() const; |
|
53 | 52 | int roundness(qreal size); |
|
54 | 53 | |
|
55 | 54 | QGraphicsItemGroup* items() { return m_items; } |
|
56 | 55 | |
|
57 | 56 | QList<QLegendMarker*> markers(QAbstractSeries *series = 0); |
|
58 | 57 | |
|
59 | 58 | public Q_SLOTS: |
|
60 | 59 | void handleSeriesAdded(QAbstractSeries *series); |
|
61 | 60 | void handleSeriesRemoved(QAbstractSeries *series); |
|
62 | 61 | void handleSeriesVisibleChanged(); |
|
63 | 62 | void handleCountChanged(); |
|
64 | 63 | |
|
65 | 64 | private: |
|
66 | 65 | // Internal helpers |
|
67 | 66 | void addMarkers(QList<QLegendMarker *> markers); |
|
68 | 67 | void removeMarkers(QList<QLegendMarker *> markers); |
|
69 | 68 | void decorateMarkers(QList<QLegendMarker *> markers); |
|
70 | 69 | |
|
71 | 70 | private: |
|
72 | 71 | QLegend *q_ptr; |
|
73 | 72 | ChartPresenter *m_presenter; |
|
74 | 73 | LegendLayout *m_layout; |
|
75 | 74 | QChart *m_chart; |
|
76 | 75 | QGraphicsItemGroup *m_items; |
|
77 | 76 | Qt::Alignment m_alignment; |
|
78 | 77 | QBrush m_brush; |
|
79 | 78 | QPen m_pen; |
|
80 | 79 | QFont m_font; |
|
81 | 80 | QBrush m_labelBrush; |
|
82 | 81 | |
|
83 | 82 | qreal m_diameter; |
|
84 | 83 | bool m_attachedToChart; |
|
85 | 84 | bool m_backgroundVisible; |
|
86 | 85 | |
|
87 | 86 | QList<QLegendMarker *> m_markers; |
|
88 | 87 | QList<QAbstractSeries *> m_series; |
|
89 | 88 | |
|
90 | 89 | QHash<QGraphicsItem *, QLegendMarker *> m_markerHash; |
|
91 | 90 | |
|
92 | 91 | friend class QLegend; |
|
93 | 92 | friend class LegendMarkerItem; |
|
94 | 93 | friend class LegendLayout; |
|
95 | 94 | friend class QLegendMarkerPrivate; |
|
96 | 95 | friend class LegendScroller; |
|
97 | 96 | }; |
|
98 | 97 | |
|
99 | 98 | QTCOMMERCIALCHART_END_NAMESPACE |
|
100 | 99 | |
|
101 | 100 | #endif |
@@ -1,654 +1,657 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qchart.h" |
|
22 | 22 | #include "qchart_p.h" |
|
23 | 23 | #include "legendscroller_p.h" |
|
24 | 24 | #include "qlegend_p.h" |
|
25 | 25 | #include "chartbackground_p.h" |
|
26 | 26 | #include "qabstractaxis.h" |
|
27 | 27 | #include "chartlayout_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | #include "chartpresenter_p.h" |
|
30 | 30 | #include "chartdataset_p.h" |
|
31 | 31 | #include <QGraphicsScene> |
|
32 | 32 | #include <QGraphicsSceneResizeEvent> |
|
33 | 33 | |
|
34 | 34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | 35 | |
|
36 | 36 | /*! |
|
37 | 37 | \enum QChart::ChartTheme |
|
38 | 38 | |
|
39 | 39 | This enum describes the theme used by the chart. |
|
40 | 40 | |
|
41 | 41 | \value ChartThemeLight The default theme |
|
42 | 42 | \value ChartThemeBlueCerulean |
|
43 | 43 | \value ChartThemeDark |
|
44 | 44 | \value ChartThemeBrownSand |
|
45 | 45 | \value ChartThemeBlueNcs |
|
46 | 46 | \value ChartThemeHighContrast |
|
47 | 47 | \value ChartThemeBlueIcy |
|
48 | 48 | */ |
|
49 | 49 | |
|
50 | 50 | /*! |
|
51 | 51 | \enum QChart::AnimationOption |
|
52 | 52 | |
|
53 | 53 | For enabling/disabling animations. Defaults to NoAnimation. |
|
54 | 54 | |
|
55 | 55 | \value NoAnimation |
|
56 | 56 | \value GridAxisAnimations |
|
57 | 57 | \value SeriesAnimations |
|
58 | 58 | \value AllAnimations |
|
59 | 59 | */ |
|
60 | 60 | |
|
61 | 61 | /*! |
|
62 | 62 | \class QChart |
|
63 | 63 | \brief QtCommercial chart API. |
|
64 | 64 | |
|
65 | 65 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
66 | 66 | representation of different types of series and other chart related objects like |
|
67 | 67 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the |
|
68 | 68 | convenience class QChartView instead of QChart. |
|
69 | 69 | \sa QChartView |
|
70 | 70 | */ |
|
71 | 71 | |
|
72 | 72 | /*! |
|
73 | 73 | \property QChart::animationOptions |
|
74 | 74 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
75 | 75 | */ |
|
76 | 76 | |
|
77 | 77 | /*! |
|
78 | 78 | \property QChart::backgroundVisible |
|
79 | 79 | Whether the chart background is visible or not. |
|
80 | 80 | \sa setBackgroundBrush(), setBackgroundPen() |
|
81 | 81 | */ |
|
82 | 82 | |
|
83 | 83 | /*! |
|
84 | 84 | \property QChart::dropShadowEnabled |
|
85 | 85 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
86 | 86 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
87 | 87 | */ |
|
88 | 88 | |
|
89 | 89 | /*! |
|
90 | 90 | \property QChart::minimumMargins |
|
91 | 91 | Minimum margins between the plot area (axes) and the edge of the chart widget. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \property QChart::theme |
|
96 | 96 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
97 | 97 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few |
|
98 | 98 | different themes. |
|
99 | 99 | Note: changing the theme will overwrite all customizations previously applied to the series. |
|
100 | 100 | */ |
|
101 | 101 | |
|
102 | 102 | /*! |
|
103 | 103 | \property QChart::title |
|
104 | 104 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. |
|
105 | 105 | */ |
|
106 | 106 | |
|
107 | 107 | /*! |
|
108 | 108 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
109 | 109 | */ |
|
110 | 110 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
111 | 111 | : QGraphicsWidget(parent, wFlags), |
|
112 | 112 | d_ptr(new QChartPrivate(this)) |
|
113 | 113 | { |
|
114 | 114 | d_ptr->m_legend = new LegendScroller(this); |
|
115 | 115 | setTheme(QChart::ChartThemeLight); |
|
116 | 116 | //TODO: what is that ? |
|
117 | 117 | //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF))); |
|
118 | 118 | setLayout(d_ptr->m_presenter->layout()); |
|
119 | 119 | } |
|
120 | 120 | |
|
121 | 121 | /*! |
|
122 | 122 | Destroys the object and it's children, like series and axis objects added to it. |
|
123 | 123 | */ |
|
124 | 124 | QChart::~QChart() |
|
125 | 125 | { |
|
126 | 126 | //start by deleting dataset, it will remove all series and axes |
|
127 | 127 | delete d_ptr->m_dataset; |
|
128 | 128 | d_ptr->m_dataset = 0; |
|
129 | 129 | } |
|
130 | 130 | |
|
131 | 131 | /*! |
|
132 | 132 | Adds the \a series onto the chart and takes the ownership of the object. |
|
133 | 133 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
134 | 134 | the y axis). |
|
135 | 135 | |
|
136 | 136 | \sa removeSeries(), removeAllSeries() |
|
137 | 137 | */ |
|
138 | 138 | void QChart::addSeries(QAbstractSeries *series) |
|
139 | 139 | { |
|
140 | 140 | Q_ASSERT(series); |
|
141 | 141 | d_ptr->m_dataset->addSeries(series); |
|
142 | 142 | } |
|
143 | 143 | |
|
144 | 144 | /*! |
|
145 | 145 | Removes the \a series specified in a perameter from the QChartView. |
|
146 | 146 | It releses its ownership of the specified QChartSeries object. |
|
147 | 147 | It does not delete the pointed QChartSeries data object |
|
148 | 148 | \sa addSeries(), removeAllSeries() |
|
149 | 149 | */ |
|
150 | 150 | void QChart::removeSeries(QAbstractSeries *series) |
|
151 | 151 | { |
|
152 | 152 | Q_ASSERT(series); |
|
153 | 153 | d_ptr->m_dataset->removeSeries(series); |
|
154 | 154 | } |
|
155 | 155 | |
|
156 | 156 | /*! |
|
157 | 157 | Removes all the QChartSeries that have been added to the QChartView |
|
158 | 158 | It also deletes the pointed QChartSeries data objects |
|
159 | 159 | \sa addSeries(), removeSeries() |
|
160 | 160 | */ |
|
161 | 161 | void QChart::removeAllSeries() |
|
162 | 162 | { |
|
163 | d_ptr->m_dataset->removeAllSeries(); | |
|
163 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ | |
|
164 | removeSeries(s); | |
|
165 | delete s; | |
|
166 | } | |
|
164 | 167 | } |
|
165 | 168 | |
|
166 | 169 | /*! |
|
167 | 170 | Sets the \a brush that is used for painting the background of the chart area. |
|
168 | 171 | */ |
|
169 | 172 | void QChart::setBackgroundBrush(const QBrush &brush) |
|
170 | 173 | { |
|
171 | 174 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
172 | 175 | } |
|
173 | 176 | |
|
174 | 177 | /*! |
|
175 | 178 | Gets the brush that is used for painting the background of the chart area. |
|
176 | 179 | */ |
|
177 | 180 | QBrush QChart::backgroundBrush() const |
|
178 | 181 | { |
|
179 | 182 | return d_ptr->m_presenter->backgroundBrush(); |
|
180 | 183 | } |
|
181 | 184 | |
|
182 | 185 | /*! |
|
183 | 186 | Sets the \a pen that is used for painting the background of the chart area. |
|
184 | 187 | */ |
|
185 | 188 | void QChart::setBackgroundPen(const QPen &pen) |
|
186 | 189 | { |
|
187 | 190 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
188 | 191 | } |
|
189 | 192 | |
|
190 | 193 | /*! |
|
191 | 194 | Gets the pen that is used for painting the background of the chart area. |
|
192 | 195 | */ |
|
193 | 196 | QPen QChart::backgroundPen() const |
|
194 | 197 | { |
|
195 | 198 | return d_ptr->m_presenter->backgroundPen(); |
|
196 | 199 | } |
|
197 | 200 | |
|
198 | 201 | /*! |
|
199 | 202 | Sets the chart \a title. The description text that is drawn above the chart. |
|
200 | 203 | */ |
|
201 | 204 | void QChart::setTitle(const QString &title) |
|
202 | 205 | { |
|
203 | 206 | d_ptr->m_presenter->setTitle(title); |
|
204 | 207 | } |
|
205 | 208 | |
|
206 | 209 | /*! |
|
207 | 210 | Returns the chart title. The description text that is drawn above the chart. |
|
208 | 211 | */ |
|
209 | 212 | QString QChart::title() const |
|
210 | 213 | { |
|
211 | 214 | return d_ptr->m_presenter->title(); |
|
212 | 215 | } |
|
213 | 216 | |
|
214 | 217 | /*! |
|
215 | 218 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. |
|
216 | 219 | */ |
|
217 | 220 | void QChart::setTitleFont(const QFont &font) |
|
218 | 221 | { |
|
219 | 222 | d_ptr->m_presenter->setTitleFont(font); |
|
220 | 223 | } |
|
221 | 224 | |
|
222 | 225 | /*! |
|
223 | 226 | Gets the font that is used for drawing the chart description text that is rendered above the chart. |
|
224 | 227 | */ |
|
225 | 228 | QFont QChart::titleFont() const |
|
226 | 229 | { |
|
227 | 230 | return d_ptr->m_presenter->titleFont(); |
|
228 | 231 | } |
|
229 | 232 | |
|
230 | 233 | /*! |
|
231 | 234 | Sets the \a brush used for rendering the title text. |
|
232 | 235 | */ |
|
233 | 236 | void QChart::setTitleBrush(const QBrush &brush) |
|
234 | 237 | { |
|
235 | 238 | d_ptr->m_presenter->setTitleBrush(brush); |
|
236 | 239 | } |
|
237 | 240 | |
|
238 | 241 | /*! |
|
239 | 242 | Returns the brush used for rendering the title text. |
|
240 | 243 | */ |
|
241 | 244 | QBrush QChart::titleBrush() const |
|
242 | 245 | { |
|
243 | 246 | return d_ptr->m_presenter->titleBrush(); |
|
244 | 247 | } |
|
245 | 248 | |
|
246 | 249 | void QChart::setTheme(QChart::ChartTheme theme) |
|
247 | 250 | { |
|
248 | 251 | d_ptr->m_themeManager->setTheme(theme); |
|
249 | 252 | } |
|
250 | 253 | |
|
251 | 254 | QChart::ChartTheme QChart::theme() const |
|
252 | 255 | { |
|
253 | 256 | return d_ptr->m_themeManager->theme()->id(); |
|
254 | 257 | } |
|
255 | 258 | |
|
256 | 259 | /*! |
|
257 | 260 | Zooms in the view by a factor of 2 |
|
258 | 261 | */ |
|
259 | 262 | void QChart::zoomIn() |
|
260 | 263 | { |
|
261 | 264 | d_ptr->zoomIn(2.0); |
|
262 | 265 | } |
|
263 | 266 | |
|
264 | 267 | /*! |
|
265 | 268 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
266 | 269 | */ |
|
267 | 270 | void QChart::zoomIn(const QRectF &rect) |
|
268 | 271 | { |
|
269 | 272 | d_ptr->zoomIn(rect); |
|
270 | 273 | } |
|
271 | 274 | |
|
272 | 275 | /*! |
|
273 | 276 | Restores the view zoom level to the previous one. |
|
274 | 277 | */ |
|
275 | 278 | void QChart::zoomOut() |
|
276 | 279 | { |
|
277 | 280 | d_ptr->zoomOut(2.0); |
|
278 | 281 | } |
|
279 | 282 | |
|
280 | 283 | /*! |
|
281 | 284 | Zooms in the view by a \a factor. |
|
282 | 285 | |
|
283 | 286 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
284 | 287 | */ |
|
285 | 288 | void QChart::zoom(qreal factor) |
|
286 | 289 | { |
|
287 | 290 | if (qFuzzyCompare(factor, 0)) |
|
288 | 291 | return; |
|
289 | 292 | |
|
290 | 293 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
291 | 294 | return; |
|
292 | 295 | |
|
293 | 296 | if (factor < 0) |
|
294 | 297 | return; |
|
295 | 298 | |
|
296 | 299 | if (factor > 1.0) |
|
297 | 300 | d_ptr->zoomIn(factor); |
|
298 | 301 | else |
|
299 | 302 | d_ptr->zoomOut(1.0 / factor); |
|
300 | 303 | } |
|
301 | 304 | |
|
302 | 305 | /*! |
|
303 | 306 | Returns the pointer to the x axis object of the chart asociated with the specified \a series |
|
304 | 307 | If no series is provided then pointer to currently visible axis is provided |
|
305 | 308 | */ |
|
306 | 309 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const |
|
307 | 310 | { |
|
308 | 311 | if(!series && d_ptr->m_dataset->series().size()>0){ |
|
309 | 312 | series = d_ptr->m_dataset->series().first(); |
|
310 | 313 | } |
|
311 | 314 | |
|
312 | 315 | QList<QAbstractAxis*> axes = series->attachedAxes(); |
|
313 | 316 | QAbstractAxis* bottom=0; |
|
314 | 317 | QAbstractAxis* top=0; |
|
315 | 318 | |
|
316 | 319 | foreach(QAbstractAxis* axis, axes){ |
|
317 | 320 | |
|
318 | 321 | if(axis->alignment()==Qt::AlignTop){ |
|
319 | 322 | top=axis; |
|
320 | 323 | } |
|
321 | 324 | |
|
322 | 325 | if(axis->alignment()==Qt::AlignBottom){ |
|
323 | 326 | bottom=axis; |
|
324 | 327 | } |
|
325 | 328 | } |
|
326 | 329 | return bottom?bottom:top; |
|
327 | 330 | } |
|
328 | 331 | |
|
329 | 332 | /*! |
|
330 | 333 | Returns the pointer to the y axis object of the chart asociated with the specified \a series |
|
331 | 334 | If no series is provided then pointer to currently visible axis is provided |
|
332 | 335 | */ |
|
333 | 336 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const |
|
334 | 337 | { |
|
335 | 338 | if(!series && d_ptr->m_dataset->series().size()>0) { |
|
336 | 339 | series = d_ptr->m_dataset->series().first(); |
|
337 | 340 | } |
|
338 | 341 | |
|
339 | 342 | QList<QAbstractAxis*> axes = series->attachedAxes(); |
|
340 | 343 | |
|
341 | 344 | QAbstractAxis* left=0; |
|
342 | 345 | QAbstractAxis* right=0; |
|
343 | 346 | |
|
344 | 347 | foreach(QAbstractAxis* axis, axes){ |
|
345 | 348 | |
|
346 | 349 | if(axis->alignment()==Qt::AlignLeft){ |
|
347 | 350 | left=axis; |
|
348 | 351 | } |
|
349 | 352 | |
|
350 | 353 | if(axis->alignment()==Qt::AlignRight){ |
|
351 | 354 | right=axis; |
|
352 | 355 | } |
|
353 | 356 | } |
|
354 | 357 | |
|
355 | 358 | return left?left:right; |
|
356 | 359 | } |
|
357 | 360 | |
|
358 | 361 | |
|
359 | 362 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const |
|
360 | 363 | { |
|
361 | 364 | QList<QAbstractAxis *> result ; |
|
362 | 365 | |
|
363 | 366 | foreach(QAbstractAxis* axis,series->attachedAxes()){ |
|
364 | 367 | if(orientation.testFlag(axis->orientation())) |
|
365 | 368 | result << axis; |
|
366 | 369 | } |
|
367 | 370 | |
|
368 | 371 | return result; |
|
369 | 372 | } |
|
370 | 373 | |
|
371 | 374 | /*! |
|
372 | 375 | NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL. |
|
373 | 376 | |
|
374 | 377 | Creates the axes for the chart based on the series that has already been added to the chart. |
|
375 | 378 | |
|
376 | 379 | \table |
|
377 | 380 | \header |
|
378 | 381 | \o Series type |
|
379 | 382 | \o X-axis |
|
380 | 383 | \o Y-axis |
|
381 | 384 | \row |
|
382 | 385 | \o QXYSeries |
|
383 | 386 | \o QValueAxis |
|
384 | 387 | \o QValueAxis |
|
385 | 388 | \row |
|
386 | 389 | \o QBarSeries |
|
387 | 390 | \o QBarCategoryAxis |
|
388 | 391 | \o QValueAxis |
|
389 | 392 | \row |
|
390 | 393 | \o QPieSeries |
|
391 | 394 | \o None |
|
392 | 395 | \o None |
|
393 | 396 | \endtable |
|
394 | 397 | |
|
395 | 398 | If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created. |
|
396 | 399 | If there are sevaral series added of different types then each series gets its own axes pair. |
|
397 | 400 | |
|
398 | 401 | NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown. |
|
399 | 402 | |
|
400 | 403 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. |
|
401 | 404 | QPieSeries does not create any axes. |
|
402 | 405 | |
|
403 | 406 | \sa axisX(), axisY(), setAxisX(), setAxisY() |
|
404 | 407 | */ |
|
405 | 408 | void QChart::createDefaultAxes() |
|
406 | 409 | { |
|
407 | 410 | d_ptr->m_dataset->createDefaultAxes(); |
|
408 | 411 | } |
|
409 | 412 | |
|
410 | 413 | /*! |
|
411 | 414 | Returns the legend object of the chart. Ownership stays in chart. |
|
412 | 415 | */ |
|
413 | 416 | QLegend *QChart::legend() const |
|
414 | 417 | { |
|
415 | 418 | return d_ptr->m_legend; |
|
416 | 419 | } |
|
417 | 420 | |
|
418 | 421 | /*! |
|
419 | 422 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
420 | 423 | Deprecated. Use setMargins(). |
|
421 | 424 | */ |
|
422 | 425 | void QChart::setMinimumMargins(const QMargins &margins) |
|
423 | 426 | { |
|
424 | 427 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; |
|
425 | 428 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
426 | 429 | } |
|
427 | 430 | |
|
428 | 431 | /*! |
|
429 | 432 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
430 | 433 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
431 | 434 | Deprecated. Use margins(). |
|
432 | 435 | */ |
|
433 | 436 | QMargins QChart::minimumMargins() const |
|
434 | 437 | { |
|
435 | 438 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; |
|
436 | 439 | return d_ptr->m_presenter->layout()->margins(); |
|
437 | 440 | } |
|
438 | 441 | |
|
439 | 442 | /*! |
|
440 | 443 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
441 | 444 | */ |
|
442 | 445 | void QChart::setMargins(const QMargins &margins) |
|
443 | 446 | { |
|
444 | 447 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
445 | 448 | } |
|
446 | 449 | |
|
447 | 450 | /*! |
|
448 | 451 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
449 | 452 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
450 | 453 | */ |
|
451 | 454 | QMargins QChart::margins() const |
|
452 | 455 | { |
|
453 | 456 | return d_ptr->m_presenter->layout()->margins(); |
|
454 | 457 | } |
|
455 | 458 | |
|
456 | 459 | /*! |
|
457 | 460 | Returns the the rect within which the drawing of the chart is done. |
|
458 | 461 | It does not include the area defines by margins. |
|
459 | 462 | */ |
|
460 | 463 | QRectF QChart::plotArea() const |
|
461 | 464 | { |
|
462 | 465 | return d_ptr->m_presenter->geometry(); |
|
463 | 466 | } |
|
464 | 467 | |
|
465 | 468 | ///*! |
|
466 | 469 | // TODO: Dummy. |
|
467 | 470 | // Adjest the ranges of the axes so that all the data of the specified \a series is visible |
|
468 | 471 | // */ |
|
469 | 472 | //void QChart::adjustViewToSeries(QAbstractSeries* series) |
|
470 | 473 | //{ |
|
471 | 474 | // // |
|
472 | 475 | //} |
|
473 | 476 | |
|
474 | 477 | /*! |
|
475 | 478 | Sets animation \a options for the chart |
|
476 | 479 | */ |
|
477 | 480 | void QChart::setAnimationOptions(AnimationOptions options) |
|
478 | 481 | { |
|
479 | 482 | d_ptr->m_presenter->setAnimationOptions(options); |
|
480 | 483 | } |
|
481 | 484 | |
|
482 | 485 | QChart::AnimationOptions QChart::animationOptions() const |
|
483 | 486 | { |
|
484 | 487 | return d_ptr->m_presenter->animationOptions(); |
|
485 | 488 | } |
|
486 | 489 | |
|
487 | 490 | /*! |
|
488 | 491 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
489 | 492 | */ |
|
490 | 493 | void QChart::scroll(qreal dx, qreal dy) |
|
491 | 494 | { |
|
492 | 495 | d_ptr->scroll(dx,dy); |
|
493 | 496 | } |
|
494 | 497 | |
|
495 | 498 | void QChart::setBackgroundVisible(bool visible) |
|
496 | 499 | { |
|
497 | 500 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
498 | 501 | } |
|
499 | 502 | |
|
500 | 503 | bool QChart::isBackgroundVisible() const |
|
501 | 504 | { |
|
502 | 505 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
503 | 506 | } |
|
504 | 507 | |
|
505 | 508 | void QChart::setDropShadowEnabled(bool enabled) |
|
506 | 509 | { |
|
507 | 510 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
508 | 511 | } |
|
509 | 512 | |
|
510 | 513 | bool QChart::isDropShadowEnabled() const |
|
511 | 514 | { |
|
512 | 515 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
513 | 516 | } |
|
514 | 517 | |
|
515 | 518 | /*! |
|
516 | 519 | Returns all the series that are added to the chart. |
|
517 | 520 | |
|
518 | 521 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
519 | 522 | */ |
|
520 | 523 | QList<QAbstractSeries *> QChart::series() const |
|
521 | 524 | { |
|
522 | 525 | return d_ptr->m_dataset->series(); |
|
523 | 526 | } |
|
524 | 527 | |
|
525 | 528 | /*! |
|
526 | 529 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
527 | 530 | |
|
528 | 531 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() |
|
529 | 532 | */ |
|
530 | 533 | void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series) |
|
531 | 534 | { |
|
532 | 535 | QList<QAbstractAxis*> list = axes(Qt::Horizontal,series); |
|
533 | 536 | |
|
534 | 537 | foreach(QAbstractAxis* a, list){ |
|
535 | 538 | d_ptr->m_dataset->removeAxis(a); |
|
536 | 539 | delete a; |
|
537 | 540 | } |
|
538 | 541 | |
|
539 | 542 | if(!d_ptr->m_dataset->axes().contains(axis)) |
|
540 | 543 | d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom); |
|
541 | 544 | d_ptr->m_dataset->attachAxis(series,axis); |
|
542 | 545 | } |
|
543 | 546 | |
|
544 | 547 | /*! |
|
545 | 548 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
546 | 549 | |
|
547 | 550 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() |
|
548 | 551 | */ |
|
549 | 552 | void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series) |
|
550 | 553 | { |
|
551 | 554 | QList<QAbstractAxis*> list = axes(Qt::Vertical,series); |
|
552 | 555 | |
|
553 | 556 | foreach(QAbstractAxis* a, list) { |
|
554 | 557 | d_ptr->m_dataset->removeAxis(a); |
|
555 | 558 | delete a; |
|
556 | 559 | } |
|
557 | 560 | |
|
558 | 561 | if(!d_ptr->m_dataset->axes().contains(axis)) |
|
559 | 562 | d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft); |
|
560 | 563 | d_ptr->m_dataset->attachAxis(series,axis); |
|
561 | 564 | } |
|
562 | 565 | |
|
563 | 566 | void QChart::addAxis(QAbstractAxis *axis,Qt::Alignment aligment) |
|
564 | 567 | { |
|
565 | 568 | d_ptr->m_dataset->addAxis(axis,aligment); |
|
566 | 569 | } |
|
567 | 570 | |
|
568 | 571 | void QChart::removeAxis(QAbstractAxis *axis) |
|
569 | 572 | { |
|
570 | 573 | d_ptr->m_dataset->removeAxis(axis); |
|
571 | 574 | } |
|
572 | 575 | |
|
573 | 576 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
574 | 577 | |
|
575 | 578 | QChartPrivate::QChartPrivate(QChart *q): |
|
576 | 579 | q_ptr(q), |
|
577 | 580 | m_legend(0), |
|
578 | 581 | m_dataset(new ChartDataSet(q)), |
|
579 | 582 | m_presenter(new ChartPresenter(q)), |
|
580 | 583 | m_themeManager(new ChartThemeManager(q)) |
|
581 | 584 | { |
|
582 | 585 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
583 | 586 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
584 | 587 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
585 | 588 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
586 | 589 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
587 | 590 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
588 | 591 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
589 | 592 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
590 | 593 | } |
|
591 | 594 | |
|
592 | 595 | QChartPrivate::~QChartPrivate() |
|
593 | 596 | { |
|
594 | 597 | |
|
595 | 598 | } |
|
596 | 599 | |
|
597 | 600 | void QChartPrivate::zoomIn(qreal factor) |
|
598 | 601 | { |
|
599 | 602 | QRectF rect = m_presenter->geometry(); |
|
600 | 603 | rect.setWidth(rect.width() / factor); |
|
601 | 604 | rect.setHeight(rect.height() / factor); |
|
602 | 605 | rect.moveCenter(m_presenter->geometry().center()); |
|
603 | 606 | zoomIn(rect); |
|
604 | 607 | } |
|
605 | 608 | |
|
606 | 609 | void QChartPrivate::zoomIn(const QRectF &rect) |
|
607 | 610 | { |
|
608 | 611 | if (!rect.isValid()) |
|
609 | 612 | return; |
|
610 | 613 | |
|
611 | 614 | QRectF r = rect.normalized(); |
|
612 | 615 | const QRectF geometry = m_presenter->geometry(); |
|
613 | 616 | r.translate(-geometry.topLeft()); |
|
614 | 617 | |
|
615 | 618 | if (!r.isValid()) |
|
616 | 619 | return; |
|
617 | 620 | |
|
618 | 621 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
619 | 622 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); |
|
620 | 623 | m_dataset->zoomInDomain(r); |
|
621 | 624 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
622 | 625 | |
|
623 | 626 | } |
|
624 | 627 | |
|
625 | 628 | void QChartPrivate::zoomOut(qreal factor) |
|
626 | 629 | { |
|
627 | 630 | const QRectF geometry = m_presenter->geometry(); |
|
628 | 631 | |
|
629 | 632 | QRectF r; |
|
630 | 633 | r.setSize(geometry.size() / factor); |
|
631 | 634 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); |
|
632 | 635 | if (!r.isValid()) |
|
633 | 636 | return; |
|
634 | 637 | |
|
635 | 638 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
636 | 639 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); |
|
637 | 640 | m_dataset->zoomOutDomain(r); |
|
638 | 641 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
639 | 642 | } |
|
640 | 643 | |
|
641 | 644 | void QChartPrivate::scroll(qreal dx, qreal dy) |
|
642 | 645 | { |
|
643 | 646 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); |
|
644 | 647 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); |
|
645 | 648 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); |
|
646 | 649 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); |
|
647 | 650 | |
|
648 | 651 | m_dataset->scrollDomain(dx, dy); |
|
649 | 652 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
650 | 653 | } |
|
651 | 654 | |
|
652 | 655 | #include "moc_qchart.cpp" |
|
653 | 656 | |
|
654 | 657 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,483 +1,398 | |||
|
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 | #ifndef BUILD_PRIVATE_UNIT_TESTS |
|
21 | 21 | #include <QtTest/QtTest> |
|
22 | 22 | |
|
23 | 23 | class tst_ChartDataSet: public QObject { |
|
24 | 24 | |
|
25 | 25 | Q_OBJECT |
|
26 | 26 | |
|
27 | 27 | private Q_SLOTS: |
|
28 | 28 | void skip(); |
|
29 | 29 | |
|
30 | 30 | }; |
|
31 | 31 | |
|
32 | 32 | void tst_ChartDataSet::skip() |
|
33 | 33 | { |
|
34 | 34 | QSKIP("This test requires the debug version of library", SkipAll); |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | QTEST_MAIN(tst_ChartDataSet) |
|
38 | 38 | #include "tst_chartdataset.moc" |
|
39 | 39 | |
|
40 | 40 | #else |
|
41 | 41 | |
|
42 | 42 | #include <QtTest/QtTest> |
|
43 | 43 | #include <qabstractaxis.h> |
|
44 | 44 | #include <qvalueaxis.h> |
|
45 | 45 | #include <qbarcategoryaxis.h> |
|
46 | 46 | #include <qcategoryaxis.h> |
|
47 | 47 | #include <qdatetimeaxis.h> |
|
48 | 48 | #include <qlineseries.h> |
|
49 | 49 | #include <qareaseries.h> |
|
50 | 50 | #include <qscatterseries.h> |
|
51 | 51 | #include <qsplineseries.h> |
|
52 | 52 | #include <qpieseries.h> |
|
53 | 53 | #include <qbarseries.h> |
|
54 | 54 | #include <qpercentbarseries.h> |
|
55 | 55 | #include <qstackedbarseries.h> |
|
56 | 56 | #include <private/chartdataset_p.h> |
|
57 | 57 | #include <private/abstractdomain_p.h> |
|
58 | 58 | #include <tst_definitions.h> |
|
59 | 59 | |
|
60 | 60 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
61 | 61 | |
|
62 | 62 | Q_DECLARE_METATYPE(AbstractDomain *) |
|
63 | 63 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
64 | 64 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
65 | 65 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) |
|
66 | 66 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) |
|
67 | 67 | Q_DECLARE_METATYPE(Qt::Alignment) |
|
68 | 68 | Q_DECLARE_METATYPE(QList<Qt::Alignment>) |
|
69 | 69 | Q_DECLARE_METATYPE(QLineSeries *) |
|
70 | 70 | |
|
71 | 71 | class tst_ChartDataSet: public QObject { |
|
72 | 72 | |
|
73 | 73 | Q_OBJECT |
|
74 | public: | |
|
75 | tst_ChartDataSet():m_dataset(0){}; | |
|
74 | 76 | |
|
75 | 77 | public Q_SLOTS: |
|
76 | 78 | void initTestCase(); |
|
77 | 79 | void cleanupTestCase(); |
|
78 | 80 | void init(); |
|
79 | 81 | void cleanup(); |
|
80 | 82 | |
|
81 | 83 | private Q_SLOTS: |
|
82 | 84 | void chartdataset_data(); |
|
83 | 85 | void chartdataset(); |
|
84 | 86 | void addSeries_data(); |
|
85 | 87 | void addSeries(); |
|
86 | 88 | void removeSeries_data(); |
|
87 | 89 | void removeSeries(); |
|
88 | void removeAllSeries_data(); | |
|
89 | void removeAllSeries(); | |
|
90 | 90 | void addAxis_data(); |
|
91 | 91 | void addAxis(); |
|
92 | 92 | void removeAxis_data(); |
|
93 | 93 | void removeAxis(); |
|
94 | void removeAllAxes_data(); | |
|
95 | void removeAllAxes(); | |
|
96 | 94 | void attachAxis_data(); |
|
97 | 95 | void attachAxis(); |
|
98 | 96 | void detachAxis_data(); |
|
99 | 97 | void detachAxis(); |
|
100 | 98 | |
|
101 | 99 | private: |
|
102 | 100 | ChartDataSet* m_dataset; |
|
103 | 101 | }; |
|
104 | 102 | |
|
105 | 103 | void tst_ChartDataSet::initTestCase() |
|
106 | 104 | { |
|
107 | 105 | qRegisterMetaType<AbstractDomain*>(); |
|
108 | 106 | qRegisterMetaType<QAbstractAxis*>(); |
|
109 | 107 | qRegisterMetaType<QAbstractSeries*>(); |
|
110 | 108 | } |
|
111 | 109 | |
|
112 | 110 | void tst_ChartDataSet::cleanupTestCase() |
|
113 | 111 | { |
|
114 | 112 | } |
|
115 | 113 | |
|
116 | 114 | void tst_ChartDataSet::init() |
|
117 | 115 | { |
|
116 | Q_ASSERT(!m_dataset); | |
|
118 | 117 | m_dataset = new ChartDataSet(0); |
|
119 | 118 | } |
|
120 | 119 | |
|
121 | 120 | |
|
122 | 121 | void tst_ChartDataSet::cleanup() |
|
123 | 122 | { |
|
124 | QList<QAbstractSeries*> series = m_dataset->series(); | |
|
125 | foreach (QAbstractSeries* serie, series) | |
|
126 | { | |
|
127 | m_dataset->removeSeries(serie); | |
|
128 | } | |
|
123 | delete m_dataset; | |
|
124 | m_dataset=0; | |
|
129 | 125 | } |
|
130 | 126 | |
|
131 | 127 | void tst_ChartDataSet::chartdataset_data() |
|
132 | 128 | { |
|
133 | 129 | } |
|
134 | 130 | |
|
135 | 131 | void tst_ChartDataSet::chartdataset() |
|
136 | 132 | { |
|
137 | 133 | QVERIFY(m_dataset->axes().isEmpty()); |
|
138 | 134 | QVERIFY(m_dataset->series().isEmpty()); |
|
139 | 135 | m_dataset->createDefaultAxes(); |
|
140 | 136 | } |
|
141 | 137 | |
|
142 | 138 | |
|
143 | 139 | void tst_ChartDataSet::addSeries_data() |
|
144 | 140 | { |
|
145 | 141 | QTest::addColumn<QAbstractSeries*>("series"); |
|
146 | 142 | |
|
147 | 143 | QAbstractSeries* line = new QLineSeries(this); |
|
148 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
|
149 | QAbstractSeries* scatter = new QScatterSeries(this); | |
|
150 | QAbstractSeries* spline = new QSplineSeries(this); | |
|
151 | QAbstractSeries* pie = new QPieSeries(this); | |
|
152 | QAbstractSeries* bar = new QBarSeries(this); | |
|
153 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
|
154 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
|
155 | ||
|
156 | 144 | QTest::newRow("line") << line; |
|
145 | ||
|
146 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(new QLineSeries(this))); | |
|
157 | 147 | QTest::newRow("area") << area; |
|
148 | ||
|
149 | QAbstractSeries* scatter = new QScatterSeries(this); | |
|
158 | 150 | QTest::newRow("scatter") << scatter; |
|
151 | ||
|
152 | QAbstractSeries* spline = new QSplineSeries(this); | |
|
159 | 153 | QTest::newRow("spline") << spline; |
|
154 | ||
|
155 | QAbstractSeries* pie = new QPieSeries(this); | |
|
160 | 156 | QTest::newRow("pie") << pie; |
|
157 | ||
|
158 | QAbstractSeries* bar = new QBarSeries(this); | |
|
161 | 159 | QTest::newRow("bar") << bar; |
|
160 | ||
|
161 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
|
162 | 162 | QTest::newRow("percent") << percent; |
|
163 | ||
|
164 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
|
163 | 165 | QTest::newRow("stacked") << stacked; |
|
164 | 166 | } |
|
165 | 167 | |
|
166 | 168 | void tst_ChartDataSet::addSeries() |
|
167 | 169 | { |
|
168 | 170 | QFETCH(QAbstractSeries*, series); |
|
169 | 171 | QVERIFY(m_dataset->series().isEmpty()); |
|
170 | 172 | |
|
171 | 173 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
172 | 174 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
173 | 175 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
174 | 176 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
175 | 177 | |
|
176 | 178 | m_dataset->addSeries(series); |
|
177 | 179 | |
|
178 | ||
|
179 | 180 | QCOMPARE(m_dataset->series().count(),1); |
|
180 | 181 | TRY_COMPARE(spy0.count(), 0); |
|
181 | 182 | TRY_COMPARE(spy1.count(), 0); |
|
182 | 183 | TRY_COMPARE(spy2.count(), 1); |
|
183 | 184 | TRY_COMPARE(spy3.count(), 0); |
|
184 | 185 | } |
|
185 | 186 | |
|
186 | 187 | void tst_ChartDataSet::removeSeries_data() |
|
187 | 188 | { |
|
188 | 189 | addSeries_data(); |
|
189 | 190 | } |
|
190 | 191 | |
|
191 | 192 | void tst_ChartDataSet::removeSeries() |
|
192 | 193 | { |
|
193 | 194 | QFETCH(QAbstractSeries*, series); |
|
194 | 195 | QVERIFY(m_dataset->series().isEmpty()); |
|
195 | 196 | m_dataset->addSeries(series); |
|
196 | 197 | |
|
197 | 198 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
198 | 199 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
199 | 200 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
200 | 201 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
201 | 202 | |
|
202 | 203 | m_dataset->removeSeries(series); |
|
203 | 204 | |
|
204 | 205 | QCOMPARE(m_dataset->series().count(),0); |
|
205 | 206 | TRY_COMPARE(spy0.count(), 0); |
|
206 | 207 | TRY_COMPARE(spy1.count(), 0); |
|
207 | 208 | TRY_COMPARE(spy2.count(), 0); |
|
208 | 209 | TRY_COMPARE(spy3.count(), 1); |
|
209 | 210 | } |
|
210 | 211 | |
|
211 | void tst_ChartDataSet::removeAllSeries_data() | |
|
212 | { | |
|
213 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
|
214 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); | |
|
215 | ||
|
216 | QList<QAbstractSeries*> series; | |
|
217 | QList<QAbstractAxis*> axis; | |
|
218 | ||
|
219 | series << new QLineSeries(this) << new QSplineSeries(this) << new QScatterSeries(this); | |
|
220 | axis << new QValueAxis(this) << new QValueAxis(this) << new QValueAxis(this); | |
|
221 | ||
|
222 | QTest::newRow("3 series , 3 axis") << series << axis; | |
|
223 | } | |
|
224 | ||
|
225 | void tst_ChartDataSet::removeAllSeries() | |
|
226 | { | |
|
227 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
|
228 | QFETCH(QList<QAbstractAxis*>, axisList); | |
|
229 | ||
|
230 | QCOMPARE(m_dataset->series().count(),0); | |
|
231 | QCOMPARE(m_dataset->axes().count(),0); | |
|
232 | ||
|
233 | foreach (QAbstractSeries* series, seriesList) { | |
|
234 | m_dataset->addSeries(series); | |
|
235 | } | |
|
236 | ||
|
237 | foreach (QAbstractAxis* axis, axisList) { | |
|
238 | m_dataset->addAxis(axis,Qt::AlignBottom); | |
|
239 | } | |
|
240 | ||
|
241 | for (int i = 0; i < seriesList.count(); i++) { | |
|
242 | m_dataset->attachAxis(seriesList.at(i),axisList.at(i)); | |
|
243 | } | |
|
244 | ||
|
245 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
|
246 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
|
247 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
|
248 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
|
249 | ||
|
250 | m_dataset->removeAllSeries(); | |
|
251 | ||
|
252 | TRY_COMPARE(spy0.count(), 0); | |
|
253 | TRY_COMPARE(spy1.count(), 0); | |
|
254 | TRY_COMPARE(spy2.count(), 0); | |
|
255 | TRY_COMPARE(spy3.count(), seriesList.count()); | |
|
256 | ||
|
257 | QCOMPARE(m_dataset->series().count(),0); | |
|
258 | QCOMPARE(m_dataset->axes().count(),axisList.count()); | |
|
259 | } | |
|
260 | ||
|
261 | 212 | void tst_ChartDataSet::addAxis_data() |
|
262 | 213 | { |
|
263 | 214 | QTest::addColumn<QAbstractAxis*>("axis"); |
|
264 | 215 | QAbstractAxis* value = new QValueAxis(this); |
|
265 | 216 | QAbstractAxis* category = new QCategoryAxis(this); |
|
266 | 217 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); |
|
267 | 218 | QAbstractAxis* datetime = new QDateTimeAxis(this); |
|
268 | 219 | |
|
269 | 220 | QTest::newRow("value") << value; |
|
270 | 221 | QTest::newRow("category") << category; |
|
271 | 222 | QTest::newRow("barcategory") << barcategory; |
|
272 | 223 | QTest::newRow("datetime") << datetime; |
|
273 | 224 | } |
|
274 | 225 | |
|
275 | 226 | void tst_ChartDataSet::addAxis() |
|
276 | 227 | { |
|
277 | 228 | QFETCH(QAbstractAxis*, axis); |
|
278 | 229 | QVERIFY(m_dataset->axes().isEmpty()); |
|
279 | 230 | |
|
280 | 231 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
281 | 232 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
282 | 233 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
283 | 234 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
284 | 235 | |
|
285 | 236 | m_dataset->addAxis(axis,Qt::AlignBottom); |
|
286 | 237 | |
|
287 | 238 | QCOMPARE(m_dataset->axes().count(),1); |
|
288 | 239 | TRY_COMPARE(spy0.count(), 1); |
|
289 | 240 | TRY_COMPARE(spy1.count(), 0); |
|
290 | 241 | TRY_COMPARE(spy2.count(), 0); |
|
291 | 242 | TRY_COMPARE(spy3.count(), 0); |
|
292 | 243 | } |
|
293 | 244 | |
|
294 | 245 | void tst_ChartDataSet::removeAxis_data() |
|
295 | 246 | { |
|
296 | 247 | addAxis_data(); |
|
297 | 248 | } |
|
298 | 249 | |
|
299 | 250 | void tst_ChartDataSet::removeAxis() |
|
300 | 251 | { |
|
301 | 252 | QFETCH(QAbstractAxis*, axis); |
|
302 | 253 | QVERIFY(m_dataset->series().isEmpty()); |
|
303 | 254 | m_dataset->addAxis(axis,Qt::AlignBottom); |
|
304 | 255 | |
|
305 | 256 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
306 | 257 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
307 | 258 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
308 | 259 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
309 | 260 | |
|
310 | 261 | m_dataset->removeAxis(axis); |
|
311 | 262 | |
|
312 | 263 | QCOMPARE(m_dataset->series().count(),0); |
|
313 | 264 | TRY_COMPARE(spy0.count(), 0); |
|
314 | 265 | TRY_COMPARE(spy1.count(), 1); |
|
315 | 266 | TRY_COMPARE(spy2.count(), 0); |
|
316 | 267 | TRY_COMPARE(spy3.count(), 0); |
|
317 | 268 | } |
|
318 | 269 | |
|
319 | void tst_ChartDataSet::removeAllAxes_data() | |
|
320 | { | |
|
321 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
|
322 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); | |
|
323 | ||
|
324 | QList<QAbstractSeries*> series; | |
|
325 | QList<QAbstractAxis*> axis; | |
|
326 | ||
|
327 | series << new QLineSeries(this) << new QSplineSeries(this) << new QScatterSeries(this); | |
|
328 | axis << new QValueAxis(this) << new QValueAxis(this) << new QValueAxis(this); | |
|
329 | ||
|
330 | QTest::newRow("3 series , 3 axis") << series << axis; | |
|
331 | } | |
|
332 | ||
|
333 | void tst_ChartDataSet::removeAllAxes() | |
|
334 | { | |
|
335 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
|
336 | QFETCH(QList<QAbstractAxis*>, axisList); | |
|
337 | ||
|
338 | QCOMPARE(m_dataset->series().count(),0); | |
|
339 | QCOMPARE(m_dataset->axes().count(),0); | |
|
340 | ||
|
341 | foreach (QAbstractSeries* series, seriesList) { | |
|
342 | m_dataset->addSeries(series); | |
|
343 | } | |
|
344 | ||
|
345 | foreach (QAbstractAxis* axis, axisList) { | |
|
346 | m_dataset->addAxis(axis,Qt::AlignBottom); | |
|
347 | } | |
|
348 | ||
|
349 | for (int i = 0; i < seriesList.count(); i++) { | |
|
350 | m_dataset->attachAxis(seriesList.at(i),axisList.at(i)); | |
|
351 | } | |
|
352 | ||
|
353 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
|
354 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
|
355 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
|
356 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
|
357 | ||
|
358 | m_dataset->removeAllAxes(); | |
|
359 | ||
|
360 | TRY_COMPARE(spy0.count(), 0); | |
|
361 | TRY_COMPARE(spy1.count(), axisList.count()); | |
|
362 | TRY_COMPARE(spy2.count(), 0); | |
|
363 | TRY_COMPARE(spy3.count(), 0); | |
|
364 | ||
|
365 | QCOMPARE(m_dataset->series().count(),seriesList.count()); | |
|
366 | QCOMPARE(m_dataset->axes().count(),0); | |
|
367 | } | |
|
368 | ||
|
369 | 270 | void tst_ChartDataSet::attachAxis_data() |
|
370 | 271 | { |
|
272 | ||
|
371 | 273 | QTest::addColumn<QList<QAbstractSeries*> >("series"); |
|
372 | 274 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); |
|
373 | 275 | QTest::addColumn<QList<Qt::Alignment> >("alignment"); |
|
374 | 276 | QTest::addColumn<QAbstractSeries*>("attachSeries"); |
|
375 | 277 | QTest::addColumn<QAbstractAxis*>("attachAxis"); |
|
376 | 278 | QTest::addColumn<bool>("success"); |
|
377 | 279 | |
|
378 | QList<QAbstractSeries*> series; | |
|
379 | QList<QAbstractAxis*> axes; | |
|
380 | QList<Qt::Alignment> alignment; | |
|
381 | ||
|
382 | QAbstractSeries* line = new QLineSeries(this); | |
|
383 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
|
280 | //QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
|
384 | 281 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
385 | 282 | QAbstractSeries* spline = new QSplineSeries(this); |
|
386 | 283 | QAbstractSeries* pie = new QPieSeries(this); |
|
387 | 284 | QAbstractSeries* bar = new QBarSeries(this); |
|
388 | 285 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
389 | 286 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
390 | 287 | |
|
391 | QAbstractAxis* value1 = new QValueAxis(this); | |
|
392 | QAbstractAxis* value2 = new QValueAxis(this); | |
|
393 | 288 | QAbstractAxis* category = new QCategoryAxis(this); |
|
394 | 289 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); |
|
395 | 290 | QAbstractAxis* datetime = new QDateTimeAxis(this); |
|
396 | 291 | |
|
292 | { | |
|
293 | QList<QAbstractSeries*> series; | |
|
294 | QList<QAbstractAxis*> axes; | |
|
295 | QList<Qt::Alignment> alignment; | |
|
296 | QAbstractSeries* line = new QLineSeries(this); | |
|
297 | QAbstractAxis* value1 = new QValueAxis(this); | |
|
298 | QAbstractAxis* value2 = new QValueAxis(this); | |
|
299 | series << line << 0; | |
|
300 | axes << value1 << value2; | |
|
301 | alignment << Qt::AlignBottom << Qt::AlignLeft; | |
|
302 | QTest::newRow("first") << series << axes << alignment << line << value2 << true ; | |
|
303 | } | |
|
397 | 304 | |
|
398 | series << line << 0; | |
|
399 | axes << value1 << value2; | |
|
400 | alignment << Qt::AlignBottom << Qt::AlignLeft; | |
|
401 | QTest::newRow("line + two axes") << series << axes << alignment << line << value2 << true; | |
|
305 | { | |
|
306 | QList<QAbstractSeries*> series; | |
|
307 | QList<QAbstractAxis*> axes; | |
|
308 | QList<Qt::Alignment> alignment; | |
|
309 | QAbstractSeries* line = new QLineSeries(this); | |
|
310 | QAbstractAxis* value1 = new QValueAxis(this); | |
|
311 | QAbstractAxis* value2 = new QValueAxis(this); | |
|
312 | series << 0 << line; | |
|
313 | axes << value1 << value2; | |
|
314 | alignment << Qt::AlignBottom << Qt::AlignLeft; | |
|
315 | QTest::newRow("second") << series << axes << alignment << line << value1 << true; | |
|
316 | } | |
|
402 | 317 | |
|
403 | 318 | } |
|
404 | 319 | |
|
405 | 320 | void tst_ChartDataSet::attachAxis() |
|
406 | 321 | { |
|
407 | 322 | QFETCH(QList<QAbstractSeries*>, series); |
|
408 | 323 | QFETCH(QList<QAbstractAxis*>, axis); |
|
409 | 324 | QFETCH(QList<Qt::Alignment>, alignment); |
|
410 | 325 | QFETCH(QAbstractSeries*, attachSeries); |
|
411 | 326 | QFETCH(QAbstractAxis*, attachAxis); |
|
412 | 327 | QFETCH(bool, success); |
|
413 | 328 | |
|
414 | 329 | Q_ASSERT(series.count() == axis.count()); |
|
415 | 330 | Q_ASSERT(series.count() == alignment.count()); |
|
416 | 331 | |
|
417 | 332 | QVERIFY(m_dataset->series().isEmpty()); |
|
418 | 333 | QVERIFY(m_dataset->axes().isEmpty()); |
|
419 | 334 | |
|
420 | 335 | for(int i = 0 ; i < series.count() ; i++){ |
|
421 | 336 | if(series[i]) m_dataset->addSeries(series[i]); |
|
422 | 337 | if(axis[i]) m_dataset->addAxis(axis[i],alignment[i]); |
|
423 | 338 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); |
|
424 | 339 | } |
|
425 | 340 | |
|
426 | 341 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
427 | 342 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
428 | 343 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
429 | 344 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
430 | 345 | |
|
431 | 346 | QCOMPARE(m_dataset->attachAxis(attachSeries,attachAxis),success); |
|
432 | 347 | |
|
433 | 348 | } |
|
434 | 349 | |
|
435 | 350 | void tst_ChartDataSet::detachAxis_data() |
|
436 | 351 | { |
|
437 | 352 | QTest::addColumn<QList<QAbstractSeries*> >("series"); |
|
438 | 353 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); |
|
439 | 354 | QTest::addColumn<QAbstractSeries*>("detachSeries"); |
|
440 | 355 | QTest::addColumn<QAbstractAxis*>("detachAxis"); |
|
441 | 356 | QTest::addColumn<bool>("success"); |
|
442 | 357 | |
|
358 | { | |
|
443 | 359 | QList<QAbstractSeries*> series; |
|
444 | 360 | QList<QAbstractAxis*> axes; |
|
445 | ||
|
446 | 361 | QAbstractSeries* line = new QLineSeries(this); |
|
447 | 362 | QAbstractAxis* value = new QValueAxis(this); |
|
448 | ||
|
449 | 363 | series << line; |
|
450 | 364 | axes << value; |
|
451 |
QTest::newRow(" |
|
|
365 | QTest::newRow("first") << series << axes << line << value << true; | |
|
366 | } | |
|
452 | 367 | } |
|
453 | 368 | |
|
454 | 369 | void tst_ChartDataSet::detachAxis() |
|
455 | 370 | { |
|
456 | 371 | QFETCH(QList<QAbstractSeries*>, series); |
|
457 | 372 | QFETCH(QList<QAbstractAxis*>, axis); |
|
458 | 373 | QFETCH(QAbstractSeries*, detachSeries); |
|
459 | 374 | QFETCH(QAbstractAxis*, detachAxis); |
|
460 | 375 | QFETCH(bool, success); |
|
461 | 376 | |
|
462 | 377 | Q_ASSERT(series.count() == axis.count()); |
|
463 | 378 | |
|
464 | 379 | QVERIFY(m_dataset->series().isEmpty()); |
|
465 | 380 | QVERIFY(m_dataset->axes().isEmpty()); |
|
466 | 381 | |
|
467 | 382 | for(int i = 0; i < series.count(); i++) { |
|
468 | 383 | if(series[i]) m_dataset->addSeries(series[i]); |
|
469 | 384 | if(axis[i]) m_dataset->addAxis(axis[i],Qt::AlignBottom); |
|
470 | 385 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); |
|
471 | 386 | } |
|
472 | 387 | |
|
473 | 388 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
474 | 389 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
475 | 390 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
476 | 391 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
477 | 392 | |
|
478 | 393 | QCOMPARE(m_dataset->detachAxis(detachSeries,detachAxis),success); |
|
479 | 394 | } |
|
480 | 395 | |
|
481 | 396 | QTEST_MAIN(tst_ChartDataSet) |
|
482 | 397 | #include "tst_chartdataset.moc" |
|
483 | 398 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now