summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Salmela <mika.salmela@digia.com>2014-08-21 09:55:23 +0300
committerMika Salmela <mika.salmela@digia.com>2014-08-21 10:09:04 +0300
commit8fab0a9cfcbed9deb47f4a9bd101434985c1c611 (patch)
tree4c884d30f6bed5ce7471a16884b734ab8a347763
parent7ef676c7cbe5e3a960a66150794be3a862642073 (diff)
Gradient to highlight series
Added a gradient to highlight series on textured surface example. Change-Id: I2fc17dfa79f986cf5b651d964eb3bcf5d65f1c80 Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
-rw-r--r--examples/datavisualization/texturesurface/custominputhandler.cpp2
-rw-r--r--examples/datavisualization/texturesurface/custominputhandler.h6
-rw-r--r--examples/datavisualization/texturesurface/doc/src/texturesurface.qdoc53
-rw-r--r--examples/datavisualization/texturesurface/highlightseries.cpp28
-rw-r--r--examples/datavisualization/texturesurface/highlightseries.h3
-rw-r--r--examples/datavisualization/texturesurface/main.cpp37
-rw-r--r--examples/datavisualization/texturesurface/surfacegraph.cpp11
-rw-r--r--examples/datavisualization/texturesurface/topographicseries.cpp2
8 files changed, 114 insertions, 28 deletions
diff --git a/examples/datavisualization/texturesurface/custominputhandler.cpp b/examples/datavisualization/texturesurface/custominputhandler.cpp
index 0f79feef..2510df54 100644
--- a/examples/datavisualization/texturesurface/custominputhandler.cpp
+++ b/examples/datavisualization/texturesurface/custominputhandler.cpp
@@ -21,8 +21,6 @@
#include <QtDataVisualization/Q3DCamera>
#include <QtCore/qmath.h>
-#include <QDebug>
-
CustomInputHandler::CustomInputHandler(QAbstract3DGraph *graph, QObject *parent) :
Q3DInputHandler(parent),
m_highlight(0),
diff --git a/examples/datavisualization/texturesurface/custominputhandler.h b/examples/datavisualization/texturesurface/custominputhandler.h
index 5307a6be..8bef990e 100644
--- a/examples/datavisualization/texturesurface/custominputhandler.h
+++ b/examples/datavisualization/texturesurface/custominputhandler.h
@@ -40,15 +40,15 @@ class CustomInputHandler : public Q3DInputHandler
public:
explicit CustomInputHandler(QAbstract3DGraph *graph, QObject *parent = 0);
- inline void setLimits(float min, float max) {
+ inline void setLimits(float min, float max, float minRange) {
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;
+ m_axisXMinRange = minRange;
+ m_axisZMinRange = minRange;
}
inline void setAxes(QValue3DAxis *axisX, QValue3DAxis *axisY, QValue3DAxis *axisZ) {
m_axisX = axisX;
diff --git a/examples/datavisualization/texturesurface/doc/src/texturesurface.qdoc b/examples/datavisualization/texturesurface/doc/src/texturesurface.qdoc
index a4aa219e..483b8110 100644
--- a/examples/datavisualization/texturesurface/doc/src/texturesurface.qdoc
+++ b/examples/datavisualization/texturesurface/doc/src/texturesurface.qdoc
@@ -21,14 +21,15 @@
\title Textured Surface Example
\ingroup qtdatavisualization_examples
\brief Using texture with Q3DSurface.
+ \since QtDataVisualization 1.2
The textured surface example shows how to add an image as a texture for a surface. The example
shows also how to:
\list
\li Create a surface series from an image
- \li Highlight an area of the surface
\li Use custom input handler to enable zooming and panning
+ \li Highlight an area of the surface
\endlist
\image texturesurface-example.png
@@ -64,6 +65,28 @@
And then the actual decoding.
\snippet texturesurface/topographicseries.cpp 1
+ \section1 Use custom input handler to enable zooming and panning
+
+ For the panning the implementation is similar to the \l{Axis Range Dragging With Labels Example}.
+ The difference is that in this example we follow only dragging of X and Z axis and we don't
+ allow dragging the surface outside the graph. The control for this is very simple and done as
+ on the following example for the X axis.
+
+ \snippet texturesurface/custominputhandler.cpp 0
+
+ For the zooming we catch the \c wheelEvent and adjust the X and Y axis ranges according to delta
+ value on QWheelEvent. The Y axis is also adjusted so that the aspect ratio between Y axis and
+ XZ plane stays the same, and we don't get silly looking graph with height exaggerated too much.
+
+ \snippet texturesurface/custominputhandler.cpp 1
+
+ In this case we want to control the zoom level so that it won't get too near to or far from the
+ surface. For instance, if the value for the X axis gets below the allowed, i.e. zooming gets too
+ far, the value is set to the minimum allowed value. If the range is going to below the range
+ minimum, both ends of the axis are adjusted so that the range stays at the limit.
+
+ \snippet texturesurface/custominputhandler.cpp 2
+
\section1 Highlight an area of the surface
The main idea on creating a highlight on the surface is to create a copy of the series and add
@@ -81,25 +104,23 @@
\snippet texturesurface/highlightseries.cpp 1
- \section1 Use custom input handler to enable zooming and panning
+ \section1 A gradient to the highlight series
- For the panning the implementation is similar to the \l{Axis Range Dragging With Labels Example}.
- The difference is that in this example we follow only dragging of X and Z axis and we don't
- allow dragging the surface outside the graph. The control for this is very simple and done as
- on the following example for the X axis.
+ Since the \c HighlightSeries is QSurface3DSeries, we can use all the decoration methods series can
+ have. In this example we added a gradient to emphasize the elevation. Because the suitable gradient
+ style depends on the range of the Y axis and we change the range when zooming, we need to adjust
+ the gradient color positions as the range change.
- \snippet texturesurface/custominputhandler.cpp 0
+ For the gradient color positions we define proportional values.
- For the zooming we catch the \c wheelEvent and adjust the X and Y axis ranges according to delta
- value on QWheelEvent. The Y axis is also adjusted so that the aspect ratio between Y axis and
- XZ plane stays the same, and we don't get silly looking graph with height exaggerated too much.
+ \snippet texturesurface/highlightseries.cpp 2
- \snippet texturesurface/custominputhandler.cpp 1
+ The gradient modification is done on \c handleGradientChange method and we connect it to react to
+ changes on Y axis.
- In this case we want to control the zoom level so that it won't get too near to or far from the
- surface. For instance, if the value for the X axis gets below the allowed, i.e. zooming gets too
- far, the value is set to the minimum allowed value. If the range is going to below the range
- minimum, both ends of the axis are adjusted so that the range stays at the limit.
+ \snippet texturesurface/surfacegraph.cpp 1
- \snippet texturesurface/custominputhandler.cpp 2
+ When a change on Y axis max value happens, we calculate the gradient color positions.
+
+ \snippet texturesurface/highlightseries.cpp 3
*/
diff --git a/examples/datavisualization/texturesurface/highlightseries.cpp b/examples/datavisualization/texturesurface/highlightseries.cpp
index 7e5f7efb..13d1fba3 100644
--- a/examples/datavisualization/texturesurface/highlightseries.cpp
+++ b/examples/datavisualization/texturesurface/highlightseries.cpp
@@ -18,10 +18,16 @@
#include "highlightseries.h"
-#include <QDebug>
-
using namespace QtDataVisualization;
+//! [2]
+const float darkRedPos = 1.0f;
+const float redPos = 0.8f;
+const float yellowPos = 0.6f;
+const float greenPos = 0.4f;
+const float darkGreenPos = 0.2f;
+//! [2]
+
HighlightSeries::HighlightSeries()
: m_width(100),
m_height(100)
@@ -93,3 +99,21 @@ void HighlightSeries::handlePositionChange(const QPoint &position)
setVisible(true);
}
//! [1]
+
+//! [3]
+void HighlightSeries::handleGradientChange(float value)
+{
+ float ratio = m_minHeight / value;
+
+ QLinearGradient gr;
+ gr.setColorAt(0.0f, Qt::black);
+ gr.setColorAt(darkGreenPos * ratio, Qt::darkGreen);
+ gr.setColorAt(greenPos * ratio, Qt::green);
+ gr.setColorAt(yellowPos * ratio, Qt::yellow);
+ gr.setColorAt(redPos * ratio, Qt::red);
+ gr.setColorAt(darkRedPos * ratio, Qt::darkRed);
+
+ setBaseGradient(gr);
+ setColorStyle(Q3DTheme::ColorStyleRangeGradient);
+}
+//! [3]
diff --git a/examples/datavisualization/texturesurface/highlightseries.h b/examples/datavisualization/texturesurface/highlightseries.h
index 36361fbc..aa1590e5 100644
--- a/examples/datavisualization/texturesurface/highlightseries.h
+++ b/examples/datavisualization/texturesurface/highlightseries.h
@@ -33,9 +33,11 @@ public:
~HighlightSeries();
void setTopographicSeries(TopographicSeries *series);
+ inline void setMinHeight(float height) { m_minHeight = height; }
public slots:
void handlePositionChange(const QPoint &position);
+ void handleGradientChange(float value);
private:
int m_width;
@@ -44,6 +46,7 @@ private:
int m_srcHeight;
QPoint m_position;
TopographicSeries *m_topographicSeries;
+ float m_minHeight;
};
#endif // HIGHLIGHTSERIES_H
diff --git a/examples/datavisualization/texturesurface/main.cpp b/examples/datavisualization/texturesurface/main.cpp
index e73dc864..ed1a9be4 100644
--- a/examples/datavisualization/texturesurface/main.cpp
+++ b/examples/datavisualization/texturesurface/main.cpp
@@ -22,8 +22,11 @@
#include <QtWidgets/QWidget>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QVBoxLayout>
+#include <QtWidgets/QGroupBox>
#include <QtWidgets/QCheckBox>
+#include <QtWidgets/QLabel>
#include <QtGui/QScreen>
+#include <QtGui/QPainter>
int main(int argc, char **argv)
{
@@ -49,7 +52,41 @@ int main(int argc, char **argv)
QCheckBox *enableTexture = new QCheckBox(widget);
enableTexture->setText(QStringLiteral("Surface texture"));
+ int height = 400;
+ int width = 100;
+ int border = 10;
+ QLinearGradient gr(0, 0, 1, height - 2 * border);
+ gr.setColorAt(1.0f, Qt::black);
+ gr.setColorAt(0.8f, Qt::darkGreen);
+ gr.setColorAt(0.6f, Qt::green);
+ gr.setColorAt(0.4f, Qt::yellow);
+ gr.setColorAt(0.2f, Qt::red);
+ gr.setColorAt(0.0f, Qt::darkRed);
+
+ QPixmap pm(width, height);
+ pm.fill(Qt::transparent);
+ QPainter pmp(&pm);
+ pmp.setBrush(QBrush(gr));
+ pmp.setPen(Qt::NoPen);
+ pmp.drawRect(border, border, 35, height - 2 * border);
+ pmp.setPen(Qt::black);
+ int step = (height - 2 * border) / 5;
+ for (int i = 0; i < 6; i++) {
+ int yPos = i * step + border;
+ pmp.drawLine(border, yPos, 55, yPos);
+ pmp.drawText(60, yPos + 2, QString("%1 m").arg(550 - (i * 110)));
+ }
+
+ QLabel *label = new QLabel(widget);
+ label->setPixmap(pm);
+
+ QGroupBox *heightMapGroupBox = new QGroupBox(QStringLiteral("Height color map"));
+ QVBoxLayout *colorMapVBox = new QVBoxLayout;
+ colorMapVBox->addWidget(label);
+ heightMapGroupBox->setLayout(colorMapVBox);
+
vLayout->addWidget(enableTexture);
+ vLayout->addWidget(heightMapGroupBox);
widget->show();
diff --git a/examples/datavisualization/texturesurface/surfacegraph.cpp b/examples/datavisualization/texturesurface/surfacegraph.cpp
index f85ef5c8..785cf576 100644
--- a/examples/datavisualization/texturesurface/surfacegraph.cpp
+++ b/examples/datavisualization/texturesurface/surfacegraph.cpp
@@ -22,13 +22,12 @@
#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;
+const float minRange = areaWidth * 0.49f;
SurfaceGraph::SurfaceGraph(Q3DSurface *surface)
: m_graph(surface)
@@ -56,6 +55,12 @@ SurfaceGraph::SurfaceGraph(Q3DSurface *surface)
m_highlight = new HighlightSeries();
m_highlight->setTopographicSeries(m_topography);
+ m_highlight->setMinHeight(minRange * aspectRatio);
+ m_highlight->handleGradientChange(areaWidth * aspectRatio);
+//! [1]
+ QObject::connect(m_graph->axisY(), &QValue3DAxis::maxChanged,
+ m_highlight, &HighlightSeries::handleGradientChange);
+//! [1]
m_graph->addSeries(m_topography);
m_graph->addSeries(m_highlight);
@@ -63,7 +68,7 @@ SurfaceGraph::SurfaceGraph(Q3DSurface *surface)
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->setLimits(0.0f, areaWidth, minRange);
m_inputHandler->setAspectRatio(aspectRatio);
m_graph->setActiveInputHandler(m_inputHandler);
diff --git a/examples/datavisualization/texturesurface/topographicseries.cpp b/examples/datavisualization/texturesurface/topographicseries.cpp
index a1c61f56..2fa29d35 100644
--- a/examples/datavisualization/texturesurface/topographicseries.cpp
+++ b/examples/datavisualization/texturesurface/topographicseries.cpp
@@ -18,8 +18,6 @@
#include "topographicseries.h"
-#include <QDebug>
-
using namespace QtDataVisualization;
//! [0]