@@ -1,601 +1,604 | |||
|
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, 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 Axis QAbstractAxis |
|
38 | 38 | \brief The Axis element is used for manipulating chart's axes |
|
39 | 39 | |
|
40 | 40 | There is only one x Axis, 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 AxisTypeValues |
|
63 | 63 | \value AxisTypeCategories |
|
64 | 64 | */ |
|
65 | 65 | |
|
66 | 66 | /*! |
|
67 | 67 | \property QAbstractAxis::type |
|
68 | 68 | The type of the axis. |
|
69 | 69 | */ |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | \property QAbstractAxis::labelsVisible |
|
73 | 73 | Defines if axis labels are visible. |
|
74 | 74 | */ |
|
75 | 75 | /*! |
|
76 | 76 | \qmlproperty bool Axis::labelsVisible |
|
77 | 77 | Defines if axis labels are visible. |
|
78 | 78 | */ |
|
79 | 79 | |
|
80 | 80 | /*! |
|
81 | 81 | \property QAbstractAxis::min |
|
82 | 82 | Defines the minimum value on the axis. |
|
83 | 83 | */ |
|
84 | 84 | /*! |
|
85 | 85 | \qmlproperty real Axis::min |
|
86 | 86 | Defines the minimum value on the axis. |
|
87 | 87 | */ |
|
88 | 88 | |
|
89 | 89 | /*! |
|
90 | 90 | \property QAbstractAxis::max |
|
91 | 91 | Defines the maximum value on the axis. |
|
92 | 92 | */ |
|
93 | 93 | /*! |
|
94 | 94 | \qmlproperty real Axis::max |
|
95 | 95 | Defines the maximum value on the axis. |
|
96 | 96 | */ |
|
97 | 97 | |
|
98 | 98 | /*! |
|
99 | 99 | \property QAbstractAxis::visible |
|
100 | 100 | The visibility of the axis. |
|
101 | 101 | */ |
|
102 | 102 | /*! |
|
103 | 103 | \qmlproperty bool Axis::visible |
|
104 | 104 | The visibility of the axis. |
|
105 | 105 | */ |
|
106 | 106 | |
|
107 | 107 | /*! |
|
108 | 108 | \property QAbstractAxis::gridVisible |
|
109 | 109 | The visibility of the grid lines. |
|
110 | 110 | */ |
|
111 | 111 | /*! |
|
112 | 112 | \qmlproperty bool Axis::gridVisible |
|
113 | 113 | The visibility of the grid lines. |
|
114 | 114 | */ |
|
115 | 115 | |
|
116 | 116 | /*! |
|
117 | 117 | \property QAbstractAxis::color |
|
118 | 118 | The color of the axis and ticks. |
|
119 | 119 | */ |
|
120 | 120 | /*! |
|
121 | 121 | \qmlproperty color Axis::color |
|
122 | 122 | The color of the axis and ticks. |
|
123 | 123 | */ |
|
124 | 124 | |
|
125 | 125 | /*! |
|
126 | 126 | \property QAxis::labelsFont |
|
127 | 127 | The font of the axis labels. |
|
128 | 128 | */ |
|
129 | 129 | /*! |
|
130 | 130 | \qmlproperty Font Axis::labelsFont |
|
131 | 131 | The font of the axis labels. |
|
132 | 132 | |
|
133 | 133 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
134 | 134 | */ |
|
135 | 135 | |
|
136 | 136 | /*! |
|
137 | 137 | \property QAbstractAxis::labelsColor |
|
138 | 138 | The color of the axis labels. |
|
139 | 139 | */ |
|
140 | 140 | /*! |
|
141 | 141 | \qmlproperty color Axis::labelsColor |
|
142 | 142 | The color of the axis labels. |
|
143 | 143 | */ |
|
144 | 144 | |
|
145 | 145 | /*! |
|
146 | 146 | \property QAbstractAxis::labelsAngle |
|
147 | 147 | The angle of the axis labels in degrees. |
|
148 | 148 | */ |
|
149 | 149 | /*! |
|
150 | 150 | \qmlproperty int Axis::labelsAngle |
|
151 | 151 | The angle of the axis labels in degrees. |
|
152 | 152 | */ |
|
153 | 153 | |
|
154 | 154 | /*! |
|
155 | 155 | \property QAbstractAxis::shadesVisible |
|
156 | 156 | The visibility of the axis shades. |
|
157 | 157 | */ |
|
158 | 158 | /*! |
|
159 | 159 | \qmlproperty bool Axis::shadesVisible |
|
160 | 160 | The visibility of the axis shades. |
|
161 | 161 | */ |
|
162 | 162 | |
|
163 | 163 | /*! |
|
164 | 164 | \property QAbstractAxis::shadesColor |
|
165 | 165 | The fill (brush) color of the axis shades. |
|
166 | 166 | */ |
|
167 | 167 | /*! |
|
168 | 168 | \qmlproperty color Axis::shadesColor |
|
169 | 169 | The fill (brush) color of the axis shades. |
|
170 | 170 | */ |
|
171 | 171 | |
|
172 | 172 | /*! |
|
173 | 173 | \property QAbstractAxis::shadesBorderColor |
|
174 | 174 | The border (pen) color of the axis shades. |
|
175 | 175 | */ |
|
176 | 176 | /*! |
|
177 | 177 | \qmlproperty color Axis::shadesBorderColor |
|
178 | 178 | The border (pen) color of the axis shades. |
|
179 | 179 | */ |
|
180 | 180 | |
|
181 | 181 | /*! |
|
182 | 182 | \property QAbstractAxis::ticksCount |
|
183 | 183 | The number of tick marks for the axis. |
|
184 | 184 | */ |
|
185 | 185 | /*! |
|
186 | 186 | \qmlproperty int Axis::ticksCount |
|
187 | 187 | The number of tick marks for the axis. |
|
188 | 188 | */ |
|
189 | 189 | |
|
190 | 190 | /*! |
|
191 | 191 | \property QAbstractAxis::niceNumbersEnabled |
|
192 | 192 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
193 | 193 | */ |
|
194 | 194 | /*! |
|
195 | 195 | \qmlproperty bool Axis::niceNumbersEnabled |
|
196 | 196 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
197 | 197 | */ |
|
198 | 198 | |
|
199 | 199 | /*! |
|
200 | 200 | \fn void QAbstractAxis::visibleChanged(bool) |
|
201 | 201 | Visiblity of the axis has changed to \a visible. |
|
202 | 202 | */ |
|
203 | 203 | |
|
204 | 204 | /*! |
|
205 | 205 | \fn void QAbstractAxis::labelsVisibleChanged(bool) |
|
206 | 206 | Visiblity of the labels of the axis has changed to \a visible. |
|
207 | 207 | */ |
|
208 | 208 | |
|
209 | 209 | /*! |
|
210 | 210 | \fn void QAbstractAxis::gridVisibleChanged(bool) |
|
211 | 211 | Visiblity of the grid lines of the axis has changed to \a visible. |
|
212 | 212 | */ |
|
213 | 213 | |
|
214 | 214 | /*! |
|
215 | 215 | \fn void QAbstractAxis::minChanged(qreal min) |
|
216 | 216 | Axis emits signal when \a min of axis has changed. |
|
217 | 217 | */ |
|
218 | 218 | |
|
219 | 219 | /*! |
|
220 | 220 | \fn void QAbstractAxis::maxChanged(qreal max) |
|
221 | 221 | Axis emits signal when \a max of axis has changed. |
|
222 | 222 | */ |
|
223 | 223 | |
|
224 | 224 | /*! |
|
225 | 225 | \fn void QAbstractAxis::rangeChanged(qreal min, qreal max) |
|
226 | 226 | Axis emits signal when \a min or \a max of axis has changed. |
|
227 | 227 | */ |
|
228 | 228 | |
|
229 | 229 | /*! |
|
230 | 230 | \fn QChartAxisCategories* QAbstractAxis::categories() |
|
231 | 231 | Returns pointer to the list of categories which correspond to the values on the axis. |
|
232 | 232 | */ |
|
233 | 233 | |
|
234 | 234 | /*! |
|
235 | 235 | \fn void QAbstractAxis::colorChanged(QColor) |
|
236 | 236 | Emitted if the \a color of the axis is changed. |
|
237 | 237 | */ |
|
238 | 238 | |
|
239 | 239 | /*! |
|
240 | 240 | \fn void QAbstractAxis::labelsColorChanged(QColor) |
|
241 | 241 | Emitted if the \a color of the axis labels is changed. |
|
242 | 242 | */ |
|
243 | 243 | |
|
244 | 244 | /*! |
|
245 | 245 | \fn void QAbstractAxis::shadesVisibleChanged(bool) |
|
246 | 246 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
247 | 247 | */ |
|
248 | 248 | |
|
249 | 249 | /*! |
|
250 | 250 | \fn void QAbstractAxis::shadesColorChanged(QColor) |
|
251 | 251 | Emitted if the \a color of the axis shades is changed. |
|
252 | 252 | */ |
|
253 | 253 | |
|
254 | 254 | /*! |
|
255 | 255 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) |
|
256 | 256 | Emitted if the border \a color of the axis shades is changed. |
|
257 | 257 | */ |
|
258 | 258 | |
|
259 | 259 | /*! |
|
260 | 260 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
261 | 261 | QChart when axis added. |
|
262 | 262 | */ |
|
263 | 263 | |
|
264 | 264 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) : |
|
265 | 265 | QObject(parent), |
|
266 | 266 | d_ptr(&d) |
|
267 | 267 | { |
|
268 | 268 | } |
|
269 | 269 | |
|
270 | 270 | /*! |
|
271 | 271 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
272 | 272 | */ |
|
273 | 273 | |
|
274 | 274 | QAbstractAxis::~QAbstractAxis() |
|
275 | 275 | { |
|
276 | 276 | } |
|
277 | 277 | |
|
278 | 278 | /*! |
|
279 | 279 | Sets \a pen used to draw axis line and ticks. |
|
280 | 280 | */ |
|
281 | 281 | void QAbstractAxis::setAxisPen(const QPen &pen) |
|
282 | 282 | { |
|
283 | 283 | if (d_ptr->m_axisPen!=pen) { |
|
284 | 284 | d_ptr->m_axisPen = pen; |
|
285 | 285 | emit d_ptr->updated(); |
|
286 | 286 | } |
|
287 | 287 | } |
|
288 | 288 | |
|
289 | 289 | /*! |
|
290 | 290 | Returns pen used to draw axis and ticks. |
|
291 | 291 | */ |
|
292 | 292 | QPen QAbstractAxis::axisPen() const |
|
293 | 293 | { |
|
294 | 294 | return d_ptr->m_axisPen; |
|
295 | 295 | } |
|
296 | 296 | |
|
297 | 297 | void QAbstractAxis::setAxisPenColor(QColor color) |
|
298 | 298 | { |
|
299 | 299 | QPen p = d_ptr->m_axisPen; |
|
300 | 300 | if (p.color() != color) { |
|
301 | 301 | p.setColor(color); |
|
302 | 302 | setAxisPen(p); |
|
303 | 303 | emit colorChanged(color); |
|
304 | 304 | } |
|
305 | 305 | } |
|
306 | 306 | |
|
307 | 307 | QColor QAbstractAxis::axisPenColor() const |
|
308 | 308 | { |
|
309 | 309 | return d_ptr->m_axisPen.color(); |
|
310 | 310 | } |
|
311 | 311 | |
|
312 | 312 | /*! |
|
313 | 313 | Sets if axis and ticks are \a visible. |
|
314 | 314 | */ |
|
315 | 315 | void QAbstractAxis::setAxisVisible(bool visible) |
|
316 | 316 | { |
|
317 | 317 | if (d_ptr->m_axisVisible != visible) { |
|
318 | 318 | d_ptr->m_axisVisible = visible; |
|
319 | 319 | emit d_ptr->updated(); |
|
320 | 320 | emit visibleChanged(visible); |
|
321 | 321 | } |
|
322 | 322 | } |
|
323 | 323 | |
|
324 | 324 | bool QAbstractAxis::isAxisVisible() const |
|
325 | 325 | { |
|
326 | 326 | return d_ptr->m_axisVisible; |
|
327 | 327 | } |
|
328 | 328 | |
|
329 | 329 | void QAbstractAxis::setGridLineVisible(bool visible) |
|
330 | 330 | { |
|
331 | 331 | if (d_ptr->m_gridLineVisible != visible) { |
|
332 | 332 | d_ptr->m_gridLineVisible = visible; |
|
333 | 333 | emit d_ptr->updated(); |
|
334 | 334 | emit gridVisibleChanged(visible); |
|
335 | 335 | } |
|
336 | 336 | } |
|
337 | 337 | |
|
338 | 338 | bool QAbstractAxis::isGridLineVisible() const |
|
339 | 339 | { |
|
340 | 340 | return d_ptr->m_gridLineVisible; |
|
341 | 341 | } |
|
342 | 342 | |
|
343 | 343 | /*! |
|
344 | 344 | Sets \a pen used to draw grid line. |
|
345 | 345 | */ |
|
346 | 346 | void QAbstractAxis::setGridLinePen(const QPen &pen) |
|
347 | 347 | { |
|
348 | 348 | if (d_ptr->m_gridLinePen != pen) { |
|
349 | 349 | d_ptr->m_gridLinePen = pen; |
|
350 | 350 | emit d_ptr->updated(); |
|
351 | 351 | } |
|
352 | 352 | } |
|
353 | 353 | |
|
354 | 354 | /*! |
|
355 | 355 | Returns pen used to draw grid. |
|
356 | 356 | */ |
|
357 | 357 | QPen QAbstractAxis::gridLinePen() const |
|
358 | 358 | { |
|
359 | 359 | return d_ptr->m_gridLinePen; |
|
360 | 360 | } |
|
361 | 361 | |
|
362 | 362 | void QAbstractAxis::setLabelsVisible(bool visible) |
|
363 | 363 | { |
|
364 | 364 | if (d_ptr->m_labelsVisible != visible) { |
|
365 | 365 | d_ptr->m_labelsVisible = visible; |
|
366 | 366 | emit d_ptr->updated(); |
|
367 | 367 | emit labelsVisibleChanged(visible); |
|
368 | 368 | } |
|
369 | 369 | } |
|
370 | 370 | |
|
371 | 371 | bool QAbstractAxis::labelsVisible() const |
|
372 | 372 | { |
|
373 | 373 | return d_ptr->m_labelsVisible; |
|
374 | 374 | } |
|
375 | 375 | |
|
376 | 376 | /*! |
|
377 | 377 | Sets \a pen used to draw labels. |
|
378 | 378 | */ |
|
379 | 379 | void QAbstractAxis::setLabelsPen(const QPen &pen) |
|
380 | 380 | { |
|
381 | 381 | if (d_ptr->m_labelsPen != pen) { |
|
382 | 382 | d_ptr->m_labelsPen = pen; |
|
383 | 383 | emit d_ptr->updated(); |
|
384 | 384 | } |
|
385 | 385 | } |
|
386 | 386 | |
|
387 | 387 | /*! |
|
388 | 388 | Returns the pen used to labels. |
|
389 | 389 | */ |
|
390 | 390 | QPen QAbstractAxis::labelsPen() const |
|
391 | 391 | { |
|
392 | 392 | return d_ptr->m_labelsPen; |
|
393 | 393 | } |
|
394 | 394 | |
|
395 | 395 | /*! |
|
396 | 396 | Sets \a brush used to draw labels. |
|
397 | 397 | */ |
|
398 | 398 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) |
|
399 | 399 | { |
|
400 | 400 | if (d_ptr->m_labelsBrush != brush) { |
|
401 | 401 | d_ptr->m_labelsBrush = brush; |
|
402 | 402 | emit d_ptr->updated(); |
|
403 | 403 | } |
|
404 | 404 | } |
|
405 | 405 | |
|
406 | 406 | /*! |
|
407 | 407 | Returns brush used to draw labels. |
|
408 | 408 | */ |
|
409 | 409 | QBrush QAbstractAxis::labelsBrush() const |
|
410 | 410 | { |
|
411 | 411 | return d_ptr->m_labelsBrush; |
|
412 | 412 | } |
|
413 | 413 | |
|
414 | 414 | /*! |
|
415 | 415 | Sets \a font used to draw labels. |
|
416 | 416 | */ |
|
417 | 417 | void QAbstractAxis::setLabelsFont(const QFont &font) |
|
418 | 418 | { |
|
419 | 419 | if (d_ptr->m_labelsFont != font) { |
|
420 | 420 | d_ptr->m_labelsFont = font; |
|
421 | 421 | emit d_ptr->updated(); |
|
422 | 422 | } |
|
423 | 423 | } |
|
424 | 424 | |
|
425 | 425 | /*! |
|
426 | 426 | Returns font used to draw labels. |
|
427 | 427 | */ |
|
428 | 428 | QFont QAbstractAxis::labelsFont() const |
|
429 | 429 | { |
|
430 | 430 | return d_ptr->m_labelsFont; |
|
431 | 431 | } |
|
432 | 432 | |
|
433 | 433 | void QAbstractAxis::setLabelsAngle(int angle) |
|
434 | 434 | { |
|
435 | 435 | if (d_ptr->m_labelsAngle != angle) { |
|
436 | 436 | d_ptr->m_labelsAngle = angle; |
|
437 | 437 | emit d_ptr->updated(); |
|
438 | 438 | } |
|
439 | 439 | } |
|
440 | 440 | |
|
441 | 441 | int QAbstractAxis::labelsAngle() const |
|
442 | 442 | { |
|
443 | 443 | return d_ptr->m_labelsAngle; |
|
444 | 444 | } |
|
445 | 445 | |
|
446 | 446 | void QAbstractAxis::setLabelsColor(QColor color) |
|
447 | 447 | { |
|
448 | 448 | QBrush b = d_ptr->m_labelsBrush; |
|
449 | 449 | if (b.color() != color) { |
|
450 | 450 | b.setColor(color); |
|
451 | 451 | setLabelsBrush(b); |
|
452 | 452 | emit labelsColorChanged(color); |
|
453 | 453 | } |
|
454 | 454 | } |
|
455 | 455 | |
|
456 | 456 | QColor QAbstractAxis::labelsColor() const |
|
457 | 457 | { |
|
458 | 458 | return d_ptr->m_labelsBrush.color(); |
|
459 | 459 | } |
|
460 | 460 | |
|
461 | 461 | void QAbstractAxis::setShadesVisible(bool visible) |
|
462 | 462 | { |
|
463 | 463 | if (d_ptr->m_shadesVisible != visible) { |
|
464 | 464 | d_ptr->m_shadesVisible = visible; |
|
465 | 465 | emit d_ptr->updated(); |
|
466 | 466 | emit shadesVisibleChanged(visible); |
|
467 | 467 | } |
|
468 | 468 | } |
|
469 | 469 | |
|
470 | 470 | bool QAbstractAxis::shadesVisible() const |
|
471 | 471 | { |
|
472 | 472 | return d_ptr->m_shadesVisible; |
|
473 | 473 | } |
|
474 | 474 | |
|
475 | 475 | /*! |
|
476 | 476 | Sets \a pen used to draw shades. |
|
477 | 477 | */ |
|
478 | 478 | void QAbstractAxis::setShadesPen(const QPen &pen) |
|
479 | 479 | { |
|
480 | 480 | if (d_ptr->m_shadesPen != pen) { |
|
481 | 481 | d_ptr->m_shadesPen = pen; |
|
482 | 482 | emit d_ptr->updated(); |
|
483 | 483 | } |
|
484 | 484 | } |
|
485 | 485 | |
|
486 | 486 | /*! |
|
487 | 487 | Returns pen used to draw shades. |
|
488 | 488 | */ |
|
489 | 489 | QPen QAbstractAxis::shadesPen() const |
|
490 | 490 | { |
|
491 | 491 | return d_ptr->m_shadesPen; |
|
492 | 492 | } |
|
493 | 493 | |
|
494 | 494 | /*! |
|
495 | 495 | Sets \a brush used to draw shades. |
|
496 | 496 | */ |
|
497 | 497 | void QAbstractAxis::setShadesBrush(const QBrush &brush) |
|
498 | 498 | { |
|
499 | 499 | if (d_ptr->m_shadesBrush != brush) { |
|
500 | 500 | d_ptr->m_shadesBrush = brush; |
|
501 | 501 | emit d_ptr->updated(); |
|
502 | 502 | emit shadesColorChanged(brush.color()); |
|
503 | 503 | } |
|
504 | 504 | } |
|
505 | 505 | |
|
506 | 506 | /*! |
|
507 | 507 | Returns brush used to draw shades. |
|
508 | 508 | */ |
|
509 | 509 | QBrush QAbstractAxis::shadesBrush() const |
|
510 | 510 | { |
|
511 | 511 | return d_ptr->m_shadesBrush; |
|
512 | 512 | } |
|
513 | 513 | |
|
514 | 514 | void QAbstractAxis::setShadesColor(QColor color) |
|
515 | 515 | { |
|
516 | 516 | QBrush b = d_ptr->m_shadesBrush; |
|
517 | 517 | b.setColor(color); |
|
518 | 518 | setShadesBrush(b); |
|
519 | 519 | } |
|
520 | 520 | |
|
521 | 521 | QColor QAbstractAxis::shadesColor() const |
|
522 | 522 | { |
|
523 | 523 | return d_ptr->m_shadesBrush.color(); |
|
524 | 524 | } |
|
525 | 525 | |
|
526 | 526 | void QAbstractAxis::setShadesBorderColor(QColor color) |
|
527 | 527 | { |
|
528 | 528 | QPen p = d_ptr->m_shadesPen; |
|
529 | 529 | p.setColor(color); |
|
530 | 530 | setShadesPen(p); |
|
531 | 531 | } |
|
532 | 532 | |
|
533 | 533 | QColor QAbstractAxis::shadesBorderColor() const |
|
534 | 534 | { |
|
535 | 535 | return d_ptr->m_shadesPen.color(); |
|
536 | 536 | } |
|
537 | 537 | |
|
538 | 538 | |
|
539 | 539 | /*! |
|
540 | 540 | Sets axis, shades, labels and grid lines to be visible. |
|
541 | 541 | */ |
|
542 | 542 | void QAbstractAxis::show() |
|
543 | 543 | { |
|
544 | 544 | d_ptr->m_axisVisible=true; |
|
545 | 545 | d_ptr->m_gridLineVisible=true; |
|
546 | 546 | d_ptr->m_labelsVisible=true; |
|
547 | 547 | d_ptr->m_shadesVisible=true; |
|
548 | 548 | emit d_ptr->updated(); |
|
549 | 549 | } |
|
550 | 550 | |
|
551 | 551 | /*! |
|
552 | 552 | Sets axis, shades, labels and grid lines to not be visible. |
|
553 | 553 | */ |
|
554 | 554 | void QAbstractAxis::hide() |
|
555 | 555 | { |
|
556 | 556 | d_ptr->m_axisVisible = false; |
|
557 | 557 | d_ptr->m_gridLineVisible = false; |
|
558 | 558 | d_ptr->m_labelsVisible = false; |
|
559 | 559 | d_ptr->m_shadesVisible = false; |
|
560 | 560 | emit d_ptr->updated(); |
|
561 | 561 | } |
|
562 | 562 | |
|
563 | 563 | |
|
564 |
void QAbstractAxis::setMin(const |
|
|
564 | void QAbstractAxis::setMin(const qreal min) | |
|
565 | 565 | { |
|
566 | 566 | d_ptr->setMin(min); |
|
567 | 567 | } |
|
568 |
void QAbstractAxis::setMax(const |
|
|
568 | void QAbstractAxis::setMax(const qreal max) | |
|
569 | 569 | { |
|
570 | 570 | d_ptr->setMax(max); |
|
571 | 571 | } |
|
572 |
void QAbstractAxis::setRange(const |
|
|
572 | void QAbstractAxis::setRange(const qreal min, const qreal max) | |
|
573 | 573 | { |
|
574 | 574 | d_ptr->setRange(min,max); |
|
575 | 575 | } |
|
576 | 576 | |
|
577 | 577 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
578 | 578 | |
|
579 | 579 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q): |
|
580 | 580 | q_ptr(q), |
|
581 | 581 | m_axisVisible(true), |
|
582 | 582 | m_gridLineVisible(true), |
|
583 | 583 | m_labelsVisible(true), |
|
584 | 584 | m_labelsAngle(0), |
|
585 | 585 | m_shadesVisible(false), |
|
586 | 586 | m_shadesBrush(Qt::SolidPattern), |
|
587 | 587 | m_shadesOpacity(1.0), |
|
588 | m_orientation(Qt::Orientation(0)) | |
|
588 | m_orientation(Qt::Orientation(0)), | |
|
589 | m_min(0), | |
|
590 | m_max(0), | |
|
591 | m_ticksCount(5) | |
|
589 | 592 | { |
|
590 | 593 | |
|
591 | 594 | } |
|
592 | 595 | |
|
593 | 596 | QAbstractAxisPrivate::~QAbstractAxisPrivate() |
|
594 | 597 | { |
|
595 | 598 | |
|
596 | 599 | } |
|
597 | 600 | |
|
598 | 601 | #include "moc_qabstractaxis.cpp" |
|
599 | 602 | #include "moc_qabstractaxis_p.cpp" |
|
600 | 603 | |
|
601 | 604 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,130 +1,130 | |||
|
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 | |
|
37 | 37 | Q_PROPERTY(bool visible READ isAxisVisible WRITE setAxisVisible NOTIFY visibleChanged) |
|
38 | 38 | Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged) |
|
39 | 39 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
40 | 40 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle) |
|
41 | 41 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont) |
|
42 | 42 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) |
|
43 | 43 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) |
|
44 | 44 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) |
|
45 | 45 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) |
|
46 | 46 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) |
|
47 | 47 | |
|
48 | 48 | public: |
|
49 | 49 | |
|
50 | 50 | enum AxisType { |
|
51 | 51 | AxisTypeValues, |
|
52 | 52 | AxisTypeCategories |
|
53 | 53 | }; |
|
54 | 54 | |
|
55 | 55 | protected: |
|
56 | 56 | explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0); |
|
57 | 57 | |
|
58 | 58 | public: |
|
59 | 59 | ~QAbstractAxis(); |
|
60 | 60 | |
|
61 | 61 | virtual AxisType type() const = 0; |
|
62 | 62 | |
|
63 | 63 | //axis handling |
|
64 | 64 | bool isAxisVisible() const; |
|
65 | 65 | void setAxisVisible(bool visible = true); |
|
66 | 66 | void setAxisPen(const QPen &pen); |
|
67 | 67 | QPen axisPen() const; |
|
68 | 68 | void setAxisPenColor(QColor color); |
|
69 | 69 | QColor axisPenColor() const; |
|
70 | 70 | |
|
71 | 71 | //grid handling |
|
72 | 72 | bool isGridLineVisible() const; |
|
73 | 73 | void setGridLineVisible(bool visible = true); |
|
74 | 74 | void setGridLinePen(const QPen &pen); |
|
75 | 75 | QPen gridLinePen() const; |
|
76 | 76 | |
|
77 | 77 | //labels handling |
|
78 | 78 | bool labelsVisible() const; |
|
79 | 79 | void setLabelsVisible(bool visible = true); |
|
80 | 80 | void setLabelsPen(const QPen &pen); |
|
81 | 81 | QPen labelsPen() const; |
|
82 | 82 | void setLabelsBrush(const QBrush &brush); |
|
83 | 83 | QBrush labelsBrush() const; |
|
84 | 84 | void setLabelsFont(const QFont &font); |
|
85 | 85 | QFont labelsFont() const; |
|
86 | 86 | void setLabelsAngle(int angle); |
|
87 | 87 | int labelsAngle() const; |
|
88 | 88 | void setLabelsColor(QColor color); |
|
89 | 89 | QColor labelsColor() const; |
|
90 | 90 | |
|
91 | 91 | //shades handling |
|
92 | 92 | bool shadesVisible() const; |
|
93 | 93 | void setShadesVisible(bool visible = true); |
|
94 | 94 | void setShadesPen(const QPen &pen); |
|
95 | 95 | QPen shadesPen() const; |
|
96 | 96 | void setShadesBrush(const QBrush &brush); |
|
97 | 97 | QBrush shadesBrush() const; |
|
98 | 98 | void setShadesColor(QColor color); |
|
99 | 99 | QColor shadesColor() const; |
|
100 | 100 | void setShadesBorderColor(QColor color); |
|
101 | 101 | QColor shadesBorderColor() const; |
|
102 | 102 | |
|
103 | 103 | //range handling |
|
104 |
void setMin(const |
|
|
105 |
void setMax(const |
|
|
106 |
void setRange(const |
|
|
104 | void setMin(const qreal min); | |
|
105 | void setMax(const qreal max); | |
|
106 | void setRange(const qreal min, const qreal max); | |
|
107 | 107 | |
|
108 | 108 | void show(); |
|
109 | 109 | void hide(); |
|
110 | 110 | |
|
111 | 111 | Q_SIGNALS: |
|
112 | 112 | void visibleChanged(bool visible); |
|
113 | 113 | void labelsVisibleChanged(bool visible); |
|
114 | 114 | void gridVisibleChanged(bool visible); |
|
115 | 115 | void colorChanged(QColor color); |
|
116 | 116 | void labelsColorChanged(QColor color); |
|
117 | 117 | void shadesVisibleChanged(bool visible); |
|
118 | 118 | void shadesColorChanged(QColor color); |
|
119 | 119 | void shadesBorderColorChanged(QColor color); |
|
120 | 120 | |
|
121 | 121 | protected: |
|
122 | 122 | QScopedPointer<QAbstractAxisPrivate> d_ptr; |
|
123 | 123 | Q_DISABLE_COPY(QAbstractAxis); |
|
124 | 124 | friend class ChartDataSet; |
|
125 | 125 | friend class ChartAxis; |
|
126 | 126 | friend class ChartPresenter; |
|
127 | 127 | }; |
|
128 | 128 | |
|
129 | 129 | QTCOMMERCIALCHART_END_NAMESPACE |
|
130 | 130 | #endif |
@@ -1,87 +1,92 | |||
|
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 QABSTRACTAXIS_P_H |
|
31 | 31 | #define QABSTRACTAXIS_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qabstractaxis.h" |
|
34 | 34 | |
|
35 | 35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | class ChartPresenter; |
|
38 | 38 | class ChartAxis; |
|
39 | 39 | |
|
40 | 40 | class QAbstractAxisPrivate : public QObject |
|
41 | 41 | { |
|
42 | 42 | Q_OBJECT |
|
43 | 43 | public: |
|
44 | 44 | QAbstractAxisPrivate(QAbstractAxis *q); |
|
45 | 45 | ~QAbstractAxisPrivate(); |
|
46 | 46 | |
|
47 | 47 | Q_SIGNALS: |
|
48 | 48 | void updated(); |
|
49 | 49 | |
|
50 | 50 | public: |
|
51 | 51 | virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0; |
|
52 | 52 | |
|
53 | 53 | protected: |
|
54 |
virtual void setMin(const |
|
|
55 |
virtual void setMax(const |
|
|
56 |
virtual void setRange(const |
|
|
54 | virtual void setMin(const qreal min) = 0; | |
|
55 | virtual void setMax(const qreal max) = 0; | |
|
56 | virtual void setRange(const qreal min, const qreal max) = 0; | |
|
57 | 57 | virtual int ticksCount() const = 0; |
|
58 | 58 | |
|
59 | 59 | public: |
|
60 | 60 | QAbstractAxis *q_ptr; |
|
61 | 61 | |
|
62 | 62 | bool m_axisVisible; |
|
63 | 63 | QPen m_axisPen; |
|
64 | 64 | QBrush m_axisBrush; |
|
65 | 65 | |
|
66 | 66 | bool m_gridLineVisible; |
|
67 | 67 | QPen m_gridLinePen; |
|
68 | 68 | |
|
69 | 69 | bool m_labelsVisible; |
|
70 | 70 | QPen m_labelsPen; |
|
71 | 71 | QBrush m_labelsBrush; |
|
72 | 72 | QFont m_labelsFont; |
|
73 | 73 | int m_labelsAngle; |
|
74 | 74 | |
|
75 | 75 | bool m_shadesVisible; |
|
76 | 76 | QPen m_shadesPen; |
|
77 | 77 | QBrush m_shadesBrush; |
|
78 | 78 | qreal m_shadesOpacity; |
|
79 | 79 | |
|
80 | 80 | Qt::Orientation m_orientation; |
|
81 | 81 | |
|
82 | // range | |
|
83 | qreal m_min; | |
|
84 | qreal m_max; | |
|
85 | int m_ticksCount; | |
|
86 | ||
|
82 | 87 | friend class QAbstractAxis; |
|
83 | 88 | }; |
|
84 | 89 | |
|
85 | 90 | QTCOMMERCIALCHART_END_NAMESPACE |
|
86 | 91 | |
|
87 | 92 | #endif |
@@ -1,222 +1,270 | |||
|
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 "qcategoriesaxis.h" |
|
22 | 22 | #include "qcategoriesaxis_p.h" |
|
23 | 23 | #include "chartcategoriesaxisx_p.h" |
|
24 | 24 | #include "chartcategoriesaxisy_p.h" |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | QCategoriesAxis::QCategoriesAxis(QObject *parent): |
|
29 | 29 | QAbstractAxis(*new QCategoriesAxisPrivate(this),parent) |
|
30 | 30 | { |
|
31 | 31 | |
|
32 | 32 | } |
|
33 | 33 | |
|
34 | 34 | QCategoriesAxis::~QCategoriesAxis() |
|
35 | 35 | { |
|
36 | 36 | |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) |
|
40 | 40 | { |
|
41 | 41 | |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | /*! |
|
45 | 45 | Appends \a categories to axis |
|
46 | 46 | */ |
|
47 | 47 | void QCategoriesAxis::append(const QStringList &categories) |
|
48 | 48 | { |
|
49 | 49 | Q_D(QCategoriesAxis); |
|
50 | 50 | d->m_categories.append(categories); |
|
51 | 51 | emit categoriesChanged(); |
|
52 | 52 | } |
|
53 | 53 | |
|
54 | 54 | /*! |
|
55 | 55 | Appends \a category to axis |
|
56 | 56 | */ |
|
57 | 57 | void QCategoriesAxis::append(const QString &category) |
|
58 | 58 | { |
|
59 | 59 | Q_D(QCategoriesAxis); |
|
60 | 60 | d->m_categories.append(category); |
|
61 | 61 | emit categoriesChanged(); |
|
62 | 62 | } |
|
63 | 63 | |
|
64 | 64 | /*! |
|
65 | 65 | Removes \a category from axis |
|
66 | 66 | */ |
|
67 | 67 | void QCategoriesAxis::remove(const QString &category) |
|
68 | 68 | { |
|
69 | 69 | Q_D(QCategoriesAxis); |
|
70 | 70 | if (d->m_categories.contains(category)) { |
|
71 | 71 | d->m_categories.removeAt(d->m_categories.indexOf(category)); |
|
72 | 72 | emit categoriesChanged(); |
|
73 | 73 | } |
|
74 | 74 | } |
|
75 | 75 | |
|
76 | 76 | /*! |
|
77 | 77 | Inserts \a category to axis at \a index |
|
78 | 78 | */ |
|
79 | 79 | void QCategoriesAxis::insert(int index, const QString &category) |
|
80 | 80 | { |
|
81 | 81 | Q_D(QCategoriesAxis); |
|
82 | 82 | d->m_categories.insert(index,category); |
|
83 | 83 | emit categoriesChanged(); |
|
84 | 84 | } |
|
85 | 85 | |
|
86 | 86 | /*! |
|
87 | 87 | Removes all categories. |
|
88 | 88 | */ |
|
89 | 89 | void QCategoriesAxis::clear() |
|
90 | 90 | { |
|
91 | 91 | Q_D(QCategoriesAxis); |
|
92 | 92 | d->m_categories.clear(); |
|
93 | 93 | emit categoriesChanged(); |
|
94 | 94 | } |
|
95 | 95 | |
|
96 | 96 | void QCategoriesAxis::setCategories(const QStringList &categories) |
|
97 | 97 | { |
|
98 | 98 | Q_D(QCategoriesAxis); |
|
99 | 99 | d->m_categories = categories; |
|
100 | 100 | emit categoriesChanged(); |
|
101 | 101 | } |
|
102 | 102 | |
|
103 | 103 | QStringList QCategoriesAxis::categories() |
|
104 | 104 | { |
|
105 | 105 | Q_D(QCategoriesAxis); |
|
106 | 106 | return d->m_categories; |
|
107 | 107 | } |
|
108 | 108 | |
|
109 | 109 | /*! |
|
110 | 110 | Returns number of categories. |
|
111 | 111 | */ |
|
112 | 112 | int QCategoriesAxis::count() const |
|
113 | 113 | { |
|
114 | 114 | Q_D(const QCategoriesAxis); |
|
115 | 115 | return d->m_categories.count(); |
|
116 | 116 | } |
|
117 | 117 | |
|
118 | 118 | /*! |
|
119 | 119 | Returns category at \a index. Index must be valid. |
|
120 | 120 | */ |
|
121 | 121 | QString QCategoriesAxis::at(int index) const |
|
122 | 122 | { |
|
123 | 123 | Q_D(const QCategoriesAxis); |
|
124 | 124 | return d->m_categories.at(index); |
|
125 | 125 | } |
|
126 | 126 | |
|
127 | 127 | /*! |
|
128 | 128 | Sets minimum category to \a minCategory. |
|
129 | 129 | */ |
|
130 | 130 | void QCategoriesAxis::setMin(const QString& minCategory) |
|
131 | 131 | { |
|
132 | 132 | Q_D(QCategoriesAxis); |
|
133 | int minIndex = d->m_categories.indexOf(minCategory); | |
|
134 | if (minIndex == -1) | |
|
135 | return; | |
|
136 | // else | |
|
137 | // QAbstractAxis::setMin(minIndex); | |
|
133 | d->setMinCategory(minCategory); | |
|
138 | 134 | } |
|
139 | 135 | |
|
140 | 136 | /*! |
|
141 | 137 | Sets maximum category to \a maxCategory. |
|
142 | 138 | */ |
|
143 | 139 | void QCategoriesAxis::setMax(const QString& maxCategory) |
|
144 | 140 | { |
|
145 | 141 | Q_D(QCategoriesAxis); |
|
146 | int maxIndex = d->m_categories.indexOf(maxCategory); | |
|
147 | if (maxIndex == -1) | |
|
148 | return; | |
|
149 | // else | |
|
150 | // QAbstractAxis::setMax(maxIndex); | |
|
142 | d->setMaxCategory(maxCategory); | |
|
151 | 143 | } |
|
152 | 144 | |
|
153 | 145 | /*! |
|
154 | 146 | Sets range from \a minCategory to \a maxCategory |
|
155 | 147 | */ |
|
156 | 148 | void QCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory) |
|
157 | 149 | { |
|
158 | // TODO: what if maxCategory < minCategory? | |
|
159 |
|
|
|
160 | setMax(maxCategory); | |
|
150 | Q_D(QCategoriesAxis); | |
|
151 | d->setRangeCategory(minCategory,maxCategory); | |
|
161 | 152 | } |
|
162 | 153 | |
|
163 | 154 | /*! |
|
164 | 155 | Returns the type of axis. |
|
165 | 156 | */ |
|
166 | 157 | QAbstractAxis::AxisType QCategoriesAxis::type() const |
|
167 | 158 | { |
|
168 | 159 | return AxisTypeCategories; |
|
169 | 160 | } |
|
170 | 161 | |
|
171 | 162 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
172 | 163 | |
|
173 | 164 | QCategoriesAxisPrivate::QCategoriesAxisPrivate(QCategoriesAxis* q): |
|
174 | 165 | QAbstractAxisPrivate(q) |
|
175 | 166 | { |
|
176 | 167 | |
|
177 | 168 | } |
|
178 | 169 | |
|
179 | 170 | QCategoriesAxisPrivate::~QCategoriesAxisPrivate() |
|
180 | 171 | { |
|
181 | 172 | |
|
182 | 173 | } |
|
183 | 174 | |
|
175 | void QCategoriesAxisPrivate::setMinCategory(const QString& minCategory) | |
|
176 | { | |
|
177 | // Convert the category to value | |
|
178 | int minIndex = m_categories.indexOf(minCategory); | |
|
179 | if (minIndex == -1) { | |
|
180 | return; | |
|
181 | } | |
|
182 | setRange(minIndex,m_max); | |
|
183 | } | |
|
184 | 184 | |
|
185 |
void QCategoriesAxisPrivate::setM |
|
|
185 | void QCategoriesAxisPrivate::setMaxCategory(const QString& maxCategory) | |
|
186 | 186 | { |
|
187 | Q_Q(QCategoriesAxis); | |
|
188 | q->setMin(min.toString()); | |
|
187 | // Convert the category to value | |
|
188 | int maxIndex = m_categories.indexOf(maxCategory); | |
|
189 | if (maxIndex == -1) { | |
|
190 | return; | |
|
191 | } | |
|
192 | setRange(m_min,maxIndex); | |
|
189 | 193 | } |
|
190 | 194 | |
|
191 |
void QCategoriesAxisPrivate::set |
|
|
195 | void QCategoriesAxisPrivate::setRangeCategory(const QString& minCategory, const QString& maxCategory) | |
|
192 | 196 | { |
|
193 | Q_Q(QCategoriesAxis); | |
|
194 | q->setMax(max.toString()); | |
|
197 | // TODO: | |
|
198 | int minIndex = m_categories.indexOf(minCategory); | |
|
199 | if (minIndex == -1) { | |
|
200 | return; | |
|
201 | } | |
|
202 | int maxIndex = m_categories.indexOf(maxCategory); | |
|
203 | if (maxIndex == -1) { | |
|
204 | return; | |
|
205 | } | |
|
206 | setRange(minIndex,maxIndex); | |
|
195 | 207 | } |
|
196 | 208 | |
|
197 |
void QCategoriesAxisPrivate::set |
|
|
209 | void QCategoriesAxisPrivate::setMin(const qreal min) | |
|
198 | 210 | { |
|
199 | Q_Q(QCategoriesAxis); | |
|
200 | q->setRange(min.toString(),max.toString()); | |
|
211 | setRange(min,m_max); | |
|
212 | } | |
|
213 | ||
|
214 | void QCategoriesAxisPrivate::setMax(const qreal max) | |
|
215 | { | |
|
216 | setRange(m_min,max); | |
|
217 | } | |
|
218 | ||
|
219 | void QCategoriesAxisPrivate::setRange(const qreal min, const qreal max) | |
|
220 | { | |
|
221 | Q_Q(QCategoriesAxis); | |
|
222 | bool changed = false; | |
|
223 | if (!qFuzzyIsNull(m_min - min)) { | |
|
224 | m_min = min; | |
|
225 | changed = true; | |
|
226 | } | |
|
227 | ||
|
228 | if (!qFuzzyIsNull(m_max - max)) { | |
|
229 | m_max = max; | |
|
230 | changed = true; | |
|
231 | } | |
|
232 | ||
|
233 | if (changed) { | |
|
234 | emit this->changed(m_min, m_max, m_ticksCount, false); | |
|
235 | emit q->categoriesChanged(); | |
|
236 | } | |
|
201 | 237 | } |
|
202 | 238 | |
|
203 | 239 | int QCategoriesAxisPrivate::ticksCount() const |
|
204 | 240 | { |
|
205 | 241 | return m_categories.count()+1; |
|
206 | 242 | } |
|
207 | 243 | |
|
244 | void QCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) | |
|
245 | { | |
|
246 | // Q_Q(QCategoriesAxis); | |
|
247 | // q->setRange(min,max); | |
|
248 | // q->setTicksCount(count); | |
|
249 | m_min = min; | |
|
250 | m_max = max; | |
|
251 | m_ticksCount = count; | |
|
252 | ||
|
253 | // TODO?: | |
|
254 | //emit updated(); | |
|
255 | } | |
|
256 | ||
|
208 | 257 | ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
209 | 258 | { |
|
210 | 259 | Q_Q( QCategoriesAxis); |
|
211 | 260 | if(m_orientation == Qt::Vertical){ |
|
212 | 261 | return new ChartCategoriesAxisY(q,presenter); |
|
213 | 262 | }else{ |
|
214 | 263 | return new ChartCategoriesAxisX(q,presenter); |
|
215 | 264 | } |
|
216 | ||
|
217 | 265 | } |
|
218 | 266 | |
|
219 | 267 | #include "moc_qcategoriesaxis.cpp" |
|
220 | 268 | #include "moc_qcategoriesaxis_p.cpp" |
|
221 | 269 | |
|
222 | 270 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,70 +1,80 | |||
|
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 QCATEGORIESAXIS_P_H |
|
31 | 31 | #define QCATEGORIESAXIS_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qcategoriesaxis.h" |
|
34 | 34 | #include "qabstractaxis_p.h" |
|
35 | 35 | |
|
36 | 36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | class QCategoriesAxisPrivate : public QAbstractAxisPrivate |
|
39 | 39 | { |
|
40 | 40 | Q_OBJECT |
|
41 | 41 | |
|
42 | 42 | public: |
|
43 | 43 | QCategoriesAxisPrivate(QCategoriesAxis *q); |
|
44 | 44 | ~QCategoriesAxisPrivate(); |
|
45 | 45 | |
|
46 | 46 | public: |
|
47 | 47 | ChartAxis* createGraphics(ChartPresenter* presenter); |
|
48 | 48 | |
|
49 | 49 | private: |
|
50 | void setMinCategory(const QString& minCategory); | |
|
51 | void setMaxCategory(const QString& maxCategory); | |
|
52 | void setRangeCategory(const QString& minCategory, const QString& maxCategory); | |
|
53 | ||
|
50 | 54 | //range handling |
|
51 |
void setMin(const |
|
|
52 |
void setMax(const |
|
|
53 |
void setRange(const |
|
|
55 | void setMin(const qreal min); | |
|
56 | void setMax(const qreal max); | |
|
57 | void setRange(const qreal min, const qreal max); | |
|
54 | 58 | int ticksCount() const; |
|
55 | 59 | |
|
60 | Q_SIGNALS: | |
|
61 | void changed(qreal min, qreal max, int tickCount,bool niceNumbers); | |
|
62 | ||
|
63 | public Q_SLOTS: | |
|
64 | void handleAxisRangeChanged(qreal min, qreal max,int count); | |
|
65 | ||
|
56 | 66 | private: |
|
57 | 67 | QStringList m_categories; |
|
58 | 68 | QString m_minCategory; |
|
59 | 69 | QString m_maxCategory; |
|
60 | 70 | |
|
61 | Q_SIGNALS: | |
|
62 | void updated(); | |
|
71 | // qreal m_rangeMin; | |
|
72 | // qreal m_rangeMax; | |
|
63 | 73 | |
|
64 | 74 | private: |
|
65 | 75 | Q_DECLARE_PUBLIC(QCategoriesAxis) |
|
66 | 76 | }; |
|
67 | 77 | |
|
68 | 78 | QTCOMMERCIALCHART_END_NAMESPACE |
|
69 | 79 | |
|
70 | 80 | #endif // QCATEGORIESAXIS_P_H |
@@ -1,265 +1,252 | |||
|
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 "qvaluesaxis.h" |
|
22 | 22 | #include "qvaluesaxis_p.h" |
|
23 | 23 | #include "chartvaluesaxisx_p.h" |
|
24 | 24 | #include "chartvaluesaxisy_p.h" |
|
25 | 25 | #include <QDebug> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | /*! |
|
29 | 29 | \class QValuesAxis |
|
30 | 30 | \brief The QValuesAxis class is used for manipulating chart's axis. |
|
31 | 31 | \mainclass |
|
32 | 32 | |
|
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 Axis QValuesAxis |
|
38 | 38 | \brief The Axis element is used for manipulating chart's axes |
|
39 | 39 | |
|
40 | 40 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
41 | 41 | |
|
42 | 42 | To access Axes you can use ChartView API. For example: |
|
43 | 43 | \code |
|
44 | 44 | ChartView { |
|
45 | 45 | axisX.min: 0 |
|
46 | 46 | axisX.max: 3 |
|
47 | 47 | axisX.ticksCount: 4 |
|
48 | 48 | axisY.min: 0 |
|
49 | 49 | axisY.max: 4 |
|
50 | 50 | // Add a few series... |
|
51 | 51 | } |
|
52 | 52 | \endcode |
|
53 | 53 | */ |
|
54 | 54 | |
|
55 | 55 | /*! |
|
56 | 56 | \property QValuesAxis::min |
|
57 | 57 | Defines the minimum value on the axis. |
|
58 | 58 | */ |
|
59 | 59 | /*! |
|
60 | 60 | \qmlproperty real Axis::min |
|
61 | 61 | Defines the minimum value on the axis. |
|
62 | 62 | */ |
|
63 | 63 | |
|
64 | 64 | /*! |
|
65 | 65 | \property QValuesAxis::max |
|
66 | 66 | Defines the maximum value on the axis. |
|
67 | 67 | */ |
|
68 | 68 | /*! |
|
69 | 69 | \qmlproperty real Axis::max |
|
70 | 70 | Defines the maximum value on the axis. |
|
71 | 71 | */ |
|
72 | 72 | |
|
73 | 73 | /*! |
|
74 | 74 | \fn void QValuesAxis::minChanged(qreal min) |
|
75 | 75 | Axis emits signal when \a min of axis has changed. |
|
76 | 76 | */ |
|
77 | 77 | |
|
78 | 78 | /*! |
|
79 | 79 | \fn void QValuesAxis::maxChanged(qreal max) |
|
80 | 80 | Axis emits signal when \a max of axis has changed. |
|
81 | 81 | */ |
|
82 | 82 | |
|
83 | 83 | /*! |
|
84 | 84 | \fn void QValuesAxis::rangeChanged(qreal min, qreal max) |
|
85 | 85 | Axis emits signal when \a min or \a max of axis has changed. |
|
86 | 86 | */ |
|
87 | 87 | |
|
88 | 88 | QValuesAxis::QValuesAxis(QObject *parent) : |
|
89 | 89 | QAbstractAxis(*new QValuesAxisPrivate(this),parent) |
|
90 | 90 | { |
|
91 | 91 | |
|
92 | 92 | } |
|
93 | 93 | |
|
94 | 94 | QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) |
|
95 | 95 | { |
|
96 | 96 | |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | QValuesAxis::~QValuesAxis() |
|
100 | 100 | { |
|
101 | 101 | |
|
102 | 102 | } |
|
103 | 103 | |
|
104 | 104 | void QValuesAxis::setMin(qreal min) |
|
105 | 105 | { |
|
106 | 106 | Q_D(QValuesAxis); |
|
107 | 107 | setRange(min,d->m_max); |
|
108 | 108 | } |
|
109 | 109 | |
|
110 | 110 | qreal QValuesAxis::min() const |
|
111 | 111 | { |
|
112 | 112 | Q_D(const QValuesAxis); |
|
113 | 113 | return d->m_min; |
|
114 | 114 | } |
|
115 | 115 | |
|
116 | 116 | void QValuesAxis::setMax(qreal max) |
|
117 | 117 | { |
|
118 | 118 | Q_D(QValuesAxis); |
|
119 | 119 | setRange(d->m_min,max); |
|
120 | 120 | } |
|
121 | 121 | |
|
122 | 122 | qreal QValuesAxis::max() const |
|
123 | 123 | { |
|
124 | 124 | Q_D(const QValuesAxis); |
|
125 | 125 | return d->m_max; |
|
126 | 126 | } |
|
127 | 127 | |
|
128 | 128 | /*! |
|
129 | 129 | Sets range from \a min to \a max on the axis. |
|
130 | 130 | */ |
|
131 | 131 | void QValuesAxis::setRange(qreal min, qreal max) |
|
132 | 132 | { |
|
133 | 133 | Q_D(QValuesAxis); |
|
134 | bool changed = false; | |
|
135 | if (!qFuzzyIsNull(d->m_min - min)) { | |
|
136 | d->m_min = min; | |
|
137 | changed = true; | |
|
138 | emit minChanged(min); | |
|
139 | } | |
|
140 | ||
|
141 | if (!qFuzzyIsNull(d->m_max - max)) { | |
|
142 | d->m_max = max; | |
|
143 | changed = true; | |
|
144 | emit maxChanged(max); | |
|
145 | } | |
|
146 | ||
|
147 | if (changed) { | |
|
148 | emit rangeChanged(d->m_min,d->m_max); | |
|
149 | emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers); | |
|
150 | } | |
|
134 | d->setRange(min,max); | |
|
151 | 135 | } |
|
152 | 136 | |
|
153 | 137 | /*! |
|
154 | 138 | Sets \a count for ticks on the axis. |
|
155 | 139 | */ |
|
156 | 140 | void QValuesAxis::setTicksCount(int count) |
|
157 | 141 | { |
|
158 | 142 | Q_D(QValuesAxis); |
|
159 | 143 | if (d->m_ticksCount != count) { |
|
160 | 144 | d->m_ticksCount = count; |
|
161 | 145 | emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers); |
|
162 | 146 | } |
|
163 | 147 | } |
|
164 | 148 | |
|
165 | 149 | /*! |
|
166 | 150 | \fn int QAbstractAxis::ticksCount() const |
|
167 | 151 | Return number of ticks on the axis |
|
168 | 152 | */ |
|
169 | 153 | int QValuesAxis::ticksCount() const |
|
170 | 154 | { |
|
171 | 155 | Q_D(const QValuesAxis); |
|
172 | 156 | return d->m_ticksCount; |
|
173 | 157 | } |
|
174 | 158 | |
|
175 | 159 | void QValuesAxis::setNiceNumbersEnabled(bool enable) |
|
176 | 160 | { |
|
177 | 161 | Q_D(QValuesAxis); |
|
178 | 162 | if (d->m_niceNumbers != enable){ |
|
179 | 163 | d->m_niceNumbers = enable; |
|
180 | 164 | emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers); |
|
181 | 165 | } |
|
182 | 166 | } |
|
183 | 167 | |
|
184 | 168 | bool QValuesAxis::niceNumbersEnabled() const |
|
185 | 169 | { |
|
186 | 170 | Q_D(const QValuesAxis); |
|
187 | 171 | return d->m_niceNumbers; |
|
188 | 172 | } |
|
189 | 173 | |
|
190 | 174 | QAbstractAxis::AxisType QValuesAxis::type() const |
|
191 | 175 | { |
|
192 | 176 | return AxisTypeValues; |
|
193 | 177 | } |
|
194 | 178 | |
|
195 | 179 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
196 | 180 | |
|
197 | 181 | QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q): |
|
198 | 182 | QAbstractAxisPrivate(q), |
|
199 | m_min(0), | |
|
200 | m_max(0), | |
|
201 | m_niceNumbers(false), | |
|
202 | m_ticksCount(5) | |
|
183 | m_niceNumbers(false) | |
|
203 | 184 | { |
|
204 | 185 | |
|
205 | 186 | } |
|
206 | 187 | |
|
207 | 188 | QValuesAxisPrivate::~QValuesAxisPrivate() |
|
208 | 189 | { |
|
209 | 190 | |
|
210 | 191 | } |
|
211 | 192 | |
|
212 | 193 | void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) |
|
213 | 194 | { |
|
214 | 195 | Q_Q(QValuesAxis); |
|
215 | 196 | q->setRange(min,max); |
|
216 | 197 | q->setTicksCount(count); |
|
217 | 198 | } |
|
218 | 199 | |
|
219 | 200 | |
|
220 |
void QValuesAxisPrivate::setMin(const |
|
|
201 | void QValuesAxisPrivate::setMin(const qreal min) | |
|
221 | 202 | { |
|
222 | Q_Q(QValuesAxis); | |
|
223 | bool ok; | |
|
224 | qreal value = min.toReal(&ok); | |
|
225 | if(ok) q->setMin(value); | |
|
203 | setRange(min,m_max); | |
|
226 | 204 | } |
|
227 | 205 | |
|
228 |
void QValuesAxisPrivate::setMax(const |
|
|
206 | void QValuesAxisPrivate::setMax(const qreal max) | |
|
229 | 207 | { |
|
230 | Q_Q(QValuesAxis); | |
|
231 | bool ok; | |
|
232 | qreal value = max.toReal(&ok); | |
|
233 | if(ok) q->setMax(value); | |
|
208 | setRange(m_min,max); | |
|
234 | 209 | } |
|
235 | 210 | |
|
236 |
void QValuesAxisPrivate::setRange(const |
|
|
211 | void QValuesAxisPrivate::setRange(const qreal min, const qreal max) | |
|
237 | 212 | { |
|
238 | 213 | Q_Q(QValuesAxis); |
|
239 | bool ok1; | |
|
240 | bool ok2; | |
|
241 | qreal value1 = min.toReal(&ok1); | |
|
242 | qreal value2 = max.toReal(&ok2); | |
|
243 | if(ok1&&ok2) q->setRange(value1,value2); | |
|
214 | bool changed = false; | |
|
215 | if (!qFuzzyIsNull(m_min - min)) { | |
|
216 | m_min = min; | |
|
217 | changed = true; | |
|
218 | emit q->minChanged(min); | |
|
219 | } | |
|
220 | ||
|
221 | if (!qFuzzyIsNull(m_max - max)) { | |
|
222 | m_max = max; | |
|
223 | changed = true; | |
|
224 | emit q->maxChanged(max); | |
|
225 | } | |
|
226 | ||
|
227 | if (changed) { | |
|
228 | emit q->rangeChanged(m_min,m_max); | |
|
229 | emit this->changed(m_min, m_max, m_ticksCount, m_niceNumbers); | |
|
230 | } | |
|
244 | 231 | } |
|
245 | 232 | |
|
246 | 233 | int QValuesAxisPrivate::ticksCount() const |
|
247 | 234 | { |
|
248 | 235 | return m_ticksCount; |
|
249 | 236 | } |
|
250 | 237 | |
|
251 | 238 | ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
252 | 239 | { |
|
253 | 240 | Q_Q(QValuesAxis); |
|
254 | 241 | if(m_orientation == Qt::Vertical){ |
|
255 | 242 | return new ChartValuesAxisY(q,presenter); |
|
256 | 243 | }else{ |
|
257 | 244 | return new ChartValuesAxisX(q,presenter); |
|
258 | 245 | } |
|
259 | 246 | |
|
260 | 247 | } |
|
261 | 248 | |
|
262 | 249 | #include "moc_qvaluesaxis.cpp" |
|
263 | 250 | #include "moc_qvaluesaxis_p.cpp" |
|
264 | 251 | |
|
265 | 252 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,70 +1,67 | |||
|
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 QVALUESAXIS_P_H |
|
31 | 31 | #define QVALUESAXIS_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qvaluesaxis.h" |
|
34 | 34 | #include "qabstractaxis_p.h" |
|
35 | 35 | |
|
36 | 36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | class QValuesAxisPrivate : public QAbstractAxisPrivate |
|
39 | 39 | { |
|
40 | 40 | Q_OBJECT |
|
41 | 41 | public: |
|
42 | 42 | QValuesAxisPrivate(QValuesAxis *q); |
|
43 | 43 | ~QValuesAxisPrivate(); |
|
44 | 44 | |
|
45 | 45 | Q_SIGNALS: |
|
46 | 46 | void changed(qreal min, qreal max, int tickCount,bool niceNumbers); |
|
47 | 47 | |
|
48 | 48 | public Q_SLOTS: |
|
49 | 49 | void handleAxisRangeChanged(qreal min, qreal max,int count); |
|
50 | 50 | |
|
51 | 51 | public: |
|
52 | 52 | ChartAxis* createGraphics(ChartPresenter* presenter); |
|
53 | 53 | |
|
54 | 54 | protected: |
|
55 |
void setMin(const |
|
|
56 |
void setMax(const |
|
|
57 |
void setRange(const |
|
|
55 | void setMin(const qreal min); | |
|
56 | void setMax(const qreal max); | |
|
57 | void setRange(const qreal min, const qreal max); | |
|
58 | 58 | int ticksCount() const; |
|
59 | 59 | |
|
60 | 60 | private: |
|
61 | qreal m_min; | |
|
62 | qreal m_max; | |
|
63 | 61 | bool m_niceNumbers; |
|
64 | int m_ticksCount; | |
|
65 | 62 | Q_DECLARE_PUBLIC(QValuesAxis) |
|
66 | 63 | }; |
|
67 | 64 | |
|
68 | 65 | QTCOMMERCIALCHART_END_NAMESPACE |
|
69 | 66 | |
|
70 | 67 | #endif // QVALUESAXIS_P_H |
@@ -1,731 +1,732 | |||
|
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 "qbarseries.h" |
|
22 | 22 | #include "qbarseries_p.h" |
|
23 | 23 | #include "qbarset.h" |
|
24 | 24 | #include "qbarset_p.h" |
|
25 | 25 | #include "domain_p.h" |
|
26 | 26 | #include "legendmarker_p.h" |
|
27 | 27 | #include "chartdataset_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | #include "chartanimator_p.h" |
|
30 | 30 | #include "qvaluesaxis.h" |
|
31 | #include "qcategoriesaxis.h" | |
|
31 | 32 | |
|
32 | 33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | 34 | |
|
34 | 35 | /*! |
|
35 | 36 | \class QBarSeries |
|
36 | 37 | \brief Series for creating a bar chart |
|
37 | 38 | \mainclass |
|
38 | 39 | |
|
39 | 40 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
40 | 41 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
41 | 42 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
42 | 43 | shows the x-values. |
|
43 | 44 | |
|
44 | 45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
45 | 46 | \image examples_barchart.png |
|
46 | 47 | |
|
47 | 48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
48 | 49 | */ |
|
49 | 50 | /*! |
|
50 | 51 | \qmlclass BarSeries QBarSeries |
|
51 | 52 | \inherits AbstractSeries |
|
52 | 53 | |
|
53 | 54 | The following QML shows how to create a simple bar chart: |
|
54 | 55 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
55 | 56 | |
|
56 | 57 | \beginfloatleft |
|
57 | 58 | \image demos_qmlchart6.png |
|
58 | 59 | \endfloat |
|
59 | 60 | \clearfloat |
|
60 | 61 | */ |
|
61 | 62 | |
|
62 | 63 | /*! |
|
63 | 64 | \property QBarSeries::barWidth |
|
64 | 65 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
65 | 66 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
66 | 67 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
67 | 68 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
68 | 69 | \sa QGroupedBarSeries |
|
69 | 70 | */ |
|
70 | 71 | /*! |
|
71 | 72 | \qmlproperty real BarSeries::barWidth |
|
72 | 73 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
73 | 74 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
74 | 75 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
75 | 76 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
76 | 77 | */ |
|
77 | 78 | |
|
78 | 79 | /*! |
|
79 | 80 | \property QBarSeries::count |
|
80 | 81 | Holds the number of sets in series. |
|
81 | 82 | */ |
|
82 | 83 | /*! |
|
83 | 84 | \qmlproperty int BarSeries::count |
|
84 | 85 | Holds the number of sets in series. |
|
85 | 86 | */ |
|
86 | 87 | |
|
87 | 88 | /*! |
|
88 | 89 | \property QBarSeries::labelsVisible |
|
89 | 90 | Defines the visibility of the labels in series |
|
90 | 91 | */ |
|
91 | 92 | /*! |
|
92 | 93 | \qmlproperty bool BarSeries::labelsVisible |
|
93 | 94 | Defines the visibility of the labels in series |
|
94 | 95 | */ |
|
95 | 96 | |
|
96 | 97 | /*! |
|
97 | 98 | \fn void QBarSeries::clicked(int index, QBarSet *barset) |
|
98 | 99 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
99 | 100 | Clicked bar inside set is indexed by \a index |
|
100 | 101 | */ |
|
101 | 102 | /*! |
|
102 | 103 | \qmlsignal BarSeries::onClicked(int index, BarSet barset) |
|
103 | 104 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
104 | 105 | Clicked bar inside set is indexed by \a index |
|
105 | 106 | */ |
|
106 | 107 | |
|
107 | 108 | /*! |
|
108 | 109 | \fn void QBarSeries::hovered(bool status, QBarSet* barset) |
|
109 | 110 | |
|
110 | 111 | The signal is emitted if mouse is hovered on top of series. |
|
111 | 112 | Parameter \a barset is the pointer of barset, where hover happened. |
|
112 | 113 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
113 | 114 | */ |
|
114 | 115 | /*! |
|
115 | 116 | \qmlsignal BarSeries::onHovered(bool status, BarSet barset) |
|
116 | 117 | |
|
117 | 118 | The signal is emitted if mouse is hovered on top of series. |
|
118 | 119 | Parameter \a barset is the pointer of barset, where hover happened. |
|
119 | 120 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
120 | 121 | */ |
|
121 | 122 | |
|
122 | 123 | /*! |
|
123 | 124 | \fn void QBarSeries::countChanged() |
|
124 | 125 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
125 | 126 | */ |
|
126 | 127 | /*! |
|
127 | 128 | \qmlsignal BarSeries::onCountChanged() |
|
128 | 129 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
129 | 130 | */ |
|
130 | 131 | |
|
131 | 132 | /*! |
|
132 | 133 | \fn void QBarSeries::labelsVisibleChanged() |
|
133 | 134 | This signal is emitted when labels visibility have changed. |
|
134 | 135 | \sa isLabelsVisible(), setLabelsVisible() |
|
135 | 136 | */ |
|
136 | 137 | |
|
137 | 138 | /*! |
|
138 | 139 | \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
139 | 140 | This signal is emitted when \a sets have been added to the series. |
|
140 | 141 | \sa append(), insert() |
|
141 | 142 | */ |
|
142 | 143 | /*! |
|
143 | 144 | \qmlsignal BarSeries::onAdded(BarSet barset) |
|
144 | 145 | Emitted when \a barset has been added to the series. |
|
145 | 146 | */ |
|
146 | 147 | |
|
147 | 148 | /*! |
|
148 | 149 | \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
149 | 150 | This signal is emitted when \a sets have been removed from the series. |
|
150 | 151 | \sa remove() |
|
151 | 152 | */ |
|
152 | 153 | /*! |
|
153 | 154 | \qmlsignal BarSeries::onRemoved(BarSet barset) |
|
154 | 155 | Emitted when \a barset has been removed from the series. |
|
155 | 156 | */ |
|
156 | 157 | |
|
157 | 158 | /*! |
|
158 | 159 | \qmlmethod BarSet BarSeries::at(int index) |
|
159 | 160 | Returns bar set at \a index. Returns null if the index is not valid. |
|
160 | 161 | */ |
|
161 | 162 | |
|
162 | 163 | /*! |
|
163 | 164 | \qmlmethod BarSet BarSeries::append(string label, VariantList values) |
|
164 | 165 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
165 | 166 | For example: |
|
166 | 167 | \code |
|
167 | 168 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
168 | 169 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); |
|
169 | 170 | \endcode |
|
170 | 171 | */ |
|
171 | 172 | |
|
172 | 173 | /*! |
|
173 | 174 | \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values) |
|
174 | 175 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
175 | 176 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
176 | 177 | appended. |
|
177 | 178 | \sa BarSeries::append() |
|
178 | 179 | */ |
|
179 | 180 | |
|
180 | 181 | /*! |
|
181 | 182 | \qmlmethod bool BarSeries::remove(BarSet barset) |
|
182 | 183 | Removes the barset from the series. Returns true if successfull, false otherwise. |
|
183 | 184 | */ |
|
184 | 185 | |
|
185 | 186 | /*! |
|
186 | 187 | \qmlmethod BarSeries::clear() |
|
187 | 188 | Removes all barsets from the series. |
|
188 | 189 | */ |
|
189 | 190 | |
|
190 | 191 | /*! |
|
191 | 192 | Constructs empty QBarSeries. |
|
192 | 193 | QBarSeries is QObject which is a child of a \a parent. |
|
193 | 194 | */ |
|
194 | 195 | QBarSeries::QBarSeries(QObject *parent) : |
|
195 | 196 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) |
|
196 | 197 | { |
|
197 | 198 | } |
|
198 | 199 | |
|
199 | 200 | /*! |
|
200 | 201 | Destructs barseries and owned barsets. |
|
201 | 202 | */ |
|
202 | 203 | QBarSeries::~QBarSeries() |
|
203 | 204 | { |
|
204 | 205 | Q_D(QBarSeries); |
|
205 | 206 | if(d->m_dataset){ |
|
206 | 207 | d->m_dataset->removeSeries(this); |
|
207 | 208 | } |
|
208 | 209 | } |
|
209 | 210 | |
|
210 | 211 | /*! |
|
211 | 212 | \internal |
|
212 | 213 | */ |
|
213 | 214 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : |
|
214 | 215 | QAbstractSeries(d,parent) |
|
215 | 216 | { |
|
216 | 217 | } |
|
217 | 218 | |
|
218 | 219 | /*! |
|
219 | 220 | Returns the type of series. Derived classes override this. |
|
220 | 221 | */ |
|
221 | 222 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
222 | 223 | { |
|
223 | 224 | return QAbstractSeries::SeriesTypeBar; |
|
224 | 225 | } |
|
225 | 226 | |
|
226 | 227 | /*! |
|
227 | 228 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
228 | 229 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
229 | 230 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
230 | 231 | Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
231 | 232 | */ |
|
232 | 233 | void QBarSeries::setBarWidth(qreal width) |
|
233 | 234 | { |
|
234 | 235 | Q_D(QBarSeries); |
|
235 | 236 | d->setBarWidth(width); |
|
236 | 237 | } |
|
237 | 238 | |
|
238 | 239 | /*! |
|
239 | 240 | Returns the width of the bars of the series. |
|
240 | 241 | \sa setBarWidth() |
|
241 | 242 | */ |
|
242 | 243 | qreal QBarSeries::barWidth() const |
|
243 | 244 | { |
|
244 | 245 | Q_D(const QBarSeries); |
|
245 | 246 | return d->barWidth(); |
|
246 | 247 | } |
|
247 | 248 | |
|
248 | 249 | /*! |
|
249 | 250 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
250 | 251 | Returns true, if appending succeeded. |
|
251 | 252 | */ |
|
252 | 253 | bool QBarSeries::append(QBarSet *set) |
|
253 | 254 | { |
|
254 | 255 | Q_D(QBarSeries); |
|
255 | 256 | bool success = d->append(set); |
|
256 | 257 | if (success) { |
|
257 | 258 | QList<QBarSet*> sets; |
|
258 | 259 | sets.append(set); |
|
259 | 260 | emit barsetsAdded(sets); |
|
260 | 261 | emit countChanged(); |
|
261 | 262 | } |
|
262 | 263 | return success; |
|
263 | 264 | } |
|
264 | 265 | |
|
265 | 266 | /*! |
|
266 | 267 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
267 | 268 | Returns true, if set was removed. |
|
268 | 269 | */ |
|
269 | 270 | bool QBarSeries::remove(QBarSet *set) |
|
270 | 271 | { |
|
271 | 272 | Q_D(QBarSeries); |
|
272 | 273 | bool success = d->remove(set); |
|
273 | 274 | if (success) { |
|
274 | 275 | QList<QBarSet*> sets; |
|
275 | 276 | sets.append(set); |
|
276 | 277 | emit barsetsRemoved(sets); |
|
277 | 278 | emit countChanged(); |
|
278 | 279 | } |
|
279 | 280 | return success; |
|
280 | 281 | } |
|
281 | 282 | |
|
282 | 283 | /*! |
|
283 | 284 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
284 | 285 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
285 | 286 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
286 | 287 | and function returns false. |
|
287 | 288 | */ |
|
288 | 289 | bool QBarSeries::append(QList<QBarSet* > sets) |
|
289 | 290 | { |
|
290 | 291 | Q_D(QBarSeries); |
|
291 | 292 | bool success = d->append(sets); |
|
292 | 293 | if (success) { |
|
293 | 294 | emit barsetsAdded(sets); |
|
294 | 295 | emit countChanged(); |
|
295 | 296 | } |
|
296 | 297 | return success; |
|
297 | 298 | } |
|
298 | 299 | |
|
299 | 300 | /*! |
|
300 | 301 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
301 | 302 | Returns true, if inserting succeeded. |
|
302 | 303 | |
|
303 | 304 | */ |
|
304 | 305 | bool QBarSeries::insert(int index, QBarSet *set) |
|
305 | 306 | { |
|
306 | 307 | Q_D(QBarSeries); |
|
307 | 308 | bool success = d->insert(index, set); |
|
308 | 309 | if (success) { |
|
309 | 310 | QList<QBarSet*> sets; |
|
310 | 311 | sets.append(set); |
|
311 | 312 | emit barsetsAdded(sets); |
|
312 | 313 | emit countChanged(); |
|
313 | 314 | } |
|
314 | 315 | return success; |
|
315 | 316 | } |
|
316 | 317 | |
|
317 | 318 | /*! |
|
318 | 319 | Removes all of the bar sets from the series |
|
319 | 320 | */ |
|
320 | 321 | void QBarSeries::clear() |
|
321 | 322 | { |
|
322 | 323 | Q_D(QBarSeries); |
|
323 | 324 | QList<QBarSet *> sets = barSets(); |
|
324 | 325 | bool success = d->remove(sets); |
|
325 | 326 | if (success) { |
|
326 | 327 | emit barsetsRemoved(sets); |
|
327 | 328 | emit countChanged(); |
|
328 | 329 | } |
|
329 | 330 | } |
|
330 | 331 | |
|
331 | 332 | /*! |
|
332 | 333 | Returns number of sets in series. |
|
333 | 334 | */ |
|
334 | 335 | int QBarSeries::count() const |
|
335 | 336 | { |
|
336 | 337 | Q_D(const QBarSeries); |
|
337 | 338 | return d->m_barSets.count(); |
|
338 | 339 | } |
|
339 | 340 | |
|
340 | 341 | /*! |
|
341 | 342 | Returns a list of sets in series. Keeps ownership of sets. |
|
342 | 343 | */ |
|
343 | 344 | QList<QBarSet*> QBarSeries::barSets() const |
|
344 | 345 | { |
|
345 | 346 | Q_D(const QBarSeries); |
|
346 | 347 | return d->m_barSets; |
|
347 | 348 | } |
|
348 | 349 | |
|
349 | 350 | /*! |
|
350 | 351 | Sets the visibility of labels in series to \a visible |
|
351 | 352 | */ |
|
352 | 353 | void QBarSeries::setLabelsVisible(bool visible) |
|
353 | 354 | { |
|
354 | 355 | Q_D(QBarSeries); |
|
355 | 356 | if (d->m_labelsVisible != visible) { |
|
356 | 357 | d->setLabelsVisible(visible); |
|
357 | 358 | emit labelsVisibleChanged(); |
|
358 | 359 | } |
|
359 | 360 | } |
|
360 | 361 | |
|
361 | 362 | /*! |
|
362 | 363 | Returns the visibility of labels |
|
363 | 364 | */ |
|
364 | 365 | bool QBarSeries::isLabelsVisible() const |
|
365 | 366 | { |
|
366 | 367 | Q_D(const QBarSeries); |
|
367 | 368 | return d->m_labelsVisible; |
|
368 | 369 | } |
|
369 | 370 | |
|
370 | 371 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
371 | 372 | |
|
372 | 373 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : |
|
373 | 374 | QAbstractSeriesPrivate(q), |
|
374 | 375 | m_barWidth(0.5), // Default value is 50% of category width |
|
375 | 376 | m_labelsVisible(false), |
|
376 | 377 | m_visible(true) |
|
377 | 378 | { |
|
378 | 379 | } |
|
379 | 380 | |
|
380 | 381 | int QBarSeriesPrivate::categoryCount() const |
|
381 | 382 | { |
|
382 | 383 | // No categories defined. return count of longest set. |
|
383 | 384 | int count = 0; |
|
384 | 385 | for (int i=0; i<m_barSets.count(); i++) { |
|
385 | 386 | if (m_barSets.at(i)->count() > count) { |
|
386 | 387 | count = m_barSets.at(i)->count(); |
|
387 | 388 | } |
|
388 | 389 | } |
|
389 | 390 | |
|
390 | 391 | return count; |
|
391 | 392 | } |
|
392 | 393 | |
|
393 | 394 | void QBarSeriesPrivate::setBarWidth(qreal width) |
|
394 | 395 | { |
|
395 | 396 | if (width < 0.0) { |
|
396 | 397 | width = 0.0; |
|
397 | 398 | } |
|
398 | 399 | m_barWidth = width; |
|
399 | 400 | emit updatedBars(); |
|
400 | 401 | } |
|
401 | 402 | |
|
402 | 403 | qreal QBarSeriesPrivate::barWidth() const |
|
403 | 404 | { |
|
404 | 405 | return m_barWidth; |
|
405 | 406 | } |
|
406 | 407 | |
|
407 | 408 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
408 | 409 | { |
|
409 | 410 | return m_barSets.at(index); |
|
410 | 411 | } |
|
411 | 412 | |
|
412 | 413 | void QBarSeriesPrivate::setVisible(bool visible) |
|
413 | 414 | { |
|
414 | 415 | m_visible = visible; |
|
415 | 416 | emit updatedBars(); |
|
416 | 417 | } |
|
417 | 418 | |
|
418 | 419 | void QBarSeriesPrivate::setLabelsVisible(bool visible) |
|
419 | 420 | { |
|
420 | 421 | m_labelsVisible = visible; |
|
421 | 422 | emit labelsVisibleChanged(visible); |
|
422 | 423 | } |
|
423 | 424 | |
|
424 | 425 | qreal QBarSeriesPrivate::min() |
|
425 | 426 | { |
|
426 | 427 | if (m_barSets.count() <= 0) { |
|
427 | 428 | return 0; |
|
428 | 429 | } |
|
429 | 430 | qreal min = INT_MAX; |
|
430 | 431 | |
|
431 | 432 | for (int i = 0; i < m_barSets.count(); i++) { |
|
432 | 433 | int categoryCount = m_barSets.at(i)->count(); |
|
433 | 434 | for (int j = 0; j < categoryCount; j++) { |
|
434 | 435 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
435 | 436 | if (temp < min) |
|
436 | 437 | min = temp; |
|
437 | 438 | } |
|
438 | 439 | } |
|
439 | 440 | return min; |
|
440 | 441 | } |
|
441 | 442 | |
|
442 | 443 | qreal QBarSeriesPrivate::max() |
|
443 | 444 | { |
|
444 | 445 | if (m_barSets.count() <= 0) { |
|
445 | 446 | return 0; |
|
446 | 447 | } |
|
447 | 448 | qreal max = INT_MIN; |
|
448 | 449 | |
|
449 | 450 | for (int i = 0; i < m_barSets.count(); i++) { |
|
450 | 451 | int categoryCount = m_barSets.at(i)->count(); |
|
451 | 452 | for (int j = 0; j < categoryCount; j++) { |
|
452 | 453 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
453 | 454 | if (temp > max) |
|
454 | 455 | max = temp; |
|
455 | 456 | } |
|
456 | 457 | } |
|
457 | 458 | |
|
458 | 459 | return max; |
|
459 | 460 | } |
|
460 | 461 | |
|
461 | 462 | qreal QBarSeriesPrivate::valueAt(int set, int category) |
|
462 | 463 | { |
|
463 | 464 | if ((set < 0) || (set >= m_barSets.count())) { |
|
464 | 465 | // No set, no value. |
|
465 | 466 | return 0; |
|
466 | 467 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
467 | 468 | // No category, no value. |
|
468 | 469 | return 0; |
|
469 | 470 | } |
|
470 | 471 | |
|
471 | 472 | return m_barSets.at(set)->at(category).y(); |
|
472 | 473 | } |
|
473 | 474 | |
|
474 | 475 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
|
475 | 476 | { |
|
476 | 477 | if ((set < 0) || (set >= m_barSets.count())) { |
|
477 | 478 | // No set, no value. |
|
478 | 479 | return 0; |
|
479 | 480 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
480 | 481 | // No category, no value. |
|
481 | 482 | return 0; |
|
482 | 483 | } |
|
483 | 484 | |
|
484 | 485 | qreal value = m_barSets.at(set)->at(category).y(); |
|
485 | 486 | qreal sum = categorySum(category); |
|
486 | 487 | if ( qFuzzyIsNull(sum) ) { |
|
487 | 488 | return 0; |
|
488 | 489 | } |
|
489 | 490 | |
|
490 | 491 | return value / sum; |
|
491 | 492 | } |
|
492 | 493 | |
|
493 | 494 | qreal QBarSeriesPrivate::categorySum(int category) |
|
494 | 495 | { |
|
495 | 496 | qreal sum(0); |
|
496 | 497 | int count = m_barSets.count(); // Count sets |
|
497 | 498 | for (int set = 0; set < count; set++) { |
|
498 | 499 | if (category < m_barSets.at(set)->count()) |
|
499 | 500 | sum += m_barSets.at(set)->at(category).y(); |
|
500 | 501 | } |
|
501 | 502 | return sum; |
|
502 | 503 | } |
|
503 | 504 | |
|
504 | 505 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) |
|
505 | 506 | { |
|
506 | 507 | qreal sum(0); |
|
507 | 508 | int count = m_barSets.count(); // Count sets |
|
508 | 509 | for (int set = 0; set < count; set++) { |
|
509 | 510 | if (category < m_barSets.at(set)->count()) |
|
510 | 511 | sum += qAbs(m_barSets.at(set)->at(category).y()); |
|
511 | 512 | } |
|
512 | 513 | return sum; |
|
513 | 514 | } |
|
514 | 515 | |
|
515 | 516 | qreal QBarSeriesPrivate::maxCategorySum() |
|
516 | 517 | { |
|
517 | 518 | qreal max = INT_MIN; |
|
518 | 519 | int count = categoryCount(); |
|
519 | 520 | for (int i = 0; i < count; i++) { |
|
520 | 521 | qreal sum = categorySum(i); |
|
521 | 522 | if (sum > max) |
|
522 | 523 | max = sum; |
|
523 | 524 | } |
|
524 | 525 | return max; |
|
525 | 526 | } |
|
526 | 527 | |
|
527 | 528 | qreal QBarSeriesPrivate::minX() |
|
528 | 529 | { |
|
529 | 530 | if (m_barSets.count() <= 0) { |
|
530 | 531 | return 0; |
|
531 | 532 | } |
|
532 | 533 | qreal min = INT_MAX; |
|
533 | 534 | |
|
534 | 535 | for (int i = 0; i < m_barSets.count(); i++) { |
|
535 | 536 | int categoryCount = m_barSets.at(i)->count(); |
|
536 | 537 | for (int j = 0; j < categoryCount; j++) { |
|
537 | 538 | qreal temp = m_barSets.at(i)->at(j).x(); |
|
538 | 539 | if (temp < min) |
|
539 | 540 | min = temp; |
|
540 | 541 | } |
|
541 | 542 | } |
|
542 | 543 | return min; |
|
543 | 544 | } |
|
544 | 545 | |
|
545 | 546 | qreal QBarSeriesPrivate::maxX() |
|
546 | 547 | { |
|
547 | 548 | if (m_barSets.count() <= 0) { |
|
548 | 549 | return 0; |
|
549 | 550 | } |
|
550 | 551 | qreal max = INT_MIN; |
|
551 | 552 | |
|
552 | 553 | for (int i = 0; i < m_barSets.count(); i++) { |
|
553 | 554 | int categoryCount = m_barSets.at(i)->count(); |
|
554 | 555 | for (int j = 0; j < categoryCount; j++) { |
|
555 | 556 | qreal temp = m_barSets.at(i)->at(j).x(); |
|
556 | 557 | if (temp > max) |
|
557 | 558 | max = temp; |
|
558 | 559 | } |
|
559 | 560 | } |
|
560 | 561 | |
|
561 | 562 | return max; |
|
562 | 563 | } |
|
563 | 564 | |
|
564 | 565 | |
|
565 | 566 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
566 | 567 | { |
|
567 | 568 | qreal minX(domain.minX()); |
|
568 | 569 | qreal minY(domain.minY()); |
|
569 | 570 | qreal maxX(domain.maxX()); |
|
570 | 571 | qreal maxY(domain.maxY()); |
|
571 | 572 | int tickXCount(domain.tickXCount()); |
|
572 | 573 | int tickYCount(domain.tickYCount()); |
|
573 | 574 | |
|
574 | 575 | qreal seriesMinX = this->minX(); |
|
575 | 576 | qreal seriesMaxX = this->maxX(); |
|
576 | 577 | qreal y = max(); |
|
577 | 578 | minX = qMin(minX, seriesMinX - 0.5); |
|
578 | 579 | minY = qMin(minY, y); |
|
579 | 580 | maxX = qMax(maxX, seriesMaxX + 0.5); |
|
580 | 581 | maxY = qMax(maxY, y); |
|
581 | 582 | tickXCount = categoryCount()+1; |
|
582 | 583 | |
|
583 | 584 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
584 | 585 | } |
|
585 | 586 | |
|
586 | 587 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
587 | 588 | { |
|
588 | 589 | Q_Q(QBarSeries); |
|
589 | 590 | |
|
590 | 591 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
591 | 592 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
592 | 593 | presenter->animator()->addAnimation(bar); |
|
593 | 594 | } |
|
594 | 595 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
595 | 596 | return bar; |
|
596 | 597 | |
|
597 | 598 | } |
|
598 | 599 | |
|
599 | 600 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
600 | 601 | { |
|
601 | 602 | Q_Q(QBarSeries); |
|
602 | 603 | QList<LegendMarker*> markers; |
|
603 | 604 | foreach(QBarSet* set, q->barSets()) { |
|
604 | 605 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
605 | 606 | markers << marker; |
|
606 | 607 | } |
|
607 | 608 | |
|
608 | 609 | return markers; |
|
609 | 610 | } |
|
610 | 611 | |
|
611 | 612 | QAbstractAxis* QBarSeriesPrivate::createAxisX(QObject* parent) |
|
612 | 613 | { |
|
613 |
return new Q |
|
|
614 | return new QCategoriesAxis(parent); | |
|
614 | 615 | } |
|
615 | 616 | |
|
616 | 617 | QAbstractAxis* QBarSeriesPrivate::createAxisY(QObject* parent) |
|
617 | 618 | { |
|
618 | 619 | return new QValuesAxis(parent); |
|
619 | 620 | } |
|
620 | 621 | |
|
621 | 622 | bool QBarSeriesPrivate::append(QBarSet *set) |
|
622 | 623 | { |
|
623 | 624 | Q_Q(QBarSeries); |
|
624 | 625 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
625 | 626 | // Fail if set is already in list or set is null. |
|
626 | 627 | return false; |
|
627 | 628 | } |
|
628 | 629 | m_barSets.append(set); |
|
629 | 630 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
630 | 631 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
631 | 632 | emit restructuredBars(); // this notifies barchartitem |
|
632 | 633 | if (m_dataset) { |
|
633 | 634 | m_dataset->updateSeries(q); // this notifies legend |
|
634 | 635 | } |
|
635 | 636 | return true; |
|
636 | 637 | } |
|
637 | 638 | |
|
638 | 639 | bool QBarSeriesPrivate::remove(QBarSet *set) |
|
639 | 640 | { |
|
640 | 641 | Q_Q(QBarSeries); |
|
641 | 642 | if (!m_barSets.contains(set)) { |
|
642 | 643 | // Fail if set is not in list |
|
643 | 644 | return false; |
|
644 | 645 | } |
|
645 | 646 | m_barSets.removeOne(set); |
|
646 | 647 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
647 | 648 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
648 | 649 | emit restructuredBars(); // this notifies barchartitem |
|
649 | 650 | if (m_dataset) { |
|
650 | 651 | m_dataset->updateSeries(q); // this notifies legend |
|
651 | 652 | } |
|
652 | 653 | return true; |
|
653 | 654 | } |
|
654 | 655 | |
|
655 | 656 | bool QBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
656 | 657 | { |
|
657 | 658 | Q_Q(QBarSeries); |
|
658 | 659 | foreach (QBarSet* set, sets) { |
|
659 | 660 | if ((set == 0) || (m_barSets.contains(set))) { |
|
660 | 661 | // Fail if any of the sets is null or is already appended. |
|
661 | 662 | return false; |
|
662 | 663 | } |
|
663 | 664 | if (sets.count(set) != 1) { |
|
664 | 665 | // Also fail if same set is more than once in given list. |
|
665 | 666 | return false; |
|
666 | 667 | } |
|
667 | 668 | } |
|
668 | 669 | |
|
669 | 670 | foreach (QBarSet* set, sets) { |
|
670 | 671 | m_barSets.append(set); |
|
671 | 672 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
672 | 673 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
673 | 674 | } |
|
674 | 675 | emit restructuredBars(); // this notifies barchartitem |
|
675 | 676 | if (m_dataset) { |
|
676 | 677 | m_dataset->updateSeries(q); // this notifies legend |
|
677 | 678 | } |
|
678 | 679 | return true; |
|
679 | 680 | } |
|
680 | 681 | |
|
681 | 682 | bool QBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
682 | 683 | { |
|
683 | 684 | Q_Q(QBarSeries); |
|
684 | 685 | if (sets.count() == 0) { |
|
685 | 686 | return false; |
|
686 | 687 | } |
|
687 | 688 | foreach (QBarSet* set, sets) { |
|
688 | 689 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
689 | 690 | // Fail if any of the sets is null or is not in series |
|
690 | 691 | return false; |
|
691 | 692 | } |
|
692 | 693 | if (sets.count(set) != 1) { |
|
693 | 694 | // Also fail if same set is more than once in given list. |
|
694 | 695 | return false; |
|
695 | 696 | } |
|
696 | 697 | } |
|
697 | 698 | |
|
698 | 699 | foreach (QBarSet* set, sets) { |
|
699 | 700 | m_barSets.removeOne(set); |
|
700 | 701 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
701 | 702 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
702 | 703 | } |
|
703 | 704 | |
|
704 | 705 | emit restructuredBars(); // this notifies barchartitem |
|
705 | 706 | if (m_dataset) { |
|
706 | 707 | m_dataset->updateSeries(q); // this notifies legend |
|
707 | 708 | } |
|
708 | 709 | return true; |
|
709 | 710 | } |
|
710 | 711 | |
|
711 | 712 | bool QBarSeriesPrivate::insert(int index, QBarSet *set) |
|
712 | 713 | { |
|
713 | 714 | Q_Q(QBarSeries); |
|
714 | 715 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
715 | 716 | // Fail if set is already in list or set is null. |
|
716 | 717 | return false; |
|
717 | 718 | } |
|
718 | 719 | m_barSets.insert(index, set); |
|
719 | 720 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
720 | 721 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
721 | 722 | emit restructuredBars(); // this notifies barchartitem |
|
722 | 723 | if (m_dataset) { |
|
723 | 724 | m_dataset->updateSeries(q); // this notifies legend |
|
724 | 725 | } |
|
725 | 726 | return true; |
|
726 | 727 | } |
|
727 | 728 | |
|
728 | 729 | #include "moc_qbarseries.cpp" |
|
729 | 730 | #include "moc_qbarseries_p.cpp" |
|
730 | 731 | |
|
731 | 732 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now