From f8f57fe64c29408a8d3c41c536639e08f84747e4 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 7 Jan 2014 11:09:34 +0200 Subject: Abstract base class for graphs Rename the Q3DWindow -> QAbstract3DGraph Moved common properties and functionality from subclasses to QAbstract3DGraph Task-number: QTRD-2213 Change-Id: Icc1733f7efb1b06bdda024f1cf42b8bc24d96885 Reviewed-by: Mika Salmela --- .../engine/abstract3dcontroller_p.h | 2 +- src/datavisualization/engine/engine.pri | 6 +- src/datavisualization/engine/q3dbars.cpp | 134 +------ src/datavisualization/engine/q3dbars.h | 27 +- src/datavisualization/engine/q3dbars_p.h | 7 +- src/datavisualization/engine/q3dscatter.cpp | 122 +----- src/datavisualization/engine/q3dscatter.h | 29 +- src/datavisualization/engine/q3dscatter_p.h | 7 +- src/datavisualization/engine/q3dscene.h | 2 +- src/datavisualization/engine/q3dsurface.cpp | 108 +----- src/datavisualization/engine/q3dsurface.h | 28 +- src/datavisualization/engine/q3dsurface_p.h | 4 +- src/datavisualization/engine/q3dwindow.cpp | 310 --------------- src/datavisualization/engine/q3dwindow.h | 76 ---- src/datavisualization/engine/q3dwindow_p.h | 71 ---- src/datavisualization/engine/qabstract3dgraph.cpp | 414 +++++++++++++++++++++ src/datavisualization/engine/qabstract3dgraph.h | 100 +++++ src/datavisualization/engine/qabstract3dgraph_p.h | 71 ++++ 18 files changed, 617 insertions(+), 901 deletions(-) delete mode 100644 src/datavisualization/engine/q3dwindow.cpp delete mode 100644 src/datavisualization/engine/q3dwindow.h delete mode 100644 src/datavisualization/engine/q3dwindow_p.h create mode 100644 src/datavisualization/engine/qabstract3dgraph.cpp create mode 100644 src/datavisualization/engine/qabstract3dgraph.h create mode 100644 src/datavisualization/engine/qabstract3dgraph_p.h diff --git a/src/datavisualization/engine/abstract3dcontroller_p.h b/src/datavisualization/engine/abstract3dcontroller_p.h index 66c61a53..b9c99210 100644 --- a/src/datavisualization/engine/abstract3dcontroller_p.h +++ b/src/datavisualization/engine/abstract3dcontroller_p.h @@ -159,9 +159,9 @@ protected: QList m_seriesList; explicit Abstract3DController(QRect initialViewport, QObject *parent = 0); - virtual ~Abstract3DController(); public: + virtual ~Abstract3DController(); inline bool isInitialized() { return (m_renderer != 0); } virtual void synchDataToRenderer(); diff --git a/src/datavisualization/engine/engine.pri b/src/datavisualization/engine/engine.pri index 899979e1..e13a9a04 100644 --- a/src/datavisualization/engine/engine.pri +++ b/src/datavisualization/engine/engine.pri @@ -1,5 +1,5 @@ -HEADERS += $$PWD/q3dwindow_p.h \ - $$PWD/q3dwindow.h \ +HEADERS += $$PWD/qabstract3dgraph_p.h \ + $$PWD/qabstract3dgraph.h \ $$PWD/q3dbars.h \ $$PWD/q3dbars_p.h \ $$PWD/drawer_p.h \ @@ -28,7 +28,7 @@ HEADERS += $$PWD/q3dwindow_p.h \ $$PWD/q3dobject_p.h \ $$PWD/q3dscene_p.h -SOURCES += $$PWD/q3dwindow.cpp \ +SOURCES += $$PWD/qabstract3dgraph.cpp \ $$PWD/q3dbars.cpp \ $$PWD/drawer.cpp \ $$PWD/bars3dcontroller.cpp \ diff --git a/src/datavisualization/engine/q3dbars.cpp b/src/datavisualization/engine/q3dbars.cpp index 530235f2..0d711359 100644 --- a/src/datavisualization/engine/q3dbars.cpp +++ b/src/datavisualization/engine/q3dbars.cpp @@ -24,9 +24,6 @@ #include "q3dcamera.h" #include "qbar3dseries_p.h" -#include - - QT_DATAVISUALIZATION_BEGIN_NAMESPACE /*! @@ -99,19 +96,11 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE * Constructs a new 3D bar graph with optional \a parent window. */ Q3DBars::Q3DBars(QWindow *parent) - : Q3DWindow(new Q3DBarsPrivate(this), parent) + : QAbstract3DGraph(new Q3DBarsPrivate(this), parent) { dptr()->m_shared = new Bars3DController(geometry()); d_ptr->setVisualController(dptr()->m_shared); dptr()->m_shared->initializeOpenGL(); - QObject::connect(dptr()->m_shared, &Abstract3DController::selectionModeChanged, this, - &Q3DBars::selectionModeChanged); - QObject::connect(dptr()->m_shared, &Abstract3DController::shadowQualityChanged, this, - &Q3DBars::shadowQualityChanged); - QObject::connect(dptr()->m_shared, &Abstract3DController::needRender, d_ptr.data(), - &Q3DWindowPrivate::renderLater); - QObject::connect(dptr()->m_shared, &Abstract3DController::shadowQualityChanged, dptr(), - &Q3DBarsPrivate::handleShadowQualityUpdate); } /*! @@ -150,65 +139,6 @@ QList Q3DBars::seriesList() return dptr()->m_shared->barSeriesList(); } -/*! - * \internal - */ -void Q3DBars::mouseDoubleClickEvent(QMouseEvent *event) -{ - dptr()->m_shared->mouseDoubleClickEvent(event); -} - -/*! - * \internal - */ -void Q3DBars::touchEvent(QTouchEvent *event) -{ - dptr()->m_shared->touchEvent(event); -} - -/*! - * \internal - */ -void Q3DBars::mousePressEvent(QMouseEvent *event) -{ - dptr()->m_shared->mousePressEvent(event, event->pos()); -} - -/*! - * \internal - */ -void Q3DBars::mouseReleaseEvent(QMouseEvent *event) -{ - dptr()->m_shared->mouseReleaseEvent(event, event->pos()); -} - -/*! - * \internal - */ -void Q3DBars::mouseMoveEvent(QMouseEvent *event) -{ - dptr()->m_shared->mouseMoveEvent(event, event->pos()); -} - -/*! - * \internal - */ -void Q3DBars::wheelEvent(QWheelEvent *event) -{ - dptr()->m_shared->wheelEvent(event); -} - - -Q3DBarsPrivate *Q3DBars::dptr() -{ - return static_cast(d_ptr.data()); -} - -const Q3DBarsPrivate *Q3DBars::dptrc() const -{ - return static_cast(d_ptr.data()); -} - /*! * \property Q3DBars::barThickness * @@ -269,52 +199,6 @@ bool Q3DBars::isBarSpacingRelative() return dptr()->m_shared->isBarSpecRelative(); } -/*! - * \property Q3DBars::selectionMode - * - * Sets bar selection \a mode to a combination of \c QDataVis::SelectionFlags. It is preset to - * \c QDataVis::SelectionItem by default. - */ -void Q3DBars::setSelectionMode(QDataVis::SelectionFlags mode) -{ - dptr()->m_shared->setSelectionMode(mode); -} - -QDataVis::SelectionFlags Q3DBars::selectionMode() const -{ - return dptrc()->m_shared->selectionMode(); -} - -/*! - * \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 dptrc()->m_shared->scene(); -} - -/*! - * \property Q3DBars::shadowQuality - * - * Sets shadow \a quality to one of \c QDataVis::ShadowQuality. It is preset to - * \c QDataVis::ShadowQualityMedium by default. - * - * \note If setting QDataVis::ShadowQuality of a certain level fails, a level is lowered - * until it is successful and shadowQualityChanged signal is emitted for each time the change is - * done. - */ -void Q3DBars::setShadowQuality(QDataVis::ShadowQuality quality) -{ - dptr()->m_shared->setShadowQuality(quality); -} - -QDataVis::ShadowQuality Q3DBars::shadowQuality() const -{ - return dptrc()->m_shared->shadowQuality(); -} - /*! * Sets a user-defined row \a axis. Implicitly calls addAxis() to transfer ownership of * the \a axis to this graph. @@ -417,19 +301,23 @@ QList Q3DBars::axes() const return dptrc()->m_shared->axes(); } -Q3DBarsPrivate::Q3DBarsPrivate(Q3DBars *q) - : Q3DWindowPrivate(q) +Q3DBarsPrivate *Q3DBars::dptr() { + return static_cast(d_ptr.data()); } -Q3DBarsPrivate::~Q3DBarsPrivate() +const Q3DBarsPrivate *Q3DBars::dptrc() const { - delete m_shared; + return static_cast(d_ptr.data()); } -void Q3DBarsPrivate::handleShadowQualityUpdate(QDataVis::ShadowQuality quality) +Q3DBarsPrivate::Q3DBarsPrivate(Q3DBars *q) + : QAbstract3DGraphPrivate(q) +{ +} + +Q3DBarsPrivate::~Q3DBarsPrivate() { - emit qptr()->shadowQualityChanged(quality); } Q3DBars *Q3DBarsPrivate::qptr() diff --git a/src/datavisualization/engine/q3dbars.h b/src/datavisualization/engine/q3dbars.h index fac9558f..7da446b4 100644 --- a/src/datavisualization/engine/q3dbars.h +++ b/src/datavisualization/engine/q3dbars.h @@ -20,7 +20,7 @@ #define Q3DBARS_H #include -#include +#include #include #include @@ -30,18 +30,14 @@ class Q3DBarsPrivate; class Q3DAbstractAxis; class Q3DCategoryAxis; class Q3DValueAxis; -class Q3DScene; class QBar3DSeries; -class QT_DATAVISUALIZATION_EXPORT Q3DBars : public Q3DWindow +class QT_DATAVISUALIZATION_EXPORT Q3DBars : public QAbstract3DGraph { Q_OBJECT - Q_PROPERTY(QtDataVisualization::QDataVis::SelectionFlags selectionMode READ selectionMode WRITE setSelectionMode NOTIFY selectionModeChanged) - Q_PROPERTY(QtDataVisualization::QDataVis::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality NOTIFY shadowQualityChanged) Q_PROPERTY(float barThickness READ barThickness WRITE setBarThickness NOTIFY barThicknessChanged) Q_PROPERTY(QSizeF barSpacing READ barSpacing WRITE setBarSpacing NOTIFY barSpacingChanged) Q_PROPERTY(bool barSpacingRelative READ isBarSpacingRelative WRITE setBarSpacingRelative NOTIFY barSpacingRelativeChanged) - Q_PROPERTY(Q3DScene* scene READ scene) public: explicit Q3DBars(QWindow *parent = 0); @@ -60,14 +56,6 @@ public: void setBarSpacingRelative(bool relative); bool isBarSpacingRelative(); - void setSelectionMode(QDataVis::SelectionFlags mode); - QDataVis::SelectionFlags selectionMode() const; - - Q3DScene *scene() const; - - void setShadowQuality(QDataVis::ShadowQuality quality); - QDataVis::ShadowQuality shadowQuality() const; - void setRowAxis(Q3DCategoryAxis *axis); Q3DCategoryAxis *rowAxis() const; void setColumnAxis(Q3DCategoryAxis *axis); @@ -79,21 +67,10 @@ public: QList axes() const; signals: - void selectionModeChanged(QDataVis::SelectionFlags mode); - void shadowQualityChanged(QDataVis::ShadowQuality quality); void barThicknessChanged(float thicknessRatio); void barSpacingChanged(QSizeF spacing); void barSpacingRelativeChanged(bool relative); -protected: - - void mouseDoubleClickEvent(QMouseEvent *event); - void touchEvent(QTouchEvent *event); - void mousePressEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void wheelEvent(QWheelEvent *event); - private: Q3DBarsPrivate *dptr(); const Q3DBarsPrivate *dptrc() const; diff --git a/src/datavisualization/engine/q3dbars_p.h b/src/datavisualization/engine/q3dbars_p.h index 9a059d8d..6bb90b40 100644 --- a/src/datavisualization/engine/q3dbars_p.h +++ b/src/datavisualization/engine/q3dbars_p.h @@ -31,22 +31,19 @@ #include "bars3dcontroller_p.h" #include "qdatavisualizationenums.h" -#include "q3dwindow_p.h" +#include "qabstract3dgraph_p.h" QT_DATAVISUALIZATION_BEGIN_NAMESPACE class Q3DBars; -class Q3DBarsPrivate : public Q3DWindowPrivate +class Q3DBarsPrivate : public QAbstract3DGraphPrivate { Q_OBJECT public: Q3DBarsPrivate(Q3DBars *q); ~Q3DBarsPrivate(); - // Used to detect when shadow quality changes autonomously due to e.g. resizing. - void handleShadowQualityUpdate(QDataVis::ShadowQuality quality); - Q3DBars *qptr(); Bars3DController *m_shared; diff --git a/src/datavisualization/engine/q3dscatter.cpp b/src/datavisualization/engine/q3dscatter.cpp index 13b22df4..aef1e89e 100644 --- a/src/datavisualization/engine/q3dscatter.cpp +++ b/src/datavisualization/engine/q3dscatter.cpp @@ -23,8 +23,6 @@ #include "q3dcamera.h" #include "qscatter3dseries_p.h" -#include - QT_DATAVISUALIZATION_BEGIN_NAMESPACE /*! @@ -83,19 +81,11 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE * Constructs a new 3D scatter graph with optional \a parent window. */ Q3DScatter::Q3DScatter(QWindow *parent) - : Q3DWindow(new Q3DScatterPrivate(this), parent) + : QAbstract3DGraph(new Q3DScatterPrivate(this), parent) { dptr()->m_shared = new Scatter3DController(geometry()); d_ptr->setVisualController(dptr()->m_shared); dptr()->m_shared->initializeOpenGL(); - QObject::connect(dptr()->m_shared, &Abstract3DController::selectionModeChanged, this, - &Q3DScatter::selectionModeChanged); - QObject::connect(dptr()->m_shared, &Abstract3DController::shadowQualityChanged, this, - &Q3DScatter::shadowQualityChanged); - QObject::connect(dptr()->m_shared, &Abstract3DController::needRender, d_ptr.data(), - &Q3DWindowPrivate::renderLater); - QObject::connect(dptr()->m_shared, &Abstract3DController::shadowQualityChanged, dptr(), - &Q3DScatterPrivate::handleShadowQualityUpdate); } /*! @@ -131,54 +121,6 @@ QList Q3DScatter::seriesList() return dptr()->m_shared->scatterSeriesList(); } -/*! - * \internal - */ -void Q3DScatter::mouseDoubleClickEvent(QMouseEvent *event) -{ - dptr()->m_shared->mouseDoubleClickEvent(event); -} - -/*! - * \internal - */ -void Q3DScatter::touchEvent(QTouchEvent *event) -{ - dptr()->m_shared->touchEvent(event); -} - -/*! - * \internal - */ -void Q3DScatter::mousePressEvent(QMouseEvent *event) -{ - dptr()->m_shared->mousePressEvent(event, event->pos()); -} - -/*! - * \internal - */ -void Q3DScatter::mouseReleaseEvent(QMouseEvent *event) -{ - dptr()->m_shared->mouseReleaseEvent(event, event->pos()); -} - -/*! - * \internal - */ -void Q3DScatter::mouseMoveEvent(QMouseEvent *event) -{ - dptr()->m_shared->mouseMoveEvent(event, event->pos()); -} - -/*! - * \internal - */ -void Q3DScatter::wheelEvent(QWheelEvent *event) -{ - dptr()->m_shared->wheelEvent(event); -} - Q3DScatterPrivate *Q3DScatter::dptr() { return static_cast(d_ptr.data()); @@ -189,54 +131,6 @@ const Q3DScatterPrivate *Q3DScatter::dptrc() const return static_cast(d_ptr.data()); } -/*! - * \property Q3DScatter::selectionMode - * - * Sets item selection \a mode to a combination of \c QDataVis::SelectionFlags. It is preset to - * \c QDataVis::SelectionItem by default. - * - * \note Only \c QDataVis::SelectionItem and \c QDataVis::SelectionNone are supported. - */ -void Q3DScatter::setSelectionMode(QDataVis::SelectionFlags mode) -{ - dptr()->m_shared->setSelectionMode(mode); -} - -QDataVis::SelectionFlags Q3DScatter::selectionMode() const -{ - return dptrc()->m_shared->selectionMode(); -} - -/*! - * \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 dptrc()->m_shared->scene(); -} - -/*! - * \property Q3DScatter::shadowQuality - * - * Sets shadow \a quality to one of \c QDataVis::ShadowQuality. It is preset to - * \c QDataVis::ShadowQualityMedium by default. - * - * \note If setting QDataVis::ShadowQuality of a certain level fails, a level is lowered - * until it is successful and shadowQualityChanged signal is emitted for each time the change is - * done. - */ -void Q3DScatter::setShadowQuality(QDataVis::ShadowQuality quality) -{ - return dptr()->m_shared->setShadowQuality(quality); -} - -QDataVis::ShadowQuality Q3DScatter::shadowQuality() const -{ - return dptrc()->m_shared->shadowQuality(); -} - /*! * Sets a user-defined X-axis. Implicitly calls addAxis() to transfer ownership * of the \a axis to this graph. @@ -346,25 +240,13 @@ QList Q3DScatter::axes() const return retList; } -/*! - * \fn void Q3DScatter::shadowQualityChanged(QDataVis::ShadowQuality quality) - * - * This signal is emitted when shadow \a quality changes. - */ - Q3DScatterPrivate::Q3DScatterPrivate(Q3DScatter *q) - : Q3DWindowPrivate(q) + : QAbstract3DGraphPrivate(q) { } Q3DScatterPrivate::~Q3DScatterPrivate() { - delete m_shared; -} - -void Q3DScatterPrivate::handleShadowQualityUpdate(QDataVis::ShadowQuality quality) -{ - emit qptr()->shadowQualityChanged(quality); } Q3DScatter *Q3DScatterPrivate::qptr() diff --git a/src/datavisualization/engine/q3dscatter.h b/src/datavisualization/engine/q3dscatter.h index f71b469e..f6f3dd2f 100644 --- a/src/datavisualization/engine/q3dscatter.h +++ b/src/datavisualization/engine/q3dscatter.h @@ -20,7 +20,7 @@ #define Q3DSCATTER_H #include -#include +#include #include #include #include @@ -28,18 +28,13 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE class Q3DScatterPrivate; -class LabelItem; class Q3DValueAxis; class Q3DCategoryAxis; class QScatter3DSeries; -class QT_DATAVISUALIZATION_EXPORT Q3DScatter : public Q3DWindow +class QT_DATAVISUALIZATION_EXPORT Q3DScatter : public QAbstract3DGraph { Q_OBJECT - Q_PROPERTY(QtDataVisualization::QDataVis::SelectionFlags selectionMode READ selectionMode WRITE setSelectionMode NOTIFY selectionModeChanged) - Q_PROPERTY(QtDataVisualization::QDataVis::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality NOTIFY shadowQualityChanged) - Q_PROPERTY(Q3DScene* scene READ scene) - public: explicit Q3DScatter(QWindow *parent = 0); virtual ~Q3DScatter(); @@ -48,14 +43,6 @@ public: void removeSeries(QScatter3DSeries *series); QList seriesList(); - void setSelectionMode(QDataVis::SelectionFlags mode); - QDataVis::SelectionFlags selectionMode() const; - - Q3DScene *scene() const; - - void setShadowQuality(QDataVis::ShadowQuality quality); - QDataVis::ShadowQuality shadowQuality() const; - void setAxisX(Q3DValueAxis *axis); Q3DValueAxis *axisX() const; void setAxisY(Q3DValueAxis *axis); @@ -66,18 +53,6 @@ public: void releaseAxis(Q3DValueAxis *axis); QList axes() const; -signals: - void selectionModeChanged(QDataVis::SelectionFlags mode); - void shadowQualityChanged(QDataVis::ShadowQuality quality); - -protected: - void mouseDoubleClickEvent(QMouseEvent *event); - void touchEvent(QTouchEvent *event); - void mousePressEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void wheelEvent(QWheelEvent *event); - private: Q3DScatterPrivate *dptr(); const Q3DScatterPrivate *dptrc() const; diff --git a/src/datavisualization/engine/q3dscatter_p.h b/src/datavisualization/engine/q3dscatter_p.h index d65776c5..e8140c04 100644 --- a/src/datavisualization/engine/q3dscatter_p.h +++ b/src/datavisualization/engine/q3dscatter_p.h @@ -31,22 +31,19 @@ #include "scatter3dcontroller_p.h" #include "qdatavisualizationenums.h" -#include "q3dwindow_p.h" +#include "qabstract3dgraph_p.h" QT_DATAVISUALIZATION_BEGIN_NAMESPACE class Q3DScatter; -class Q3DScatterPrivate : public Q3DWindowPrivate +class Q3DScatterPrivate : public QAbstract3DGraphPrivate { Q_OBJECT public: Q3DScatterPrivate(Q3DScatter *q); ~Q3DScatterPrivate(); - // Used to detect when shadow quality changes autonomously due to e.g. resizing. - void handleShadowQualityUpdate(QDataVis::ShadowQuality quality); - Q3DScatter *qptr(); Scatter3DController *m_shared; diff --git a/src/datavisualization/engine/q3dscene.h b/src/datavisualization/engine/q3dscene.h index b0dadff9..27e09ab0 100644 --- a/src/datavisualization/engine/q3dscene.h +++ b/src/datavisualization/engine/q3dscene.h @@ -96,7 +96,7 @@ private: Q_DISABLE_COPY(Q3DScene) friend class AbstractDeclarative; - friend class Q3DWindow; + friend class QAbstract3DGraph; friend class Abstract3DController; friend class Q3DScenePrivate; friend class Abstract3DRenderer; diff --git a/src/datavisualization/engine/q3dsurface.cpp b/src/datavisualization/engine/q3dsurface.cpp index feb2ef22..0df5a9bb 100644 --- a/src/datavisualization/engine/q3dsurface.cpp +++ b/src/datavisualization/engine/q3dsurface.cpp @@ -23,8 +23,6 @@ #include "q3dcamera.h" #include "qsurface3dseries_p.h" -#include - QT_DATAVISUALIZATION_BEGIN_NAMESPACE /*! @@ -96,17 +94,11 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE * Constructs a new 3D surface graph with optional \a parent window. */ Q3DSurface::Q3DSurface(QWindow *parent) - : Q3DWindow(new Q3DSurfacePrivate(this), parent) + : QAbstract3DGraph(new Q3DSurfacePrivate(this), parent) { dptr()->m_shared = new Surface3DController(geometry()); d_ptr->setVisualController(dptr()->m_shared); dptr()->m_shared->initializeOpenGL(); - QObject::connect(dptr()->m_shared, &Abstract3DController::selectionModeChanged, this, - &Q3DSurface::selectionModeChanged); - QObject::connect(dptr()->m_shared, &Abstract3DController::shadowQualityChanged, this, - &Q3DSurface::shadowQualityChanged); - QObject::connect(dptr()->m_shared, &Abstract3DController::needRender, d_ptr.data(), - &Q3DWindowPrivate::renderLater); } /*! @@ -144,54 +136,6 @@ QList Q3DSurface::seriesList() return dptr()->m_shared->surfaceSeriesList(); } -/*! - * \internal - */ -void Q3DSurface::mouseDoubleClickEvent(QMouseEvent *event) -{ - dptr()->m_shared->mouseDoubleClickEvent(event); -} - -/*! - * \internal - */ -void Q3DSurface::touchEvent(QTouchEvent *event) -{ - dptr()->m_shared->touchEvent(event); -} - -/*! - * \internal - */ -void Q3DSurface::mousePressEvent(QMouseEvent *event) -{ - dptr()->m_shared->mousePressEvent(event, event->pos()); -} - -/*! - * \internal - */ -void Q3DSurface::mouseReleaseEvent(QMouseEvent *event) -{ - dptr()->m_shared->mouseReleaseEvent(event, event->pos()); -} - -/*! - * \internal - */ -void Q3DSurface::mouseMoveEvent(QMouseEvent *event) -{ - dptr()->m_shared->mouseMoveEvent(event, event->pos()); -} - -/*! - * \internal - */ -void Q3DSurface::wheelEvent(QWheelEvent *event) -{ - dptr()->m_shared->wheelEvent(event); -} - Q3DSurfacePrivate *Q3DSurface::dptr() { return static_cast(d_ptr.data()); @@ -202,53 +146,6 @@ const Q3DSurfacePrivate *Q3DSurface::dptrc() const return static_cast(d_ptr.data()); } -/*! - * \property Q3DSurface::shadowQuality - * - * Sets shadow \a quality to one of \c QDataVis::ShadowQuality. It is preset to - * \c QDataVis::ShadowQualityMedium by default. - * - * \note If setting QDataVis::ShadowQuality of a certain level fails, a level is lowered - * until it is successful and shadowQualityChanged signal is emitted for each time the change is - * done. - */ -void Q3DSurface::setShadowQuality(QDataVis::ShadowQuality quality) -{ - return dptr()->m_shared->setShadowQuality(quality); -} - -QDataVis::ShadowQuality Q3DSurface::shadowQuality() const -{ - return dptrc()->m_shared->shadowQuality(); -} - -/*! - * \property Q3DSurface::selectionMode - * - * Sets point selection \a mode to a combination of \c QDataVis::SelectionFlags. Surface supports - * \c SelectionItem and \c SelectionSlice with either \c SelectionRow or \c SelectionColumn. - * It is preset to \c SelectionItem by default. - */ -void Q3DSurface::setSelectionMode(QDataVis::SelectionFlags mode) -{ - dptr()->m_shared->setSelectionMode(mode); -} - -QDataVis::SelectionFlags Q3DSurface::selectionMode() const -{ - return dptrc()->m_shared->selectionMode(); -} - -/*! - * \property Q3DSurface::scene - * - * This property contains the read only Q3DScene that can be used to access, for example, a camera object. - */ -Q3DScene *Q3DSurface::scene() const -{ - return dptrc()->m_shared->scene(); -} - /*! * Sets a user-defined X-axis. Implicitly calls addAxis() to transfer ownership * of the \a axis to this graph. @@ -361,13 +258,12 @@ QList Q3DSurface::axes() const /////////////////// PRIVATE /////////////////////////////////// Q3DSurfacePrivate::Q3DSurfacePrivate(Q3DSurface *q) - : Q3DWindowPrivate(q) + : QAbstract3DGraphPrivate(q) { } Q3DSurfacePrivate::~Q3DSurfacePrivate() { - delete m_shared; } Q3DSurface *Q3DSurfacePrivate::qptr() diff --git a/src/datavisualization/engine/q3dsurface.h b/src/datavisualization/engine/q3dsurface.h index b91854d5..822e9d7c 100644 --- a/src/datavisualization/engine/q3dsurface.h +++ b/src/datavisualization/engine/q3dsurface.h @@ -20,7 +20,7 @@ #define Q3DSURFACE_H #include -#include +#include #include #include @@ -30,13 +30,9 @@ class Q3DSurfacePrivate; class Q3DValueAxis; class QSurface3DSeries; -class QT_DATAVISUALIZATION_EXPORT Q3DSurface : public Q3DWindow +class QT_DATAVISUALIZATION_EXPORT Q3DSurface : public QAbstract3DGraph { Q_OBJECT - Q_PROPERTY(QtDataVisualization::QDataVis::SelectionFlags selectionMode READ selectionMode WRITE setSelectionMode NOTIFY selectionModeChanged) - Q_PROPERTY(QtDataVisualization::QDataVis::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality NOTIFY shadowQualityChanged) - Q_PROPERTY(Q3DScene* scene READ scene) - public: explicit Q3DSurface(QWindow *parent = 0); virtual ~Q3DSurface(); @@ -45,12 +41,6 @@ public: void removeSeries(QSurface3DSeries *series); QList seriesList(); - void setShadowQuality(QDataVis::ShadowQuality quality); - QDataVis::ShadowQuality shadowQuality() const; - - void setSelectionMode(QDataVis::SelectionFlags mode); - QDataVis::SelectionFlags selectionMode() const; - // Axes void setAxisX(Q3DValueAxis *axis); Q3DValueAxis *axisX() const; @@ -62,20 +52,6 @@ public: void releaseAxis(Q3DValueAxis *axis); QList axes() const; - Q3DScene *scene() const; - -signals: - void selectionModeChanged(QDataVis::SelectionFlags mode); - void shadowQualityChanged(QDataVis::ShadowQuality quality); - -protected: - void mouseDoubleClickEvent(QMouseEvent *event); - void touchEvent(QTouchEvent *event); - void mousePressEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void wheelEvent(QWheelEvent *event); - private: Q3DSurfacePrivate *dptr(); const Q3DSurfacePrivate *dptrc() const; diff --git a/src/datavisualization/engine/q3dsurface_p.h b/src/datavisualization/engine/q3dsurface_p.h index de2a518c..b1284453 100644 --- a/src/datavisualization/engine/q3dsurface_p.h +++ b/src/datavisualization/engine/q3dsurface_p.h @@ -31,7 +31,7 @@ #include "surface3dcontroller_p.h" #include "qdatavisualizationenums.h" -#include "q3dwindow_p.h" +#include "qabstract3dgraph_p.h" #include @@ -39,7 +39,7 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE class Q3DSurface; -class Q3DSurfacePrivate : public Q3DWindowPrivate +class Q3DSurfacePrivate : public QAbstract3DGraphPrivate { Q_OBJECT public: diff --git a/src/datavisualization/engine/q3dwindow.cpp b/src/datavisualization/engine/q3dwindow.cpp deleted file mode 100644 index 6bf7da5e..00000000 --- a/src/datavisualization/engine/q3dwindow.cpp +++ /dev/null @@ -1,310 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 "q3dwindow.h" -#include "q3dwindow_p.h" -#include "abstract3dcontroller_p.h" -#include "qabstract3dinputhandler_p.h" -#include "q3dscene_p.h" - -#include -#include -#include -#include - - -QT_DATAVISUALIZATION_BEGIN_NAMESPACE - -/*! - * \class Q3DWindow - * \inmodule QtDataVisualization - * \brief The Q3DWindow class provides a window and render loop. - * \since Qt Data Visualization 1.0 - * - * This class creates a QWindow and provides render loop for visualization types inheriting it. - * - * You should not need to use this class directly, but one of its subclasses instead. - * - * \note Q3DWindow sets window flag \c{Qt::FramelessWindowHint} on by default. If you want to display - * graph windows as standalone windows with regular window frame, clear this flag after constructing - * the graph. For example: - * - * \code - * Q3DBars *graphWindow = new Q3DBars; - * graphWindow->setFlags(graphWindow->flags() ^ Qt::FramelessWindowHint); - * \endcode - * - * \sa Q3DBars, Q3DScatter, Q3DSurface, {Qt Data Visualization C++ Classes} - */ - -/*! - * \internal - */ -Q3DWindow::Q3DWindow(Q3DWindowPrivate *d, QWindow *parent) - : QWindow(parent), - d_ptr(d) -{ - d_ptr->m_context = new QOpenGLContext(this); - - setFlags(flags() | Qt::FramelessWindowHint); - setSurfaceType(QWindow::OpenGLSurface); - QSurfaceFormat surfaceFormat; - surfaceFormat.setDepthBufferSize(24); -#if !defined(QT_OPENGL_ES_2) - surfaceFormat.setSamples(8); - surfaceFormat.setRenderableType(QSurfaceFormat::OpenGL); -#else - surfaceFormat.setRenderableType(QSurfaceFormat::OpenGLES); -#endif - surfaceFormat.setSwapBehavior(QSurfaceFormat::DoubleBuffer); - setFormat(surfaceFormat); - - create(); - - d_ptr->m_context->setFormat(requestedFormat()); - d_ptr->m_context->create(); - d_ptr->m_context->makeCurrent(this); - - initializeOpenGLFunctions(); - - const GLubyte *version = glGetString(GL_VERSION); - qDebug() << "OpenGL version:" << (const char *)version; - version = glGetString(GL_SHADING_LANGUAGE_VERSION); - qDebug() << "GLSL version:" << (const char *)version; -#if !defined(QT_OPENGL_ES_2) - // If we have real OpenGL, GLSL version must be 1.2 or over. Quit if not. - QStringList splitversionstr = QString::fromLatin1((const char *)version).split(QChar::fromLatin1(' ')); - if (splitversionstr[0].toFloat() < 1.2) - qFatal("GLSL version must be 1.20 or higher. Try installing latest display drivers."); -#endif - - QObject::connect(d_ptr->m_visualController, &Abstract3DController::activeThemeChanged, this, - &Q3DWindow::activeThemeChanged); - - d_ptr->renderLater(); -} - -/*! - * Destroys Q3DWindow. - */ -Q3DWindow::~Q3DWindow() -{ -} - -/*! - * Adds the given \a inputHandler to the graph. The input handlers added via addInputHandler - * are not taken in to use directly. Only the ownership of the a\ inputHandler is given to the graph. - * The \a inputHandler must not be null or already added to another graph. - * - * \sa releaseInputHandler(), setActiveInputHandler() - */ -void Q3DWindow::addInputHandler(QAbstract3DInputHandler *inputHandler) -{ - d_ptr->m_visualController->addInputHandler(inputHandler); -} - -/*! - * Releases the ownership of the \a inputHandler back to the caller, if it was added to this graph. - * If the released \a inputHandler is in use there will be no input handler active after this call. - * - * If the default input handler is released and added back later, it behaves as any other input handler would. - * - * \sa addInputHandler(), setActiveInputHandler() - */ -void Q3DWindow::releaseInputHandler(QAbstract3DInputHandler *inputHandler) -{ - d_ptr->m_visualController->releaseInputHandler(inputHandler); -} - -/*! - * Sets the active \a inputHandler. Implicitly calls addInputHandler() to transfer ownership of - * the \a inputHandler to this graph. - * - * If the \a inputHandler is null, no input handler will be active after this call. - * - * \sa addInputHandler(), releaseInputHandler() - */ -void Q3DWindow::setActiveInputHandler(QAbstract3DInputHandler *inputHandler) -{ - d_ptr->m_visualController->setActiveInputHandler(inputHandler); -} - -/*! - * \return currently active input handler. - */ -QAbstract3DInputHandler *Q3DWindow::activeInputHandler() -{ - return d_ptr->m_visualController->activeInputHandler(); -} - -/*! - * Adds the given \a theme to the graph. The themes added via addTheme are not taken in to use - * directly. Only the ownership of the a\ theme is given to the graph. - * The \a theme must not be null or already added to another graph. - * - * \sa releaseTheme(), setActiveTheme() - */ -void Q3DWindow::addTheme(Q3DTheme *theme) -{ - d_ptr->m_visualController->addTheme(theme); -} - -/*! - * Releases the ownership of the \a theme back to the caller, if it was added to this graph. - * If the released \a theme is in use, a new default theme will be created and set active. - * - * If the default theme is released and added back later, it behaves as any other theme would. - * - * \sa addTheme(), setActiveTheme() - */ -void Q3DWindow::releaseTheme(Q3DTheme *theme) -{ - d_ptr->m_visualController->releaseTheme(theme); -} - -/*! - * \property Q3DWindow::activeTheme - * - * The active \a theme to be used for the graph. Implicitly calls addTheme() to transfer ownership - * of the \a theme to this graph. - * If the \a theme is null, a temporary default theme is created. This temporary theme is destroyed - * if any theme is explicitly set later. - * Properties of the \a theme can be modified even after setting it, and the modifications take - * effect immediately. - */ -void Q3DWindow::setActiveTheme(Q3DTheme *theme) -{ - d_ptr->m_visualController->setActiveTheme(theme); -} - - -Q3DTheme *Q3DWindow::activeTheme() const -{ - return d_ptr->m_visualController->activeTheme(); -} - -/*! - * \return list of all added themes. - * - * \sa addTheme() - */ -QList Q3DWindow::themes() const -{ - return d_ptr->m_visualController->themes(); -} - -/*! - * \internal - */ -bool Q3DWindow::event(QEvent *event) -{ - switch (event->type()) { - case QEvent::UpdateRequest: - d_ptr->renderNow(); - return true; - case QEvent::TouchBegin: - case QEvent::TouchCancel: - case QEvent::TouchUpdate: - case QEvent::TouchEnd: - d_ptr->m_visualController->touchEvent(static_cast(event)); - return true; - default: - return QWindow::event(event); - } -} - -/*! - * \internal - */ -void Q3DWindow::resizeEvent(QResizeEvent *event) -{ - Q_UNUSED(event); - - Q3DScene *scene = d_ptr->m_visualController->scene(); - scene->d_ptr->setWindowSize(QSize(width(), height())); - scene->d_ptr->setViewport(QRect(0, 0, width(), height())); -} - -/*! - * \internal - */ -void Q3DWindow::exposeEvent(QExposeEvent *event) -{ - Q_UNUSED(event); - - if (isExposed()) - d_ptr->renderNow(); -} - -Q3DWindowPrivate::Q3DWindowPrivate(Q3DWindow *q) - : QObject(0), - q_ptr(q), - m_updatePending(false), - m_visualController(0), - m_devicePixelRatio(1.f) -{ -} - -Q3DWindowPrivate::~Q3DWindowPrivate() -{ -} - -void Q3DWindowPrivate::render() -{ - handleDevicePixelRatioChange(); - m_visualController->synchDataToRenderer(); - m_visualController->render(); -} - -void Q3DWindowPrivate::renderLater() -{ - if (!m_updatePending) { - m_updatePending = true; - QCoreApplication::postEvent(q_ptr, new QEvent(QEvent::UpdateRequest)); - } -} - -void Q3DWindowPrivate::renderNow() -{ - if (!q_ptr->isExposed()) - return; - - m_updatePending = false; - - m_context->makeCurrent(q_ptr); - - render(); - - m_context->swapBuffers(q_ptr); -} - -void Q3DWindowPrivate::setVisualController(Abstract3DController *controller) -{ - m_visualController = controller; -} - -void Q3DWindowPrivate::handleDevicePixelRatioChange() -{ - if (q_ptr->devicePixelRatio() == m_devicePixelRatio || !m_visualController) - return; - - m_devicePixelRatio = q_ptr->devicePixelRatio(); - m_visualController->scene()->setDevicePixelRatio(m_devicePixelRatio); -} - -QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualization/engine/q3dwindow.h b/src/datavisualization/engine/q3dwindow.h deleted file mode 100644 index 18542868..00000000 --- a/src/datavisualization/engine/q3dwindow.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 Q3DWINDOW_H -#define Q3DWINDOW_H - -#include - -#include -#include -#include - -class QPainter; - -QT_DATAVISUALIZATION_BEGIN_NAMESPACE - -class Q3DWindowPrivate; -class Abstract3DController; -class QAbstract3DInputHandler; -class Q3DTheme; - -class QT_DATAVISUALIZATION_EXPORT Q3DWindow : public QWindow, protected QOpenGLFunctions -{ - Q_OBJECT - Q_PROPERTY(Q3DTheme* activeTheme READ activeTheme WRITE setActiveTheme NOTIFY activeThemeChanged) - -protected: - explicit Q3DWindow(Q3DWindowPrivate *d, QWindow *parent = 0); -public: - virtual ~Q3DWindow(); - - void addInputHandler(QAbstract3DInputHandler *inputHandler); - void releaseInputHandler(QAbstract3DInputHandler *inputHandler); - void setActiveInputHandler(QAbstract3DInputHandler *inputHandler); - QAbstract3DInputHandler *activeInputHandler(); - - void addTheme(Q3DTheme *theme); - void releaseTheme(Q3DTheme *theme); - void setActiveTheme(Q3DTheme *theme); - Q3DTheme *activeTheme() const; - QList themes() const; - -protected: - bool event(QEvent *event); - void resizeEvent(QResizeEvent *event); - void exposeEvent(QExposeEvent *event); - -signals: - void activeThemeChanged(Q3DTheme *theme); - -private: - QScopedPointer d_ptr; - - friend class Q3DBars; - friend class Q3DScatter; - friend class Q3DSurface; -}; - -QT_DATAVISUALIZATION_END_NAMESPACE - -#endif diff --git a/src/datavisualization/engine/q3dwindow_p.h b/src/datavisualization/engine/q3dwindow_p.h deleted file mode 100644 index ba8c67da..00000000 --- a/src/datavisualization/engine/q3dwindow_p.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 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 -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the QtDataVisualization API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. - -#ifndef Q3DWINDOW_P_H -#define Q3DWINDOW_P_H - -#include "datavisualizationglobal_p.h" - -#include - -class QOpenGLContext; -class QOpenGLPaintDevice; - -QT_DATAVISUALIZATION_BEGIN_NAMESPACE - -class Q3DWindow; -class Abstract3DController; - -class Q3DWindowPrivate : public QObject -{ - Q_OBJECT -public: - Q3DWindowPrivate(Q3DWindow *q); - ~Q3DWindowPrivate(); - - void render(); - - void setVisualController(Abstract3DController *controller); - void handleDevicePixelRatioChange(); - -public slots: - void renderLater(); - void renderNow(); - -public: - Q3DWindow *q_ptr; - - bool m_updatePending; - QOpenGLContext *m_context; - Abstract3DController *m_visualController; - float m_devicePixelRatio; -}; - -QT_DATAVISUALIZATION_END_NAMESPACE - -#endif diff --git a/src/datavisualization/engine/qabstract3dgraph.cpp b/src/datavisualization/engine/qabstract3dgraph.cpp new file mode 100644 index 00000000..8968ebb0 --- /dev/null +++ b/src/datavisualization/engine/qabstract3dgraph.cpp @@ -0,0 +1,414 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 "qabstract3dgraph.h" +#include "qabstract3dgraph_p.h" +#include "abstract3dcontroller_p.h" +#include "qabstract3dinputhandler_p.h" +#include "q3dscene_p.h" + +#include +#include +#include +#include + + +QT_DATAVISUALIZATION_BEGIN_NAMESPACE + +/*! + * \class QAbstract3DGraph + * \inmodule QtDataVisualization + * \brief The QAbstract3DGraph class provides a window and render loop for graphs. + * \since Qt Data Visualization 1.0 + * + * This class subclasses a QWindow and provides render loop for graphs inheriting it. + * + * You should not need to use this class directly, but one of its subclasses instead. + * + * \note QAbstract3DGraph sets window flag \c{Qt::FramelessWindowHint} on by default. If you want to display + * graph windows as standalone windows with regular window frame, clear this flag after constructing + * the graph. For example: + * + * \code + * Q3DBars *graphWindow = new Q3DBars; + * graphWindow->setFlags(graphWindow->flags() ^ Qt::FramelessWindowHint); + * \endcode + * + * \sa Q3DBars, Q3DScatter, Q3DSurface, {Qt Data Visualization C++ Classes} + */ + +/*! + * \internal + */ +QAbstract3DGraph::QAbstract3DGraph(QAbstract3DGraphPrivate *d, QWindow *parent) + : QWindow(parent), + d_ptr(d) +{ + d_ptr->m_context = new QOpenGLContext(this); + + setFlags(flags() | Qt::FramelessWindowHint); + setSurfaceType(QWindow::OpenGLSurface); + QSurfaceFormat surfaceFormat; + surfaceFormat.setDepthBufferSize(24); +#if !defined(QT_OPENGL_ES_2) + surfaceFormat.setSamples(8); + surfaceFormat.setRenderableType(QSurfaceFormat::OpenGL); +#else + surfaceFormat.setRenderableType(QSurfaceFormat::OpenGLES); +#endif + surfaceFormat.setSwapBehavior(QSurfaceFormat::DoubleBuffer); + setFormat(surfaceFormat); + + create(); + + d_ptr->m_context->setFormat(requestedFormat()); + d_ptr->m_context->create(); + d_ptr->m_context->makeCurrent(this); + + initializeOpenGLFunctions(); + + const GLubyte *version = glGetString(GL_VERSION); + qDebug() << "OpenGL version:" << (const char *)version; + version = glGetString(GL_SHADING_LANGUAGE_VERSION); + qDebug() << "GLSL version:" << (const char *)version; +#if !defined(QT_OPENGL_ES_2) + // If we have real OpenGL, GLSL version must be 1.2 or over. Quit if not. + QStringList splitversionstr = QString::fromLatin1((const char *)version).split(QChar::fromLatin1(' ')); + if (splitversionstr[0].toFloat() < 1.2) + qFatal("GLSL version must be 1.20 or higher. Try installing latest display drivers."); +#endif + + d_ptr->renderLater(); +} + +/*! + * Destroys QAbstract3DGraph. + */ +QAbstract3DGraph::~QAbstract3DGraph() +{ +} + +/*! + * Adds the given \a inputHandler to the graph. The input handlers added via addInputHandler + * are not taken in to use directly. Only the ownership of the a\ inputHandler is given to the graph. + * The \a inputHandler must not be null or already added to another graph. + * + * \sa releaseInputHandler(), setActiveInputHandler() + */ +void QAbstract3DGraph::addInputHandler(QAbstract3DInputHandler *inputHandler) +{ + d_ptr->m_visualController->addInputHandler(inputHandler); +} + +/*! + * Releases the ownership of the \a inputHandler back to the caller, if it was added to this graph. + * If the released \a inputHandler is in use there will be no input handler active after this call. + * + * If the default input handler is released and added back later, it behaves as any other input handler would. + * + * \sa addInputHandler(), setActiveInputHandler() + */ +void QAbstract3DGraph::releaseInputHandler(QAbstract3DInputHandler *inputHandler) +{ + d_ptr->m_visualController->releaseInputHandler(inputHandler); +} + +/*! + * \property QAbstract3DGraph::activeInputHandler + * + * The active \a inputHandler used in the graph. Implicitly calls addInputHandler() to transfer + * ownership of the \a inputHandler to this graph. + * + * If the \a inputHandler is null, no input handler will be active after this call. + * + * \sa addInputHandler(), releaseInputHandler() + */ +void QAbstract3DGraph::setActiveInputHandler(QAbstract3DInputHandler *inputHandler) +{ + d_ptr->m_visualController->setActiveInputHandler(inputHandler); +} + +QAbstract3DInputHandler *QAbstract3DGraph::activeInputHandler() +{ + return d_ptr->m_visualController->activeInputHandler(); +} + +/*! + * Adds the given \a theme to the graph. The themes added via addTheme are not taken in to use + * directly. Only the ownership of the a\ theme is given to the graph. + * The \a theme must not be null or already added to another graph. + * + * \sa releaseTheme(), setActiveTheme() + */ +void QAbstract3DGraph::addTheme(Q3DTheme *theme) +{ + d_ptr->m_visualController->addTheme(theme); +} + +/*! + * Releases the ownership of the \a theme back to the caller, if it was added to this graph. + * If the released \a theme is in use, a new default theme will be created and set active. + * + * If the default theme is released and added back later, it behaves as any other theme would. + * + * \sa addTheme(), setActiveTheme() + */ +void QAbstract3DGraph::releaseTheme(Q3DTheme *theme) +{ + d_ptr->m_visualController->releaseTheme(theme); +} + +/*! + * \property QAbstract3DGraph::activeTheme + * + * The active \a theme to be used for the graph. Implicitly calls addTheme() to transfer ownership + * of the \a theme to this graph. + * If the \a theme is null, a temporary default theme is created. This temporary theme is destroyed + * if any theme is explicitly set later. + * Properties of the \a theme can be modified even after setting it, and the modifications take + * effect immediately. + */ +void QAbstract3DGraph::setActiveTheme(Q3DTheme *theme) +{ + d_ptr->m_visualController->setActiveTheme(theme); +} + + +Q3DTheme *QAbstract3DGraph::activeTheme() const +{ + return d_ptr->m_visualController->activeTheme(); +} + +/*! + * \return list of all added themes. + * + * \sa addTheme() + */ +QList QAbstract3DGraph::themes() const +{ + return d_ptr->m_visualController->themes(); +} + +/*! + * \property QAbstract3DGraph::selectionMode + * + * Sets selection \a mode to a combination of \c QDataVis::SelectionFlags. It is preset to + * \c QDataVis::SelectionItem by default. + * Different graph types support different selection modes. See \c QDataVis::SelectionFlags + * documentation for details. + */ +void QAbstract3DGraph::setSelectionMode(QDataVis::SelectionFlags mode) +{ + d_ptr->m_visualController->setSelectionMode(mode); +} + +QDataVis::SelectionFlags QAbstract3DGraph::selectionMode() const +{ + return d_ptr->m_visualController->selectionMode(); +} + +/*! + * \property QAbstract3DGraph::shadowQuality + * + * Sets shadow \a quality to one of \c QDataVis::ShadowQuality. It is preset to + * \c QDataVis::ShadowQualityMedium by default. + * + * \note If setting QDataVis::ShadowQuality of a certain level fails, a level is lowered + * until it is successful and shadowQualityChanged signal is emitted for each time the change is + * done. + */ +void QAbstract3DGraph::setShadowQuality(QDataVis::ShadowQuality quality) +{ + d_ptr->m_visualController->setShadowQuality(quality); +} + +QDataVis::ShadowQuality QAbstract3DGraph::shadowQuality() const +{ + return d_ptr->m_visualController->shadowQuality(); +} + +/*! + * \property QAbstract3DGraph::scene + * + * This property contains the read only Q3DScene that can be used to access e.g. camera object. + */ +Q3DScene *QAbstract3DGraph::scene() const +{ + return d_ptr->m_visualController->scene(); +} + +/*! + * \internal + */ +bool QAbstract3DGraph::event(QEvent *event) +{ + switch (event->type()) { + case QEvent::UpdateRequest: + d_ptr->renderNow(); + return true; + case QEvent::TouchBegin: + case QEvent::TouchCancel: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: + d_ptr->m_visualController->touchEvent(static_cast(event)); + return true; + default: + return QWindow::event(event); + } +} + +/*! + * \internal + */ +void QAbstract3DGraph::resizeEvent(QResizeEvent *event) +{ + Q_UNUSED(event); + + Q3DScene *scene = d_ptr->m_visualController->scene(); + scene->d_ptr->setWindowSize(QSize(width(), height())); + scene->d_ptr->setViewport(QRect(0, 0, width(), height())); +} + +/*! + * \internal + */ +void QAbstract3DGraph::exposeEvent(QExposeEvent *event) +{ + Q_UNUSED(event); + + if (isExposed()) + d_ptr->renderNow(); +} + +/*! + * \internal + */ +void QAbstract3DGraph::mouseDoubleClickEvent(QMouseEvent *event) +{ + d_ptr->m_visualController->mouseDoubleClickEvent(event); +} + +/*! + * \internal + */ +void QAbstract3DGraph::touchEvent(QTouchEvent *event) +{ + d_ptr->m_visualController->touchEvent(event); +} + +/*! + * \internal + */ +void QAbstract3DGraph::mousePressEvent(QMouseEvent *event) +{ + d_ptr->m_visualController->mousePressEvent(event, event->pos()); +} + +/*! + * \internal + */ +void QAbstract3DGraph::mouseReleaseEvent(QMouseEvent *event) +{ + d_ptr->m_visualController->mouseReleaseEvent(event, event->pos()); +} + +/*! + * \internal + */ +void QAbstract3DGraph::mouseMoveEvent(QMouseEvent *event) +{ + d_ptr->m_visualController->mouseMoveEvent(event, event->pos()); +} + +/*! + * \internal + */ +void QAbstract3DGraph::wheelEvent(QWheelEvent *event) +{ + d_ptr->m_visualController->wheelEvent(event); +} + +QAbstract3DGraphPrivate::QAbstract3DGraphPrivate(QAbstract3DGraph *q) + : QObject(0), + q_ptr(q), + m_updatePending(false), + m_visualController(0), + m_devicePixelRatio(1.f) +{ +} + +QAbstract3DGraphPrivate::~QAbstract3DGraphPrivate() +{ + delete m_visualController; +} + +void QAbstract3DGraphPrivate::render() +{ + handleDevicePixelRatioChange(); + m_visualController->synchDataToRenderer(); + m_visualController->render(); +} + +void QAbstract3DGraphPrivate::renderLater() +{ + if (!m_updatePending) { + m_updatePending = true; + QCoreApplication::postEvent(q_ptr, new QEvent(QEvent::UpdateRequest)); + } +} + +void QAbstract3DGraphPrivate::renderNow() +{ + if (!q_ptr->isExposed()) + return; + + m_updatePending = false; + + m_context->makeCurrent(q_ptr); + + render(); + + m_context->swapBuffers(q_ptr); +} + +void QAbstract3DGraphPrivate::setVisualController(Abstract3DController *controller) +{ + m_visualController = controller; + + QObject::connect(m_visualController, &Abstract3DController::activeInputHandlerChanged, q_ptr, + &QAbstract3DGraph::activeInputHandlerChanged); + QObject::connect(m_visualController, &Abstract3DController::activeThemeChanged, q_ptr, + &QAbstract3DGraph::activeThemeChanged); + QObject::connect(m_visualController, &Abstract3DController::selectionModeChanged, q_ptr, + &QAbstract3DGraph::selectionModeChanged); + QObject::connect(m_visualController, &Abstract3DController::shadowQualityChanged, q_ptr, + &QAbstract3DGraph::shadowQualityChanged); + QObject::connect(m_visualController, &Abstract3DController::needRender, this, + &QAbstract3DGraphPrivate::renderLater); +} + +void QAbstract3DGraphPrivate::handleDevicePixelRatioChange() +{ + if (q_ptr->devicePixelRatio() == m_devicePixelRatio || !m_visualController) + return; + + m_devicePixelRatio = q_ptr->devicePixelRatio(); + m_visualController->scene()->setDevicePixelRatio(m_devicePixelRatio); +} + +QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualization/engine/qabstract3dgraph.h b/src/datavisualization/engine/qabstract3dgraph.h new file mode 100644 index 00000000..f2d7eb48 --- /dev/null +++ b/src/datavisualization/engine/qabstract3dgraph.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 QABSTRACT3DGRAPH_H +#define QABSTRACT3DGRAPH_H + +#include + +#include +#include +#include + +class QPainter; + +QT_DATAVISUALIZATION_BEGIN_NAMESPACE + +class QAbstract3DGraphPrivate; +class Abstract3DController; +class QAbstract3DInputHandler; +class Q3DTheme; +class Q3DScene; + +class QT_DATAVISUALIZATION_EXPORT QAbstract3DGraph : public QWindow, protected QOpenGLFunctions +{ + Q_OBJECT + Q_PROPERTY(QAbstract3DInputHandler* activeInputHandler READ activeInputHandler WRITE setActiveInputHandler NOTIFY activeInputHandlerChanged) + Q_PROPERTY(Q3DTheme* activeTheme READ activeTheme WRITE setActiveTheme NOTIFY activeThemeChanged) + Q_PROPERTY(QtDataVisualization::QDataVis::SelectionFlags selectionMode READ selectionMode WRITE setSelectionMode NOTIFY selectionModeChanged) + Q_PROPERTY(QtDataVisualization::QDataVis::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality NOTIFY shadowQualityChanged) + Q_PROPERTY(Q3DScene* scene READ scene) + +protected: + explicit QAbstract3DGraph(QAbstract3DGraphPrivate *d, QWindow *parent = 0); +public: + virtual ~QAbstract3DGraph(); + + void addInputHandler(QAbstract3DInputHandler *inputHandler); + void releaseInputHandler(QAbstract3DInputHandler *inputHandler); + void setActiveInputHandler(QAbstract3DInputHandler *inputHandler); + QAbstract3DInputHandler *activeInputHandler(); + + void addTheme(Q3DTheme *theme); + void releaseTheme(Q3DTheme *theme); + void setActiveTheme(Q3DTheme *theme); + Q3DTheme *activeTheme() const; + QList themes() const; + + void setSelectionMode(QDataVis::SelectionFlags mode); + QDataVis::SelectionFlags selectionMode() const; + + void setShadowQuality(QDataVis::ShadowQuality quality); + QDataVis::ShadowQuality shadowQuality() const; + + Q3DScene *scene() const; + +protected: + bool event(QEvent *event); + void resizeEvent(QResizeEvent *event); + void exposeEvent(QExposeEvent *event); + + void mouseDoubleClickEvent(QMouseEvent *event); + void touchEvent(QTouchEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void wheelEvent(QWheelEvent *event); + + +signals: + void activeInputHandlerChanged(QAbstract3DInputHandler *inputHandler); + void activeThemeChanged(Q3DTheme *theme); + void selectionModeChanged(QDataVis::SelectionFlags mode); + void shadowQualityChanged(QDataVis::ShadowQuality quality); + +private: + QScopedPointer d_ptr; + + friend class Q3DBars; + friend class Q3DScatter; + friend class Q3DSurface; +}; + +QT_DATAVISUALIZATION_END_NAMESPACE + +#endif diff --git a/src/datavisualization/engine/qabstract3dgraph_p.h b/src/datavisualization/engine/qabstract3dgraph_p.h new file mode 100644 index 00000000..18e88c92 --- /dev/null +++ b/src/datavisualization/engine/qabstract3dgraph_p.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the QtDataVisualization API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef QABSTRACT3DGRAPH_P_H +#define QABSTRACT3DGRAPH_P_H + +#include "datavisualizationglobal_p.h" + +#include + +class QOpenGLContext; +class QOpenGLPaintDevice; + +QT_DATAVISUALIZATION_BEGIN_NAMESPACE + +class QAbstract3DGraph; +class Abstract3DController; + +class QAbstract3DGraphPrivate : public QObject +{ + Q_OBJECT +public: + QAbstract3DGraphPrivate(QAbstract3DGraph *q); + ~QAbstract3DGraphPrivate(); + + void render(); + + void setVisualController(Abstract3DController *controller); + void handleDevicePixelRatioChange(); + +public slots: + void renderLater(); + void renderNow(); + +public: + QAbstract3DGraph *q_ptr; + + bool m_updatePending; + QOpenGLContext *m_context; + Abstract3DController *m_visualController; + float m_devicePixelRatio; +}; + +QT_DATAVISUALIZATION_END_NAMESPACE + +#endif -- cgit v1.2.3