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 "surfacegraph.h"
31#include "topographicseries.h"
32
33#include <QtDataVisualization/QValue3DAxis>
34#include <QtDataVisualization/Q3DTheme>
35
36using namespace QtDataVisualization;
37
38const float areaWidth = 8000.0f;
39const float areaHeight = 8000.0f;
40const float aspectRatio = 0.1389f;
41const float minRange = areaWidth * 0.49f;
42
43SurfaceGraph::SurfaceGraph(Q3DSurface *surface)
44 : m_graph(surface)
45{
46 m_graph->setAxisX(new QValue3DAxis);
47 m_graph->setAxisY(new QValue3DAxis);
48 m_graph->setAxisZ(new QValue3DAxis);
49 m_graph->axisX()->setLabelFormat("%i");
50 m_graph->axisZ()->setLabelFormat("%i");
51 m_graph->axisX()->setRange(min: 0.0f, max: areaWidth);
52 m_graph->axisY()->setRange(min: 100.0f, max: areaWidth * aspectRatio);
53 m_graph->axisZ()->setRange(min: 0.0f, max: areaHeight);
54 m_graph->axisX()->setLabelAutoRotation(30);
55 m_graph->axisY()->setLabelAutoRotation(90);
56 m_graph->axisZ()->setLabelAutoRotation(30);
57 m_graph->activeTheme()->setType(Q3DTheme::ThemePrimaryColors);
58
59 QFont font = m_graph->activeTheme()->font();
60 font.setPointSize(20);
61 m_graph->activeTheme()->setFont(font);
62
63 m_topography = new TopographicSeries();
64 m_topography->setTopographyFile(file: ":/maps/topography", width: areaWidth, height: areaHeight);
65 m_topography->setItemLabelFormat(QStringLiteral("@yLabel m"));
66
67 m_highlight = new HighlightSeries();
68 m_highlight->setTopographicSeries(m_topography);
69 m_highlight->setMinHeight(minRange * aspectRatio);
70 m_highlight->handleGradientChange(value: areaWidth * aspectRatio);
71//! [1]
72 QObject::connect(sender: m_graph->axisY(), signal: &QValue3DAxis::maxChanged,
73 receiver: m_highlight, slot: &HighlightSeries::handleGradientChange);
74//! [1]
75
76 m_graph->addSeries(series: m_topography);
77 m_graph->addSeries(series: m_highlight);
78
79 m_inputHandler = new CustomInputHandler(m_graph);
80 m_inputHandler->setHighlightSeries(m_highlight);
81 m_inputHandler->setAxes(axisX: m_graph->axisX(), axisY: m_graph->axisY(), axisZ: m_graph->axisZ());
82 m_inputHandler->setLimits(min: 0.0f, max: areaWidth, minRange);
83 m_inputHandler->setAspectRatio(aspectRatio);
84
85 m_graph->setActiveInputHandler(m_inputHandler);
86}
87
88SurfaceGraph::~SurfaceGraph()
89{
90 delete m_graph;
91}
92
93//! [0]
94void SurfaceGraph::toggleSurfaceTexture(bool enable)
95{
96 if (enable)
97 m_topography->setTextureFile(":/maps/maptexture");
98 else
99 m_topography->setTextureFile("");
100}
101//! [0]
102

source code of qtdatavis3d/examples/datavisualization/texturesurface/surfacegraph.cpp