summaryrefslogtreecommitdiffstats
path: root/examples/bars/doc/src/bars.qdoc
blob: 9c80b8044b38d485ca0ae7be91089642cd40e726 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/****************************************************************************
**
** 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 bars
    \title Bars Example
    \ingroup qtdatavisualization_examples
    \brief Using Q3DBars in a widget application.

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

    \list
        \li Create an application with Q3DBars and some widgets
        \li Use QBar3DSeries and QBarDataProxy to set data to the graph
        \li Adjust some graph and series properties using widget controls
    \endlist

    It also demonstrates how having negative bar values affects the graph.

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

    \image bars-example.png

    \section1 Creating the application

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

    \snippet ../examples/bars/main.cpp 0

    The call to QWidget::createWindowContainer is required, as all data visualization types
    (Q3DBars, Q3DScatter, 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 ../examples/bars/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 GraphModifier (See \l {Setting up the graph} and
    \l {Adding data to the graph} for details):

    \snippet ../examples/bars/main.cpp 2

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

    \snippet ../examples/bars/main.cpp 3

    \section1 Setting up the graph

    Let's set up the graph in the constructor of the \c GraphModifier class we instantiated in the
    application main:

    \snippet ../examples/bars/graphmodifier.cpp 0

    Let's take a closer look at parts of the code.

    First we're creating the axes and the series into member variables to support changing them
    easily later on, if we want to:

    \snippet ../examples/bars/graphmodifier.cpp 1

    Then we're setting some of the visual qualities for the graph:

    \snippet ../examples/bars/graphmodifier.cpp 2

    We're also setting up the axes and setting them to the graph as active axes:

    \snippet ../examples/bars/graphmodifier.cpp 3

    Next we initialize the visual properties of the series.
    Note that the second series is initially not visible:

    \snippet ../examples/bars/graphmodifier.cpp 8

    The series need to be added to the graph to show them:

    \snippet ../examples/bars/graphmodifier.cpp 4

    Finally, we set the camera angle by calling the same method the camera angle change button
    in the UI uses to cycle through various camera angles:

    \snippet ../examples/bars/graphmodifier.cpp 6

    There you can see that the camera is controlled via the scene object of the graph:

    \snippet ../examples/bars/graphmodifier.cpp 10

    For more information about using scene and cameras, see Q3DScene and Q3DCamera.

    That concludes setting up the graph.

    \section1 Adding data to the graph

    At the end of the constructor there's a call:

    \snippet ../examples/bars/graphmodifier.cpp 9

    This method is used to add data to the proxies of the two series:

    \snippet ../examples/bars/graphmodifier.cpp 5

    Now the series have data to show.

    \section1 Using widgets to control the graph

    There isn't much interaction yet, so let's continue by adding some widgets back in the
    application main. Let's just focus on two as an example:

    \snippet ../examples/bars/main.cpp 4

    We can use these slider widgets to rotate the graph instead of just using the mouse or
    touch.

    Let's add them to the vertical layout we created earlier:

    \snippet ../examples/bars/main.cpp 5

    Then we'll connect them to methods in \c GraphModifier:

    \snippet ../examples/bars/main.cpp 6

    Here are the methods in \c GraphModifier the signals were connected to. The camera
    is controlled via the scene object. This time we specify the actual camera position
    along the orbit around the center point, instead of specifying a preset camera angle:

    \snippet ../examples/bars/graphmodifier.cpp 7

    Now these two sliders can be used to rotate the graph.

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

    \list
        \li Graph rotation
        \li Label style
        \li Camera preset
        \li Background visibility
        \li Grid visibility
        \li Bar shading smoothness
        \li Visibility of the second bar series
        \li Bar style
        \li Selection mode
        \li Theme
        \li Shadow quality
        \li Font
        \li Font size
    \endlist

    \section1 Example contents

*/