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 "graphmodifier.h"
31
32#include <QtWidgets/QApplication>
33#include <QtWidgets/QWidget>
34#include <QtWidgets/QHBoxLayout>
35#include <QtWidgets/QVBoxLayout>
36#include <QtWidgets/QPushButton>
37#include <QtWidgets/QCheckBox>
38#include <QtWidgets/QSlider>
39#include <QtWidgets/QFontComboBox>
40#include <QtWidgets/QLabel>
41#include <QtWidgets/QMessageBox>
42#include <QtGui/QScreen>
43#include <QtGui/QFontDatabase>
44
45int main(int argc, char **argv)
46{
47 //! [0]
48 QApplication app(argc, argv);
49 Q3DBars *widgetgraph = new Q3DBars();
50 QWidget *container = QWidget::createWindowContainer(window: widgetgraph);
51 //! [0]
52
53 if (!widgetgraph->hasContext()) {
54 QMessageBox msgBox;
55 msgBox.setText("Couldn't initialize the OpenGL context.");
56 msgBox.exec();
57 return -1;
58 }
59
60 QSize screenSize = widgetgraph->screen()->size();
61 container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.5));
62 container->setMaximumSize(screenSize);
63 container->setSizePolicy(hor: QSizePolicy::Expanding, ver: QSizePolicy::Expanding);
64 container->setFocusPolicy(Qt::StrongFocus);
65
66 //! [1]
67 QWidget *widget = new QWidget;
68 QHBoxLayout *hLayout = new QHBoxLayout(widget);
69 QVBoxLayout *vLayout = new QVBoxLayout();
70 hLayout->addWidget(container, stretch: 1);
71 hLayout->addLayout(layout: vLayout);
72 //! [1]
73
74 widget->setWindowTitle(QStringLiteral("Average temperatures in Oulu and Helsinki, Finland (2006-2013)"));
75
76 QComboBox *themeList = new QComboBox(widget);
77 themeList->addItem(QStringLiteral("Qt"));
78 themeList->addItem(QStringLiteral("Primary Colors"));
79 themeList->addItem(QStringLiteral("Digia"));
80 themeList->addItem(QStringLiteral("Stone Moss"));
81 themeList->addItem(QStringLiteral("Army Blue"));
82 themeList->addItem(QStringLiteral("Retro"));
83 themeList->addItem(QStringLiteral("Ebony"));
84 themeList->addItem(QStringLiteral("Isabelle"));
85 themeList->setCurrentIndex(0);
86
87 QPushButton *labelButton = new QPushButton(widget);
88 labelButton->setText(QStringLiteral("Change label style"));
89
90 QCheckBox *smoothCheckBox = new QCheckBox(widget);
91 smoothCheckBox->setText(QStringLiteral("Smooth bars"));
92 smoothCheckBox->setChecked(false);
93
94
95 QComboBox *barStyleList = new QComboBox(widget);
96 barStyleList->addItem(QStringLiteral("Bar"), auserData: int(QAbstract3DSeries::MeshBar));
97 barStyleList->addItem(QStringLiteral("Pyramid"), auserData: int(QAbstract3DSeries::MeshPyramid));
98 barStyleList->addItem(QStringLiteral("Cone"), auserData: int(QAbstract3DSeries::MeshCone));
99 barStyleList->addItem(QStringLiteral("Cylinder"), auserData: int(QAbstract3DSeries::MeshCylinder));
100 barStyleList->addItem(QStringLiteral("Bevel bar"), auserData: int(QAbstract3DSeries::MeshBevelBar));
101 barStyleList->addItem(QStringLiteral("Sphere"), auserData: int(QAbstract3DSeries::MeshSphere));
102 barStyleList->setCurrentIndex(4);
103
104 QPushButton *cameraButton = new QPushButton(widget);
105 cameraButton->setText(QStringLiteral("Change camera preset"));
106
107 QPushButton *zoomToSelectedButton = new QPushButton(widget);
108 zoomToSelectedButton->setText(QStringLiteral("Zoom to selected bar"));
109
110 QComboBox *selectionModeList = new QComboBox(widget);
111 selectionModeList->addItem(QStringLiteral("None"),
112 auserData: int(QAbstract3DGraph::SelectionNone));
113 selectionModeList->addItem(QStringLiteral("Bar"),
114 auserData: int(QAbstract3DGraph::SelectionItem));
115 selectionModeList->addItem(QStringLiteral("Row"),
116 auserData: int(QAbstract3DGraph::SelectionRow));
117 selectionModeList->addItem(QStringLiteral("Bar and Row"),
118 auserData: int(QAbstract3DGraph::SelectionItemAndRow));
119 selectionModeList->addItem(QStringLiteral("Column"),
120 auserData: int(QAbstract3DGraph::SelectionColumn));
121 selectionModeList->addItem(QStringLiteral("Bar and Column"),
122 auserData: int(QAbstract3DGraph::SelectionItemAndColumn));
123 selectionModeList->addItem(QStringLiteral("Row and Column"),
124 auserData: int(QAbstract3DGraph::SelectionRowAndColumn));
125 selectionModeList->addItem(QStringLiteral("Bar, Row and Column"),
126 auserData: int(QAbstract3DGraph::SelectionItemRowAndColumn));
127 selectionModeList->addItem(QStringLiteral("Slice into Row"),
128 auserData: int(QAbstract3DGraph::SelectionSlice | QAbstract3DGraph::SelectionRow));
129 selectionModeList->addItem(QStringLiteral("Slice into Row and Item"),
130 auserData: int(QAbstract3DGraph::SelectionSlice | QAbstract3DGraph::SelectionItemAndRow));
131 selectionModeList->addItem(QStringLiteral("Slice into Column"),
132 auserData: int(QAbstract3DGraph::SelectionSlice | QAbstract3DGraph::SelectionColumn));
133 selectionModeList->addItem(QStringLiteral("Slice into Column and Item"),
134 auserData: int(QAbstract3DGraph::SelectionSlice | QAbstract3DGraph::SelectionItemAndColumn));
135 selectionModeList->addItem(QStringLiteral("Multi: Bar, Row, Col"),
136 auserData: int(QAbstract3DGraph::SelectionItemRowAndColumn
137 | QAbstract3DGraph::SelectionMultiSeries));
138 selectionModeList->addItem(QStringLiteral("Multi, Slice: Row, Item"),
139 auserData: int(QAbstract3DGraph::SelectionSlice | QAbstract3DGraph::SelectionItemAndRow
140 | QAbstract3DGraph::SelectionMultiSeries));
141 selectionModeList->addItem(QStringLiteral("Multi, Slice: Col, Item"),
142 auserData: int(QAbstract3DGraph::SelectionSlice | QAbstract3DGraph::SelectionItemAndColumn
143 | QAbstract3DGraph::SelectionMultiSeries));
144 selectionModeList->setCurrentIndex(1);
145
146 QCheckBox *backgroundCheckBox = new QCheckBox(widget);
147 backgroundCheckBox->setText(QStringLiteral("Show background"));
148 backgroundCheckBox->setChecked(false);
149
150 QCheckBox *gridCheckBox = new QCheckBox(widget);
151 gridCheckBox->setText(QStringLiteral("Show grid"));
152 gridCheckBox->setChecked(true);
153
154 QCheckBox *seriesCheckBox = new QCheckBox(widget);
155 seriesCheckBox->setText(QStringLiteral("Show second series"));
156 seriesCheckBox->setChecked(false);
157
158 QCheckBox *reverseValueAxisCheckBox = new QCheckBox(widget);
159 reverseValueAxisCheckBox->setText(QStringLiteral("Reverse value axis"));
160 reverseValueAxisCheckBox->setChecked(false);
161
162 QCheckBox *reflectionCheckBox = new QCheckBox(widget);
163 reflectionCheckBox->setText(QStringLiteral("Show reflections"));
164 reflectionCheckBox->setChecked(false);
165
166 //! [4]
167 QSlider *rotationSliderX = new QSlider(Qt::Horizontal, widget);
168 rotationSliderX->setTickInterval(30);
169 rotationSliderX->setTickPosition(QSlider::TicksBelow);
170 rotationSliderX->setMinimum(-180);
171 rotationSliderX->setValue(0);
172 rotationSliderX->setMaximum(180);
173 QSlider *rotationSliderY = new QSlider(Qt::Horizontal, widget);
174 rotationSliderY->setTickInterval(15);
175 rotationSliderY->setTickPosition(QSlider::TicksAbove);
176 rotationSliderY->setMinimum(-90);
177 rotationSliderY->setValue(0);
178 rotationSliderY->setMaximum(90);
179 //! [4]
180
181 QSlider *fontSizeSlider = new QSlider(Qt::Horizontal, widget);
182 fontSizeSlider->setTickInterval(10);
183 fontSizeSlider->setTickPosition(QSlider::TicksBelow);
184 fontSizeSlider->setMinimum(1);
185 fontSizeSlider->setValue(30);
186 fontSizeSlider->setMaximum(100);
187
188 QFontComboBox *fontList = new QFontComboBox(widget);
189 fontList->setCurrentFont(QFont("Times New Roman"));
190
191 QComboBox *shadowQuality = new QComboBox(widget);
192 shadowQuality->addItem(QStringLiteral("None"));
193 shadowQuality->addItem(QStringLiteral("Low"));
194 shadowQuality->addItem(QStringLiteral("Medium"));
195 shadowQuality->addItem(QStringLiteral("High"));
196 shadowQuality->addItem(QStringLiteral("Low Soft"));
197 shadowQuality->addItem(QStringLiteral("Medium Soft"));
198 shadowQuality->addItem(QStringLiteral("High Soft"));
199 shadowQuality->setCurrentIndex(5);
200
201 QComboBox *rangeList = new QComboBox(widget);
202 rangeList->addItem(QStringLiteral("2006"));
203 rangeList->addItem(QStringLiteral("2007"));
204 rangeList->addItem(QStringLiteral("2008"));
205 rangeList->addItem(QStringLiteral("2009"));
206 rangeList->addItem(QStringLiteral("2010"));
207 rangeList->addItem(QStringLiteral("2011"));
208 rangeList->addItem(QStringLiteral("2012"));
209 rangeList->addItem(QStringLiteral("2013"));
210 rangeList->addItem(QStringLiteral("All"));
211 rangeList->setCurrentIndex(8);
212
213 QCheckBox *axisTitlesVisibleCB = new QCheckBox(widget);
214 axisTitlesVisibleCB->setText(QStringLiteral("Axis titles visible"));
215 axisTitlesVisibleCB->setChecked(true);
216
217 QCheckBox *axisTitlesFixedCB = new QCheckBox(widget);
218 axisTitlesFixedCB->setText(QStringLiteral("Axis titles fixed"));
219 axisTitlesFixedCB->setChecked(true);
220
221 QSlider *axisLabelRotationSlider = new QSlider(Qt::Horizontal, widget);
222 axisLabelRotationSlider->setTickInterval(10);
223 axisLabelRotationSlider->setTickPosition(QSlider::TicksBelow);
224 axisLabelRotationSlider->setMinimum(0);
225 axisLabelRotationSlider->setValue(30);
226 axisLabelRotationSlider->setMaximum(90);
227
228 //! [5]
229 vLayout->addWidget(new QLabel(QStringLiteral("Rotate horizontally")));
230 vLayout->addWidget(rotationSliderX, stretch: 0, alignment: Qt::AlignTop);
231 vLayout->addWidget(new QLabel(QStringLiteral("Rotate vertically")));
232 vLayout->addWidget(rotationSliderY, stretch: 0, alignment: Qt::AlignTop);
233 //! [5]
234 vLayout->addWidget(labelButton, stretch: 0, alignment: Qt::AlignTop);
235 vLayout->addWidget(cameraButton, stretch: 0, alignment: Qt::AlignTop);
236 vLayout->addWidget(zoomToSelectedButton, stretch: 0, alignment: Qt::AlignTop);
237 vLayout->addWidget(backgroundCheckBox);
238 vLayout->addWidget(gridCheckBox);
239 vLayout->addWidget(smoothCheckBox);
240 vLayout->addWidget(reflectionCheckBox);
241 vLayout->addWidget(seriesCheckBox);
242 vLayout->addWidget(reverseValueAxisCheckBox);
243 vLayout->addWidget(axisTitlesVisibleCB);
244 vLayout->addWidget(axisTitlesFixedCB);
245 vLayout->addWidget(new QLabel(QStringLiteral("Show year")));
246 vLayout->addWidget(rangeList);
247 vLayout->addWidget(new QLabel(QStringLiteral("Change bar style")));
248 vLayout->addWidget(barStyleList);
249 vLayout->addWidget(new QLabel(QStringLiteral("Change selection mode")));
250 vLayout->addWidget(selectionModeList);
251 vLayout->addWidget(new QLabel(QStringLiteral("Change theme")));
252 vLayout->addWidget(themeList);
253 vLayout->addWidget(new QLabel(QStringLiteral("Adjust shadow quality")));
254 vLayout->addWidget(shadowQuality);
255 vLayout->addWidget(new QLabel(QStringLiteral("Change font")));
256 vLayout->addWidget(fontList);
257 vLayout->addWidget(new QLabel(QStringLiteral("Adjust font size")));
258 vLayout->addWidget(fontSizeSlider);
259 vLayout->addWidget(new QLabel(QStringLiteral("Axis label rotation")));
260 vLayout->addWidget(axisLabelRotationSlider, stretch: 1, alignment: Qt::AlignTop);
261
262 //! [2]
263 GraphModifier *modifier = new GraphModifier(widgetgraph);
264 //! [2]
265
266 //! [6]
267 QObject::connect(sender: rotationSliderX, signal: &QSlider::valueChanged, receiver: modifier, slot: &GraphModifier::rotateX);
268 QObject::connect(sender: rotationSliderY, signal: &QSlider::valueChanged, receiver: modifier, slot: &GraphModifier::rotateY);
269 //! [6]
270
271 QObject::connect(sender: labelButton, signal: &QPushButton::clicked, receiver: modifier,
272 slot: &GraphModifier::changeLabelBackground);
273 QObject::connect(sender: cameraButton, signal: &QPushButton::clicked, receiver: modifier,
274 slot: &GraphModifier::changePresetCamera);
275 QObject::connect(sender: zoomToSelectedButton, signal: &QPushButton::clicked, receiver: modifier,
276 slot: &GraphModifier::zoomToSelectedBar);
277
278 QObject::connect(sender: backgroundCheckBox, signal: &QCheckBox::stateChanged, receiver: modifier,
279 slot: &GraphModifier::setBackgroundEnabled);
280 QObject::connect(sender: gridCheckBox, signal: &QCheckBox::stateChanged, receiver: modifier,
281 slot: &GraphModifier::setGridEnabled);
282 QObject::connect(sender: smoothCheckBox, signal: &QCheckBox::stateChanged, receiver: modifier,
283 slot: &GraphModifier::setSmoothBars);
284 QObject::connect(sender: seriesCheckBox, signal: &QCheckBox::stateChanged, receiver: modifier,
285 slot: &GraphModifier::setSeriesVisibility);
286 QObject::connect(sender: reverseValueAxisCheckBox, signal: &QCheckBox::stateChanged, receiver: modifier,
287 slot: &GraphModifier::setReverseValueAxis);
288 QObject::connect(sender: reflectionCheckBox, signal: &QCheckBox::stateChanged, receiver: modifier,
289 slot: &GraphModifier::setReflection);
290
291 QObject::connect(sender: modifier, signal: &GraphModifier::backgroundEnabledChanged,
292 receiver: backgroundCheckBox, slot: &QCheckBox::setChecked);
293 QObject::connect(sender: modifier, signal: &GraphModifier::gridEnabledChanged,
294 receiver: gridCheckBox, slot: &QCheckBox::setChecked);
295
296 QObject::connect(sender: rangeList, SIGNAL(currentIndexChanged(int)), receiver: modifier,
297 SLOT(changeRange(int)));
298
299 QObject::connect(sender: barStyleList, SIGNAL(currentIndexChanged(int)), receiver: modifier,
300 SLOT(changeStyle(int)));
301
302 QObject::connect(sender: selectionModeList, SIGNAL(currentIndexChanged(int)), receiver: modifier,
303 SLOT(changeSelectionMode(int)));
304
305 QObject::connect(sender: themeList, SIGNAL(currentIndexChanged(int)), receiver: modifier,
306 SLOT(changeTheme(int)));
307
308 QObject::connect(sender: shadowQuality, SIGNAL(currentIndexChanged(int)), receiver: modifier,
309 SLOT(changeShadowQuality(int)));
310
311 QObject::connect(sender: modifier, signal: &GraphModifier::shadowQualityChanged, receiver: shadowQuality,
312 slot: &QComboBox::setCurrentIndex);
313 QObject::connect(sender: widgetgraph, signal: &Q3DBars::shadowQualityChanged, receiver: modifier,
314 slot: &GraphModifier::shadowQualityUpdatedByVisual);
315
316 QObject::connect(sender: fontSizeSlider, signal: &QSlider::valueChanged, receiver: modifier,
317 slot: &GraphModifier::changeFontSize);
318 QObject::connect(sender: fontList, signal: &QFontComboBox::currentFontChanged, receiver: modifier,
319 slot: &GraphModifier::changeFont);
320
321 QObject::connect(sender: modifier, signal: &GraphModifier::fontSizeChanged, receiver: fontSizeSlider,
322 slot: &QSlider::setValue);
323 QObject::connect(sender: modifier, signal: &GraphModifier::fontChanged, receiver: fontList,
324 slot: &QFontComboBox::setCurrentFont);
325
326 QObject::connect(sender: axisTitlesVisibleCB, signal: &QCheckBox::stateChanged, receiver: modifier,
327 slot: &GraphModifier::setAxisTitleVisibility);
328 QObject::connect(sender: axisTitlesFixedCB, signal: &QCheckBox::stateChanged, receiver: modifier,
329 slot: &GraphModifier::setAxisTitleFixed);
330 QObject::connect(sender: axisLabelRotationSlider, signal: &QSlider::valueChanged, receiver: modifier,
331 slot: &GraphModifier::changeLabelRotation);
332 //! [3]
333 widget->show();
334 return app.exec();
335 //! [3]
336}
337

source code of qtdatavis3d/examples/datavisualization/bars/main.cpp