1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "declarativesurface_p.h"
5#include <QtCore/QMutexLocker>
6
7QT_BEGIN_NAMESPACE
8
9DeclarativeSurface::DeclarativeSurface(QQuickItem *parent)
10 : AbstractDeclarative(parent),
11 m_surfaceController(0)
12{
13 setAcceptedMouseButtons(Qt::AllButtons);
14
15 // Create the shared component on the main GUI thread.
16 m_surfaceController = new Surface3DController(boundingRect().toRect(), new Declarative3DScene);
17 setSharedController(m_surfaceController);
18
19 QObject::connect(sender: m_surfaceController, signal: &Surface3DController::selectedSeriesChanged,
20 context: this, slot: &DeclarativeSurface::selectedSeriesChanged);
21 QObject::connect(sender: m_surfaceController, signal: &Surface3DController::flipHorizontalGridChanged,
22 context: this, slot: &DeclarativeSurface::flipHorizontalGridChanged);
23}
24
25DeclarativeSurface::~DeclarativeSurface()
26{
27 QMutexLocker locker(m_nodeMutex.data());
28 const QMutexLocker locker2(mutex());
29 delete m_surfaceController;
30}
31
32QValue3DAxis *DeclarativeSurface::axisX() const
33{
34 return static_cast<QValue3DAxis *>(m_surfaceController->axisX());
35}
36
37void DeclarativeSurface::setAxisX(QValue3DAxis *axis)
38{
39 m_surfaceController->setAxisX(axis);
40}
41
42QValue3DAxis *DeclarativeSurface::axisY() const
43{
44 return static_cast<QValue3DAxis *>(m_surfaceController->axisY());
45}
46
47void DeclarativeSurface::setAxisY(QValue3DAxis *axis)
48{
49 m_surfaceController->setAxisY(axis);
50}
51
52QValue3DAxis *DeclarativeSurface::axisZ() const
53{
54 return static_cast<QValue3DAxis *>(m_surfaceController->axisZ());
55}
56
57void DeclarativeSurface::setAxisZ(QValue3DAxis *axis)
58{
59 m_surfaceController->setAxisZ(axis);
60}
61
62QSurface3DSeries *DeclarativeSurface::selectedSeries() const
63{
64 return m_surfaceController->selectedSeries();
65}
66
67void DeclarativeSurface::setFlipHorizontalGrid(bool flip)
68{
69 m_surfaceController->setFlipHorizontalGrid(flip);
70}
71
72bool DeclarativeSurface::flipHorizontalGrid() const
73{
74 return m_surfaceController->flipHorizontalGrid();
75}
76
77QQmlListProperty<QSurface3DSeries> DeclarativeSurface::seriesList()
78{
79 return QQmlListProperty<QSurface3DSeries>(this, this,
80 &DeclarativeSurface::appendSeriesFunc,
81 &DeclarativeSurface::countSeriesFunc,
82 &DeclarativeSurface::atSeriesFunc,
83 &DeclarativeSurface::clearSeriesFunc);
84}
85
86void DeclarativeSurface::appendSeriesFunc(QQmlListProperty<QSurface3DSeries> *list,
87 QSurface3DSeries *series)
88{
89 reinterpret_cast<DeclarativeSurface *>(list->data)->addSeries(series);
90}
91
92qsizetype DeclarativeSurface::countSeriesFunc(QQmlListProperty<QSurface3DSeries> *list)
93{
94 return reinterpret_cast<DeclarativeSurface *>(list->data)->m_surfaceController->surfaceSeriesList().size();
95}
96
97QSurface3DSeries *DeclarativeSurface::atSeriesFunc(QQmlListProperty<QSurface3DSeries> *list,
98 qsizetype index)
99{
100 return reinterpret_cast<DeclarativeSurface *>(list->data)->m_surfaceController->surfaceSeriesList().at(i: index);
101}
102
103void DeclarativeSurface::clearSeriesFunc(QQmlListProperty<QSurface3DSeries> *list)
104{
105 DeclarativeSurface *declSurface = reinterpret_cast<DeclarativeSurface *>(list->data);
106 QList<QSurface3DSeries *> realList = declSurface->m_surfaceController->surfaceSeriesList();
107 int count = realList.size();
108 for (int i = 0; i < count; i++)
109 declSurface->removeSeries(series: realList.at(i));
110}
111
112void DeclarativeSurface::addSeries(QSurface3DSeries *series)
113{
114 m_surfaceController->addSeries(series);
115}
116
117void DeclarativeSurface::removeSeries(QSurface3DSeries *series)
118{
119 m_surfaceController->removeSeries(series);
120 series->setParent(this); // Reparent as removing will leave series parentless
121}
122
123void DeclarativeSurface::handleAxisXChanged(QAbstract3DAxis *axis)
124{
125 emit axisXChanged(axis: static_cast<QValue3DAxis *>(axis));
126}
127
128void DeclarativeSurface::handleAxisYChanged(QAbstract3DAxis *axis)
129{
130 emit axisYChanged(axis: static_cast<QValue3DAxis *>(axis));
131}
132
133void DeclarativeSurface::handleAxisZChanged(QAbstract3DAxis *axis)
134{
135 emit axisZChanged(axis: static_cast<QValue3DAxis *>(axis));
136}
137
138QT_END_NAMESPACE
139

source code of qtdatavis3d/src/datavisualizationqml/declarativesurface.cpp