summaryrefslogtreecommitdiffstats
path: root/examples/datavisualization/scatter/doc/src/scatter.qdoc
blob: 3c9d72bc5d71a694d4f24d3491695fdb5d0a62a6 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/****************************************************************************
**
** Copyright (C) 2014 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 scatter
    \title Scatter Example
    \ingroup qtdatavisualization_examples
    \brief Using Q3DScatter in a widget application.

    The scatter example shows how to make a simple 3D scatter graph using Q3DScatter and
    combining the use of widgets for adjusting several adjustable qualities. The example shows
    how to:

    \list
        \li Create an application with Q3DScatter and some widgets
        \li Use QScatterDataProxy to set data to the graph
        \li Adjust some graph properties using widget controls
    \endlist

    For instructions about how to interact with the graph, see \l{Qt Data Visualization Interacting with Data}{this page}.

    \image scatter-example.png

    \section1 Creating the application

    First, in main.cpp, we create a QApplication, instantiate Q3DScatter, and a window container
    for it:

    \snippet scatter/main.cpp 0

    The call to QWidget::createWindowContainer is required, as all data visualization types
    (Q3DBars, Q3DScatter, and Q3DSurface) inherit QWindow. Any class inheriting QWindow cannot be used
    as a widget any other way.

    Then we'll create horizontal and vertical layouts. We'll add the graph and the vertical
    layout into the horizontal one:

    \snippet scatter/main.cpp 1

    We're not using the vertical layout for anything yet, but we'll get back to it in
    \l {Using widgets to control the graph}

    Next, let's create another class to handle the data addition and other interaction with the
    graph. Let's call it \c ScatterDataModifier (See \l {Setting up the graph} and
    \l {Adding data to the graph} for details):

    \snippet scatter/main.cpp 2

    The application main is done. We can show the graph and start the event loop:

    \snippet scatter/main.cpp 3

    \section1 Setting up the graph

    Let's set up some visual qualities for the graph in the constructor of the \c ScatterDataModifier
    class we instantiated in the application main:

    \snippet scatter/scatterdatamodifier.cpp 0

    None of these are required, but are used to override graph defaults. You can try how it looks
    with the preset defaults by commenting the block above out.

    Finally we create a QScatterDataProxy and the associated QScatter3DSeries. We set custom label format
    and mesh smoothing for the series and add it to the graph:

    \snippet scatter/scatterdatamodifier.cpp 2

    That concludes setting up the graph.

    \section1 Adding data to the graph

    The last thing we do in the \c ScatterDataModifier constructor is to add data to the graph:

    \snippet scatter/scatterdatamodifier.cpp 3

    The actual data addition is done in \c addData() method. First we configure the axes:

    \snippet scatter/scatterdatamodifier.cpp 4

    This could have been done in the constructor of \c {ScatterDataModifier}, but we added it here
    to keep the constructor simpler and the axes configuration near the data.

    Next we create a data array:

    \snippet scatter/scatterdatamodifier.cpp 5

    and populate it:

    \snippet scatter/scatterdatamodifier.cpp 6

    Finally we tell the proxy to start using the data we gave it:

    \snippet scatter/scatterdatamodifier.cpp 7

    Now our graph has the data and is ready to be used. There isn't much interaction yet, though,
    so let's continue by adding some widgets to play with.

    \section1 Using widgets to control the graph

    First, back in the application main, we'll create some widgets:

    \snippet scatter/main.cpp 4

    And add them to the vertical layout we created earlier:

    \snippet scatter/main.cpp 5

    Now, let's connect them to methods in ScatterDataModifier:

    \snippet scatter/main.cpp 6

    Here are the methods in ScatterDataModifier the signals were connected to:

    \snippet scatter/scatterdatamodifier.cpp 8

    And so we have an application in which we can control:

    \list
        \li Label style
        \li Camera preset
        \li Background visibility
        \li Grid visibility
        \li Dot shading smoothness
        \li Dot style
        \li Theme
        \li Shadow quality
        \li Label font
    \endlist

    \section1 Example contents
*/