mirror of https://github.com/qt/qtdatavis3d.git
272 lines
12 KiB
C++
272 lines
12 KiB
C++
/****************************************************************************
|
|
**
|
|
** 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
|
|
**
|
|
****************************************************************************/
|
|
|
|
#include "graphmodifier.h"
|
|
|
|
#include <QApplication>
|
|
#include <QWidget>
|
|
#include <QHBoxLayout>
|
|
#include <QVBoxLayout>
|
|
#include <QPushButton>
|
|
#include <QCheckBox>
|
|
#include <QSlider>
|
|
#include <QFontComboBox>
|
|
#include <QLabel>
|
|
#include <QScreen>
|
|
#include <QFontDatabase>
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
//! [0]
|
|
QApplication app(argc, argv);
|
|
Q3DBars *widgetgraph = new Q3DBars();
|
|
QWidget *container = QWidget::createWindowContainer(widgetgraph);
|
|
//! [0]
|
|
|
|
QSize screenSize = widgetgraph->screen()->size();
|
|
container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.5));
|
|
container->setMaximumSize(screenSize);
|
|
container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
container->setFocusPolicy(Qt::StrongFocus);
|
|
|
|
//! [1]
|
|
QWidget *widget = new QWidget;
|
|
QHBoxLayout *hLayout = new QHBoxLayout(widget);
|
|
QVBoxLayout *vLayout = new QVBoxLayout();
|
|
hLayout->addWidget(container, 1);
|
|
hLayout->addLayout(vLayout);
|
|
//! [1]
|
|
|
|
widget->setWindowTitle(QStringLiteral("Average temperatures in Oulu and Helsinki, Finland (2006-2013)"));
|
|
|
|
QComboBox *themeList = new QComboBox(widget);
|
|
themeList->addItem(QStringLiteral("Qt"));
|
|
themeList->addItem(QStringLiteral("Primary Colors"));
|
|
themeList->addItem(QStringLiteral("Digia"));
|
|
themeList->addItem(QStringLiteral("Stone Moss"));
|
|
themeList->addItem(QStringLiteral("Army Blue"));
|
|
themeList->addItem(QStringLiteral("Retro"));
|
|
themeList->addItem(QStringLiteral("Ebony"));
|
|
themeList->addItem(QStringLiteral("Isabelle"));
|
|
themeList->setCurrentIndex(0);
|
|
|
|
QPushButton *labelButton = new QPushButton(widget);
|
|
labelButton->setText(QStringLiteral("Change label style"));
|
|
|
|
QCheckBox *smoothCheckBox = new QCheckBox(widget);
|
|
smoothCheckBox->setText(QStringLiteral("Smooth bars"));
|
|
smoothCheckBox->setChecked(false);
|
|
|
|
QComboBox *barStyleList = new QComboBox(widget);
|
|
barStyleList->addItem(QStringLiteral("Bar"), int(QAbstract3DSeries::MeshBar));
|
|
barStyleList->addItem(QStringLiteral("Pyramid"), int(QAbstract3DSeries::MeshPyramid));
|
|
barStyleList->addItem(QStringLiteral("Cone"), int(QAbstract3DSeries::MeshCone));
|
|
barStyleList->addItem(QStringLiteral("Cylinder"), int(QAbstract3DSeries::MeshCylinder));
|
|
barStyleList->addItem(QStringLiteral("Bevel bar"), int(QAbstract3DSeries::MeshBevelBar));
|
|
barStyleList->addItem(QStringLiteral("Sphere"), int(QAbstract3DSeries::MeshSphere));
|
|
barStyleList->setCurrentIndex(4);
|
|
|
|
QPushButton *cameraButton = new QPushButton(widget);
|
|
cameraButton->setText(QStringLiteral("Change camera preset"));
|
|
|
|
QComboBox *selectionModeList = new QComboBox(widget);
|
|
selectionModeList->addItem(QStringLiteral("None"),
|
|
int(QAbstract3DGraph::SelectionNone));
|
|
selectionModeList->addItem(QStringLiteral("Bar"),
|
|
int(QAbstract3DGraph::SelectionItem));
|
|
selectionModeList->addItem(QStringLiteral("Row"),
|
|
int(QAbstract3DGraph::SelectionRow));
|
|
selectionModeList->addItem(QStringLiteral("Bar and Row"),
|
|
int(QAbstract3DGraph::SelectionItemAndRow));
|
|
selectionModeList->addItem(QStringLiteral("Column"),
|
|
int(QAbstract3DGraph::SelectionColumn));
|
|
selectionModeList->addItem(QStringLiteral("Bar and Column"),
|
|
int(QAbstract3DGraph::SelectionItemAndColumn));
|
|
selectionModeList->addItem(QStringLiteral("Row and Column"),
|
|
int(QAbstract3DGraph::SelectionRowAndColumn));
|
|
selectionModeList->addItem(QStringLiteral("Bar, Row and Column"),
|
|
int(QAbstract3DGraph::SelectionItemRowAndColumn));
|
|
selectionModeList->addItem(QStringLiteral("Slice into Row"),
|
|
int(QAbstract3DGraph::SelectionSlice | QAbstract3DGraph::SelectionRow));
|
|
selectionModeList->addItem(QStringLiteral("Slice into Row and Item"),
|
|
int(QAbstract3DGraph::SelectionSlice | QAbstract3DGraph::SelectionItemAndRow));
|
|
selectionModeList->addItem(QStringLiteral("Slice into Column"),
|
|
int(QAbstract3DGraph::SelectionSlice | QAbstract3DGraph::SelectionColumn));
|
|
selectionModeList->addItem(QStringLiteral("Slice into Column and Item"),
|
|
int(QAbstract3DGraph::SelectionSlice | QAbstract3DGraph::SelectionItemAndColumn));
|
|
selectionModeList->addItem(QStringLiteral("Multi: Bar, Row, Col"),
|
|
int(QAbstract3DGraph::SelectionItemRowAndColumn
|
|
| QAbstract3DGraph::SelectionMultiSeries));
|
|
selectionModeList->addItem(QStringLiteral("Multi, Slice: Row, Item"),
|
|
int(QAbstract3DGraph::SelectionSlice | QAbstract3DGraph::SelectionItemAndRow
|
|
| QAbstract3DGraph::SelectionMultiSeries));
|
|
selectionModeList->addItem(QStringLiteral("Multi, Slice: Col, Item"),
|
|
int(QAbstract3DGraph::SelectionSlice | QAbstract3DGraph::SelectionItemAndColumn
|
|
| QAbstract3DGraph::SelectionMultiSeries));
|
|
selectionModeList->setCurrentIndex(1);
|
|
|
|
QCheckBox *backgroundCheckBox = new QCheckBox(widget);
|
|
backgroundCheckBox->setText(QStringLiteral("Show background"));
|
|
backgroundCheckBox->setChecked(false);
|
|
|
|
QCheckBox *gridCheckBox = new QCheckBox(widget);
|
|
gridCheckBox->setText(QStringLiteral("Show grid"));
|
|
gridCheckBox->setChecked(true);
|
|
|
|
QCheckBox *seriesCheckBox = new QCheckBox(widget);
|
|
seriesCheckBox->setText(QStringLiteral("Show second series"));
|
|
seriesCheckBox->setChecked(false);
|
|
|
|
//! [4]
|
|
QSlider *rotationSliderX = new QSlider(Qt::Horizontal, widget);
|
|
rotationSliderX->setTickInterval(30);
|
|
rotationSliderX->setTickPosition(QSlider::TicksBelow);
|
|
rotationSliderX->setMinimum(-180);
|
|
rotationSliderX->setValue(0);
|
|
rotationSliderX->setMaximum(180);
|
|
QSlider *rotationSliderY = new QSlider(Qt::Horizontal, widget);
|
|
rotationSliderY->setTickInterval(15);
|
|
rotationSliderY->setTickPosition(QSlider::TicksAbove);
|
|
rotationSliderY->setMinimum(-90);
|
|
rotationSliderY->setValue(0);
|
|
rotationSliderY->setMaximum(90);
|
|
//! [4]
|
|
|
|
QSlider *fontSizeSlider = new QSlider(Qt::Horizontal, widget);
|
|
fontSizeSlider->setTickInterval(10);
|
|
fontSizeSlider->setTickPosition(QSlider::TicksBelow);
|
|
fontSizeSlider->setMinimum(1);
|
|
fontSizeSlider->setValue(30);
|
|
fontSizeSlider->setMaximum(100);
|
|
|
|
QFontComboBox *fontList = new QFontComboBox(widget);
|
|
fontList->setCurrentFont(QFont("Times New Roman"));
|
|
|
|
QComboBox *shadowQuality = new QComboBox(widget);
|
|
shadowQuality->addItem(QStringLiteral("None"));
|
|
shadowQuality->addItem(QStringLiteral("Low"));
|
|
shadowQuality->addItem(QStringLiteral("Medium"));
|
|
shadowQuality->addItem(QStringLiteral("High"));
|
|
shadowQuality->addItem(QStringLiteral("Low Soft"));
|
|
shadowQuality->addItem(QStringLiteral("Medium Soft"));
|
|
shadowQuality->addItem(QStringLiteral("High Soft"));
|
|
shadowQuality->setCurrentIndex(5);
|
|
|
|
QComboBox *rangeList = new QComboBox(widget);
|
|
rangeList->addItem(QStringLiteral("2006"));
|
|
rangeList->addItem(QStringLiteral("2007"));
|
|
rangeList->addItem(QStringLiteral("2008"));
|
|
rangeList->addItem(QStringLiteral("2009"));
|
|
rangeList->addItem(QStringLiteral("2010"));
|
|
rangeList->addItem(QStringLiteral("2011"));
|
|
rangeList->addItem(QStringLiteral("2012"));
|
|
rangeList->addItem(QStringLiteral("2013"));
|
|
rangeList->addItem(QStringLiteral("All"));
|
|
rangeList->setCurrentIndex(8);
|
|
|
|
//! [5]
|
|
vLayout->addWidget(new QLabel(QStringLiteral("Rotate horizontally")));
|
|
vLayout->addWidget(rotationSliderX, 0, Qt::AlignTop);
|
|
vLayout->addWidget(new QLabel(QStringLiteral("Rotate vertically")));
|
|
vLayout->addWidget(rotationSliderY, 0, Qt::AlignTop);
|
|
//! [5]
|
|
vLayout->addWidget(labelButton, 0, Qt::AlignTop);
|
|
vLayout->addWidget(cameraButton, 0, Qt::AlignTop);
|
|
vLayout->addWidget(backgroundCheckBox);
|
|
vLayout->addWidget(gridCheckBox);
|
|
vLayout->addWidget(smoothCheckBox);
|
|
vLayout->addWidget(seriesCheckBox);
|
|
vLayout->addWidget(new QLabel(QStringLiteral("Show year")));
|
|
vLayout->addWidget(rangeList);
|
|
vLayout->addWidget(new QLabel(QStringLiteral("Change bar style")));
|
|
vLayout->addWidget(barStyleList);
|
|
vLayout->addWidget(new QLabel(QStringLiteral("Change selection mode")));
|
|
vLayout->addWidget(selectionModeList);
|
|
vLayout->addWidget(new QLabel(QStringLiteral("Change theme")));
|
|
vLayout->addWidget(themeList);
|
|
vLayout->addWidget(new QLabel(QStringLiteral("Adjust shadow quality")));
|
|
vLayout->addWidget(shadowQuality);
|
|
vLayout->addWidget(new QLabel(QStringLiteral("Change font")));
|
|
vLayout->addWidget(fontList);
|
|
vLayout->addWidget(new QLabel(QStringLiteral("Adjust font size")));
|
|
vLayout->addWidget(fontSizeSlider, 1, Qt::AlignTop);
|
|
|
|
//! [2]
|
|
GraphModifier *modifier = new GraphModifier(widgetgraph);
|
|
//! [2]
|
|
|
|
//! [6]
|
|
QObject::connect(rotationSliderX, &QSlider::valueChanged, modifier, &GraphModifier::rotateX);
|
|
QObject::connect(rotationSliderY, &QSlider::valueChanged, modifier, &GraphModifier::rotateY);
|
|
//! [6]
|
|
|
|
QObject::connect(labelButton, &QPushButton::clicked, modifier,
|
|
&GraphModifier::changeLabelBackground);
|
|
QObject::connect(cameraButton, &QPushButton::clicked, modifier,
|
|
&GraphModifier::changePresetCamera);
|
|
|
|
QObject::connect(backgroundCheckBox, &QCheckBox::stateChanged, modifier,
|
|
&GraphModifier::setBackgroundEnabled);
|
|
QObject::connect(gridCheckBox, &QCheckBox::stateChanged, modifier,
|
|
&GraphModifier::setGridEnabled);
|
|
QObject::connect(smoothCheckBox, &QCheckBox::stateChanged, modifier,
|
|
&GraphModifier::setSmoothBars);
|
|
QObject::connect(seriesCheckBox, &QCheckBox::stateChanged, modifier,
|
|
&GraphModifier::setSeriesVisibility);
|
|
|
|
QObject::connect(modifier, &GraphModifier::backgroundEnabledChanged,
|
|
backgroundCheckBox, &QCheckBox::setChecked);
|
|
QObject::connect(modifier, &GraphModifier::gridEnabledChanged,
|
|
gridCheckBox, &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, &GraphModifier::shadowQualityChanged, shadowQuality,
|
|
&QComboBox::setCurrentIndex);
|
|
QObject::connect(widgetgraph, &Q3DBars::shadowQualityChanged, modifier,
|
|
&GraphModifier::shadowQualityUpdatedByVisual);
|
|
|
|
QObject::connect(fontSizeSlider, &QSlider::valueChanged, modifier,
|
|
&GraphModifier::changeFontSize);
|
|
QObject::connect(fontList, &QFontComboBox::currentFontChanged, modifier,
|
|
&GraphModifier::changeFont);
|
|
|
|
QObject::connect(modifier, &GraphModifier::fontSizeChanged, fontSizeSlider,
|
|
&QSlider::setValue);
|
|
QObject::connect(modifier, &GraphModifier::fontChanged, fontList,
|
|
&QFontComboBox::setCurrentFont);
|
|
|
|
//! [3]
|
|
widget->show();
|
|
return app.exec();
|
|
//! [3]
|
|
}
|