@@ -1,1012 +1,1012 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 <QtCharts/QAbstractAxis> |
|
22 | 22 | #include <private/qabstractaxis_p.h> |
|
23 | 23 | #include <private/chartdataset_p.h> |
|
24 | 24 | #include <private/charttheme_p.h> |
|
25 | 25 | #include <private/qchart_p.h> |
|
26 | 26 | |
|
27 | 27 | QT_CHARTS_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | /*! |
|
30 | 30 | \class QAbstractAxis |
|
31 | 31 | \inmodule Qt Charts |
|
32 | 32 | \brief The QAbstractAxis class is used for manipulating chart's axis. |
|
33 | 33 | \mainclass |
|
34 | 34 | |
|
35 | 35 | Each series can be bound to one or more horizontal and vertical axes, but mixing axis types |
|
36 | 36 | that would result in different domains is not supported, such as specifying |
|
37 | 37 | QValueAxis and QLogValueAxis on the same orientation. |
|
38 | 38 | |
|
39 | 39 | Properties and visibility of various axis elements such as axis line, title, labels, grid lines, |
|
40 | 40 | and shades can be individually controlled. |
|
41 | 41 | */ |
|
42 | 42 | /*! |
|
43 | 43 | \qmltype AbstractAxis |
|
44 | 44 | \instantiates QAbstractAxis |
|
45 | 45 | \inqmlmodule QtCharts |
|
46 | 46 | |
|
47 | 47 | \brief The AbstractAxis is a base element used for specialized axis elements. |
|
48 | 48 | |
|
49 | 49 | Each series can be bound to only one horizontal and vertical axis. |
|
50 | 50 | |
|
51 | 51 | Properties and visibility of various axis elements such as axis line, title, labels, grid lines, |
|
52 | 52 | and shades can be individually controlled. |
|
53 | 53 | */ |
|
54 | 54 | |
|
55 | 55 | /*! |
|
56 | 56 | \enum QAbstractAxis::AxisType |
|
57 | 57 | |
|
58 |
The type of the |
|
|
58 | The type of the axis object. | |
|
59 | 59 | |
|
60 | 60 | \value AxisTypeNoAxis |
|
61 | 61 | \value AxisTypeValue |
|
62 | 62 | \value AxisTypeBarCategory |
|
63 | 63 | \value AxisTypeCategory |
|
64 | 64 | \value AxisTypeDateTime |
|
65 | 65 | \value AxisTypeLogValue |
|
66 | 66 | */ |
|
67 | 67 | |
|
68 | 68 | /*! |
|
69 | 69 | *\fn void QAbstractAxis::type() const |
|
70 | 70 | Returns the type of the axis |
|
71 | 71 | */ |
|
72 | 72 | |
|
73 | 73 | /*! |
|
74 | 74 | \property QAbstractAxis::lineVisible |
|
75 | 75 | The visibility of the axis line |
|
76 | 76 | */ |
|
77 | 77 | /*! |
|
78 | 78 | \qmlproperty bool AbstractAxis::lineVisible |
|
79 | 79 | The visibility of the axis line |
|
80 | 80 | */ |
|
81 | 81 | |
|
82 | 82 | /*! |
|
83 | 83 | \property QAbstractAxis::linePen |
|
84 | 84 | The pen of the line. |
|
85 | 85 | */ |
|
86 | 86 | |
|
87 | 87 | /*! |
|
88 | 88 | \property QAbstractAxis::labelsVisible |
|
89 | 89 | Defines if axis labels are visible. |
|
90 | 90 | */ |
|
91 | 91 | /*! |
|
92 | 92 | \qmlproperty bool AbstractAxis::labelsVisible |
|
93 | 93 | Defines if axis labels are visible. |
|
94 | 94 | */ |
|
95 | 95 | |
|
96 | 96 | /*! |
|
97 | 97 | \property QAbstractAxis::labelsPen |
|
98 | 98 | \deprecated |
|
99 | 99 | The pen of the labels. |
|
100 | 100 | */ |
|
101 | 101 | |
|
102 | 102 | /*! |
|
103 | 103 | \property QAbstractAxis::labelsBrush |
|
104 | 104 | The brush of the labels. Only the color of the brush is relevant. |
|
105 | 105 | */ |
|
106 | 106 | |
|
107 | 107 | /*! |
|
108 | 108 | \property QAbstractAxis::visible |
|
109 | 109 | The visibility of the axis. |
|
110 | 110 | */ |
|
111 | 111 | /*! |
|
112 | 112 | \qmlproperty bool AbstractAxis::visible |
|
113 | 113 | The visibility of the axis. |
|
114 | 114 | */ |
|
115 | 115 | |
|
116 | 116 | /*! |
|
117 | 117 | \property QAbstractAxis::gridVisible |
|
118 | 118 | The visibility of the grid lines. |
|
119 | 119 | */ |
|
120 | 120 | /*! |
|
121 | 121 | \qmlproperty bool AbstractAxis::gridVisible |
|
122 | 122 | The visibility of the grid lines. |
|
123 | 123 | */ |
|
124 | 124 | |
|
125 | 125 | /*! |
|
126 | 126 | \property QAbstractAxis::color |
|
127 | 127 | The color of the axis and ticks. |
|
128 | 128 | */ |
|
129 | 129 | /*! |
|
130 | 130 | \qmlproperty color AbstractAxis::color |
|
131 | 131 | The color of the axis and ticks. |
|
132 | 132 | */ |
|
133 | 133 | |
|
134 | 134 | /*! |
|
135 | 135 | \property QAbstractAxis::gridLinePen |
|
136 | 136 | The pen of the grid line. |
|
137 | 137 | */ |
|
138 | 138 | |
|
139 | 139 | /*! |
|
140 | 140 | \property QAbstractAxis::labelsFont |
|
141 | 141 | The font of the axis labels. |
|
142 | 142 | */ |
|
143 | 143 | |
|
144 | 144 | /*! |
|
145 | 145 | \qmlproperty Font AbstractAxis::labelsFont |
|
146 | 146 | The font of the axis labels. |
|
147 | 147 | |
|
148 | 148 | See the Qt documentation for more details of Font. |
|
149 | 149 | */ |
|
150 | 150 | |
|
151 | 151 | /*! |
|
152 | 152 | \property QAbstractAxis::labelsColor |
|
153 | 153 | The color of the axis labels. |
|
154 | 154 | */ |
|
155 | 155 | /*! |
|
156 | 156 | \qmlproperty color AbstractAxis::labelsColor |
|
157 | 157 | The color of the axis labels. |
|
158 | 158 | */ |
|
159 | 159 | |
|
160 | 160 | /*! |
|
161 | 161 | \property QAbstractAxis::labelsAngle |
|
162 | 162 | The angle of the axis labels in degrees. |
|
163 | 163 | */ |
|
164 | 164 | /*! |
|
165 | 165 | \qmlproperty int AbstractAxis::labelsAngle |
|
166 | 166 | The angle of the axis labels in degrees. |
|
167 | 167 | */ |
|
168 | 168 | |
|
169 | 169 | /*! |
|
170 | 170 | \property QAbstractAxis::shadesVisible |
|
171 | 171 | The visibility of the axis shades. |
|
172 | 172 | */ |
|
173 | 173 | /*! |
|
174 | 174 | \qmlproperty bool AbstractAxis::shadesVisible |
|
175 | 175 | The visibility of the axis shades. |
|
176 | 176 | */ |
|
177 | 177 | |
|
178 | 178 | /*! |
|
179 | 179 | \property QAbstractAxis::shadesColor |
|
180 | 180 | The fill (brush) color of the axis shades. |
|
181 | 181 | */ |
|
182 | 182 | /*! |
|
183 | 183 | \qmlproperty color AbstractAxis::shadesColor |
|
184 | 184 | The fill (brush) color of the axis shades. |
|
185 | 185 | */ |
|
186 | 186 | |
|
187 | 187 | /*! |
|
188 | 188 | \property QAbstractAxis::shadesBorderColor |
|
189 | 189 | The border (pen) color of the axis shades. |
|
190 | 190 | */ |
|
191 | 191 | /*! |
|
192 | 192 | \qmlproperty color AbstractAxis::shadesBorderColor |
|
193 | 193 | The border (pen) color of the axis shades. |
|
194 | 194 | */ |
|
195 | 195 | |
|
196 | 196 | /*! |
|
197 | 197 | \property QAbstractAxis::shadesPen |
|
198 | 198 | The pen of the axis shades (area between grid lines). |
|
199 | 199 | */ |
|
200 | 200 | |
|
201 | 201 | /*! |
|
202 | 202 | \property QAbstractAxis::shadesBrush |
|
203 | 203 | The brush of the axis shades (area between grid lines). |
|
204 | 204 | */ |
|
205 | 205 | |
|
206 | 206 | /*! |
|
207 | 207 | \property QAbstractAxis::titleVisible |
|
208 | 208 | The visibility of the axis title. By default the value is true. |
|
209 | 209 | */ |
|
210 | 210 | /*! |
|
211 | 211 | \qmlproperty bool AbstractAxis::titleVisible |
|
212 | 212 | The visibility of the axis title. By default the value is true. |
|
213 | 213 | */ |
|
214 | 214 | |
|
215 | 215 | /*! |
|
216 | 216 | \property QAbstractAxis::titleText |
|
217 | 217 | The title of the axis. Empty by default. Axis titles support html formatting. |
|
218 | 218 | */ |
|
219 | 219 | /*! |
|
220 | 220 | \qmlproperty String AbstractAxis::titleText |
|
221 | 221 | The title of the axis. Empty by default. Axis titles support html formatting. |
|
222 | 222 | */ |
|
223 | 223 | |
|
224 | 224 | /*! |
|
225 | 225 | \property QAbstractAxis::titlePen |
|
226 | 226 | \deprecated |
|
227 | 227 | The pen of the title text. |
|
228 | 228 | */ |
|
229 | 229 | |
|
230 | 230 | /*! |
|
231 | 231 | \property QAbstractAxis::titleBrush |
|
232 | 232 | The brush of the title text. Only the color of the brush is relevant. |
|
233 | 233 | */ |
|
234 | 234 | |
|
235 | 235 | /*! |
|
236 | 236 | \property QAbstractAxis::titleFont |
|
237 | 237 | The font of the title of the axis. |
|
238 | 238 | */ |
|
239 | 239 | /*! |
|
240 | 240 | \qmlproperty Font AbstractAxis::titleFont |
|
241 | 241 | The font of the title of the axis. |
|
242 | 242 | */ |
|
243 | 243 | |
|
244 | 244 | /*! |
|
245 | 245 | \property QAbstractAxis::orientation |
|
246 | 246 | The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart. |
|
247 | 247 | */ |
|
248 | 248 | /*! |
|
249 | 249 | \qmlproperty Qt.Orientation AbstractAxis::orientation |
|
250 | 250 | The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a series. |
|
251 | 251 | */ |
|
252 | 252 | |
|
253 | 253 | /*! |
|
254 | 254 | \property QAbstractAxis::alignment |
|
255 | 255 | The alignment of the axis. Can be Qt::AlignLeft, Qt::AlignRight, Qt::AlignBottom, or Qt::AlignTop. |
|
256 | 256 | */ |
|
257 | 257 | /*! |
|
258 | 258 | \qmlproperty alignment AbstractAxis::alignment |
|
259 | 259 | The alignment of the axis. Can be Qt.AlignLeft, Qt.AlignRight, Qt.AlignBottom, or Qt.AlignTop. |
|
260 | 260 | */ |
|
261 | 261 | |
|
262 | 262 | /*! |
|
263 | 263 | \fn void QAbstractAxis::visibleChanged(bool visible) |
|
264 | 264 | Visibility of the axis has changed to \a visible. |
|
265 | 265 | */ |
|
266 | 266 | /*! |
|
267 | 267 | \qmlsignal AbstractAxis::onVisibleChanged(bool visible) |
|
268 | 268 | Visibility of the axis has changed to \a visible. |
|
269 | 269 | */ |
|
270 | 270 | |
|
271 | 271 | /*! |
|
272 | 272 | \fn void QAbstractAxis::linePenChanged(const QPen& pen) |
|
273 | 273 | The pen of the line of the axis has changed to \a pen. |
|
274 | 274 | */ |
|
275 | 275 | |
|
276 | 276 | /*! |
|
277 | 277 | \fn void QAbstractAxis::lineVisibleChanged(bool visible) |
|
278 | 278 | Visibility of the axis line has changed to \a visible. |
|
279 | 279 | */ |
|
280 | 280 | /*! |
|
281 | 281 | \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible) |
|
282 | 282 | Visibility of the axis line has changed to \a visible. |
|
283 | 283 | */ |
|
284 | 284 | |
|
285 | 285 | /*! |
|
286 | 286 | \fn void QAbstractAxis::labelsVisibleChanged(bool visible) |
|
287 | 287 | Visibility of the labels of the axis has changed to \a visible. |
|
288 | 288 | */ |
|
289 | 289 | /*! |
|
290 | 290 | \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible) |
|
291 | 291 | Visibility of the labels of the axis has changed to \a visible. |
|
292 | 292 | */ |
|
293 | 293 | |
|
294 | 294 | /*! |
|
295 | 295 | \fn void QAbstractAxis::labelsFontChanged(const QFont& font) |
|
296 | 296 | The font of the axis labels has changed to \a font. |
|
297 | 297 | */ |
|
298 | 298 | /*! |
|
299 | 299 | \qmlsignal AbstractAxis::onLabelsFontChanged(Font font) |
|
300 | 300 | The font of the axis labels has changed to \a font. |
|
301 | 301 | */ |
|
302 | 302 | |
|
303 | 303 | /*! |
|
304 | 304 | \fn void QAbstractAxis::labelsPenChanged(const QPen& pen) |
|
305 | 305 | \deprecated |
|
306 | 306 | The pen of the axis labels has changed to \a pen. |
|
307 | 307 | */ |
|
308 | 308 | |
|
309 | 309 | /*! |
|
310 | 310 | \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush) |
|
311 | 311 | The brush of the axis labels has changed to \a brush. |
|
312 | 312 | */ |
|
313 | 313 | |
|
314 | 314 | /*! |
|
315 | 315 | \fn void QAbstractAxis::labelsAngleChanged(int angle) |
|
316 | 316 | The angle of the axis labels has changed to \a angle. |
|
317 | 317 | */ |
|
318 | 318 | /*! |
|
319 | 319 | \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle) |
|
320 | 320 | The angle of the axis labels has changed to \a angle. |
|
321 | 321 | */ |
|
322 | 322 | |
|
323 | 323 | /*! |
|
324 | 324 | \fn void QAbstractAxis::gridVisibleChanged(bool visible) |
|
325 | 325 | Visibility of the grid lines of the axis has changed to \a visible. |
|
326 | 326 | */ |
|
327 | 327 | /*! |
|
328 | 328 | \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible) |
|
329 | 329 | Visibility of the grid lines of the axis has changed to \a visible. |
|
330 | 330 | */ |
|
331 | 331 | |
|
332 | 332 | /*! |
|
333 | 333 | \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen) |
|
334 | 334 | The pen of the grid line has changed to \a pen. |
|
335 | 335 | */ |
|
336 | 336 | |
|
337 | 337 | /*! |
|
338 | 338 | \fn void QAbstractAxis::colorChanged(QColor color) |
|
339 | 339 | Emitted if the \a color of the axis is changed. |
|
340 | 340 | */ |
|
341 | 341 | /*! |
|
342 | 342 | \qmlsignal AbstractAxis::onColorChanged(QColor color) |
|
343 | 343 | Emitted if the \a color of the axis is changed. |
|
344 | 344 | */ |
|
345 | 345 | |
|
346 | 346 | /*! |
|
347 | 347 | \fn void QAbstractAxis::labelsColorChanged(QColor color) |
|
348 | 348 | Emitted if the \a color of the axis labels is changed. |
|
349 | 349 | */ |
|
350 | 350 | /*! |
|
351 | 351 | \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color) |
|
352 | 352 | Emitted if the \a color of the axis labels is changed. |
|
353 | 353 | */ |
|
354 | 354 | |
|
355 | 355 | /*! |
|
356 | 356 | \fn void QAbstractAxis::titleVisibleChanged(bool visible) |
|
357 | 357 | Visibility of the title text of the axis has changed to \a visible. |
|
358 | 358 | */ |
|
359 | 359 | /*! |
|
360 | 360 | \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible) |
|
361 | 361 | Visibility of the title text of the axis has changed to \a visible. |
|
362 | 362 | */ |
|
363 | 363 | |
|
364 | 364 | /*! |
|
365 | 365 | \fn void QAbstractAxis::titleTextChanged(const QString& text) |
|
366 | 366 | The text of the axis title has changed to \a text. |
|
367 | 367 | */ |
|
368 | 368 | /*! |
|
369 | 369 | \qmlsignal AbstractAxis::onTitleTextChanged(String text) |
|
370 | 370 | The text of the axis title has changed to \a text. |
|
371 | 371 | */ |
|
372 | 372 | |
|
373 | 373 | /*! |
|
374 | 374 | \fn void QAbstractAxis::titlePenChanged(const QPen& pen) |
|
375 | 375 | \deprecated |
|
376 | 376 | The pen of the axis shades has changed to \a pen. |
|
377 | 377 | */ |
|
378 | 378 | |
|
379 | 379 | /*! |
|
380 | 380 | \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush) |
|
381 | 381 | The brush of the axis title has changed to \a brush. |
|
382 | 382 | */ |
|
383 | 383 | |
|
384 | 384 | /*! |
|
385 | 385 | \fn void QAbstractAxis::titleFontChanged(const QFont& font) |
|
386 | 386 | The font of the axis title has changed to \a font. |
|
387 | 387 | */ |
|
388 | 388 | /*! |
|
389 | 389 | \qmlsignal AbstractAxis::onTitleFontChanged(Font font) |
|
390 | 390 | The font of the axis title has changed to \a font. |
|
391 | 391 | */ |
|
392 | 392 | |
|
393 | 393 | /*! |
|
394 | 394 | \fn void QAbstractAxis::shadesVisibleChanged(bool) |
|
395 | 395 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
396 | 396 | */ |
|
397 | 397 | /*! |
|
398 | 398 | \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible) |
|
399 | 399 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
400 | 400 | */ |
|
401 | 401 | |
|
402 | 402 | /*! |
|
403 | 403 | \fn void QAbstractAxis::shadesColorChanged(QColor color) |
|
404 | 404 | Emitted if the \a color of the axis shades is changed. |
|
405 | 405 | */ |
|
406 | 406 | /*! |
|
407 | 407 | \qmlsignal AbstractAxis::onShadesColorChanged(QColor color) |
|
408 | 408 | Emitted if the \a color of the axis shades is changed. |
|
409 | 409 | */ |
|
410 | 410 | |
|
411 | 411 | /*! |
|
412 | 412 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) |
|
413 | 413 | Emitted if the border \a color of the axis shades is changed. |
|
414 | 414 | */ |
|
415 | 415 | /*! |
|
416 | 416 | \qmlsignal AbstractAxis::onBorderColorChanged(QColor color) |
|
417 | 417 | Emitted if the border \a color of the axis shades is changed. |
|
418 | 418 | */ |
|
419 | 419 | |
|
420 | 420 | /*! |
|
421 | 421 | \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush) |
|
422 | 422 | The brush of the axis shades has changed to \a brush. |
|
423 | 423 | */ |
|
424 | 424 | |
|
425 | 425 | /*! |
|
426 | 426 | \fn void QAbstractAxis::shadesPenChanged(const QPen& pen) |
|
427 | 427 | The pen of the axis shades has changed to \a pen. |
|
428 | 428 | */ |
|
429 | 429 | |
|
430 | 430 | /*! |
|
431 | 431 | \internal |
|
432 | 432 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
433 | 433 | QChart when axis added. |
|
434 | 434 | */ |
|
435 | 435 | |
|
436 | 436 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) |
|
437 | 437 | : QObject(parent), |
|
438 | 438 | d_ptr(&d) |
|
439 | 439 | { |
|
440 | 440 | } |
|
441 | 441 | |
|
442 | 442 | /*! |
|
443 | 443 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
444 | 444 | */ |
|
445 | 445 | |
|
446 | 446 | QAbstractAxis::~QAbstractAxis() |
|
447 | 447 | { |
|
448 | 448 | if (d_ptr->m_chart) |
|
449 | 449 | qFatal("Still binded axis detected !"); |
|
450 | 450 | } |
|
451 | 451 | |
|
452 | 452 | /*! |
|
453 | 453 | Sets \a pen used to draw axis line and ticks. |
|
454 | 454 | */ |
|
455 | 455 | void QAbstractAxis::setLinePen(const QPen &pen) |
|
456 | 456 | { |
|
457 | 457 | if (d_ptr->m_axisPen != pen) { |
|
458 | 458 | d_ptr->m_axisPen = pen; |
|
459 | 459 | emit linePenChanged(pen); |
|
460 | 460 | } |
|
461 | 461 | } |
|
462 | 462 | |
|
463 | 463 | /*! |
|
464 | 464 | Returns pen used to draw axis and ticks. |
|
465 | 465 | */ |
|
466 | 466 | QPen QAbstractAxis::linePen() const |
|
467 | 467 | { |
|
468 | 468 | if (d_ptr->m_axisPen == QChartPrivate::defaultPen()) |
|
469 | 469 | return QPen(); |
|
470 | 470 | else |
|
471 | 471 | return d_ptr->m_axisPen; |
|
472 | 472 | } |
|
473 | 473 | |
|
474 | 474 | void QAbstractAxis::setLinePenColor(QColor color) |
|
475 | 475 | { |
|
476 | 476 | QPen p = d_ptr->m_axisPen; |
|
477 | 477 | if (p.color() != color) { |
|
478 | 478 | p.setColor(color); |
|
479 | 479 | setLinePen(p); |
|
480 | 480 | emit colorChanged(color); |
|
481 | 481 | } |
|
482 | 482 | } |
|
483 | 483 | |
|
484 | 484 | QColor QAbstractAxis::linePenColor() const |
|
485 | 485 | { |
|
486 | 486 | return linePen().color(); |
|
487 | 487 | } |
|
488 | 488 | |
|
489 | 489 | /*! |
|
490 | 490 | Sets if axis and ticks are \a visible. |
|
491 | 491 | */ |
|
492 | 492 | void QAbstractAxis::setLineVisible(bool visible) |
|
493 | 493 | { |
|
494 | 494 | if (d_ptr->m_arrowVisible != visible) { |
|
495 | 495 | d_ptr->m_arrowVisible = visible; |
|
496 | 496 | emit lineVisibleChanged(visible); |
|
497 | 497 | } |
|
498 | 498 | } |
|
499 | 499 | |
|
500 | 500 | bool QAbstractAxis::isLineVisible() const |
|
501 | 501 | { |
|
502 | 502 | return d_ptr->m_arrowVisible; |
|
503 | 503 | } |
|
504 | 504 | |
|
505 | 505 | void QAbstractAxis::setGridLineVisible(bool visible) |
|
506 | 506 | { |
|
507 | 507 | if (d_ptr->m_gridLineVisible != visible) { |
|
508 | 508 | d_ptr->m_gridLineVisible = visible; |
|
509 | 509 | emit gridVisibleChanged(visible); |
|
510 | 510 | } |
|
511 | 511 | } |
|
512 | 512 | |
|
513 | 513 | bool QAbstractAxis::isGridLineVisible() const |
|
514 | 514 | { |
|
515 | 515 | return d_ptr->m_gridLineVisible; |
|
516 | 516 | } |
|
517 | 517 | |
|
518 | 518 | /*! |
|
519 | 519 | Sets \a pen used to draw grid line. |
|
520 | 520 | */ |
|
521 | 521 | void QAbstractAxis::setGridLinePen(const QPen &pen) |
|
522 | 522 | { |
|
523 | 523 | if (d_ptr->m_gridLinePen != pen) { |
|
524 | 524 | d_ptr->m_gridLinePen = pen; |
|
525 | 525 | emit gridLinePenChanged(pen); |
|
526 | 526 | } |
|
527 | 527 | } |
|
528 | 528 | |
|
529 | 529 | /*! |
|
530 | 530 | Returns pen used to draw grid. |
|
531 | 531 | */ |
|
532 | 532 | QPen QAbstractAxis::gridLinePen() const |
|
533 | 533 | { |
|
534 | 534 | if (d_ptr->m_gridLinePen == QChartPrivate::defaultPen()) |
|
535 | 535 | return QPen(); |
|
536 | 536 | else |
|
537 | 537 | return d_ptr->m_gridLinePen; |
|
538 | 538 | } |
|
539 | 539 | |
|
540 | 540 | void QAbstractAxis::setLabelsVisible(bool visible) |
|
541 | 541 | { |
|
542 | 542 | if (d_ptr->m_labelsVisible != visible) { |
|
543 | 543 | d_ptr->m_labelsVisible = visible; |
|
544 | 544 | emit labelsVisibleChanged(visible); |
|
545 | 545 | } |
|
546 | 546 | } |
|
547 | 547 | |
|
548 | 548 | bool QAbstractAxis::labelsVisible() const |
|
549 | 549 | { |
|
550 | 550 | return d_ptr->m_labelsVisible; |
|
551 | 551 | } |
|
552 | 552 | |
|
553 | 553 | void QAbstractAxis::setLabelsPen(const QPen &pen) |
|
554 | 554 | { |
|
555 | 555 | if (d_ptr->m_labelsPen != pen) { |
|
556 | 556 | d_ptr->m_labelsPen = pen; |
|
557 | 557 | emit labelsPenChanged(pen); |
|
558 | 558 | } |
|
559 | 559 | } |
|
560 | 560 | |
|
561 | 561 | QPen QAbstractAxis::labelsPen() const |
|
562 | 562 | { |
|
563 | 563 | if (d_ptr->m_labelsPen == QChartPrivate::defaultPen()) |
|
564 | 564 | return QPen(); |
|
565 | 565 | else |
|
566 | 566 | return d_ptr->m_labelsPen; |
|
567 | 567 | } |
|
568 | 568 | |
|
569 | 569 | /*! |
|
570 | 570 | Sets \a brush used to draw labels. |
|
571 | 571 | */ |
|
572 | 572 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) |
|
573 | 573 | { |
|
574 | 574 | if (d_ptr->m_labelsBrush != brush) { |
|
575 | 575 | d_ptr->m_labelsBrush = brush; |
|
576 | 576 | emit labelsBrushChanged(brush); |
|
577 | 577 | } |
|
578 | 578 | } |
|
579 | 579 | |
|
580 | 580 | /*! |
|
581 | 581 | Returns brush used to draw labels. |
|
582 | 582 | */ |
|
583 | 583 | QBrush QAbstractAxis::labelsBrush() const |
|
584 | 584 | { |
|
585 | 585 | if (d_ptr->m_labelsBrush == QChartPrivate::defaultBrush()) |
|
586 | 586 | return QBrush(); |
|
587 | 587 | else |
|
588 | 588 | return d_ptr->m_labelsBrush; |
|
589 | 589 | } |
|
590 | 590 | |
|
591 | 591 | /*! |
|
592 | 592 | Sets \a font used to draw labels. |
|
593 | 593 | */ |
|
594 | 594 | void QAbstractAxis::setLabelsFont(const QFont &font) |
|
595 | 595 | { |
|
596 | 596 | if (d_ptr->m_labelsFont != font) { |
|
597 | 597 | d_ptr->m_labelsFont = font; |
|
598 | 598 | emit labelsFontChanged(font); |
|
599 | 599 | } |
|
600 | 600 | } |
|
601 | 601 | |
|
602 | 602 | /*! |
|
603 | 603 | Returns font used to draw labels. |
|
604 | 604 | */ |
|
605 | 605 | QFont QAbstractAxis::labelsFont() const |
|
606 | 606 | { |
|
607 | 607 | if (d_ptr->m_labelsFont == QChartPrivate::defaultFont()) |
|
608 | 608 | return QFont(); |
|
609 | 609 | else |
|
610 | 610 | return d_ptr->m_labelsFont; |
|
611 | 611 | } |
|
612 | 612 | |
|
613 | 613 | void QAbstractAxis::setLabelsAngle(int angle) |
|
614 | 614 | { |
|
615 | 615 | if (d_ptr->m_labelsAngle != angle) { |
|
616 | 616 | d_ptr->m_labelsAngle = angle; |
|
617 | 617 | emit labelsAngleChanged(angle); |
|
618 | 618 | } |
|
619 | 619 | } |
|
620 | 620 | |
|
621 | 621 | int QAbstractAxis::labelsAngle() const |
|
622 | 622 | { |
|
623 | 623 | return d_ptr->m_labelsAngle; |
|
624 | 624 | } |
|
625 | 625 | void QAbstractAxis::setLabelsColor(QColor color) |
|
626 | 626 | { |
|
627 | 627 | QBrush b = d_ptr->m_labelsBrush; |
|
628 | 628 | if (b.color() != color) { |
|
629 | 629 | b.setColor(color); |
|
630 | 630 | setLabelsBrush(b); |
|
631 | 631 | emit labelsColorChanged(color); |
|
632 | 632 | } |
|
633 | 633 | } |
|
634 | 634 | |
|
635 | 635 | QColor QAbstractAxis::labelsColor() const |
|
636 | 636 | { |
|
637 | 637 | return labelsBrush().color(); |
|
638 | 638 | } |
|
639 | 639 | |
|
640 | 640 | void QAbstractAxis::setTitleVisible(bool visible) |
|
641 | 641 | { |
|
642 | 642 | if (d_ptr->m_titleVisible != visible) { |
|
643 | 643 | d_ptr->m_titleVisible = visible; |
|
644 | 644 | emit titleVisibleChanged(visible); |
|
645 | 645 | } |
|
646 | 646 | } |
|
647 | 647 | |
|
648 | 648 | bool QAbstractAxis::isTitleVisible() const |
|
649 | 649 | { |
|
650 | 650 | return d_ptr->m_titleVisible; |
|
651 | 651 | } |
|
652 | 652 | |
|
653 | 653 | void QAbstractAxis::setTitlePen(const QPen &pen) |
|
654 | 654 | { |
|
655 | 655 | if (d_ptr->m_titlePen != pen) { |
|
656 | 656 | d_ptr->m_titlePen = pen; |
|
657 | 657 | emit titlePenChanged(pen); |
|
658 | 658 | } |
|
659 | 659 | } |
|
660 | 660 | |
|
661 | 661 | QPen QAbstractAxis::titlePen() const |
|
662 | 662 | { |
|
663 | 663 | if (d_ptr->m_titlePen == QChartPrivate::defaultPen()) |
|
664 | 664 | return QPen(); |
|
665 | 665 | else |
|
666 | 666 | return d_ptr->m_titlePen; |
|
667 | 667 | } |
|
668 | 668 | |
|
669 | 669 | /*! |
|
670 | 670 | Sets \a brush used to draw title. |
|
671 | 671 | */ |
|
672 | 672 | void QAbstractAxis::setTitleBrush(const QBrush &brush) |
|
673 | 673 | { |
|
674 | 674 | if (d_ptr->m_titleBrush != brush) { |
|
675 | 675 | d_ptr->m_titleBrush = brush; |
|
676 | 676 | emit titleBrushChanged(brush); |
|
677 | 677 | } |
|
678 | 678 | } |
|
679 | 679 | |
|
680 | 680 | /*! |
|
681 | 681 | Returns brush used to draw title. |
|
682 | 682 | */ |
|
683 | 683 | QBrush QAbstractAxis::titleBrush() const |
|
684 | 684 | { |
|
685 | 685 | if (d_ptr->m_titleBrush == QChartPrivate::defaultBrush()) |
|
686 | 686 | return QBrush(); |
|
687 | 687 | else |
|
688 | 688 | return d_ptr->m_titleBrush; |
|
689 | 689 | } |
|
690 | 690 | |
|
691 | 691 | /*! |
|
692 | 692 | Sets \a font used to draw title. |
|
693 | 693 | */ |
|
694 | 694 | void QAbstractAxis::setTitleFont(const QFont &font) |
|
695 | 695 | { |
|
696 | 696 | if (d_ptr->m_titleFont != font) { |
|
697 | 697 | d_ptr->m_titleFont = font; |
|
698 | 698 | emit titleFontChanged(font); |
|
699 | 699 | } |
|
700 | 700 | } |
|
701 | 701 | |
|
702 | 702 | /*! |
|
703 | 703 | Returns font used to draw title. |
|
704 | 704 | */ |
|
705 | 705 | QFont QAbstractAxis::titleFont() const |
|
706 | 706 | { |
|
707 | 707 | if (d_ptr->m_titleFont == QChartPrivate::defaultFont()) |
|
708 | 708 | return QFont(); |
|
709 | 709 | else |
|
710 | 710 | return d_ptr->m_titleFont; |
|
711 | 711 | } |
|
712 | 712 | |
|
713 | 713 | void QAbstractAxis::setTitleText(const QString &title) |
|
714 | 714 | { |
|
715 | 715 | if (d_ptr->m_title != title) { |
|
716 | 716 | d_ptr->m_title = title; |
|
717 | 717 | emit titleTextChanged(title); |
|
718 | 718 | } |
|
719 | 719 | } |
|
720 | 720 | |
|
721 | 721 | QString QAbstractAxis::titleText() const |
|
722 | 722 | { |
|
723 | 723 | return d_ptr->m_title; |
|
724 | 724 | } |
|
725 | 725 | |
|
726 | 726 | |
|
727 | 727 | void QAbstractAxis::setShadesVisible(bool visible) |
|
728 | 728 | { |
|
729 | 729 | if (d_ptr->m_shadesVisible != visible) { |
|
730 | 730 | d_ptr->m_shadesVisible = visible; |
|
731 | 731 | emit shadesVisibleChanged(visible); |
|
732 | 732 | } |
|
733 | 733 | } |
|
734 | 734 | |
|
735 | 735 | bool QAbstractAxis::shadesVisible() const |
|
736 | 736 | { |
|
737 | 737 | return d_ptr->m_shadesVisible; |
|
738 | 738 | } |
|
739 | 739 | |
|
740 | 740 | /*! |
|
741 | 741 | Sets \a pen used to draw shades. |
|
742 | 742 | */ |
|
743 | 743 | void QAbstractAxis::setShadesPen(const QPen &pen) |
|
744 | 744 | { |
|
745 | 745 | if (d_ptr->m_shadesPen != pen) { |
|
746 | 746 | d_ptr->m_shadesPen = pen; |
|
747 | 747 | emit shadesPenChanged(pen); |
|
748 | 748 | } |
|
749 | 749 | } |
|
750 | 750 | |
|
751 | 751 | /*! |
|
752 | 752 | Returns pen used to draw shades. |
|
753 | 753 | */ |
|
754 | 754 | QPen QAbstractAxis::shadesPen() const |
|
755 | 755 | { |
|
756 | 756 | if (d_ptr->m_shadesPen == QChartPrivate::defaultPen()) |
|
757 | 757 | return QPen(); |
|
758 | 758 | else |
|
759 | 759 | return d_ptr->m_shadesPen; |
|
760 | 760 | } |
|
761 | 761 | |
|
762 | 762 | /*! |
|
763 | 763 | Sets \a brush used to draw shades. |
|
764 | 764 | */ |
|
765 | 765 | void QAbstractAxis::setShadesBrush(const QBrush &brush) |
|
766 | 766 | { |
|
767 | 767 | if (d_ptr->m_shadesBrush != brush) { |
|
768 | 768 | d_ptr->m_shadesBrush = brush; |
|
769 | 769 | emit shadesBrushChanged(brush); |
|
770 | 770 | } |
|
771 | 771 | } |
|
772 | 772 | |
|
773 | 773 | /*! |
|
774 | 774 | Returns brush used to draw shades. |
|
775 | 775 | */ |
|
776 | 776 | QBrush QAbstractAxis::shadesBrush() const |
|
777 | 777 | { |
|
778 | 778 | if (d_ptr->m_shadesBrush == QChartPrivate::defaultBrush()) |
|
779 | 779 | return QBrush(Qt::SolidPattern); |
|
780 | 780 | else |
|
781 | 781 | return d_ptr->m_shadesBrush; |
|
782 | 782 | } |
|
783 | 783 | |
|
784 | 784 | void QAbstractAxis::setShadesColor(QColor color) |
|
785 | 785 | { |
|
786 | 786 | QBrush b = d_ptr->m_shadesBrush; |
|
787 | 787 | if (b.color() != color) { |
|
788 | 788 | b.setColor(color); |
|
789 | 789 | setShadesBrush(b); |
|
790 | 790 | emit shadesColorChanged(color); |
|
791 | 791 | } |
|
792 | 792 | } |
|
793 | 793 | |
|
794 | 794 | QColor QAbstractAxis::shadesColor() const |
|
795 | 795 | { |
|
796 | 796 | return shadesBrush().color(); |
|
797 | 797 | } |
|
798 | 798 | |
|
799 | 799 | void QAbstractAxis::setShadesBorderColor(QColor color) |
|
800 | 800 | { |
|
801 | 801 | QPen p = d_ptr->m_shadesPen; |
|
802 | 802 | if (p.color() != color) { |
|
803 | 803 | p.setColor(color); |
|
804 | 804 | setShadesPen(p); |
|
805 | 805 | emit shadesColorChanged(color); |
|
806 | 806 | } |
|
807 | 807 | } |
|
808 | 808 | |
|
809 | 809 | QColor QAbstractAxis::shadesBorderColor() const |
|
810 | 810 | { |
|
811 | 811 | return shadesPen().color(); |
|
812 | 812 | } |
|
813 | 813 | |
|
814 | 814 | |
|
815 | 815 | bool QAbstractAxis::isVisible() const |
|
816 | 816 | { |
|
817 | 817 | return d_ptr->m_visible; |
|
818 | 818 | } |
|
819 | 819 | |
|
820 | 820 | /*! |
|
821 | 821 | Sets axis, shades, labels and grid lines to be visible. |
|
822 | 822 | */ |
|
823 | 823 | void QAbstractAxis::setVisible(bool visible) |
|
824 | 824 | { |
|
825 | 825 | if (d_ptr->m_visible != visible) { |
|
826 | 826 | d_ptr->m_visible = visible; |
|
827 | 827 | emit visibleChanged(visible); |
|
828 | 828 | } |
|
829 | 829 | } |
|
830 | 830 | |
|
831 | 831 | |
|
832 | 832 | /*! |
|
833 | 833 | Sets axis, shades, labels and grid lines to be visible. |
|
834 | 834 | */ |
|
835 | 835 | void QAbstractAxis::show() |
|
836 | 836 | { |
|
837 | 837 | setVisible(true); |
|
838 | 838 | } |
|
839 | 839 | |
|
840 | 840 | /*! |
|
841 | 841 | Sets axis, shades, labels and grid lines to not be visible. |
|
842 | 842 | */ |
|
843 | 843 | void QAbstractAxis::hide() |
|
844 | 844 | { |
|
845 | 845 | setVisible(false); |
|
846 | 846 | } |
|
847 | 847 | |
|
848 | 848 | /*! |
|
849 | 849 | Sets the minimum value shown on the axis. |
|
850 | 850 | Depending on the actual axis type the \a min parameter is converted to appropriate type. |
|
851 | 851 | If the conversion is impossible then the function call does nothing |
|
852 | 852 | */ |
|
853 | 853 | void QAbstractAxis::setMin(const QVariant &min) |
|
854 | 854 | { |
|
855 | 855 | d_ptr->setMin(min); |
|
856 | 856 | } |
|
857 | 857 | |
|
858 | 858 | /*! |
|
859 | 859 | Sets the maximum value shown on the axis. |
|
860 | 860 | Depending on the actual axis type the \a max parameter is converted to appropriate type. |
|
861 | 861 | If the conversion is impossible then the function call does nothing |
|
862 | 862 | */ |
|
863 | 863 | void QAbstractAxis::setMax(const QVariant &max) |
|
864 | 864 | { |
|
865 | 865 | d_ptr->setMax(max); |
|
866 | 866 | } |
|
867 | 867 | |
|
868 | 868 | /*! |
|
869 | 869 | Sets the range shown on the axis. |
|
870 | 870 | Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types. |
|
871 | 871 | If the conversion is impossible then the function call does nothing. |
|
872 | 872 | */ |
|
873 | 873 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) |
|
874 | 874 | { |
|
875 | 875 | d_ptr->setRange(min, max); |
|
876 | 876 | } |
|
877 | 877 | |
|
878 | 878 | |
|
879 | 879 | /*! |
|
880 | 880 | Returns the orientation in which the axis is being used (Vertical or Horizontal) |
|
881 | 881 | */ |
|
882 | 882 | Qt::Orientation QAbstractAxis::orientation() |
|
883 | 883 | { |
|
884 | 884 | return d_ptr->orientation(); |
|
885 | 885 | } |
|
886 | 886 | |
|
887 | 887 | Qt::Alignment QAbstractAxis::alignment() const |
|
888 | 888 | { |
|
889 | 889 | return d_ptr->alignment(); |
|
890 | 890 | } |
|
891 | 891 | |
|
892 | 892 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
893 | 893 | |
|
894 | 894 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q) |
|
895 | 895 | : q_ptr(q), |
|
896 | 896 | m_chart(0), |
|
897 | 897 | m_alignment(0), |
|
898 | 898 | m_orientation(Qt::Orientation(0)), |
|
899 | 899 | m_visible(true), |
|
900 | 900 | m_arrowVisible(true), |
|
901 | 901 | m_axisPen(QChartPrivate::defaultPen()), |
|
902 | 902 | m_axisBrush(QChartPrivate::defaultBrush()), |
|
903 | 903 | m_gridLineVisible(true), |
|
904 | 904 | m_gridLinePen(QChartPrivate::defaultPen()), |
|
905 | 905 | m_labelsVisible(true), |
|
906 | 906 | m_labelsPen(QChartPrivate::defaultPen()), |
|
907 | 907 | m_labelsBrush(QChartPrivate::defaultBrush()), |
|
908 | 908 | m_labelsFont(QChartPrivate::defaultFont()), |
|
909 | 909 | m_labelsAngle(0), |
|
910 | 910 | m_titleVisible(true), |
|
911 | 911 | m_titlePen(QChartPrivate::defaultPen()), |
|
912 | 912 | m_titleBrush(QChartPrivate::defaultBrush()), |
|
913 | 913 | m_titleFont(QChartPrivate::defaultFont()), |
|
914 | 914 | m_shadesVisible(false), |
|
915 | 915 | m_shadesPen(QChartPrivate::defaultPen()), |
|
916 | 916 | m_shadesBrush(QChartPrivate::defaultBrush()), |
|
917 | 917 | m_shadesOpacity(1.0), |
|
918 | 918 | m_dirty(false) |
|
919 | 919 | { |
|
920 | 920 | } |
|
921 | 921 | |
|
922 | 922 | QAbstractAxisPrivate::~QAbstractAxisPrivate() |
|
923 | 923 | { |
|
924 | 924 | } |
|
925 | 925 | |
|
926 | 926 | void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment) |
|
927 | 927 | { |
|
928 | 928 | switch(alignment) { |
|
929 | 929 | case Qt::AlignTop: |
|
930 | 930 | case Qt::AlignBottom: |
|
931 | 931 | m_orientation = Qt::Horizontal; |
|
932 | 932 | break; |
|
933 | 933 | case Qt::AlignLeft: |
|
934 | 934 | case Qt::AlignRight: |
|
935 | 935 | m_orientation = Qt::Vertical; |
|
936 | 936 | break; |
|
937 | 937 | default: |
|
938 | 938 | qWarning()<<"No alignment specified !"; |
|
939 | 939 | break; |
|
940 | 940 | }; |
|
941 | 941 | m_alignment=alignment; |
|
942 | 942 | } |
|
943 | 943 | |
|
944 | 944 | void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced) |
|
945 | 945 | { |
|
946 | 946 | if (forced || QChartPrivate::defaultPen() == m_axisPen) |
|
947 | 947 | q_ptr->setLinePen(theme->axisLinePen()); |
|
948 | 948 | |
|
949 | 949 | if (forced || QChartPrivate::defaultPen() == m_gridLinePen) |
|
950 | 950 | q_ptr->setGridLinePen(theme->girdLinePen()); |
|
951 | 951 | |
|
952 | 952 | if (forced || QChartPrivate::defaultBrush() == m_labelsBrush) |
|
953 | 953 | q_ptr->setLabelsBrush(theme->labelBrush()); |
|
954 | 954 | if (forced || QChartPrivate::defaultPen() == m_labelsPen) |
|
955 | 955 | q_ptr->setLabelsPen(Qt::NoPen); // NoPen for performance reasons |
|
956 | 956 | if (forced || QChartPrivate::defaultFont() == m_labelsFont) |
|
957 | 957 | q_ptr->setLabelsFont(theme->labelFont()); |
|
958 | 958 | |
|
959 | 959 | if (forced || QChartPrivate::defaultBrush() == m_titleBrush) |
|
960 | 960 | q_ptr->setTitleBrush(theme->labelBrush()); |
|
961 | 961 | if (forced || QChartPrivate::defaultPen() == m_titlePen) |
|
962 | 962 | q_ptr->setTitlePen(Qt::NoPen); // NoPen for performance reasons |
|
963 | 963 | if (forced || QChartPrivate::defaultFont() == m_titleFont) { |
|
964 | 964 | QFont font(m_labelsFont); |
|
965 | 965 | font.setBold(true); |
|
966 | 966 | q_ptr->setTitleFont(font); |
|
967 | 967 | } |
|
968 | 968 | |
|
969 | 969 | if (forced || QChartPrivate::defaultBrush() == m_shadesBrush) |
|
970 | 970 | q_ptr->setShadesBrush(theme->backgroundShadesBrush()); |
|
971 | 971 | if (forced || QChartPrivate::defaultPen() == m_shadesPen) |
|
972 | 972 | q_ptr->setShadesPen(theme->backgroundShadesPen()); |
|
973 | 973 | |
|
974 | 974 | bool axisX = m_orientation == Qt::Horizontal; |
|
975 | 975 | if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth |
|
976 | 976 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX) |
|
977 | 977 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) { |
|
978 | 978 | q_ptr->setShadesVisible(true); |
|
979 | 979 | } else if (forced) { |
|
980 | 980 | q_ptr->setShadesVisible(false); |
|
981 | 981 | } |
|
982 | 982 | } |
|
983 | 983 | |
|
984 | 984 | void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max) |
|
985 | 985 | { |
|
986 | 986 | setRange(min,max); |
|
987 | 987 | } |
|
988 | 988 | |
|
989 | 989 | void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
990 | 990 | { |
|
991 | 991 | Q_UNUSED(parent); |
|
992 | 992 | } |
|
993 | 993 | |
|
994 | 994 | void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
995 | 995 | { |
|
996 | 996 | ChartAxisElement *axis = m_item.data(); |
|
997 | 997 | Q_ASSERT(axis); |
|
998 | 998 | if (axis->animation()) |
|
999 | 999 | axis->animation()->stopAndDestroyLater(); |
|
1000 | 1000 | |
|
1001 | 1001 | if (options.testFlag(QChart::GridAxisAnimations)) |
|
1002 | 1002 | axis->setAnimation(new AxisAnimation(axis)); |
|
1003 | 1003 | else |
|
1004 | 1004 | axis->setAnimation(0); |
|
1005 | 1005 | } |
|
1006 | 1006 | |
|
1007 | 1007 | |
|
1008 | 1008 | |
|
1009 | 1009 | #include "moc_qabstractaxis.cpp" |
|
1010 | 1010 | #include "moc_qabstractaxis_p.cpp" |
|
1011 | 1011 | |
|
1012 | 1012 | QT_CHARTS_END_NAMESPACE |
@@ -1,193 +1,193 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 <QtCharts/QChartGlobal> |
|
25 | 25 | #include <QtGui/QPen> |
|
26 | 26 | #include <QtGui/QFont> |
|
27 | 27 | #include <QtCore/QVariant> |
|
28 | 28 | |
|
29 | 29 | QT_CHARTS_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class QAbstractAxisPrivate; |
|
32 | 32 | |
|
33 | 33 | class QT_CHARTS_EXPORT QAbstractAxis : public QObject |
|
34 | 34 | { |
|
35 | 35 | Q_OBJECT |
|
36 | 36 | //visibility |
|
37 | 37 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) |
|
38 | 38 | //arrow |
|
39 | 39 | Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged) |
|
40 | 40 | Q_PROPERTY(QPen linePen READ linePen WRITE setLinePen NOTIFY linePenChanged) |
|
41 | 41 | Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged) |
|
42 | 42 | //labels |
|
43 | 43 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
44 | 44 | Q_PROPERTY(QPen labelsPen READ labelsPen WRITE setLabelsPen NOTIFY labelsPenChanged) |
|
45 | 45 | Q_PROPERTY(QBrush labelsBrush READ labelsBrush WRITE setLabelsBrush NOTIFY labelsBrushChanged) |
|
46 | 46 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle NOTIFY labelsAngleChanged) |
|
47 | 47 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont NOTIFY labelsFontChanged) |
|
48 | 48 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) |
|
49 | 49 | //grid |
|
50 | 50 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) |
|
51 | 51 | Q_PROPERTY(QPen gridLinePen READ gridLinePen WRITE setGridLinePen NOTIFY gridLinePenChanged) |
|
52 | 52 | //shades |
|
53 | 53 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) |
|
54 | 54 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) |
|
55 | 55 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) |
|
56 | 56 | Q_PROPERTY(QPen shadesPen READ shadesPen WRITE setShadesPen NOTIFY shadesPenChanged) |
|
57 | 57 | Q_PROPERTY(QBrush shadesBrush READ shadesBrush WRITE setShadesBrush NOTIFY shadesBrushChanged) |
|
58 | 58 | //title |
|
59 | 59 | Q_PROPERTY(QString titleText READ titleText WRITE setTitleText NOTIFY titleTextChanged) |
|
60 | 60 | Q_PROPERTY(QPen titlePen READ titlePen WRITE setTitlePen NOTIFY titlePenChanged) |
|
61 | 61 | Q_PROPERTY(QBrush titleBrush READ titleBrush WRITE setTitleBrush NOTIFY titleBrushChanged) |
|
62 | 62 | Q_PROPERTY(bool titleVisible READ isTitleVisible WRITE setTitleVisible NOTIFY titleVisibleChanged) |
|
63 | 63 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont NOTIFY titleFontChanged) |
|
64 | 64 | //orientation |
|
65 | 65 | Q_PROPERTY(Qt::Orientation orientation READ orientation) |
|
66 | 66 | //aligment |
|
67 | 67 | Q_PROPERTY(Qt::Alignment alignment READ alignment) |
|
68 | 68 | |
|
69 | 69 | public: |
|
70 | 70 | |
|
71 | 71 | enum AxisType { |
|
72 | 72 | AxisTypeNoAxis = 0x0, |
|
73 | 73 | AxisTypeValue = 0x1, |
|
74 | 74 | AxisTypeBarCategory = 0x2, |
|
75 |
AxisTypeCategory = 0x |
|
|
76 |
AxisTypeDateTime = 0x |
|
|
77 |
AxisTypeLogValue = 0x |
|
|
75 | AxisTypeCategory = 0x4, | |
|
76 | AxisTypeDateTime = 0x8, | |
|
77 | AxisTypeLogValue = 0x10 | |
|
78 | 78 | }; |
|
79 | 79 | |
|
80 | 80 | Q_DECLARE_FLAGS(AxisTypes, AxisType) |
|
81 | 81 | |
|
82 | 82 | protected: |
|
83 | 83 | explicit QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent = 0); |
|
84 | 84 | |
|
85 | 85 | public: |
|
86 | 86 | ~QAbstractAxis(); |
|
87 | 87 | |
|
88 | 88 | virtual AxisType type() const = 0; |
|
89 | 89 | |
|
90 | 90 | //visibility handling |
|
91 | 91 | bool isVisible() const; |
|
92 | 92 | void setVisible(bool visible = true); |
|
93 | 93 | void show(); |
|
94 | 94 | void hide(); |
|
95 | 95 | |
|
96 | 96 | //arrow handling |
|
97 | 97 | bool isLineVisible() const; |
|
98 | 98 | void setLineVisible(bool visible = true); |
|
99 | 99 | void setLinePen(const QPen &pen); |
|
100 | 100 | QPen linePen() const; |
|
101 | 101 | void setLinePenColor(QColor color); |
|
102 | 102 | QColor linePenColor() const; |
|
103 | 103 | |
|
104 | 104 | //grid handling |
|
105 | 105 | bool isGridLineVisible() const; |
|
106 | 106 | void setGridLineVisible(bool visible = true); |
|
107 | 107 | void setGridLinePen(const QPen &pen); |
|
108 | 108 | QPen gridLinePen() const; |
|
109 | 109 | |
|
110 | 110 | //labels handling |
|
111 | 111 | bool labelsVisible() const; |
|
112 | 112 | void setLabelsVisible(bool visible = true); |
|
113 | 113 | void setLabelsPen(const QPen &pen); |
|
114 | 114 | QPen labelsPen() const; |
|
115 | 115 | void setLabelsBrush(const QBrush &brush); |
|
116 | 116 | QBrush labelsBrush() const; |
|
117 | 117 | void setLabelsFont(const QFont &font); |
|
118 | 118 | QFont labelsFont() const; |
|
119 | 119 | void setLabelsAngle(int angle); |
|
120 | 120 | int labelsAngle() const; |
|
121 | 121 | void setLabelsColor(QColor color); |
|
122 | 122 | QColor labelsColor() const; |
|
123 | 123 | |
|
124 | 124 | //title handling |
|
125 | 125 | bool isTitleVisible() const; |
|
126 | 126 | void setTitleVisible(bool visible = true); |
|
127 | 127 | void setTitlePen(const QPen &pen); |
|
128 | 128 | QPen titlePen() const; |
|
129 | 129 | void setTitleBrush(const QBrush &brush); |
|
130 | 130 | QBrush titleBrush() const; |
|
131 | 131 | void setTitleFont(const QFont &font); |
|
132 | 132 | QFont titleFont() const; |
|
133 | 133 | void setTitleText(const QString &title); |
|
134 | 134 | QString titleText() const; |
|
135 | 135 | |
|
136 | 136 | //shades handling |
|
137 | 137 | bool shadesVisible() const; |
|
138 | 138 | void setShadesVisible(bool visible = true); |
|
139 | 139 | void setShadesPen(const QPen &pen); |
|
140 | 140 | QPen shadesPen() const; |
|
141 | 141 | void setShadesBrush(const QBrush &brush); |
|
142 | 142 | QBrush shadesBrush() const; |
|
143 | 143 | void setShadesColor(QColor color); |
|
144 | 144 | QColor shadesColor() const; |
|
145 | 145 | void setShadesBorderColor(QColor color); |
|
146 | 146 | QColor shadesBorderColor() const; |
|
147 | 147 | |
|
148 | 148 | Qt::Orientation orientation(); |
|
149 | 149 | Qt::Alignment alignment() const; |
|
150 | 150 | |
|
151 | 151 | //range handling |
|
152 | 152 | void setMin(const QVariant &min); |
|
153 | 153 | void setMax(const QVariant &max); |
|
154 | 154 | void setRange(const QVariant &min, const QVariant &max); |
|
155 | 155 | |
|
156 | 156 | Q_SIGNALS: |
|
157 | 157 | void visibleChanged(bool visible); |
|
158 | 158 | void linePenChanged(const QPen &pen); |
|
159 | 159 | void lineVisibleChanged(bool visible); |
|
160 | 160 | void labelsVisibleChanged(bool visible); |
|
161 | 161 | void labelsPenChanged(const QPen &pen); |
|
162 | 162 | void labelsBrushChanged(const QBrush &brush); |
|
163 | 163 | void labelsFontChanged(const QFont &pen); |
|
164 | 164 | void labelsAngleChanged(int angle); |
|
165 | 165 | void gridLinePenChanged(const QPen &pen); |
|
166 | 166 | void gridVisibleChanged(bool visible); |
|
167 | 167 | void colorChanged(QColor color); |
|
168 | 168 | void labelsColorChanged(QColor color); |
|
169 | 169 | void titleTextChanged(const QString &title); |
|
170 | 170 | void titlePenChanged(const QPen &pen); |
|
171 | 171 | void titleBrushChanged(const QBrush &brush); |
|
172 | 172 | void titleVisibleChanged(bool visible); |
|
173 | 173 | void titleFontChanged(const QFont &font); |
|
174 | 174 | void shadesVisibleChanged(bool visible); |
|
175 | 175 | void shadesColorChanged(QColor color); |
|
176 | 176 | void shadesBorderColorChanged(QColor color); |
|
177 | 177 | void shadesPenChanged(const QPen &pen); |
|
178 | 178 | void shadesBrushChanged(const QBrush &brush); |
|
179 | 179 | |
|
180 | 180 | protected: |
|
181 | 181 | QScopedPointer<QAbstractAxisPrivate> d_ptr; |
|
182 | 182 | Q_DISABLE_COPY(QAbstractAxis) |
|
183 | 183 | friend class ChartDataSet; |
|
184 | 184 | friend class ChartPresenter; |
|
185 | 185 | friend class ChartThemeManager; |
|
186 | 186 | friend class AbstractDomain; |
|
187 | 187 | friend class ChartAxisElement; |
|
188 | 188 | friend class XYChart; |
|
189 | 189 | }; |
|
190 | 190 | |
|
191 | 191 | QT_CHARTS_END_NAMESPACE |
|
192 | 192 | |
|
193 | 193 | #endif // QABSTRACTAXIS_H |
@@ -1,639 +1,624 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 <private/chartdataset_p.h> |
|
22 | 22 | #include <private/chartpresenter_p.h> |
|
23 | 23 | #include <QtCharts/QChart> |
|
24 | 24 | #include <private/qchart_p.h> |
|
25 | 25 | #include <QtCharts/QValueAxis> |
|
26 | 26 | #include <QtCharts/QBarCategoryAxis> |
|
27 | 27 | #include <private/qvalueaxis_p.h> |
|
28 | 28 | #include <QtCharts/QCategoryAxis> |
|
29 | 29 | #include <private/qabstractseries_p.h> |
|
30 | 30 | #include <QtCharts/QAbstractBarSeries> |
|
31 | 31 | #include <QtCharts/QStackedBarSeries> |
|
32 | 32 | #include <QtCharts/QPercentBarSeries> |
|
33 | 33 | #include <QtCharts/QPieSeries> |
|
34 | 34 | #include <private/chartitem_p.h> |
|
35 | 35 | #include <private/xydomain_p.h> |
|
36 | 36 | #include <private/xypolardomain_p.h> |
|
37 | 37 | #include <private/xlogydomain_p.h> |
|
38 | 38 | #include <private/logxydomain_p.h> |
|
39 | 39 | #include <private/logxlogydomain_p.h> |
|
40 | 40 | #include <private/xlogypolardomain_p.h> |
|
41 | 41 | #include <private/logxypolardomain_p.h> |
|
42 | 42 | #include <private/logxlogypolardomain_p.h> |
|
43 | 43 | |
|
44 | 44 | #ifndef QT_ON_ARM |
|
45 | 45 | #include <QtCharts/QDateTimeAxis> |
|
46 | 46 | #endif |
|
47 | 47 | |
|
48 | 48 | QT_CHARTS_BEGIN_NAMESPACE |
|
49 | 49 | |
|
50 | 50 | ChartDataSet::ChartDataSet(QChart *chart) |
|
51 | 51 | : QObject(chart), |
|
52 | 52 | m_chart(chart) |
|
53 | 53 | { |
|
54 | 54 | |
|
55 | 55 | } |
|
56 | 56 | |
|
57 | 57 | ChartDataSet::~ChartDataSet() |
|
58 | 58 | { |
|
59 | 59 | deleteAllSeries(); |
|
60 | 60 | deleteAllAxes(); |
|
61 | 61 | } |
|
62 | 62 | |
|
63 | 63 | /* |
|
64 | 64 | * This method adds series to chartdataset, series ownership is taken from caller. |
|
65 | 65 | */ |
|
66 | 66 | void ChartDataSet::addSeries(QAbstractSeries *series) |
|
67 | 67 | { |
|
68 | 68 | if (m_seriesList.contains(series)) { |
|
69 | 69 | qWarning() << QObject::tr("Can not add series. Series already on the chart."); |
|
70 | 70 | return; |
|
71 | 71 | } |
|
72 | 72 | |
|
73 | 73 | // Ignore unsupported series added to polar chart |
|
74 | 74 | if (m_chart && m_chart->chartType() == QChart::ChartTypePolar) { |
|
75 | 75 | if (!(series->type() == QAbstractSeries::SeriesTypeArea |
|
76 | 76 | || series->type() == QAbstractSeries::SeriesTypeLine |
|
77 | 77 | || series->type() == QAbstractSeries::SeriesTypeScatter |
|
78 | 78 | || series->type() == QAbstractSeries::SeriesTypeSpline)) { |
|
79 | 79 | qWarning() << QObject::tr("Can not add series. Series type is not supported by a polar chart."); |
|
80 | 80 | return; |
|
81 | 81 | } |
|
82 | 82 | series->d_ptr->setDomain(new XYPolarDomain()); |
|
83 | 83 | } else { |
|
84 | 84 | series->d_ptr->setDomain(new XYDomain()); |
|
85 | 85 | } |
|
86 | 86 | |
|
87 | 87 | series->d_ptr->initializeDomain(); |
|
88 | 88 | m_seriesList.append(series); |
|
89 | 89 | |
|
90 | 90 | series->setParent(this); // take ownership |
|
91 | 91 | series->d_ptr->m_chart = m_chart; |
|
92 | 92 | |
|
93 | 93 | emit seriesAdded(series); |
|
94 | 94 | } |
|
95 | 95 | |
|
96 | 96 | /* |
|
97 | 97 | * This method adds axis to chartdataset, axis ownership is taken from caller. |
|
98 | 98 | */ |
|
99 | 99 | void ChartDataSet::addAxis(QAbstractAxis *axis, Qt::Alignment aligment) |
|
100 | 100 | { |
|
101 | 101 | if (m_axisList.contains(axis)) { |
|
102 | 102 | qWarning() << QObject::tr("Can not add axis. Axis already on the chart."); |
|
103 | 103 | return; |
|
104 | 104 | } |
|
105 | 105 | |
|
106 | 106 | axis->d_ptr->setAlignment(aligment); |
|
107 | 107 | |
|
108 | 108 | if (!axis->alignment()) { |
|
109 | 109 | qWarning() << QObject::tr("No alignment specified !"); |
|
110 | 110 | return; |
|
111 | 111 | }; |
|
112 | 112 | |
|
113 | 113 | AbstractDomain *newDomain; |
|
114 | 114 | if (m_chart && m_chart->chartType() == QChart::ChartTypePolar) |
|
115 | 115 | newDomain = new XYPolarDomain(); |
|
116 | 116 | else |
|
117 | 117 | newDomain = new XYDomain(); |
|
118 | 118 | |
|
119 | 119 | QSharedPointer<AbstractDomain> domain(newDomain); |
|
120 | 120 | axis->d_ptr->initializeDomain(domain.data()); |
|
121 | 121 | |
|
122 | 122 | axis->setParent(this); |
|
123 | 123 | axis->d_ptr->m_chart = m_chart; |
|
124 | 124 | m_axisList.append(axis); |
|
125 | 125 | |
|
126 | 126 | emit axisAdded(axis); |
|
127 | 127 | } |
|
128 | 128 | |
|
129 | 129 | /* |
|
130 | 130 | * This method removes series form chartdataset, series ownership is passed back to caller. |
|
131 | 131 | */ |
|
132 | 132 | void ChartDataSet::removeSeries(QAbstractSeries *series) |
|
133 | 133 | { |
|
134 | 134 | |
|
135 | 135 | if (! m_seriesList.contains(series)) { |
|
136 | 136 | qWarning() << QObject::tr("Can not remove series. Series not found on the chart."); |
|
137 | 137 | return; |
|
138 | 138 | } |
|
139 | 139 | |
|
140 | 140 | QList<QAbstractAxis*> axes = series->d_ptr->m_axes; |
|
141 | 141 | |
|
142 | 142 | foreach(QAbstractAxis* axis, axes) { |
|
143 | 143 | detachAxis(series,axis); |
|
144 | 144 | } |
|
145 | 145 | |
|
146 | 146 | emit seriesRemoved(series); |
|
147 | 147 | m_seriesList.removeAll(series); |
|
148 | 148 | |
|
149 | 149 | // Reset domain to default |
|
150 | 150 | series->d_ptr->setDomain(new XYDomain()); |
|
151 | 151 | series->setParent(0); |
|
152 | 152 | series->d_ptr->m_chart = 0; |
|
153 | 153 | } |
|
154 | 154 | |
|
155 | 155 | /* |
|
156 | 156 | * This method removes axis form chartdataset, series ownership is passed back to caller. |
|
157 | 157 | */ |
|
158 | 158 | void ChartDataSet::removeAxis(QAbstractAxis *axis) |
|
159 | 159 | { |
|
160 | 160 | if (! m_axisList.contains(axis)) { |
|
161 | 161 | qWarning() << QObject::tr("Can not remove axis. Axis not found on the chart."); |
|
162 | 162 | return; |
|
163 | 163 | } |
|
164 | 164 | |
|
165 | 165 | QList<QAbstractSeries*> series = axis->d_ptr->m_series; |
|
166 | 166 | |
|
167 | 167 | foreach(QAbstractSeries* s, series) { |
|
168 | 168 | detachAxis(s,axis); |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | emit axisRemoved(axis); |
|
172 | 172 | m_axisList.removeAll(axis); |
|
173 | 173 | |
|
174 | 174 | axis->setParent(0); |
|
175 | 175 | axis->d_ptr->m_chart = 0; |
|
176 | 176 | } |
|
177 | 177 | |
|
178 | 178 | /* |
|
179 | 179 | * This method attaches axis to series, return true if success. |
|
180 | 180 | */ |
|
181 | 181 | bool ChartDataSet::attachAxis(QAbstractSeries *series,QAbstractAxis *axis) |
|
182 | 182 | { |
|
183 | 183 | Q_ASSERT(axis); |
|
184 | 184 | |
|
185 | 185 | if (!series) |
|
186 | 186 | return false; |
|
187 | 187 | |
|
188 | 188 | QList<QAbstractSeries *> attachedSeriesList = axis->d_ptr->m_series; |
|
189 | 189 | QList<QAbstractAxis *> attachedAxisList = series->d_ptr->m_axes; |
|
190 | 190 | |
|
191 | 191 | if (!m_seriesList.contains(series)) { |
|
192 | 192 | qWarning() << QObject::tr("Can not find series on the chart."); |
|
193 | 193 | return false; |
|
194 | 194 | } |
|
195 | 195 | |
|
196 | 196 | if (axis && !m_axisList.contains(axis)) { |
|
197 | 197 | qWarning() << QObject::tr("Can not find axis on the chart."); |
|
198 | 198 | return false; |
|
199 | 199 | } |
|
200 | 200 | |
|
201 | 201 | if (attachedAxisList.contains(axis)) { |
|
202 | 202 | qWarning() << QObject::tr("Axis already attached to series."); |
|
203 | 203 | return false; |
|
204 | 204 | } |
|
205 | 205 | |
|
206 | 206 | if (attachedSeriesList.contains(series)) { |
|
207 | 207 | qWarning() << QObject::tr("Axis already attached to series."); |
|
208 | 208 | return false; |
|
209 | 209 | } |
|
210 | 210 | |
|
211 | 211 | AbstractDomain *domain = series->d_ptr->domain(); |
|
212 | 212 | AbstractDomain::DomainType type = selectDomain(attachedAxisList<<axis); |
|
213 | 213 | |
|
214 | 214 | if (type == AbstractDomain::UndefinedDomain) return false; |
|
215 | 215 | |
|
216 | 216 | if (domain->type() != type) { |
|
217 | 217 | AbstractDomain *old = domain; |
|
218 | 218 | domain = createDomain(type); |
|
219 | 219 | domain->setRange(old->minX(), old->maxX(), old->minY(), old->maxY()); |
|
220 | 220 | // Initialize domain size to old domain size, as it won't get updated |
|
221 | 221 | // unless geometry changes. |
|
222 | 222 | domain->setSize(old->size()); |
|
223 | 223 | } |
|
224 | 224 | |
|
225 | 225 | if (!domain) |
|
226 | 226 | return false; |
|
227 | 227 | |
|
228 | 228 | if (!domain->attachAxis(axis)) |
|
229 | 229 | return false; |
|
230 | 230 | |
|
231 | 231 | QList<AbstractDomain *> blockedDomains; |
|
232 | 232 | domain->blockRangeSignals(true); |
|
233 | 233 | blockedDomains << domain; |
|
234 | 234 | |
|
235 | 235 | if (domain != series->d_ptr->domain()) { |
|
236 | 236 | foreach (QAbstractAxis *axis, series->d_ptr->m_axes) { |
|
237 | 237 | series->d_ptr->domain()->detachAxis(axis); |
|
238 | 238 | domain->attachAxis(axis); |
|
239 | 239 | foreach (QAbstractSeries *otherSeries, axis->d_ptr->m_series) { |
|
240 | 240 | if (otherSeries != series && otherSeries->d_ptr->domain()) { |
|
241 | 241 | if (!otherSeries->d_ptr->domain()->rangeSignalsBlocked()) { |
|
242 | 242 | otherSeries->d_ptr->domain()->blockRangeSignals(true); |
|
243 | 243 | blockedDomains << otherSeries->d_ptr->domain(); |
|
244 | 244 | } |
|
245 | 245 | } |
|
246 | 246 | } |
|
247 | 247 | } |
|
248 | 248 | series->d_ptr->setDomain(domain); |
|
249 | 249 | series->d_ptr->initializeDomain(); |
|
250 | 250 | } |
|
251 | 251 | |
|
252 | 252 | series->d_ptr->m_axes<<axis; |
|
253 | 253 | axis->d_ptr->m_series<<series; |
|
254 | 254 | |
|
255 | 255 | series->d_ptr->initializeAxes(); |
|
256 | 256 | axis->d_ptr->initializeDomain(domain); |
|
257 | 257 | |
|
258 | 258 | foreach (AbstractDomain *blockedDomain, blockedDomains) |
|
259 | 259 | blockedDomain->blockRangeSignals(false); |
|
260 | 260 | |
|
261 | 261 | return true; |
|
262 | 262 | } |
|
263 | 263 | |
|
264 | 264 | /* |
|
265 | 265 | * This method detaches axis to series, return true if success. |
|
266 | 266 | */ |
|
267 | 267 | bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis) |
|
268 | 268 | { |
|
269 | 269 | Q_ASSERT(series); |
|
270 | 270 | Q_ASSERT(axis); |
|
271 | 271 | |
|
272 | 272 | QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series; |
|
273 | 273 | QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes; |
|
274 | 274 | AbstractDomain* domain = series->d_ptr->domain(); |
|
275 | 275 | |
|
276 | 276 | if (!m_seriesList.contains(series)) { |
|
277 | 277 | qWarning() << QObject::tr("Can not find series on the chart."); |
|
278 | 278 | return false; |
|
279 | 279 | } |
|
280 | 280 | |
|
281 | 281 | if (axis && !m_axisList.contains(axis)) { |
|
282 | 282 | qWarning() << QObject::tr("Can not find axis on the chart."); |
|
283 | 283 | return false; |
|
284 | 284 | } |
|
285 | 285 | |
|
286 | 286 | if (!attachedAxisList.contains(axis)) { |
|
287 | 287 | qWarning() << QObject::tr("Axis not attached to series."); |
|
288 | 288 | return false; |
|
289 | 289 | } |
|
290 | 290 | |
|
291 | 291 | Q_ASSERT(axis->d_ptr->m_series.contains(series)); |
|
292 | 292 | |
|
293 | 293 | domain->detachAxis(axis); |
|
294 | 294 | series->d_ptr->m_axes.removeAll(axis); |
|
295 | 295 | axis->d_ptr->m_series.removeAll(series); |
|
296 | 296 | |
|
297 | 297 | return true; |
|
298 | 298 | } |
|
299 | 299 | |
|
300 | 300 | void ChartDataSet::createDefaultAxes() |
|
301 | 301 | { |
|
302 | 302 | if (m_seriesList.isEmpty()) |
|
303 | 303 | return; |
|
304 | 304 | |
|
305 | 305 | QAbstractAxis::AxisTypes typeX(0); |
|
306 | 306 | QAbstractAxis::AxisTypes typeY(0); |
|
307 | 307 | |
|
308 | 308 | // Remove possibly existing axes |
|
309 | 309 | deleteAllAxes(); |
|
310 | 310 | |
|
311 | 311 | Q_ASSERT(m_axisList.isEmpty()); |
|
312 | 312 | |
|
313 | 313 | // Select the required axis x and axis y types based on the types of the current series |
|
314 | 314 | foreach(QAbstractSeries* s, m_seriesList) { |
|
315 | 315 | typeX |= s->d_ptr->defaultAxisType(Qt::Horizontal); |
|
316 | 316 | typeY |= s->d_ptr->defaultAxisType(Qt::Vertical); |
|
317 | 317 | } |
|
318 | 318 | |
|
319 | // Create the axes of the types selected | |
|
320 | // As long as AxisType enum balues are sequential a check to see if there are series of | |
|
321 | // different types is needed. In such cases AxisTypeNoAxis is used to create separate axes | |
|
322 | // for the types. | |
|
323 | if (typeX != QAbstractAxis::AxisTypeNoAxis) { | |
|
324 | if (typeX != m_seriesList.first()->d_ptr->defaultAxisType(Qt::Horizontal)) | |
|
325 | typeX = QAbstractAxis::AxisTypeNoAxis; | |
|
326 | createAxes(typeX, Qt::Horizontal); | |
|
327 | } | |
|
328 | ||
|
329 | if (typeY != QAbstractAxis::AxisTypeNoAxis) { | |
|
330 | if (typeY != m_seriesList.first()->d_ptr->defaultAxisType(Qt::Vertical)) | |
|
331 | typeY = QAbstractAxis::AxisTypeNoAxis; | |
|
332 | createAxes(typeY, Qt::Vertical); | |
|
333 | } | |
|
334 | ||
|
319 | createAxes(typeX, Qt::Horizontal); | |
|
320 | createAxes(typeY, Qt::Vertical); | |
|
335 | 321 | } |
|
336 | 322 | |
|
337 | 323 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation) |
|
338 | 324 | { |
|
339 | 325 | QAbstractAxis *axis = 0; |
|
340 | 326 | //decide what axis should be created |
|
341 | 327 | |
|
342 | 328 | switch (type) { |
|
343 | 329 | case QAbstractAxis::AxisTypeValue: |
|
344 | 330 | axis = new QValueAxis(this); |
|
345 | 331 | break; |
|
346 | 332 | case QAbstractAxis::AxisTypeBarCategory: |
|
347 | 333 | axis = new QBarCategoryAxis(this); |
|
348 | 334 | break; |
|
349 | 335 | case QAbstractAxis::AxisTypeCategory: |
|
350 | 336 | axis = new QCategoryAxis(this); |
|
351 | 337 | break; |
|
352 | 338 | #ifndef Q_WS_QWS |
|
353 | 339 | case QAbstractAxis::AxisTypeDateTime: |
|
354 | 340 | axis = new QDateTimeAxis(this); |
|
355 | 341 | break; |
|
356 | 342 | #endif |
|
357 | 343 | default: |
|
358 | 344 | axis = 0; |
|
359 | 345 | break; |
|
360 | 346 | } |
|
361 | 347 | |
|
362 | 348 | if (axis) { |
|
363 | 349 | //create one axis for all |
|
364 | 350 | |
|
365 | 351 | addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft); |
|
366 | 352 | qreal min = 0; |
|
367 | 353 | qreal max = 0; |
|
368 | 354 | findMinMaxForSeries(m_seriesList,orientation,min,max); |
|
369 | 355 | foreach(QAbstractSeries *s, m_seriesList) { |
|
370 | 356 | attachAxis(s,axis); |
|
371 | 357 | } |
|
372 | 358 | axis->setRange(min,max); |
|
373 | } | |
|
374 | else if (type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { | |
|
375 | //create separate axis | |
|
359 | } else { | |
|
360 | // Create separate axis for each series | |
|
376 | 361 | foreach(QAbstractSeries *s, m_seriesList) { |
|
377 | 362 | QAbstractAxis *axis = s->d_ptr->createDefaultAxis(orientation); |
|
378 | 363 | if(axis) { |
|
379 | 364 | addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft); |
|
380 | 365 | attachAxis(s,axis); |
|
381 | 366 | } |
|
382 | 367 | } |
|
383 | 368 | } |
|
384 | 369 | } |
|
385 | 370 | |
|
386 | 371 | void ChartDataSet::findMinMaxForSeries(QList<QAbstractSeries *> series,Qt::Orientations orientation, qreal &min, qreal &max) |
|
387 | 372 | { |
|
388 | 373 | Q_ASSERT(!series.isEmpty()); |
|
389 | 374 | |
|
390 | 375 | AbstractDomain *domain = series.first()->d_ptr->domain(); |
|
391 | 376 | min = (orientation == Qt::Vertical) ? domain->minY() : domain->minX(); |
|
392 | 377 | max = (orientation == Qt::Vertical) ? domain->maxY() : domain->maxX(); |
|
393 | 378 | |
|
394 | 379 | for (int i = 1; i< series.size(); i++) { |
|
395 | 380 | AbstractDomain *domain = series[i]->d_ptr->domain(); |
|
396 | 381 | min = qMin((orientation == Qt::Vertical) ? domain->minY() : domain->minX(), min); |
|
397 | 382 | max = qMax((orientation == Qt::Vertical) ? domain->maxY() : domain->maxX(), max); |
|
398 | 383 | } |
|
399 | 384 | if (min == max) { |
|
400 | 385 | min -= 0.5; |
|
401 | 386 | max += 0.5; |
|
402 | 387 | } |
|
403 | 388 | } |
|
404 | 389 | |
|
405 | 390 | void ChartDataSet::deleteAllSeries() |
|
406 | 391 | { |
|
407 | 392 | foreach (QAbstractSeries *s , m_seriesList){ |
|
408 | 393 | removeSeries(s); |
|
409 | 394 | s->deleteLater(); |
|
410 | 395 | } |
|
411 | 396 | Q_ASSERT(m_seriesList.count() == 0); |
|
412 | 397 | } |
|
413 | 398 | |
|
414 | 399 | void ChartDataSet::deleteAllAxes() |
|
415 | 400 | { |
|
416 | 401 | foreach (QAbstractAxis *a , m_axisList){ |
|
417 | 402 | removeAxis(a); |
|
418 | 403 | a->deleteLater(); |
|
419 | 404 | } |
|
420 | 405 | Q_ASSERT(m_axisList.count() == 0); |
|
421 | 406 | } |
|
422 | 407 | |
|
423 | 408 | void ChartDataSet::zoomInDomain(const QRectF &rect) |
|
424 | 409 | { |
|
425 | 410 | QList<AbstractDomain*> domains; |
|
426 | 411 | foreach(QAbstractSeries *s, m_seriesList) { |
|
427 | 412 | AbstractDomain* domain = s->d_ptr->domain(); |
|
428 | 413 | s->d_ptr->m_domain->blockRangeSignals(true); |
|
429 | 414 | domains<<domain; |
|
430 | 415 | } |
|
431 | 416 | |
|
432 | 417 | foreach(AbstractDomain *domain, domains) |
|
433 | 418 | domain->zoomIn(rect); |
|
434 | 419 | |
|
435 | 420 | foreach(AbstractDomain *domain, domains) |
|
436 | 421 | domain->blockRangeSignals(false); |
|
437 | 422 | } |
|
438 | 423 | |
|
439 | 424 | void ChartDataSet::zoomOutDomain(const QRectF &rect) |
|
440 | 425 | { |
|
441 | 426 | QList<AbstractDomain*> domains; |
|
442 | 427 | foreach(QAbstractSeries *s, m_seriesList) { |
|
443 | 428 | AbstractDomain* domain = s->d_ptr->domain(); |
|
444 | 429 | s->d_ptr->m_domain->blockRangeSignals(true); |
|
445 | 430 | domains<<domain; |
|
446 | 431 | } |
|
447 | 432 | |
|
448 | 433 | foreach(AbstractDomain *domain, domains) |
|
449 | 434 | domain->zoomOut(rect); |
|
450 | 435 | |
|
451 | 436 | foreach(AbstractDomain *domain, domains) |
|
452 | 437 | domain->blockRangeSignals(false); |
|
453 | 438 | } |
|
454 | 439 | |
|
455 | 440 | void ChartDataSet::zoomResetDomain() |
|
456 | 441 | { |
|
457 | 442 | QList<AbstractDomain*> domains; |
|
458 | 443 | foreach (QAbstractSeries *s, m_seriesList) { |
|
459 | 444 | AbstractDomain *domain = s->d_ptr->domain(); |
|
460 | 445 | s->d_ptr->m_domain->blockRangeSignals(true); |
|
461 | 446 | domains << domain; |
|
462 | 447 | } |
|
463 | 448 | |
|
464 | 449 | foreach (AbstractDomain *domain, domains) |
|
465 | 450 | domain->zoomReset(); |
|
466 | 451 | |
|
467 | 452 | foreach (AbstractDomain *domain, domains) |
|
468 | 453 | domain->blockRangeSignals(false); |
|
469 | 454 | } |
|
470 | 455 | |
|
471 | 456 | bool ChartDataSet::isZoomedDomain() |
|
472 | 457 | { |
|
473 | 458 | foreach (QAbstractSeries *s, m_seriesList) { |
|
474 | 459 | if (s->d_ptr->domain()->isZoomed()) |
|
475 | 460 | return true; |
|
476 | 461 | } |
|
477 | 462 | return false; |
|
478 | 463 | } |
|
479 | 464 | |
|
480 | 465 | void ChartDataSet::scrollDomain(qreal dx, qreal dy) |
|
481 | 466 | { |
|
482 | 467 | QList<AbstractDomain*> domains; |
|
483 | 468 | foreach(QAbstractSeries *s, m_seriesList) { |
|
484 | 469 | AbstractDomain* domain = s->d_ptr->domain(); |
|
485 | 470 | s->d_ptr->m_domain->blockRangeSignals(true); |
|
486 | 471 | domains<<domain; |
|
487 | 472 | } |
|
488 | 473 | |
|
489 | 474 | foreach(AbstractDomain *domain, domains) |
|
490 | 475 | domain->move(dx, dy); |
|
491 | 476 | |
|
492 | 477 | foreach(AbstractDomain *domain, domains) |
|
493 | 478 | domain->blockRangeSignals(false); |
|
494 | 479 | } |
|
495 | 480 | |
|
496 | 481 | QPointF ChartDataSet::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
497 | 482 | { |
|
498 | 483 | QPointF point; |
|
499 | 484 | if (series == 0 && !m_seriesList.isEmpty()) |
|
500 | 485 | series = m_seriesList.first(); |
|
501 | 486 | |
|
502 | 487 | if (series && series->type() == QAbstractSeries::SeriesTypePie) |
|
503 | 488 | return point; |
|
504 | 489 | |
|
505 | 490 | if (series && m_seriesList.contains(series)) |
|
506 | 491 | point = series->d_ptr->m_domain->calculateDomainPoint(position - m_chart->plotArea().topLeft()); |
|
507 | 492 | return point; |
|
508 | 493 | } |
|
509 | 494 | |
|
510 | 495 | QPointF ChartDataSet::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
511 | 496 | { |
|
512 | 497 | QPointF point = m_chart->plotArea().topLeft(); |
|
513 | 498 | if (series == 0 && !m_seriesList.isEmpty()) |
|
514 | 499 | series = m_seriesList.first(); |
|
515 | 500 | |
|
516 | 501 | if (series && series->type() == QAbstractSeries::SeriesTypePie) |
|
517 | 502 | return QPoint(0, 0); |
|
518 | 503 | |
|
519 | 504 | bool ok; |
|
520 | 505 | if (series && m_seriesList.contains(series)) |
|
521 | 506 | point += series->d_ptr->m_domain->calculateGeometryPoint(value, ok); |
|
522 | 507 | return point; |
|
523 | 508 | } |
|
524 | 509 | |
|
525 | 510 | QList<QAbstractAxis *> ChartDataSet::axes() const |
|
526 | 511 | { |
|
527 | 512 | return m_axisList; |
|
528 | 513 | } |
|
529 | 514 | |
|
530 | 515 | QList<QAbstractSeries *> ChartDataSet::series() const |
|
531 | 516 | { |
|
532 | 517 | return m_seriesList; |
|
533 | 518 | } |
|
534 | 519 | |
|
535 | 520 | AbstractDomain::DomainType ChartDataSet::selectDomain(QList<QAbstractAxis *> axes) |
|
536 | 521 | { |
|
537 | 522 | enum Type { |
|
538 | 523 | Undefined = 0, |
|
539 | 524 | LogType = 0x1, |
|
540 | 525 | ValueType = 0x2 |
|
541 | 526 | }; |
|
542 | 527 | |
|
543 | 528 | int horizontal(Undefined); |
|
544 | 529 | int vertical(Undefined); |
|
545 | 530 | |
|
546 | 531 | // Assume cartesian chart type, unless chart is set |
|
547 | 532 | QChart::ChartType chartType(QChart::ChartTypeCartesian); |
|
548 | 533 | if (m_chart) |
|
549 | 534 | chartType = m_chart->chartType(); |
|
550 | 535 | |
|
551 | 536 | foreach (QAbstractAxis *axis, axes) |
|
552 | 537 | { |
|
553 | 538 | switch (axis->type()) { |
|
554 | 539 | case QAbstractAxis::AxisTypeLogValue: |
|
555 | 540 | if (axis->orientation() == Qt::Horizontal) |
|
556 | 541 | horizontal |= LogType; |
|
557 | 542 | if (axis->orientation() == Qt::Vertical) |
|
558 | 543 | vertical |= LogType; |
|
559 | 544 | break; |
|
560 | 545 | case QAbstractAxis::AxisTypeValue: |
|
561 | 546 | case QAbstractAxis::AxisTypeBarCategory: |
|
562 | 547 | case QAbstractAxis::AxisTypeCategory: |
|
563 | 548 | case QAbstractAxis::AxisTypeDateTime: |
|
564 | 549 | if (axis->orientation() == Qt::Horizontal) |
|
565 | 550 | horizontal |= ValueType; |
|
566 | 551 | if (axis->orientation() == Qt::Vertical) |
|
567 | 552 | vertical |= ValueType; |
|
568 | 553 | break; |
|
569 | 554 | default: |
|
570 | 555 | qWarning() << "Undefined type"; |
|
571 | 556 | break; |
|
572 | 557 | } |
|
573 | 558 | } |
|
574 | 559 | |
|
575 | 560 | if (vertical == Undefined) |
|
576 | 561 | vertical = ValueType; |
|
577 | 562 | if (horizontal == Undefined) |
|
578 | 563 | horizontal = ValueType; |
|
579 | 564 | |
|
580 | 565 | if (vertical == ValueType && horizontal == ValueType) { |
|
581 | 566 | if (chartType == QChart::ChartTypeCartesian) |
|
582 | 567 | return AbstractDomain::XYDomain; |
|
583 | 568 | else if (chartType == QChart::ChartTypePolar) |
|
584 | 569 | return AbstractDomain::XYPolarDomain; |
|
585 | 570 | } |
|
586 | 571 | |
|
587 | 572 | if (vertical == LogType && horizontal == ValueType) { |
|
588 | 573 | if (chartType == QChart::ChartTypeCartesian) |
|
589 | 574 | return AbstractDomain::XLogYDomain; |
|
590 | 575 | if (chartType == QChart::ChartTypePolar) |
|
591 | 576 | return AbstractDomain::XLogYPolarDomain; |
|
592 | 577 | } |
|
593 | 578 | |
|
594 | 579 | if (vertical == ValueType && horizontal == LogType) { |
|
595 | 580 | if (chartType == QChart::ChartTypeCartesian) |
|
596 | 581 | return AbstractDomain::LogXYDomain; |
|
597 | 582 | else if (chartType == QChart::ChartTypePolar) |
|
598 | 583 | return AbstractDomain::LogXYPolarDomain; |
|
599 | 584 | } |
|
600 | 585 | |
|
601 | 586 | if (vertical == LogType && horizontal == LogType) { |
|
602 | 587 | if (chartType == QChart::ChartTypeCartesian) |
|
603 | 588 | return AbstractDomain::LogXLogYDomain; |
|
604 | 589 | else if (chartType == QChart::ChartTypePolar) |
|
605 | 590 | return AbstractDomain::LogXLogYPolarDomain; |
|
606 | 591 | } |
|
607 | 592 | |
|
608 | 593 | return AbstractDomain::UndefinedDomain; |
|
609 | 594 | } |
|
610 | 595 | |
|
611 | 596 | //refactor create factory |
|
612 | 597 | AbstractDomain* ChartDataSet::createDomain(AbstractDomain::DomainType type) |
|
613 | 598 | { |
|
614 | 599 | switch (type) |
|
615 | 600 | { |
|
616 | 601 | case AbstractDomain::LogXLogYDomain: |
|
617 | 602 | return new LogXLogYDomain(); |
|
618 | 603 | case AbstractDomain::XYDomain: |
|
619 | 604 | return new XYDomain(); |
|
620 | 605 | case AbstractDomain::XLogYDomain: |
|
621 | 606 | return new XLogYDomain(); |
|
622 | 607 | case AbstractDomain::LogXYDomain: |
|
623 | 608 | return new LogXYDomain(); |
|
624 | 609 | case AbstractDomain::XYPolarDomain: |
|
625 | 610 | return new XYPolarDomain(); |
|
626 | 611 | case AbstractDomain::XLogYPolarDomain: |
|
627 | 612 | return new XLogYPolarDomain(); |
|
628 | 613 | case AbstractDomain::LogXYPolarDomain: |
|
629 | 614 | return new LogXYPolarDomain(); |
|
630 | 615 | case AbstractDomain::LogXLogYPolarDomain: |
|
631 | 616 | return new LogXLogYPolarDomain(); |
|
632 | 617 | default: |
|
633 | 618 | return 0; |
|
634 | 619 | } |
|
635 | 620 | } |
|
636 | 621 | |
|
637 | 622 | #include "moc_chartdataset_p.cpp" |
|
638 | 623 | |
|
639 | 624 | QT_CHARTS_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now