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

source code of qtcharts/src/charts/axis/qabstractaxis.cpp