1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 or (at your option) any later version |
20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
22 | ** included in the packaging of this file. Please review the following |
23 | ** information to ensure the GNU General Public License requirements will |
24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
25 | ** |
26 | ** $QT_END_LICENSE$ |
27 | ** |
28 | ****************************************************************************/ |
29 | |
30 | #include <QtCharts/QAbstractAxis> |
31 | #include <private/qabstractaxis_p.h> |
32 | #include <private/chartdataset_p.h> |
33 | #include <private/charttheme_p.h> |
34 | #include <private/qchart_p.h> |
35 | |
36 | QT_CHARTS_BEGIN_NAMESPACE |
37 | |
38 | /*! |
39 | \class QAbstractAxis |
40 | \inmodule QtCharts |
41 | \brief The QAbstractAxis class is a base class used for specialized axis classes. |
42 | |
43 | Each series can be bound to one or more horizontal and vertical axes, but mixing axis types |
44 | that would result in different domains is not supported, such as specifying |
45 | QValueAxis and QLogValueAxis on the same orientation. |
46 | |
47 | The properties and visibility of various axis elements, such as axis line, title, labels, |
48 | grid lines, and shades, can be individually controlled. |
49 | */ |
50 | /*! |
51 | \qmltype AbstractAxis |
52 | \instantiates QAbstractAxis |
53 | \inqmlmodule QtCharts |
54 | |
55 | \brief A base type used for specialized axis types. |
56 | |
57 | Each series can be bound to only one horizontal and vertical axis. |
58 | |
59 | The properties and visibility of various axis elements, such as axis line, title, labels, |
60 | grid lines, and shades, can be individually controlled. |
61 | */ |
62 | |
63 | /*! |
64 | \enum QAbstractAxis::AxisType |
65 | |
66 | This enum type specifies the type of the axis object. |
67 | |
68 | \value AxisTypeNoAxis |
69 | \value AxisTypeValue |
70 | \value AxisTypeBarCategory |
71 | \value AxisTypeCategory |
72 | \value AxisTypeDateTime |
73 | \value AxisTypeLogValue |
74 | */ |
75 | |
76 | /*! |
77 | \fn void QAbstractAxis::type() const |
78 | Returns the type of the axis. |
79 | */ |
80 | |
81 | /*! |
82 | \property QAbstractAxis::lineVisible |
83 | \brief The visibility of the axis line. |
84 | */ |
85 | /*! |
86 | \qmlproperty bool AbstractAxis::lineVisible |
87 | The visibility of the axis line. |
88 | */ |
89 | |
90 | /*! |
91 | \property QAbstractAxis::linePen |
92 | \brief The pen used to draw the line. |
93 | */ |
94 | |
95 | /*! |
96 | \property QAbstractAxis::labelsVisible |
97 | \brief Whether axis labels are visible. |
98 | */ |
99 | /*! |
100 | \qmlproperty bool AbstractAxis::labelsVisible |
101 | The visibility of axis labels. |
102 | */ |
103 | |
104 | /*! |
105 | \property QAbstractAxis::labelsBrush |
106 | \brief The brush used to draw the labels. |
107 | |
108 | Only the color of the brush is relevant. |
109 | */ |
110 | |
111 | /*! |
112 | \property QAbstractAxis::visible |
113 | \brief The visibility of the axis. |
114 | */ |
115 | /*! |
116 | \qmlproperty bool AbstractAxis::visible |
117 | The visibility of the axis. |
118 | */ |
119 | |
120 | /*! |
121 | \property QAbstractAxis::gridVisible |
122 | \brief The visibility of the grid lines. |
123 | */ |
124 | /*! |
125 | \qmlproperty bool AbstractAxis::gridVisible |
126 | The visibility of the grid lines. |
127 | */ |
128 | |
129 | /*! |
130 | \property QAbstractAxis::minorGridVisible |
131 | \brief The visibility of the minor grid lines. |
132 | |
133 | Applies only to axes that support minor grid lines. |
134 | */ |
135 | /*! |
136 | \qmlproperty bool AbstractAxis::minorGridVisible |
137 | The visibility of the minor grid lines. Applies only to axes that support |
138 | minor grid lines. |
139 | */ |
140 | |
141 | /*! |
142 | \property QAbstractAxis::color |
143 | \brief The color of the axis and tick marks. |
144 | */ |
145 | /*! |
146 | \qmlproperty color AbstractAxis::color |
147 | The color of the axis and tick marks. |
148 | */ |
149 | |
150 | /*! |
151 | \property QAbstractAxis::gridLinePen |
152 | \brief The pen used to draw the grid line. |
153 | */ |
154 | |
155 | /*! |
156 | \property QAbstractAxis::minorGridLinePen |
157 | \brief The pen used to draw the minor grid line. |
158 | |
159 | Applies only to axes that support minor grid lines. |
160 | */ |
161 | |
162 | /*! |
163 | \property QAbstractAxis::gridLineColor |
164 | \brief The color of the grid line. |
165 | */ |
166 | |
167 | /*! |
168 | \qmlproperty color AbstractAxis::gridLineColor |
169 | The color of the grid line. |
170 | */ |
171 | |
172 | /*! |
173 | \property QAbstractAxis::minorGridLineColor |
174 | \brief The color of the minor grid line. |
175 | |
176 | Applies only to axes that support minor grid lines. |
177 | */ |
178 | |
179 | /*! |
180 | \qmlproperty color AbstractAxis::minorGridLineColor |
181 | The color of the minor grid line. |
182 | |
183 | Applies only to axes that support minor grid lines. |
184 | */ |
185 | |
186 | /*! |
187 | \property QAbstractAxis::labelsFont |
188 | \brief The font of the axis labels. |
189 | */ |
190 | |
191 | /*! |
192 | \qmlproperty font AbstractAxis::labelsFont |
193 | The font of the axis labels. |
194 | |
195 | For more information, see \l [QML]{font}. |
196 | */ |
197 | |
198 | /*! |
199 | \property QAbstractAxis::labelsColor |
200 | \brief The color of the axis labels. |
201 | */ |
202 | /*! |
203 | \qmlproperty color AbstractAxis::labelsColor |
204 | The color of the axis labels. |
205 | */ |
206 | |
207 | /*! |
208 | \property QAbstractAxis::labelsAngle |
209 | \brief The angle of the axis labels in degrees. |
210 | */ |
211 | /*! |
212 | \qmlproperty int AbstractAxis::labelsAngle |
213 | The angle of the axis labels in degrees. |
214 | */ |
215 | |
216 | /*! |
217 | \property QAbstractAxis::shadesVisible |
218 | \brief The visibility of the axis shades. |
219 | */ |
220 | /*! |
221 | \qmlproperty bool AbstractAxis::shadesVisible |
222 | The visibility of the axis shades. |
223 | */ |
224 | |
225 | /*! |
226 | \property QAbstractAxis::shadesColor |
227 | \brief The fill (brush) color of the axis shades. |
228 | */ |
229 | /*! |
230 | \qmlproperty color AbstractAxis::shadesColor |
231 | The fill (brush) color of the axis shades. |
232 | */ |
233 | |
234 | /*! |
235 | \property QAbstractAxis::shadesBorderColor |
236 | \brief The border (pen) color of the axis shades. |
237 | */ |
238 | /*! |
239 | \qmlproperty color AbstractAxis::shadesBorderColor |
240 | The border (pen) color of the axis shades. |
241 | */ |
242 | |
243 | /*! |
244 | \property QAbstractAxis::shadesPen |
245 | \brief The pen used to draw the axis shades (the area between the grid lines). |
246 | */ |
247 | |
248 | /*! |
249 | \property QAbstractAxis::shadesBrush |
250 | \brief The brush used to draw the axis shades (the area between the grid lines). |
251 | */ |
252 | |
253 | /*! |
254 | \property QAbstractAxis::titleVisible |
255 | \brief The visibility of the axis title. |
256 | |
257 | By default, the value is \c true. |
258 | */ |
259 | /*! |
260 | \qmlproperty bool AbstractAxis::titleVisible |
261 | The visibility of the axis title. By default, the value is \c true. |
262 | */ |
263 | |
264 | /*! |
265 | \property QAbstractAxis::titleText |
266 | \brief The title of the axis. |
267 | |
268 | Empty by default. Axis titles support HTML formatting. |
269 | */ |
270 | /*! |
271 | \qmlproperty string AbstractAxis::titleText |
272 | The title of the axis. Empty by default. Axis titles support HTML formatting. |
273 | */ |
274 | |
275 | /*! |
276 | \property QAbstractAxis::titleBrush |
277 | \brief The brush used to draw the title text. |
278 | |
279 | Only the color of the brush is relevant. |
280 | */ |
281 | |
282 | /*! |
283 | \property QAbstractAxis::titleFont |
284 | \brief The font of the title of the axis. |
285 | */ |
286 | /*! |
287 | \qmlproperty font AbstractAxis::titleFont |
288 | The font of the title of the axis. |
289 | */ |
290 | |
291 | /*! |
292 | \property QAbstractAxis::orientation |
293 | \brief The orientation of the axis. |
294 | |
295 | Fixed to either Qt::Horizontal or Qt::Vertical when the axis is added to a chart. |
296 | */ |
297 | /*! |
298 | \qmlproperty Qt.Orientation AbstractAxis::orientation |
299 | The orientation of the axis. Fixed to either \l {Qt::Horizontal}{Qt.Horizontal} |
300 | or \l{Qt::Vertical}{Qt.Vertical} when the axis is set to a series. |
301 | */ |
302 | |
303 | /*! |
304 | \property QAbstractAxis::alignment |
305 | \brief The alignment of the axis. |
306 | |
307 | Can be Qt::AlignLeft, Qt::AlignRight, Qt::AlignBottom, or Qt::AlignTop. |
308 | */ |
309 | /*! |
310 | \qmlproperty alignment AbstractAxis::alignment |
311 | The alignment of the axis. Can be \l{Qt::AlignLeft}{Qt.AlignLeft}, |
312 | \l{Qt::AlignRight}{Qt.AlignRight}, \l{Qt::AlignBottom}{Qt.AlignBottom}, or |
313 | \l{Qt::AlignTop}{Qt.AlignTop}. |
314 | */ |
315 | |
316 | /*! |
317 | \property QAbstractAxis::reverse |
318 | \brief Whether a reverse axis is used. |
319 | |
320 | By default, the value is \c false. |
321 | |
322 | The reverse axis is supported with a line, spline, and scatter series, as well as an area series |
323 | with a cartesian chart. All axes of the same orientation attached to the same series must be |
324 | reversed if one is reversed or the behavior is undefined. |
325 | */ |
326 | /*! |
327 | \qmlproperty alignment AbstractAxis::reverse |
328 | Defines whether a reverse axis is used. By default, the value is \c false. |
329 | |
330 | The reverse axis is supported with a line, spline, and scatter series, as well as an area series |
331 | with a cartesian chart. All axes of the same orientation attached to the same series must be |
332 | reversed if one is reversed or the behavior is undefined. |
333 | */ |
334 | |
335 | /*! |
336 | \fn void QAbstractAxis::visibleChanged(bool visible) |
337 | This signal is emitted when the visibility of the axis changes to \a visible. |
338 | */ |
339 | |
340 | /*! |
341 | \fn void QAbstractAxis::linePenChanged(const QPen& pen) |
342 | This signal is emitted when the pen used to draw the line of the axis changes to \a pen. |
343 | */ |
344 | |
345 | /*! |
346 | \fn void QAbstractAxis::lineVisibleChanged(bool visible) |
347 | This signal is emitted when the visibility of the axis line changes to \a visible. |
348 | */ |
349 | |
350 | /*! |
351 | \fn void QAbstractAxis::labelsVisibleChanged(bool visible) |
352 | This signal is emitted when the visibility of the labels of the axis changes to \a visible. |
353 | */ |
354 | |
355 | /*! |
356 | \fn void QAbstractAxis::labelsFontChanged(const QFont& font) |
357 | This signal is emitted when the font of the axis labels changes to \a font. |
358 | */ |
359 | |
360 | /*! |
361 | \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush) |
362 | This signal is emitted when the brush used to draw the axis labels changes to \a brush. |
363 | */ |
364 | |
365 | /*! |
366 | \fn void QAbstractAxis::labelsAngleChanged(int angle) |
367 | This signal is emitted when the angle of the axis labels changes to \a angle. |
368 | */ |
369 | |
370 | /*! |
371 | \fn void QAbstractAxis::labelsEditableChanged(bool editable) |
372 | \since 5.13 |
373 | This signal is emitted when the \a editable state of the label changes. |
374 | */ |
375 | |
376 | /*! |
377 | \fn void QAbstractAxis::gridVisibleChanged(bool visible) |
378 | This signal is emitted when the visibility of the grid lines of the axis changes to \a visible. |
379 | */ |
380 | |
381 | /*! |
382 | \fn void QAbstractAxis::minorGridVisibleChanged(bool visible) |
383 | This signal is emitted when the visibility of the minor grid lines of the axis |
384 | changes to \a visible. |
385 | */ |
386 | |
387 | /*! |
388 | \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen) |
389 | This signal is emitted when the pen used to draw the grid line changes to \a pen. |
390 | */ |
391 | |
392 | /*! |
393 | \fn void QAbstractAxis::minorGridLinePenChanged(const QPen& pen) |
394 | This signal is emitted when the pen used to draw the minor grid line changes to \a pen. |
395 | */ |
396 | |
397 | /*! |
398 | \fn void QAbstractAxis::gridLineColorChanged(const QColor &color) |
399 | This signal is emitted when the color of the pen used to draw the grid line changes to \a color. |
400 | */ |
401 | |
402 | /*! |
403 | \fn void QAbstractAxis::minorGridLineColorChanged(const QColor &color) |
404 | This signal is emitted when the color of the pen used to draw the minor grid line changes |
405 | to \a color. |
406 | */ |
407 | |
408 | /*! |
409 | \fn void QAbstractAxis::colorChanged(QColor color) |
410 | This signal is emitted when the color of the axis changes to \a color. |
411 | */ |
412 | |
413 | /*! |
414 | \fn void QAbstractAxis::labelsColorChanged(QColor color) |
415 | This signal is emitted when the color of the axis labels changes to \a color. |
416 | */ |
417 | |
418 | /*! |
419 | \fn void QAbstractAxis::titleVisibleChanged(bool visible) |
420 | This signal is emitted when the visibility of the title text of the axis changes to \a visible. |
421 | */ |
422 | |
423 | /*! |
424 | \fn void QAbstractAxis::titleTextChanged(const QString& text) |
425 | This signal is emitted when the text of the axis title changes to \a text. |
426 | */ |
427 | |
428 | /*! |
429 | \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush) |
430 | This signal is emitted when the brush used to draw the axis title changes to \a brush. |
431 | */ |
432 | |
433 | /*! |
434 | \fn void QAbstractAxis::titleFontChanged(const QFont& font) |
435 | This signal is emitted when the font of the axis title changes to \a font. |
436 | */ |
437 | |
438 | /*! |
439 | \fn void QAbstractAxis::shadesVisibleChanged(bool) |
440 | This signal is emitted when the visibility of the axis shades changes to \a visible. |
441 | */ |
442 | |
443 | /*! |
444 | \fn void QAbstractAxis::shadesColorChanged(QColor color) |
445 | This signal is emitted when the color of the axis shades changes to \a color. |
446 | */ |
447 | |
448 | /*! |
449 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor color) |
450 | This signal is emitted when the border color of the axis shades changes to \a color. |
451 | */ |
452 | |
453 | /*! |
454 | \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush) |
455 | This signal is emitted when the brush used to draw the axis shades changes to \a brush. |
456 | */ |
457 | |
458 | /*! |
459 | \fn void QAbstractAxis::shadesPenChanged(const QPen& pen) |
460 | This signal is emitted when the pen used to draw the axis shades changes to \a pen. |
461 | */ |
462 | |
463 | /*! |
464 | \internal |
465 | Constructs a new axis object that is a child of \a parent. The ownership is taken by |
466 | QChart when the axis is added. |
467 | */ |
468 | |
469 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) |
470 | : QObject(parent), |
471 | d_ptr(&d) |
472 | { |
473 | } |
474 | |
475 | /*! |
476 | Destructs the axis object. When the axis is added to a chart, the chart object takes ownership. |
477 | */ |
478 | |
479 | QAbstractAxis::~QAbstractAxis() |
480 | { |
481 | if (d_ptr->m_chart) |
482 | qFatal(msg: "Still binded axis detected !" ); |
483 | } |
484 | |
485 | /*! |
486 | Sets the pen used to draw the axis line and tick marks to \a pen. |
487 | */ |
488 | void QAbstractAxis::setLinePen(const QPen &pen) |
489 | { |
490 | if (d_ptr->m_axisPen != pen) { |
491 | d_ptr->m_axisPen = pen; |
492 | emit linePenChanged(pen); |
493 | } |
494 | } |
495 | |
496 | /*! |
497 | Returns the pen used to draw the axis line and tick marks. |
498 | */ |
499 | QPen QAbstractAxis::linePen() const |
500 | { |
501 | if (d_ptr->m_axisPen == QChartPrivate::defaultPen()) |
502 | return QPen(); |
503 | else |
504 | return d_ptr->m_axisPen; |
505 | } |
506 | |
507 | void QAbstractAxis::setLinePenColor(QColor color) |
508 | { |
509 | QPen p = linePen(); |
510 | if (p.color() != color || d_ptr->m_axisPen == QChartPrivate::defaultPen()) { |
511 | p.setColor(color); |
512 | setLinePen(p); |
513 | emit colorChanged(color); |
514 | } |
515 | } |
516 | |
517 | QColor QAbstractAxis::linePenColor() const |
518 | { |
519 | return linePen().color(); |
520 | } |
521 | |
522 | /*! |
523 | Determines whether the axis line and tick marks are \a visible. |
524 | */ |
525 | void QAbstractAxis::setLineVisible(bool visible) |
526 | { |
527 | if (d_ptr->m_arrowVisible != visible) { |
528 | d_ptr->m_arrowVisible = visible; |
529 | emit lineVisibleChanged(visible); |
530 | } |
531 | } |
532 | |
533 | bool QAbstractAxis::isLineVisible() const |
534 | { |
535 | return d_ptr->m_arrowVisible; |
536 | } |
537 | |
538 | void QAbstractAxis::setGridLineVisible(bool visible) |
539 | { |
540 | if (d_ptr->m_gridLineVisible != visible) { |
541 | d_ptr->m_gridLineVisible = visible; |
542 | emit gridVisibleChanged(visible); |
543 | } |
544 | } |
545 | |
546 | bool QAbstractAxis::isGridLineVisible() const |
547 | { |
548 | return d_ptr->m_gridLineVisible; |
549 | } |
550 | |
551 | void QAbstractAxis::setMinorGridLineVisible(bool visible) |
552 | { |
553 | if (d_ptr->m_minorGridLineVisible != visible) { |
554 | d_ptr->m_minorGridLineVisible = visible; |
555 | emit minorGridVisibleChanged(visible); |
556 | } |
557 | } |
558 | |
559 | bool QAbstractAxis::isMinorGridLineVisible() const |
560 | { |
561 | return d_ptr->m_minorGridLineVisible; |
562 | } |
563 | |
564 | /*! |
565 | Sets the pen used to draw the grid lines to \a pen. |
566 | */ |
567 | void QAbstractAxis::setGridLinePen(const QPen &pen) |
568 | { |
569 | if (d_ptr->m_gridLinePen != pen) { |
570 | d_ptr->m_gridLinePen = pen; |
571 | emit gridLinePenChanged(pen); |
572 | } |
573 | } |
574 | |
575 | /*! |
576 | Returns the pen used to draw the grid. |
577 | */ |
578 | QPen QAbstractAxis::gridLinePen() const |
579 | { |
580 | if (d_ptr->m_gridLinePen == QChartPrivate::defaultPen()) |
581 | return QPen(); |
582 | else |
583 | return d_ptr->m_gridLinePen; |
584 | } |
585 | |
586 | void QAbstractAxis::setMinorGridLinePen(const QPen &pen) |
587 | { |
588 | if (d_ptr->m_minorGridLinePen != pen) { |
589 | d_ptr->m_minorGridLinePen = pen; |
590 | emit minorGridLinePenChanged(pen); |
591 | } |
592 | } |
593 | |
594 | QPen QAbstractAxis::minorGridLinePen() const |
595 | { |
596 | if (d_ptr->m_minorGridLinePen == QChartPrivate::defaultPen()) |
597 | return QPen(); |
598 | else |
599 | return d_ptr->m_minorGridLinePen; |
600 | } |
601 | |
602 | void QAbstractAxis::setGridLineColor(const QColor &color) |
603 | { |
604 | QPen pen = gridLinePen(); |
605 | if (color != pen.color() || d_ptr->m_gridLinePen == QChartPrivate::defaultPen()) { |
606 | pen.setColor(color); |
607 | setGridLinePen(pen); |
608 | emit gridLineColorChanged(color); |
609 | } |
610 | } |
611 | |
612 | QColor QAbstractAxis::gridLineColor() |
613 | { |
614 | return gridLinePen().color(); |
615 | } |
616 | |
617 | void QAbstractAxis::setMinorGridLineColor(const QColor &color) |
618 | { |
619 | QPen pen = minorGridLinePen(); |
620 | if (color != pen.color() || d_ptr->m_minorGridLinePen == QChartPrivate::defaultPen()) { |
621 | pen.setColor(color); |
622 | setMinorGridLinePen(pen); |
623 | emit minorGridLineColorChanged(color); |
624 | } |
625 | } |
626 | |
627 | QColor QAbstractAxis::minorGridLineColor() |
628 | { |
629 | return minorGridLinePen().color(); |
630 | } |
631 | |
632 | void QAbstractAxis::setLabelsVisible(bool visible) |
633 | { |
634 | if (d_ptr->m_labelsVisible != visible) { |
635 | d_ptr->m_labelsVisible = visible; |
636 | emit labelsVisibleChanged(visible); |
637 | } |
638 | } |
639 | |
640 | bool QAbstractAxis::labelsVisible() const |
641 | { |
642 | return d_ptr->m_labelsVisible; |
643 | } |
644 | |
645 | /*! |
646 | Sets the brush used to draw labels to \a brush. |
647 | */ |
648 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) |
649 | { |
650 | if (d_ptr->m_labelsBrush != brush) { |
651 | d_ptr->m_labelsBrush = brush; |
652 | emit labelsBrushChanged(brush); |
653 | } |
654 | } |
655 | |
656 | /*! |
657 | Returns the brush used to draw labels. |
658 | */ |
659 | QBrush QAbstractAxis::labelsBrush() const |
660 | { |
661 | if (d_ptr->m_labelsBrush == QChartPrivate::defaultBrush()) |
662 | return QBrush(); |
663 | else |
664 | return d_ptr->m_labelsBrush; |
665 | } |
666 | |
667 | /*! |
668 | Sets the font used to draw labels to \a font. |
669 | */ |
670 | void QAbstractAxis::setLabelsFont(const QFont &font) |
671 | { |
672 | if (d_ptr->m_labelsFont != font) { |
673 | d_ptr->m_labelsFont = font; |
674 | emit labelsFontChanged(pen: font); |
675 | } |
676 | } |
677 | |
678 | /*! |
679 | Returns the font used to draw labels. |
680 | */ |
681 | QFont QAbstractAxis::labelsFont() const |
682 | { |
683 | if (d_ptr->m_labelsFont == QChartPrivate::defaultFont()) |
684 | return QFont(); |
685 | else |
686 | return d_ptr->m_labelsFont; |
687 | } |
688 | |
689 | void QAbstractAxis::setLabelsAngle(int angle) |
690 | { |
691 | if (d_ptr->m_labelsAngle != angle) { |
692 | d_ptr->m_labelsAngle = angle; |
693 | emit labelsAngleChanged(angle); |
694 | } |
695 | } |
696 | |
697 | int QAbstractAxis::labelsAngle() const |
698 | { |
699 | return d_ptr->m_labelsAngle; |
700 | } |
701 | void QAbstractAxis::setLabelsColor(QColor color) |
702 | { |
703 | QBrush b = labelsBrush(); |
704 | if (b.color() != color || d_ptr->m_labelsBrush == QChartPrivate::defaultBrush()) { |
705 | b.setColor(color); |
706 | setLabelsBrush(b); |
707 | emit labelsColorChanged(color); |
708 | } |
709 | } |
710 | |
711 | QColor QAbstractAxis::labelsColor() const |
712 | { |
713 | return labelsBrush().color(); |
714 | } |
715 | |
716 | void QAbstractAxis::setTitleVisible(bool visible) |
717 | { |
718 | if (d_ptr->m_titleVisible != visible) { |
719 | d_ptr->m_titleVisible = visible; |
720 | emit titleVisibleChanged(visible); |
721 | } |
722 | } |
723 | |
724 | bool QAbstractAxis::isTitleVisible() const |
725 | { |
726 | return d_ptr->m_titleVisible; |
727 | } |
728 | |
729 | /*! |
730 | Sets the brush used to draw titles to \a brush. |
731 | */ |
732 | void QAbstractAxis::setTitleBrush(const QBrush &brush) |
733 | { |
734 | if (d_ptr->m_titleBrush != brush) { |
735 | d_ptr->m_titleBrush = brush; |
736 | emit titleBrushChanged(brush); |
737 | } |
738 | } |
739 | |
740 | /*! |
741 | Returns the brush used to draw titles. |
742 | */ |
743 | QBrush QAbstractAxis::titleBrush() const |
744 | { |
745 | if (d_ptr->m_titleBrush == QChartPrivate::defaultBrush()) |
746 | return QBrush(); |
747 | else |
748 | return d_ptr->m_titleBrush; |
749 | } |
750 | |
751 | /*! |
752 | Sets the font used to draw titles to \a font. |
753 | */ |
754 | void QAbstractAxis::setTitleFont(const QFont &font) |
755 | { |
756 | if (d_ptr->m_titleFont != font) { |
757 | d_ptr->m_titleFont = font; |
758 | emit titleFontChanged(font); |
759 | } |
760 | } |
761 | |
762 | /*! |
763 | Returns the font used to draw titles. |
764 | */ |
765 | QFont QAbstractAxis::titleFont() const |
766 | { |
767 | if (d_ptr->m_titleFont == QChartPrivate::defaultFont()) |
768 | return QFont(); |
769 | else |
770 | return d_ptr->m_titleFont; |
771 | } |
772 | |
773 | void QAbstractAxis::setTitleText(const QString &title) |
774 | { |
775 | if (d_ptr->m_title != title) { |
776 | d_ptr->m_title = title; |
777 | emit titleTextChanged(title); |
778 | } |
779 | } |
780 | |
781 | QString QAbstractAxis::titleText() const |
782 | { |
783 | return d_ptr->m_title; |
784 | } |
785 | |
786 | |
787 | void QAbstractAxis::setShadesVisible(bool visible) |
788 | { |
789 | if (d_ptr->m_shadesVisible != visible) { |
790 | d_ptr->m_shadesVisible = visible; |
791 | emit shadesVisibleChanged(visible); |
792 | } |
793 | } |
794 | |
795 | bool QAbstractAxis::shadesVisible() const |
796 | { |
797 | return d_ptr->m_shadesVisible; |
798 | } |
799 | |
800 | /*! |
801 | Sets the pen used to draw shades to \a pen. |
802 | */ |
803 | void QAbstractAxis::setShadesPen(const QPen &pen) |
804 | { |
805 | if (d_ptr->m_shadesPen != pen) { |
806 | d_ptr->m_shadesPen = pen; |
807 | emit shadesPenChanged(pen); |
808 | } |
809 | } |
810 | |
811 | /*! |
812 | Returns the pen used to draw shades. |
813 | */ |
814 | QPen QAbstractAxis::shadesPen() const |
815 | { |
816 | if (d_ptr->m_shadesPen == QChartPrivate::defaultPen()) |
817 | return QPen(); |
818 | else |
819 | return d_ptr->m_shadesPen; |
820 | } |
821 | |
822 | /*! |
823 | Sets the brush used to draw shades to \a brush. |
824 | */ |
825 | void QAbstractAxis::setShadesBrush(const QBrush &brush) |
826 | { |
827 | if (d_ptr->m_shadesBrush != brush) { |
828 | d_ptr->m_shadesBrush = brush; |
829 | emit shadesBrushChanged(brush); |
830 | } |
831 | } |
832 | |
833 | /*! |
834 | Returns the brush used to draw shades. |
835 | */ |
836 | QBrush QAbstractAxis::shadesBrush() const |
837 | { |
838 | if (d_ptr->m_shadesBrush == QChartPrivate::defaultBrush()) |
839 | return QBrush(Qt::SolidPattern); |
840 | else |
841 | return d_ptr->m_shadesBrush; |
842 | } |
843 | |
844 | void QAbstractAxis::setShadesColor(QColor color) |
845 | { |
846 | QBrush b = shadesBrush(); |
847 | if (b.color() != color || d_ptr->m_shadesBrush == QChartPrivate::defaultBrush()) { |
848 | b.setColor(color); |
849 | setShadesBrush(b); |
850 | emit shadesColorChanged(color); |
851 | } |
852 | } |
853 | |
854 | QColor QAbstractAxis::shadesColor() const |
855 | { |
856 | return shadesBrush().color(); |
857 | } |
858 | |
859 | void QAbstractAxis::setShadesBorderColor(QColor color) |
860 | { |
861 | QPen p = shadesPen(); |
862 | if (p.color() != color || d_ptr->m_shadesPen == QChartPrivate::defaultPen()) { |
863 | p.setColor(color); |
864 | setShadesPen(p); |
865 | emit shadesColorChanged(color); |
866 | } |
867 | } |
868 | |
869 | QColor QAbstractAxis::shadesBorderColor() const |
870 | { |
871 | return shadesPen().color(); |
872 | } |
873 | |
874 | |
875 | bool QAbstractAxis::isVisible() const |
876 | { |
877 | return d_ptr->m_visible; |
878 | } |
879 | |
880 | /*! |
881 | Sets the visibility of the axis, shades, labels, and grid lines to \a visible. |
882 | */ |
883 | void QAbstractAxis::setVisible(bool visible) |
884 | { |
885 | if (d_ptr->m_visible != visible) { |
886 | d_ptr->m_visible = visible; |
887 | emit visibleChanged(visible); |
888 | } |
889 | } |
890 | |
891 | |
892 | /*! |
893 | Makes the axis, shades, labels, and grid lines visible. |
894 | */ |
895 | void QAbstractAxis::show() |
896 | { |
897 | setVisible(true); |
898 | } |
899 | |
900 | /*! |
901 | Makes the axis, shades, labels, and grid lines invisible. |
902 | */ |
903 | void QAbstractAxis::hide() |
904 | { |
905 | setVisible(false); |
906 | } |
907 | |
908 | /*! |
909 | Sets the minimum value shown on the axis. |
910 | Depending on the actual axis type, the \a min parameter is converted to the appropriate type |
911 | of value. If the conversion is impossible, the function call does nothing. |
912 | */ |
913 | void QAbstractAxis::setMin(const QVariant &min) |
914 | { |
915 | d_ptr->setMin(min); |
916 | } |
917 | |
918 | /*! |
919 | Sets the maximum value shown on the axis. |
920 | Depending on the actual axis type, the \a max parameter is converted to the appropriate type |
921 | of value. If the conversion is impossible, the function call does nothing. |
922 | */ |
923 | void QAbstractAxis::setMax(const QVariant &max) |
924 | { |
925 | d_ptr->setMax(max); |
926 | } |
927 | |
928 | /*! |
929 | Sets the range shown on the axis. |
930 | Depending on the actual axis type, the \a min and \a max parameters are converted to |
931 | appropriate types of values. If the conversion is impossible, the function call does nothing. |
932 | */ |
933 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) |
934 | { |
935 | d_ptr->setRange(min, max); |
936 | } |
937 | |
938 | |
939 | /*! |
940 | Returns the orientation of the axis (vertical or horizontal). |
941 | */ |
942 | Qt::Orientation QAbstractAxis::orientation() const |
943 | { |
944 | return d_ptr->orientation(); |
945 | } |
946 | |
947 | Qt::Alignment QAbstractAxis::alignment() const |
948 | { |
949 | return d_ptr->alignment(); |
950 | } |
951 | |
952 | bool QAbstractAxis::isReverse() const |
953 | { |
954 | return d_ptr->m_reverse; |
955 | } |
956 | |
957 | /*! |
958 | Sets axis labels editability to \a editable. |
959 | |
960 | When the labels are editable the user will be able to change the range of the |
961 | axis conveniently by editing any of the labels. This feature is only supported |
962 | for the QValueAxis and the QDateTimeAxis. |
963 | |
964 | By default, labels are not editable. |
965 | \since 5.13 |
966 | */ |
967 | void QAbstractAxis::setLabelsEditable(bool editable) |
968 | { |
969 | if (d_ptr->m_labelsEditable != editable) { |
970 | // In the case if the axis already added to a chart |
971 | // set the labels editability on the axisItem(). |
972 | // Otherwise the labels editability will be set in the |
973 | // QValueAxisPrivate::initializeGraphics. |
974 | if (d_ptr->axisItem() != nullptr) |
975 | d_ptr->axisItem()->setLabelsEditable(editable); |
976 | d_ptr->m_labelsEditable = editable; |
977 | emit labelsEditableChanged(editable); |
978 | } |
979 | } |
980 | |
981 | /*! |
982 | Returns \c true if axis labels are editable. |
983 | \since 5.13 |
984 | */ |
985 | bool QAbstractAxis::labelsEditable() const |
986 | { |
987 | return d_ptr->m_labelsEditable; |
988 | } |
989 | |
990 | void QAbstractAxis::setReverse(bool reverse) |
991 | { |
992 | if (d_ptr->m_reverse != reverse && type() != QAbstractAxis::AxisTypeBarCategory) { |
993 | d_ptr->m_reverse = reverse; |
994 | emit reverseChanged(reverse); |
995 | } |
996 | } |
997 | |
998 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
999 | |
1000 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q) |
1001 | : q_ptr(q), |
1002 | m_axisPen(QChartPrivate::defaultPen()), |
1003 | m_axisBrush(QChartPrivate::defaultBrush()), |
1004 | m_gridLinePen(QChartPrivate::defaultPen()), |
1005 | m_minorGridLinePen(QChartPrivate::defaultPen()), |
1006 | m_labelsBrush(QChartPrivate::defaultBrush()), |
1007 | m_labelsFont(QChartPrivate::defaultFont()), |
1008 | m_titleBrush(QChartPrivate::defaultBrush()), |
1009 | m_titleFont(QChartPrivate::defaultFont()), |
1010 | m_shadesPen(QChartPrivate::defaultPen()), |
1011 | m_shadesBrush(QChartPrivate::defaultBrush()) |
1012 | { |
1013 | } |
1014 | |
1015 | QAbstractAxisPrivate::~QAbstractAxisPrivate() |
1016 | { |
1017 | } |
1018 | |
1019 | void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment) |
1020 | { |
1021 | switch(alignment) { |
1022 | case Qt::AlignTop: |
1023 | case Qt::AlignBottom: |
1024 | m_orientation = Qt::Horizontal; |
1025 | break; |
1026 | case Qt::AlignLeft: |
1027 | case Qt::AlignRight: |
1028 | m_orientation = Qt::Vertical; |
1029 | break; |
1030 | default: |
1031 | qWarning()<<"No alignment specified !" ; |
1032 | break; |
1033 | }; |
1034 | m_alignment=alignment; |
1035 | } |
1036 | |
1037 | void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced) |
1038 | { |
1039 | if (forced || QChartPrivate::defaultPen() == m_axisPen) |
1040 | q_ptr->setLinePen(theme->axisLinePen()); |
1041 | |
1042 | if (forced || QChartPrivate::defaultPen() == m_gridLinePen) |
1043 | q_ptr->setGridLinePen(theme->gridLinePen()); |
1044 | if (forced || QChartPrivate::defaultPen() == m_minorGridLinePen) |
1045 | q_ptr->setMinorGridLinePen(theme->minorGridLinePen()); |
1046 | |
1047 | if (forced || QChartPrivate::defaultBrush() == m_labelsBrush) |
1048 | q_ptr->setLabelsBrush(theme->labelBrush()); |
1049 | if (forced || QChartPrivate::defaultFont() == m_labelsFont) |
1050 | q_ptr->setLabelsFont(theme->labelFont()); |
1051 | |
1052 | if (forced || QChartPrivate::defaultBrush() == m_titleBrush) |
1053 | q_ptr->setTitleBrush(theme->labelBrush()); |
1054 | if (forced || QChartPrivate::defaultFont() == m_titleFont) { |
1055 | QFont font(m_labelsFont); |
1056 | font.setBold(true); |
1057 | q_ptr->setTitleFont(font); |
1058 | } |
1059 | |
1060 | if (forced || QChartPrivate::defaultBrush() == m_shadesBrush) |
1061 | q_ptr->setShadesBrush(theme->backgroundShadesBrush()); |
1062 | if (forced || QChartPrivate::defaultPen() == m_shadesPen) |
1063 | q_ptr->setShadesPen(theme->backgroundShadesPen()); |
1064 | |
1065 | bool axisX = m_orientation == Qt::Horizontal; |
1066 | if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth |
1067 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX) |
1068 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) { |
1069 | q_ptr->setShadesVisible(true); |
1070 | } else if (forced) { |
1071 | q_ptr->setShadesVisible(false); |
1072 | } |
1073 | } |
1074 | |
1075 | void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max) |
1076 | { |
1077 | setRange(min,max); |
1078 | } |
1079 | |
1080 | void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
1081 | { |
1082 | Q_UNUSED(parent); |
1083 | } |
1084 | |
1085 | void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options, int duration, |
1086 | QEasingCurve &curve) |
1087 | { |
1088 | ChartAxisElement *axis = m_item.data(); |
1089 | Q_ASSERT(axis); |
1090 | if (axis->animation()) |
1091 | axis->animation()->stopAndDestroyLater(); |
1092 | |
1093 | if (options.testFlag(flag: QChart::GridAxisAnimations)) |
1094 | axis->setAnimation(new AxisAnimation(axis, duration, curve)); |
1095 | else |
1096 | axis->setAnimation(0); |
1097 | } |
1098 | |
1099 | QT_CHARTS_END_NAMESPACE |
1100 | |
1101 | #include "moc_qabstractaxis.cpp" |
1102 | #include "moc_qabstractaxis_p.cpp" |
1103 | |