From 0144b397eff1340497ac2e599f7d9238bf99609c Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Wed, 8 Jan 2014 11:32:33 +0200 Subject: Enable showing multiple graphs in QML MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + other minor fixes Task-number: QTRD-2749 Change-Id: I654d41fd4124d6596f9df3ace7019706452d8bfa Reviewed-by: Pasi Keränen --- src/datavisualizationqml2/abstractdeclarative.cpp | 38 +++++++++++++++++------ src/datavisualizationqml2/abstractdeclarative_p.h | 21 ++++++++----- 2 files changed, 42 insertions(+), 17 deletions(-) (limited to 'src/datavisualizationqml2') diff --git a/src/datavisualizationqml2/abstractdeclarative.cpp b/src/datavisualizationqml2/abstractdeclarative.cpp index 5cac1882..65f27da0 100644 --- a/src/datavisualizationqml2/abstractdeclarative.cpp +++ b/src/datavisualizationqml2/abstractdeclarative.cpp @@ -24,9 +24,12 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE +static QList clearList; + AbstractDeclarative::AbstractDeclarative(QQuickItem *parent) : QQuickItem(parent), - m_controller(0) + m_controller(0), + m_clearWindowBeforeRendering(true) { connect(this, &QQuickItem::windowChanged, this, &AbstractDeclarative::handleWindowChanged); setAntialiasing(true); @@ -51,6 +54,19 @@ Q3DTheme *AbstractDeclarative::theme() const return m_controller->activeTheme(); } +void AbstractDeclarative::setClearWindowBeforeRendering(bool enable) +{ + if (m_clearWindowBeforeRendering != enable) { + m_clearWindowBeforeRendering = enable; + emit clearWindowBeforeRenderingChanged(enable); + } +} + +bool AbstractDeclarative::clearWindowBeforeRendering() const +{ + return m_clearWindowBeforeRendering; +} + void AbstractDeclarative::setSelectionMode(QDataVis::SelectionFlags mode) { m_controller->setSelectionMode(mode); @@ -87,6 +103,8 @@ void AbstractDeclarative::setSharedController(Abstract3DController *controller) void AbstractDeclarative::synchDataToRenderer() { + if (m_clearWindowBeforeRendering && clearList.size()) + clearList.clear(); m_controller->initializeOpenGL(); m_controller->synchDataToRenderer(); } @@ -140,10 +158,9 @@ void AbstractDeclarative::updateWindowParameters() win->update(); } - QPointF point = QQuickItem::mapToScene(QPointF(m_cachedGeometry.x(), m_cachedGeometry.y())); - if (m_controller) { + QPointF point = QQuickItem::mapToScene(QPointF(0.0f, 0.0f)); + if (m_controller) scene->d_ptr->setViewport(QRect(point.x(), point.y(), m_cachedGeometry.width(), m_cachedGeometry.height())); - } } } @@ -151,11 +168,14 @@ void AbstractDeclarative::render() { updateWindowParameters(); - // Clear the background as that is not done by default - glViewport(0, 0, window()->width(), window()->height()); - QColor clearColor = window()->color(); - glClearColor(clearColor.redF(), clearColor.greenF(), clearColor.blueF(), 1.0f); - glClear(GL_COLOR_BUFFER_BIT); + // Clear the background once per window as that is not done by default + const QQuickWindow *win = window(); + if (m_clearWindowBeforeRendering && !clearList.contains(win)) { + clearList.append(win); + QColor clearColor = win->color(); + glClearColor(clearColor.redF(), clearColor.greenF(), clearColor.blueF(), 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + } // TODO: Store the state of these and restore before returning glDepthMask(GL_TRUE); diff --git a/src/datavisualizationqml2/abstractdeclarative_p.h b/src/datavisualizationqml2/abstractdeclarative_p.h index 42cf13a4..5da22df3 100644 --- a/src/datavisualizationqml2/abstractdeclarative_p.h +++ b/src/datavisualizationqml2/abstractdeclarative_p.h @@ -48,11 +48,18 @@ class AbstractDeclarative : public QQuickItem Q_PROPERTY(Q3DScene* scene READ scene NOTIFY sceneChanged) Q_PROPERTY(QAbstract3DInputHandler* inputHandler READ inputHandler WRITE setInputHandler NOTIFY inputHandlerChanged) Q_PROPERTY(Q3DTheme* theme READ theme WRITE setTheme NOTIFY themeChanged) + Q_PROPERTY(bool clearWindowBeforeRendering READ clearWindowBeforeRendering WRITE setClearWindowBeforeRendering NOTIFY clearWindowBeforeRenderingChanged) public: explicit AbstractDeclarative(QQuickItem *parent = 0); virtual ~AbstractDeclarative(); + virtual void setSelectionMode(QDataVis::SelectionFlags mode); + virtual QDataVis::SelectionFlags selectionMode() const; + + virtual void setShadowQuality(QDataVis::ShadowQuality quality); + virtual QDataVis::ShadowQuality shadowQuality() const; + virtual Q3DScene *scene() const; virtual QAbstract3DInputHandler *inputHandler() const; @@ -61,14 +68,11 @@ public: virtual void setTheme(Q3DTheme *theme); virtual Q3DTheme *theme() const; - virtual void setSelectionMode(QDataVis::SelectionFlags mode); - virtual QDataVis::SelectionFlags selectionMode() const; + virtual void setClearWindowBeforeRendering(bool enable); + virtual bool clearWindowBeforeRendering() const; virtual void geometryChanged(const QRectF & newGeometry, const QRectF & oldGeometry); - virtual void setShadowQuality(QDataVis::ShadowQuality quality); - virtual QDataVis::ShadowQuality shadowQuality() const; - void setSharedController(Abstract3DController *controller); // Used to synch up data model from controller to renderer while main thread is locked void synchDataToRenderer(); @@ -87,16 +91,17 @@ protected: signals: // Signals shadow quality changes. + void selectionModeChanged(QDataVis::SelectionFlags mode); void shadowQualityChanged(QDataVis::ShadowQuality quality); + void sceneChanged(Q3DScene *scene); void inputHandlerChanged(QAbstract3DInputHandler *inputHandler); void themeChanged(Q3DTheme *theme); - void selectionModeChanged(QDataVis::SelectionFlags mode); - void itemLabelFormatChanged(QString format); - void sceneChanged(Q3DScene *scene); + void clearWindowBeforeRenderingChanged(bool enable); private: Abstract3DController *m_controller; QRectF m_cachedGeometry; + bool m_clearWindowBeforeRendering; }; QT_DATAVISUALIZATION_END_NAMESPACE -- cgit v1.2.3