1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3#include <private/qspline3dseries_p.h>
4#include "qgraphs3dlogging_p.h"
5
6QT_BEGIN_NAMESPACE
7
8/*!
9 * \class QSpline3DSeries
10 * \inmodule QtGraphs
11 * \ingroup graphs_3D
12 * \since 6.9
13 * \brief The QSpline3DSeries class represents a data series as a spline.
14 *
15 * Spline graphs are used to show information as a series of data points connected
16 * by a curved or straight Catmull-Rom spline.
17 *
18 * This class manages the spline specific visual elements.
19 *
20 * Spline3DSeries extends the Scatter3DSeries API.
21 */
22
23/*!
24 * \qmltype Spline3DSeries
25 * \nativetype QSpline3DSeries
26 * \inqmlmodule QtGraphs
27 * \ingroup graphs_qml_3D
28 * \inherits Scatter3DSeries
29 * \since 6.9
30 * \brief Represents a data series in a 3D spline graph.
31 *
32 * Spline graphs are used to show information as a series of data points connected
33 * by a curved or straight Catmull-Rom spline.
34 *
35 * This type manages the spline specific visual elements.
36 *
37 */
38
39/*!
40 * \qmlproperty bool Spline3DSeries::splineVisible
41 *
42 * Visibility of the spline. The default value is \c true.
43 */
44
45/*!
46 * \qmlproperty real Spline3DSeries::splineTension
47 *
48 * The tension of the spline.
49 *
50 * The spline uses maximum curvature for segments at a value of \c 0.0
51 * Segments are completely straight at a value of \c 1.0
52 * Must be between \c 0.0 and \c 1.0
53 * The default value is \c 0.0
54 *
55 */
56
57/*!
58 * \qmlproperty real Spline3DSeries::splineKnotting
59 *
60 * The knot parametrization of the spline.
61 *
62 * This parameter can change the profile of the curve.
63 * The spline is classified as a uniform Catmull-Rom spline at a value of \c 0.0,
64 * a centripetal Catmull-Rom spline at a value of \c 0.5,
65 * and a chordal Catmull-Rom spline at a value of \c 1.0.
66 *
67 * The value must be between \c 0.0 and \c 1.0.
68 * The default value is \c 0.5.
69 *
70 */
71
72/*!
73 * \qmlproperty bool Spline3DSeries::splineLooping
74 *
75 * Determines whether the spline loops.
76 *
77 * This adds a spline segment between the first and last points of the series
78 * connecting the spline into a loop.
79 *
80 * The default value is \c false
81 *
82 */
83
84/*!
85 * \qmlproperty int QSpline3DSeries::splineResolution
86 *
87 * The resolution of the segments spline.
88 *
89 * The number of vertices per spline segment,
90 * which is defined as the part between two points.
91 *
92 * Must be a value above \c 2.
93 * The default value is \c 10.
94 */
95
96/*!
97 * \qmlproperty color Spline3DSeries::splineColor
98 *
99 * The color of the spline.
100 *
101 */
102
103/*!
104 \qmlsignal Scatter3DSeries::splineVisibilityChanged(bool visible)
105
106 This signal is emitted when splineVisible changes to \a visible.
107*/
108
109/*!
110 \qmlsignal Scatter3DSeries::splineTensionChanged(real tension)
111
112 This signal is emitted when splineTension changes to \a tension.
113*/
114
115/*!
116 \qmlsignal Scatter3DSeries::splineKnottingChanged(real knotting)
117
118 This signal is emitted when splineKnotting changes to \a knotting.
119*/
120
121/*!
122 \qmlsignal Scatter3DSeries::splineLoopingChanged(bool looping)
123
124 This signal is emitted when splineLooping changes to \a looping.
125*/
126
127/*!
128 \qmlsignal Scatter3DSeries::splineColorChanged(color color)
129
130 This signal is emitted when splineColor changes to \a color.
131*/
132
133/*!
134 \qmlsignal Scatter3DSeries::splineResolutionChanged(int resolution)
135
136 This signal is emitted when splineResolution changes to \a resolution.
137*/
138
139/*!
140 * Constructs a spline 3D series with the parent \a parent.
141 */
142QSpline3DSeries ::QSpline3DSeries(QObject *parent)
143 : QScatter3DSeries(*(new QSpline3DSeriesPrivate()), parent)
144{
145 Q_D(QScatter3DSeries);
146 // Default proxy
147 d->setDataProxy(new QScatterDataProxy);
148}
149
150/*!
151 * Constructs a spline 3D series with the data proxy \a dataProxy and the
152 * parent \a parent.
153 */
154QSpline3DSeries ::QSpline3DSeries(QScatterDataProxy *dataProxy, QObject *parent)
155 : QScatter3DSeries(*(new QSpline3DSeriesPrivate()), parent)
156{
157 Q_D(QScatter3DSeries);
158 // Default proxy
159 d->setDataProxy(dataProxy);
160}
161
162/*!
163 * \internal
164 */
165QSpline3DSeries ::QSpline3DSeries(QSpline3DSeriesPrivate &dd, QObject *parent)
166 : QScatter3DSeries(dd, parent)
167{}
168
169/*!
170 * Deletes the spline 3D series.
171 */
172QSpline3DSeries::~QSpline3DSeries() {}
173
174/*!
175 * \property QSpline3DSeries::splineVisible
176 *
177 * \brief Visibility of the spline.
178 *
179 * Visibility of the spline.
180 * The default value is \c true.
181 *
182 */
183void QSpline3DSeries::setSplineVisible(bool visible)
184{
185 Q_D(QSpline3DSeries);
186 if (d->m_splineVisible == visible) {
187 qCDebug(lcProperties3D) << __FUNCTION__
188 << "value is already set to:" << visible;
189 return;
190 }
191 d->m_splineVisible = visible;
192 emit splineVisibilityChanged(visible);
193}
194
195bool QSpline3DSeries::isSplineVisible() const
196{
197 const Q_D(QSpline3DSeries);
198 return d->m_splineVisible;
199}
200
201/*!
202 * \property QSpline3DSeries::splineTension
203 *
204 * \brief The tension of the spline.
205 *
206 * The spline uses maximum curvature for segments at a value of \c 0.0
207 * Segments are completely straight at a value of \c 1.0
208 * Must be between \c 0.0 and \c 1.0
209 * The default value is \c 0.0
210 *
211 */
212void QSpline3DSeries::setSplineTension(qreal tension)
213{
214 Q_D(QSpline3DSeries);
215 if (tension < 0.0f || tension > 1.0f) {
216 qCWarning(lcProperties3D, "%s invalid tension. Valid range for tension is 0.0f...1.0f",
217 qUtf8Printable(QLatin1String(__FUNCTION__)));
218 return;
219 } else if (d->m_tension == tension) {
220 qCDebug(lcProperties3D, "%s value is already set to: %f",
221 qUtf8Printable(QLatin1String(__FUNCTION__)), tension);
222 return;
223 }
224 d->m_tension = tension;
225 emit splineTensionChanged(tension);
226}
227
228qreal QSpline3DSeries::splineTension() const
229{
230 const Q_D(QSpline3DSeries);
231 return d->m_tension;
232}
233
234/*!
235 * \property QSpline3DSeries::splineKnotting
236 *
237 * \brief The knot parametrization of the spline.
238 *
239 * This parameter can change the profile of the curve.
240 * The spline is classified as a uniform Catmull-Rom spline at a value of \c 0.0,
241 * a centripetal Catmull-Rom spline at a value of \c 0.5,
242 * and a chordal Catmull-Rom spline at a value of \c 1.0.
243 *
244 * The value must be between \c 0.0 and \c 1.0.
245 * The default value is \c 0.5.
246 *
247 */
248void QSpline3DSeries::setSplineKnotting(qreal knotting)
249{
250 Q_D(QSpline3DSeries);
251 if (knotting < 0.0f || knotting > 1.0f) {
252 qCWarning(lcProperties3D, "%s invalid knotting. Valid range for knotting is 0.0f...1.0f",
253 qUtf8Printable(QLatin1String(__FUNCTION__)));
254 return;
255 } else if (d->m_knotting == knotting) {
256 qCDebug(lcProperties3D, "%s value is already set to: %f",
257 qUtf8Printable(QLatin1String(__FUNCTION__)), knotting);
258 return;
259 }
260 d->m_knotting = knotting;
261 emit splineKnottingChanged(knotting);
262}
263
264qreal QSpline3DSeries::splineKnotting() const
265{
266 const Q_D(QSpline3DSeries);
267 return d->m_knotting;
268}
269
270/*!
271 * \property QSpline3DSeries::splineLooping
272 *
273 * \brief Determines whether the spline loops.
274 *
275 * This adds a spline segment between the first and last points of the series
276 * connecting the spline into a loop.
277 *
278 * The default value is \c false
279 *
280 */
281void QSpline3DSeries::setSplineLooping(bool looping)
282{
283 Q_D(QSpline3DSeries);
284 if (d->m_looping == looping) {
285 qCDebug(lcProperties3D) << __FUNCTION__
286 << "value is already set to:" << looping;
287 return;
288 }
289 d->m_looping = looping;
290 emit splineLoopingChanged(looping);
291}
292
293bool QSpline3DSeries::isSplineLooping() const
294{
295 const Q_D(QSpline3DSeries);
296 return d->m_looping;
297}
298
299/*!
300 * \property QSpline3DSeries::splineColor
301 *
302 * \brief The color of the spline.
303 *
304 */
305void QSpline3DSeries::setSplineColor(QColor color)
306{
307 Q_D(QSpline3DSeries);
308 if (d->m_splineColor == color) {
309 qCDebug(lcProperties3D) << __FUNCTION__
310 << "value is already set to:" << color;
311 return;
312 }
313 d->m_splineColor = color;
314 emit splineColorChanged(color);
315}
316
317QColor QSpline3DSeries::splineColor() const
318{
319 const Q_D(QSpline3DSeries);
320 return d->m_splineColor;
321}
322
323/*!
324 * \property QSpline3DSeries::splineResolution
325 *
326 * \brief The resolution of the segments spline.
327 *
328 * The number of vertices per spline segment,
329 * which is defined as the part between two points.
330 *
331 * Must be a value above \c 2.
332 * The default value is \c 10.
333 */
334
335void QSpline3DSeries::setSplineResolution(int resolution)
336{
337 Q_D(QSpline3DSeries);
338 if (resolution < 2) {
339 qCWarning(lcProperties3D, "%s invalid resolution. The resolution must be 2 or above",
340 qUtf8Printable(QLatin1String(__FUNCTION__)));
341 return;
342 } else if (d->m_resolution == resolution) {
343 qCDebug(lcProperties3D, "%s value is already set to: %d",
344 qUtf8Printable(QLatin1String(__FUNCTION__)), resolution);
345 return;
346 }
347 d->m_resolution = resolution;
348 emit splineResolutionChanged(resolution);
349}
350
351int QSpline3DSeries::splineResolution() const
352{
353 const Q_D(QSpline3DSeries);
354 return d->m_resolution;
355}
356
357// QSpline3DSeriesPrivate
358
359QSpline3DSeriesPrivate::QSpline3DSeriesPrivate()
360 : QScatter3DSeriesPrivate()
361{}
362
363QSpline3DSeriesPrivate::~QSpline3DSeriesPrivate() {}
364
365QT_END_NAMESPACE
366

source code of qtgraphs/src/graphs3d/data/qspline3dseries.cpp