1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "qquickgraphssurfacenode_p.h"
QT_BEGIN_NAMESPACE
/*!
* \qmltype Surface3DNode
* \inherits GraphsNode
* \inqmlmodule QtGraphs
* \ingroup graphs_qml_3D
* \brief Describes the usage of the 3D surface graph node.
*
* This type enables developers to render a surface graph node in 3D with Qt Quick.
*
* You will need to import the Qt Graphs module to use this type:
*
* \snippet doc_src_qmlnodes.qml 0
*
* After that you can use Surface3DNode in your qml files:
*
* \snippet doc_src_qmlnodes.qml 3
*
*
* \sa Surface3DSeries, ItemModelSurfaceDataProxy, Bars3DNode, Scatter3DNode,
* {Qt Graphs C++ Classes for 3D}
*/
/*!
* \qmlproperty Value3DAxis Surface3DNode::axisX
* The active x-axis.
*
* If an axis is not given, a temporary default axis with no labels and an
* automatically adjusting range is created.
* This temporary axis is destroyed if another axis is explicitly set to the
* same orientation.
*/
/*!
* \qmlproperty Value3DAxis Surface3DNode::axisY
* The active y-axis.
*
* If an axis is not given, a temporary default axis with no labels and an
* automatically adjusting range is created.
* This temporary axis is destroyed if another axis is explicitly set to the
* same orientation.
*/
/*!
* \qmlproperty Value3DAxis Surface3DNode::axisZ
* The active z-axis.
*
* If an axis is not given, a temporary default axis with no labels and an
* automatically adjusting range is created.
* This temporary axis is destroyed if another axis is explicitly set to the
* same orientation.
*/
/*!
* \qmlproperty Surface3DSeries Surface3DNode::selectedSeries
* \readonly
*
* The selected series or null. If \l {GraphsNode::selectionMode}{selectionMode}
* has the \c MultiSeries flag set, this property holds the series
* which owns the selected point.
*/
/*!
* \qmlproperty list<Surface3DSeries> Surface3DNode::seriesList
* \qmldefault
* This property holds the series of the graph.
* By default, this property contains an empty list.
* To set the series, either use the addSeries() function or define them as
* children of the graph.
*/
/*!
* \qmlproperty bool Surface3DNode::flipHorizontalGrid
*
* In some use cases the horizontal axis grid is mostly covered by the surface,
* so it can be more useful to display the horizontal axis grid on top of the
* graph rather than on the bottom. A typical use case for this is showing 2D
* spectrograms using orthoGraphic projection with a top-down viewpoint.
*
* If \c{false}, the horizontal axis grid and labels are drawn on the horizontal
* background of the graph.
* If \c{true}, the horizontal axis grid and labels are drawn on the opposite
* side of the graph from the horizontal background.
* Defaults to \c{false}.
*/
/*!
* \qmlmethod void Surface3DNode::addSeries(Surface3DSeries series)
* Adds the \a series to the graph.
* \sa GraphsNode::hasSeries()
*/
/*!
* \qmlmethod void Surface3DNode::removeSeries(Surface3DSeries series)
* Removes the \a series from the graph.
* \sa GraphsNode::hasSeries()
*/
/*!
* \qmlsignal Surface3DNode::axisXChanged(ValueAxis3D axis)
*
* This signal is emitted when axisX changes to \a axis.
*/
/*!
* \qmlsignal Surface3DNode::axisYChanged(ValueAxis3D axis)
*
* This signal is emitted when axisY changes to \a axis.
*/
/*!
* \qmlsignal Surface3DNode::axisZChanged(ValueAxis3D axis)
*
* This signal is emitted when axisZ changes to \a axis.
*/
/*!
* \qmlsignal Surface3DNode::selectedSeriesChanged(Surface3DSeries series)
*
* This signal is emitted when selectedSeries changes to \a series.
*/
/*!
* \qmlsignal Surface3DNode::flipHorizontalGridChanged(bool flip)
*
* This signal is emitted when flipHorizontalGrid changes to \a flip.
*/
QQuickGraphsSurfaceNode::QQuickGraphsSurfaceNode(QQuick3DNode *parent)
: QQuickGraphsNode(parent)
, m_flipHorizontalGrid(false)
{}
QQuickGraphsSurfaceNode::~QQuickGraphsSurfaceNode() {}
void QQuickGraphsSurfaceNode::componentComplete()
{
const QString qmlData = QLatin1StringView(R"QML(
import QtQuick;
import QtGraphs;
Surface3D{}
)QML");
QQmlComponent *component = new QQmlComponent(qmlEngine(this), this);
component->setData(qmlData.toUtf8(), QUrl());
m_graph.reset(qobject_cast<QQuickGraphsItem *>(component->create()));
setGraphParent();
QQuickGraphsNode::componentComplete();
//initialize components
if (m_axisX)
graphSurface()->setAxisX(static_cast<QValue3DAxis *>(m_axisX));
if (m_axisY)
graphSurface()->setAxisY(static_cast<QValue3DAxis *>(m_axisY));
if (m_axisZ)
graphSurface()->setAxisZ(static_cast<QValue3DAxis *>(m_axisZ));
graphSurface()->setSelectionMode(m_selectionMode);
graphSurface()->setFlipHorizontalGrid(m_flipHorizontalGrid);
for (auto series : m_seriesList)
graphSurface()->addSeries(static_cast<QSurface3DSeries *>(series));
//connect signals
connect(graphSurface(),
&QQuickGraphsSurface::axisXChanged,
this,
&QQuickGraphsSurfaceNode::axisXChanged);
connect(graphSurface(),
&QQuickGraphsSurface::axisYChanged,
this,
&QQuickGraphsSurfaceNode::axisYChanged);
connect(graphSurface(),
&QQuickGraphsSurface::axisZChanged,
this,
&QQuickGraphsSurfaceNode::axisZChanged);
connect(graphSurface(),
&QQuickGraphsSurface::flipHorizontalGridChanged,
this,
&QQuickGraphsSurfaceNode::flipHorizontalGridChanged);
}
QValue3DAxis *QQuickGraphsSurfaceNode::axisX() const
{
if (graphSurface())
return graphSurface()->axisX();
else
return static_cast<QValue3DAxis *>(m_axisX);
}
void QQuickGraphsSurfaceNode::setAxisX(QValue3DAxis *axis)
{
if (m_axisX == axis)
return;
m_axisX = axis;
if (graphSurface())
graphSurface()->setAxisX(axis);
}
QValue3DAxis *QQuickGraphsSurfaceNode::axisY() const
{
if (graphSurface())
return graphSurface()->axisY();
else
return static_cast<QValue3DAxis *>(m_axisY);
}
void QQuickGraphsSurfaceNode::setAxisY(QValue3DAxis *axis)
{
if (m_axisY == axis)
return;
m_axisY = axis;
if (graphSurface())
graphSurface()->setAxisY(axis);
}
QValue3DAxis *QQuickGraphsSurfaceNode::axisZ() const
{
if (graphSurface())
return graphSurface()->axisZ();
else
return static_cast<QValue3DAxis *>(m_axisZ);
}
void QQuickGraphsSurfaceNode::setAxisZ(QValue3DAxis *axis)
{
if (m_axisZ == axis)
return;
m_axisZ = axis;
if (graphSurface())
graphSurface()->setAxisZ(axis);
}
QSurface3DSeries *QQuickGraphsSurfaceNode::selectedSeries() const
{
if (graphSurface())
return graphSurface()->selectedSeries();
else
return nullptr;
}
void QQuickGraphsSurfaceNode::setSelectionMode(QtGraphs3D::SelectionFlags mode)
{
if (graphSurface())
graphSurface()->setSelectionMode(mode);
else
setSelectionMode(mode);
}
bool QQuickGraphsSurfaceNode::flipHorizontalGrid() const
{
if (graphSurface())
return graphSurface()->flipHorizontalGrid();
else
return m_flipHorizontalGrid;
}
void QQuickGraphsSurfaceNode::setFlipHorizontalGrid(bool flip)
{
if (m_flipHorizontalGrid == flip)
return;
m_flipHorizontalGrid = flip;
if (graphSurface())
graphSurface()->setFlipHorizontalGrid(flip);
}
QList<QSurface3DSeries *> QQuickGraphsSurfaceNode::surfaceSeriesList()
{
if (graphSurface()) {
return graphSurface()->surfaceSeriesList();
} else {
QList<QSurface3DSeries *> surfaceSeriesList;
for (QAbstract3DSeries *abstractSeries : m_seriesList) {
QSurface3DSeries *surfaceSeries = qobject_cast<QSurface3DSeries *>(abstractSeries);
if (surfaceSeries)
surfaceSeriesList.append(surfaceSeries);
}
return surfaceSeriesList;
}
}
QQmlListProperty<QSurface3DSeries> QQuickGraphsSurfaceNode::seriesList()
{
if (graphSurface()) {
return graphSurface()->seriesList();
} else {
return QQmlListProperty<QSurface3DSeries>(this,
this,
&QQuickGraphsSurfaceNode::appendSeriesFunc,
&QQuickGraphsSurfaceNode::countSeriesFunc,
&QQuickGraphsSurfaceNode::atSeriesFunc,
&QQuickGraphsSurfaceNode::clearSeriesFunc);
}
}
void QQuickGraphsSurfaceNode::appendSeriesFunc(QQmlListProperty<QSurface3DSeries> *list,
QSurface3DSeries *series)
{
reinterpret_cast<QQuickGraphsSurfaceNode *>(list->data)->addSeries(series);
}
qsizetype QQuickGraphsSurfaceNode::countSeriesFunc(QQmlListProperty<QSurface3DSeries> *list)
{
return reinterpret_cast<QQuickGraphsSurfaceNode *>(list->data)->surfaceSeriesList().size();
}
QSurface3DSeries *QQuickGraphsSurfaceNode::atSeriesFunc(QQmlListProperty<QSurface3DSeries> *list,
qsizetype index)
{
return reinterpret_cast<QQuickGraphsSurfaceNode *>(list->data)->surfaceSeriesList().at(index);
}
void QQuickGraphsSurfaceNode::clearSeriesFunc(QQmlListProperty<QSurface3DSeries> *list)
{
QQuickGraphsSurfaceNode *declSurfaceNode = reinterpret_cast<QQuickGraphsSurfaceNode *>(
list->data);
QList<QSurface3DSeries *> realList = declSurfaceNode->surfaceSeriesList();
qsizetype count = realList.size();
for (qsizetype i = 0; i < count; i++)
declSurfaceNode->removeSeries(realList.at(i));
}
void QQuickGraphsSurfaceNode::addSeries(QSurface3DSeries *series)
{
Q_ASSERT(series && series->type() == QAbstract3DSeries::SeriesType::Surface);
if (graphSurface())
graphSurface()->addSeries(series);
QQuickGraphsNode::addSeriesInternal(series);
}
void QQuickGraphsSurfaceNode::removeSeries(QSurface3DSeries *series)
{
if (graphSurface())
graphSurface()->removeSeries(series);
QQuickGraphsNode::removeSeriesInternal(series);
}
void QQuickGraphsSurfaceNode::clearSelection()
{
if (graphSurface())
graphSurface()->clearSelection();
}
bool QQuickGraphsSurfaceNode::doPicking(QPointF point)
{
if (graphSurface())
return graphSurface()->doPicking(point);
else
return false;
}
bool QQuickGraphsSurfaceNode::doRayPicking(const QVector3D &origin, const QVector3D &direction)
{
if (graphSurface())
return graphSurface()->doRayPicking(origin, direction);
else
return false;
}
/*!
* \internal
*/
QQuickGraphsSurface *QQuickGraphsSurfaceNode::graphSurface()
{
return static_cast<QQuickGraphsSurface *>(m_graph.get());
}
/*!
* \internal
*/
const QQuickGraphsSurface *QQuickGraphsSurfaceNode::graphSurface() const
{
return static_cast<QQuickGraphsSurface *>(m_graph.get());
}
QT_END_NAMESPACE
|