summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJere Tuliniemi <jere.tuliniemi@qt.io>2017-05-09 11:30:47 +0300
committerJere Tuliniemi <jere.tuliniemi@qt.io>2017-05-15 10:36:40 +0000
commit757e26894b5b912bd03ce93b7e538e26f88c9b62 (patch)
tree523ecb86985bc350104f633c31481403464dca2d /src
parent1d03c298fa27e2747fd41a9b5378135d57656fd9 (diff)
Implement PIMPL for Qt3DWindow
Added private members of Qt3DWindow to Qt3DWindowPrivate to hide implementation. m_aspectEngine is a normal pointer now so that it can be deleted from Qt3DWindow destructor. Screen connection happens after QWindow constructor now because it lacks a constructor that takes a d_ptr and a screen pointer. Task-number: QTBUG-60426 Change-Id: I08e431ec0ea570e5f2c5fb103bcf0fe16e1b23bc Reviewed-by: Antti Määttä <antti.maatta@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/extras/defaults/defaults.pri1
-rw-r--r--src/extras/defaults/qt3dwindow.cpp80
-rw-r--r--src/extras/defaults/qt3dwindow.h25
-rw-r--r--src/extras/defaults/qt3dwindow_p.h92
4 files changed, 147 insertions, 51 deletions
diff --git a/src/extras/defaults/defaults.pri b/src/extras/defaults/defaults.pri
index ec8c9a7b5..8a18fb6e9 100644
--- a/src/extras/defaults/defaults.pri
+++ b/src/extras/defaults/defaults.pri
@@ -24,6 +24,7 @@ HEADERS += \
$$PWD/qphongalphamaterial.h \
$$PWD/qphongalphamaterial_p.h \
$$PWD/qt3dwindow.h \
+ $$PWD/qt3dwindow_p.h \
$$PWD/qfirstpersoncameracontroller.h \
$$PWD/qfirstpersoncameracontroller_p.h \
$$PWD/qorbitcameracontroller.h \
diff --git a/src/extras/defaults/qt3dwindow.cpp b/src/extras/defaults/qt3dwindow.cpp
index a0ce40e16..635d81956 100644
--- a/src/extras/defaults/qt3dwindow.cpp
+++ b/src/extras/defaults/qt3dwindow.cpp
@@ -49,6 +49,7 @@
****************************************************************************/
#include "qt3dwindow.h"
+#include "qt3dwindow_p.h"
#include <Qt3DCore/qaspectengine.h>
#include <Qt3DCore/qentity.h>
@@ -65,9 +66,8 @@ QT_BEGIN_NAMESPACE
namespace Qt3DExtras {
-Qt3DWindow::Qt3DWindow(QScreen *screen)
- : QWindow(screen)
- , m_aspectEngine(new Qt3DCore::QAspectEngine)
+Qt3DWindowPrivate::Qt3DWindowPrivate()
+ : m_aspectEngine(new Qt3DCore::QAspectEngine)
, m_renderAspect(new Qt3DRender::QRenderAspect)
, m_inputAspect(new Qt3DInput::QInputAspect)
, m_logicAspect(new Qt3DLogic::QLogicAspect)
@@ -79,6 +79,16 @@ Qt3DWindow::Qt3DWindow(QScreen *screen)
, m_userRoot(nullptr)
, m_initialized(false)
{
+}
+
+Qt3DWindow::Qt3DWindow(QScreen *screen)
+ : QWindow(*new Qt3DWindowPrivate(), nullptr)
+{
+ Q_D(Qt3DWindow);
+
+ if (!d->parentWindow)
+ d->connectToScreen(screen ? screen : d->topLevelScreen.data());
+
setSurfaceType(QSurface::OpenGLSurface);
resize(1024, 768);
@@ -98,77 +108,88 @@ Qt3DWindow::Qt3DWindow(QScreen *screen)
setFormat(format);
QSurfaceFormat::setDefaultFormat(format);
- m_aspectEngine->registerAspect(m_renderAspect);
- m_aspectEngine->registerAspect(m_inputAspect);
- m_aspectEngine->registerAspect(m_logicAspect);
+ d->m_aspectEngine->registerAspect(d->m_renderAspect);
+ d->m_aspectEngine->registerAspect(d->m_inputAspect);
+ d->m_aspectEngine->registerAspect(d->m_logicAspect);
- m_defaultCamera->setParent(m_root);
- m_forwardRenderer->setCamera(m_defaultCamera);
- m_forwardRenderer->setSurface(this);
- m_renderSettings->setActiveFrameGraph(m_forwardRenderer);
- m_inputSettings->setEventSource(this);
+ d->m_defaultCamera->setParent(d->m_root);
+ d->m_forwardRenderer->setCamera(d->m_defaultCamera);
+ d->m_forwardRenderer->setSurface(this);
+ d->m_renderSettings->setActiveFrameGraph(d->m_forwardRenderer);
+ d->m_inputSettings->setEventSource(this);
}
Qt3DWindow::~Qt3DWindow()
{
+ Q_D(Qt3DWindow);
+ delete d->m_aspectEngine;
}
void Qt3DWindow::registerAspect(Qt3DCore::QAbstractAspect *aspect)
{
Q_ASSERT(!isVisible());
- m_aspectEngine->registerAspect(aspect);
+ Q_D(Qt3DWindow);
+ d->m_aspectEngine->registerAspect(aspect);
}
void Qt3DWindow::registerAspect(const QString &name)
{
Q_ASSERT(!isVisible());
- m_aspectEngine->registerAspect(name);
+ Q_D(Qt3DWindow);
+ d->m_aspectEngine->registerAspect(name);
}
void Qt3DWindow::setRootEntity(Qt3DCore::QEntity *root)
{
- if (m_userRoot != root) {
- if (m_userRoot != nullptr)
- m_userRoot->setParent(static_cast<Qt3DCore::QNode*>(nullptr));
+ Q_D(Qt3DWindow);
+ if (d->m_userRoot != root) {
+ if (d->m_userRoot != nullptr)
+ d->m_userRoot->setParent(static_cast<Qt3DCore::QNode*>(nullptr));
if (root != nullptr)
- root->setParent(m_root);
- m_userRoot = root;
+ root->setParent(d->m_root);
+ d->m_userRoot = root;
}
}
void Qt3DWindow::setActiveFrameGraph(Qt3DRender::QFrameGraphNode *activeFrameGraph)
{
- m_renderSettings->setActiveFrameGraph(activeFrameGraph);
+ Q_D(Qt3DWindow);
+ d->m_renderSettings->setActiveFrameGraph(activeFrameGraph);
}
Qt3DRender::QFrameGraphNode *Qt3DWindow::activeFrameGraph() const
{
- return m_renderSettings->activeFrameGraph();
+ Q_D(const Qt3DWindow);
+ return d->m_renderSettings->activeFrameGraph();
}
Qt3DExtras::QForwardRenderer *Qt3DWindow::defaultFrameGraph() const
{
- return m_forwardRenderer;
+ Q_D(const Qt3DWindow);
+ return d->m_forwardRenderer;
}
Qt3DRender::QCamera *Qt3DWindow::camera() const
{
- return m_defaultCamera;
+ Q_D(const Qt3DWindow);
+ return d->m_defaultCamera;
}
Qt3DRender::QRenderSettings *Qt3DWindow::renderSettings() const
{
- return m_renderSettings;
+ Q_D(const Qt3DWindow);
+ return d->m_renderSettings;
}
void Qt3DWindow::showEvent(QShowEvent *e)
{
- if (!m_initialized) {
- m_root->addComponent(m_renderSettings);
- m_root->addComponent(m_inputSettings);
- m_aspectEngine->setRootEntity(Qt3DCore::QEntityPtr(m_root));
+ Q_D(Qt3DWindow);
+ if (!d->m_initialized) {
+ d->m_root->addComponent(d->m_renderSettings);
+ d->m_root->addComponent(d->m_inputSettings);
+ d->m_aspectEngine->setRootEntity(Qt3DCore::QEntityPtr(d->m_root));
- m_initialized = true;
+ d->m_initialized = true;
}
QWindow::showEvent(e);
@@ -176,7 +197,8 @@ void Qt3DWindow::showEvent(QShowEvent *e)
void Qt3DWindow::resizeEvent(QResizeEvent *)
{
- m_defaultCamera->setAspectRatio(float(width()) / float(height()));
+ Q_D(Qt3DWindow);
+ d->m_defaultCamera->setAspectRatio(float(width()) / float(height()));
}
} // Qt3DExtras
diff --git a/src/extras/defaults/qt3dwindow.h b/src/extras/defaults/qt3dwindow.h
index 811bb134d..6ec1bbf8b 100644
--- a/src/extras/defaults/qt3dwindow.h
+++ b/src/extras/defaults/qt3dwindow.h
@@ -84,6 +84,8 @@ class QLogicAspect;
namespace Qt3DExtras {
+class Qt3DWindowPrivate;
+
class QT3DEXTRASSHARED_EXPORT Qt3DWindow : public QWindow
{
Q_OBJECT
@@ -112,28 +114,7 @@ protected:
void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
private:
- QScopedPointer<Qt3DCore::QAspectEngine> m_aspectEngine;
-
- // Aspects
- Qt3DRender::QRenderAspect *m_renderAspect;
- Qt3DInput::QInputAspect *m_inputAspect;
- Qt3DLogic::QLogicAspect *m_logicAspect;
-
- // Renderer configuration
- Qt3DRender::QRenderSettings *m_renderSettings;
- Qt3DExtras::QForwardRenderer *m_forwardRenderer;
- Qt3DRender::QCamera *m_defaultCamera;
-
- // Input configuration
- Qt3DInput::QInputSettings *m_inputSettings;
-
- // Logic configuration
-
- // Scene
- Qt3DCore::QEntity *m_root;
- Qt3DCore::QEntity *m_userRoot;
-
- bool m_initialized;
+ Q_DECLARE_PRIVATE(Qt3DWindow)
};
} // Qt3DExtras
diff --git a/src/extras/defaults/qt3dwindow_p.h b/src/extras/defaults/qt3dwindow_p.h
new file mode 100644
index 000000000..731d5298e
--- /dev/null
+++ b/src/extras/defaults/qt3dwindow_p.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DWINDOW_P_H
+#define QT3DWINDOW_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtGui/private/qwindow_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DExtras {
+
+class Qt3DWindowPrivate : public QWindowPrivate
+{
+public:
+ Qt3DWindowPrivate();
+
+ Qt3DCore::QAspectEngine *m_aspectEngine;
+
+ // Aspects
+ Qt3DRender::QRenderAspect *m_renderAspect;
+ Qt3DInput::QInputAspect *m_inputAspect;
+ Qt3DLogic::QLogicAspect *m_logicAspect;
+
+ // Renderer configuration
+ Qt3DRender::QRenderSettings *m_renderSettings;
+ Qt3DExtras::QForwardRenderer *m_forwardRenderer;
+ Qt3DRender::QCamera *m_defaultCamera;
+
+ // Input configuration
+ Qt3DInput::QInputSettings *m_inputSettings;
+
+ // Logic configuration
+
+ // Scene
+ Qt3DCore::QEntity *m_root;
+ Qt3DCore::QEntity *m_userRoot;
+
+ bool m_initialized;
+
+ Q_DECLARE_PUBLIC(Qt3DWindow)
+};
+
+} // Qt3DExtras
+
+QT_END_NAMESPACE
+
+#endif // QT3DWINDOW_P_H