1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "axisgrid_p.h"
5
6QT_BEGIN_NAMESPACE
7
8AxisGrid::AxisGrid(QQuickItem *parent) :
9 QQuickShaderEffect(parent)
10{
11}
12
13AxisGrid::~AxisGrid() {}
14
15void AxisGrid::componentComplete()
16{
17 QQuickShaderEffect::componentComplete();
18 setupShaders();
19}
20
21void AxisGrid::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
22{
23 m_iResolution = QVector3D(newGeometry.width(), newGeometry.height(), 1.0);
24 emit iResolutionChanged();
25
26 QQuickShaderEffect::geometryChange(newGeometry, oldGeometry);
27}
28
29void AxisGrid::setupShaders()
30{
31 setFragmentShader(QUrl(QStringLiteral("qrc:/shaders/gridshader.frag.qsb")));
32 setVertexShader(QUrl(QStringLiteral("qrc:/shaders/gridshader.vert.qsb")));
33}
34
35QVector3D AxisGrid::iResolution() const
36{
37 return m_iResolution;
38}
39
40qreal AxisGrid::smoothing() const
41{
42 return m_smoothing;
43}
44
45void AxisGrid::setSmoothing(qreal newSmoothing)
46{
47 if (qFuzzyCompare(p1: m_smoothing, p2: newSmoothing))
48 return;
49 m_smoothing = newSmoothing;
50 emit smoothingChanged();
51}
52
53int AxisGrid::origo() const
54{
55 return m_origo;
56}
57
58void AxisGrid::setOrigo(int newOrigo)
59{
60 if (m_origo == newOrigo)
61 return;
62 m_origo = newOrigo;
63 emit origoChanged();
64}
65
66QVector4D AxisGrid::gridVisibility() const
67{
68 return m_gridVisibility;
69}
70
71void AxisGrid::setGridVisibility(const QVector4D &newGridVisibility)
72{
73 if (m_gridVisibility == newGridVisibility)
74 return;
75 m_gridVisibility = newGridVisibility;
76 emit gridVisibilityChanged();
77}
78
79qreal AxisGrid::gridWidth() const
80{
81 return m_gridWidth;
82}
83
84void AxisGrid::setGridWidth(qreal newGridWidth)
85{
86 if (qFuzzyCompare(p1: m_gridWidth, p2: newGridWidth))
87 return;
88 m_gridWidth = newGridWidth;
89 emit gridWidthChanged();
90}
91
92qreal AxisGrid::gridHeight() const
93{
94 return m_gridHeight;
95}
96
97void AxisGrid::setGridHeight(qreal newGridHeight)
98{
99 if (qFuzzyCompare(p1: m_gridHeight, p2: newGridHeight))
100 return;
101 m_gridHeight = newGridHeight;
102 emit gridHeightChanged();
103}
104
105QPointF AxisGrid::gridMovement() const
106{
107 return m_gridMovement;
108}
109
110void AxisGrid::setGridMovement(QPointF newGridMovement)
111{
112 if (m_gridMovement == newGridMovement)
113 return;
114 m_gridMovement = newGridMovement;
115 emit gridMovementChanged();
116}
117
118QColor AxisGrid::subGridColor() const
119{
120 return m_subGridColor;
121}
122
123void AxisGrid::setSubGridColor(QColor newSubGridColor)
124{
125 if (m_subGridColor == newSubGridColor)
126 return;
127 m_subGridColor = newSubGridColor;
128 emit subGridColorChanged();
129}
130
131QColor AxisGrid::gridColor() const
132{
133 return m_gridColor;
134}
135
136void AxisGrid::setGridColor(QColor newGridColor)
137{
138 if (m_gridColor == newGridColor)
139 return;
140 m_gridColor = newGridColor;
141 emit gridColorChanged();
142}
143
144QColor AxisGrid::plotAreaBackgroundColor() const
145{
146 return m_plotAreaBackgroundColor;
147}
148
149void AxisGrid::setPlotAreaBackgroundColor(QColor color)
150{
151 if (m_plotAreaBackgroundColor == color)
152 return;
153 m_plotAreaBackgroundColor = color;
154 emit plotAreaBackgroundColorChanged();
155}
156
157qreal AxisGrid::subGridLineWidth() const
158{
159 return m_subGridLineWidth;
160}
161
162void AxisGrid::setSubGridLineWidth(qreal newSubGridLineWidth)
163{
164 if (qFuzzyCompare(p1: m_subGridLineWidth, p2: newSubGridLineWidth))
165 return;
166 m_subGridLineWidth = newSubGridLineWidth;
167 emit subGridLineWidthChanged();
168}
169
170qreal AxisGrid::gridLineWidth() const
171{
172 return m_gridLineWidth;
173}
174
175void AxisGrid::setGridLineWidth(qreal newGridLineWidth)
176{
177 if (qFuzzyCompare(p1: m_gridLineWidth, p2: newGridLineWidth))
178 return;
179 m_gridLineWidth = newGridLineWidth;
180 emit gridLineWidthChanged();
181}
182
183qreal AxisGrid::verticalSubGridScale() const
184{
185 return m_verticalSubGridScale;
186}
187
188void AxisGrid::setVerticalSubGridScale(qreal newVerticalSubGridScale)
189{
190 if (qFuzzyCompare(p1: m_verticalSubGridScale, p2: newVerticalSubGridScale))
191 return;
192 m_verticalSubGridScale = newVerticalSubGridScale;
193 emit verticalSubGridScaleChanged();
194}
195
196qreal AxisGrid::horizontalSubGridScale() const
197{
198 return m_horizontalSubGridScale;
199}
200
201void AxisGrid::setHorizontalSubGridScale(qreal newHorizontalSubGridScale)
202{
203 if (qFuzzyCompare(p1: m_horizontalSubGridScale, p2: newHorizontalSubGridScale))
204 return;
205 m_horizontalSubGridScale = newHorizontalSubGridScale;
206 emit horizontalSubGridScaleChanged();
207}
208
209QT_END_NAMESPACE
210

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

source code of qtgraphs/src/graphs2d/axis/axisgrid.cpp