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 "data.h"
31
32#include <QtCore/QRandomGenerator>
33#include <QtDataVisualization/QScatterDataProxy>
34#include <QtDataVisualization/Q3DScene>
35#include <QtDataVisualization/Q3DCamera>
36#include <QtDataVisualization/QScatter3DSeries>
37#include <QtDataVisualization/Q3DTheme>
38
39using namespace QtDataVisualization;
40
41const int itemCount = 500;
42
43Data::Data(Q3DScatter *scatter)
44 : m_graph(scatter),
45 //! [1]
46 m_inputHandler(new AxesInputHandler(scatter)),
47 //! [1]
48 m_autoAdjust(false)
49{
50 m_graph->activeTheme()->setType(Q3DTheme::ThemeEbony);
51 m_graph->activeTheme()->setLabelBorderEnabled(true);
52 m_graph->activeTheme()->setLabelBackgroundColor(QColor(QRgb(0x151550)));
53 m_graph->activeTheme()->setLabelTextColor(Qt::lightGray);
54 m_graph->activeTheme()->setFont(QFont("Arial Black", 30));
55 m_graph->setShadowQuality(QAbstract3DGraph::ShadowQualityMedium);
56 m_graph->scene()->activeCamera()->setCameraPreset(Q3DCamera::CameraPresetIsometricRight);
57
58 m_graph->axisX()->setRange(min: -20.0f, max: 20.0f);
59 m_graph->axisY()->setRange(min: -10.0f, max: 10.0f);
60 m_graph->axisZ()->setRange(min: -20.0f, max: 20.0f);
61
62 //! [0]
63 // Give ownership of the handler to the graph and make it the active handler
64 m_graph->setActiveInputHandler(m_inputHandler);
65 //! [0]
66
67 //! [2]
68 // Give our axes to the input handler
69 m_inputHandler->setAxes(axisX: m_graph->axisX(), axisZ: m_graph->axisZ(), axisY: m_graph->axisY());
70 //! [2]
71
72 addData();
73}
74
75Data::~Data()
76{
77 delete m_graph;
78}
79
80void Data::toggleRanges()
81{
82 if (!m_autoAdjust) {
83 m_graph->axisX()->setAutoAdjustRange(true);
84 m_graph->axisZ()->setAutoAdjustRange(true);
85 m_graph->axisY()->setAutoAdjustRange(true);
86 m_inputHandler->setDragSpeedModifier(1.5f);
87 m_autoAdjust = true;
88 } else {
89 m_graph->axisX()->setRange(min: -20.0f, max: 20.0f);
90 m_graph->axisY()->setRange(min: -10.0f, max: 10.0f);
91 m_graph->axisZ()->setRange(min: -20.0f, max: 20.0f);
92 m_inputHandler->setDragSpeedModifier(15.0f);
93 m_autoAdjust = false;
94 }
95}
96
97void Data::addData()
98{
99 QScatter3DSeries *series = new QScatter3DSeries;
100 series->setMesh(QAbstract3DSeries::MeshCube);
101 series->setMeshSmooth(true);
102 m_graph->addSeries(series);
103
104 QScatter3DSeries *series2 = new QScatter3DSeries;
105 series2->setMesh(QAbstract3DSeries::MeshMinimal);
106 series2->setMeshSmooth(true);
107 m_graph->addSeries(series: series2);
108
109 QScatter3DSeries *series3 = new QScatter3DSeries;
110 series3->setMesh(QAbstract3DSeries::MeshSphere);
111 series3->setMeshSmooth(true);
112 m_graph->addSeries(series: series3);
113
114 QScatter3DSeries *series4 = new QScatter3DSeries;
115 series4->setMesh(QAbstract3DSeries::MeshBevelCube);
116 series4->setMeshSmooth(true);
117 m_graph->addSeries(series: series4);
118
119 QScatter3DSeries *series5 = new QScatter3DSeries;
120 series5->setMesh(QAbstract3DSeries::MeshSphere);
121 m_graph->addSeries(series: series5);
122
123 QScatterDataArray *dataArray = new QScatterDataArray;
124 dataArray->resize(asize: itemCount);
125 QScatterDataItem *ptrToDataArray = &dataArray->first();
126 for (int i = 0; i < itemCount; i++) {
127 ptrToDataArray->setPosition(randVector());
128 ptrToDataArray++;
129 }
130 QScatterDataArray *dataArray2 = new QScatterDataArray;
131 dataArray2->resize(asize: itemCount);
132 ptrToDataArray = &dataArray2->first();
133 for (int i = 0; i < itemCount; i++) {
134 ptrToDataArray->setPosition(randVector());
135 ptrToDataArray++;
136 }
137 QScatterDataArray *dataArray3 = new QScatterDataArray;
138 dataArray3->resize(asize: itemCount);
139 ptrToDataArray = &dataArray3->first();
140 for (int i = 0; i < itemCount; i++) {
141 ptrToDataArray->setPosition(randVector());
142 ptrToDataArray++;
143 }
144 QScatterDataArray *dataArray4 = new QScatterDataArray;
145 dataArray4->resize(asize: itemCount);
146 ptrToDataArray = &dataArray4->first();
147 for (int i = 0; i < itemCount; i++) {
148 ptrToDataArray->setPosition(randVector());
149 ptrToDataArray++;
150 }
151 QScatterDataArray *dataArray5 = new QScatterDataArray;
152 dataArray5->resize(asize: itemCount);
153 ptrToDataArray = &dataArray5->first();
154 for (int i = 0; i < itemCount; i++) {
155 ptrToDataArray->setPosition(randVector());
156 ptrToDataArray++;
157 }
158
159 m_graph->seriesList().at(i: 0)->dataProxy()->resetArray(newArray: dataArray);
160 m_graph->seriesList().at(i: 1)->dataProxy()->resetArray(newArray: dataArray2);
161 m_graph->seriesList().at(i: 2)->dataProxy()->resetArray(newArray: dataArray3);
162 m_graph->seriesList().at(i: 3)->dataProxy()->resetArray(newArray: dataArray4);
163 m_graph->seriesList().at(i: 4)->dataProxy()->resetArray(newArray: dataArray5);
164}
165
166QVector3D Data::randVector()
167{
168 return QVector3D(
169 (float)(QRandomGenerator::global()->bounded(highest: 100)) / 2.0f -
170 (float)(QRandomGenerator::global()->bounded(highest: 100)) / 2.0f,
171 (float)(QRandomGenerator::global()->bounded(highest: 100)) / 2.0f -
172 (float)(QRandomGenerator::global()->bounded(highest: 100)) / 2.0f,
173 (float)(QRandomGenerator::global()->bounded(highest: 100)) / 2.0f -
174 (float)(QRandomGenerator::global()->bounded(highest: 100)) / 2.0f);
175}
176

source code of qtdatavis3d/examples/datavisualization/draggableaxes/data.cpp