summaryrefslogtreecommitdiffstats
path: root/examples/surface/doc/src/surface.qdoc
blob: 4a0ce7943ce16bde446b470acd9118a80ff4577c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
** This file is part of the QtDataVisualization module.
**
** Licensees holding valid Qt Enterprise licenses may use this file in
** accordance with the Qt Enterprise License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.digia.com
**
****************************************************************************/

/*!
    \example surface
    \title Surface Example
    \ingroup qtdatavisualization_examples
    \brief Using Q3DSurface in a widget application.

    The surface example shows how to make a simple 3D surface graph using Q3DSurface and
    combining the use of widgets for adjusting several adjustable qualities. This example
    demonstrates the following features:

    \list
        \li How to set up a basic QSurfaceDataProxy and set data for it.
        \li How to use QHeightMapSurfaceDataProxy for showing 3D height maps.
        \li Three different selection modes for studying the graph.
        \li Axis range usage for selecting slices from the graph.
        \li Theme usage on the surface graph.
        \li How to set a custom surface gradient.
    \endlist
    \image surface-example.png

    \section1 Setting up proxies and setting the data

    First we instantiate a new QSurfaceDataProxy:

    \snippet ../examples/surface/surfacegraph.cpp 0

    Then we fill it with a simple square root and sin wave data. This is done by
    creating a new QSurfaceDataArray instance and adding QSurfaceDataRow elements.
    The created QSurfaceDataArray is set to be a the data array for the QSurfaceDataProxy.

    \snippet ../examples/surface/surfacegraph.cpp 1

    The height map is created by instantiating a QHeightMapSurfaceDataProxy with
    a QImage containing the height data. The method setValueRanges is used to define
    the value range of the map. In our example the map is from imaginary position of
    34.0\unicode 0x00B0 N - 40.0\unicode 0x00B0 N and 18.0\unicode 0x00B0 E - 24.0\unicode 0x00B0 E.
    These values are used to show and position the map to the axis.

    \snippet ../examples/surface/surfacegraph.cpp 2

    For demonstrating different proxies this example has two radio buttons which
    the user can use to switch between active proxies. When the user selects the
    Sqrt&Sin radio button the selected proxy is activated with the following
    code. First we set the decorative issues like enable the grid for the surface and
    select the flat surface mode. Next lines define the axis label format and value
    ranges. Since the algorithm studies the value variation between -8.0 and 8.0 we
    set these values for X and Z coordinates. The value itself varies between 0.0 and
    2.0. The method setActiveDataProxy sets the basic data proxy to be active.

    \snippet ../examples/surface/surfacegraph.cpp 3

    When the Height Map radio button is activated, the following code sets the proxy on.
    First the surface grid is turned off and the smooth mode is activated. The axis label
    format is set to show N and E letters and ranges are set to the imaginary coordinates.
    Finally the height map proxy is set to be active.

    \snippet ../examples/surface/surfacegraph.cpp 4

    \section1 Selection modes

    Q3Dsurface supports three different selection modes and these are demonstrated on the
    example with radio buttons which the user can use to activate suitable selection mode.
    Following inline methods are connected to radio buttons to activate the selected mode.

    \snippet ../examples/surface/surfacegraph.h 0

    \section1 Axis ranges for studying the graph

    The example has four slider controls for adjusting the min and max values for X and Z
    axis. When selecting the proxy these sliders are adjusted so that one step on the slider
    moves the range by one segment step. The example has some code to keep the sliders on
    valid positions, like when the X axis minimum exceeds the maximum the maximum is increased
    and so on. Finally the ranges are set for the graph like this:

    \snippet ../examples/surface/surfacegraph.cpp 5

    \section1 Themes

    Q3Dsurface supports all the themes QtDatavisualization has. The example has a pull
    down menu for selecting the theme and the following code snippet is connected to the menu to
    activate the selected theme.

    \snippet ../examples/surface/surfacegraph.cpp 6

    \section1 Custom surface gradients

    The example demonstrates the custom surface gradients with two push buttons. The gradient
    can be defined with QLinearGradient where the desired colors are set to positions. Following
    snippet shows how to create an example gradient and set it to the graph.

    \snippet ../examples/surface/surfacegraph.cpp 7
*/