summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJere Tuliniemi <jere.tuliniemi@qt.io>2017-05-09 12:34:37 +0300
committerJere Tuliniemi <jere.tuliniemi@qt.io>2017-05-15 05:54:59 +0000
commit1d03c298fa27e2747fd41a9b5378135d57656fd9 (patch)
tree14489ac76fe17706038b17590581c5a00c54f16f /src
parent8dfcdb186dd15f2948c02054bdef94f7aafeb412 (diff)
Implement PIMPL for Qt3DQuickWindow
Moved private members of Qt3DQuickWindow to Qt3DQuickWindowPrivate to hide implementation. m_engine is now a normal pointer so that it can be deleted in the Qt3DQuickWindow destructor. Task-number: QTBUG-60426 Change-Id: I99dd1b89aa2036272add7ba276e9b8f0c867e4a1 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/quick3d/quick3dextras/qt3dquickwindow.cpp80
-rw-r--r--src/quick3d/quick3dextras/qt3dquickwindow.h14
-rw-r--r--src/quick3d/quick3dextras/qt3dquickwindow_p.h86
-rw-r--r--src/quick3d/quick3dextras/quick3dextras.pro1
4 files changed, 138 insertions, 43 deletions
diff --git a/src/quick3d/quick3dextras/qt3dquickwindow.cpp b/src/quick3d/quick3dextras/qt3dquickwindow.cpp
index 7f32f03f0..91773bb66 100644
--- a/src/quick3d/quick3dextras/qt3dquickwindow.cpp
+++ b/src/quick3d/quick3dextras/qt3dquickwindow.cpp
@@ -49,6 +49,7 @@
****************************************************************************/
#include <Qt3DQuickExtras/qt3dquickwindow.h>
+#include "qt3dquickwindow_p.h"
#include <Qt3DQuick/QQmlAspectEngine>
#include <Qt3DQuickExtras/qt3dquickwindow.h>
#include <Qt3DInput/qinputaspect.h>
@@ -96,16 +97,21 @@ private:
} // anonymous
-Qt3DQuickWindow::Qt3DQuickWindow(QWindow *parent)
- : QWindow(parent)
- , m_engine(nullptr)
+Qt3DQuickWindowPrivate::Qt3DQuickWindowPrivate()
+ : m_engine(nullptr)
, m_renderAspect(nullptr)
, m_inputAspect(nullptr)
, m_logicAspect(nullptr)
, m_initialized(false)
- , m_cameraAspectRatioMode(AutomaticAspectRatio)
+ , m_cameraAspectRatioMode(Qt3DQuickWindow::AutomaticAspectRatio)
, m_incubationController(nullptr)
{
+}
+
+Qt3DQuickWindow::Qt3DQuickWindow(QWindow *parent)
+ : QWindow(*new Qt3DQuickWindowPrivate(), parent)
+{
+ Q_D(Qt3DQuickWindow);
setSurfaceType(QSurface::OpenGLSurface);
resize(1024, 768);
@@ -125,78 +131,87 @@ Qt3DQuickWindow::Qt3DQuickWindow(QWindow *parent)
setFormat(format);
QSurfaceFormat::setDefaultFormat(format);
- m_engine.reset(new Qt3DCore::Quick::QQmlAspectEngine);
- m_renderAspect = new Qt3DRender::QRenderAspect;
- m_inputAspect = new Qt3DInput::QInputAspect;
- m_logicAspect = new Qt3DLogic::QLogicAspect;
+ d->m_engine = new Qt3DCore::Quick::QQmlAspectEngine;
+ d->m_renderAspect = new Qt3DRender::QRenderAspect;
+ d->m_inputAspect = new Qt3DInput::QInputAspect;
+ d->m_logicAspect = new Qt3DLogic::QLogicAspect;
- m_engine->aspectEngine()->registerAspect(m_renderAspect);
- m_engine->aspectEngine()->registerAspect(m_inputAspect);
- m_engine->aspectEngine()->registerAspect(m_logicAspect);
+ d->m_engine->aspectEngine()->registerAspect(d->m_renderAspect);
+ d->m_engine->aspectEngine()->registerAspect(d->m_inputAspect);
+ d->m_engine->aspectEngine()->registerAspect(d->m_logicAspect);
}
Qt3DQuickWindow::~Qt3DQuickWindow()
{
+ Q_D(Qt3DQuickWindow);
+ delete d->m_engine;
}
void Qt3DQuickWindow::registerAspect(Qt3DCore::QAbstractAspect *aspect)
{
Q_ASSERT(!isVisible());
- m_engine->aspectEngine()->registerAspect(aspect);
+ Q_D(Qt3DQuickWindow);
+ d->m_engine->aspectEngine()->registerAspect(aspect);
}
void Qt3DQuickWindow::registerAspect(const QString &name)
{
Q_ASSERT(!isVisible());
- m_engine->aspectEngine()->registerAspect(name);
+ Q_D(Qt3DQuickWindow);
+ d->m_engine->aspectEngine()->registerAspect(name);
}
void Qt3DQuickWindow::setSource(const QUrl &source)
{
- m_source = source;
+ Q_D(Qt3DQuickWindow);
+ d->m_source = source;
}
Qt3DCore::Quick::QQmlAspectEngine *Qt3DQuickWindow::engine() const
{
- return m_engine.data();
+ Q_D(const Qt3DQuickWindow);
+ return d->m_engine;
}
void Qt3DQuickWindow::setCameraAspectRatioMode(CameraAspectRatioMode mode)
{
- if (m_cameraAspectRatioMode == mode)
+ Q_D(Qt3DQuickWindow);
+ if (d->m_cameraAspectRatioMode == mode)
return;
- m_cameraAspectRatioMode = mode;
+ d->m_cameraAspectRatioMode = mode;
setCameraAspectModeHelper();
emit cameraAspectRatioModeChanged(mode);
}
Qt3DQuickWindow::CameraAspectRatioMode Qt3DQuickWindow::cameraAspectRatioMode() const
{
- return m_cameraAspectRatioMode;
+ Q_D(const Qt3DQuickWindow);
+ return d->m_cameraAspectRatioMode;
}
void Qt3DQuickWindow::showEvent(QShowEvent *e)
{
- if (!m_initialized) {
+ Q_D(Qt3DQuickWindow);
+ if (!d->m_initialized) {
// Connect to the QQmlAspectEngine's statusChanged signal so that when the QML is loaded
// and th eobjects hav ebeen instantiated, but before we set them on the QAspectEngine we
// can swoop in and set the window surface and camera on the framegraph and ensure the camera
// respects the window's aspect ratio
- connect(m_engine.data(), &Qt3DCore::Quick::QQmlAspectEngine::sceneCreated,
+ connect(d->m_engine, &Qt3DCore::Quick::QQmlAspectEngine::sceneCreated,
this, &Qt3DQuickWindow::onSceneCreated);
- m_engine->setSource(m_source);
+ d->m_engine->setSource(d->m_source);
// Set the QQmlIncubationController on the window
// to benefit from asynchronous incubation
- if (!m_incubationController)
- m_incubationController = new Qt3DQuickWindowIncubationController(this);
+ if (!d->m_incubationController)
+ d->m_incubationController = new Qt3DQuickWindowIncubationController(this);
- m_engine->qmlEngine()->setIncubationController(m_incubationController);
+ d->m_engine->qmlEngine()->setIncubationController(d->m_incubationController);
- m_initialized = true;
+ d->m_initialized = true;
}
QWindow::showEvent(e);
}
@@ -204,17 +219,18 @@ void Qt3DQuickWindow::showEvent(QShowEvent *e)
void Qt3DQuickWindow::onSceneCreated(QObject *rootObject)
{
Q_ASSERT(rootObject);
+ Q_D(Qt3DQuickWindow);
setWindowSurface(rootObject);
- if (m_cameraAspectRatioMode == AutomaticAspectRatio) {
+ if (d->m_cameraAspectRatioMode == AutomaticAspectRatio) {
// Set aspect ratio of first camera to match the window
QList<Qt3DRender::QCamera *> cameras
= rootObject->findChildren<Qt3DRender::QCamera *>();
if (cameras.isEmpty()) {
qCDebug(QuickWindow) << "No camera found";
} else {
- m_camera = cameras.first();
+ d->m_camera = cameras.first();
setCameraAspectModeHelper();
}
}
@@ -237,7 +253,8 @@ void Qt3DQuickWindow::setWindowSurface(QObject *rootObject)
void Qt3DQuickWindow::setCameraAspectModeHelper()
{
- switch (m_cameraAspectRatioMode) {
+ Q_D(Qt3DQuickWindow);
+ switch (d->m_cameraAspectRatioMode) {
case AutomaticAspectRatio:
connect(this, &QWindow::widthChanged, this, &Qt3DQuickWindow::updateCameraAspectRatio);
connect(this, &QWindow::heightChanged, this, &Qt3DQuickWindow::updateCameraAspectRatio);
@@ -253,9 +270,10 @@ void Qt3DQuickWindow::setCameraAspectModeHelper()
void Qt3DQuickWindow::updateCameraAspectRatio()
{
- if (m_camera) {
- m_camera->setAspectRatio(static_cast<float>(width()) /
- static_cast<float>(height()));
+ Q_D(Qt3DQuickWindow);
+ if (d->m_camera) {
+ d->m_camera->setAspectRatio(static_cast<float>(width()) /
+ static_cast<float>(height()));
}
}
diff --git a/src/quick3d/quick3dextras/qt3dquickwindow.h b/src/quick3d/quick3dextras/qt3dquickwindow.h
index 1b4d3fabf..0880fc160 100644
--- a/src/quick3d/quick3dextras/qt3dquickwindow.h
+++ b/src/quick3d/quick3dextras/qt3dquickwindow.h
@@ -84,6 +84,7 @@ namespace Qt3DExtras {
namespace Quick {
+class Qt3DQuickWindowPrivate;
class QT3DQUICKEXTRASSHARED_EXPORT Qt3DQuickWindow : public QWindow
{
@@ -121,18 +122,7 @@ private:
void setCameraAspectModeHelper();
void updateCameraAspectRatio();
- QScopedPointer<Qt3DCore::Quick::QQmlAspectEngine> m_engine;
-
- // Aspects
- Qt3DRender::QRenderAspect *m_renderAspect;
- Qt3DInput::QInputAspect *m_inputAspect;
- Qt3DLogic::QLogicAspect *m_logicAspect;
-
- QUrl m_source;
- bool m_initialized;
- QPointer<Qt3DRender::QCamera> m_camera;
- CameraAspectRatioMode m_cameraAspectRatioMode;
- QQmlIncubationController *m_incubationController;
+ Q_DECLARE_PRIVATE(Qt3DQuickWindow)
};
} // Quick
diff --git a/src/quick3d/quick3dextras/qt3dquickwindow_p.h b/src/quick3d/quick3dextras/qt3dquickwindow_p.h
new file mode 100644
index 000000000..f2f8d0492
--- /dev/null
+++ b/src/quick3d/quick3dextras/qt3dquickwindow_p.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** 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 QT3DQUICKWINDOW_P_H
+#define QT3DQUICKWINDOW_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 {
+
+namespace Quick {
+
+class Qt3DQuickWindowPrivate : public QWindowPrivate
+{
+public:
+ Qt3DQuickWindowPrivate();
+
+ Qt3DCore::Quick::QQmlAspectEngine *m_engine;
+
+ // Aspects
+ Qt3DRender::QRenderAspect *m_renderAspect;
+ Qt3DInput::QInputAspect *m_inputAspect;
+ Qt3DLogic::QLogicAspect *m_logicAspect;
+
+ QUrl m_source;
+ bool m_initialized;
+ QPointer<Qt3DRender::QCamera> m_camera;
+ Qt3DQuickWindow::CameraAspectRatioMode m_cameraAspectRatioMode;
+ QQmlIncubationController *m_incubationController;
+
+ Q_DECLARE_PUBLIC(Qt3DQuickWindow)
+};
+
+} // Quick
+
+} // Qt3DExtras
+
+QT_END_NAMESPACE
+
+#endif // QT3DQUICKWINDOW_P_H
diff --git a/src/quick3d/quick3dextras/quick3dextras.pro b/src/quick3d/quick3dextras/quick3dextras.pro
index 9044c1668..976430eba 100644
--- a/src/quick3d/quick3dextras/quick3dextras.pro
+++ b/src/quick3d/quick3dextras/quick3dextras.pro
@@ -21,6 +21,7 @@ HEADERS += \
qt3dquickextras_global.h \
qt3dquickextras_global_p.h \
qt3dquickwindow.h \
+ qt3dquickwindow_p.h \
qt3dquickwindowlogging_p.h
# otherwise mingw headers do not declare common functions like ::strcasecmp