@@ -1,627 +1,628 | |||
|
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 | |
|
24 | 24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 25 | |
|
26 | 26 | /*! |
|
27 | 27 | \class QAbstractAxis |
|
28 | 28 | \brief The QAbstractAxis class is used for manipulating chart's axis. |
|
29 | 29 | \mainclass |
|
30 | 30 | |
|
31 | 31 | There is only one x Axis visible at the time, however there can be multiple y axes. |
|
32 | 32 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
33 | 33 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
34 | 34 | */ |
|
35 | 35 | |
|
36 | 36 | /*! |
|
37 | 37 | \qmlclass AbstractAxis QAbstractAxis |
|
38 | 38 | \brief The Axis element is used for manipulating chart's axes |
|
39 | 39 | |
|
40 | 40 | There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView. |
|
41 | 41 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
42 | 42 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
43 | 43 | |
|
44 | 44 | To access Axes you can use ChartView API. For example: |
|
45 | 45 | \code |
|
46 | 46 | ChartView { |
|
47 | 47 | axisX.min: 0 |
|
48 | 48 | axisX.max: 3 |
|
49 | 49 | axisX.ticksCount: 4 |
|
50 | 50 | axisY.min: 0 |
|
51 | 51 | axisY.max: 4 |
|
52 | 52 | // Add a few series... |
|
53 | 53 | } |
|
54 | 54 | \endcode |
|
55 | 55 | */ |
|
56 | 56 | |
|
57 | 57 | /*! |
|
58 | 58 | \enum QAbstractAxis::AxisType |
|
59 | 59 | |
|
60 | 60 | The type of the series object. |
|
61 | 61 | |
|
62 | 62 | \value AxisTypeNoAxis |
|
63 | 63 | \value AxisTypeValues |
|
64 | 64 | \value AxisTypeCategories |
|
65 | 65 | */ |
|
66 | 66 | |
|
67 | 67 | /*! |
|
68 | 68 | *\fn void QAbstractAxis::type() const |
|
69 | 69 | Returns the type of the axis |
|
70 | 70 | */ |
|
71 | 71 | |
|
72 | 72 | /*! |
|
73 | 73 | \property QAbstractAxis::arrowVisible |
|
74 | 74 | The visibility of the axis arrow |
|
75 | 75 | */ |
|
76 | 76 | /*! |
|
77 | 77 | \qmlproperty bool AbstractAxis::arrrowVisible |
|
78 | 78 | The visibility of the axis arrow |
|
79 | 79 | */ |
|
80 | 80 | |
|
81 | 81 | /*! |
|
82 | 82 | \property QAbstractAxis::labelsVisible |
|
83 | 83 | Defines if axis labels are visible. |
|
84 | 84 | */ |
|
85 | 85 | /*! |
|
86 | 86 | \qmlproperty bool AbstractAxis::labelsVisible |
|
87 | 87 | Defines if axis labels are visible. |
|
88 | 88 | */ |
|
89 | 89 | |
|
90 | 90 | /*! |
|
91 | 91 | \property QAbstractAxis::visible |
|
92 | 92 | The visibility of the axis. |
|
93 | 93 | */ |
|
94 | 94 | /*! |
|
95 | 95 | \qmlproperty bool AbstractAxis::visible |
|
96 | 96 | The visibility of the axis. |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \property QAbstractAxis::gridVisible |
|
101 | 101 | The visibility of the grid lines. |
|
102 | 102 | */ |
|
103 | 103 | /*! |
|
104 | 104 | \qmlproperty bool AbstractAxis::gridVisible |
|
105 | 105 | The visibility of the grid lines. |
|
106 | 106 | */ |
|
107 | 107 | |
|
108 | 108 | /*! |
|
109 | 109 | \property QAbstractAxis::color |
|
110 | 110 | The color of the axis and ticks. |
|
111 | 111 | */ |
|
112 | 112 | /*! |
|
113 | 113 | \qmlproperty color AbstractAxis::color |
|
114 | 114 | The color of the axis and ticks. |
|
115 | 115 | */ |
|
116 | 116 | |
|
117 | 117 | /*! |
|
118 | 118 | \property QAbstractAxis::labelsFont |
|
119 | 119 | The font of the axis labels. |
|
120 | 120 | */ |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | \qmlproperty Font AbstractAxis::labelsFont |
|
124 | 124 | The font of the axis labels. |
|
125 | 125 | |
|
126 | 126 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
127 | 127 | */ |
|
128 | 128 | |
|
129 | 129 | /*! |
|
130 | 130 | \property QAbstractAxis::labelsColor |
|
131 | 131 | The color of the axis labels. |
|
132 | 132 | */ |
|
133 | 133 | /*! |
|
134 | 134 | \qmlproperty color AbstractAxis::labelsColor |
|
135 | 135 | The color of the axis labels. |
|
136 | 136 | */ |
|
137 | 137 | |
|
138 | 138 | /*! |
|
139 | 139 | \property QAbstractAxis::labelsAngle |
|
140 | 140 | The angle of the axis labels in degrees. |
|
141 | 141 | */ |
|
142 | 142 | /*! |
|
143 | 143 | \qmlproperty int AbstractAxis::labelsAngle |
|
144 | 144 | The angle of the axis labels in degrees. |
|
145 | 145 | */ |
|
146 | 146 | |
|
147 | 147 | /*! |
|
148 | 148 | \property QAbstractAxis::shadesVisible |
|
149 | 149 | The visibility of the axis shades. |
|
150 | 150 | */ |
|
151 | 151 | /*! |
|
152 | 152 | \qmlproperty bool AbstractAxis::shadesVisible |
|
153 | 153 | The visibility of the axis shades. |
|
154 | 154 | */ |
|
155 | 155 | |
|
156 | 156 | /*! |
|
157 | 157 | \property QAbstractAxis::shadesColor |
|
158 | 158 | The fill (brush) color of the axis shades. |
|
159 | 159 | */ |
|
160 | 160 | /*! |
|
161 | 161 | \qmlproperty color AbstractAxis::shadesColor |
|
162 | 162 | The fill (brush) color of the axis shades. |
|
163 | 163 | */ |
|
164 | 164 | |
|
165 | 165 | /*! |
|
166 | 166 | \property QAbstractAxis::shadesBorderColor |
|
167 | 167 | The border (pen) color of the axis shades. |
|
168 | 168 | */ |
|
169 | 169 | /*! |
|
170 | 170 | \qmlproperty color AbstractAxis::shadesBorderColor |
|
171 | 171 | The border (pen) color of the axis shades. |
|
172 | 172 | */ |
|
173 | 173 | |
|
174 | 174 | /*! |
|
175 | 175 | \fn void QAbstractAxis::visibleChanged(bool visible) |
|
176 | 176 | Visiblity of the axis has changed to \a visible. |
|
177 | 177 | */ |
|
178 | 178 | /*! |
|
179 | 179 | \qmlsignal AbstractAxis::onVisibleChanged(bool visible) |
|
180 | 180 | Visiblity of the axis has changed to \a visible. |
|
181 | 181 | */ |
|
182 | 182 | |
|
183 | 183 | /*! |
|
184 | 184 | \fn void QAbstractAxis::arrowVisibleChanged(bool visible) |
|
185 | 185 | Visiblity of the axis arrow has changed to \a visible. |
|
186 | 186 | */ |
|
187 | 187 | /*! |
|
188 | 188 | \qmlsignal AbstractAxis::onArrowVisibleChanged(bool visible) |
|
189 | 189 | Visiblity of the axis arrow has changed to \a visible. |
|
190 | 190 | */ |
|
191 | 191 | |
|
192 | 192 | /*! |
|
193 | 193 | \fn void QAbstractAxis::labelsVisibleChanged(bool visible) |
|
194 | 194 | Visiblity of the labels of the axis has changed to \a visible. |
|
195 | 195 | */ |
|
196 | 196 | /*! |
|
197 | 197 | \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible) |
|
198 | 198 | Visiblity of the labels of the axis has changed to \a visible. |
|
199 | 199 | */ |
|
200 | 200 | |
|
201 | 201 | /*! |
|
202 | 202 | \fn void QAbstractAxis::gridVisibleChanged(bool visible) |
|
203 | 203 | Visiblity of the grid lines of the axis has changed to \a visible. |
|
204 | 204 | */ |
|
205 | 205 | /*! |
|
206 | 206 | \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible) |
|
207 | 207 | Visiblity of the grid lines of the axis has changed to \a visible. |
|
208 | 208 | */ |
|
209 | 209 | |
|
210 | 210 | /*! |
|
211 | 211 | \fn void QAbstractAxis::colorChanged(QColor color) |
|
212 | 212 | Emitted if the \a color of the axis is changed. |
|
213 | 213 | */ |
|
214 | 214 | /*! |
|
215 | 215 | \qmlsignal AbstractAxis::onColorChanged(QColor color) |
|
216 | 216 | Emitted if the \a color of the axis is changed. |
|
217 | 217 | */ |
|
218 | 218 | |
|
219 | 219 | /*! |
|
220 | 220 | \fn void QAbstractAxis::labelsColorChanged(QColor color) |
|
221 | 221 | Emitted if the \a color of the axis labels is changed. |
|
222 | 222 | */ |
|
223 | 223 | /*! |
|
224 | 224 | \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color) |
|
225 | 225 | Emitted if the \a color of the axis labels is changed. |
|
226 | 226 | */ |
|
227 | 227 | |
|
228 | 228 | /*! |
|
229 | 229 | \fn void QAbstractAxis::shadesVisibleChanged(bool) |
|
230 | 230 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
231 | 231 | */ |
|
232 | 232 | /*! |
|
233 | 233 | \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible) |
|
234 | 234 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
235 | 235 | */ |
|
236 | 236 | |
|
237 | 237 | /*! |
|
238 | 238 | \fn void QAbstractAxis::shadesColorChanged(QColor color) |
|
239 | 239 | Emitted if the \a color of the axis shades is changed. |
|
240 | 240 | */ |
|
241 | 241 | /*! |
|
242 | 242 | \qmlsignal AbstractAxis::onShadesColorChanged(QColor color) |
|
243 | 243 | Emitted if the \a color of the axis shades is changed. |
|
244 | 244 | */ |
|
245 | 245 | |
|
246 | 246 | /*! |
|
247 | 247 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) |
|
248 | 248 | Emitted if the border \a color of the axis shades is changed. |
|
249 | 249 | */ |
|
250 | 250 | /*! |
|
251 | 251 | \qmlsignal AbstractAxis::onBorderColorChanged(QColor color) |
|
252 | 252 | Emitted if the border \a color of the axis shades is changed. |
|
253 | 253 | */ |
|
254 | 254 | |
|
255 | 255 | /*! |
|
256 | \internal | |
|
256 | 257 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
257 | 258 | QChart when axis added. |
|
258 | 259 | */ |
|
259 | 260 | |
|
260 | 261 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) : |
|
261 | 262 | QObject(parent), |
|
262 | 263 | d_ptr(&d) |
|
263 | 264 | { |
|
264 | 265 | } |
|
265 | 266 | |
|
266 | 267 | /*! |
|
267 | 268 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
268 | 269 | */ |
|
269 | 270 | |
|
270 | 271 | QAbstractAxis::~QAbstractAxis() |
|
271 | 272 | { |
|
272 | 273 | } |
|
273 | 274 | |
|
274 | 275 | /*! |
|
275 | 276 | Sets \a pen used to draw axis line and ticks. |
|
276 | 277 | */ |
|
277 | 278 | void QAbstractAxis::setAxisPen(const QPen &pen) |
|
278 | 279 | { |
|
279 | 280 | if (d_ptr->m_axisPen!=pen) { |
|
280 | 281 | d_ptr->m_axisPen = pen; |
|
281 | 282 | emit d_ptr->updated(); |
|
282 | 283 | } |
|
283 | 284 | } |
|
284 | 285 | |
|
285 | 286 | /*! |
|
286 | 287 | Returns pen used to draw axis and ticks. |
|
287 | 288 | */ |
|
288 | 289 | QPen QAbstractAxis::axisPen() const |
|
289 | 290 | { |
|
290 | 291 | return d_ptr->m_axisPen; |
|
291 | 292 | } |
|
292 | 293 | |
|
293 | 294 | void QAbstractAxis::setAxisPenColor(QColor color) |
|
294 | 295 | { |
|
295 | 296 | QPen p = d_ptr->m_axisPen; |
|
296 | 297 | if (p.color() != color) { |
|
297 | 298 | p.setColor(color); |
|
298 | 299 | setAxisPen(p); |
|
299 | 300 | emit colorChanged(color); |
|
300 | 301 | } |
|
301 | 302 | } |
|
302 | 303 | |
|
303 | 304 | QColor QAbstractAxis::axisPenColor() const |
|
304 | 305 | { |
|
305 | 306 | return d_ptr->m_axisPen.color(); |
|
306 | 307 | } |
|
307 | 308 | |
|
308 | 309 | /*! |
|
309 | 310 | Sets if axis and ticks are \a visible. |
|
310 | 311 | */ |
|
311 | 312 | void QAbstractAxis::setArrowVisible(bool visible) |
|
312 | 313 | { |
|
313 | 314 | if (d_ptr->m_arrowVisible != visible) { |
|
314 | 315 | d_ptr->m_arrowVisible = visible; |
|
315 | 316 | emit d_ptr->updated(); |
|
316 | 317 | emit arrowVisibleChanged(visible); |
|
317 | 318 | } |
|
318 | 319 | } |
|
319 | 320 | |
|
320 | 321 | bool QAbstractAxis::isArrowVisible() const |
|
321 | 322 | { |
|
322 | 323 | return d_ptr->m_arrowVisible; |
|
323 | 324 | } |
|
324 | 325 | |
|
325 | 326 | void QAbstractAxis::setGridLineVisible(bool visible) |
|
326 | 327 | { |
|
327 | 328 | if (d_ptr->m_gridLineVisible != visible) { |
|
328 | 329 | d_ptr->m_gridLineVisible = visible; |
|
329 | 330 | emit d_ptr->updated(); |
|
330 | 331 | emit gridVisibleChanged(visible); |
|
331 | 332 | } |
|
332 | 333 | } |
|
333 | 334 | |
|
334 | 335 | bool QAbstractAxis::isGridLineVisible() const |
|
335 | 336 | { |
|
336 | 337 | return d_ptr->m_gridLineVisible; |
|
337 | 338 | } |
|
338 | 339 | |
|
339 | 340 | /*! |
|
340 | 341 | Sets \a pen used to draw grid line. |
|
341 | 342 | */ |
|
342 | 343 | void QAbstractAxis::setGridLinePen(const QPen &pen) |
|
343 | 344 | { |
|
344 | 345 | if (d_ptr->m_gridLinePen != pen) { |
|
345 | 346 | d_ptr->m_gridLinePen = pen; |
|
346 | 347 | emit d_ptr->updated(); |
|
347 | 348 | } |
|
348 | 349 | } |
|
349 | 350 | |
|
350 | 351 | /*! |
|
351 | 352 | Returns pen used to draw grid. |
|
352 | 353 | */ |
|
353 | 354 | QPen QAbstractAxis::gridLinePen() const |
|
354 | 355 | { |
|
355 | 356 | return d_ptr->m_gridLinePen; |
|
356 | 357 | } |
|
357 | 358 | |
|
358 | 359 | void QAbstractAxis::setLabelsVisible(bool visible) |
|
359 | 360 | { |
|
360 | 361 | if (d_ptr->m_labelsVisible != visible) { |
|
361 | 362 | d_ptr->m_labelsVisible = visible; |
|
362 | 363 | emit d_ptr->updated(); |
|
363 | 364 | emit labelsVisibleChanged(visible); |
|
364 | 365 | } |
|
365 | 366 | } |
|
366 | 367 | |
|
367 | 368 | bool QAbstractAxis::labelsVisible() const |
|
368 | 369 | { |
|
369 | 370 | return d_ptr->m_labelsVisible; |
|
370 | 371 | } |
|
371 | 372 | |
|
372 | 373 | /*! |
|
373 | 374 | Sets \a pen used to draw labels. |
|
374 | 375 | */ |
|
375 | 376 | void QAbstractAxis::setLabelsPen(const QPen &pen) |
|
376 | 377 | { |
|
377 | 378 | if (d_ptr->m_labelsPen != pen) { |
|
378 | 379 | d_ptr->m_labelsPen = pen; |
|
379 | 380 | emit d_ptr->updated(); |
|
380 | 381 | } |
|
381 | 382 | } |
|
382 | 383 | |
|
383 | 384 | /*! |
|
384 | 385 | Returns the pen used to labels. |
|
385 | 386 | */ |
|
386 | 387 | QPen QAbstractAxis::labelsPen() const |
|
387 | 388 | { |
|
388 | 389 | return d_ptr->m_labelsPen; |
|
389 | 390 | } |
|
390 | 391 | |
|
391 | 392 | /*! |
|
392 | 393 | Sets \a brush used to draw labels. |
|
393 | 394 | */ |
|
394 | 395 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) |
|
395 | 396 | { |
|
396 | 397 | if (d_ptr->m_labelsBrush != brush) { |
|
397 | 398 | d_ptr->m_labelsBrush = brush; |
|
398 | 399 | emit d_ptr->updated(); |
|
399 | 400 | } |
|
400 | 401 | } |
|
401 | 402 | |
|
402 | 403 | /*! |
|
403 | 404 | Returns brush used to draw labels. |
|
404 | 405 | */ |
|
405 | 406 | QBrush QAbstractAxis::labelsBrush() const |
|
406 | 407 | { |
|
407 | 408 | return d_ptr->m_labelsBrush; |
|
408 | 409 | } |
|
409 | 410 | |
|
410 | 411 | /*! |
|
411 | 412 | Sets \a font used to draw labels. |
|
412 | 413 | */ |
|
413 | 414 | void QAbstractAxis::setLabelsFont(const QFont &font) |
|
414 | 415 | { |
|
415 | 416 | if (d_ptr->m_labelsFont != font) { |
|
416 | 417 | d_ptr->m_labelsFont = font; |
|
417 | 418 | emit d_ptr->updated(); |
|
418 | 419 | } |
|
419 | 420 | } |
|
420 | 421 | |
|
421 | 422 | /*! |
|
422 | 423 | Returns font used to draw labels. |
|
423 | 424 | */ |
|
424 | 425 | QFont QAbstractAxis::labelsFont() const |
|
425 | 426 | { |
|
426 | 427 | return d_ptr->m_labelsFont; |
|
427 | 428 | } |
|
428 | 429 | |
|
429 | 430 | void QAbstractAxis::setLabelsAngle(int angle) |
|
430 | 431 | { |
|
431 | 432 | if (d_ptr->m_labelsAngle != angle) { |
|
432 | 433 | d_ptr->m_labelsAngle = angle; |
|
433 | 434 | emit d_ptr->updated(); |
|
434 | 435 | } |
|
435 | 436 | } |
|
436 | 437 | |
|
437 | 438 | int QAbstractAxis::labelsAngle() const |
|
438 | 439 | { |
|
439 | 440 | return d_ptr->m_labelsAngle; |
|
440 | 441 | } |
|
441 | 442 | |
|
442 | 443 | void QAbstractAxis::setLabelsColor(QColor color) |
|
443 | 444 | { |
|
444 | 445 | QBrush b = d_ptr->m_labelsBrush; |
|
445 | 446 | if (b.color() != color) { |
|
446 | 447 | b.setColor(color); |
|
447 | 448 | setLabelsBrush(b); |
|
448 | 449 | emit labelsColorChanged(color); |
|
449 | 450 | } |
|
450 | 451 | } |
|
451 | 452 | |
|
452 | 453 | QColor QAbstractAxis::labelsColor() const |
|
453 | 454 | { |
|
454 | 455 | return d_ptr->m_labelsBrush.color(); |
|
455 | 456 | } |
|
456 | 457 | |
|
457 | 458 | void QAbstractAxis::setShadesVisible(bool visible) |
|
458 | 459 | { |
|
459 | 460 | if (d_ptr->m_shadesVisible != visible) { |
|
460 | 461 | d_ptr->m_shadesVisible = visible; |
|
461 | 462 | emit d_ptr->updated(); |
|
462 | 463 | emit shadesVisibleChanged(visible); |
|
463 | 464 | } |
|
464 | 465 | } |
|
465 | 466 | |
|
466 | 467 | bool QAbstractAxis::shadesVisible() const |
|
467 | 468 | { |
|
468 | 469 | return d_ptr->m_shadesVisible; |
|
469 | 470 | } |
|
470 | 471 | |
|
471 | 472 | /*! |
|
472 | 473 | Sets \a pen used to draw shades. |
|
473 | 474 | */ |
|
474 | 475 | void QAbstractAxis::setShadesPen(const QPen &pen) |
|
475 | 476 | { |
|
476 | 477 | if (d_ptr->m_shadesPen != pen) { |
|
477 | 478 | d_ptr->m_shadesPen = pen; |
|
478 | 479 | emit d_ptr->updated(); |
|
479 | 480 | } |
|
480 | 481 | } |
|
481 | 482 | |
|
482 | 483 | /*! |
|
483 | 484 | Returns pen used to draw shades. |
|
484 | 485 | */ |
|
485 | 486 | QPen QAbstractAxis::shadesPen() const |
|
486 | 487 | { |
|
487 | 488 | return d_ptr->m_shadesPen; |
|
488 | 489 | } |
|
489 | 490 | |
|
490 | 491 | /*! |
|
491 | 492 | Sets \a brush used to draw shades. |
|
492 | 493 | */ |
|
493 | 494 | void QAbstractAxis::setShadesBrush(const QBrush &brush) |
|
494 | 495 | { |
|
495 | 496 | if (d_ptr->m_shadesBrush != brush) { |
|
496 | 497 | d_ptr->m_shadesBrush = brush; |
|
497 | 498 | emit d_ptr->updated(); |
|
498 | 499 | emit shadesColorChanged(brush.color()); |
|
499 | 500 | } |
|
500 | 501 | } |
|
501 | 502 | |
|
502 | 503 | /*! |
|
503 | 504 | Returns brush used to draw shades. |
|
504 | 505 | */ |
|
505 | 506 | QBrush QAbstractAxis::shadesBrush() const |
|
506 | 507 | { |
|
507 | 508 | return d_ptr->m_shadesBrush; |
|
508 | 509 | } |
|
509 | 510 | |
|
510 | 511 | void QAbstractAxis::setShadesColor(QColor color) |
|
511 | 512 | { |
|
512 | 513 | QBrush b = d_ptr->m_shadesBrush; |
|
513 | 514 | b.setColor(color); |
|
514 | 515 | setShadesBrush(b); |
|
515 | 516 | } |
|
516 | 517 | |
|
517 | 518 | QColor QAbstractAxis::shadesColor() const |
|
518 | 519 | { |
|
519 | 520 | return d_ptr->m_shadesBrush.color(); |
|
520 | 521 | } |
|
521 | 522 | |
|
522 | 523 | void QAbstractAxis::setShadesBorderColor(QColor color) |
|
523 | 524 | { |
|
524 | 525 | QPen p = d_ptr->m_shadesPen; |
|
525 | 526 | p.setColor(color); |
|
526 | 527 | setShadesPen(p); |
|
527 | 528 | } |
|
528 | 529 | |
|
529 | 530 | QColor QAbstractAxis::shadesBorderColor() const |
|
530 | 531 | { |
|
531 | 532 | return d_ptr->m_shadesPen.color(); |
|
532 | 533 | } |
|
533 | 534 | |
|
534 | 535 | |
|
535 | 536 | bool QAbstractAxis::isVisible() const |
|
536 | 537 | { |
|
537 | 538 | return d_ptr->m_visible; |
|
538 | 539 | } |
|
539 | 540 | |
|
540 | 541 | /*! |
|
541 | 542 | Sets axis, shades, labels and grid lines to be visible. |
|
542 | 543 | */ |
|
543 | 544 | void QAbstractAxis::setVisible(bool visible) |
|
544 | 545 | { |
|
545 | 546 | if(d_ptr->m_visible!=visible){ |
|
546 | 547 | d_ptr->m_visible=visible; |
|
547 | 548 | emit visibleChanged(visible); |
|
548 | 549 | emit d_ptr->updated(); |
|
549 | 550 | } |
|
550 | 551 | } |
|
551 | 552 | |
|
552 | 553 | |
|
553 | 554 | /*! |
|
554 | 555 | Sets axis, shades, labels and grid lines to be visible. |
|
555 | 556 | */ |
|
556 | 557 | void QAbstractAxis::show() |
|
557 | 558 | { |
|
558 | 559 | setVisible(true); |
|
559 | 560 | } |
|
560 | 561 | |
|
561 | 562 | /*! |
|
562 | 563 | Sets axis, shades, labels and grid lines to not be visible. |
|
563 | 564 | */ |
|
564 | 565 | void QAbstractAxis::hide() |
|
565 | 566 | { |
|
566 | 567 | setVisible(false); |
|
567 | 568 | } |
|
568 | 569 | |
|
569 | 570 | /*! |
|
570 | 571 | Sets the minimum value shown on the axis. |
|
571 | 572 | Depending on the actual axis type the \a min paramter is converted to appropriate type. |
|
572 | 573 | If the conversion is impossible then the function call does nothing |
|
573 | 574 | */ |
|
574 | 575 | void QAbstractAxis::setMin(const QVariant &min) |
|
575 | 576 | { |
|
576 | 577 | d_ptr->setMin(min); |
|
577 | 578 | } |
|
578 | 579 | |
|
579 | 580 | /*! |
|
580 | 581 | Sets the maximum value shown on the axis. |
|
581 | 582 | Depending on the actual axis type the \a max paramter is converted to appropriate type. |
|
582 | 583 | If the conversion is impossible then the function call does nothing |
|
583 | 584 | */ |
|
584 | 585 | void QAbstractAxis::setMax(const QVariant &max) |
|
585 | 586 | { |
|
586 | 587 | d_ptr->setMax(max); |
|
587 | 588 | } |
|
588 | 589 | |
|
589 | 590 | /*! |
|
590 | 591 | Sets the range shown on the axis. |
|
591 | 592 | Depending on the actual axis type the \a min and \a max paramters are converted to appropriate types. |
|
592 | 593 | If the conversion is impossible then the function call does nothing. |
|
593 | 594 | */ |
|
594 | 595 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) |
|
595 | 596 | { |
|
596 | 597 | d_ptr->setRange(min,max); |
|
597 | 598 | } |
|
598 | 599 | |
|
599 | 600 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
600 | 601 | |
|
601 | 602 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q): |
|
602 | 603 | q_ptr(q), |
|
603 | 604 | m_visible(false), |
|
604 | 605 | m_arrowVisible(true), |
|
605 | 606 | m_gridLineVisible(true), |
|
606 | 607 | m_labelsVisible(true), |
|
607 | 608 | m_labelsAngle(0), |
|
608 | 609 | m_shadesVisible(false), |
|
609 | 610 | m_shadesBrush(Qt::SolidPattern), |
|
610 | 611 | m_shadesOpacity(1.0), |
|
611 | 612 | m_orientation(Qt::Orientation(0)), |
|
612 | 613 | m_min(0), |
|
613 | 614 | m_max(0), |
|
614 | 615 | m_ticksCount(5) |
|
615 | 616 | { |
|
616 | 617 | |
|
617 | 618 | } |
|
618 | 619 | |
|
619 | 620 | QAbstractAxisPrivate::~QAbstractAxisPrivate() |
|
620 | 621 | { |
|
621 | 622 | |
|
622 | 623 | } |
|
623 | 624 | |
|
624 | 625 | #include "moc_qabstractaxis.cpp" |
|
625 | 626 | #include "moc_qabstractaxis_p.cpp" |
|
626 | 627 | |
|
627 | 628 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,389 +1,394 | |||
|
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 "qbarcategoriesaxis.h" |
|
22 | 22 | #include "qbarcategoriesaxis_p.h" |
|
23 | 23 | #include "chartcategoriesaxisx_p.h" |
|
24 | 24 | #include "chartcategoriesaxisy_p.h" |
|
25 | 25 | #include <qmath.h> |
|
26 | 26 | #include <QDebug> |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | /*! |
|
30 | 30 | \class QBarCategoriesAxis |
|
31 | 31 | \brief The QBarCategoriesAxis class is used for manipulating chart's axis. |
|
32 | 32 | \mainclass |
|
33 | 33 | |
|
34 | 34 | BarCategoriesAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
35 | 35 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
36 | 36 | See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that. |
|
37 | 37 | */ |
|
38 | 38 | |
|
39 | 39 | /*! |
|
40 | 40 | \qmlclass BarCategoriesAxis QBarCategoriesAxis |
|
41 | 41 | \brief The Axis element is used for manipulating chart's axes. |
|
42 | 42 | |
|
43 | 43 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
44 | 44 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
45 | 45 | |
|
46 | 46 | To access BarCategoriesAxis you can use ChartView API. For example: |
|
47 | 47 | \code |
|
48 | 48 | ChartView { |
|
49 | 49 | BarCategoriesAxis { |
|
50 | 50 | id: categoryAxis |
|
51 | 51 | categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] |
|
52 | 52 | } |
|
53 | 53 | // Add a few series... |
|
54 | 54 | } |
|
55 | 55 | \endcode |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | \property QBarCategoriesAxis::categories |
|
60 | 60 | Defines the categories of axis |
|
61 | 61 | */ |
|
62 | 62 | /*! |
|
63 | 63 | \qmlproperty QStringList BarCategoriesAxis::categories |
|
64 | 64 | Defines the categories of axis |
|
65 | 65 | */ |
|
66 | 66 | |
|
67 | 67 | /*! |
|
68 | 68 | \property QBarCategoriesAxis::min |
|
69 | 69 | Defines the minimum value on the axis. |
|
70 | 70 | */ |
|
71 | 71 | /*! |
|
72 | 72 | \qmlproperty QString BarCategoriesAxis::min |
|
73 | 73 | Defines the minimum value on the axis. |
|
74 | 74 | */ |
|
75 | 75 | |
|
76 | 76 | /*! |
|
77 | 77 | \property QBarCategoriesAxis::max |
|
78 | 78 | Defines the maximum value on the axis. |
|
79 | 79 | */ |
|
80 | 80 | /*! |
|
81 | 81 | \qmlproperty QString BarCategoriesAxis::max |
|
82 | 82 | Defines the maximum value on the axis. |
|
83 | 83 | */ |
|
84 | 84 | |
|
85 | ||
|
86 | /*! | |
|
87 | \fn void QBarCategoriesAxis::categoriesChanged() | |
|
88 | Axis emits signal when the categories of the axis has changed. | |
|
89 | */ | |
|
85 | 90 | /*! |
|
86 | 91 | \fn void QBarCategoriesAxis::minChanged(const QString &min) |
|
87 | 92 | Axis emits signal when \a min of axis has changed. |
|
88 | 93 | */ |
|
89 | 94 | /*! |
|
90 | 95 | \qmlsignal BarCategoriesAxis::onMinChanged(const QString &min) |
|
91 | 96 | Axis emits signal when \a min of axis has changed. |
|
92 | 97 | */ |
|
93 | 98 | |
|
94 | 99 | /*! |
|
95 | 100 | \fn void QBarCategoriesAxis::maxChanged(const QString &max) |
|
96 | 101 | Axis emits signal when \a max of axis has changed. |
|
97 | 102 | */ |
|
98 | 103 | /*! |
|
99 | 104 | \qmlsignal BarCategoriesAxis::onMaxChanged(const QString &max) |
|
100 | 105 | Axis emits signal when \a max of axis has changed. |
|
101 | 106 | */ |
|
102 | 107 | |
|
103 | 108 | /*! |
|
104 | 109 | \fn void QBarCategoriesAxis::rangeChanged(const QString &min, const QString &max) |
|
105 | 110 | Axis emits signal when \a min or \a max of axis has changed. |
|
106 | 111 | */ |
|
107 | 112 | |
|
108 | 113 | /*! |
|
109 | 114 | Constructs an axis object which is a child of \a parent. |
|
110 | 115 | */ |
|
111 | 116 | QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent): |
|
112 | 117 | QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent) |
|
113 | 118 | { |
|
114 | 119 | } |
|
115 | 120 | |
|
116 | 121 | /*! |
|
117 | 122 | Destroys the object |
|
118 | 123 | */ |
|
119 | 124 | QBarCategoriesAxis::~QBarCategoriesAxis() |
|
120 | 125 | { |
|
121 | 126 | } |
|
122 | 127 | |
|
123 | 128 | /*! |
|
124 | 129 | \internal |
|
125 | 130 | */ |
|
126 | 131 | QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) |
|
127 | 132 | { |
|
128 | 133 | |
|
129 | 134 | } |
|
130 | 135 | |
|
131 | 136 | /*! |
|
132 | 137 | Appends \a categories to axis |
|
133 | 138 | */ |
|
134 | 139 | void QBarCategoriesAxis::append(const QStringList &categories) |
|
135 | 140 | { |
|
136 | 141 | if(categories.isEmpty()) return; |
|
137 | 142 | |
|
138 | 143 | Q_D(QBarCategoriesAxis); |
|
139 | 144 | if (d->m_categories.isEmpty()) { |
|
140 | 145 | d->m_categories.append(categories); |
|
141 | 146 | setRange(categories.first(),categories.last()); |
|
142 | 147 | }else{ |
|
143 | 148 | d->m_categories.append(categories); |
|
144 | 149 | } |
|
145 | 150 | emit d->updated(); |
|
146 | 151 | emit categoriesChanged(); |
|
147 | 152 | } |
|
148 | 153 | |
|
149 | 154 | /*! |
|
150 | 155 | Appends \a category to axis |
|
151 | 156 | */ |
|
152 | 157 | void QBarCategoriesAxis::append(const QString &category) |
|
153 | 158 | { |
|
154 | 159 | Q_D(QBarCategoriesAxis); |
|
155 | 160 | if (d->m_categories.isEmpty()) { |
|
156 | 161 | d->m_categories.append(category); |
|
157 | 162 | setRange(category,category); |
|
158 | 163 | }else{ |
|
159 | 164 | d->m_categories.append(category); |
|
160 | 165 | } |
|
161 | 166 | emit d->updated(); |
|
162 | 167 | emit categoriesChanged(); |
|
163 | 168 | } |
|
164 | 169 | |
|
165 | 170 | /*! |
|
166 | 171 | Removes \a category from axis |
|
167 | 172 | */ |
|
168 | 173 | void QBarCategoriesAxis::remove(const QString &category) |
|
169 | 174 | { |
|
170 | 175 | Q_D(QBarCategoriesAxis); |
|
171 | 176 | if (d->m_categories.contains(category)) { |
|
172 | 177 | d->m_categories.removeAt(d->m_categories.indexOf(category)); |
|
173 | 178 | setRange(d->m_categories.first(),d->m_categories.last()); |
|
174 | 179 | emit d->updated(); |
|
175 | 180 | emit categoriesChanged(); |
|
176 | 181 | } |
|
177 | 182 | } |
|
178 | 183 | |
|
179 | 184 | /*! |
|
180 | 185 | Inserts \a category to axis at \a index |
|
181 | 186 | */ |
|
182 | 187 | void QBarCategoriesAxis::insert(int index, const QString &category) |
|
183 | 188 | { |
|
184 | 189 | Q_D(QBarCategoriesAxis); |
|
185 | 190 | if (d->m_categories.isEmpty()) { |
|
186 | 191 | d->m_categories.insert(index,category); |
|
187 | 192 | setRange(category,category); |
|
188 | 193 | }else{ |
|
189 | 194 | d->m_categories.insert(index,category); |
|
190 | 195 | } |
|
191 | 196 | emit d->updated(); |
|
192 | 197 | emit categoriesChanged(); |
|
193 | 198 | } |
|
194 | 199 | |
|
195 | 200 | /*! |
|
196 | 201 | Removes all categories. |
|
197 | 202 | */ |
|
198 | 203 | void QBarCategoriesAxis::clear() |
|
199 | 204 | { |
|
200 | 205 | Q_D(QBarCategoriesAxis); |
|
201 | 206 | d->m_categories.clear(); |
|
202 | 207 | setRange(QString::null,QString::null); |
|
203 | 208 | emit d->updated(); |
|
204 | 209 | emit categoriesChanged(); |
|
205 | 210 | } |
|
206 | 211 | |
|
207 | 212 | void QBarCategoriesAxis::setCategories(const QStringList &categories) |
|
208 | 213 | { |
|
209 | 214 | Q_D(QBarCategoriesAxis); |
|
210 | 215 | if(d->m_categories!=categories){ |
|
211 | 216 | d->m_categories = categories; |
|
212 | 217 | setRange(categories.first(),categories.last()); |
|
213 | 218 | emit d->updated(); |
|
214 | 219 | emit categoriesChanged(); |
|
215 | 220 | } |
|
216 | 221 | } |
|
217 | 222 | |
|
218 | 223 | QStringList QBarCategoriesAxis::categories() |
|
219 | 224 | { |
|
220 | 225 | Q_D(QBarCategoriesAxis); |
|
221 | 226 | return d->m_categories; |
|
222 | 227 | } |
|
223 | 228 | |
|
224 | 229 | /*! |
|
225 | 230 | Returns number of categories. |
|
226 | 231 | */ |
|
227 | 232 | int QBarCategoriesAxis::count() const |
|
228 | 233 | { |
|
229 | 234 | Q_D(const QBarCategoriesAxis); |
|
230 | 235 | return d->m_categories.count(); |
|
231 | 236 | } |
|
232 | 237 | |
|
233 | 238 | /*! |
|
234 | 239 | Returns category at \a index. Index must be valid. |
|
235 | 240 | */ |
|
236 | 241 | QString QBarCategoriesAxis::at(int index) const |
|
237 | 242 | { |
|
238 | 243 | Q_D(const QBarCategoriesAxis); |
|
239 | 244 | return d->m_categories.at(index); |
|
240 | 245 | } |
|
241 | 246 | |
|
242 | 247 | /*! |
|
243 | 248 | Sets minimum category to \a min. |
|
244 | 249 | */ |
|
245 | 250 | void QBarCategoriesAxis::setMin(const QString& min) |
|
246 | 251 | { |
|
247 | 252 | Q_D(QBarCategoriesAxis); |
|
248 | 253 | setRange(min,d->m_maxCategory); |
|
249 | 254 | } |
|
250 | 255 | |
|
251 | 256 | /*! |
|
252 | 257 | Returns minimum category. |
|
253 | 258 | */ |
|
254 | 259 | QString QBarCategoriesAxis::min() const |
|
255 | 260 | { |
|
256 | 261 | Q_D(const QBarCategoriesAxis); |
|
257 | 262 | return d->m_minCategory; |
|
258 | 263 | } |
|
259 | 264 | |
|
260 | 265 | /*! |
|
261 | 266 | Sets maximum category to \a max. |
|
262 | 267 | */ |
|
263 | 268 | void QBarCategoriesAxis::setMax(const QString& max) |
|
264 | 269 | { |
|
265 | 270 | Q_D(QBarCategoriesAxis); |
|
266 | 271 | setRange(d->m_minCategory,max); |
|
267 | 272 | } |
|
268 | 273 | |
|
269 | 274 | /*! |
|
270 | 275 | Returns maximum category |
|
271 | 276 | */ |
|
272 | 277 | QString QBarCategoriesAxis::max() const |
|
273 | 278 | { |
|
274 | 279 | Q_D(const QBarCategoriesAxis); |
|
275 | 280 | return d->m_maxCategory; |
|
276 | 281 | } |
|
277 | 282 | |
|
278 | 283 | /*! |
|
279 | 284 | Sets range from \a minCategory to \a maxCategory |
|
280 | 285 | */ |
|
281 | 286 | void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory) |
|
282 | 287 | { |
|
283 | 288 | Q_D(QBarCategoriesAxis); |
|
284 | 289 | |
|
285 | 290 | int minIndex = d->m_categories.indexOf(minCategory); |
|
286 | 291 | if (minIndex == -1) { |
|
287 | 292 | return; |
|
288 | 293 | } |
|
289 | 294 | int maxIndex = d->m_categories.indexOf(maxCategory); |
|
290 | 295 | if (maxIndex == -1) { |
|
291 | 296 | return; |
|
292 | 297 | } |
|
293 | 298 | |
|
294 | 299 | if (maxIndex <= minIndex) { |
|
295 | 300 | // max must be greater than min |
|
296 | 301 | return; |
|
297 | 302 | } |
|
298 | 303 | |
|
299 | 304 | bool changed = false; |
|
300 | 305 | if (!qFuzzyIsNull(d->m_min - (minIndex))||d->m_minCategory!=minCategory) { |
|
301 | 306 | d->m_minCategory = minCategory; |
|
302 | 307 | d->m_min = minIndex; |
|
303 | 308 | emit minChanged(minCategory); |
|
304 | 309 | changed = true; |
|
305 | 310 | } |
|
306 | 311 | |
|
307 | 312 | if (!qFuzzyIsNull(d->m_max - (maxIndex))||d->m_maxCategory!=maxCategory ) { |
|
308 | 313 | d->m_max = maxIndex; |
|
309 | 314 | d->m_maxCategory = maxCategory; |
|
310 | 315 | emit maxChanged(maxCategory); |
|
311 | 316 | changed = true; |
|
312 | 317 | } |
|
313 | 318 | |
|
314 | 319 | if (changed) { |
|
315 | 320 | d->emitRange(); |
|
316 | 321 | } |
|
317 | 322 | } |
|
318 | 323 | |
|
319 | 324 | /*! |
|
320 | 325 | Returns the type of the axis |
|
321 | 326 | */ |
|
322 | 327 | QAbstractAxis::AxisType QBarCategoriesAxis::type() const |
|
323 | 328 | { |
|
324 | 329 | return AxisTypeCategories; |
|
325 | 330 | } |
|
326 | 331 | |
|
327 | 332 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
328 | 333 | |
|
329 | 334 | QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q): |
|
330 | 335 | QAbstractAxisPrivate(q) |
|
331 | 336 | { |
|
332 | 337 | |
|
333 | 338 | } |
|
334 | 339 | |
|
335 | 340 | QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate() |
|
336 | 341 | { |
|
337 | 342 | |
|
338 | 343 | } |
|
339 | 344 | |
|
340 | 345 | void QBarCategoriesAxisPrivate::setMin(const QVariant &min) |
|
341 | 346 | { |
|
342 | 347 | setRange(min,m_maxCategory); |
|
343 | 348 | } |
|
344 | 349 | |
|
345 | 350 | void QBarCategoriesAxisPrivate::setMax(const QVariant &max) |
|
346 | 351 | { |
|
347 | 352 | setRange(m_minCategory,max); |
|
348 | 353 | } |
|
349 | 354 | |
|
350 | 355 | void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
351 | 356 | { |
|
352 | 357 | Q_Q(QBarCategoriesAxis); |
|
353 | 358 | QString value1 = min.toString(); |
|
354 | 359 | QString value2 = max.toString(); |
|
355 | 360 | q->setRange(value1,value2); |
|
356 | 361 | } |
|
357 | 362 | |
|
358 | 363 | int QBarCategoriesAxisPrivate::ticksCount() const |
|
359 | 364 | { |
|
360 | 365 | return m_categories.count()+1; |
|
361 | 366 | } |
|
362 | 367 | |
|
363 | 368 | void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) |
|
364 | 369 | { |
|
365 | 370 | m_min = min; |
|
366 | 371 | m_max = max; |
|
367 | 372 | m_ticksCount = count; |
|
368 | 373 | } |
|
369 | 374 | |
|
370 | 375 | ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
371 | 376 | { |
|
372 | 377 | Q_Q( QBarCategoriesAxis); |
|
373 | 378 | if(m_orientation == Qt::Vertical){ |
|
374 | 379 | return new ChartCategoriesAxisY(q,presenter); |
|
375 | 380 | }else{ |
|
376 | 381 | return new ChartCategoriesAxisX(q,presenter); |
|
377 | 382 | } |
|
378 | 383 | } |
|
379 | 384 | |
|
380 | 385 | void QBarCategoriesAxisPrivate::emitRange() |
|
381 | 386 | { |
|
382 | 387 | emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false); |
|
383 | 388 | } |
|
384 | 389 | |
|
385 | 390 | |
|
386 | 391 | #include "moc_qbarcategoriesaxis.cpp" |
|
387 | 392 | #include "moc_qbarcategoriesaxis_p.cpp" |
|
388 | 393 | |
|
389 | 394 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,199 +1,199 | |||
|
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 "qabstractseries.h" |
|
22 | 22 | #include "qabstractseries_p.h" |
|
23 | 23 | #include "chartdataset_p.h" |
|
24 | 24 | |
|
25 | 25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | 26 | |
|
27 | 27 | /*! |
|
28 | 28 | \class QAbstractSeries |
|
29 | 29 | \brief Base class for all QtCommercial Chart series. |
|
30 | 30 | \mainclass |
|
31 | 31 | |
|
32 | 32 | Usually you use the series type specific inherited classes instead of the base class. |
|
33 | 33 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries, |
|
34 | 34 | QPercentBarSeries, QPieSeries |
|
35 | 35 | */ |
|
36 | 36 | /*! |
|
37 | 37 | \qmlclass AbstractSeries |
|
38 | 38 | AbstractSeries is the base class for all series. |
|
39 | 39 | The class cannot be instantiated by the user. |
|
40 | 40 | */ |
|
41 | 41 | |
|
42 | 42 | /*! |
|
43 | 43 | \enum QAbstractSeries::SeriesType |
|
44 | 44 | |
|
45 | 45 | The type of the series object. |
|
46 | 46 | |
|
47 | 47 | \value SeriesTypeLine |
|
48 | 48 | \value SeriesTypeArea |
|
49 | 49 | \value SeriesTypeBar |
|
50 | 50 | \value SeriesTypeStackedBar |
|
51 | 51 | \value SeriesTypePercentBar |
|
52 | 52 | \value SeriesTypePie |
|
53 | 53 | \value SeriesTypeScatter |
|
54 | 54 | \value SeriesTypeSpline |
|
55 | 55 | */ |
|
56 | 56 | |
|
57 | 57 | /*! |
|
58 | 58 | \property QAbstractSeries::type |
|
59 | 59 | The type of the series. |
|
60 | 60 | */ |
|
61 | 61 | /*! |
|
62 | 62 | \qmlproperty ChartView.SeriesType AbstractSeries::type |
|
63 | 63 | The type of the series. |
|
64 | 64 | */ |
|
65 | 65 | |
|
66 | 66 | /*! |
|
67 | 67 | \property QAbstractSeries::name |
|
68 | 68 | \brief name of the series property. The name is shown in legend for QXYSeries. |
|
69 | 69 | */ |
|
70 | 70 | /*! |
|
71 | 71 | \qmlproperty string AbstractSeries::name |
|
72 | 72 | Name of the series. The name is shown in legend for QXYSeries. |
|
73 | 73 | */ |
|
74 | 74 | |
|
75 | 75 | /*! |
|
76 | 76 | \fn void QAbstractSeries::nameChanged() |
|
77 | 77 | This signal is emitted when the series name changes. |
|
78 | 78 | */ |
|
79 | 79 | /*! |
|
80 | 80 | \qmlsignal AbstractSeries::nameChanged() |
|
81 | 81 | This signal is emitted when the series name changes. |
|
82 | 82 | */ |
|
83 | 83 | |
|
84 | 84 | /*! |
|
85 | 85 | \property QAbstractSeries::visible |
|
86 | 86 | \brief whether the series is visible or not; true by default. |
|
87 | 87 | */ |
|
88 | 88 | |
|
89 | 89 | /*! |
|
90 | 90 | \fn void QAbstractSeries::visibleChanged() |
|
91 | 91 | Emitted when the series visibility changes. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \internal |
|
96 | 96 | \brief Constructs ChartSeries object with \a parent. |
|
97 | 97 | */ |
|
98 | 98 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : |
|
99 | 99 | QObject(parent), |
|
100 | 100 | d_ptr(&d) |
|
101 | 101 | { |
|
102 | 102 | } |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | \brief Virtual destructor for the chart series. |
|
106 | 106 | */ |
|
107 | 107 | QAbstractSeries::~QAbstractSeries() |
|
108 | 108 | { |
|
109 | 109 | if(d_ptr->m_dataset) qFatal("Still binded series detected !"); |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | 112 | void QAbstractSeries::setName(const QString& name) |
|
113 | 113 | { |
|
114 | 114 | if (name != d_ptr->m_name) { |
|
115 | 115 | d_ptr->m_name = name; |
|
116 | 116 | emit nameChanged(); |
|
117 | 117 | } |
|
118 | 118 | } |
|
119 | 119 | |
|
120 | 120 | QString QAbstractSeries::name() const |
|
121 | 121 | { |
|
122 | 122 | return d_ptr->m_name; |
|
123 | 123 | } |
|
124 | 124 | |
|
125 | 125 | /*! |
|
126 | 126 | Sets the visibility of series to \a visible |
|
127 | 127 | */ |
|
128 | 128 | void QAbstractSeries::setVisible(bool visible) |
|
129 | 129 | { |
|
130 | 130 | if (visible != d_ptr->m_visible) { |
|
131 | 131 | d_ptr->m_visible = visible; |
|
132 | 132 | emit visibleChanged(); |
|
133 | 133 | } |
|
134 | 134 | } |
|
135 | 135 | |
|
136 | 136 | /*! |
|
137 | 137 | Returns the visibility of series |
|
138 | 138 | */ |
|
139 | 139 | bool QAbstractSeries::isVisible() const |
|
140 | 140 | { |
|
141 | 141 | return d_ptr->m_visible; |
|
142 | 142 | } |
|
143 | 143 | |
|
144 | 144 | /*! |
|
145 | 145 | \brief Returns the chart where series belongs to. |
|
146 | 146 | |
|
147 | 147 | Set automatically when the series is added to the chart |
|
148 | 148 | and unset when the series is removed from the chart. |
|
149 | 149 | */ |
|
150 | 150 | QChart* QAbstractSeries::chart() const |
|
151 | 151 | { |
|
152 | 152 | return d_ptr->m_chart; |
|
153 | 153 | } |
|
154 | 154 | |
|
155 | void QAbstractSeries::adjustView() | |
|
156 | { | |
|
157 | //TODO: | |
|
158 | } | |
|
155 | //void QAbstractSeries::adjustView() | |
|
156 | //{ | |
|
157 | // //TODO: | |
|
158 | //} | |
|
159 | 159 | |
|
160 | 160 | /*! |
|
161 | 161 | \brief Sets the visibility of the series to true |
|
162 | 162 | |
|
163 | 163 | \sa setVisible(), isVisible() |
|
164 | 164 | */ |
|
165 | 165 | void QAbstractSeries::show() |
|
166 | 166 | { |
|
167 | 167 | setVisible(true); |
|
168 | 168 | } |
|
169 | 169 | |
|
170 | 170 | /*! |
|
171 | 171 | \brief Sets the visibility of the series to false |
|
172 | 172 | |
|
173 | 173 | \sa setVisible(), isVisible() |
|
174 | 174 | */ |
|
175 | 175 | void QAbstractSeries::hide() |
|
176 | 176 | { |
|
177 | 177 | setVisible(false); |
|
178 | 178 | } |
|
179 | 179 | |
|
180 | 180 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
181 | 181 | |
|
182 | 182 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q): |
|
183 | 183 | q_ptr(q), |
|
184 | 184 | m_chart(0), |
|
185 | 185 | m_dataset(0), |
|
186 | 186 | m_visible(true) |
|
187 | 187 | { |
|
188 | 188 | } |
|
189 | 189 | |
|
190 | 190 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() |
|
191 | 191 | { |
|
192 | 192 | } |
|
193 | 193 | |
|
194 | 194 | #include "moc_qabstractseries.cpp" |
|
195 | 195 | #include "moc_qabstractseries_p.cpp" |
|
196 | 196 | |
|
197 | 197 | QTCOMMERCIALCHART_END_NAMESPACE |
|
198 | 198 | |
|
199 | 199 |
@@ -1,84 +1,83 | |||
|
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 QABSTRACTSERIES_H |
|
22 | 22 | #define QABSTRACTSERIES_H |
|
23 | 23 | |
|
24 | 24 | #include <qchartglobal.h> |
|
25 | 25 | #include <qabstractaxis.h> |
|
26 | 26 | #include <QObject> |
|
27 | 27 | #include <QPen> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class QAbstractSeriesPrivate; |
|
32 | 32 | class QChart; |
|
33 | 33 | |
|
34 | 34 | class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject |
|
35 | 35 | { |
|
36 | 36 | Q_OBJECT |
|
37 | 37 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) |
|
38 | 38 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) |
|
39 | 39 | Q_PROPERTY(SeriesType type READ type) |
|
40 | 40 | Q_ENUMS(SeriesType) |
|
41 | 41 | |
|
42 | 42 | public: |
|
43 | 43 | enum SeriesType { |
|
44 | 44 | SeriesTypeLine, |
|
45 | 45 | SeriesTypeArea, |
|
46 | 46 | SeriesTypeBar, |
|
47 | 47 | SeriesTypeStackedBar, |
|
48 | 48 | SeriesTypePercentBar, |
|
49 | 49 | SeriesTypePie, |
|
50 | 50 | SeriesTypeScatter, |
|
51 | 51 | SeriesTypeSpline |
|
52 | 52 | }; |
|
53 | 53 | |
|
54 | 54 | protected: |
|
55 | 55 | QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent = 0); |
|
56 | 56 | |
|
57 | 57 | public: |
|
58 | 58 | ~QAbstractSeries(); |
|
59 | 59 | virtual SeriesType type() const = 0; |
|
60 | 60 | |
|
61 | 61 | void setName(const QString& name); |
|
62 | 62 | QString name() const; |
|
63 | 63 | void setVisible(bool visible = true); |
|
64 | 64 | bool isVisible() const; |
|
65 | 65 | QChart* chart() const; |
|
66 | 66 | |
|
67 | void adjustView(); | |
|
68 | 67 | void show(); |
|
69 | 68 | void hide(); |
|
70 | 69 | |
|
71 | 70 | Q_SIGNALS: |
|
72 | 71 | void nameChanged(); |
|
73 | 72 | void visibleChanged(); |
|
74 | 73 | |
|
75 | 74 | protected: |
|
76 | 75 | QScopedPointer<QAbstractSeriesPrivate> d_ptr; |
|
77 | 76 | friend class ChartDataSet; |
|
78 | 77 | friend class ChartPresenter; |
|
79 | 78 | friend class QLegendPrivate; |
|
80 | 79 | }; |
|
81 | 80 | |
|
82 | 81 | QTCOMMERCIALCHART_END_NAMESPACE |
|
83 | 82 | |
|
84 | 83 | #endif |
@@ -1,490 +1,504 | |||
|
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 <QGraphicsScene> |
|
28 | 28 | #include <QGraphicsSceneResizeEvent> |
|
29 | 29 | #include <QGraphicsLayout> |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | |
|
33 | 33 | /*! |
|
34 | 34 | \enum QChart::ChartTheme |
|
35 | 35 | |
|
36 | 36 | This enum describes the theme used by the chart. |
|
37 | 37 | |
|
38 | 38 | \value ChartThemeLight The default theme |
|
39 | 39 | \value ChartThemeBlueCerulean |
|
40 | 40 | \value ChartThemeDark |
|
41 | 41 | \value ChartThemeBrownSand |
|
42 | 42 | \value ChartThemeBlueNcs |
|
43 | 43 | \value ChartThemeHighContrast |
|
44 | 44 | \value ChartThemeBlueIcy |
|
45 | 45 | */ |
|
46 | 46 | |
|
47 | 47 | /*! |
|
48 | 48 | \enum QChart::AnimationOption |
|
49 | 49 | |
|
50 | 50 | For enabling/disabling animations. Defaults to NoAnimation. |
|
51 | 51 | |
|
52 | 52 | \value NoAnimation |
|
53 | 53 | \value GridAxisAnimations |
|
54 | 54 | \value SeriesAnimations |
|
55 | 55 | \value AllAnimations |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | \class QChart |
|
60 | 60 | \brief QtCommercial chart API. |
|
61 | 61 | |
|
62 | 62 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
63 | 63 | representation of different types of series and other chart related objects like |
|
64 | 64 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the |
|
65 | 65 | convenience class QChartView instead of QChart. |
|
66 | 66 | \sa QChartView |
|
67 | 67 | */ |
|
68 | 68 | |
|
69 | 69 | /*! |
|
70 | 70 | \property QChart::animationOptions |
|
71 | 71 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
72 | 72 | */ |
|
73 | 73 | |
|
74 | 74 | /*! |
|
75 | 75 | \property QChart::backgroundVisible |
|
76 | 76 | Whether the chart background is visible or not. |
|
77 | 77 | \sa setBackgroundBrush(), setBackgroundPen() |
|
78 | 78 | */ |
|
79 | 79 | |
|
80 | 80 | /*! |
|
81 | 81 | \property QChart::dropShadowEnabled |
|
82 | 82 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
83 | 83 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
84 | 84 | */ |
|
85 | 85 | |
|
86 | 86 | /*! |
|
87 | 87 | \property QChart::margins |
|
88 | 88 | Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes. |
|
89 | 89 | */ |
|
90 | 90 | |
|
91 | 91 | /*! |
|
92 | 92 | \property QChart::theme |
|
93 | 93 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
94 | 94 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few |
|
95 | 95 | different themes. |
|
96 | 96 | Note: changing the theme will overwrite all customizations previously applied to the series. |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \property QChart::title |
|
101 | 101 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. |
|
102 | 102 | */ |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | \fn void QChart::marginsChanged(QRectF newMargins) |
|
106 | 106 | The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size, |
|
107 | 107 | modify axes or hide/show legend. |
|
108 | 108 | */ |
|
109 | 109 | |
|
110 | 110 | /*! |
|
111 | 111 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
112 | 112 | */ |
|
113 | 113 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
114 | 114 | d_ptr(new QChartPrivate()) |
|
115 | 115 | { |
|
116 | 116 | d_ptr->m_dataset = new ChartDataSet(this); |
|
117 | 117 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
118 | 118 | d_ptr->createConnections(); |
|
119 | 119 | d_ptr->m_legend = new LegendScroller(this); |
|
120 | 120 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); |
|
121 | 121 | //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF))); |
|
122 | 122 | setLayout(d_ptr->m_presenter->layout()); |
|
123 | 123 | } |
|
124 | 124 | |
|
125 | 125 | /*! |
|
126 | 126 | Destroys the object and it's children, like series and axis objects added to it. |
|
127 | 127 | */ |
|
128 | 128 | QChart::~QChart() |
|
129 | 129 | { |
|
130 | 130 | //delete first presenter , since this is a root of all the graphical items |
|
131 | 131 | setLayout(0); |
|
132 | 132 | delete d_ptr->m_presenter; |
|
133 | 133 | d_ptr->m_presenter=0; |
|
134 | 134 | } |
|
135 | 135 | |
|
136 | 136 | /*! |
|
137 | 137 | Adds the \a series onto the chart and takes the ownership of the object. |
|
138 | 138 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
139 | 139 | the y axis). |
|
140 | 140 | |
|
141 | 141 | \sa removeSeries(), removeAllSeries() |
|
142 | 142 | */ |
|
143 | 143 | void QChart::addSeries(QAbstractSeries *series) |
|
144 | 144 | { |
|
145 | 145 | Q_ASSERT(series); |
|
146 | 146 | d_ptr->m_dataset->addSeries(series); |
|
147 | 147 | } |
|
148 | 148 | |
|
149 | 149 | /*! |
|
150 | 150 | Removes the \a series specified in a perameter from the QChartView. |
|
151 | 151 | It releses its ownership of the specified QChartSeries object. |
|
152 | 152 | It does not delete the pointed QChartSeries data object |
|
153 | 153 | \sa addSeries(), removeAllSeries() |
|
154 | 154 | */ |
|
155 | 155 | void QChart::removeSeries(QAbstractSeries *series) |
|
156 | 156 | { |
|
157 | 157 | Q_ASSERT(series); |
|
158 | 158 | d_ptr->m_dataset->removeSeries(series); |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | /*! |
|
162 | 162 | Removes all the QChartSeries that have been added to the QChartView |
|
163 | 163 | It also deletes the pointed QChartSeries data objects |
|
164 | 164 | \sa addSeries(), removeSeries() |
|
165 | 165 | */ |
|
166 | 166 | void QChart::removeAllSeries() |
|
167 | 167 | { |
|
168 | 168 | d_ptr->m_dataset->removeAllSeries(); |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | /*! |
|
172 | 172 | Sets the \a brush that is used for painting the background of the chart area. |
|
173 | 173 | */ |
|
174 | 174 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
175 | 175 | { |
|
176 | 176 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
177 | 177 | } |
|
178 | 178 | |
|
179 | 179 | /*! |
|
180 | 180 | Gets the brush that is used for painting the background of the chart area. |
|
181 | 181 | */ |
|
182 | 182 | QBrush QChart::backgroundBrush() const |
|
183 | 183 | { |
|
184 | 184 | return d_ptr->m_presenter->backgroundBrush(); |
|
185 | 185 | } |
|
186 | 186 | |
|
187 | 187 | /*! |
|
188 | 188 | Sets the \a pen that is used for painting the background of the chart area. |
|
189 | 189 | */ |
|
190 | 190 | void QChart::setBackgroundPen(const QPen& pen) |
|
191 | 191 | { |
|
192 | 192 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
193 | 193 | } |
|
194 | 194 | |
|
195 | 195 | /*! |
|
196 | 196 | Gets the pen that is used for painting the background of the chart area. |
|
197 | 197 | */ |
|
198 | 198 | QPen QChart::backgroundPen() const |
|
199 | 199 | { |
|
200 | 200 | return d_ptr->m_presenter->backgroundPen(); |
|
201 | 201 | } |
|
202 | 202 | |
|
203 | 203 | /*! |
|
204 | 204 | Sets the chart \a title. The description text that is drawn above the chart. |
|
205 | 205 | */ |
|
206 | 206 | void QChart::setTitle(const QString& title) |
|
207 | 207 | { |
|
208 | 208 | d_ptr->m_presenter->setTitle(title); |
|
209 | 209 | } |
|
210 | 210 | |
|
211 | 211 | /*! |
|
212 | 212 | Returns the chart title. The description text that is drawn above the chart. |
|
213 | 213 | */ |
|
214 | 214 | QString QChart::title() const |
|
215 | 215 | { |
|
216 | 216 | return d_ptr->m_presenter->title(); |
|
217 | 217 | } |
|
218 | 218 | |
|
219 | 219 | /*! |
|
220 | 220 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. |
|
221 | 221 | */ |
|
222 | 222 | void QChart::setTitleFont(const QFont& font) |
|
223 | 223 | { |
|
224 | 224 | d_ptr->m_presenter->setTitleFont(font); |
|
225 | 225 | } |
|
226 | 226 | |
|
227 | 227 | /*! |
|
228 | 228 | Gets the font that is used for drawing the chart description text that is rendered above the chart. |
|
229 | 229 | */ |
|
230 | 230 | QFont QChart::titleFont() const |
|
231 | 231 | { |
|
232 | 232 | return d_ptr->m_presenter->titleFont(); |
|
233 | 233 | } |
|
234 | 234 | |
|
235 | 235 | /*! |
|
236 | 236 | Sets the \a brush used for rendering the title text. |
|
237 | 237 | */ |
|
238 | 238 | void QChart::setTitleBrush(const QBrush &brush) |
|
239 | 239 | { |
|
240 | 240 | d_ptr->m_presenter->setTitleBrush(brush); |
|
241 | 241 | } |
|
242 | 242 | |
|
243 | 243 | /*! |
|
244 | 244 | Returns the brush used for rendering the title text. |
|
245 | 245 | */ |
|
246 | 246 | QBrush QChart::titleBrush() const |
|
247 | 247 | { |
|
248 | 248 | return d_ptr->m_presenter->titleBrush(); |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | void QChart::setTheme(QChart::ChartTheme theme) |
|
252 | 252 | { |
|
253 | 253 | d_ptr->m_presenter->setTheme(theme); |
|
254 | 254 | } |
|
255 | 255 | |
|
256 | 256 | QChart::ChartTheme QChart::theme() const |
|
257 | 257 | { |
|
258 | 258 | return d_ptr->m_presenter->theme(); |
|
259 | 259 | } |
|
260 | 260 | |
|
261 | 261 | /*! |
|
262 | 262 | Zooms in the view by a factor of 2 |
|
263 | 263 | */ |
|
264 | 264 | void QChart::zoomIn() |
|
265 | 265 | { |
|
266 | 266 | d_ptr->m_presenter->zoomIn(2.0); |
|
267 | 267 | } |
|
268 | 268 | |
|
269 | 269 | /*! |
|
270 | 270 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
271 | 271 | */ |
|
272 | 272 | void QChart::zoomIn(const QRectF& rect) |
|
273 | 273 | { |
|
274 | 274 | if (!rect.isValid()) return; |
|
275 | 275 | d_ptr->m_presenter->zoomIn(rect); |
|
276 | 276 | } |
|
277 | 277 | |
|
278 | 278 | /*! |
|
279 | 279 | Restores the view zoom level to the previous one. |
|
280 | 280 | */ |
|
281 | 281 | void QChart::zoomOut() |
|
282 | 282 | { |
|
283 | 283 | d_ptr->m_presenter->zoomOut(2.0); |
|
284 | 284 | } |
|
285 | 285 | |
|
286 | 286 | /*! |
|
287 | 287 | Zooms in the view by a \a factor. |
|
288 | 288 | |
|
289 | 289 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
290 | 290 | */ |
|
291 | 291 | void QChart::zoom(qreal factor) |
|
292 | 292 | { |
|
293 | 293 | if (qFuzzyIsNull(factor)) |
|
294 | 294 | return; |
|
295 | 295 | |
|
296 | 296 | if (qFuzzyCompare(factor, 1.0)) |
|
297 | 297 | return; |
|
298 | 298 | |
|
299 | 299 | if (factor < 0) |
|
300 | 300 | return; |
|
301 | 301 | |
|
302 | 302 | if (factor > 1.0) |
|
303 | 303 | d_ptr->m_presenter->zoomIn(factor); |
|
304 | 304 | else |
|
305 | 305 | d_ptr->m_presenter->zoomOut(1.0 / factor); |
|
306 | 306 | } |
|
307 | 307 | |
|
308 | 308 | /*! |
|
309 | 309 | Returns the pointer to the x axis object of the chart asociated with the specified \a series |
|
310 | 310 | If no series is provided then pointer to currently visible axis is provided |
|
311 | 311 | */ |
|
312 | 312 | QAbstractAxis* QChart::axisX(QAbstractSeries* series) const |
|
313 | 313 | { |
|
314 | 314 | return d_ptr->m_dataset->axisX(series); |
|
315 | 315 | } |
|
316 | 316 | |
|
317 | 317 | /*! |
|
318 | 318 | Returns the pointer to the y axis object of the chart asociated with the specified \a series |
|
319 | 319 | If no series is provided then pointer to currently visible axis is provided |
|
320 | 320 | */ |
|
321 | 321 | QAbstractAxis* QChart::axisY(QAbstractSeries *series) const |
|
322 | 322 | { |
|
323 | 323 | return d_ptr->m_dataset->axisY(series); |
|
324 | 324 | } |
|
325 | 325 | |
|
326 | 326 | /*! |
|
327 | 327 | 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. |
|
328 | 328 | |
|
329 | 329 | Creates the axes for the chart based on the series that has already been added to the chart. |
|
330 | 330 | |
|
331 | 331 | \table |
|
332 | 332 | \header |
|
333 | 333 | \o Series type |
|
334 | 334 | \o X-axis |
|
335 | 335 | \o Y-axis |
|
336 | 336 | \row |
|
337 | 337 | \o QXYSeries |
|
338 | 338 | \o QValuesAxis |
|
339 | 339 | \o QValuesAxis |
|
340 | 340 | \row |
|
341 | 341 | \o QBarSeries |
|
342 | 342 | \o QBarCategoriesAxis |
|
343 | 343 | \o QValuesAxis |
|
344 | 344 | \row |
|
345 | 345 | \o QPieSeries |
|
346 | 346 | \o None |
|
347 | 347 | \o None |
|
348 | 348 | \endtable |
|
349 | 349 | |
|
350 | 350 | 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. |
|
351 | 351 | If there are sevaral series added of different types then each series gets its own axes pair. |
|
352 | 352 | |
|
353 | 353 | 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. |
|
354 | 354 | |
|
355 | 355 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. |
|
356 | 356 | QPieSeries does not create any axes. |
|
357 | 357 | |
|
358 | 358 | \sa axisX(), axisY(), setAxisX(), setAxisY() |
|
359 | 359 | */ |
|
360 | 360 | void QChart::createDefaultAxes() |
|
361 | 361 | { |
|
362 | 362 | d_ptr->m_dataset->createDefaultAxes(); |
|
363 | 363 | } |
|
364 | 364 | |
|
365 | 365 | /*! |
|
366 | 366 | Returns the legend object of the chart. Ownership stays in chart. |
|
367 | 367 | */ |
|
368 | 368 | QLegend* QChart::legend() const |
|
369 | 369 | { |
|
370 | 370 | return d_ptr->m_legend; |
|
371 | 371 | } |
|
372 | 372 | |
|
373 | 373 | /*! |
|
374 | 374 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
375 | 375 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
376 | 376 | */ |
|
377 | 377 | QRectF QChart::margins() const |
|
378 | 378 | { |
|
379 | 379 | return d_ptr->m_presenter->margins(); |
|
380 | 380 | } |
|
381 | 381 | |
|
382 | /*! | |
|
383 | Returns the the rect within which the drawing of the chart is done. | |
|
384 | It does not include the area defines by margins. | |
|
385 | */ | |
|
382 | 386 | QRectF QChart::plotArea() const |
|
383 | 387 | { |
|
384 | 388 | return d_ptr->m_presenter->geometry(); |
|
385 | 389 | } |
|
386 | 390 | |
|
391 | ///*! | |
|
392 | // TODO: Dummy. | |
|
393 | // Adjest the ranges of the axes so that all the data of the specified \a series is visible | |
|
394 | // */ | |
|
395 | //void QChart::adjustViewToSeries(QAbstractSeries* series) | |
|
396 | //{ | |
|
397 | // // | |
|
398 | //} | |
|
399 | ||
|
387 | 400 | /*! |
|
388 | 401 | Sets animation \a options for the chart |
|
389 | 402 | */ |
|
390 | ||
|
391 | 403 | void QChart::setAnimationOptions(AnimationOptions options) |
|
392 | 404 | { |
|
393 | 405 | d_ptr->m_presenter->setAnimationOptions(options); |
|
394 | 406 | } |
|
395 | 407 | |
|
396 | 408 | QChart::AnimationOptions QChart::animationOptions() const |
|
397 | 409 | { |
|
398 | 410 | return d_ptr->m_presenter->animationOptions(); |
|
399 | 411 | } |
|
400 | 412 | |
|
401 | 413 | /*! |
|
402 | 414 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
403 | 415 | */ |
|
404 | 416 | void QChart::scroll(qreal dx, qreal dy) |
|
405 | 417 | { |
|
406 | 418 | d_ptr->m_presenter->scroll(dx, dy); |
|
407 | 419 | } |
|
408 | 420 | |
|
409 | 421 | void QChart::setBackgroundVisible(bool visible) |
|
410 | 422 | { |
|
411 | 423 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
412 | 424 | } |
|
413 | 425 | |
|
414 | 426 | bool QChart::isBackgroundVisible() const |
|
415 | 427 | { |
|
416 | 428 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
417 | 429 | } |
|
418 | 430 | |
|
419 | 431 | void QChart::setDropShadowEnabled(bool enabled) |
|
420 | 432 | { |
|
421 | 433 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
422 | 434 | } |
|
423 | 435 | |
|
424 | 436 | bool QChart::isDropShadowEnabled() const |
|
425 | 437 | { |
|
426 | 438 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
427 | 439 | } |
|
428 | 440 | |
|
429 | 441 | /*! |
|
430 | 442 | Returns all the series that are added to the chart. |
|
431 | 443 | |
|
432 | 444 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
433 | 445 | */ |
|
434 | 446 | QList<QAbstractSeries*> QChart::series() const |
|
435 | 447 | { |
|
436 | 448 | return d_ptr->m_dataset->series(); |
|
437 | 449 | } |
|
438 | ||
|
450 | /*! | |
|
451 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. | |
|
452 | */ | |
|
439 | 453 | void QChart::setMarginsMinimum(const QRectF& margins) |
|
440 | 454 | { |
|
441 | 455 | d_ptr->m_presenter->setMarginsMinimum(margins); |
|
442 | 456 | } |
|
443 | 457 | |
|
444 | 458 | /*! |
|
445 | 459 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
446 | 460 | |
|
447 | 461 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes() |
|
448 | 462 | */ |
|
449 | 463 | void QChart::setAxisX(QAbstractAxis* axis , QAbstractSeries *series) |
|
450 | 464 | { |
|
451 | 465 | d_ptr->m_dataset->setAxisX(series,axis); |
|
452 | 466 | } |
|
453 | 467 | |
|
454 | 468 | /*! |
|
455 | 469 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
456 | 470 | |
|
457 | 471 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes() |
|
458 | 472 | */ |
|
459 | 473 | void QChart::setAxisY( QAbstractAxis* axis , QAbstractSeries *series) |
|
460 | 474 | { |
|
461 | 475 | d_ptr->m_dataset->setAxisY(series,axis); |
|
462 | 476 | } |
|
463 | 477 | |
|
464 | 478 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
465 | 479 | |
|
466 | 480 | QChartPrivate::QChartPrivate(): |
|
467 | 481 | m_legend(0), |
|
468 | 482 | m_dataset(0), |
|
469 | 483 | m_presenter(0) |
|
470 | 484 | { |
|
471 | 485 | |
|
472 | 486 | } |
|
473 | 487 | |
|
474 | 488 | QChartPrivate::~QChartPrivate() |
|
475 | 489 | { |
|
476 | 490 | |
|
477 | 491 | } |
|
478 | 492 | |
|
479 | 493 | void QChartPrivate::createConnections() |
|
480 | 494 | { |
|
481 | 495 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
482 | 496 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
483 | 497 | QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*))); |
|
484 | 498 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
485 | 499 | //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF))); |
|
486 | 500 | } |
|
487 | 501 | |
|
488 | 502 | #include "moc_qchart.cpp" |
|
489 | 503 | |
|
490 | 504 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,136 +1,134 | |||
|
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 QCHART_H |
|
22 | 22 | #define QCHART_H |
|
23 | 23 | |
|
24 | 24 | #include <QAbstractSeries> |
|
25 | 25 | #include <QLegend> |
|
26 | 26 | #include <QGraphicsWidget> |
|
27 | 27 | |
|
28 | 28 | class QGraphicsSceneResizeEvent; |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | class QAbstractSeries; |
|
33 | 33 | class QAbstractAxis; |
|
34 | 34 | class QLegend; |
|
35 | 35 | struct QChartPrivate; |
|
36 | 36 | |
|
37 | 37 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
38 | 38 | { |
|
39 | 39 | Q_OBJECT |
|
40 | 40 | Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme) |
|
41 | 41 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
42 | 42 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible) |
|
43 | 43 | Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled) |
|
44 | 44 | Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions) |
|
45 | 45 | Q_PROPERTY(QRectF margins READ margins NOTIFY marginsChanged) |
|
46 | 46 | Q_ENUMS(ChartTheme) |
|
47 | 47 | Q_ENUMS(AnimationOption) |
|
48 | 48 | |
|
49 | 49 | public: |
|
50 | 50 | enum ChartTheme { |
|
51 | 51 | ChartThemeLight = 0, |
|
52 | 52 | ChartThemeBlueCerulean, |
|
53 | 53 | ChartThemeDark, |
|
54 | 54 | ChartThemeBrownSand, |
|
55 | 55 | ChartThemeBlueNcs, |
|
56 | 56 | ChartThemeHighContrast, |
|
57 | 57 | ChartThemeBlueIcy |
|
58 | 58 | }; |
|
59 | 59 | |
|
60 | 60 | enum AnimationOption { |
|
61 | 61 | NoAnimation = 0x0, |
|
62 | 62 | GridAxisAnimations = 0x1, |
|
63 | 63 | SeriesAnimations =0x2, |
|
64 | 64 | AllAnimations = 0x3 |
|
65 | 65 | }; |
|
66 | 66 | |
|
67 | 67 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
68 | 68 | |
|
69 | 69 | public: |
|
70 | 70 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
71 | 71 | ~QChart(); |
|
72 | 72 | |
|
73 | 73 | void addSeries(QAbstractSeries *series); |
|
74 | 74 | void removeSeries(QAbstractSeries *series); |
|
75 | 75 | void removeAllSeries(); |
|
76 | 76 | QList<QAbstractSeries*> series() const; |
|
77 | 77 | |
|
78 | 78 | void setAxisX(QAbstractAxis* axis, QAbstractSeries *series = 0); |
|
79 | 79 | void setAxisY(QAbstractAxis* axis, QAbstractSeries *series = 0); |
|
80 | 80 | |
|
81 | 81 | QAbstractAxis* axisX(QAbstractSeries* series = 0) const; |
|
82 | 82 | QAbstractAxis* axisY(QAbstractSeries* series = 0) const; |
|
83 | 83 | |
|
84 | 84 | void createDefaultAxes(); |
|
85 | 85 | |
|
86 | 86 | void setTheme(QChart::ChartTheme theme); |
|
87 | 87 | QChart::ChartTheme theme() const; |
|
88 | 88 | |
|
89 | 89 | void setTitle(const QString& title); |
|
90 | 90 | QString title() const; |
|
91 | 91 | void setTitleFont(const QFont& font); |
|
92 | 92 | QFont titleFont() const; |
|
93 | 93 | void setTitleBrush(const QBrush &brush); |
|
94 | 94 | QBrush titleBrush() const; |
|
95 | 95 | |
|
96 | 96 | void setBackgroundBrush(const QBrush &brush); |
|
97 | 97 | QBrush backgroundBrush() const; |
|
98 | 98 | void setBackgroundPen(const QPen &pen); |
|
99 | 99 | QPen backgroundPen() const; |
|
100 | 100 | void setBackgroundVisible(bool visible = true); |
|
101 | 101 | bool isBackgroundVisible() const; |
|
102 | 102 | |
|
103 | 103 | void setDropShadowEnabled(bool enabled = true); |
|
104 | 104 | bool isDropShadowEnabled() const; |
|
105 | 105 | void setAnimationOptions(AnimationOptions options); |
|
106 | 106 | AnimationOptions animationOptions() const; |
|
107 | 107 | |
|
108 | 108 | void zoomIn(); |
|
109 | 109 | void zoomIn(const QRectF &rect); |
|
110 | 110 | void zoomOut(); |
|
111 | 111 | void zoom(qreal factor); |
|
112 | 112 | void scroll(qreal dx, qreal dy); |
|
113 | 113 | |
|
114 | void adjustViewToSeries(QAbstractSeries* series = 0); | |
|
115 | ||
|
116 | 114 | QLegend* legend() const; |
|
117 | 115 | |
|
118 | 116 | void setMarginsMinimum(const QRectF& margins); |
|
119 | 117 | QRectF margins() const; |
|
120 | 118 | QRectF plotArea() const; |
|
121 | 119 | |
|
122 | 120 | Q_SIGNALS: |
|
123 | 121 | void marginsChanged(QRectF newMargins); |
|
124 | 122 | |
|
125 | 123 | protected: |
|
126 | 124 | QScopedPointer<QChartPrivate> d_ptr; |
|
127 | 125 | friend class QLegend; |
|
128 | 126 | friend class ChartPresenter; |
|
129 | 127 | Q_DISABLE_COPY(QChart) |
|
130 | 128 | }; |
|
131 | 129 | |
|
132 | 130 | QTCOMMERCIALCHART_END_NAMESPACE |
|
133 | 131 | |
|
134 | 132 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
135 | 133 | |
|
136 | 134 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now