@@ -1,604 +1,587 | |||
|
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 | \property QAxis::labelsFont | |
|
126 | \property QAbstractAxis::labelsFont | |
|
127 | 127 | The font of the axis labels. |
|
128 | 128 | */ |
|
129 | ||
|
129 | 130 | /*! |
|
130 | 131 | \qmlproperty Font Axis::labelsFont |
|
131 | 132 | The font of the axis labels. |
|
132 | 133 | |
|
133 | 134 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
134 | 135 | */ |
|
135 | 136 | |
|
136 | 137 | /*! |
|
137 | 138 | \property QAbstractAxis::labelsColor |
|
138 | 139 | The color of the axis labels. |
|
139 | 140 | */ |
|
140 | 141 | /*! |
|
141 | 142 | \qmlproperty color Axis::labelsColor |
|
142 | 143 | The color of the axis labels. |
|
143 | 144 | */ |
|
144 | 145 | |
|
145 | 146 | /*! |
|
146 | 147 | \property QAbstractAxis::labelsAngle |
|
147 | 148 | The angle of the axis labels in degrees. |
|
148 | 149 | */ |
|
149 | 150 | /*! |
|
150 | 151 | \qmlproperty int Axis::labelsAngle |
|
151 | 152 | The angle of the axis labels in degrees. |
|
152 | 153 | */ |
|
153 | 154 | |
|
154 | 155 | /*! |
|
155 | 156 | \property QAbstractAxis::shadesVisible |
|
156 | 157 | The visibility of the axis shades. |
|
157 | 158 | */ |
|
158 | 159 | /*! |
|
159 | 160 | \qmlproperty bool Axis::shadesVisible |
|
160 | 161 | The visibility of the axis shades. |
|
161 | 162 | */ |
|
162 | 163 | |
|
163 | 164 | /*! |
|
164 | 165 | \property QAbstractAxis::shadesColor |
|
165 | 166 | The fill (brush) color of the axis shades. |
|
166 | 167 | */ |
|
167 | 168 | /*! |
|
168 | 169 | \qmlproperty color Axis::shadesColor |
|
169 | 170 | The fill (brush) color of the axis shades. |
|
170 | 171 | */ |
|
171 | 172 | |
|
172 | 173 | /*! |
|
173 | 174 | \property QAbstractAxis::shadesBorderColor |
|
174 | 175 | The border (pen) color of the axis shades. |
|
175 | 176 | */ |
|
176 | 177 | /*! |
|
177 | 178 | \qmlproperty color Axis::shadesBorderColor |
|
178 | 179 | The border (pen) color of the axis shades. |
|
179 | 180 | */ |
|
180 | 181 | |
|
181 | 182 | /*! |
|
182 | \property QAbstractAxis::ticksCount | |
|
183 | The number of tick marks for the axis. | |
|
184 | */ | |
|
185 | /*! | |
|
186 | \qmlproperty int Axis::ticksCount | |
|
187 | The number of tick marks for the axis. | |
|
188 | */ | |
|
189 | ||
|
190 | /*! | |
|
191 | \property QAbstractAxis::niceNumbersEnabled | |
|
192 | Whether the nice numbers algorithm is enabled or not for the axis. | |
|
193 | */ | |
|
194 | /*! | |
|
195 | \qmlproperty bool Axis::niceNumbersEnabled | |
|
196 | Whether the nice numbers algorithm is enabled or not for the axis. | |
|
197 | */ | |
|
198 | ||
|
199 | /*! | |
|
200 | 183 | \fn void QAbstractAxis::visibleChanged(bool) |
|
201 | 184 | Visiblity of the axis has changed to \a visible. |
|
202 | 185 | */ |
|
203 | 186 | |
|
204 | 187 | /*! |
|
205 | 188 | \fn void QAbstractAxis::labelsVisibleChanged(bool) |
|
206 | 189 | Visiblity of the labels of the axis has changed to \a visible. |
|
207 | 190 | */ |
|
208 | 191 | |
|
209 | 192 | /*! |
|
210 | 193 | \fn void QAbstractAxis::gridVisibleChanged(bool) |
|
211 | 194 | Visiblity of the grid lines of the axis has changed to \a visible. |
|
212 | 195 | */ |
|
213 | 196 | |
|
214 |
/* |
|
|
197 | /* | |
|
215 | 198 | \fn void QAbstractAxis::minChanged(qreal min) |
|
216 | 199 | Axis emits signal when \a min of axis has changed. |
|
217 | 200 | */ |
|
218 | 201 | |
|
219 |
/* |
|
|
202 | /* | |
|
220 | 203 | \fn void QAbstractAxis::maxChanged(qreal max) |
|
221 | 204 | Axis emits signal when \a max of axis has changed. |
|
222 | 205 | */ |
|
223 | 206 | |
|
224 |
/* |
|
|
207 | /* | |
|
225 | 208 | \fn void QAbstractAxis::rangeChanged(qreal min, qreal max) |
|
226 | 209 | Axis emits signal when \a min or \a max of axis has changed. |
|
227 | 210 | */ |
|
228 | 211 | |
|
229 |
/* |
|
|
212 | /* | |
|
230 | 213 | \fn QChartAxisCategories* QAbstractAxis::categories() |
|
231 | 214 | Returns pointer to the list of categories which correspond to the values on the axis. |
|
232 | 215 | */ |
|
233 | 216 | |
|
234 | 217 | /*! |
|
235 | 218 | \fn void QAbstractAxis::colorChanged(QColor) |
|
236 | 219 | Emitted if the \a color of the axis is changed. |
|
237 | 220 | */ |
|
238 | 221 | |
|
239 | 222 | /*! |
|
240 | 223 | \fn void QAbstractAxis::labelsColorChanged(QColor) |
|
241 | 224 | Emitted if the \a color of the axis labels is changed. |
|
242 | 225 | */ |
|
243 | 226 | |
|
244 | 227 | /*! |
|
245 | 228 | \fn void QAbstractAxis::shadesVisibleChanged(bool) |
|
246 | 229 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
247 | 230 | */ |
|
248 | 231 | |
|
249 | 232 | /*! |
|
250 | 233 | \fn void QAbstractAxis::shadesColorChanged(QColor) |
|
251 | 234 | Emitted if the \a color of the axis shades is changed. |
|
252 | 235 | */ |
|
253 | 236 | |
|
254 | 237 | /*! |
|
255 | 238 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) |
|
256 | 239 | Emitted if the border \a color of the axis shades is changed. |
|
257 | 240 | */ |
|
258 | 241 | |
|
259 | 242 | /*! |
|
260 | 243 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
261 | 244 | QChart when axis added. |
|
262 | 245 | */ |
|
263 | 246 | |
|
264 | 247 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) : |
|
265 | 248 | QObject(parent), |
|
266 | 249 | d_ptr(&d) |
|
267 | 250 | { |
|
268 | 251 | } |
|
269 | 252 | |
|
270 | 253 | /*! |
|
271 | 254 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
272 | 255 | */ |
|
273 | 256 | |
|
274 | 257 | QAbstractAxis::~QAbstractAxis() |
|
275 | 258 | { |
|
276 | 259 | } |
|
277 | 260 | |
|
278 | 261 | /*! |
|
279 | 262 | Sets \a pen used to draw axis line and ticks. |
|
280 | 263 | */ |
|
281 | 264 | void QAbstractAxis::setAxisPen(const QPen &pen) |
|
282 | 265 | { |
|
283 | 266 | if (d_ptr->m_axisPen!=pen) { |
|
284 | 267 | d_ptr->m_axisPen = pen; |
|
285 | 268 | emit d_ptr->updated(); |
|
286 | 269 | } |
|
287 | 270 | } |
|
288 | 271 | |
|
289 | 272 | /*! |
|
290 | 273 | Returns pen used to draw axis and ticks. |
|
291 | 274 | */ |
|
292 | 275 | QPen QAbstractAxis::axisPen() const |
|
293 | 276 | { |
|
294 | 277 | return d_ptr->m_axisPen; |
|
295 | 278 | } |
|
296 | 279 | |
|
297 | 280 | void QAbstractAxis::setAxisPenColor(QColor color) |
|
298 | 281 | { |
|
299 | 282 | QPen p = d_ptr->m_axisPen; |
|
300 | 283 | if (p.color() != color) { |
|
301 | 284 | p.setColor(color); |
|
302 | 285 | setAxisPen(p); |
|
303 | 286 | emit colorChanged(color); |
|
304 | 287 | } |
|
305 | 288 | } |
|
306 | 289 | |
|
307 | 290 | QColor QAbstractAxis::axisPenColor() const |
|
308 | 291 | { |
|
309 | 292 | return d_ptr->m_axisPen.color(); |
|
310 | 293 | } |
|
311 | 294 | |
|
312 | 295 | /*! |
|
313 | 296 | Sets if axis and ticks are \a visible. |
|
314 | 297 | */ |
|
315 | 298 | void QAbstractAxis::setAxisVisible(bool visible) |
|
316 | 299 | { |
|
317 | 300 | if (d_ptr->m_axisVisible != visible) { |
|
318 | 301 | d_ptr->m_axisVisible = visible; |
|
319 | 302 | emit d_ptr->updated(); |
|
320 | 303 | emit visibleChanged(visible); |
|
321 | 304 | } |
|
322 | 305 | } |
|
323 | 306 | |
|
324 | 307 | bool QAbstractAxis::isAxisVisible() const |
|
325 | 308 | { |
|
326 | 309 | return d_ptr->m_axisVisible; |
|
327 | 310 | } |
|
328 | 311 | |
|
329 | 312 | void QAbstractAxis::setGridLineVisible(bool visible) |
|
330 | 313 | { |
|
331 | 314 | if (d_ptr->m_gridLineVisible != visible) { |
|
332 | 315 | d_ptr->m_gridLineVisible = visible; |
|
333 | 316 | emit d_ptr->updated(); |
|
334 | 317 | emit gridVisibleChanged(visible); |
|
335 | 318 | } |
|
336 | 319 | } |
|
337 | 320 | |
|
338 | 321 | bool QAbstractAxis::isGridLineVisible() const |
|
339 | 322 | { |
|
340 | 323 | return d_ptr->m_gridLineVisible; |
|
341 | 324 | } |
|
342 | 325 | |
|
343 | 326 | /*! |
|
344 | 327 | Sets \a pen used to draw grid line. |
|
345 | 328 | */ |
|
346 | 329 | void QAbstractAxis::setGridLinePen(const QPen &pen) |
|
347 | 330 | { |
|
348 | 331 | if (d_ptr->m_gridLinePen != pen) { |
|
349 | 332 | d_ptr->m_gridLinePen = pen; |
|
350 | 333 | emit d_ptr->updated(); |
|
351 | 334 | } |
|
352 | 335 | } |
|
353 | 336 | |
|
354 | 337 | /*! |
|
355 | 338 | Returns pen used to draw grid. |
|
356 | 339 | */ |
|
357 | 340 | QPen QAbstractAxis::gridLinePen() const |
|
358 | 341 | { |
|
359 | 342 | return d_ptr->m_gridLinePen; |
|
360 | 343 | } |
|
361 | 344 | |
|
362 | 345 | void QAbstractAxis::setLabelsVisible(bool visible) |
|
363 | 346 | { |
|
364 | 347 | if (d_ptr->m_labelsVisible != visible) { |
|
365 | 348 | d_ptr->m_labelsVisible = visible; |
|
366 | 349 | emit d_ptr->updated(); |
|
367 | 350 | emit labelsVisibleChanged(visible); |
|
368 | 351 | } |
|
369 | 352 | } |
|
370 | 353 | |
|
371 | 354 | bool QAbstractAxis::labelsVisible() const |
|
372 | 355 | { |
|
373 | 356 | return d_ptr->m_labelsVisible; |
|
374 | 357 | } |
|
375 | 358 | |
|
376 | 359 | /*! |
|
377 | 360 | Sets \a pen used to draw labels. |
|
378 | 361 | */ |
|
379 | 362 | void QAbstractAxis::setLabelsPen(const QPen &pen) |
|
380 | 363 | { |
|
381 | 364 | if (d_ptr->m_labelsPen != pen) { |
|
382 | 365 | d_ptr->m_labelsPen = pen; |
|
383 | 366 | emit d_ptr->updated(); |
|
384 | 367 | } |
|
385 | 368 | } |
|
386 | 369 | |
|
387 | 370 | /*! |
|
388 | 371 | Returns the pen used to labels. |
|
389 | 372 | */ |
|
390 | 373 | QPen QAbstractAxis::labelsPen() const |
|
391 | 374 | { |
|
392 | 375 | return d_ptr->m_labelsPen; |
|
393 | 376 | } |
|
394 | 377 | |
|
395 | 378 | /*! |
|
396 | 379 | Sets \a brush used to draw labels. |
|
397 | 380 | */ |
|
398 | 381 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) |
|
399 | 382 | { |
|
400 | 383 | if (d_ptr->m_labelsBrush != brush) { |
|
401 | 384 | d_ptr->m_labelsBrush = brush; |
|
402 | 385 | emit d_ptr->updated(); |
|
403 | 386 | } |
|
404 | 387 | } |
|
405 | 388 | |
|
406 | 389 | /*! |
|
407 | 390 | Returns brush used to draw labels. |
|
408 | 391 | */ |
|
409 | 392 | QBrush QAbstractAxis::labelsBrush() const |
|
410 | 393 | { |
|
411 | 394 | return d_ptr->m_labelsBrush; |
|
412 | 395 | } |
|
413 | 396 | |
|
414 | 397 | /*! |
|
415 | 398 | Sets \a font used to draw labels. |
|
416 | 399 | */ |
|
417 | 400 | void QAbstractAxis::setLabelsFont(const QFont &font) |
|
418 | 401 | { |
|
419 | 402 | if (d_ptr->m_labelsFont != font) { |
|
420 | 403 | d_ptr->m_labelsFont = font; |
|
421 | 404 | emit d_ptr->updated(); |
|
422 | 405 | } |
|
423 | 406 | } |
|
424 | 407 | |
|
425 | 408 | /*! |
|
426 | 409 | Returns font used to draw labels. |
|
427 | 410 | */ |
|
428 | 411 | QFont QAbstractAxis::labelsFont() const |
|
429 | 412 | { |
|
430 | 413 | return d_ptr->m_labelsFont; |
|
431 | 414 | } |
|
432 | 415 | |
|
433 | 416 | void QAbstractAxis::setLabelsAngle(int angle) |
|
434 | 417 | { |
|
435 | 418 | if (d_ptr->m_labelsAngle != angle) { |
|
436 | 419 | d_ptr->m_labelsAngle = angle; |
|
437 | 420 | emit d_ptr->updated(); |
|
438 | 421 | } |
|
439 | 422 | } |
|
440 | 423 | |
|
441 | 424 | int QAbstractAxis::labelsAngle() const |
|
442 | 425 | { |
|
443 | 426 | return d_ptr->m_labelsAngle; |
|
444 | 427 | } |
|
445 | 428 | |
|
446 | 429 | void QAbstractAxis::setLabelsColor(QColor color) |
|
447 | 430 | { |
|
448 | 431 | QBrush b = d_ptr->m_labelsBrush; |
|
449 | 432 | if (b.color() != color) { |
|
450 | 433 | b.setColor(color); |
|
451 | 434 | setLabelsBrush(b); |
|
452 | 435 | emit labelsColorChanged(color); |
|
453 | 436 | } |
|
454 | 437 | } |
|
455 | 438 | |
|
456 | 439 | QColor QAbstractAxis::labelsColor() const |
|
457 | 440 | { |
|
458 | 441 | return d_ptr->m_labelsBrush.color(); |
|
459 | 442 | } |
|
460 | 443 | |
|
461 | 444 | void QAbstractAxis::setShadesVisible(bool visible) |
|
462 | 445 | { |
|
463 | 446 | if (d_ptr->m_shadesVisible != visible) { |
|
464 | 447 | d_ptr->m_shadesVisible = visible; |
|
465 | 448 | emit d_ptr->updated(); |
|
466 | 449 | emit shadesVisibleChanged(visible); |
|
467 | 450 | } |
|
468 | 451 | } |
|
469 | 452 | |
|
470 | 453 | bool QAbstractAxis::shadesVisible() const |
|
471 | 454 | { |
|
472 | 455 | return d_ptr->m_shadesVisible; |
|
473 | 456 | } |
|
474 | 457 | |
|
475 | 458 | /*! |
|
476 | 459 | Sets \a pen used to draw shades. |
|
477 | 460 | */ |
|
478 | 461 | void QAbstractAxis::setShadesPen(const QPen &pen) |
|
479 | 462 | { |
|
480 | 463 | if (d_ptr->m_shadesPen != pen) { |
|
481 | 464 | d_ptr->m_shadesPen = pen; |
|
482 | 465 | emit d_ptr->updated(); |
|
483 | 466 | } |
|
484 | 467 | } |
|
485 | 468 | |
|
486 | 469 | /*! |
|
487 | 470 | Returns pen used to draw shades. |
|
488 | 471 | */ |
|
489 | 472 | QPen QAbstractAxis::shadesPen() const |
|
490 | 473 | { |
|
491 | 474 | return d_ptr->m_shadesPen; |
|
492 | 475 | } |
|
493 | 476 | |
|
494 | 477 | /*! |
|
495 | 478 | Sets \a brush used to draw shades. |
|
496 | 479 | */ |
|
497 | 480 | void QAbstractAxis::setShadesBrush(const QBrush &brush) |
|
498 | 481 | { |
|
499 | 482 | if (d_ptr->m_shadesBrush != brush) { |
|
500 | 483 | d_ptr->m_shadesBrush = brush; |
|
501 | 484 | emit d_ptr->updated(); |
|
502 | 485 | emit shadesColorChanged(brush.color()); |
|
503 | 486 | } |
|
504 | 487 | } |
|
505 | 488 | |
|
506 | 489 | /*! |
|
507 | 490 | Returns brush used to draw shades. |
|
508 | 491 | */ |
|
509 | 492 | QBrush QAbstractAxis::shadesBrush() const |
|
510 | 493 | { |
|
511 | 494 | return d_ptr->m_shadesBrush; |
|
512 | 495 | } |
|
513 | 496 | |
|
514 | 497 | void QAbstractAxis::setShadesColor(QColor color) |
|
515 | 498 | { |
|
516 | 499 | QBrush b = d_ptr->m_shadesBrush; |
|
517 | 500 | b.setColor(color); |
|
518 | 501 | setShadesBrush(b); |
|
519 | 502 | } |
|
520 | 503 | |
|
521 | 504 | QColor QAbstractAxis::shadesColor() const |
|
522 | 505 | { |
|
523 | 506 | return d_ptr->m_shadesBrush.color(); |
|
524 | 507 | } |
|
525 | 508 | |
|
526 | 509 | void QAbstractAxis::setShadesBorderColor(QColor color) |
|
527 | 510 | { |
|
528 | 511 | QPen p = d_ptr->m_shadesPen; |
|
529 | 512 | p.setColor(color); |
|
530 | 513 | setShadesPen(p); |
|
531 | 514 | } |
|
532 | 515 | |
|
533 | 516 | QColor QAbstractAxis::shadesBorderColor() const |
|
534 | 517 | { |
|
535 | 518 | return d_ptr->m_shadesPen.color(); |
|
536 | 519 | } |
|
537 | 520 | |
|
538 | 521 | |
|
539 | 522 | /*! |
|
540 | 523 | Sets axis, shades, labels and grid lines to be visible. |
|
541 | 524 | */ |
|
542 | 525 | void QAbstractAxis::show() |
|
543 | 526 | { |
|
544 | 527 | d_ptr->m_axisVisible=true; |
|
545 | 528 | d_ptr->m_gridLineVisible=true; |
|
546 | 529 | d_ptr->m_labelsVisible=true; |
|
547 | 530 | d_ptr->m_shadesVisible=true; |
|
548 | 531 | emit d_ptr->updated(); |
|
549 | 532 | } |
|
550 | 533 | |
|
551 | 534 | /*! |
|
552 | 535 | Sets axis, shades, labels and grid lines to not be visible. |
|
553 | 536 | */ |
|
554 | 537 | void QAbstractAxis::hide() |
|
555 | 538 | { |
|
556 | 539 | d_ptr->m_axisVisible = false; |
|
557 | 540 | d_ptr->m_gridLineVisible = false; |
|
558 | 541 | d_ptr->m_labelsVisible = false; |
|
559 | 542 | d_ptr->m_shadesVisible = false; |
|
560 | 543 | emit d_ptr->updated(); |
|
561 | 544 | } |
|
562 | 545 | |
|
563 | 546 | |
|
564 | 547 | void QAbstractAxis::setMin(const qreal min) |
|
565 | 548 | { |
|
566 | 549 | d_ptr->setMin(min); |
|
567 | 550 | } |
|
568 | 551 | void QAbstractAxis::setMax(const qreal max) |
|
569 | 552 | { |
|
570 | 553 | d_ptr->setMax(max); |
|
571 | 554 | } |
|
572 | 555 | void QAbstractAxis::setRange(const qreal min, const qreal max) |
|
573 | 556 | { |
|
574 | 557 | d_ptr->setRange(min,max); |
|
575 | 558 | } |
|
576 | 559 | |
|
577 | 560 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
578 | 561 | |
|
579 | 562 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q): |
|
580 | 563 | q_ptr(q), |
|
581 | 564 | m_axisVisible(true), |
|
582 | 565 | m_gridLineVisible(true), |
|
583 | 566 | m_labelsVisible(true), |
|
584 | 567 | m_labelsAngle(0), |
|
585 | 568 | m_shadesVisible(false), |
|
586 | 569 | m_shadesBrush(Qt::SolidPattern), |
|
587 | 570 | m_shadesOpacity(1.0), |
|
588 | 571 | m_orientation(Qt::Orientation(0)), |
|
589 | 572 | m_min(0), |
|
590 | 573 | m_max(0), |
|
591 | 574 | m_ticksCount(5) |
|
592 | 575 | { |
|
593 | 576 | |
|
594 | 577 | } |
|
595 | 578 | |
|
596 | 579 | QAbstractAxisPrivate::~QAbstractAxisPrivate() |
|
597 | 580 | { |
|
598 | 581 | |
|
599 | 582 | } |
|
600 | 583 | |
|
601 | 584 | #include "moc_qabstractaxis.cpp" |
|
602 | 585 | #include "moc_qabstractaxis_p.cpp" |
|
603 | 586 | |
|
604 | 587 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,257 +1,277 | |||
|
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 | /*! | |
|
89 | \property QValuesAxis::ticksCount | |
|
90 | The number of tick marks for the axis. | |
|
91 | */ | |
|
92 | ||
|
93 | /*! | |
|
94 | \qmlproperty int Axis::ticksCount | |
|
95 | The number of tick marks for the axis. | |
|
96 | */ | |
|
97 | ||
|
98 | /*! | |
|
99 | \property QValuesAxis::niceNumbersEnabled | |
|
100 | Whether the nice numbers algorithm is enabled or not for the axis. | |
|
101 | */ | |
|
102 | ||
|
103 | /*! | |
|
104 | \qmlproperty bool Axis::niceNumbersEnabled | |
|
105 | Whether the nice numbers algorithm is enabled or not for the axis. | |
|
106 | */ | |
|
107 | ||
|
88 | 108 | QValuesAxis::QValuesAxis(QObject *parent) : |
|
89 | 109 | QAbstractAxis(*new QValuesAxisPrivate(this),parent) |
|
90 | 110 | { |
|
91 | 111 | |
|
92 | 112 | } |
|
93 | 113 | |
|
94 | 114 | QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) |
|
95 | 115 | { |
|
96 | 116 | |
|
97 | 117 | } |
|
98 | 118 | |
|
99 | 119 | QValuesAxis::~QValuesAxis() |
|
100 | 120 | { |
|
101 | 121 | |
|
102 | 122 | } |
|
103 | 123 | |
|
104 | 124 | void QValuesAxis::setMin(qreal min) |
|
105 | 125 | { |
|
106 | 126 | Q_D(QValuesAxis); |
|
107 | 127 | setRange(min,d->m_max); |
|
108 | 128 | } |
|
109 | 129 | |
|
110 | 130 | qreal QValuesAxis::min() const |
|
111 | 131 | { |
|
112 | 132 | Q_D(const QValuesAxis); |
|
113 | 133 | return d->m_min; |
|
114 | 134 | } |
|
115 | 135 | |
|
116 | 136 | void QValuesAxis::setMax(qreal max) |
|
117 | 137 | { |
|
118 | 138 | Q_D(QValuesAxis); |
|
119 | 139 | setRange(d->m_min,max); |
|
120 | 140 | } |
|
121 | 141 | |
|
122 | 142 | qreal QValuesAxis::max() const |
|
123 | 143 | { |
|
124 | 144 | Q_D(const QValuesAxis); |
|
125 | 145 | return d->m_max; |
|
126 | 146 | } |
|
127 | 147 | |
|
128 | 148 | /*! |
|
129 | 149 | Sets range from \a min to \a max on the axis. |
|
130 | 150 | */ |
|
131 | 151 | void QValuesAxis::setRange(qreal min, qreal max) |
|
132 | 152 | { |
|
133 | 153 | Q_D(QValuesAxis); |
|
134 | 154 | d->setRange(min,max); |
|
135 | 155 | } |
|
136 | 156 | |
|
137 | 157 | /*! |
|
138 | 158 | Sets \a count for ticks on the axis. |
|
139 | 159 | */ |
|
140 | 160 | void QValuesAxis::setTicksCount(int count) |
|
141 | 161 | { |
|
142 | 162 | Q_D(QValuesAxis); |
|
143 | 163 | if (d->m_ticksCount != count) { |
|
144 | 164 | d->m_ticksCount = count; |
|
145 | 165 | emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers); |
|
146 | 166 | } |
|
147 | 167 | } |
|
148 | 168 | |
|
149 | 169 | /*! |
|
150 |
\fn int Q |
|
|
170 | \fn int QValuesAxis::ticksCount() const | |
|
151 | 171 | Return number of ticks on the axis |
|
152 | 172 | */ |
|
153 | 173 | int QValuesAxis::ticksCount() const |
|
154 | 174 | { |
|
155 | 175 | Q_D(const QValuesAxis); |
|
156 | 176 | return d->m_ticksCount; |
|
157 | 177 | } |
|
158 | 178 | |
|
159 | 179 | void QValuesAxis::setNiceNumbersEnabled(bool enable) |
|
160 | 180 | { |
|
161 | 181 | Q_D(QValuesAxis); |
|
162 | 182 | if (d->m_niceNumbers != enable){ |
|
163 | 183 | d->m_niceNumbers = enable; |
|
164 | 184 | emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers); |
|
165 | 185 | } |
|
166 | 186 | } |
|
167 | 187 | |
|
168 | 188 | bool QValuesAxis::niceNumbersEnabled() const |
|
169 | 189 | { |
|
170 | 190 | Q_D(const QValuesAxis); |
|
171 | 191 | return d->m_niceNumbers; |
|
172 | 192 | } |
|
173 | 193 | |
|
174 | 194 | QAbstractAxis::AxisType QValuesAxis::type() const |
|
175 | 195 | { |
|
176 | 196 | return AxisTypeValues; |
|
177 | 197 | } |
|
178 | 198 | |
|
179 | 199 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
180 | 200 | |
|
181 | 201 | QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q): |
|
182 | 202 | QAbstractAxisPrivate(q), |
|
183 | 203 | m_niceNumbers(false) |
|
184 | 204 | { |
|
185 | 205 | |
|
186 | 206 | } |
|
187 | 207 | |
|
188 | 208 | QValuesAxisPrivate::~QValuesAxisPrivate() |
|
189 | 209 | { |
|
190 | 210 | |
|
191 | 211 | } |
|
192 | 212 | |
|
193 | 213 | void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) |
|
194 | 214 | { |
|
195 | 215 | Q_Q(QValuesAxis); |
|
196 | 216 | q->setRange(min,max); |
|
197 | 217 | q->setTicksCount(count); |
|
198 | 218 | } |
|
199 | 219 | |
|
200 | 220 | |
|
201 | 221 | void QValuesAxisPrivate::setMin(const qreal min) |
|
202 | 222 | { |
|
203 | 223 | setRange(min,m_max); |
|
204 | 224 | } |
|
205 | 225 | |
|
206 | 226 | void QValuesAxisPrivate::setMax(const qreal max) |
|
207 | 227 | { |
|
208 | 228 | setRange(m_min,max); |
|
209 | 229 | } |
|
210 | 230 | |
|
211 | 231 | void QValuesAxisPrivate::setRange(const qreal min, const qreal max, bool force) |
|
212 | 232 | { |
|
213 | 233 | Q_Q(QValuesAxis); |
|
214 | 234 | bool changed = false; |
|
215 | 235 | if (!qFuzzyIsNull(m_min - min)) { |
|
216 | 236 | m_min = min; |
|
217 | 237 | changed = true; |
|
218 | 238 | emit q->minChanged(min); |
|
219 | 239 | } |
|
220 | 240 | |
|
221 | 241 | if (!qFuzzyIsNull(m_max - max)) { |
|
222 | 242 | m_max = max; |
|
223 | 243 | changed = true; |
|
224 | 244 | emit q->maxChanged(max); |
|
225 | 245 | } |
|
226 | 246 | |
|
227 | 247 | if ((changed) ||(force)) { |
|
228 | 248 | emit q->rangeChanged(m_min,m_max); |
|
229 | 249 | emit this->changed(m_min, m_max, m_ticksCount, m_niceNumbers); |
|
230 | 250 | } |
|
231 | 251 | } |
|
232 | 252 | |
|
233 | 253 | int QValuesAxisPrivate::ticksCount() const |
|
234 | 254 | { |
|
235 | 255 | return m_ticksCount; |
|
236 | 256 | } |
|
237 | 257 | |
|
238 | 258 | ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
239 | 259 | { |
|
240 | 260 | Q_Q(QValuesAxis); |
|
241 | 261 | if(m_orientation == Qt::Vertical){ |
|
242 | 262 | return new ChartValuesAxisY(q,presenter); |
|
243 | 263 | }else{ |
|
244 | 264 | return new ChartValuesAxisX(q,presenter); |
|
245 | 265 | } |
|
246 | 266 | |
|
247 | 267 | } |
|
248 | 268 | |
|
249 | 269 | void QValuesAxisPrivate::updateRange() |
|
250 | 270 | { |
|
251 | 271 | setRange(m_min,m_max,true); |
|
252 | 272 | } |
|
253 | 273 | |
|
254 | 274 | #include "moc_qvaluesaxis.cpp" |
|
255 | 275 | #include "moc_qvaluesaxis_p.cpp" |
|
256 | 276 | |
|
257 | 277 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,548 +1,533 | |||
|
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 "qlegend.h" |
|
22 | 22 | #include "qlegend_p.h" |
|
23 | 23 | #include "qabstractseries.h" |
|
24 | 24 | #include "qabstractseries_p.h" |
|
25 | 25 | #include "qchart_p.h" |
|
26 | 26 | #include "legendlayout_p.h" |
|
27 | 27 | #include "legendmarker_p.h" |
|
28 | 28 | #include "qxyseries.h" |
|
29 | 29 | #include "qlineseries.h" |
|
30 | 30 | #include "qareaseries.h" |
|
31 | 31 | #include "qscatterseries.h" |
|
32 | 32 | #include "qsplineseries.h" |
|
33 | 33 | #include "qbarseries.h" |
|
34 | 34 | #include "qstackedbarseries.h" |
|
35 | 35 | #include "qpercentbarseries.h" |
|
36 | 36 | #include "qbarset.h" |
|
37 | 37 | #include "qpieseries.h" |
|
38 | 38 | #include "qpieseries_p.h" |
|
39 | 39 | #include "qpieslice.h" |
|
40 | 40 | #include "chartpresenter_p.h" |
|
41 | 41 | #include <QPainter> |
|
42 | 42 | #include <QPen> |
|
43 | 43 | #include <QTimer> |
|
44 | 44 | #include <QGraphicsLayout> |
|
45 | 45 | #include <QGraphicsSceneEvent> |
|
46 | 46 | |
|
47 | 47 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
48 | 48 | |
|
49 | 49 | /*! |
|
50 | 50 | \class QLegend |
|
51 | 51 | \brief Legend object |
|
52 | 52 | \mainclass |
|
53 | 53 | |
|
54 | 54 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when |
|
55 | 55 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
56 | 56 | handle the drawing manually. |
|
57 | 57 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
58 | 58 | |
|
59 | 59 | \image examples_percentbarchart_legend.png |
|
60 | 60 | |
|
61 | 61 | \sa QChart |
|
62 | 62 | */ |
|
63 | 63 | /*! |
|
64 | 64 | \qmlclass Legend QLegend |
|
65 | 65 | \brief Legend is part of QtCommercial Chart QML API. |
|
66 | 66 | |
|
67 | 67 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when |
|
68 | 68 | series have been changed. Legend is used via ChartView class. For example: |
|
69 | 69 | \code |
|
70 | 70 | ChartView { |
|
71 | 71 | legend.visible: true |
|
72 | 72 | legend.alignment: Qt.AlignBottom |
|
73 | 73 | // Add a few series... |
|
74 | 74 | } |
|
75 | 75 | \endcode |
|
76 | 76 | |
|
77 | 77 | \image examples_percentbarchart_legend.png |
|
78 | 78 | */ |
|
79 | 79 | |
|
80 | 80 | /*! |
|
81 | 81 | \property QLegend::alignment |
|
82 | 82 | \brief The alignment of the legend. |
|
83 | 83 | |
|
84 | 84 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
85 | 85 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. |
|
86 | 86 | */ |
|
87 | 87 | /*! |
|
88 | 88 | \qmlproperty Qt.Alignment Legend::alignment |
|
89 | 89 | \brief The alignment of the legend. |
|
90 | 90 | |
|
91 | 91 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
92 | 92 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. |
|
93 | 93 | */ |
|
94 | 94 | |
|
95 | 95 | /*! |
|
96 | 96 | \property QLegend::backgroundVisible |
|
97 | 97 | Whether the legend background is visible or not. |
|
98 | 98 | */ |
|
99 | 99 | /*! |
|
100 | 100 | \qmlproperty bool Legend::backgroundVisible |
|
101 | 101 | Whether the legend background is visible or not. |
|
102 | 102 | */ |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | \property QLegend::color |
|
106 | 106 | The color of the legend, i.e. the background (brush) color. Note that if you change the color |
|
107 | 107 | of the legend, the style of the legend brush is set to Qt::SolidPattern. |
|
108 | 108 | */ |
|
109 | 109 | /*! |
|
110 | 110 | \qmlproperty color Legend::color |
|
111 | 111 | The color of the legend, i.e. the background (brush) color. |
|
112 | 112 | */ |
|
113 | 113 | |
|
114 | 114 | /*! |
|
115 | 115 | \property QLegend::borderColor |
|
116 | 116 | The border color of the legend, i.e. the line color. |
|
117 | 117 | */ |
|
118 | 118 | /*! |
|
119 | 119 | \qmlproperty color Legend::borderColor |
|
120 | 120 | The border color of the legend, i.e. the line color. |
|
121 | 121 | */ |
|
122 | 122 | |
|
123 | 123 | /*! |
|
124 | 124 | \property QLegend::font |
|
125 | 125 | The font of markers used by legend |
|
126 | 126 | */ |
|
127 | 127 | /*! |
|
128 | 128 | \qmlproperty color Legend::font |
|
129 | 129 | The font of markers used by legend |
|
130 | 130 | */ |
|
131 | 131 | |
|
132 | 132 | /*! |
|
133 | 133 | \property QLegend::labelColor |
|
134 | 134 | The color of brush used to draw labels. |
|
135 | 135 | */ |
|
136 | 136 | /*! |
|
137 | 137 | \qmlproperty color QLegend::labelColor |
|
138 | 138 | The color of brush used to draw labels. |
|
139 | 139 | */ |
|
140 | 140 | |
|
141 | 141 | /*! |
|
142 | 142 | \fn void QLegend::backgroundVisibleChanged(bool) |
|
143 | 143 | The visibility of the legend background changed to \a visible. |
|
144 | 144 | */ |
|
145 | 145 | |
|
146 | 146 | /*! |
|
147 | 147 | \fn void QLegend::colorChanged(QColor) |
|
148 | 148 | The color of the legend background changed to \a color. |
|
149 | 149 | */ |
|
150 | 150 | |
|
151 | 151 | /*! |
|
152 | 152 | \fn void QLegend::borderColorChanged(QColor) |
|
153 | 153 | The border color of the legend background changed to \a color. |
|
154 | 154 | */ |
|
155 | 155 | |
|
156 | 156 | /*! |
|
157 | 157 | \fn void QLegend::fontChanged(QFont) |
|
158 | 158 | The font of markers of the legend changed to \a font. |
|
159 | 159 | */ |
|
160 | 160 | |
|
161 | 161 | /*! |
|
162 | \fn void QLegend::labelBrushChanged(QBrush brush) | |
|
163 | This signal is emitted when the brush used to draw labels has changed to \a brush. | |
|
164 | */ | |
|
165 | ||
|
166 | /*! | |
|
167 | 162 | \fn void QLegend::labelColorChanged(QColor color) |
|
168 | 163 | This signal is emitted when the color of brush used to draw labels has changed to \a color. |
|
169 | 164 | */ |
|
170 | 165 | |
|
171 | 166 | /*! |
|
172 | \fn qreal QLegend::minWidth() const | |
|
173 | Returns minimum width of the legend | |
|
174 | */ | |
|
175 | ||
|
176 | /*! | |
|
177 | \fn qreal QLegend::minHeight() const | |
|
178 | Returns minimum height of the legend | |
|
179 | */ | |
|
180 | ||
|
181 | /*! | |
|
182 | 167 | Constructs the legend object and sets the parent to \a parent |
|
183 | 168 | */ |
|
184 | 169 | |
|
185 | 170 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), |
|
186 | 171 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this)) |
|
187 | 172 | { |
|
188 | 173 | setZValue(ChartPresenter::LegendZValue); |
|
189 | 174 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
190 | 175 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
191 | 176 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
192 | 177 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); |
|
193 | 178 | setLayout(d_ptr->m_layout); |
|
194 | 179 | } |
|
195 | 180 | |
|
196 | 181 | /*! |
|
197 | 182 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. |
|
198 | 183 | */ |
|
199 | 184 | QLegend::~QLegend() |
|
200 | 185 | { |
|
201 | 186 | } |
|
202 | 187 | |
|
203 | 188 | /*! |
|
204 | 189 | \internal |
|
205 | 190 | */ |
|
206 | 191 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
207 | 192 | { |
|
208 | 193 | Q_UNUSED(option) |
|
209 | 194 | Q_UNUSED(widget) |
|
210 | 195 | if(!d_ptr->m_backgroundVisible) return; |
|
211 | 196 | |
|
212 | 197 | painter->setOpacity(opacity()); |
|
213 | 198 | painter->setPen(d_ptr->m_pen); |
|
214 | 199 | painter->setBrush(d_ptr->m_brush); |
|
215 | 200 | painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height())); |
|
216 | 201 | |
|
217 | 202 | } |
|
218 | 203 | |
|
219 | 204 | |
|
220 | 205 | /*! |
|
221 | 206 | Sets the \a brush of legend. Brush affects the background of legend. |
|
222 | 207 | */ |
|
223 | 208 | void QLegend::setBrush(const QBrush &brush) |
|
224 | 209 | { |
|
225 | 210 | if (d_ptr->m_brush != brush) { |
|
226 | 211 | d_ptr->m_brush = brush; |
|
227 | 212 | update(); |
|
228 | 213 | emit colorChanged(brush.color()); |
|
229 | 214 | } |
|
230 | 215 | } |
|
231 | 216 | |
|
232 | 217 | /*! |
|
233 | 218 | Returns the brush used by legend. |
|
234 | 219 | */ |
|
235 | 220 | QBrush QLegend::brush() const |
|
236 | 221 | { |
|
237 | 222 | return d_ptr->m_brush; |
|
238 | 223 | } |
|
239 | 224 | |
|
240 | 225 | void QLegend::setColor(QColor color) |
|
241 | 226 | { |
|
242 | 227 | QBrush b = d_ptr->m_brush; |
|
243 | 228 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
244 | 229 | b.setStyle(Qt::SolidPattern); |
|
245 | 230 | b.setColor(color); |
|
246 | 231 | setBrush(b); |
|
247 | 232 | } |
|
248 | 233 | } |
|
249 | 234 | |
|
250 | 235 | QColor QLegend::color() |
|
251 | 236 | { |
|
252 | 237 | return d_ptr->m_brush.color(); |
|
253 | 238 | } |
|
254 | 239 | |
|
255 | 240 | /*! |
|
256 | 241 | Sets the \a pen of legend. Pen affects the legend borders. |
|
257 | 242 | */ |
|
258 | 243 | void QLegend::setPen(const QPen &pen) |
|
259 | 244 | { |
|
260 | 245 | if (d_ptr->m_pen != pen) { |
|
261 | 246 | d_ptr->m_pen = pen; |
|
262 | 247 | update(); |
|
263 | 248 | emit borderColorChanged(pen.color()); |
|
264 | 249 | } |
|
265 | 250 | } |
|
266 | 251 | |
|
267 | 252 | /*! |
|
268 | 253 | Returns the pen used by legend |
|
269 | 254 | */ |
|
270 | 255 | |
|
271 | 256 | QPen QLegend::pen() const |
|
272 | 257 | { |
|
273 | 258 | return d_ptr->m_pen; |
|
274 | 259 | } |
|
275 | 260 | |
|
276 | 261 | void QLegend::setFont(const QFont &font) |
|
277 | 262 | { |
|
278 | 263 | if (d_ptr->m_font != font) { |
|
279 | 264 | d_ptr->m_font = font; |
|
280 | 265 | |
|
281 | 266 | foreach (LegendMarker *marker, d_ptr->markers()) { |
|
282 | 267 | marker->setFont(d_ptr->m_font); |
|
283 | 268 | } |
|
284 | 269 | layout()->invalidate(); |
|
285 | 270 | emit fontChanged(font); |
|
286 | 271 | } |
|
287 | 272 | } |
|
288 | 273 | |
|
289 | 274 | QFont QLegend::font() const |
|
290 | 275 | { |
|
291 | 276 | return d_ptr->m_font; |
|
292 | 277 | } |
|
293 | 278 | |
|
294 | 279 | void QLegend::setBorderColor(QColor color) |
|
295 | 280 | { |
|
296 | 281 | QPen p = d_ptr->m_pen; |
|
297 | 282 | if (p.color() != color) { |
|
298 | 283 | p.setColor(color); |
|
299 | 284 | setPen(p); |
|
300 | 285 | } |
|
301 | 286 | } |
|
302 | 287 | |
|
303 | 288 | QColor QLegend::borderColor() |
|
304 | 289 | { |
|
305 | 290 | return d_ptr->m_pen.color(); |
|
306 | 291 | } |
|
307 | 292 | |
|
308 | 293 | /*! |
|
309 | 294 | Set brush used to draw labels to \a brush. |
|
310 | 295 | */ |
|
311 | 296 | void QLegend::setLabelBrush(const QBrush &brush) |
|
312 | 297 | { |
|
313 | 298 | if (d_ptr->m_labelBrush != brush) { |
|
314 | 299 | d_ptr->m_labelBrush = brush; |
|
315 | 300 | foreach (LegendMarker *marker, d_ptr->markers()) { |
|
316 | 301 | marker->setLabelBrush(d_ptr->m_labelBrush); |
|
317 | 302 | } |
|
318 | 303 | emit labelColorChanged(brush.color()); |
|
319 | 304 | } |
|
320 | 305 | } |
|
321 | 306 | |
|
322 | 307 | /*! |
|
323 | 308 | Brush used to draw labels. |
|
324 | 309 | */ |
|
325 | 310 | QBrush QLegend::labelBrush() const |
|
326 | 311 | { |
|
327 | 312 | return d_ptr->m_labelBrush; |
|
328 | 313 | } |
|
329 | 314 | |
|
330 | 315 | void QLegend::setLabelColor(QColor color) |
|
331 | 316 | { |
|
332 | 317 | QBrush b = d_ptr->m_labelBrush; |
|
333 | 318 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
334 | 319 | b.setStyle(Qt::SolidPattern); |
|
335 | 320 | b.setColor(color); |
|
336 | 321 | setLabelBrush(b); |
|
337 | 322 | } |
|
338 | 323 | } |
|
339 | 324 | |
|
340 | 325 | QColor QLegend::labelColor() const |
|
341 | 326 | { |
|
342 | 327 | return d_ptr->m_labelBrush.color(); |
|
343 | 328 | } |
|
344 | 329 | |
|
345 | 330 | |
|
346 | 331 | void QLegend::setAlignment(Qt::Alignment alignment) |
|
347 | 332 | { |
|
348 | 333 | if(d_ptr->m_alignment!=alignment) { |
|
349 | 334 | d_ptr->m_alignment = alignment; |
|
350 | 335 | updateGeometry(); |
|
351 | 336 | if(isAttachedToChart()){ |
|
352 | 337 | d_ptr->m_presenter->layout()->invalidate(); |
|
353 | 338 | }else{ |
|
354 | 339 | layout()->invalidate(); |
|
355 | 340 | } |
|
356 | 341 | } |
|
357 | 342 | } |
|
358 | 343 | |
|
359 | 344 | Qt::Alignment QLegend::alignment() const |
|
360 | 345 | { |
|
361 | 346 | return d_ptr->m_alignment; |
|
362 | 347 | } |
|
363 | 348 | |
|
364 | 349 | /*! |
|
365 | 350 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
366 | 351 | */ |
|
367 | 352 | void QLegend::detachFromChart() |
|
368 | 353 | { |
|
369 | 354 | d_ptr->m_attachedToChart = false; |
|
370 | 355 | d_ptr->m_layout->invalidate(); |
|
371 | 356 | setParent(0); |
|
372 | 357 | |
|
373 | 358 | } |
|
374 | 359 | |
|
375 | 360 | /*! |
|
376 | 361 | Attaches the legend to chart. Chart may change layout of the legend. |
|
377 | 362 | */ |
|
378 | 363 | void QLegend::attachToChart() |
|
379 | 364 | { |
|
380 | 365 | d_ptr->m_attachedToChart = true; |
|
381 | 366 | d_ptr->m_layout->invalidate(); |
|
382 | 367 | setParent(d_ptr->m_chart); |
|
383 | 368 | } |
|
384 | 369 | |
|
385 | 370 | /*! |
|
386 | 371 | Returns true, if legend is attached to chart. |
|
387 | 372 | */ |
|
388 | 373 | bool QLegend::isAttachedToChart() |
|
389 | 374 | { |
|
390 | 375 | return d_ptr->m_attachedToChart; |
|
391 | 376 | } |
|
392 | 377 | |
|
393 | 378 | /*! |
|
394 | 379 | Sets the visibility of legend background to \a visible |
|
395 | 380 | */ |
|
396 | 381 | void QLegend::setBackgroundVisible(bool visible) |
|
397 | 382 | { |
|
398 | 383 | if(d_ptr->m_backgroundVisible != visible) { |
|
399 | 384 | d_ptr->m_backgroundVisible = visible; |
|
400 | 385 | update(); |
|
401 | 386 | emit backgroundVisibleChanged(visible); |
|
402 | 387 | } |
|
403 | 388 | } |
|
404 | 389 | |
|
405 | 390 | /*! |
|
406 | 391 | Returns the visibility of legend background |
|
407 | 392 | */ |
|
408 | 393 | bool QLegend::isBackgroundVisible() const |
|
409 | 394 | { |
|
410 | 395 | return d_ptr->m_backgroundVisible; |
|
411 | 396 | } |
|
412 | 397 | |
|
413 | 398 | /*! |
|
414 | 399 | \internal \a event see QGraphicsWidget for details |
|
415 | 400 | */ |
|
416 | 401 | void QLegend::hideEvent(QHideEvent *event) |
|
417 | 402 | { |
|
418 | 403 | QGraphicsWidget::hideEvent(event); |
|
419 | 404 | d_ptr->m_presenter->layout()->invalidate(); |
|
420 | 405 | } |
|
421 | 406 | |
|
422 | 407 | /*! |
|
423 | 408 | \internal \a event see QGraphicsWidget for details |
|
424 | 409 | */ |
|
425 | 410 | void QLegend::showEvent(QShowEvent *event) |
|
426 | 411 | { |
|
427 | 412 | QGraphicsWidget::showEvent(event); |
|
428 | 413 | d_ptr->m_presenter->layout()->invalidate(); |
|
429 | 414 | } |
|
430 | 415 | |
|
431 | 416 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
432 | 417 | |
|
433 | 418 | QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q): |
|
434 | 419 | q_ptr(q), |
|
435 | 420 | m_presenter(presenter), |
|
436 | 421 | m_layout(new LegendLayout(q)), |
|
437 | 422 | m_chart(chart), |
|
438 | 423 | m_items(new QGraphicsItemGroup(q)), |
|
439 | 424 | m_alignment(Qt::AlignTop), |
|
440 | 425 | m_brush(QBrush()), |
|
441 | 426 | m_pen(QPen()), |
|
442 | 427 | m_labelBrush(QBrush()), |
|
443 | 428 | m_diameter(5), |
|
444 | 429 | m_attachedToChart(true), |
|
445 | 430 | m_backgroundVisible(false) |
|
446 | 431 | { |
|
447 | 432 | |
|
448 | 433 | } |
|
449 | 434 | |
|
450 | 435 | QLegendPrivate::~QLegendPrivate() |
|
451 | 436 | { |
|
452 | 437 | |
|
453 | 438 | } |
|
454 | 439 | |
|
455 | 440 | void QLegendPrivate::setOffset(qreal x, qreal y) |
|
456 | 441 | { |
|
457 | 442 | m_layout->setOffset(x,y); |
|
458 | 443 | } |
|
459 | 444 | |
|
460 | 445 | QPointF QLegendPrivate::offset() const |
|
461 | 446 | { |
|
462 | 447 | return m_layout->offset(); |
|
463 | 448 | } |
|
464 | 449 | |
|
465 | 450 | int QLegendPrivate::roundness(qreal size) |
|
466 | 451 | { |
|
467 | 452 | return 100*m_diameter/int(size); |
|
468 | 453 | } |
|
469 | 454 | |
|
470 | 455 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) |
|
471 | 456 | { |
|
472 | 457 | Q_UNUSED(domain) |
|
473 | 458 | |
|
474 | 459 | QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr); |
|
475 | 460 | |
|
476 | 461 | foreach(LegendMarker* marker, markers) { |
|
477 | 462 | marker->setFont(m_font); |
|
478 | 463 | marker->setLabelBrush(m_labelBrush); |
|
479 | 464 | m_items->addToGroup(marker); |
|
480 | 465 | m_markers<<marker; |
|
481 | 466 | } |
|
482 | 467 | |
|
483 | 468 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
484 | 469 | |
|
485 | 470 | if(series->type() == QAbstractSeries::SeriesTypePie) { |
|
486 | 471 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
487 | 472 | QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
488 | 473 | QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
489 | 474 | } |
|
490 | 475 | |
|
491 | 476 | q_ptr->layout()->invalidate(); |
|
492 | 477 | q_ptr->layout()->activate(); |
|
493 | 478 | } |
|
494 | 479 | |
|
495 | 480 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) |
|
496 | 481 | { |
|
497 | 482 | foreach (LegendMarker *marker, m_markers) { |
|
498 | 483 | if (marker->series() == series) { |
|
499 | 484 | delete marker; |
|
500 | 485 | m_markers.removeAll(marker); |
|
501 | 486 | } |
|
502 | 487 | } |
|
503 | 488 | |
|
504 | 489 | if(series->type() == QAbstractSeries::SeriesTypePie) |
|
505 | 490 | { |
|
506 | 491 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
507 | 492 | QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
508 | 493 | QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
509 | 494 | } |
|
510 | 495 | |
|
511 | 496 | q_ptr->layout()->invalidate(); |
|
512 | 497 | } |
|
513 | 498 | |
|
514 | 499 | void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series) |
|
515 | 500 | { |
|
516 | 501 | // TODO: find out which markers are are added or removed. Update them |
|
517 | 502 | // TODO: better implementation |
|
518 | 503 | handleSeriesRemoved(series); |
|
519 | 504 | Domain domain; |
|
520 | 505 | handleSeriesAdded(series, &domain); |
|
521 | 506 | } |
|
522 | 507 | |
|
523 | 508 | void QLegendPrivate::handleUpdatePieSeries() |
|
524 | 509 | { |
|
525 | 510 | //TODO: reimplement to be optimal |
|
526 | 511 | QPieSeries* series = qobject_cast<QPieSeries *> (sender()); |
|
527 | 512 | Q_ASSERT(series); |
|
528 | 513 | handleSeriesRemoved(series); |
|
529 | 514 | handleSeriesAdded(series, 0); |
|
530 | 515 | } |
|
531 | 516 | |
|
532 | 517 | void QLegendPrivate::handleSeriesVisibleChanged() |
|
533 | 518 | { |
|
534 | 519 | QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender()); |
|
535 | 520 | |
|
536 | 521 | foreach (LegendMarker* marker, m_markers) { |
|
537 | 522 | if (marker->series() == series) { |
|
538 | 523 | marker->setVisible(!marker->isVisible()); |
|
539 | 524 | } |
|
540 | 525 | } |
|
541 | 526 | |
|
542 | 527 | q_ptr->layout()->invalidate(); |
|
543 | 528 | } |
|
544 | 529 | |
|
545 | 530 | #include "moc_qlegend.cpp" |
|
546 | 531 | #include "moc_qlegend_p.cpp" |
|
547 | 532 | |
|
548 | 533 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,435 +1,435 | |||
|
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 |
Adds the \a series |
|
|
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 |
|
310 | 310 | */ |
|
311 | 311 | QAbstractAxis* QChart::axisX(QAbstractSeries* series) const |
|
312 | 312 | { |
|
313 | 313 | return d_ptr->m_dataset->axisX(series); |
|
314 | 314 | } |
|
315 | 315 | |
|
316 | 316 | /*! |
|
317 | 317 | Returns the pointer to the y axis object of the \a series |
|
318 | 318 | If no \a series is provided then default Y axis of the chart is returned. |
|
319 | 319 | */ |
|
320 | 320 | QAbstractAxis* QChart::axisY(QAbstractSeries *series) const |
|
321 | 321 | { |
|
322 | 322 | return d_ptr->m_dataset->axisY(series); |
|
323 | 323 | } |
|
324 | 324 | |
|
325 | 325 | /*! |
|
326 | 326 | Returns the legend object of the chart. Ownership stays in chart. |
|
327 | 327 | */ |
|
328 | 328 | QLegend* QChart::legend() const |
|
329 | 329 | { |
|
330 | 330 | return d_ptr->m_legend; |
|
331 | 331 | } |
|
332 | 332 | |
|
333 | 333 | /*! |
|
334 | 334 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
335 | 335 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
336 | 336 | */ |
|
337 | 337 | QRectF QChart::margins() const |
|
338 | 338 | { |
|
339 | 339 | return d_ptr->m_presenter->margins(); |
|
340 | 340 | } |
|
341 | 341 | |
|
342 | 342 | /*! |
|
343 | 343 | Sets animation \a options for the chart |
|
344 | 344 | */ |
|
345 | 345 | |
|
346 | 346 | void QChart::setAnimationOptions(AnimationOptions options) |
|
347 | 347 | { |
|
348 | 348 | d_ptr->m_presenter->setAnimationOptions(options); |
|
349 | 349 | } |
|
350 | 350 | |
|
351 | 351 | QChart::AnimationOptions QChart::animationOptions() const |
|
352 | 352 | { |
|
353 | 353 | return d_ptr->m_presenter->animationOptions(); |
|
354 | 354 | } |
|
355 | 355 | |
|
356 | 356 | /*! |
|
357 |
Scrolls the visible area of the chart by the distance defined in the \a d |
|
|
357 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. | |
|
358 | 358 | */ |
|
359 | 359 | void QChart::scroll(qreal dx, qreal dy) |
|
360 | 360 | { |
|
361 | 361 | d_ptr->m_presenter->scroll(dx, dy); |
|
362 | 362 | } |
|
363 | 363 | |
|
364 | 364 | void QChart::setBackgroundVisible(bool visible) |
|
365 | 365 | { |
|
366 | 366 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
367 | 367 | } |
|
368 | 368 | |
|
369 | 369 | bool QChart::isBackgroundVisible() const |
|
370 | 370 | { |
|
371 | 371 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
372 | 372 | } |
|
373 | 373 | |
|
374 | 374 | void QChart::setDropShadowEnabled(bool enabled) |
|
375 | 375 | { |
|
376 | 376 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
377 | 377 | } |
|
378 | 378 | |
|
379 | 379 | bool QChart::isDropShadowEnabled() const |
|
380 | 380 | { |
|
381 | 381 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
382 | 382 | } |
|
383 | 383 | |
|
384 | 384 | /*! |
|
385 | 385 | Returns all the series that are added to the chart. |
|
386 | 386 | |
|
387 | 387 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
388 | 388 | */ |
|
389 | 389 | QList<QAbstractSeries*> QChart::series() const |
|
390 | 390 | { |
|
391 | 391 | return d_ptr->m_dataset->series(); |
|
392 | 392 | } |
|
393 | 393 | |
|
394 | 394 | void QChart::setMarginsMinimum(const QRectF& margins) |
|
395 | 395 | { |
|
396 | 396 | d_ptr->m_presenter->setMarginsMinimum(margins); |
|
397 | 397 | } |
|
398 | 398 | |
|
399 | 399 | void QChart::setAxisX(QAbstractSeries *series, QAbstractAxis* axis) |
|
400 | 400 | { |
|
401 | 401 | d_ptr->m_dataset->setAxisX(series, axis); |
|
402 | 402 | } |
|
403 | 403 | |
|
404 | 404 | void QChart::setAxisY(QAbstractSeries *series, QAbstractAxis* axis) |
|
405 | 405 | { |
|
406 | 406 | d_ptr->m_dataset->setAxisY(series, axis); |
|
407 | 407 | } |
|
408 | 408 | |
|
409 | 409 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
410 | 410 | |
|
411 | 411 | QChartPrivate::QChartPrivate(): |
|
412 | 412 | m_legend(0), |
|
413 | 413 | m_dataset(0), |
|
414 | 414 | m_presenter(0) |
|
415 | 415 | { |
|
416 | 416 | |
|
417 | 417 | } |
|
418 | 418 | |
|
419 | 419 | QChartPrivate::~QChartPrivate() |
|
420 | 420 | { |
|
421 | 421 | |
|
422 | 422 | } |
|
423 | 423 | |
|
424 | 424 | void QChartPrivate::createConnections() |
|
425 | 425 | { |
|
426 | 426 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
427 | 427 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
428 | 428 | QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*))); |
|
429 | 429 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
430 | 430 | //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF))); |
|
431 | 431 | } |
|
432 | 432 | |
|
433 | 433 | #include "moc_qchart.cpp" |
|
434 | 434 | |
|
435 | 435 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now