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

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