diff options
Diffstat (limited to 'examples/datavisualization/surface')
-rw-r--r-- | examples/datavisualization/surface/CMakeLists.txt | 54 | ||||
-rw-r--r-- | examples/datavisualization/surface/doc/images/surface-example.png | bin | 149046 -> 0 bytes | |||
-rw-r--r-- | examples/datavisualization/surface/doc/src/surface.qdoc | 147 | ||||
-rw-r--r-- | examples/datavisualization/surface/main.cpp | 231 | ||||
-rw-r--r-- | examples/datavisualization/surface/mountain.png | bin | 34540 -> 0 bytes | |||
-rw-r--r-- | examples/datavisualization/surface/surface.pro | 20 | ||||
-rw-r--r-- | examples/datavisualization/surface/surface.qrc | 5 | ||||
-rw-r--r-- | examples/datavisualization/surface/surfacegraph.cpp | 277 | ||||
-rw-r--r-- | examples/datavisualization/surface/surfacegraph.h | 97 |
9 files changed, 0 insertions, 831 deletions
diff --git a/examples/datavisualization/surface/CMakeLists.txt b/examples/datavisualization/surface/CMakeLists.txt deleted file mode 100644 index 8740d13e..00000000 --- a/examples/datavisualization/surface/CMakeLists.txt +++ /dev/null @@ -1,54 +0,0 @@ -cmake_minimum_required(VERSION 3.16) -project(surface LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) -find_package(Qt6 COMPONENTS DataVisualization) - -qt_add_executable(surface - main.cpp - surfacegraph.cpp surfacegraph.h -) -set_target_properties(surface PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) -target_link_libraries(surface PUBLIC - Qt::Core - Qt::Gui - Qt::Widgets - Qt::DataVisualization -) - -set_source_files_properties("mountain.png" - PROPERTIES QT_RESOURCE_ALIAS "mountain" -) -set(surface_resource_files - "mountain.png" -) - -qt6_add_resources(surface "surface" - PREFIX - "/maps" - FILES - ${surface_resource_files} -) - -install(TARGETS surface - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/datavisualization/surface/doc/images/surface-example.png b/examples/datavisualization/surface/doc/images/surface-example.png Binary files differdeleted file mode 100644 index c323df78..00000000 --- a/examples/datavisualization/surface/doc/images/surface-example.png +++ /dev/null diff --git a/examples/datavisualization/surface/doc/src/surface.qdoc b/examples/datavisualization/surface/doc/src/surface.qdoc deleted file mode 100644 index a81b760a..00000000 --- a/examples/datavisualization/surface/doc/src/surface.qdoc +++ /dev/null @@ -1,147 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** 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 Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example surface - \title Surface Example - \ingroup qtdatavisualization_examples - \brief Using Q3DSurface in a widget application. - - The surface example shows how to make a simple 3D surface graph using Q3DSurface and - combining the use of widgets for adjusting several adjustable qualities. This example - demonstrates the following features: - - \list - \li How to set up a basic QSurfaceDataProxy and set data for it. - \li How to use QHeightMapSurfaceDataProxy for showing 3D height maps. - \li Three different selection modes for studying the graph. - \li Axis range usage for displaying selected portions of the graph. - \li Changing theme. - \li How to set a custom surface gradient. - \endlist - - For instructions about how to interact with the graph, see \l{Qt Data Visualization Interacting with Data}{this page}. - - \image surface-example.png - - \include examples-run.qdocinc - - \section1 Creating the Application - - First, in \c main.cpp, we create a QApplication, instantiate Q3DSurface, and a window container - for it: - - \snippet surface/main.cpp 0 - - The call to QWidget::createWindowContainer is required, as all data visualization graph classes - (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 with the container and - the vertical layout into the horizontal one: - - \snippet surface/main.cpp 1 - - The rest of the code in \c main.cpp is creating control widgets for features in Q3DSurface. We - have separated code for changing these features into \c surfacegraph.cpp and only connect - signals from widgets into methods in \c surfacegraph.cpp. Next chapter explains more - about using Q3DSurface. - - \section1 Setting up Proxies and Data - - First we instantiate a new QSurfaceDataProxy and attach it to a new QSurface3DSeries: - - \snippet surface/surfacegraph.cpp 0 - - Then we fill the proxy with a simple square root and sine wave data. This is done by - creating a new \c QSurfaceDataArray instance and adding \c QSurfaceDataRow elements to it. - The created \c QSurfaceDataArray is set to be the data array for the QSurfaceDataProxy. - - \snippet surface/surfacegraph.cpp 1 - - The height map is created by instantiating a QHeightMapSurfaceDataProxy with - a QImage containing the height data. The method QHeightMapSurfaceDataProxy::setValueRanges() is - used to define the value range of the map. In our example the map is from imaginary position of - 34.0\unicode 0x00B0 N - 40.0\unicode 0x00B0 N and 18.0\unicode 0x00B0 E - 24.0\unicode 0x00B0 E. - These values are used to show and position the map to the axis. - - \snippet surface/surfacegraph.cpp 2 - - For demonstrating different proxies this example has two radio buttons which - the user can use to switch between the series. When the user selects the - \c {Sqrt & Sin} radio button, the selected series is activated with the following - code. First we set the decorative issues like enable the grid for the surface and - select the flat shading mode. Next lines define the axis label format and value - ranges. Automatic label rotation is set to improve label readability at low camera angles. - Finally we make sure the correct series is added to the graph: - - \snippet surface/surfacegraph.cpp 3 - - When the \c{Height Map} radio button is activated, the following code sets the correct series active. - The axis label format is set to show N and E letters and ranges are set to the imaginary coordinates. - Auto adjusting Y-axis range is fine for our height map surface, so we ensure it is set. - - \snippet surface/surfacegraph.cpp 4 - - \section1 Selection Modes - - Q3Dsurface supports three different selection modes. These are demonstrated in the - example with radio buttons, which the user can use to activate a suitable selection mode. - The following inline methods are connected to radio buttons to activate the selected mode. - - \snippet surface/surfacegraph.h 0 - - \section1 Axis Ranges for Studying the Graph - - The example has four slider controls for adjusting the min and max values for X and Z - axis. When selecting the proxy these sliders are adjusted so that one step on the slider - moves the range by one segment step: - - \snippet surface/surfacegraph.cpp 8 - - The ranges are set for the axes like this: - - \snippet surface/surfacegraph.cpp 5 - - \section1 Themes - - Q3DSurface supports all the themes Qt Data Visualization has. The example has a pull - down menu for selecting the theme. The following method is connected to the - menu to activate the selected theme. The theme type is changed to another predefined theme, - which overwrites all theme properties to predefined values: - - \snippet surface/surfacegraph.cpp 6 - - \section1 Custom Surface Gradients - - The example demonstrates the custom surface gradients with two push buttons. The gradient - can be defined with QLinearGradient where the desired colors are set to positions. The following - code shows how to create an example gradient and set it to the series. Note that you also need - to change the color style to Q3DTheme::ColorStyleRangeGradient to actually use the gradient. - - \snippet surface/surfacegraph.cpp 7 -*/ diff --git a/examples/datavisualization/surface/main.cpp b/examples/datavisualization/surface/main.cpp deleted file mode 100644 index d8ac30c5..00000000 --- a/examples/datavisualization/surface/main.cpp +++ /dev/null @@ -1,231 +0,0 @@ -/**************************************************************************** -** -** 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 "surfacegraph.h" - -#include <QtWidgets/QApplication> -#include <QtWidgets/QWidget> -#include <QtWidgets/QHBoxLayout> -#include <QtWidgets/QVBoxLayout> -#include <QtWidgets/QPushButton> -#include <QtWidgets/QRadioButton> -#include <QtWidgets/QSlider> -#include <QtWidgets/QGroupBox> -#include <QtWidgets/QComboBox> -#include <QtWidgets/QLabel> -#include <QtWidgets/QMessageBox> -#include <QtGui/QPainter> -#include <QtGui/QScreen> - -int main(int argc, char **argv) -{ - qputenv("QSG_RHI_BACKEND", "opengl"); - //! [0] - QApplication app(argc, argv); - Q3DSurface *graph = new Q3DSurface(); - QWidget *container = QWidget::createWindowContainer(graph); - //! [0] - - if (!graph->hasContext()) { - QMessageBox msgBox; - msgBox.setText("Couldn't initialize the OpenGL context."); - msgBox.exec(); - return -1; - } - - QSize screenSize = graph->screen()->size(); - container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.6)); - 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); - vLayout->setAlignment(Qt::AlignTop); - //! [1] - - widget->setWindowTitle(QStringLiteral("Surface example")); - - QGroupBox *modelGroupBox = new QGroupBox(QStringLiteral("Model")); - - QRadioButton *sqrtSinModelRB = new QRadioButton(widget); - sqrtSinModelRB->setText(QStringLiteral("Sqrt && Sin")); - sqrtSinModelRB->setChecked(false); - - QRadioButton *heightMapModelRB = new QRadioButton(widget); - heightMapModelRB->setText(QStringLiteral("Height Map")); - heightMapModelRB->setChecked(false); - - QVBoxLayout *modelVBox = new QVBoxLayout; - modelVBox->addWidget(sqrtSinModelRB); - modelVBox->addWidget(heightMapModelRB); - modelGroupBox->setLayout(modelVBox); - - QGroupBox *selectionGroupBox = new QGroupBox(QStringLiteral("Selection Mode")); - - QRadioButton *modeNoneRB = new QRadioButton(widget); - modeNoneRB->setText(QStringLiteral("No selection")); - modeNoneRB->setChecked(false); - - QRadioButton *modeItemRB = new QRadioButton(widget); - modeItemRB->setText(QStringLiteral("Item")); - modeItemRB->setChecked(false); - - QRadioButton *modeSliceRowRB = new QRadioButton(widget); - modeSliceRowRB->setText(QStringLiteral("Row Slice")); - modeSliceRowRB->setChecked(false); - - QRadioButton *modeSliceColumnRB = new QRadioButton(widget); - modeSliceColumnRB->setText(QStringLiteral("Column Slice")); - modeSliceColumnRB->setChecked(false); - - QVBoxLayout *selectionVBox = new QVBoxLayout; - selectionVBox->addWidget(modeNoneRB); - selectionVBox->addWidget(modeItemRB); - selectionVBox->addWidget(modeSliceRowRB); - selectionVBox->addWidget(modeSliceColumnRB); - selectionGroupBox->setLayout(selectionVBox); - - QSlider *axisMinSliderX = new QSlider(Qt::Horizontal, widget); - axisMinSliderX->setMinimum(0); - axisMinSliderX->setTickInterval(1); - axisMinSliderX->setEnabled(true); - QSlider *axisMaxSliderX = new QSlider(Qt::Horizontal, widget); - axisMaxSliderX->setMinimum(1); - axisMaxSliderX->setTickInterval(1); - axisMaxSliderX->setEnabled(true); - QSlider *axisMinSliderZ = new QSlider(Qt::Horizontal, widget); - axisMinSliderZ->setMinimum(0); - axisMinSliderZ->setTickInterval(1); - axisMinSliderZ->setEnabled(true); - QSlider *axisMaxSliderZ = new QSlider(Qt::Horizontal, widget); - axisMaxSliderZ->setMinimum(1); - axisMaxSliderZ->setTickInterval(1); - axisMaxSliderZ->setEnabled(true); - - 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")); - - QGroupBox *colorGroupBox = new QGroupBox(QStringLiteral("Custom gradient")); - - QLinearGradient grBtoY(0, 0, 1, 100); - grBtoY.setColorAt(1.0, Qt::black); - grBtoY.setColorAt(0.67, Qt::blue); - grBtoY.setColorAt(0.33, Qt::red); - grBtoY.setColorAt(0.0, Qt::yellow); - QPixmap pm(24, 100); - QPainter pmp(&pm); - pmp.setBrush(QBrush(grBtoY)); - pmp.setPen(Qt::NoPen); - pmp.drawRect(0, 0, 24, 100); - QPushButton *gradientBtoYPB = new QPushButton(widget); - gradientBtoYPB->setIcon(QIcon(pm)); - gradientBtoYPB->setIconSize(QSize(24, 100)); - - QLinearGradient grGtoR(0, 0, 1, 100); - grGtoR.setColorAt(1.0, Qt::darkGreen); - grGtoR.setColorAt(0.5, Qt::yellow); - grGtoR.setColorAt(0.2, Qt::red); - grGtoR.setColorAt(0.0, Qt::darkRed); - pmp.setBrush(QBrush(grGtoR)); - pmp.drawRect(0, 0, 24, 100); - QPushButton *gradientGtoRPB = new QPushButton(widget); - gradientGtoRPB->setIcon(QIcon(pm)); - gradientGtoRPB->setIconSize(QSize(24, 100)); - - QHBoxLayout *colorHBox = new QHBoxLayout; - colorHBox->addWidget(gradientBtoYPB); - colorHBox->addWidget(gradientGtoRPB); - colorGroupBox->setLayout(colorHBox); - - vLayout->addWidget(modelGroupBox); - vLayout->addWidget(selectionGroupBox); - vLayout->addWidget(new QLabel(QStringLiteral("Column range"))); - vLayout->addWidget(axisMinSliderX); - vLayout->addWidget(axisMaxSliderX); - vLayout->addWidget(new QLabel(QStringLiteral("Row range"))); - vLayout->addWidget(axisMinSliderZ); - vLayout->addWidget(axisMaxSliderZ); - vLayout->addWidget(new QLabel(QStringLiteral("Theme"))); - vLayout->addWidget(themeList); - vLayout->addWidget(colorGroupBox); - - widget->show(); - - SurfaceGraph *modifier = new SurfaceGraph(graph); - - QObject::connect(heightMapModelRB, &QRadioButton::toggled, - modifier, &SurfaceGraph::enableHeightMapModel); - QObject::connect(sqrtSinModelRB, &QRadioButton::toggled, - modifier, &SurfaceGraph::enableSqrtSinModel); - QObject::connect(modeNoneRB, &QRadioButton::toggled, - modifier, &SurfaceGraph::toggleModeNone); - QObject::connect(modeItemRB, &QRadioButton::toggled, - modifier, &SurfaceGraph::toggleModeItem); - QObject::connect(modeSliceRowRB, &QRadioButton::toggled, - modifier, &SurfaceGraph::toggleModeSliceRow); - QObject::connect(modeSliceColumnRB, &QRadioButton::toggled, - modifier, &SurfaceGraph::toggleModeSliceColumn); - QObject::connect(axisMinSliderX, &QSlider::valueChanged, - modifier, &SurfaceGraph::adjustXMin); - QObject::connect(axisMaxSliderX, &QSlider::valueChanged, - modifier, &SurfaceGraph::adjustXMax); - QObject::connect(axisMinSliderZ, &QSlider::valueChanged, - modifier, &SurfaceGraph::adjustZMin); - QObject::connect(axisMaxSliderZ, &QSlider::valueChanged, - modifier, &SurfaceGraph::adjustZMax); - QObject::connect(themeList, SIGNAL(currentIndexChanged(int)), - modifier, SLOT(changeTheme(int))); - QObject::connect(gradientBtoYPB, &QPushButton::pressed, - modifier, &SurfaceGraph::setBlackToYellowGradient); - QObject::connect(gradientGtoRPB, &QPushButton::pressed, - modifier, &SurfaceGraph::setGreenToRedGradient); - - modifier->setAxisMinSliderX(axisMinSliderX); - modifier->setAxisMaxSliderX(axisMaxSliderX); - modifier->setAxisMinSliderZ(axisMinSliderZ); - modifier->setAxisMaxSliderZ(axisMaxSliderZ); - - sqrtSinModelRB->setChecked(true); - modeItemRB->setChecked(true); - themeList->setCurrentIndex(2); - - return app.exec(); -} diff --git a/examples/datavisualization/surface/mountain.png b/examples/datavisualization/surface/mountain.png Binary files differdeleted file mode 100644 index 9138c710..00000000 --- a/examples/datavisualization/surface/mountain.png +++ /dev/null diff --git a/examples/datavisualization/surface/surface.pro b/examples/datavisualization/surface/surface.pro deleted file mode 100644 index a49fa468..00000000 --- a/examples/datavisualization/surface/surface.pro +++ /dev/null @@ -1,20 +0,0 @@ -android|ios|winrt { - error( "This example is not supported for android, ios, or winrt." ) -} - -!include( ../examples.pri ) { - error( "Couldn't find the examples.pri file!" ) -} - -SOURCES += main.cpp \ - surfacegraph.cpp - -HEADERS += surfacegraph.h - -QT += widgets -requires(qtConfig(combobox)) - -RESOURCES += surface.qrc - -OTHER_FILES += doc/src/* \ - doc/images/* diff --git a/examples/datavisualization/surface/surface.qrc b/examples/datavisualization/surface/surface.qrc deleted file mode 100644 index e4a7c38b..00000000 --- a/examples/datavisualization/surface/surface.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="/maps"> - <file alias="mountain">mountain.png</file> - </qresource> -</RCC> diff --git a/examples/datavisualization/surface/surfacegraph.cpp b/examples/datavisualization/surface/surfacegraph.cpp deleted file mode 100644 index 08c35be7..00000000 --- a/examples/datavisualization/surface/surfacegraph.cpp +++ /dev/null @@ -1,277 +0,0 @@ -/**************************************************************************** -** -** 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 "surfacegraph.h" - -#include <QtDataVisualization/QValue3DAxis> -#include <QtDataVisualization/Q3DTheme> -#include <QtGui/QImage> -#include <QtCore/qmath.h> - -const int sampleCountX = 50; -const int sampleCountZ = 50; -const int heightMapGridStepX = 6; -const int heightMapGridStepZ = 6; -const float sampleMin = -8.0f; -const float sampleMax = 8.0f; - -SurfaceGraph::SurfaceGraph(Q3DSurface *surface) - : m_graph(surface) -{ - m_graph->setAxisX(new QValue3DAxis); - m_graph->setAxisY(new QValue3DAxis); - m_graph->setAxisZ(new QValue3DAxis); - - //! [0] - m_sqrtSinProxy = new QSurfaceDataProxy(); - m_sqrtSinSeries = new QSurface3DSeries(m_sqrtSinProxy); - //! [0] - fillSqrtSinProxy(); - - //! [2] - QImage heightMapImage(":/maps/mountain"); - m_heightMapProxy = new QHeightMapSurfaceDataProxy(heightMapImage); - m_heightMapSeries = new QSurface3DSeries(m_heightMapProxy); - m_heightMapSeries->setItemLabelFormat(QStringLiteral("(@xLabel, @zLabel): @yLabel")); - m_heightMapProxy->setValueRanges(34.0f, 40.0f, 18.0f, 24.0f); - //! [2] - m_heightMapWidth = heightMapImage.width(); - m_heightMapHeight = heightMapImage.height(); -} - -SurfaceGraph::~SurfaceGraph() -{ - delete m_graph; -} - -//! [1] -void SurfaceGraph::fillSqrtSinProxy() -{ - float stepX = (sampleMax - sampleMin) / float(sampleCountX - 1); - float stepZ = (sampleMax - sampleMin) / float(sampleCountZ - 1); - - QSurfaceDataArray *dataArray = new QSurfaceDataArray; - dataArray->reserve(sampleCountZ); - for (int i = 0 ; i < sampleCountZ ; i++) { - QSurfaceDataRow *newRow = new QSurfaceDataRow(sampleCountX); - // Keep values within range bounds, since just adding step can cause minor drift due - // to the rounding errors. - float z = qMin(sampleMax, (i * stepZ + sampleMin)); - int index = 0; - for (int j = 0; j < sampleCountX; j++) { - float x = qMin(sampleMax, (j * stepX + sampleMin)); - float R = qSqrt(z * z + x * x) + 0.01f; - float y = (qSin(R) / R + 0.24f) * 1.61f; - (*newRow)[index++].setPosition(QVector3D(x, y, z)); - } - *dataArray << newRow; - } - - m_sqrtSinProxy->resetArray(dataArray); -} -//! [1] - -void SurfaceGraph::enableSqrtSinModel(bool enable) -{ - if (enable) { - //! [3] - m_sqrtSinSeries->setDrawMode(QSurface3DSeries::DrawSurfaceAndWireframe); - m_sqrtSinSeries->setFlatShadingEnabled(true); - - m_graph->axisX()->setLabelFormat("%.2f"); - m_graph->axisZ()->setLabelFormat("%.2f"); - m_graph->axisX()->setRange(sampleMin, sampleMax); - m_graph->axisY()->setRange(0.0f, 2.0f); - m_graph->axisZ()->setRange(sampleMin, sampleMax); - m_graph->axisX()->setLabelAutoRotation(30); - m_graph->axisY()->setLabelAutoRotation(90); - m_graph->axisZ()->setLabelAutoRotation(30); - - m_graph->removeSeries(m_heightMapSeries); - m_graph->addSeries(m_sqrtSinSeries); - //! [3] - - //! [8] - // Reset range sliders for Sqrt&Sin - m_rangeMinX = sampleMin; - m_rangeMinZ = sampleMin; - m_stepX = (sampleMax - sampleMin) / float(sampleCountX - 1); - m_stepZ = (sampleMax - sampleMin) / float(sampleCountZ - 1); - m_axisMinSliderX->setMaximum(sampleCountX - 2); - m_axisMinSliderX->setValue(0); - m_axisMaxSliderX->setMaximum(sampleCountX - 1); - m_axisMaxSliderX->setValue(sampleCountX - 1); - m_axisMinSliderZ->setMaximum(sampleCountZ - 2); - m_axisMinSliderZ->setValue(0); - m_axisMaxSliderZ->setMaximum(sampleCountZ - 1); - m_axisMaxSliderZ->setValue(sampleCountZ - 1); - //! [8] - } -} - -void SurfaceGraph::enableHeightMapModel(bool enable) -{ - if (enable) { - //! [4] - m_heightMapSeries->setDrawMode(QSurface3DSeries::DrawSurface); - m_heightMapSeries->setFlatShadingEnabled(false); - - m_graph->axisX()->setLabelFormat("%.1f N"); - m_graph->axisZ()->setLabelFormat("%.1f E"); - m_graph->axisX()->setRange(34.0f, 40.0f); - m_graph->axisY()->setAutoAdjustRange(true); - m_graph->axisZ()->setRange(18.0f, 24.0f); - - m_graph->axisX()->setTitle(QStringLiteral("Latitude")); - m_graph->axisY()->setTitle(QStringLiteral("Height")); - m_graph->axisZ()->setTitle(QStringLiteral("Longitude")); - - m_graph->removeSeries(m_sqrtSinSeries); - m_graph->addSeries(m_heightMapSeries); - //! [4] - - // Reset range sliders for height map - int mapGridCountX = m_heightMapWidth / heightMapGridStepX; - int mapGridCountZ = m_heightMapHeight / heightMapGridStepZ; - m_rangeMinX = 34.0f; - m_rangeMinZ = 18.0f; - m_stepX = 6.0f / float(mapGridCountX - 1); - m_stepZ = 6.0f / float(mapGridCountZ - 1); - m_axisMinSliderX->setMaximum(mapGridCountX - 2); - m_axisMinSliderX->setValue(0); - m_axisMaxSliderX->setMaximum(mapGridCountX - 1); - m_axisMaxSliderX->setValue(mapGridCountX - 1); - m_axisMinSliderZ->setMaximum(mapGridCountZ - 2); - m_axisMinSliderZ->setValue(0); - m_axisMaxSliderZ->setMaximum(mapGridCountZ - 1); - m_axisMaxSliderZ->setValue(mapGridCountZ - 1); - } -} - -void SurfaceGraph::adjustXMin(int min) -{ - float minX = m_stepX * float(min) + m_rangeMinX; - - int max = m_axisMaxSliderX->value(); - if (min >= max) { - max = min + 1; - m_axisMaxSliderX->setValue(max); - } - float maxX = m_stepX * max + m_rangeMinX; - - setAxisXRange(minX, maxX); -} - -void SurfaceGraph::adjustXMax(int max) -{ - float maxX = m_stepX * float(max) + m_rangeMinX; - - int min = m_axisMinSliderX->value(); - if (max <= min) { - min = max - 1; - m_axisMinSliderX->setValue(min); - } - float minX = m_stepX * min + m_rangeMinX; - - setAxisXRange(minX, maxX); -} - -void SurfaceGraph::adjustZMin(int min) -{ - float minZ = m_stepZ * float(min) + m_rangeMinZ; - - int max = m_axisMaxSliderZ->value(); - if (min >= max) { - max = min + 1; - m_axisMaxSliderZ->setValue(max); - } - float maxZ = m_stepZ * max + m_rangeMinZ; - - setAxisZRange(minZ, maxZ); -} - -void SurfaceGraph::adjustZMax(int max) -{ - float maxX = m_stepZ * float(max) + m_rangeMinZ; - - int min = m_axisMinSliderZ->value(); - if (max <= min) { - min = max - 1; - m_axisMinSliderZ->setValue(min); - } - float minX = m_stepZ * min + m_rangeMinZ; - - setAxisZRange(minX, maxX); -} - -//! [5] -void SurfaceGraph::setAxisXRange(float min, float max) -{ - m_graph->axisX()->setRange(min, max); -} - -void SurfaceGraph::setAxisZRange(float min, float max) -{ - m_graph->axisZ()->setRange(min, max); -} -//! [5] - -//! [6] -void SurfaceGraph::changeTheme(int theme) -{ - m_graph->activeTheme()->setType(Q3DTheme::Theme(theme)); -} -//! [6] - -void SurfaceGraph::setBlackToYellowGradient() -{ - //! [7] - QLinearGradient gr; - gr.setColorAt(0.0, Qt::black); - gr.setColorAt(0.33, Qt::blue); - gr.setColorAt(0.67, Qt::red); - gr.setColorAt(1.0, Qt::yellow); - - m_graph->seriesList().at(0)->setBaseGradient(gr); - m_graph->seriesList().at(0)->setColorStyle(Q3DTheme::ColorStyleRangeGradient); - //! [7] -} - -void SurfaceGraph::setGreenToRedGradient() -{ - QLinearGradient gr; - gr.setColorAt(0.0, Qt::darkGreen); - gr.setColorAt(0.5, Qt::yellow); - gr.setColorAt(0.8, Qt::red); - gr.setColorAt(1.0, Qt::darkRed); - - m_graph->seriesList().at(0)->setBaseGradient(gr); - m_graph->seriesList().at(0)->setColorStyle(Q3DTheme::ColorStyleRangeGradient); -} - diff --git a/examples/datavisualization/surface/surfacegraph.h b/examples/datavisualization/surface/surfacegraph.h deleted file mode 100644 index 3684fc9a..00000000 --- a/examples/datavisualization/surface/surfacegraph.h +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef SURFACEGRAPH_H -#define SURFACEGRAPH_H - -#include <QtDataVisualization/Q3DSurface> -#include <QtDataVisualization/QSurfaceDataProxy> -#include <QtDataVisualization/QHeightMapSurfaceDataProxy> -#include <QtDataVisualization/QSurface3DSeries> -#include <QtWidgets/QSlider> - -class SurfaceGraph : public QObject -{ - Q_OBJECT -public: - explicit SurfaceGraph(Q3DSurface *surface); - ~SurfaceGraph(); - - void enableHeightMapModel(bool enable); - void enableSqrtSinModel(bool enable); - - //! [0] - void toggleModeNone() { m_graph->setSelectionMode(QAbstract3DGraph::SelectionNone); } - void toggleModeItem() { m_graph->setSelectionMode(QAbstract3DGraph::SelectionItem); } - void toggleModeSliceRow() { m_graph->setSelectionMode(QAbstract3DGraph::SelectionItemAndRow - | QAbstract3DGraph::SelectionSlice); } - void toggleModeSliceColumn() { m_graph->setSelectionMode(QAbstract3DGraph::SelectionItemAndColumn - | QAbstract3DGraph::SelectionSlice); } - //! [0] - - void setBlackToYellowGradient(); - void setGreenToRedGradient(); - - void setAxisMinSliderX(QSlider *slider) { m_axisMinSliderX = slider; } - void setAxisMaxSliderX(QSlider *slider) { m_axisMaxSliderX = slider; } - void setAxisMinSliderZ(QSlider *slider) { m_axisMinSliderZ = slider; } - void setAxisMaxSliderZ(QSlider *slider) { m_axisMaxSliderZ = slider; } - - void adjustXMin(int min); - void adjustXMax(int max); - void adjustZMin(int min); - void adjustZMax(int max); - -public Q_SLOTS: - void changeTheme(int theme); - -private: - Q3DSurface *m_graph; - QHeightMapSurfaceDataProxy *m_heightMapProxy; - QSurfaceDataProxy *m_sqrtSinProxy; - QSurface3DSeries *m_heightMapSeries; - QSurface3DSeries *m_sqrtSinSeries; - - QSlider *m_axisMinSliderX; - QSlider *m_axisMaxSliderX; - QSlider *m_axisMinSliderZ; - QSlider *m_axisMaxSliderZ; - float m_rangeMinX; - float m_rangeMinZ; - float m_stepX; - float m_stepZ; - int m_heightMapWidth; - int m_heightMapHeight; - - void setAxisXRange(float min, float max); - void setAxisZRange(float min, float max); - void fillSqrtSinProxy(); -}; - -#endif // SURFACEGRAPH_H |