Bars Example▲
Sélectionnez
/**
**************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Data Visualization module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
***************************************************************************
*/
#include
"graphmodifier.h"
#include <QtWidgets/QApplication>
#include <QtWidgets/QWidget>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QSlider>
#include <QtWidgets/QFontComboBox>
#include <QtWidgets/QLabel>
#include <QtWidgets/QMessageBox>
#include <QtGui/QScreen>
#include <QtGui/QFontDatabase>
int
main(int
argc, char
**
argv)
{
QApplication app(argc, argv);
Q3DBars *
widgetgraph =
new
Q3DBars();
QWidget *
container =
QWidget::
createWindowContainer(widgetgraph);
if
(!
widgetgraph-&
gt;hasContext()) {
QMessageBox msgBox;
msgBox.setText("Couldn't initialize the OpenGL context."
);
msgBox.exec();
return
-
1
;
}
QSize screenSize =
widgetgraph-&
gt;screen()-&
gt;size();
container-&
gt;setMinimumSize(QSize(screenSize.width() /
2
, screenSize.height() /
1.5
));
container-&
gt;setMaximumSize(screenSize);
container-&
gt;setSizePolicy(QSizePolicy::
Expanding, QSizePolicy::
Expanding);
container-&
gt;setFocusPolicy(Qt::
StrongFocus);
QWidget *
widget =
new
QWidget;
QHBoxLayout *
hLayout =
new
QHBoxLayout(widget);
QVBoxLayout *
vLayout =
new
QVBoxLayout();
hLayout-&
gt;addWidget(container, 1
);
hLayout-&
gt;addLayout(vLayout);
widget-&
gt;setWindowTitle(QStringLiteral("Average temperatures in Oulu and Helsinki, Finland (2006-2013)"
));
QComboBox *
themeList =
new
QComboBox(widget);
themeList-&
gt;addItem(QStringLiteral("Qt"
));
themeList-&
gt;addItem(QStringLiteral("Primary Colors"
));
themeList-&
gt;addItem(QStringLiteral("Digia"
));
themeList-&
gt;addItem(QStringLiteral("Stone Moss"
));
themeList-&
gt;addItem(QStringLiteral("Army Blue"
));
themeList-&
gt;addItem(QStringLiteral("Retro"
));
themeList-&
gt;addItem(QStringLiteral("Ebony"
));
themeList-&
gt;addItem(QStringLiteral("Isabelle"
));
themeList-&
gt;setCurrentIndex(0
);
QPushButton *
labelButton =
new
QPushButton(widget);
labelButton-&
gt;setText(QStringLiteral("Change label style"
));
QCheckBox *
smoothCheckBox =
new
QCheckBox(widget);
smoothCheckBox-&
gt;setText(QStringLiteral("Smooth bars"
));
smoothCheckBox-&
gt;setChecked(false
);
QComboBox *
barStyleList =
new
QComboBox(widget);
barStyleList-&
gt;addItem(QStringLiteral("Bar"
), int
(QAbstract3DSeries::
MeshBar));
barStyleList-&
gt;addItem(QStringLiteral("Pyramid"
), int
(QAbstract3DSeries::
MeshPyramid));
barStyleList-&
gt;addItem(QStringLiteral("Cone"
), int
(QAbstract3DSeries::
MeshCone));
barStyleList-&
gt;addItem(QStringLiteral("Cylinder"
), int
(QAbstract3DSeries::
MeshCylinder));
barStyleList-&
gt;addItem(QStringLiteral("Bevel bar"
), int
(QAbstract3DSeries::
MeshBevelBar));
barStyleList-&
gt;addItem(QStringLiteral("Sphere"
), int
(QAbstract3DSeries::
MeshSphere));
barStyleList-&
gt;setCurrentIndex(4
);
QPushButton *
cameraButton =
new
QPushButton(widget);
cameraButton-&
gt;setText(QStringLiteral("Change camera preset"
));
QPushButton *
zoomToSelectedButton =
new
QPushButton(widget);
zoomToSelectedButton-&
gt;setText(QStringLiteral("Zoom to selected bar"
));
QComboBox *
selectionModeList =
new
QComboBox(widget);
selectionModeList-&
gt;addItem(QStringLiteral("None"
),
int
(QAbstract3DGraph::
SelectionNone));
selectionModeList-&
gt;addItem(QStringLiteral("Bar"
),
int
(QAbstract3DGraph::
SelectionItem));
selectionModeList-&
gt;addItem(QStringLiteral("Row"
),
int
(QAbstract3DGraph::
SelectionRow));
selectionModeList-&
gt;addItem(QStringLiteral("Bar and Row"
),
int
(QAbstract3DGraph::
SelectionItemAndRow));
selectionModeList-&
gt;addItem(QStringLiteral("Column"
),
int
(QAbstract3DGraph::
SelectionColumn));
selectionModeList-&
gt;addItem(QStringLiteral("Bar and Column"
),
int
(QAbstract3DGraph::
SelectionItemAndColumn));
selectionModeList-&
gt;addItem(QStringLiteral("Row and Column"
),
int
(QAbstract3DGraph::
SelectionRowAndColumn));
selectionModeList-&
gt;addItem(QStringLiteral("Bar, Row and Column"
),
int
(QAbstract3DGraph::
SelectionItemRowAndColumn));
selectionModeList-&
gt;addItem(QStringLiteral("Slice into Row"
),
int
(QAbstract3DGraph::
SelectionSlice |
QAbstract3DGraph::
SelectionRow));
selectionModeList-&
gt;addItem(QStringLiteral("Slice into Row and Item"
),
int
(QAbstract3DGraph::
SelectionSlice |
QAbstract3DGraph::
SelectionItemAndRow));
selectionModeList-&
gt;addItem(QStringLiteral("Slice into Column"
),
int
(QAbstract3DGraph::
SelectionSlice |
QAbstract3DGraph::
SelectionColumn));
selectionModeList-&
gt;addItem(QStringLiteral("Slice into Column and Item"
),
int
(QAbstract3DGraph::
SelectionSlice |
QAbstract3DGraph::
SelectionItemAndColumn));
selectionModeList-&
gt;addItem(QStringLiteral("Multi: Bar, Row, Col"
),
int
(QAbstract3DGraph::
SelectionItemRowAndColumn
|
QAbstract3DGraph::
SelectionMultiSeries));
selectionModeList-&
gt;addItem(QStringLiteral("Multi, Slice: Row, Item"
),
int
(QAbstract3DGraph::
SelectionSlice |
QAbstract3DGraph::
SelectionItemAndRow
|
QAbstract3DGraph::
SelectionMultiSeries));
selectionModeList-&
gt;addItem(QStringLiteral("Multi, Slice: Col, Item"
),
int
(QAbstract3DGraph::
SelectionSlice |
QAbstract3DGraph::
SelectionItemAndColumn
|
QAbstract3DGraph::
SelectionMultiSeries));
selectionModeList-&
gt;setCurrentIndex(1
);
QCheckBox *
backgroundCheckBox =
new
QCheckBox(widget);
backgroundCheckBox-&
gt;setText(QStringLiteral("Show background"
));
backgroundCheckBox-&
gt;setChecked(false
);
QCheckBox *
gridCheckBox =
new
QCheckBox(widget);
gridCheckBox-&
gt;setText(QStringLiteral("Show grid"
));
gridCheckBox-&
gt;setChecked(true
);
QCheckBox *
seriesCheckBox =
new
QCheckBox(widget);
seriesCheckBox-&
gt;setText(QStringLiteral("Show second series"
));
seriesCheckBox-&
gt;setChecked(false
);
QCheckBox *
reverseValueAxisCheckBox =
new
QCheckBox(widget);
reverseValueAxisCheckBox-&
gt;setText(QStringLiteral("Reverse value axis"
));
reverseValueAxisCheckBox-&
gt;setChecked(false
);
QCheckBox *
reflectionCheckBox =
new
QCheckBox(widget);
reflectionCheckBox-&
gt;setText(QStringLiteral("Show reflections"
));
reflectionCheckBox-&
gt;setChecked(false
);
QSlider *
rotationSliderX =
new
QSlider(Qt::
Horizontal, widget);
rotationSliderX-&
gt;setTickInterval(30
);
rotationSliderX-&
gt;setTickPosition(QSlider::
TicksBelow);
rotationSliderX-&
gt;setMinimum(-
180
);
rotationSliderX-&
gt;setValue(0
);
rotationSliderX-&
gt;setMaximum(180
);
QSlider *
rotationSliderY =
new
QSlider(Qt::
Horizontal, widget);
rotationSliderY-&
gt;setTickInterval(15
);
rotationSliderY-&
gt;setTickPosition(QSlider::
TicksAbove);
rotationSliderY-&
gt;setMinimum(-
90
);
rotationSliderY-&
gt;setValue(0
);
rotationSliderY-&
gt;setMaximum(90
);
QSlider *
fontSizeSlider =
new
QSlider(Qt::
Horizontal, widget);
fontSizeSlider-&
gt;setTickInterval(10
);
fontSizeSlider-&
gt;setTickPosition(QSlider::
TicksBelow);
fontSizeSlider-&
gt;setMinimum(1
);
fontSizeSlider-&
gt;setValue(30
);
fontSizeSlider-&
gt;setMaximum(100
);
QFontComboBox *
fontList =
new
QFontComboBox(widget);
fontList-&
gt;setCurrentFont(QFont("Times New Roman"
));
QComboBox *
shadowQuality =
new
QComboBox(widget);
shadowQuality-&
gt;addItem(QStringLiteral("None"
));
shadowQuality-&
gt;addItem(QStringLiteral("Low"
));
shadowQuality-&
gt;addItem(QStringLiteral("Medium"
));
shadowQuality-&
gt;addItem(QStringLiteral("High"
));
shadowQuality-&
gt;addItem(QStringLiteral("Low Soft"
));
shadowQuality-&
gt;addItem(QStringLiteral("Medium Soft"
));
shadowQuality-&
gt;addItem(QStringLiteral("High Soft"
));
shadowQuality-&
gt;setCurrentIndex(5
);
QComboBox *
rangeList =
new
QComboBox(widget);
rangeList-&
gt;addItem(QStringLiteral("2006"
));
rangeList-&
gt;addItem(QStringLiteral("2007"
));
rangeList-&
gt;addItem(QStringLiteral("2008"
));
rangeList-&
gt;addItem(QStringLiteral("2009"
));
rangeList-&
gt;addItem(QStringLiteral("2010"
));
rangeList-&
gt;addItem(QStringLiteral("2011"
));
rangeList-&
gt;addItem(QStringLiteral("2012"
));
rangeList-&
gt;addItem(QStringLiteral("2013"
));
rangeList-&
gt;addItem(QStringLiteral("All"
));
rangeList-&
gt;setCurrentIndex(8
);
QCheckBox *
axisTitlesVisibleCB =
new
QCheckBox(widget);
axisTitlesVisibleCB-&
gt;setText(QStringLiteral("Axis titles visible"
));
axisTitlesVisibleCB-&
gt;setChecked(true
);
QCheckBox *
axisTitlesFixedCB =
new
QCheckBox(widget);
axisTitlesFixedCB-&
gt;setText(QStringLiteral("Axis titles fixed"
));
axisTitlesFixedCB-&
gt;setChecked(true
);
QSlider *
axisLabelRotationSlider =
new
QSlider(Qt::
Horizontal, widget);
axisLabelRotationSlider-&
gt;setTickInterval(10
);
axisLabelRotationSlider-&
gt;setTickPosition(QSlider::
TicksBelow);
axisLabelRotationSlider-&
gt;setMinimum(0
);
axisLabelRotationSlider-&
gt;setValue(30
);
axisLabelRotationSlider-&
gt;setMaximum(90
);
vLayout-&
gt;addWidget(new
QLabel(QStringLiteral("Rotate horizontally"
)));
vLayout-&
gt;addWidget(rotationSliderX, 0
, Qt::
AlignTop);
vLayout-&
gt;addWidget(new
QLabel(QStringLiteral("Rotate vertically"
)));
vLayout-&
gt;addWidget(rotationSliderY, 0
, Qt::
AlignTop);
vLayout-&
gt;addWidget(labelButton, 0
, Qt::
AlignTop);
vLayout-&
gt;addWidget(cameraButton, 0
, Qt::
AlignTop);
vLayout-&
gt;addWidget(zoomToSelectedButton, 0
, Qt::
AlignTop);
vLayout-&
gt;addWidget(backgroundCheckBox);
vLayout-&
gt;addWidget(gridCheckBox);
vLayout-&
gt;addWidget(smoothCheckBox);
vLayout-&
gt;addWidget(reflectionCheckBox);
vLayout-&
gt;addWidget(seriesCheckBox);
vLayout-&
gt;addWidget(reverseValueAxisCheckBox);
vLayout-&
gt;addWidget(axisTitlesVisibleCB);
vLayout-&
gt;addWidget(axisTitlesFixedCB);
vLayout-&
gt;addWidget(new
QLabel(QStringLiteral("Show year"
)));
vLayout-&
gt;addWidget(rangeList);
vLayout-&
gt;addWidget(new
QLabel(QStringLiteral("Change bar style"
)));
vLayout-&
gt;addWidget(barStyleList);
vLayout-&
gt;addWidget(new
QLabel(QStringLiteral("Change selection mode"
)));
vLayout-&
gt;addWidget(selectionModeList);
vLayout-&
gt;addWidget(new
QLabel(QStringLiteral("Change theme"
)));
vLayout-&
gt;addWidget(themeList);
vLayout-&
gt;addWidget(new
QLabel(QStringLiteral("Adjust shadow quality"
)));
vLayout-&
gt;addWidget(shadowQuality);
vLayout-&
gt;addWidget(new
QLabel(QStringLiteral("Change font"
)));
vLayout-&
gt;addWidget(fontList);
vLayout-&
gt;addWidget(new
QLabel(QStringLiteral("Adjust font size"
)));
vLayout-&
gt;addWidget(fontSizeSlider);
vLayout-&
gt;addWidget(new
QLabel(QStringLiteral("Axis label rotation"
)));
vLayout-&
gt;addWidget(axisLabelRotationSlider, 1
, Qt::
AlignTop);
GraphModifier *
modifier =
new
GraphModifier(widgetgraph);
QObject::
connect(rotationSliderX, &
amp;QSlider::
valueChanged, modifier, &
amp;GraphModifier::
rotateX);
QObject::
connect(rotationSliderY, &
amp;QSlider::
valueChanged, modifier, &
amp;GraphModifier::
rotateY);
QObject::
connect(labelButton, &
amp;QPushButton::
clicked, modifier,
&
amp;GraphModifier::
changeLabelBackground);
QObject::
connect(cameraButton, &
amp;QPushButton::
clicked, modifier,
&
amp;GraphModifier::
changePresetCamera);
QObject::
connect(zoomToSelectedButton, &
amp;QPushButton::
clicked, modifier,
&
amp;GraphModifier::
zoomToSelectedBar);
QObject::
connect(backgroundCheckBox, &
amp;QCheckBox::
stateChanged, modifier,
&
amp;GraphModifier::
setBackgroundEnabled);
QObject::
connect(gridCheckBox, &
amp;QCheckBox::
stateChanged, modifier,
&
amp;GraphModifier::
setGridEnabled);
QObject::
connect(smoothCheckBox, &
amp;QCheckBox::
stateChanged, modifier,
&
amp;GraphModifier::
setSmoothBars);
QObject::
connect(seriesCheckBox, &
amp;QCheckBox::
stateChanged, modifier,
&
amp;GraphModifier::
setSeriesVisibility);
QObject::
connect(reverseValueAxisCheckBox, &
amp;QCheckBox::
stateChanged, modifier,
&
amp;GraphModifier::
setReverseValueAxis);
QObject::
connect(reflectionCheckBox, &
amp;QCheckBox::
stateChanged, modifier,
&
amp;GraphModifier::
setReflection);
QObject::
connect(modifier, &
amp;GraphModifier::
backgroundEnabledChanged,
backgroundCheckBox, &
amp;QCheckBox::
setChecked);
QObject::
connect(modifier, &
amp;GraphModifier::
gridEnabledChanged,
gridCheckBox, &
amp;QCheckBox::
setChecked);
QObject::
connect(rangeList, SIGNAL(currentIndexChanged(int
)), modifier,
SLOT(changeRange(int
)));
QObject::
connect(barStyleList, SIGNAL(currentIndexChanged(int
)), modifier,
SLOT(changeStyle(int
)));
QObject::
connect(selectionModeList, SIGNAL(currentIndexChanged(int
)), modifier,
SLOT(changeSelectionMode(int
)));
QObject::
connect(themeList, SIGNAL(currentIndexChanged(int
)), modifier,
SLOT(changeTheme(int
)));
QObject::
connect(shadowQuality, SIGNAL(currentIndexChanged(int
)), modifier,
SLOT(changeShadowQuality(int
)));
QObject::
connect(modifier, &
amp;GraphModifier::
shadowQualityChanged, shadowQuality,
&
amp;QComboBox::
setCurrentIndex);
QObject::
connect(widgetgraph, &
amp;Q3DBars::
shadowQualityChanged, modifier,
&
amp;GraphModifier::
shadowQualityUpdatedByVisual);
QObject::
connect(fontSizeSlider, &
amp;QSlider::
valueChanged, modifier,
&
amp;GraphModifier::
changeFontSize);
QObject::
connect(fontList, &
amp;QFontComboBox::
currentFontChanged, modifier,
&
amp;GraphModifier::
changeFont);
QObject::
connect(modifier, &
amp;GraphModifier::
fontSizeChanged, fontSizeSlider,
&
amp;QSlider::
setValue);
QObject::
connect(modifier, &
amp;GraphModifier::
fontChanged, fontList,
&
amp;QFontComboBox::
setCurrentFont);
QObject::
connect(axisTitlesVisibleCB, &
amp;QCheckBox::
stateChanged, modifier,
&
amp;GraphModifier::
setAxisTitleVisibility);
QObject::
connect(axisTitlesFixedCB, &
amp;QCheckBox::
stateChanged, modifier,
&
amp;GraphModifier::
setAxisTitleFixed);
QObject::
connect(axisLabelRotationSlider, &
amp;QSlider::
valueChanged, modifier,
&
amp;GraphModifier::
changeLabelRotation);
widget-&
gt;show();
return
app.exec();
}