summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/datavisualization/datavisualization.pro3
-rw-r--r--examples/datavisualization/texturesurface/custominputhandler.cpp178
-rw-r--r--examples/datavisualization/texturesurface/custominputhandler.h91
-rw-r--r--examples/datavisualization/texturesurface/doc/src/texturesurface.qdoc26
-rw-r--r--examples/datavisualization/texturesurface/highlightseries.cpp91
-rw-r--r--examples/datavisualization/texturesurface/highlightseries.h49
-rw-r--r--examples/datavisualization/texturesurface/main.cpp64
-rw-r--r--examples/datavisualization/texturesurface/maptexture.jpgbin0 -> 352922 bytes
-rw-r--r--examples/datavisualization/texturesurface/surfacegraph.cpp78
-rw-r--r--examples/datavisualization/texturesurface/surfacegraph.h52
-rw-r--r--examples/datavisualization/texturesurface/texturedsurface.qrc6
-rw-r--r--examples/datavisualization/texturesurface/texturesurface.pro25
-rw-r--r--examples/datavisualization/texturesurface/topographicseries.cpp69
-rw-r--r--examples/datavisualization/texturesurface/topographicseries.h45
-rw-r--r--examples/datavisualization/texturesurface/topography.pngbin0 -> 395504 bytes
15 files changed, 776 insertions, 1 deletions
diff --git a/examples/datavisualization/datavisualization.pro b/examples/datavisualization/datavisualization.pro
index c078630d..cb861b81 100644
--- a/examples/datavisualization/datavisualization.pro
+++ b/examples/datavisualization/datavisualization.pro
@@ -20,7 +20,8 @@ SUBDIRS += qmlbars \
surface \
rotations \
draggableaxes \
- customitems
+ customitems \
+ texturesurface
}
qtHaveModule(multimedia):!android:!ios: SUBDIRS += audiolevels
diff --git a/examples/datavisualization/texturesurface/custominputhandler.cpp b/examples/datavisualization/texturesurface/custominputhandler.cpp
new file mode 100644
index 00000000..9072a0b4
--- /dev/null
+++ b/examples/datavisualization/texturesurface/custominputhandler.cpp
@@ -0,0 +1,178 @@
+/****************************************************************************
+**
+** 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 "custominputhandler.h"
+
+#include <QtDataVisualization/Q3DCamera>
+#include <QtCore/qmath.h>
+
+#include <QDebug>
+
+CustomInputHandler::CustomInputHandler(QAbstract3DGraph *graph, QObject *parent) :
+ Q3DInputHandler(parent),
+ m_highlight(0),
+ m_mousePressed(false),
+ m_state(StateNormal),
+ m_axisX(0),
+ m_axisZ(0),
+ m_speedModifier(20.0f)
+{
+ // Connect to the item selection signal from graph
+ connect(graph, &QAbstract3DGraph::selectedElementChanged, this,
+ &CustomInputHandler::handleElementSelected);
+}
+
+void CustomInputHandler::mousePressEvent(QMouseEvent *event, const QPoint &mousePos)
+{
+ if (Qt::LeftButton == event->button()) {
+ m_highlight->setVisible(false);
+ m_mousePressed = true;
+ }
+ Q3DInputHandler::mousePressEvent(event, mousePos);
+}
+
+void CustomInputHandler::wheelEvent(QWheelEvent *event)
+{
+ float delta = float(event->delta());
+
+ m_axisXMinValue += delta;
+ m_axisXMaxValue -= delta;
+ m_axisZMinValue += delta;
+ m_axisZMaxValue -= delta;
+ checkConstraints();
+
+ float y = (m_axisXMaxValue - m_axisXMinValue) * m_aspectRatio;
+
+ m_axisX->setRange(m_axisXMinValue, m_axisXMaxValue);
+ m_axisY->setRange(100.0f, y);
+ m_axisZ->setRange(m_axisZMinValue, m_axisZMaxValue);
+}
+
+void CustomInputHandler::mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos)
+{
+ // Check if we're trying to drag axis label
+ if (m_mousePressed && m_state != StateNormal) {
+ setPreviousInputPos(inputPosition());
+ setInputPosition(mousePos);
+ handleAxisDragging();
+ } else {
+ Q3DInputHandler::mouseMoveEvent(event, mousePos);
+ }
+}
+
+void CustomInputHandler::mouseReleaseEvent(QMouseEvent *event, const QPoint &mousePos)
+{
+ Q3DInputHandler::mouseReleaseEvent(event, mousePos);
+ m_mousePressed = false;
+ m_state = StateNormal;
+}
+
+void CustomInputHandler::handleElementSelected(QAbstract3DGraph::ElementType type)
+{
+ switch (type) {
+ case QAbstract3DGraph::ElementAxisXLabel:
+ m_state = StateDraggingX;
+ break;
+ case QAbstract3DGraph::ElementAxisZLabel:
+ m_state = StateDraggingZ;
+ break;
+ default:
+ m_state = StateNormal;
+ break;
+ }
+}
+
+void CustomInputHandler::handleAxisDragging()
+{
+ float distance = 0.0f;
+
+ // Get scene orientation from active camera
+ float xRotation = scene()->activeCamera()->xRotation();
+
+ // Calculate directional drag multipliers based on rotation
+ float xMulX = qCos(qDegreesToRadians(xRotation));
+ float xMulY = qSin(qDegreesToRadians(xRotation));
+ float zMulX = qSin(qDegreesToRadians(xRotation));
+ float zMulY = qCos(qDegreesToRadians(xRotation));
+
+ // Get the drag amount
+ QPoint move = inputPosition() - previousInputPos();
+
+ // Adjust axes
+ switch (m_state) {
+ case StateDraggingX:
+ distance = (move.x() * xMulX - move.y() * xMulY) * m_speedModifier;
+ m_axisXMinValue -= distance;
+ m_axisXMaxValue -= distance;
+ if (m_axisXMinValue < m_areaMinValue) {
+ float dist = m_axisXMaxValue - m_axisXMinValue;
+ m_axisXMinValue = m_areaMinValue;
+ m_axisXMaxValue = m_axisXMinValue + dist;
+ }
+ if (m_axisXMaxValue > m_areaMaxValue) {
+ float dist = m_axisXMaxValue - m_axisXMinValue;
+ m_axisXMaxValue = m_areaMaxValue;
+ m_axisXMinValue = m_axisXMaxValue - dist;
+ }
+ m_axisX->setRange(m_axisXMinValue, m_axisXMaxValue);
+ break;
+ case StateDraggingZ:
+ distance = (move.x() * zMulX + move.y() * zMulY) * m_speedModifier;
+ m_axisZMinValue += distance;
+ m_axisZMaxValue += distance;
+ if (m_axisZMinValue < m_areaMinValue) {
+ float dist = m_axisZMaxValue - m_axisZMinValue;
+ m_axisZMinValue = m_areaMinValue;
+ m_axisZMaxValue = m_axisZMinValue + dist;
+ }
+ if (m_axisZMaxValue > m_areaMaxValue) {
+ float dist = m_axisZMaxValue - m_axisZMinValue;
+ m_axisZMaxValue = m_areaMaxValue;
+ m_axisZMinValue = m_axisZMaxValue - dist;
+ }
+ m_axisZ->setRange(m_axisZMinValue, m_axisZMaxValue);
+ break;
+ default:
+ break;
+ }
+}
+
+void CustomInputHandler::checkConstraints()
+{
+ if (m_axisXMinValue < m_areaMinValue)
+ m_axisXMinValue = m_areaMinValue;
+ if (m_axisXMaxValue > m_areaMaxValue)
+ m_axisXMaxValue = m_areaMaxValue;
+ // Don't allow too much zoom in
+ if ((m_axisXMaxValue - m_axisXMinValue) < m_axisXMinRange) {
+ float adjust = (m_axisXMinRange - (m_axisXMaxValue - m_axisXMinValue)) / 2.0f;
+ m_axisXMinValue -= adjust;
+ m_axisXMaxValue += adjust;
+ }
+
+ if (m_axisZMinValue < m_areaMinValue)
+ m_axisZMinValue = m_areaMinValue;
+ if (m_axisZMaxValue > m_areaMaxValue)
+ m_axisZMaxValue = m_areaMaxValue;
+ // Don't allow too much zoom in
+ if ((m_axisZMaxValue - m_axisZMinValue) < m_axisZMinRange) {
+ float adjust = (m_axisZMinRange - (m_axisZMaxValue - m_axisZMinValue)) / 2.0f;
+ m_axisZMinValue -= adjust;
+ m_axisZMaxValue += adjust;
+ }
+}
diff --git a/examples/datavisualization/texturesurface/custominputhandler.h b/examples/datavisualization/texturesurface/custominputhandler.h
new file mode 100644
index 00000000..5307a6be
--- /dev/null
+++ b/examples/datavisualization/texturesurface/custominputhandler.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** 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
+**
+****************************************************************************/
+
+#ifndef CUSTOMINPUTHANDLER_H
+#define CUSTOMINPUTHANDLER_H
+
+#include <QtDataVisualization/Q3DInputHandler>
+#include <QtDataVisualization/QAbstract3DGraph>
+#include <QtDataVisualization/QValue3DAxis>
+#include "highlightseries.h"
+
+using namespace QtDataVisualization;
+
+class CustomInputHandler : public Q3DInputHandler
+{
+ Q_OBJECT
+
+ enum InputState {
+ StateNormal = 0,
+ StateDraggingX,
+ StateDraggingZ,
+ StateDraggingY
+ };
+
+public:
+ explicit CustomInputHandler(QAbstract3DGraph *graph, QObject *parent = 0);
+
+ inline void setLimits(float min, float max) {
+ m_areaMinValue = min;
+ m_areaMaxValue = max;
+ m_axisXMinValue = m_areaMinValue;
+ m_axisXMaxValue = m_areaMaxValue;
+ m_axisZMinValue = m_areaMinValue;
+ m_axisZMaxValue = m_areaMaxValue;
+ m_axisXMinRange = (m_areaMaxValue - m_areaMinValue) * 0.49f;
+ m_axisZMinRange = (m_areaMaxValue - m_areaMinValue) * 0.49f;
+ }
+ inline void setAxes(QValue3DAxis *axisX, QValue3DAxis *axisY, QValue3DAxis *axisZ) {
+ m_axisX = axisX;
+ m_axisY = axisY;
+ m_axisZ = axisZ;
+ }
+ inline void setAspectRatio(float ratio) { m_aspectRatio = ratio; }
+ inline void setHighlightSeries(HighlightSeries *series) { m_highlight = series; }
+ inline void setDragSpeedModifier(float modifier) { m_speedModifier = modifier; }
+
+ virtual void mousePressEvent(QMouseEvent *event, const QPoint &mousePos);
+ virtual void mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos);
+ virtual void mouseReleaseEvent(QMouseEvent *event, const QPoint &mousePos);
+ virtual void wheelEvent(QWheelEvent *event);
+
+private:
+ void handleElementSelected(QAbstract3DGraph::ElementType type);
+ void handleAxisDragging();
+ void checkConstraints();
+
+private:
+ HighlightSeries *m_highlight;
+ bool m_mousePressed;
+ InputState m_state;
+ QValue3DAxis *m_axisX;
+ QValue3DAxis *m_axisY;
+ QValue3DAxis *m_axisZ;
+ float m_speedModifier;
+ float m_aspectRatio;
+ float m_axisXMinValue;
+ float m_axisXMaxValue;
+ float m_axisXMinRange;
+ float m_axisZMinValue;
+ float m_axisZMaxValue;
+ float m_axisZMinRange;
+ float m_areaMinValue;
+ float m_areaMaxValue;
+};
+
+#endif
diff --git a/examples/datavisualization/texturesurface/doc/src/texturesurface.qdoc b/examples/datavisualization/texturesurface/doc/src/texturesurface.qdoc
new file mode 100644
index 00000000..ee93dd0a
--- /dev/null
+++ b/examples/datavisualization/texturesurface/doc/src/texturesurface.qdoc
@@ -0,0 +1,26 @@
+/****************************************************************************
+**
+** 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 texturesurface
+ \title Texture Surface Example
+ \ingroup qtdatavisualization_examples
+ \brief Using texture with Q3DSurface.
+
+ TODO
+*/
diff --git a/examples/datavisualization/texturesurface/highlightseries.cpp b/examples/datavisualization/texturesurface/highlightseries.cpp
new file mode 100644
index 00000000..3584d1d4
--- /dev/null
+++ b/examples/datavisualization/texturesurface/highlightseries.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** 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 "highlightseries.h"
+
+#include <QDebug>
+
+using namespace QtDataVisualization;
+
+HighlightSeries::HighlightSeries()
+ : m_width(100),
+ m_height(100)
+{
+ setDrawMode(QSurface3DSeries::DrawSurface);
+ setFlatShadingEnabled(true);
+ setVisible(false);
+}
+
+HighlightSeries::~HighlightSeries()
+{
+}
+
+void HighlightSeries::setTopographicSeries(TopographicSeries *series)
+{
+ m_topographicSeries = series;
+ m_srcWidth = m_topographicSeries->dataProxy()->array()->at(0)->size();
+ m_srcHeight = m_topographicSeries->dataProxy()->array()->size();
+
+ QObject::connect(m_topographicSeries, &QSurface3DSeries::selectedPointChanged,
+ this, &HighlightSeries::handlePositionChange);
+}
+
+void HighlightSeries::handlePositionChange(const QPoint &position)
+{
+ m_position = position;
+
+ if (position == invalidSelectionPosition()) {
+ setVisible(false);
+
+ return;
+ }
+
+ int halfWidth = m_width / 2;
+ int halfHeight = m_height / 2;
+
+ int startX = position.y() - halfWidth;
+ if (startX < 0 )
+ startX = 0;
+ int endX = position.y() + halfWidth;
+ if (endX > (m_srcWidth - 1))
+ endX = m_srcWidth - 1;
+ int startZ = position.x() - halfHeight;
+ if (startZ < 0 )
+ startZ = 0;
+ int endZ = position.x() + halfHeight;
+ if (endZ > (m_srcHeight - 1))
+ endZ = m_srcHeight - 1;
+
+ QSurfaceDataProxy *srcProxy = m_topographicSeries->dataProxy();
+ const QSurfaceDataArray &srcArray = *srcProxy->array();
+
+ QSurfaceDataArray *dataArray = new QSurfaceDataArray;
+ dataArray->reserve(endZ - startZ);
+ for (int i = startZ; i < endZ; i++) {
+ QSurfaceDataRow *newRow = new QSurfaceDataRow(endX - startX);
+ QSurfaceDataRow *srcRow = srcArray.at(i);
+ for (int j = startX, p = 0; j < endX; j++, p++) {
+ QVector3D pos = srcRow->at(j).position();
+ (*newRow)[p].setPosition(QVector3D(pos.x(), pos.y() + 0.1f, pos.z()));
+ }
+ *dataArray << newRow;
+ }
+
+ dataProxy()->resetArray(dataArray);
+ setVisible(true);
+}
diff --git a/examples/datavisualization/texturesurface/highlightseries.h b/examples/datavisualization/texturesurface/highlightseries.h
new file mode 100644
index 00000000..36361fbc
--- /dev/null
+++ b/examples/datavisualization/texturesurface/highlightseries.h
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** 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
+**
+****************************************************************************/
+
+#ifndef HIGHLIGHTSERIES_H
+#define HIGHLIGHTSERIES_H
+
+#include <QtDataVisualization/QSurface3DSeries>
+
+#include "topographicseries.h"
+
+using namespace QtDataVisualization;
+
+class HighlightSeries : public QSurface3DSeries
+{
+ Q_OBJECT
+public:
+ explicit HighlightSeries();
+ ~HighlightSeries();
+
+ void setTopographicSeries(TopographicSeries *series);
+
+public slots:
+ void handlePositionChange(const QPoint &position);
+
+private:
+ int m_width;
+ int m_height;
+ int m_srcWidth;
+ int m_srcHeight;
+ QPoint m_position;
+ TopographicSeries *m_topographicSeries;
+};
+
+#endif // HIGHLIGHTSERIES_H
diff --git a/examples/datavisualization/texturesurface/main.cpp b/examples/datavisualization/texturesurface/main.cpp
new file mode 100644
index 00000000..e73dc864
--- /dev/null
+++ b/examples/datavisualization/texturesurface/main.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** 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 "surfacegraph.h"
+
+#include <QtWidgets/QApplication>
+#include <QtWidgets/QWidget>
+#include <QtWidgets/QHBoxLayout>
+#include <QtWidgets/QVBoxLayout>
+#include <QtWidgets/QCheckBox>
+#include <QtGui/QScreen>
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ Q3DSurface *graph = new Q3DSurface();
+ QWidget *container = QWidget::createWindowContainer(graph);
+
+ 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);
+
+ QWidget *widget = new QWidget;
+ QHBoxLayout *hLayout = new QHBoxLayout(widget);
+ QVBoxLayout *vLayout = new QVBoxLayout();
+ hLayout->addWidget(container, 1);
+ hLayout->addLayout(vLayout);
+ vLayout->setAlignment(Qt::AlignTop);
+
+ widget->setWindowTitle(QStringLiteral("Textured surface example"));
+
+ QCheckBox *enableTexture = new QCheckBox(widget);
+ enableTexture->setText(QStringLiteral("Surface texture"));
+
+ vLayout->addWidget(enableTexture);
+
+ widget->show();
+
+ SurfaceGraph *modifier = new SurfaceGraph(graph);
+
+ QObject::connect(enableTexture, &QCheckBox::stateChanged,
+ modifier, &SurfaceGraph::toggleSurfaceTexture);
+
+ enableTexture->setChecked(true);
+
+ return app.exec();
+}
diff --git a/examples/datavisualization/texturesurface/maptexture.jpg b/examples/datavisualization/texturesurface/maptexture.jpg
new file mode 100644
index 00000000..ae5d66eb
--- /dev/null
+++ b/examples/datavisualization/texturesurface/maptexture.jpg
Binary files differ
diff --git a/examples/datavisualization/texturesurface/surfacegraph.cpp b/examples/datavisualization/texturesurface/surfacegraph.cpp
new file mode 100644
index 00000000..b8e92988
--- /dev/null
+++ b/examples/datavisualization/texturesurface/surfacegraph.cpp
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** 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 "surfacegraph.h"
+#include "topographicseries.h"
+
+#include <QtDataVisualization/QValue3DAxis>
+#include <QtDataVisualization/Q3DTheme>
+
+#include <QDebug>
+
+using namespace QtDataVisualization;
+
+const float areaWidth = 8000.0f;
+const float areaHeight = 8000.0f;
+const float aspectRatio = 0.1389f;
+
+SurfaceGraph::SurfaceGraph(Q3DSurface *surface)
+ : m_graph(surface)
+{
+ m_graph->setAxisX(new QValue3DAxis);
+ m_graph->setAxisY(new QValue3DAxis);
+ m_graph->setAxisZ(new QValue3DAxis);
+ m_graph->axisX()->setLabelFormat("%i");
+ m_graph->axisZ()->setLabelFormat("%i");
+ m_graph->axisX()->setRange(0.0f, areaWidth);
+ m_graph->axisY()->setRange(100.0f, areaWidth * aspectRatio);
+ m_graph->axisZ()->setRange(0.0f, areaHeight);
+ m_graph->axisX()->setLabelAutoRotation(30);
+ m_graph->axisY()->setLabelAutoRotation(90);
+ m_graph->axisZ()->setLabelAutoRotation(30);
+
+ m_topography = new TopographicSeries();
+ m_topography->setTopographyFile(":/maps/topography", areaWidth, areaHeight);
+ m_topography->setItemLabelFormat(QStringLiteral("@yLabel m"));
+
+ m_highlight = new HighlightSeries();
+ m_highlight->setTopographicSeries(m_topography);
+
+ m_graph->addSeries(m_topography);
+ m_graph->addSeries(m_highlight);
+
+ m_inputHandler = new CustomInputHandler(m_graph);
+ m_inputHandler->setHighlightSeries(m_highlight);
+ m_inputHandler->setAxes(m_graph->axisX(), m_graph->axisY(), m_graph->axisZ());
+ m_inputHandler->setLimits(0.0f, areaWidth);
+ m_inputHandler->setAspectRatio(aspectRatio);
+
+ m_graph->setActiveInputHandler(m_inputHandler);
+}
+
+SurfaceGraph::~SurfaceGraph()
+{
+ delete m_graph;
+}
+
+void SurfaceGraph::toggleSurfaceTexture(bool enable)
+{
+ if (enable)
+ m_topography->setTextureFile(":/maps/maptexture");
+ else
+ m_topography->setTextureFile("");
+}
diff --git a/examples/datavisualization/texturesurface/surfacegraph.h b/examples/datavisualization/texturesurface/surfacegraph.h
new file mode 100644
index 00000000..c1d81595
--- /dev/null
+++ b/examples/datavisualization/texturesurface/surfacegraph.h
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** 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
+**
+****************************************************************************/
+
+#ifndef SURFACEGRAPH_H
+#define SURFACEGRAPH_H
+
+#include <QtDataVisualization/Q3DSurface>
+#include <QtDataVisualization/QSurface3DSeries>
+#include <QtWidgets/QSlider>
+#include "topographicseries.h"
+#include "highlightseries.h"
+
+#include "custominputhandler.h"
+
+using namespace QtDataVisualization;
+
+class SurfaceGraph : public QObject
+{
+ Q_OBJECT
+public:
+ explicit SurfaceGraph(Q3DSurface *surface);
+ ~SurfaceGraph();
+
+ void toggleSurfaceTexture(bool enable);
+
+private:
+ Q3DSurface *m_graph;
+
+ TopographicSeries *m_topography;
+ HighlightSeries *m_highlight;
+ int m_highlightWidth;
+ int m_highlightHeight;
+
+ CustomInputHandler *m_inputHandler;
+};
+
+#endif // SURFACEGRAPH_H
diff --git a/examples/datavisualization/texturesurface/texturedsurface.qrc b/examples/datavisualization/texturesurface/texturedsurface.qrc
new file mode 100644
index 00000000..94b96d24
--- /dev/null
+++ b/examples/datavisualization/texturesurface/texturedsurface.qrc
@@ -0,0 +1,6 @@
+<RCC>
+ <qresource prefix="/maps">
+ <file alias="topography">topography.png</file>
+ <file alias="maptexture">maptexture.jpg</file>
+ </qresource>
+</RCC>
diff --git a/examples/datavisualization/texturesurface/texturesurface.pro b/examples/datavisualization/texturesurface/texturesurface.pro
new file mode 100644
index 00000000..f24c3d17
--- /dev/null
+++ b/examples/datavisualization/texturesurface/texturesurface.pro
@@ -0,0 +1,25 @@
+android|ios {
+ error( "This example is not supported for android or ios." )
+}
+
+!include( ../examples.pri ) {
+ error( "Couldn't find the examples.pri file!" )
+}
+
+SOURCES += main.cpp \
+ surfacegraph.cpp \
+ topographicseries.cpp \
+ highlightseries.cpp \
+ custominputhandler.cpp
+
+HEADERS += surfacegraph.h \
+ topographicseries.h \
+ highlightseries.h \
+ custominputhandler.h
+
+QT += widgets
+
+RESOURCES += texturedsurface.qrc
+
+OTHER_FILES += doc/src/* \
+ doc/images/*
diff --git a/examples/datavisualization/texturesurface/topographicseries.cpp b/examples/datavisualization/texturesurface/topographicseries.cpp
new file mode 100644
index 00000000..1d94aead
--- /dev/null
+++ b/examples/datavisualization/texturesurface/topographicseries.cpp
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** 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 "topographicseries.h"
+
+#include <QDebug>
+
+using namespace QtDataVisualization;
+
+// Value used to encode height data as RGB value on PNG file
+const float packingFactor = 11983.0f;
+
+TopographicSeries::TopographicSeries()
+{
+ setDrawMode(QSurface3DSeries::DrawSurface);
+ setFlatShadingEnabled(true);
+}
+
+TopographicSeries::~TopographicSeries()
+{
+}
+
+void TopographicSeries::setTopographyFile(const QString file, float width, float height)
+{
+ QImage heightMapImage(file);
+ uchar *bits = heightMapImage.bits();
+ int imageHeight = heightMapImage.height();
+ int imageWidth = heightMapImage.width();
+ int widthBits = imageWidth * 4;
+ float stepX = width / float(imageWidth);
+ float stepZ = height / float(imageHeight);
+
+ QSurfaceDataArray *dataArray = new QSurfaceDataArray;
+ dataArray->reserve(imageHeight);
+ for (int i = 0; i < imageHeight; i++) {
+ int p = (imageHeight - 1 - i) * widthBits;
+ QSurfaceDataRow *newRow = new QSurfaceDataRow(imageWidth);
+ for (int j = 0; j < imageWidth; j++) {
+ uchar aa = bits[p + 0];
+ uchar rr = bits[p + 1];
+ uchar gg = bits[p + 2];
+ uint color = uint((gg << 16) + (rr << 8) + aa);
+ float y = float(color) / packingFactor;
+ (*newRow)[j].setPosition(QVector3D(float(j) * stepX, y, float(i) * stepZ));
+ p = p + 4;
+ }
+ *dataArray << newRow;
+ }
+
+ m_sampleCountX = float(imageWidth);
+ m_sampleCountZ = float(imageHeight);
+
+ dataProxy()->resetArray(dataArray);
+}
diff --git a/examples/datavisualization/texturesurface/topographicseries.h b/examples/datavisualization/texturesurface/topographicseries.h
new file mode 100644
index 00000000..06530c63
--- /dev/null
+++ b/examples/datavisualization/texturesurface/topographicseries.h
@@ -0,0 +1,45 @@
+/****************************************************************************
+**
+** 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
+**
+****************************************************************************/
+
+#ifndef TOPOGRAPHICSERIES_H
+#define TOPOGRAPHICSERIES_H
+
+#include <QtDataVisualization/QSurface3DSeries>
+
+using namespace QtDataVisualization;
+
+class TopographicSeries : public QSurface3DSeries
+{
+ Q_OBJECT
+public:
+ explicit TopographicSeries();
+ ~TopographicSeries();
+
+ void setTopographyFile(const QString file, float width, float height);
+
+ float sampleCountX() { return m_sampleCountX; }
+ float sampleCountZ() { return m_sampleCountZ; }
+
+public slots:
+
+private:
+ float m_sampleCountX;
+ float m_sampleCountZ;
+};
+
+#endif // TOPOGRAPHICSERIES_H
diff --git a/examples/datavisualization/texturesurface/topography.png b/examples/datavisualization/texturesurface/topography.png
new file mode 100644
index 00000000..9349cdb3
--- /dev/null
+++ b/examples/datavisualization/texturesurface/topography.png
Binary files differ