summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/engine
diff options
context:
space:
mode:
authorKeränen Pasi <pasi.keranen@digia.com>2013-09-27 09:05:53 +0300
committerPasi Keränen <pasi.keranen@digia.com>2013-10-08 10:50:41 +0300
commit66e1b09592efe77f839a0878ec6165a02408ca6f (patch)
tree709736fc6693c014abc0467a7c1ac766c1c62c4f /src/datavisualization/engine
parent0daa4359bdaba6372bc8235550892afdef003120 (diff)
Added Camera QML API and Example
Change-Id: Ibc790ac6c720b6d22d68f662ff2f50e74a9abaae Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src/datavisualization/engine')
-rw-r--r--src/datavisualization/engine/abstract3dcontroller.cpp72
-rw-r--r--src/datavisualization/engine/abstract3dcontroller_p.h14
-rw-r--r--src/datavisualization/engine/bars3drenderer.cpp10
-rw-r--r--src/datavisualization/engine/drawer.cpp7
-rw-r--r--src/datavisualization/engine/q3dbars.cpp37
-rw-r--r--src/datavisualization/engine/q3dbars.h11
-rw-r--r--src/datavisualization/engine/q3dcamera.cpp388
-rw-r--r--src/datavisualization/engine/q3dcamera.h90
-rw-r--r--src/datavisualization/engine/q3dcamera_p.h13
-rw-r--r--src/datavisualization/engine/q3dobject.cpp1
-rw-r--r--src/datavisualization/engine/q3dobject.h15
-rw-r--r--src/datavisualization/engine/q3dscatter.cpp37
-rw-r--r--src/datavisualization/engine/q3dscatter.h10
-rw-r--r--src/datavisualization/engine/q3dscene.cpp35
-rw-r--r--src/datavisualization/engine/q3dscene.h26
-rw-r--r--src/datavisualization/engine/q3dscene_p.h2
-rw-r--r--src/datavisualization/engine/q3dsurface.cpp36
-rw-r--r--src/datavisualization/engine/q3dsurface.h10
-rw-r--r--src/datavisualization/engine/scatter3drenderer.cpp4
-rw-r--r--src/datavisualization/engine/selectionpointer.cpp7
20 files changed, 555 insertions, 270 deletions
diff --git a/src/datavisualization/engine/abstract3dcontroller.cpp b/src/datavisualization/engine/abstract3dcontroller.cpp
index 3631bad1..e4286465 100644
--- a/src/datavisualization/engine/abstract3dcontroller.cpp
+++ b/src/datavisualization/engine/abstract3dcontroller.cpp
@@ -35,8 +35,6 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE
Abstract3DController::Abstract3DController(QRect boundRect, QObject *parent) :
QObject(parent),
m_boundingRect(boundRect.x(), boundRect.y(), boundRect.width(), boundRect.height()),
- m_horizontalRotation(-45.0f),
- m_verticalRotation(15.0f),
m_theme(),
m_font(QFont(QStringLiteral("Arial"))),
m_selectionMode(QDataVis::SelectionModeItem),
@@ -304,37 +302,49 @@ void Abstract3DController::render(const GLuint defaultFboHandle)
void Abstract3DController::mouseDoubleClickEvent(QMouseEvent *event)
{
- m_activeInputHandler->mouseDoubleClickEvent(event);
+ if (m_activeInputHandler)
+ m_activeInputHandler->mouseDoubleClickEvent(event);
+
emitNeedRender();
}
void Abstract3DController::touchEvent(QTouchEvent *event)
{
- m_activeInputHandler->touchEvent(event);
+ if (m_activeInputHandler)
+ m_activeInputHandler->touchEvent(event);
+
emitNeedRender();
}
void Abstract3DController::mousePressEvent(QMouseEvent *event, const QPoint &mousePos)
{
- m_activeInputHandler->mousePressEvent(event, mousePos);
+ if (m_activeInputHandler)
+ m_activeInputHandler->mousePressEvent(event, mousePos);
+
emitNeedRender();
}
void Abstract3DController::mouseReleaseEvent(QMouseEvent *event, const QPoint &mousePos)
{
- m_activeInputHandler->mouseReleaseEvent(event, mousePos);
+ if (m_activeInputHandler)
+ m_activeInputHandler->mouseReleaseEvent(event, mousePos);
+
emitNeedRender();
}
void Abstract3DController::mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos)
{
- m_activeInputHandler->mouseMoveEvent(event, mousePos);
+ if (m_activeInputHandler)
+ m_activeInputHandler->mouseMoveEvent(event, mousePos);
+
emitNeedRender();
}
void Abstract3DController::wheelEvent(QWheelEvent *event)
{
- m_activeInputHandler->wheelEvent(event);
+ if (m_activeInputHandler)
+ m_activeInputHandler->wheelEvent(event);
+
emitNeedRender();
}
@@ -609,6 +619,9 @@ void Abstract3DController::releaseInputHandler(QAbstract3DInputHandler *inputHan
void Abstract3DController::setActiveInputHandler(QAbstract3DInputHandler *inputHandler)
{
+ if (inputHandler == m_activeInputHandler)
+ return;
+
// If existing input handler is the default input handler, delete it
if (m_activeInputHandler) {
if (m_activeInputHandler->d_ptr->m_isDefaultHandler) {
@@ -621,10 +634,15 @@ void Abstract3DController::setActiveInputHandler(QAbstract3DInputHandler *inputH
}
// Assume ownership and connect to this controller's scene
- addInputHandler(inputHandler);
+ if (inputHandler)
+ addInputHandler(inputHandler);
+
m_activeInputHandler = inputHandler;
if (m_activeInputHandler)
m_activeInputHandler->setScene(m_scene);
+
+ // Notify change of input handler
+ emit activeInputHandlerChanged(m_activeInputHandler);
}
QAbstract3DInputHandler* Abstract3DController::activeInputHandler()
@@ -645,32 +663,6 @@ void Abstract3DController::setZoomLevel(int zoomLevel)
emitNeedRender();
}
-void Abstract3DController::setCameraPreset(QDataVis::CameraPreset preset)
-{
- m_scene->activeCamera()->setCameraPreset(preset);
- emitNeedRender();
-}
-
-QDataVis::CameraPreset Abstract3DController::cameraPreset() const
-{
- return m_scene->activeCamera()->cameraPreset();
-}
-
-void Abstract3DController::setCameraPosition(GLfloat horizontal, GLfloat vertical, GLint distance)
-{
- // disable camera movement if in slice view
- if (scene()->isSlicingActive())
- return;
-
- m_horizontalRotation = qBound(-180.0f, horizontal, 180.0f);
- m_verticalRotation = qBound(0.0f, vertical, 90.0f);
- m_scene->activeCamera()->setZoomLevel(qBound(10, distance, 500));
- m_scene->activeCamera()->setRotations(QPointF(m_horizontalRotation,
- m_verticalRotation));
- //qDebug() << "camera rotation set to" << m_horizontalRotation << m_verticalRotation;
- emitNeedRender();
-}
-
void Abstract3DController::setObjectColor(const QColor &baseColor, bool uniform)
{
m_theme.m_baseColor = baseColor;
@@ -787,12 +779,18 @@ void Abstract3DController::setSlicingActive(bool isSlicing)
QDataVis::InputState Abstract3DController::inputState()
{
- return m_activeInputHandler->inputState();
+ if (m_activeInputHandler)
+ return m_activeInputHandler->inputState();
+ else
+ return QDataVis::InputStateNone;
}
QPoint Abstract3DController::inputPosition()
{
- return m_activeInputHandler->inputPosition();
+ if (m_activeInputHandler)
+ return m_activeInputHandler->inputPosition();
+ else
+ return QPoint(0,0);
}
void Abstract3DController::setMeshFileName(const QString &fileName)
diff --git a/src/datavisualization/engine/abstract3dcontroller_p.h b/src/datavisualization/engine/abstract3dcontroller_p.h
index c857d5f1..f17c6c4d 100644
--- a/src/datavisualization/engine/abstract3dcontroller_p.h
+++ b/src/datavisualization/engine/abstract3dcontroller_p.h
@@ -29,8 +29,6 @@
#ifndef CONTROLLER3DBASE_H
#define CONTROLLER3DBASE_H
-#include <QObject>
-
#include "datavisualizationglobal_p.h"
#include "theme_p.h"
#include "q3dabstractaxis.h"
@@ -40,6 +38,8 @@
#include "q3dscene.h"
#include "q3dbox.h"
+#include <QObject>
+
class QFont;
QT_DATAVISUALIZATION_BEGIN_NAMESPACE
@@ -240,15 +240,6 @@ public:
virtual int zoomLevel();
virtual void setZoomLevel(int zoomLevel);
- // Select preset camera placement
- virtual void setCameraPreset(QDataVis::CameraPreset preset);
- virtual QDataVis::CameraPreset cameraPreset() const;
-
- // Set camera rotation if you don't want to use the presets (in horizontal (-180...180) and
- // vertical (0...90) (or (-90...90) if there are negative values) angles and distance in
- // percentage (10...500))
- virtual void setCameraPosition(GLfloat horizontal, GLfloat vertical, GLint distance = 100);
-
// Set color if you don't want to use themes.
virtual void setObjectColor(const QColor &baseColor, bool uniform = true);
virtual QColor objectColor() const;
@@ -324,6 +315,7 @@ public slots:
signals:
void shadowQualityChanged(QDataVis::ShadowQuality quality);
+ void activeInputHandlerChanged(QAbstract3DInputHandler *inputHandler);
void needRender();
protected:
diff --git a/src/datavisualization/engine/bars3drenderer.cpp b/src/datavisualization/engine/bars3drenderer.cpp
index 129ae924..38c4aa6a 100644
--- a/src/datavisualization/engine/bars3drenderer.cpp
+++ b/src/datavisualization/engine/bars3drenderer.cpp
@@ -209,7 +209,13 @@ void Bars3DRenderer::updateScene(Q3DScene *scene)
// TODO: Move these to more suitable place e.g. controller should be controlling the viewports.
scene->setSecondarySubViewport(m_sliceViewPort);
scene->setPrimarySubViewport(m_mainViewPort);
- scene->setUnderSideCameraEnabled(m_hasNegativeValues);
+
+ // TODO: See QTRD-2374
+ if (m_hasNegativeValues)
+ scene->activeCamera()->setMinYRotation(-90.0);
+ else
+ scene->activeCamera()->setMinYRotation(0.0);
+
if (m_hasHeightAdjustmentChanged) {
// Set initial camera position. Also update if height adjustment has changed.
scene->activeCamera()->setBaseOrientation(QVector3D(0.0f, 0.0f, cameraDistance + zComp),
@@ -256,7 +262,7 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel,
GLfloat negativesComp = 1.0f;
// Compensate bar scaling a bit to avoid drawing on axis titles when we have negative values
- if (m_cachedScene->isUnderSideCameraEnabled())
+ if (m_hasNegativeValues)
negativesComp = 0.67f;
// Specify viewport
diff --git a/src/datavisualization/engine/drawer.cpp b/src/datavisualization/engine/drawer.cpp
index 35623c99..9d50186d 100644
--- a/src/datavisualization/engine/drawer.cpp
+++ b/src/datavisualization/engine/drawer.cpp
@@ -316,9 +316,10 @@ void Drawer::drawLabel(const AbstractRenderItem &item, const LabelItem &labelIte
if (useDepth && !rotateAlong) {
qreal yComp = qreal(qRadiansToDegrees(qTan(positionComp.y() / cameraDistance)));
// Apply negative camera rotations to keep labels facing camera
- QPointF camRotations = camera->rotations();
- modelMatrix.rotate(-camRotations.x(), 0.0f, 1.0f, 0.0f);
- modelMatrix.rotate(-camRotations.y() - yComp, 1.0f, 0.0f, 0.0f);
+ qreal camRotationX = camera->xRotation();
+ qreal camRotationY = camera->yRotation();
+ modelMatrix.rotate(-camRotationX, 0.0f, 1.0f, 0.0f);
+ modelMatrix.rotate(-camRotationY - yComp, 1.0f, 0.0f, 0.0f);
}
// Scale label based on text size
diff --git a/src/datavisualization/engine/q3dbars.cpp b/src/datavisualization/engine/q3dbars.cpp
index ef0eb88b..6af18b1f 100644
--- a/src/datavisualization/engine/q3dbars.cpp
+++ b/src/datavisualization/engine/q3dbars.cpp
@@ -22,6 +22,7 @@
#include "q3dvalueaxis.h"
#include "q3dcategoryaxis.h"
#include "qbardataproxy.h"
+#include "q3dcamera.h"
#include <QMouseEvent>
@@ -253,32 +254,6 @@ void Q3DBars::setBarType(QDataVis::MeshStyle style, bool smooth)
}
/*!
- * \property Q3DBars::cameraPreset
- *
- * The \a preset position of the camera. The position can be one of \c QDataVis::CameraPreset.
- */
-void Q3DBars::setCameraPreset(QDataVis::CameraPreset preset)
-{
- d_ptr->m_shared->setCameraPreset(preset);
-}
-
-QDataVis::CameraPreset Q3DBars::cameraPreset() const
-{
- return d_ptr->m_shared->cameraPreset();
-}
-
-/*!
- * Move camera to a wanted position based on \a horizontal and \a vertical angles. Angles are limited
- * to -180...180 in horizontal direction and either -90...90 or 0...90 in vertical, depending
- * on data values. Negative vertical angles are allowed only if there are negative bar values.
- * \a distance is adjustable between 10 and 500, being \c 100 by default.
- */
-void Q3DBars::setCameraPosition(qreal horizontal, qreal vertical, int distance)
-{
- d_ptr->m_shared->setCameraPosition(GLfloat(horizontal), GLfloat(vertical), GLint(distance));
-}
-
-/*!
* Sets a predefined \a theme from \c QDataVis::Theme. It is preset to \c QDataVis::ThemeQt by
* default. Theme affects bar colors, label colors, text color, background color, window color and
* grid color. Lighting is also adjusted by themes.
@@ -367,6 +342,16 @@ QFont Q3DBars::font() const
}
/*!
+ * \property Q3DBars::scene
+ *
+ * This property contains the read only Q3DScene that can be used to access e.g. camera object.
+ */
+Q3DScene *Q3DBars::scene() const
+{
+ return d_ptr->m_shared->scene();
+}
+
+/*!
* \property Q3DBars::labelStyle
*
* Sets label \a style to one of \c QDataVis::LabelStyle. It is preset to
diff --git a/src/datavisualization/engine/q3dbars.h b/src/datavisualization/engine/q3dbars.h
index b62ebd32..d0ddf3fb 100644
--- a/src/datavisualization/engine/q3dbars.h
+++ b/src/datavisualization/engine/q3dbars.h
@@ -30,6 +30,7 @@ class Q3DAbstractAxis;
class Q3DCategoryAxis;
class Q3DValueAxis;
class QBarDataProxy;
+class Q3DScene;
class QT_DATAVISUALIZATION_EXPORT Q3DBars : public Q3DWindow
{
@@ -37,7 +38,6 @@ class QT_DATAVISUALIZATION_EXPORT Q3DBars : public Q3DWindow
Q_PROPERTY(QtDataVisualization::QDataVis::SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
Q_PROPERTY(QtDataVisualization::QDataVis::LabelStyle labelStyle READ labelStyle WRITE setLabelStyle)
Q_PROPERTY(QtDataVisualization::QDataVis::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality NOTIFY shadowQualityChanged)
- Q_PROPERTY(QtDataVisualization::QDataVis::CameraPreset cameraPreset READ cameraPreset WRITE setCameraPreset)
Q_PROPERTY(qreal barThickness READ barThickness WRITE setBarThickness)
Q_PROPERTY(QSizeF barSpacing READ barSpacing WRITE setBarSpacing)
Q_PROPERTY(bool barSpacingRelative READ isBarSpacingRelative WRITE setBarSpacingRelative)
@@ -46,6 +46,8 @@ class QT_DATAVISUALIZATION_EXPORT Q3DBars : public Q3DWindow
Q_PROPERTY(bool gridVisible READ isGridVisible WRITE setGridVisible)
Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible)
Q_PROPERTY(QPoint selectedBarPos READ selectedBarPos WRITE setSelectedBarPos NOTIFY selectedBarPosChanged)
+ Q_PROPERTY(Q3DScene* scene READ scene)
+
Q_ENUMS(QtDataVisualization::QDataVis::SelectionMode)
Q_ENUMS(QtDataVisualization::QDataVis::ShadowQuality)
Q_ENUMS(QtDataVisualization::QDataVis::LabelStyle)
@@ -57,11 +59,6 @@ public:
void setBarType(QDataVis::MeshStyle style, bool smooth = false);
- void setCameraPreset(QDataVis::CameraPreset preset);
- QDataVis::CameraPreset cameraPreset() const;
-
- void setCameraPosition(qreal horizontal, qreal vertical, int distance = 100);
-
void setTheme(QDataVis::Theme theme);
void setBarThickness(qreal thicknessRatio);
@@ -85,6 +82,8 @@ public:
void setFont(const QFont &font);
QFont font() const;
+ Q3DScene *scene() const;
+
void setLabelStyle(QDataVis::LabelStyle style);
QDataVis::LabelStyle labelStyle() const;
diff --git a/src/datavisualization/engine/q3dcamera.cpp b/src/datavisualization/engine/q3dcamera.cpp
index 6b91cac8..51973e02 100644
--- a/src/datavisualization/engine/q3dcamera.cpp
+++ b/src/datavisualization/engine/q3dcamera.cpp
@@ -21,6 +21,7 @@
#include "q3dscene.h"
#include "q3dbox.h"
#include "q3dobject.h"
+#include "utils_p.h"
#include <qmath.h>
#include <QVector3D>
@@ -79,28 +80,201 @@ void Q3DCamera::copyValuesFrom(const Q3DCamera &source)
d_ptr->m_xRotation = source.d_ptr->m_xRotation;
d_ptr->m_yRotation = source.d_ptr->m_yRotation;
+ d_ptr->m_minXRotation = source.d_ptr->m_minXRotation;
+ d_ptr->m_minYRotation = source.d_ptr->m_minYRotation;
+ d_ptr->m_maxXRotation = source.d_ptr->m_maxXRotation;
+ d_ptr->m_maxYRotation = source.d_ptr->m_maxYRotation;
+
+ d_ptr->m_wrapXRotation = source.d_ptr->m_wrapXRotation;
+ d_ptr->m_wrapYRotation = source.d_ptr->m_wrapYRotation;
+
d_ptr->m_zoomLevel = source.d_ptr->m_zoomLevel;
d_ptr->m_activePreset = source.d_ptr->m_activePreset;
}
/*!
- * \property Q3DCamera::rotations
+ * \property Q3DCamera::xRotation
*
- * This property contains the rotation angles of the camera around the target point in degrees starting from
+ * This property contains the X-rotation angle of the camera around the target point in degrees starting from
* the current base position set by the setBaseOrientation() methods.
*/
-QPointF Q3DCamera::rotations() const
+qreal Q3DCamera::xRotation() const {
+ return d_ptr->m_xRotation;
+}
+
+void Q3DCamera::setXRotation(qreal rotation)
{
- QPointF rotations(d_ptr->m_xRotation, d_ptr->m_yRotation);
- return rotations;
+ if (d_ptr->m_wrapXRotation)
+ rotation = Utils::wrapValue(rotation, d_ptr->m_minXRotation, d_ptr->m_maxXRotation);
+ else
+ rotation = qBound(qreal(d_ptr->m_minXRotation), qreal(rotation), qreal(d_ptr->m_maxXRotation));
+
+ if (d_ptr->m_xRotation != rotation) {
+ d_ptr->setXRotation(rotation);
+ if (d_ptr->m_activePreset != QDataVis::CameraPresetNone) {
+ d_ptr->m_activePreset = QDataVis::CameraPresetNone;
+ setDirty(true);
+ }
+
+ emit xRotationChanged(d_ptr->m_xRotation);
+ }
+}
+
+/*!
+ * \property Q3DCamera::yRotation
+ *
+ * This property contains the Y-rotation angle of the camera around the target point in degrees starting from
+ * the current base position set by the setBaseOrientation() methods.
+ */
+qreal Q3DCamera::yRotation() const {
+ return d_ptr->m_yRotation;
}
-void Q3DCamera::setRotations(const QPointF &rotation)
+void Q3DCamera::setYRotation(qreal rotation)
{
- d_ptr->setRotations(rotation);
- if (d_ptr->m_activePreset != QDataVis::CameraPresetNone) {
- d_ptr->m_activePreset = QDataVis::CameraPresetNone;
- setDirty(true);
+ if (d_ptr->m_wrapYRotation)
+ rotation = Utils::wrapValue(rotation, d_ptr->m_minYRotation, d_ptr->m_maxYRotation);
+ else
+ rotation = qBound(qreal(d_ptr->m_minYRotation), qreal(rotation), qreal(d_ptr->m_maxYRotation));
+
+ if (d_ptr->m_yRotation != rotation) {
+ d_ptr->setYRotation(rotation);
+ if (d_ptr->m_activePreset != QDataVis::CameraPresetNone) {
+ d_ptr->m_activePreset = QDataVis::CameraPresetNone;
+ setDirty(true);
+ }
+
+ emit yRotationChanged(d_ptr->m_yRotation);
+ }
+}
+
+/*!
+ * \property Q3DCamera::minXRotation
+ *
+ * This property contains the current minimum X-rotation for the camera.
+ * The full circle range is [-180,180] and the minimum value is limited to -180.
+ * Also the value can't be higher than maximum, and is adjusted if necessary.
+ *
+ * \sa wrapXRotation, maxXRotation
+ */
+qreal Q3DCamera::minXRotation() const
+{
+ return d_ptr->m_minXRotation;
+}
+
+/*!
+ * \internal
+ */
+void Q3DCamera::setMinXRotation(qreal minRotation)
+{
+ minRotation = qBound(-180.0, minRotation, 180.0);
+ if (minRotation > d_ptr->m_maxXRotation)
+ minRotation = d_ptr->m_maxXRotation;
+
+ if (d_ptr->m_minXRotation != minRotation) {
+ d_ptr->m_minXRotation = minRotation;
+ emit minXRotationChanged(minRotation);
+
+ if (d_ptr->m_xRotation < d_ptr->m_minXRotation)
+ setXRotation(d_ptr->m_xRotation);
+ }
+}
+
+/*!
+ * \property Q3DCamera::minYRotation
+ *
+ * This property contains the current minimum Y-rotation for the camera.
+ * The full Y angle range is [-90,90] and the minimum value is limited to -90.
+ * Also the value can't be higher than maximum, and is adjusted if necessary.
+ *
+ * \sa wrapYRotation, maxYRotation
+ */
+qreal Q3DCamera::minYRotation() const
+{
+ return d_ptr->m_minYRotation;
+}
+
+/*!
+ * \internal
+ */
+void Q3DCamera::setMinYRotation(qreal minRotation)
+{
+ minRotation = qBound(-90.0, minRotation, 90.0);
+ if (minRotation > d_ptr->m_maxYRotation)
+ minRotation = d_ptr->m_maxYRotation;
+
+ if (d_ptr->m_minYRotation != minRotation) {
+ d_ptr->m_minYRotation = minRotation;
+ emit minYRotationChanged(minRotation);
+
+ if (d_ptr->m_yRotation < d_ptr->m_minYRotation)
+ setYRotation(d_ptr->m_yRotation);
+ }
+}
+
+/*!
+ * \property Q3DCamera::maxXRotation
+ *
+ * This property contains the current maximum X-rotation for the camera.
+ * The full circle range is [-180,180] and the maximum value is limited to 180.
+ * Also the value can't be lower than minimum, and is adjusted if necessary.
+ *
+ * \sa wrapXRotation, minXRotation
+ */
+qreal Q3DCamera::maxXRotation() const
+{
+ return d_ptr->m_maxXRotation;
+}
+
+/*!
+ * \internal
+ */
+void Q3DCamera::setMaxXRotation(qreal maxRotation)
+{
+ maxRotation = qBound(-180.0, maxRotation, 180.0);
+
+ if (maxRotation < d_ptr->m_minXRotation)
+ maxRotation = d_ptr->m_minXRotation;
+
+ if (d_ptr->m_maxXRotation != maxRotation) {
+ d_ptr->m_maxXRotation = maxRotation;
+ emit maxXRotationChanged(maxRotation);
+
+ if (d_ptr->m_xRotation > d_ptr->m_maxXRotation)
+ setXRotation(d_ptr->m_xRotation);
+ }
+}
+
+/*!
+ * \property Q3DCamera::maxYRotation
+ *
+ * This property contains the current maximum Y-rotation for the camera.
+ * The full Y angle range is [-90,90] and the maximum value is limited to 90.
+ * Also the value can't be lower than minimum, and is adjusted if necessary.
+ *
+ * \sa wrapYRotation, minYRotation
+ */
+qreal Q3DCamera::maxYRotation() const
+{
+ return d_ptr->m_maxYRotation;
+}
+
+/*!
+ * \internal
+ */
+void Q3DCamera::setMaxYRotation(qreal maxRotation)
+{
+ maxRotation = qBound(-90.0, maxRotation, 90.0);
+
+ if (maxRotation < d_ptr->m_minYRotation)
+ maxRotation = d_ptr->m_minYRotation;
+
+ if (d_ptr->m_maxYRotation != maxRotation) {
+ d_ptr->m_maxYRotation = maxRotation;
+ emit maxYRotationChanged(maxRotation);
+
+ if (d_ptr->m_yRotation > d_ptr->m_maxYRotation)
+ setYRotation(d_ptr->m_yRotation);
}
}
@@ -141,6 +315,7 @@ void Q3DCamera::setViewMatrix(const QMatrix4x4 &viewMatrix)
if (d_ptr->m_viewMatrix != viewMatrix) {
d_ptr->m_viewMatrix = viewMatrix;
setDirty(true);
+ emit viewMatrixChanged(d_ptr->m_viewMatrix);
}
}
@@ -159,6 +334,7 @@ bool Q3DCamera::isViewMatrixAutoUpdateEnabled()
void Q3DCamera::setViewMatrixAutoUpdateEnabled(bool isEnabled)
{
d_ptr->m_isViewMatrixUpdateActive = isEnabled;
+ emit viewMatrixAutoUpdateChanged(isEnabled);
}
/*!
@@ -178,99 +354,123 @@ void Q3DCamera::setCameraPreset(QDataVis::CameraPreset preset)
{
switch (preset) {
case QDataVis::CameraPresetFrontLow: {
- d_ptr->setRotations(QPointF(0.0f, 0.0f));
+ setXRotation(0.0);
+ setYRotation(0.0);
break;
}
case QDataVis::CameraPresetFront: {
- d_ptr->setRotations(QPointF(0.0f, 22.5f));
+ setXRotation(0.0);
+ setYRotation(22.5);
break;
}
case QDataVis::CameraPresetFrontHigh: {
- d_ptr->setRotations(QPointF(0.0f, 45.0f));
+ setXRotation(0.0);
+ setYRotation(45.0);
break;
}
case QDataVis::CameraPresetLeftLow: {
- d_ptr->setRotations(QPointF(90.0f, 0.0f));
+ setXRotation(90.0);
+ setYRotation(0.0);
break;
}
case QDataVis::CameraPresetLeft: {
- d_ptr->setRotations(QPointF(90.0f, 22.5f));
+ setXRotation(90.0);
+ setYRotation(22.5);
break;
}
case QDataVis::CameraPresetLeftHigh: {
- d_ptr->setRotations(QPointF(90.0f, 45.0f));
+ setXRotation(90.0);
+ setYRotation(45.0);
break;
}
case QDataVis::CameraPresetRightLow: {
- d_ptr->setRotations(QPointF(-90.0f, 0.0f));
+ setXRotation(-90.0);
+ setYRotation(0.0);
break;
}
case QDataVis::CameraPresetRight: {
- d_ptr->setRotations(QPointF(-90.0f, 22.5f));
+ setXRotation(-90.0);
+ setYRotation(22.5);
break;
}
case QDataVis::CameraPresetRightHigh: {
- d_ptr->setRotations(QPointF(-90.0f, 45.0f));
+ setXRotation(-90.0);
+ setYRotation(45.0);
break;
}
case QDataVis::CameraPresetBehindLow: {
- d_ptr->setRotations(QPointF(180.0f, 0.0f));
+ setXRotation(180.0);
+ setYRotation(0.0);
break;
}
case QDataVis::CameraPresetBehind: {
- d_ptr->setRotations(QPointF(180.0f, 22.5f));
+ setXRotation(180.0);
+ setYRotation(22.5);
break;
}
case QDataVis::CameraPresetBehindHigh: {
- d_ptr->setRotations(QPointF(180.0f, 45.0f));
+ setXRotation(180.0);
+ setYRotation(45.0);
break;
}
case QDataVis::CameraPresetIsometricLeft: {
- d_ptr->setRotations(QPointF(45.0f, 22.5f));
+ setXRotation(45.0);
+ setYRotation(22.5);
break;
}
case QDataVis::CameraPresetIsometricLeftHigh: {
- d_ptr->setRotations(QPointF(45.0f, 45.0f));
+ setXRotation(45.0);
+ setYRotation(45.0);
break;
}
case QDataVis::CameraPresetIsometricRight: {
- d_ptr->setRotations(QPointF(-45.0f, 22.5f));
+ setXRotation(-45.0);
+ setYRotation(22.5);
break;
}
case QDataVis::CameraPresetIsometricRightHigh: {
- d_ptr->setRotations(QPointF(-45.0f, 45.0f));
+ setXRotation(-45.0);
+ setYRotation(45.0);
break;
}
case QDataVis::CameraPresetDirectlyAbove: {
- d_ptr->setRotations(QPointF(0.0f, 90.0f));
+ setXRotation(0.0);
+ setYRotation(90.0);
break;
}
case QDataVis::CameraPresetDirectlyAboveCW45: {
- d_ptr->setRotations(QPointF(-45.0f, 90.0f));
+ setXRotation(-45.0);
+ setYRotation(90.0);
break;
}
case QDataVis::CameraPresetDirectlyAboveCCW45: {
- d_ptr->setRotations(QPointF(45.0f, 90.0f));
+ setXRotation(45.0);
+ setYRotation(90.0);
break;
}
case QDataVis::CameraPresetFrontBelow: {
- d_ptr->setRotations(QPointF(0.0f, -45.0f));
+ setXRotation(0.0);
+ setYRotation(-45.0);
break;
}
case QDataVis::CameraPresetLeftBelow: {
- d_ptr->setRotations(QPointF(90.0f, -45.0f));
+ setXRotation(90.0);
+ setYRotation(-45.0);
break;
}
case QDataVis::CameraPresetRightBelow: {
- d_ptr->setRotations(QPointF(-90.0f, -45.0f));
+ setXRotation(-90.0);
+ setYRotation(-45.0);
break;
}
case QDataVis::CameraPresetBehindBelow: {
- d_ptr->setRotations(QPointF(180.0f, -45.0f));
+ setXRotation(180.0);
+ setYRotation(-45.0);
break;
}
case QDataVis::CameraPresetDirectlyBelow: {
- d_ptr->setRotations(QPointF(0.0f, -90.0f));
+ setXRotation(0.0);
+ setYRotation(-90.0);
break;
}
default:
@@ -281,6 +481,7 @@ void Q3DCamera::setCameraPreset(QDataVis::CameraPreset preset)
if (d_ptr->m_activePreset != preset) {
d_ptr->m_activePreset = preset;
setDirty(true);
+ emit cameraPresetChanged(preset);
}
}
@@ -300,6 +501,7 @@ void Q3DCamera::setZoomLevel(int zoomLevel)
if (d_ptr->m_zoomLevel != zoomLevel) {
d_ptr->m_zoomLevel = zoomLevel;
setDirty(true);
+ emit zoomLevelChanged(zoomLevel);
}
}
@@ -336,18 +538,71 @@ QVector3D Q3DCamera::calculatePositionRelativeToCamera(const QVector3D &relative
zPos + relativePosition.z());
}
+/*!
+ * \property Q3DCamera::wrapXRotation
+ *
+ * This property determines the behavior of the minimum and maximum limits in the X-rotation.
+ * By default the X-rotation wraps from minimum value to maximum and from maximum to minimum.
+ *
+ * If set to true the X-rotation of the camera is wrapped from minimum to maximum and from maximum to minimum.
+ * If set to false the X-rotation of the camera is limited to the sector determined by minimum and maximum values.
+ */
+bool Q3DCamera::wrapXRotation() const
+{
+ return d_ptr->m_wrapXRotation;
+}
+
+void Q3DCamera::setWrapXRotation(bool isEnabled)
+{
+ d_ptr->m_wrapXRotation = isEnabled;
+}
+
+/*!
+ * \property Q3DCamera::wrapYRotation
+ *
+ * This property determines the behavior of the minimum and maximum limits in the Y-rotation.
+ * By default the Y-rotation is limited between the minimum and maximum values without any wrapping.
+ *
+ * If true the Y-rotation of the camera is wrapped from minimum to maximum and from maximum to minimum.
+ * If false the Y-rotation of the camera is limited to the sector determined by minimum and maximum values.
+ */
+bool Q3DCamera::wrapYRotation() const
+{
+ return d_ptr->m_wrapYRotation;
+}
+
+void Q3DCamera::setWrapYRotation(bool isEnabled)
+{
+ d_ptr->m_wrapYRotation = isEnabled;
+}
+
+/*!
+ * Utility function that sets the camera rotations and distance.\a horizontal and \a vertical define the camera rotations to be used.
+ * Optional \a zoom parameter can be given to set the zoom of the camera in range of 10-500%.
+ */
+void Q3DCamera::setCameraPosition(qreal horizontal, qreal vertical, qreal zoom)
+{
+ setZoomLevel(qBound(10.0, distance, 500.0));
+ setXRotation(horizontal);
+ setYRotation(vertical);
+}
Q3DCameraPrivate::Q3DCameraPrivate(Q3DCamera *q) :
q_ptr(q),
m_isViewMatrixUpdateActive(true),
- m_xRotation(0.0f),
- m_yRotation(0.0f),
+ m_xRotation(0.0),
+ m_yRotation(0.0),
+ m_minXRotation(-180.0),
+ m_minYRotation(0.0),
+ m_maxXRotation(180.0),
+ m_maxYRotation(90.0),
+ m_wrapXRotation(true),
+ m_wrapYRotation(false),
m_zoomLevel(100),
m_activePreset(QDataVis::CameraPresetNone)
{
}
-
Q3DCameraPrivate::~Q3DCameraPrivate()
{
}
@@ -363,11 +618,50 @@ void Q3DCameraPrivate::sync(Q3DCamera &other)
}
}
-void Q3DCameraPrivate::setRotations(const QPointF &rotation)
+void Q3DCameraPrivate::setXRotation(const qreal rotation)
+{
+ if (m_xRotation != rotation) {
+ m_xRotation = rotation;
+ q_ptr->setDirty(true);
+ }
+}
+
+void Q3DCameraPrivate::setYRotation(const qreal rotation)
+{
+ if (m_yRotation != rotation) {
+ m_yRotation = rotation;
+ q_ptr->setDirty(true);
+ }
+}
+
+void Q3DCameraPrivate::setMinXRotation(const qreal rotation)
+{
+ if (m_minXRotation != rotation) {
+ m_minXRotation = rotation;
+ q_ptr->setDirty(true);
+ }
+}
+
+void Q3DCameraPrivate::setMinYRotation(const qreal rotation)
+{
+ if (m_minYRotation != rotation) {
+ m_minYRotation = rotation;
+ q_ptr->setDirty(true);
+ }
+}
+
+void Q3DCameraPrivate::setMaxXRotation(const qreal rotation)
+{
+ if (m_maxXRotation != rotation) {
+ m_maxXRotation = rotation;
+ q_ptr->setDirty(true);
+ }
+}
+
+void Q3DCameraPrivate::setMaxYRotation(const qreal rotation)
{
- if (m_xRotation != rotation.x() || m_yRotation != rotation.y()) {
- m_xRotation = rotation.x();
- m_yRotation = rotation.y();
+ if (m_maxYRotation != rotation) {
+ m_maxYRotation = rotation;
q_ptr->setDirty(true);
}
}
@@ -379,20 +673,8 @@ void Q3DCameraPrivate::updateViewMatrix(qreal zoomAdjustment)
if (!m_isViewMatrixUpdateActive)
return;
- bool showUnder = q_ptr->parentScene()->isUnderSideCameraEnabled();
int zoom = m_zoomLevel * zoomAdjustment;
QMatrix4x4 viewMatrix;
- GLfloat lowerLimit = 0.0f;
- if (showUnder)
- lowerLimit = -90.0f;
-
- // Reset at 360 in x and limit to 0...90 in y
- if (qAbs(m_xRotation) >= 360.0f)
- m_xRotation = 0.0f;
- if (m_yRotation >= 90.0f)
- m_yRotation = 90.0f;
- else if (m_yRotation <= lowerLimit)
- m_yRotation = lowerLimit;
// Apply to view matrix
viewMatrix.lookAt(q_ptr->position(), m_target, m_up);
diff --git a/src/datavisualization/engine/q3dcamera.h b/src/datavisualization/engine/q3dcamera.h
index 5780fcda..ee750cec 100644
--- a/src/datavisualization/engine/q3dcamera.h
+++ b/src/datavisualization/engine/q3dcamera.h
@@ -24,7 +24,6 @@
class QVector3D;
class QPoint;
-class QPointF;
QT_DATAVISUALIZATION_BEGIN_NAMESPACE
@@ -33,40 +32,83 @@ class Q3DCameraPrivate;
class QT_DATAVISUALIZATION_EXPORT Q3DCamera : public Q3DObject
{
Q_OBJECT
- Q_PROPERTY(QPointF rotations READ rotations WRITE setRotations)
- Q_PROPERTY(QMatrix4x4 viewMatrix READ viewMatrix WRITE setViewMatrix)
- Q_PROPERTY(QtDataVisualization::QDataVis::CameraPreset cameraPreset READ cameraPreset WRITE setCameraPreset)
- Q_PROPERTY(int zoomLevel READ zoomLevel WRITE setZoomLevel)
- Q_PROPERTY(bool viewMatrixAutoUpdateEnabled READ isViewMatrixAutoUpdateEnabled WRITE setViewMatrixAutoUpdateEnabled)
+ Q_PROPERTY(qreal xRotation READ xRotation WRITE setXRotation NOTIFY xRotationChanged)
+ Q_PROPERTY(qreal yRotation READ yRotation WRITE setYRotation NOTIFY yRotationChanged)
+ Q_PROPERTY(qreal minXRotation READ minXRotation NOTIFY minXRotationChanged)
+ Q_PROPERTY(qreal minYRotation READ minYRotation NOTIFY minYRotationChanged)
+ Q_PROPERTY(qreal maxXRotation READ maxXRotation NOTIFY maxXRotationChanged)
+ Q_PROPERTY(qreal maxYRotation READ maxYRotation NOTIFY maxYRotationChanged)
+ Q_PROPERTY(int zoomLevel READ zoomLevel WRITE setZoomLevel NOTIFY zoomLevelChanged)
+ Q_PROPERTY(QMatrix4x4 viewMatrix READ viewMatrix WRITE setViewMatrix NOTIFY viewMatrixChanged)
+ Q_PROPERTY(QtDataVisualization::QDataVis::CameraPreset cameraPreset READ cameraPreset WRITE setCameraPreset NOTIFY cameraPresetChanged)
+ Q_PROPERTY(bool viewMatrixAutoUpdateEnabled READ isViewMatrixAutoUpdateEnabled WRITE setViewMatrixAutoUpdateEnabled NOTIFY viewMatrixAutoUpdateChanged)
+ Q_PROPERTY(bool wrapXRotation READ wrapXRotation WRITE setWrapXRotation NOTIFY wrapXRotationChanged )
+ Q_PROPERTY(bool wrapYRotation READ wrapYRotation WRITE setWrapYRotation NOTIFY wrapYRotationChanged )
+ Q_ENUMS(QtDataVisualization::QDataVis::CameraPreset)
public:
Q3DCamera(QObject *parent = 0);
virtual ~Q3DCamera();
- void copyValuesFrom(const Q3DCamera &source);
-
- virtual QPointF rotations() const;
- virtual void setRotations(const QPointF &rotation);
+ qreal xRotation() const;
+ void setXRotation(qreal rotation);
+ qreal yRotation() const;
+ void setYRotation(qreal rotation);
- virtual QMatrix4x4 viewMatrix() const;
- virtual void setViewMatrix(const QMatrix4x4 &viewMatrix);
+ qreal minXRotation() const;
+ qreal maxXRotation() const;
- virtual bool isViewMatrixAutoUpdateEnabled();
- virtual void setViewMatrixAutoUpdateEnabled(bool isEnabled);
+ qreal minYRotation() const;
+ qreal maxYRotation() const;
- virtual QDataVis::CameraPreset cameraPreset();
- virtual void setCameraPreset(QDataVis::CameraPreset preset);
+ bool wrapXRotation() const;
+ void setWrapXRotation(bool isEnabled);
- virtual int zoomLevel();
- virtual void setZoomLevel(int zoomLevel);
+ bool wrapYRotation() const;
+ void setWrapYRotation(bool isEnabled);
- virtual void setBaseOrientation(const QVector3D &defaultPosition,
- const QVector3D &defaultTarget,
- const QVector3D &defaultUp);
+ void copyValuesFrom(const Q3DCamera &source);
- virtual QVector3D calculatePositionRelativeToCamera(const QVector3D &relativePosition,
- qreal fixedRotation,
- qreal distanceModifier) const;
+ QMatrix4x4 viewMatrix() const;
+ void setViewMatrix(const QMatrix4x4 &viewMatrix);
+
+ bool isViewMatrixAutoUpdateEnabled();
+ void setViewMatrixAutoUpdateEnabled(bool isEnabled);
+
+ QDataVis::CameraPreset cameraPreset();
+ void setCameraPreset(QDataVis::CameraPreset preset);
+
+ int zoomLevel();
+ void setZoomLevel(int zoomLevel);
+
+ void setBaseOrientation(const QVector3D &defaultPosition,
+ const QVector3D &defaultTarget,
+ const QVector3D &defaultUp);
+
+ QVector3D calculatePositionRelativeToCamera(const QVector3D &relativePosition,
+ qreal fixedRotation,
+ qreal distanceModifier) const;
+ void setCameraPosition(qreal horizontal, qreal vertical, qreal distance = 100.0);
+
+signals:
+ void xRotationChanged(qreal rotation);
+ void yRotationChanged(qreal rotation);
+ void minXRotationChanged(qreal rotation);
+ void minYRotationChanged(qreal rotation);
+ void maxXRotationChanged(qreal rotation);
+ void maxYRotationChanged(qreal rotation);
+ void zoomLevelChanged(int zoomLevel);
+ void viewMatrixChanged(QMatrix4x4 viewMatrix);
+ void cameraPresetChanged(QDataVis::CameraPreset preset);
+ void viewMatrixAutoUpdateChanged(bool enabled);
+ void wrapXRotationChanged(bool isEnabled);
+ void wrapYRotationChanged(bool isEnabled);
+
+protected:
+ void setMinXRotation(qreal rotation);
+ void setMinYRotation(qreal rotation);
+ void setMaxXRotation(qreal rotation);
+ void setMaxYRotation(qreal rotation);
private:
QScopedPointer<Q3DCameraPrivate> d_ptr;
diff --git a/src/datavisualization/engine/q3dcamera_p.h b/src/datavisualization/engine/q3dcamera_p.h
index 8c160d8c..e0528dcc 100644
--- a/src/datavisualization/engine/q3dcamera_p.h
+++ b/src/datavisualization/engine/q3dcamera_p.h
@@ -44,7 +44,12 @@ public:
void sync(Q3DCamera &other);
- void setRotations(const QPointF &rotation);
+ void setXRotation(qreal rotation);
+ void setYRotation(qreal rotation);
+ void setMinXRotation(qreal rotation);
+ void setMinYRotation(qreal rotation);
+ void setMaxXRotation(qreal rotation);
+ void setMaxYRotation(qreal rotation);
void updateViewMatrix(qreal zoomAdjustment);
@@ -59,6 +64,12 @@ public:
GLfloat m_xRotation;
GLfloat m_yRotation;
+ GLfloat m_minXRotation;
+ GLfloat m_minYRotation;
+ GLfloat m_maxXRotation;
+ GLfloat m_maxYRotation;
+ bool m_wrapXRotation;
+ bool m_wrapYRotation;
int m_zoomLevel;
QDataVis::CameraPreset m_activePreset;
diff --git a/src/datavisualization/engine/q3dobject.cpp b/src/datavisualization/engine/q3dobject.cpp
index 55583b5b..ae13af7d 100644
--- a/src/datavisualization/engine/q3dobject.cpp
+++ b/src/datavisualization/engine/q3dobject.cpp
@@ -86,6 +86,7 @@ void Q3DObject::setPosition(const QVector3D &position)
if (d_ptr->m_position != position) {
d_ptr->m_position = position;
setDirty(true);
+ emit positionChanged(d_ptr->m_position);
}
}
diff --git a/src/datavisualization/engine/q3dobject.h b/src/datavisualization/engine/q3dobject.h
index db8ec68b..930bb022 100644
--- a/src/datavisualization/engine/q3dobject.h
+++ b/src/datavisualization/engine/q3dobject.h
@@ -20,19 +20,19 @@
#define Q3DOBJECT_H
#include <QtDataVisualization/qdatavisualizationenums.h>
+#include <QtDataVisualization/q3dscene.h>
+
#include <QObject>
#include <QVector3D>
QT_DATAVISUALIZATION_BEGIN_NAMESPACE
-
-class Q3DScene;
class Q3DObjectPrivate;
class Q3DObject : public QObject
{
Q_OBJECT
Q_PROPERTY(Q3DScene* parentScene READ parentScene)
- Q_PROPERTY(QVector3D position READ position WRITE setPosition)
+ Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged)
public:
Q3DObject(QObject *parent = 0);
@@ -40,10 +40,13 @@ public:
void copyValuesFrom(const Q3DObject &source);
- virtual Q3DScene *parentScene();
+ Q3DScene *parentScene();
+
+ QVector3D position() const;
+ void setPosition(const QVector3D &position);
- virtual QVector3D position() const;
- virtual void setPosition(const QVector3D &position);
+signals:
+ void positionChanged(QVector3D position);
protected:
void setDirty(bool dirty);
diff --git a/src/datavisualization/engine/q3dscatter.cpp b/src/datavisualization/engine/q3dscatter.cpp
index 55e353bf..a5053bf3 100644
--- a/src/datavisualization/engine/q3dscatter.cpp
+++ b/src/datavisualization/engine/q3dscatter.cpp
@@ -21,9 +21,9 @@
#include "scatter3dcontroller_p.h"
#include "q3dvalueaxis.h"
#include "qscatterdataproxy.h"
+#include "q3dcamera.h"
#include <QMouseEvent>
-
#include <QDebug>
QT_DATAVISUALIZATION_BEGIN_NAMESPACE
@@ -189,31 +189,6 @@ void Q3DScatter::setObjectType(QDataVis::MeshStyle style, bool smooth)
}
/*!
- * \property Q3DScatter::cameraPreset
- *
- * The \a preset position of the camera. The position can be one of \c QDataVis::CameraPreset.
- */
-void Q3DScatter::setCameraPreset(QDataVis::CameraPreset preset)
-{
- d_ptr->m_shared->setCameraPreset(preset);
-}
-
-QDataVis::CameraPreset Q3DScatter::cameraPreset() const
-{
- return d_ptr->m_shared->cameraPreset();
-}
-
-/*!
- * Move camera to a wanted position based on \a horizontal and \a vertical angles. Angles are limited
- * to -180...180 in horizontal direction and -90...90 in vertical. \a distance is adjustable
- * between 10 and 500, being \c 100 by default.
- */
-void Q3DScatter::setCameraPosition(qreal horizontal, qreal vertical, int distance)
-{
- d_ptr->m_shared->setCameraPosition(GLfloat(horizontal), GLfloat(vertical), GLint(distance));
-}
-
-/*!
* Sets a predefined \a theme from \c QDataVis::Theme. It is preset to \c QDataVis::ThemeQt by
* default. Theme affects bar colors, label colors, text color, background color, window color and
* grid color. Lighting is also adjusted by themes.
@@ -302,6 +277,16 @@ QFont Q3DScatter::font() const
}
/*!
+ * \property Q3DScatter::scene
+ *
+ * This property contains the read only Q3DScene that can be used to access e.g. camera object.
+ */
+Q3DScene *Q3DScatter::scene() const
+{
+ return d_ptr->m_shared->scene();
+}
+
+/*!
* \property Q3DScatter::labelStyle
*
* Sets label \a style to one of \c QDataVis::LabelStyle. It is preset to
diff --git a/src/datavisualization/engine/q3dscatter.h b/src/datavisualization/engine/q3dscatter.h
index 137ccafb..fdea604e 100644
--- a/src/datavisualization/engine/q3dscatter.h
+++ b/src/datavisualization/engine/q3dscatter.h
@@ -21,6 +21,7 @@
#include <QtDataVisualization/qdatavisualizationenums.h>
#include <QtDataVisualization/q3dwindow.h>
+#include <QtDataVisualization/q3dscene.h>
#include <QFont>
QT_DATAVISUALIZATION_BEGIN_NAMESPACE
@@ -37,12 +38,12 @@ class QT_DATAVISUALIZATION_EXPORT Q3DScatter : public Q3DWindow
Q_PROPERTY(QtDataVisualization::QDataVis::SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
Q_PROPERTY(QtDataVisualization::QDataVis::LabelStyle labelStyle READ labelStyle WRITE setLabelStyle)
Q_PROPERTY(QtDataVisualization::QDataVis::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality)
- Q_PROPERTY(QtDataVisualization::QDataVis::CameraPreset cameraPreset READ cameraPreset WRITE setCameraPreset)
Q_PROPERTY(QString meshFileName READ meshFileName WRITE setMeshFileName)
Q_PROPERTY(QFont font READ font WRITE setFont)
Q_PROPERTY(bool gridVisible READ isGridVisible WRITE setGridVisible)
Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible)
Q_PROPERTY(int selectedItemIndex READ selectedItemIndex WRITE setSelectedItemIndex NOTIFY selectedItemIndexChanged)
+ Q_PROPERTY(Q3DScene* scene READ scene)
Q_ENUMS(QtDataVisualization::QDataVis::SelectionMode)
Q_ENUMS(QtDataVisualization::QDataVis::ShadowQuality)
Q_ENUMS(QtDataVisualization::QDataVis::LabelStyle)
@@ -54,11 +55,6 @@ public:
void setObjectType(QDataVis::MeshStyle style, bool smooth = false);
- void setCameraPreset(QDataVis::CameraPreset preset);
- QDataVis::CameraPreset cameraPreset() const;
-
- void setCameraPosition(qreal horizontal, qreal vertical, int distance = 100);
-
void setTheme(QDataVis::Theme theme);
void setObjectColor(const QColor &baseColor, bool uniform = true);
@@ -73,6 +69,8 @@ public:
void setFont(const QFont &font);
QFont font() const;
+ Q3DScene *scene() const;
+
void setLabelStyle(QDataVis::LabelStyle style);
QDataVis::LabelStyle labelStyle() const;
diff --git a/src/datavisualization/engine/q3dscene.cpp b/src/datavisualization/engine/q3dscene.cpp
index abf41b19..b607dc4a 100644
--- a/src/datavisualization/engine/q3dscene.cpp
+++ b/src/datavisualization/engine/q3dscene.cpp
@@ -81,6 +81,7 @@ void Q3DScene::setViewport(const QRect &viewport)
d_ptr->m_viewport.setX(0);
d_ptr->m_viewport.setY(0);
d_ptr->m_changeTracker.viewportChanged = true;
+ emit viewportChanged(viewport);
}
}
@@ -89,10 +90,12 @@ void Q3DScene::setViewport(const QRect &viewport)
*/
void Q3DScene::setViewportSize(int width, int height)
{
- if (d_ptr->m_viewport.width() != width || d_ptr->m_viewport.height() != height) {
+ if (d_ptr->m_viewport.width() != width
+ || d_ptr->m_viewport.height() != height) {
d_ptr->m_viewport.setWidth(width);
d_ptr->m_viewport.setHeight(height);
d_ptr->m_changeTracker.viewportChanged = true;
+ emit viewportChanged(d_ptr->m_viewport);
}
}
@@ -112,6 +115,7 @@ void Q3DScene::setPrimarySubViewport(const QRect &primarySubViewport)
if (d_ptr->m_primarySubViewport != primarySubViewport) {
d_ptr->m_primarySubViewport = primarySubViewport;
d_ptr->m_changeTracker.primarySubViewportChanged = true;
+ emit primarySubViewportChanged(primarySubViewport);
}
}
@@ -169,6 +173,7 @@ void Q3DScene::setSecondarySubViewport(const QRect &secondarySubViewport)
if (d_ptr->m_secondarySubViewport != secondarySubViewport) {
d_ptr->m_secondarySubViewport = secondarySubViewport;
d_ptr->m_changeTracker.secondarySubViewportChanged = true;
+ emit secondarySubViewportChanged(secondarySubViewport);
}
}
@@ -188,6 +193,7 @@ void Q3DScene::setSlicingActive(bool isSlicing)
if (d_ptr->m_isSlicingActive != isSlicing) {
d_ptr->m_isSlicingActive = isSlicing;
d_ptr->m_changeTracker.slicingActivatedChanged = true;
+ emit slicingActiveChanged(isSlicing);
}
}
@@ -213,6 +219,7 @@ void Q3DScene::setActiveCamera(Q3DCamera *camera)
if (camera != d_ptr->m_camera) {
d_ptr->m_camera = camera;
d_ptr->m_changeTracker.cameraChanged = true;
+ emit activeCameraChanged(camera);
}
}
@@ -238,6 +245,7 @@ void Q3DScene::setActiveLight(Q3DLight *light)
if (light != d_ptr->m_light) {
d_ptr->m_light = light;
d_ptr->m_changeTracker.lightChanged = true;
+ emit activeLightChanged(light);
}
}
@@ -254,10 +262,12 @@ qreal Q3DScene::devicePixelRatio() const
void Q3DScene::setDevicePixelRatio(qreal pixelRatio)
{
- d_ptr->m_devicePixelRatio = pixelRatio;
+ if (d_ptr->m_devicePixelRatio != pixelRatio) {
+ d_ptr->m_devicePixelRatio = pixelRatio;
+ emit devicePixelRatioChanged(pixelRatio);
+ }
}
-
/*!
* Calculates and sets the light position relative to the currently active camera using the given parameters.
* \a relativePosition defines the relative 3D offset to the current camera position.
@@ -273,20 +283,6 @@ void Q3DScene::setLightPositionRelativeToCamera(const QVector3D &relativePositio
distanceModifier));
}
-bool Q3DScene::isUnderSideCameraEnabled() const
-{
- return d_ptr->m_isUnderSideCameraEnabled;
-}
-
-void Q3DScene::setUnderSideCameraEnabled(bool isEnabled)
-{
- if (d_ptr->m_isUnderSideCameraEnabled != isEnabled) {
- d_ptr->m_isUnderSideCameraEnabled = isEnabled;
- d_ptr->m_changeTracker.underSideCameraEnabledChanged = true;
- }
-}
-
-
Q3DScenePrivate::Q3DScenePrivate(Q3DScene *q) :
q_ptr(q),
m_devicePixelRatio(1.f),
@@ -336,11 +332,6 @@ void Q3DScenePrivate::sync(Q3DScenePrivate &other)
}
m_light->d_ptr->sync(*other.m_light);
- if (m_changeTracker.underSideCameraEnabledChanged) {
- other.q_ptr->setUnderSideCameraEnabled(q_ptr->isUnderSideCameraEnabled());
- m_changeTracker.underSideCameraEnabledChanged = false;
- other.m_changeTracker.underSideCameraEnabledChanged = false;
- }
if (m_changeTracker.slicingActivatedChanged) {
other.q_ptr->setSlicingActive(q_ptr->isSlicingActive());
m_changeTracker.slicingActivatedChanged = false;
diff --git a/src/datavisualization/engine/q3dscene.h b/src/datavisualization/engine/q3dscene.h
index 8c4f67f8..66a5aa64 100644
--- a/src/datavisualization/engine/q3dscene.h
+++ b/src/datavisualization/engine/q3dscene.h
@@ -33,13 +33,13 @@ class Q3DScenePrivate;
class QT_DATAVISUALIZATION_EXPORT Q3DScene : public QObject
{
Q_OBJECT
- Q_PROPERTY(QRect viewport READ viewport WRITE setViewport)
- Q_PROPERTY(QRect primarySubViewport READ primarySubViewport WRITE setPrimarySubViewport)
- Q_PROPERTY(QRect secondarySubViewport READ secondarySubViewport WRITE setSecondarySubViewport)
- Q_PROPERTY(bool slicingActive READ isSlicingActive WRITE setSlicingActive)
- Q_PROPERTY(Q3DCamera* activeCamera READ activeCamera WRITE setActiveCamera)
- Q_PROPERTY(Q3DLight* activeLight READ activeLight WRITE setActiveLight)
- Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio WRITE setDevicePixelRatio)
+ Q_PROPERTY(QRect viewport READ viewport WRITE setViewport NOTIFY viewportChanged)
+ Q_PROPERTY(QRect primarySubViewport READ primarySubViewport WRITE setPrimarySubViewport NOTIFY primarySubViewportChanged)
+ Q_PROPERTY(QRect secondarySubViewport READ secondarySubViewport WRITE setSecondarySubViewport NOTIFY secondarySubViewportChanged)
+ Q_PROPERTY(bool slicingActive READ isSlicingActive WRITE setSlicingActive NOTIFY slicingActiveChanged)
+ Q_PROPERTY(Q3DCamera* activeCamera READ activeCamera WRITE setActiveCamera NOTIFY activeCameraChanged)
+ Q_PROPERTY(Q3DLight* activeLight READ activeLight WRITE setActiveLight NOTIFY activeLightChanged)
+ Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio WRITE setDevicePixelRatio NOTIFY devicePixelRatioChanged)
public:
Q3DScene(QObject *parent = 0);
@@ -73,10 +73,16 @@ public:
qreal fixedRotation = 0.0,
qreal distanceModifier = 0.0);
-private:
- bool isUnderSideCameraEnabled() const;
- void setUnderSideCameraEnabled(bool isEnabled);
+signals:
+ void viewportChanged(QRect viewport);
+ void primarySubViewportChanged(QRect subViewport);
+ void secondarySubViewportChanged(QRect subViewport);
+ void slicingActiveChanged(bool isSlicingActive);
+ void activeCameraChanged(const Q3DCamera *camera);
+ void activeLightChanged(const Q3DLight *light);
+ void devicePixelRatioChanged(qreal pixelRatio);
+private:
QScopedPointer<Q3DScenePrivate> d_ptr;
Q_DISABLE_COPY(Q3DScene)
diff --git a/src/datavisualization/engine/q3dscene_p.h b/src/datavisualization/engine/q3dscene_p.h
index 20a74467..b28baaae 100644
--- a/src/datavisualization/engine/q3dscene_p.h
+++ b/src/datavisualization/engine/q3dscene_p.h
@@ -44,7 +44,6 @@ struct Q3DSceneChangeBitField {
bool secondarySubViewportChanged : 1;
bool cameraChanged : 1;
bool lightChanged : 1;
- bool underSideCameraEnabledChanged : 1;
bool slicingActivatedChanged : 1;
bool devicePixelRatioChanged : 1;
@@ -54,7 +53,6 @@ struct Q3DSceneChangeBitField {
secondarySubViewportChanged(true),
cameraChanged(true),
lightChanged(true),
- underSideCameraEnabledChanged(true),
slicingActivatedChanged(true),
devicePixelRatioChanged(true)
{
diff --git a/src/datavisualization/engine/q3dsurface.cpp b/src/datavisualization/engine/q3dsurface.cpp
index 8e32d5d7..7990f362 100644
--- a/src/datavisualization/engine/q3dsurface.cpp
+++ b/src/datavisualization/engine/q3dsurface.cpp
@@ -20,6 +20,7 @@
#include "q3dsurface_p.h"
#include "q3dvalueaxis.h"
#include "qsurfacedataproxy.h"
+#include "q3dcamera.h"
#include <QMouseEvent>
@@ -239,31 +240,6 @@ QDataVis::ShadowQuality Q3DSurface::shadowQuality() const
}
/*!
- * \property Q3DSurface::cameraPreset
- *
- * The \a preset position of the camera. The position can be one of \c QDataVis::CameraPreset.
- */
-void Q3DSurface::setCameraPreset(QDataVis::CameraPreset preset)
-{
- d_ptr->m_shared->setCameraPreset(preset);
-}
-
-QDataVis::CameraPreset Q3DSurface::cameraPreset() const
-{
- return d_ptr->m_shared->cameraPreset();
-}
-
-/*!
- * Move camera to a wanted position based on \a horizontal and \a vertical angles. Angles are limited
- * to -180...180 in horizontal direction and 0...90 in vertical. \a distance is adjustable
- * between 10 and 500, being \c 100 by default.
- */
-void Q3DSurface::setCameraPosition(qreal horizontal, qreal vertical, int distance)
-{
- d_ptr->m_shared->setCameraPosition(GLfloat(horizontal), GLfloat(vertical), GLint(distance));
-}
-
-/*!
* \property Q3DSurface::smoothSurfaceEnabled
*
* Sets surface smoothing to \a enabled. It is preset to \c false by default.
@@ -345,6 +321,16 @@ QFont Q3DSurface::font() const
}
/*!
+ * \property Q3DSurface::scene
+ *
+ * This property contains the read only Q3DScene that can be used to access e.g. camera object.
+ */
+Q3DScene *Q3DSurface::scene() const
+{
+ return d_ptr->m_shared->scene();
+}
+
+/*!
* \property Q3DSurface::labelStyle
*
* Sets label \a style to one of \c QDataVis::LabelStyle. It is preset to
diff --git a/src/datavisualization/engine/q3dsurface.h b/src/datavisualization/engine/q3dsurface.h
index 60847265..1b572a36 100644
--- a/src/datavisualization/engine/q3dsurface.h
+++ b/src/datavisualization/engine/q3dsurface.h
@@ -21,6 +21,7 @@
#include <QtDataVisualization/qdatavisualizationenums.h>
#include <QtDataVisualization/q3dwindow.h>
+#include <QtDataVisualization/q3dscene.h>
#include <QFont>
#include <QLinearGradient>
@@ -37,13 +38,13 @@ class QT_DATAVISUALIZATION_EXPORT Q3DSurface : public Q3DWindow
Q_PROPERTY(QtDataVisualization::QDataVis::LabelStyle labelStyle READ labelStyle WRITE setLabelStyle)
Q_PROPERTY(QtDataVisualization::QDataVis::Theme theme READ theme WRITE setTheme)
Q_PROPERTY(QtDataVisualization::QDataVis::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality)
- Q_PROPERTY(QtDataVisualization::QDataVis::CameraPreset cameraPreset READ cameraPreset WRITE setCameraPreset)
Q_PROPERTY(bool gridVisible READ isGridVisible WRITE setGridVisible)
Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible)
Q_PROPERTY(bool smoothSurfaceEnabled READ isSmoothSurfaceEnabled WRITE setSmoothSurfaceEnabled)
Q_PROPERTY(bool surfaceGridEnabled READ isSurfaceGridEnabled WRITE setSurfaceGridEnabled)
Q_PROPERTY(QLinearGradient gradient READ gradient WRITE setGradient)
Q_PROPERTY(QFont font READ font WRITE setFont)
+ Q_PROPERTY(Q3DScene* scene READ scene)
Q_ENUMS(QtDataVisualization::QDataVis::SelectionMode)
Q_ENUMS(QtDataVisualization::QDataVis::ShadowQuality)
Q_ENUMS(QtDataVisualization::QDataVis::LabelStyle)
@@ -65,11 +66,6 @@ public:
void setShadowQuality(QDataVis::ShadowQuality quality);
QDataVis::ShadowQuality shadowQuality() const;
- void setCameraPreset(QDataVis::CameraPreset preset);
- QDataVis::CameraPreset cameraPreset() const;
-
- void setCameraPosition(qreal horizontal, qreal vertical, int distance = 100);
-
void setSmoothSurfaceEnabled(bool enabled);
bool isSmoothSurfaceEnabled() const;
@@ -103,6 +99,8 @@ public:
void setFont(const QFont &font);
QFont font() const;
+ Q3DScene *scene() const;
+
void setLabelStyle(QDataVis::LabelStyle style);
QDataVis::LabelStyle labelStyle() const;
diff --git a/src/datavisualization/engine/scatter3drenderer.cpp b/src/datavisualization/engine/scatter3drenderer.cpp
index 61610e1a..a482cc42 100644
--- a/src/datavisualization/engine/scatter3drenderer.cpp
+++ b/src/datavisualization/engine/scatter3drenderer.cpp
@@ -176,7 +176,9 @@ void Scatter3DRenderer::updateScene(Q3DScene *scene)
{
// TODO: Move these to more suitable place e.g. controller should be controlling the viewports.
scene->setPrimarySubViewport(m_mainViewPort);
- scene->setUnderSideCameraEnabled(true);
+
+ // TODO: See QTRD-2374
+ scene->activeCamera()->setMinYRotation(-90.0f);
if (m_hasHeightAdjustmentChanged) {
// Set initial m_cachedScene->activeCamera() position. Also update if height adjustment has changed.
diff --git a/src/datavisualization/engine/selectionpointer.cpp b/src/datavisualization/engine/selectionpointer.cpp
index 8a68d792..d1a4c42a 100644
--- a/src/datavisualization/engine/selectionpointer.cpp
+++ b/src/datavisualization/engine/selectionpointer.cpp
@@ -166,10 +166,11 @@ void SelectionPointer::render(GLuint defaultFboHandle)
modelMatrixLabel.translate(m_position + labelAlign + QVector3D(0.0f, 0.0f, zComp));
// Position the label towards the camera
- QPointF camRotations = camera->rotations();
+ qreal camRotationsX = camera->xRotation();
+ qreal camRotationsY = camera->yRotation();
if (!m_cachedIsSlicingActivated) {
- modelMatrixLabel.rotate(-camRotations.x(), 0.0f, 1.0f, 0.0f);
- modelMatrixLabel.rotate(-camRotations.y(), 1.0f, 0.0f, 0.0f);
+ modelMatrixLabel.rotate(-camRotationsX, 0.0f, 1.0f, 0.0f);
+ modelMatrixLabel.rotate(-camRotationsY, 1.0f, 0.0f, 0.0f);
}
// Scale label based on text size