1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef AXISRENDERER_H
5#define AXISRENDERER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the QtGraphs API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16
17#include <QQuickItem>
18#include <QRectF>
19#include <QList>
20#include <QList>
21#include <QtQuick/private/qquicktext_p.h>
22#include <private/axisgrid_p.h>
23#include <private/axisticker_p.h>
24#include <private/axisline_p.h>
25
26QT_BEGIN_NAMESPACE
27
28class QAbstractAxis;
29class QGraphsView;
30class QBarCategoryAxis;
31class QValueAxis;
32class QGraphsTheme;
33class QDateTimeAxis;
34
35class AxisRenderer : public QQuickItem
36{
37 Q_OBJECT
38public:
39 AxisRenderer(QQuickItem *parent = nullptr);
40 ~AxisRenderer() override;
41
42 void handlePolish();
43 void updateAxis();
44 void updateAxisTickers();
45 void updateAxisTickersShadow();
46 void updateAxisGrid();
47 void updateAxisGridShadow();
48 void updateAxisTitles(const QRectF xAxisRect, const QRectF yAxisRect);
49 void updateBarXAxisLabels(QBarCategoryAxis *axis, const QRectF rect);
50 void updateBarYAxisLabels(QBarCategoryAxis *axis, const QRectF rect);
51 void updateValueYAxisLabels(QValueAxis *axis, const QRectF rect);
52 void updateValueXAxisLabels(QValueAxis *axis, const QRectF rect);
53 void updateDateTimeYAxisLabels(QDateTimeAxis *axis, const QRectF rect);
54 void updateDateTimeXAxisLabels(QDateTimeAxis *axis, const QRectF rect);
55 void initialize();
56
57Q_SIGNALS:
58
59private:
60 friend class QGraphsView;
61 friend class BarsRenderer;
62 friend class LinesRenderer;
63 friend class PointRenderer;
64 friend class AreaRenderer;
65
66 double getValueStepsFromRange(double range);
67 int getValueDecimalsFromRange(double range);
68 void setLabelTextProperties(QQuickItem *item, const QString &text, bool xAxis,
69 QQuickText::HAlignment hAlign = QQuickText::HAlignment::AlignHCenter,
70 QQuickText::VAlignment vAlign = QQuickText::VAlignment::AlignVCenter);
71 void updateAxisLabelItems(QList<QQuickItem *> &textItems, qsizetype neededSize, QQmlComponent *component);
72
73 QGraphsView *m_graph = nullptr;
74 QGraphsTheme *theme();
75 bool m_initialized = false;
76 bool m_wasVertical = false;
77 bool m_verticalAxisOnRight = false;
78 bool m_horizontalAxisOnTop = false;
79
80 QAbstractAxis *m_axisVertical = nullptr;
81 QAbstractAxis *m_axisHorizontal = nullptr;
82 QList<QQuickItem *> m_xAxisTextItems;
83 QList<QQuickItem *> m_yAxisTextItems;
84 QQuickText *m_xAxisTitle = nullptr;
85 QQuickText *m_yAxisTitle = nullptr;
86 AxisGrid *m_axisGrid = nullptr;
87 AxisTicker *m_axisTickerVertical = nullptr;
88 AxisTicker *m_axisTickerHorizontal = nullptr;
89 AxisLine *m_axisLineVertical = nullptr;
90 AxisLine *m_axisLineHorizontal = nullptr;
91
92 // Shadow
93 AxisGrid *m_axisGridShadow = nullptr;
94 AxisTicker *m_axisTickerVerticalShadow = nullptr;
95 AxisTicker *m_axisTickerHorizontalShadow = nullptr;
96 AxisLine *m_axisLineVerticalShadow = nullptr;
97 AxisLine *m_axisLineHorizontalShadow = nullptr;
98
99 // Vertical axis
100 // Max value
101 double m_axisVerticalMaxValue = 20;
102 // Min value
103 double m_axisVerticalMinValue = 0;
104 // Values range, so m_axisVerticalMaxValue - m_axisVerticalMinValue
105 double m_axisVerticalValueRange = 0;
106 // How much each major value step is
107 double m_axisVerticalValueStep = 1.0;
108 // px between major ticks
109 double m_axisVerticalStepPx = 0;
110 // Ticks movement, between -m_axisHorizontalStepPx .. m_axisHorizontalStepPx.
111 double m_axisYDisplacement = 0;
112 // The value of smallest label
113 double m_axisVerticalMinLabel = 0;
114
115
116 // Horizontal axis
117 // Max value
118 double m_axisHorizontalMaxValue = 20;
119 // Min value
120 double m_axisHorizontalMinValue = 0;
121 // Values range, so m_axisHorizontalMaxValue - m_axisHorizontalMinValue
122 double m_axisHorizontalValueRange = 0;
123 // How much each major value step is
124 double m_axisHorizontalValueStep = 1.0;
125 // px between major ticks
126 double m_axisHorizontalStepPx = 0;
127 // Ticks movement, between -m_axisHorizontalStepPx .. m_axisHorizontalStepPx.
128 double m_axisXDisplacement = 0;
129 // The value of smallest label
130 double m_axisHorizontalMinLabel = 0;
131
132 double m_axisVerticalSubGridScale = 0.5;
133 double m_axisHorizontalSubGridScale = 0.5;
134 bool m_gridHorizontalLinesVisible = true;
135 bool m_gridVerticalLinesVisible = true;
136 bool m_gridHorizontalSubLinesVisible = false;
137 bool m_gridVerticalSubLinesVisible = false;
138};
139
140QT_END_NAMESPACE
141
142#endif // AXISRENDERER_H
143

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtgraphs/src/graphs2d/qsgrenderer/axisrenderer_p.h