1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Data Visualization module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30#include "declarativesurface_p.h"
31#include <QtCore/QMutexLocker>
32
33QT_BEGIN_NAMESPACE_DATAVISUALIZATION
34
35DeclarativeSurface::DeclarativeSurface(QQuickItem *parent)
36 : AbstractDeclarative(parent),
37 m_surfaceController(0)
38{
39 setAcceptedMouseButtons(Qt::AllButtons);
40
41 // Create the shared component on the main GUI thread.
42 m_surfaceController = new Surface3DController(boundingRect().toRect(), new Declarative3DScene);
43 setSharedController(m_surfaceController);
44
45 QObject::connect(m_surfaceController, &Surface3DController::selectedSeriesChanged,
46 this, &DeclarativeSurface::selectedSeriesChanged);
47 QObject::connect(m_surfaceController, &Surface3DController::flipHorizontalGridChanged,
48 this, &DeclarativeSurface::flipHorizontalGridChanged);
49}
50
51DeclarativeSurface::~DeclarativeSurface()
52{
53 QMutexLocker locker(m_nodeMutex.data());
54 const QMutexLocker locker2(mutex());
55 delete m_surfaceController;
56}
57
58QValue3DAxis *DeclarativeSurface::axisX() const
59{
60 return static_cast<QValue3DAxis *>(m_surfaceController->axisX());
61}
62
63void DeclarativeSurface::setAxisX(QValue3DAxis *axis)
64{
65 m_surfaceController->setAxisX(axis);
66}
67
68QValue3DAxis *DeclarativeSurface::axisY() const
69{
70 return static_cast<QValue3DAxis *>(m_surfaceController->axisY());
71}
72
73void DeclarativeSurface::setAxisY(QValue3DAxis *axis)
74{
75 m_surfaceController->setAxisY(axis);
76}
77
78QValue3DAxis *DeclarativeSurface::axisZ() const
79{
80 return static_cast<QValue3DAxis *>(m_surfaceController->axisZ());
81}
82
83void DeclarativeSurface::setAxisZ(QValue3DAxis *axis)
84{
85 m_surfaceController->setAxisZ(axis);
86}
87
88QSurface3DSeries *DeclarativeSurface::selectedSeries() const
89{
90 return m_surfaceController->selectedSeries();
91}
92
93void DeclarativeSurface::setFlipHorizontalGrid(bool flip)
94{
95 m_surfaceController->setFlipHorizontalGrid(flip);
96}
97
98bool DeclarativeSurface::flipHorizontalGrid() const
99{
100 return m_surfaceController->flipHorizontalGrid();
101}
102
103QQmlListProperty<QSurface3DSeries> DeclarativeSurface::seriesList()
104{
105 return QQmlListProperty<QSurface3DSeries>(this, this,
106 &DeclarativeSurface::appendSeriesFunc,
107 &DeclarativeSurface::countSeriesFunc,
108 &DeclarativeSurface::atSeriesFunc,
109 &DeclarativeSurface::clearSeriesFunc);
110}
111
112void DeclarativeSurface::appendSeriesFunc(QQmlListProperty<QSurface3DSeries> *list,
113 QSurface3DSeries *series)
114{
115 reinterpret_cast<DeclarativeSurface *>(list->data)->addSeries(series);
116}
117
118int DeclarativeSurface::countSeriesFunc(QQmlListProperty<QSurface3DSeries> *list)
119{
120 return reinterpret_cast<DeclarativeSurface *>(list->data)->m_surfaceController->surfaceSeriesList().size();
121}
122
123QSurface3DSeries *DeclarativeSurface::atSeriesFunc(QQmlListProperty<QSurface3DSeries> *list, int index)
124{
125 return reinterpret_cast<DeclarativeSurface *>(list->data)->m_surfaceController->surfaceSeriesList().at(index);
126}
127
128void DeclarativeSurface::clearSeriesFunc(QQmlListProperty<QSurface3DSeries> *list)
129{
130 DeclarativeSurface *declSurface = reinterpret_cast<DeclarativeSurface *>(list->data);
131 QList<QSurface3DSeries *> realList = declSurface->m_surfaceController->surfaceSeriesList();
132 int count = realList.size();
133 for (int i = 0; i < count; i++)
134 declSurface->removeSeries(realList.at(i));
135}
136
137void DeclarativeSurface::addSeries(QSurface3DSeries *series)
138{
139 m_surfaceController->addSeries(series);
140}
141
142void DeclarativeSurface::removeSeries(QSurface3DSeries *series)
143{
144 m_surfaceController->removeSeries(series);
145 series->setParent(this); // Reparent as removing will leave series parentless
146}
147
148void DeclarativeSurface::handleAxisXChanged(QAbstract3DAxis *axis)
149{
150 emit axisXChanged(static_cast<QValue3DAxis *>(axis));
151}
152
153void DeclarativeSurface::handleAxisYChanged(QAbstract3DAxis *axis)
154{
155 emit axisYChanged(static_cast<QValue3DAxis *>(axis));
156}
157
158void DeclarativeSurface::handleAxisZChanged(QAbstract3DAxis *axis)
159{
160 emit axisZChanged(static_cast<QValue3DAxis *>(axis));
161}
162
163QT_END_NAMESPACE_DATAVISUALIZATION
164