summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2014-05-05 09:37:21 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-24 11:10:47 +0200
commit04c4055ad9eef2247d2abfae126c2bc8b90bf847 (patch)
tree96866d9084e75a758fb9567ebbe00677ba2d268f
parent727d7f83735f5128058d661a1633a2b435fcf4b5 (diff)
Quick3D independent library
In order to be able to have Qt3D work without dependencies to the Qml module, a dedicated Quick3D library has been set up for that purpose. It offers a QQuickWindow class which extends Qt3D::Window and allows to load a Qml source file. Examples have been updated to use QuickWindow. Note: There are still dependencies to the Qml module in Qt3DCore and Qt3DRenderer. This patch is a first step toward the removal of those. Follow up commits will completely remove those dependencies. Change-Id: I603eec8fb01b3706f648550b43b62356b0b4b4ac Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--examples/assimp/assimp.pro2
-rw-r--r--examples/assimp/main.cpp4
-rw-r--r--examples/gltf/gltf.pro2
-rw-r--r--examples/gltf/main.cpp4
-rw-r--r--examples/simple-qml/main.cpp4
-rw-r--r--examples/simple-qml/simple-qml.pro2
-rw-r--r--src/core/aspects/qaspectengine.h2
-rw-r--r--src/core/window.cpp76
-rw-r--r--src/core/window.h17
-rw-r--r--src/quick3d/qt3dquick_global.h57
-rw-r--r--src/quick3d/quick3d.pro30
-rw-r--r--src/quick3d/quickwindow.cpp139
-rw-r--r--src/quick3d/quickwindow.h89
-rw-r--r--src/src.pro3
-rw-r--r--sync.profile1
15 files changed, 330 insertions, 102 deletions
diff --git a/examples/assimp/assimp.pro b/examples/assimp/assimp.pro
index 3c56b754f..e2871ca80 100644
--- a/examples/assimp/assimp.pro
+++ b/examples/assimp/assimp.pro
@@ -2,7 +2,7 @@ TEMPLATE = app
SOURCE += main.cpp
-QT += qml quick 3dcore 3drenderer
+QT += qml quick 3dcore 3drenderer 3dquick
OTHER_FILES += main.qml
diff --git a/examples/assimp/main.cpp b/examples/assimp/main.cpp
index 3e7412ffd..3211f0b8b 100644
--- a/examples/assimp/main.cpp
+++ b/examples/assimp/main.cpp
@@ -41,7 +41,7 @@
#include <exampleresources.h>
-#include <window.h>
+#include <quickwindow.h>
#include <rendereraspect.h>
#include <QGuiApplication>
@@ -53,7 +53,7 @@ int main(int argc, char* argv[])
initializeAssetResources("../exampleresources/example-assets.qrb");
- Qt3D::Window view;
+ Qt3D::Quick::QuickWindow view;
view.registerAspect(new Qt3D::RendererAspect());
view.setSource(QUrl("qrc:/main.qml"));
view.show();
diff --git a/examples/gltf/gltf.pro b/examples/gltf/gltf.pro
index a439d6a12..5a1dde26d 100644
--- a/examples/gltf/gltf.pro
+++ b/examples/gltf/gltf.pro
@@ -1,6 +1,6 @@
TEMPLATE = app
-QT += 3dcore 3drenderer qml quick
+QT += 3dcore 3drenderer 3dquick qml quick
include("../exampleresources/exampleresources.pri")
diff --git a/examples/gltf/main.cpp b/examples/gltf/main.cpp
index 020401d9f..7fc2a5ecf 100644
--- a/examples/gltf/main.cpp
+++ b/examples/gltf/main.cpp
@@ -40,7 +40,7 @@
****************************************************************************/
#include <exampleresources.h>
-#include <window.h>
+#include <quickwindow.h>
#include <rendereraspect.h>
#include <QGuiApplication>
@@ -52,7 +52,7 @@ int main(int argc, char* argv[])
initializeAssetResources("../exampleresources/example-assets.qrb");
- Qt3D::Window view;
+ Qt3D::Quick::QuickWindow view;
view.registerAspect(new Qt3D::RendererAspect());
view.setSource(QUrl("qrc:/main.qml"));
view.show();
diff --git a/examples/simple-qml/main.cpp b/examples/simple-qml/main.cpp
index bb2ac5898..ad8802ce6 100644
--- a/examples/simple-qml/main.cpp
+++ b/examples/simple-qml/main.cpp
@@ -39,7 +39,7 @@
**
****************************************************************************/
-#include <window.h>
+#include <quickwindow.h>
#include <rendereraspect.h>
@@ -50,7 +50,7 @@ int main(int argc, char* argv[])
{
QGuiApplication app(argc, argv);
- Qt3D::Window view;
+ Qt3D::Quick::QuickWindow view;
view.registerAspect(new Qt3D::RendererAspect());
// There should be some synchronising mechanism to make sure
// the source is set after alll aspects have been completely initialized
diff --git a/examples/simple-qml/simple-qml.pro b/examples/simple-qml/simple-qml.pro
index b534097a5..8df6820f3 100644
--- a/examples/simple-qml/simple-qml.pro
+++ b/examples/simple-qml/simple-qml.pro
@@ -1,6 +1,6 @@
TEMPLATE = app
-QT += 3dcore 3drenderer qml quick
+QT += 3dcore 3drenderer 3dquick qml quick
include("../exampleresources/exampleresources.pri")
diff --git a/src/core/aspects/qaspectengine.h b/src/core/aspects/qaspectengine.h
index 92ecfdf5c..3c6e4316e 100644
--- a/src/core/aspects/qaspectengine.h
+++ b/src/core/aspects/qaspectengine.h
@@ -57,7 +57,7 @@ namespace Qt3D {
class AbstractAspect;
class QAspectThread;
-class QAspectEngine : public QObject
+class QT3DCORESHARED_EXPORT QAspectEngine : public QObject
{
Q_OBJECT
public:
diff --git a/src/core/window.cpp b/src/core/window.cpp
index c4561350b..d014c80fc 100644
--- a/src/core/window.cpp
+++ b/src/core/window.cpp
@@ -42,7 +42,6 @@
#include "window.h"
#include <QDebug>
-#include <QQmlComponent>
#include <QTimer>
#include <QKeyEvent>
#include <QMouseEvent>
@@ -51,8 +50,7 @@
#include "node.h"
#include "camera.h"
#include "entity.h"
-#include <qaspectengine.h>
-
+#include "qaspectengine.h"
#include "cameracontroller.h"
QT_BEGIN_NAMESPACE
@@ -61,7 +59,6 @@ namespace Qt3D {
Window::Window(QScreen *screen)
: QWindow(screen)
- , m_engine(new QQmlEngine)
, m_aspectEngine(new QAspectEngine(this))
, m_camera(NULL)
, m_controller(NULL)
@@ -93,17 +90,6 @@ Window::~Window()
delete m_aspectEngine;
}
-Window::Status Window::status() const
-{
- if (!m_engine)
- return Error;
-
- if (!m_component)
- return Null;
-
- return Status(m_component->status());
-}
-
/*!
* Registers an Aspect module to the AspectEngine;
*/
@@ -112,66 +98,6 @@ void Window::registerAspect(AbstractAspect *aspect)
m_aspectEngine->registerAspect(aspect);
}
-void Window::setSource( const QUrl& source )
-{
- if (!m_engine) {
- qWarning() << "Window: invalid qml engine.";
- return;
- }
-
- if (m_root) {
- m_aspectEngine->shutdown();
- m_aspectEngine->setRoot(0);
- m_root = QSharedPointer<QObject>();
- }
-
- if (m_component)
- m_component = QSharedPointer<QQmlComponent>();
-
- if (!source.isEmpty()) {
- m_component = QSharedPointer<QQmlComponent>(new QQmlComponent(m_engine.data(), source, this));
- if (!m_component->isLoading()) {
- continueExecute();
- } else {
- QObject::connect(m_component.data(), SIGNAL(statusChanged(QQmlComponent::Status)),
- this, SLOT(continueExecute()));
- }
- }
-}
-
-void Window::continueExecute()
-{
- qDebug() << Q_FUNC_INFO;
-
- disconnect(m_component.data(), SIGNAL(statusChanged(QQmlComponent::Status)),
- this, SLOT(continueExecute()));
-
- if (m_component->isError()) {
- QList<QQmlError> errorList = m_component->errors();
- Q_FOREACH ( const QQmlError& error, errorList ) {
- QMessageLogger(error.url().toString().toLatin1().constData(), error.line(), 0).warning()
- << error;
- }
- emit statusChanged(status());
- return;
- }
-
- QObject* obj = m_component->create();
-
- if (m_component->isError()) {
- QList<QQmlError> errorList = m_component->errors();
- Q_FOREACH ( const QQmlError& error, errorList ) {
- QMessageLogger(error.url().toString().toLatin1().constData(), error.line(), 0).warning()
- << error;
- }
- emit statusChanged(status());
- return;
- }
-
- setRootObject(obj);
- emit statusChanged(status());
-}
-
void Window::onUpdate()
{
m_controller->update(1.0 / 60.0);
diff --git a/src/core/window.h b/src/core/window.h
index 067634029..87cbe306c 100644
--- a/src/core/window.h
+++ b/src/core/window.h
@@ -45,8 +45,6 @@
#include <QWindow>
#include <Qt3DCore/qt3dcore_global.h>
-#include <QQmlEngine>
-
QT_BEGIN_NAMESPACE
class QTimer;
@@ -67,18 +65,11 @@ public:
explicit Window(QScreen *screen = 0);
~Window();
- void setSource( const QUrl& url );
void setRootObject( QObject* obj );
- enum Status { Null, Ready, Loading, Error };
- Status status() const;
-
QSharedPointer<QObject> rootObject() { return m_root; }
void registerAspect(AbstractAspect *aspect);
-Q_SIGNALS:
- void statusChanged( Qt3D::Window::Status );
-
protected:
virtual void keyPressEvent(QKeyEvent *e);
virtual void keyReleaseEvent( QKeyEvent* e );
@@ -89,20 +80,14 @@ protected:
virtual void resizeEvent(QResizeEvent *e);
private slots:
- void continueExecute();
-
void onUpdate();
-private:
-
- QScopedPointer<QQmlEngine> m_engine;
+protected:
QSharedPointer<QObject> m_root;
- QSharedPointer<QQmlComponent> m_component;
// The various aspects (subsystems) that will be interested in (parts)
// of the objects in the object tree.
QAspectEngine *m_aspectEngine;
-
Camera* m_camera;
// temporary, borrowed from training material
diff --git a/src/quick3d/qt3dquick_global.h b/src/quick3d/qt3dquick_global.h
new file mode 100644
index 000000000..a3c45d7f0
--- /dev/null
+++ b/src/quick3d/qt3dquick_global.h
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DQUICK_GLOBAL_H
+#define QT3DQUICK_GLOBAL_H
+
+#include <QtCore/qglobal.h>
+
+QT_BEGIN_NAMESPACE
+
+#if defined(QT3DQUICK_LIBRARY)
+# define QT3DQUICKSHARED_EXPORT Q_DECL_EXPORT
+#else
+# define QT3DQUICKSHARED_EXPORT Q_DECL_IMPORT
+#endif
+
+QT_END_NAMESPACE
+
+#endif // QT3DQUICK_GLOBAL_H
diff --git a/src/quick3d/quick3d.pro b/src/quick3d/quick3d.pro
new file mode 100644
index 000000000..b05fabd14
--- /dev/null
+++ b/src/quick3d/quick3d.pro
@@ -0,0 +1,30 @@
+TARGET = Qt3DQuick
+
+QT += core-private gui-private qml qml-private quick 3dcore
+
+DEFINES += QT3DQUICK_LIBRARY
+
+MODULE = 3dquick
+
+load(qt_module)
+
+gcov {
+ CONFIG += static
+ QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage
+ QMAKE_LFLAGS += -fprofile-arcs -ftest-coverage
+} else {
+ CONFIG += dll
+}
+
+HEADERS += $$PRIVATE_HEADERS \
+ qt3dquick_global.h \
+ quickwindow.h
+
+!contains(QT_CONFIG, egl):DEFINES += QT_NO_EGL
+
+# otherwise mingw headers do not declare common functions like ::strcasecmp
+win32-g++*:QMAKE_CXXFLAGS_CXX11 = -std=gnu++0x
+
+SOURCES += \
+ quickwindow.cpp
+
diff --git a/src/quick3d/quickwindow.cpp b/src/quick3d/quickwindow.cpp
new file mode 100644
index 000000000..339084acf
--- /dev/null
+++ b/src/quick3d/quickwindow.cpp
@@ -0,0 +1,139 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "quickwindow.h"
+#include <Qt3DCore/qaspectengine.h>
+
+#include <QQmlComponent>
+#include <QDebug>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Quick {
+
+QuickWindow::QuickWindow(QScreen *screen)
+ : Window(screen)
+ , m_engine(new QQmlEngine)
+{
+}
+
+QuickWindow::~QuickWindow()
+{
+}
+
+QuickWindow::Status QuickWindow::status() const
+{
+ if (!m_engine)
+ return Error;
+
+ if (!m_component)
+ return Null;
+
+ return Status(m_component->status());
+}
+
+void QuickWindow::setSource(const QUrl& source)
+{
+ if (!m_engine) {
+ qWarning() << "Window: invalid qml engine.";
+ return;
+ }
+
+ if (m_root) {
+ m_aspectEngine->shutdown();
+ m_aspectEngine->setRoot(0);
+ m_root = QSharedPointer<QObject>();
+ }
+
+ if (m_component)
+ m_component = QSharedPointer<QQmlComponent>();
+
+ if (!source.isEmpty()) {
+ m_component = QSharedPointer<QQmlComponent>(new QQmlComponent(m_engine.data(), source, this));
+ if (!m_component->isLoading()) {
+ continueExecute();
+ } else {
+ QObject::connect(m_component.data(), SIGNAL(statusChanged(QQmlComponent::Status)),
+ this, SLOT(continueExecute()));
+ }
+ }
+}
+
+void QuickWindow::continueExecute()
+{
+ qDebug() << Q_FUNC_INFO;
+
+ QObject::disconnect(m_component.data(), SIGNAL(statusChanged(QQmlComponent::Status)),
+ this, SLOT(continueExecute()));
+
+ if (m_component->isError()) {
+ QList<QQmlError> errorList = m_component->errors();
+ Q_FOREACH ( const QQmlError& error, errorList ) {
+ QMessageLogger(error.url().toString().toLatin1().constData(), error.line(), 0).warning()
+ << error;
+ }
+ emit statusChanged(status());
+ return;
+ }
+
+ QObject* obj = m_component->create();
+
+ if (m_component->isError()) {
+ QList<QQmlError> errorList = m_component->errors();
+ Q_FOREACH ( const QQmlError& error, errorList ) {
+ QMessageLogger(error.url().toString().toLatin1().constData(), error.line(), 0).warning()
+ << error;
+ }
+ emit statusChanged(status());
+ return;
+ }
+
+ setRootObject(obj);
+ emit statusChanged(status());
+}
+
+} // Quick
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/quick3d/quickwindow.h b/src/quick3d/quickwindow.h
new file mode 100644
index 000000000..f104fe7c0
--- /dev/null
+++ b/src/quick3d/quickwindow.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_QUICK_QUICKWINDOW_H
+#define QT3D_QUICK_QUICKWINDOW_H
+
+#include <QWindow>
+#include <QQmlEngine>
+
+#include <Qt3DQuick/qt3dquick_global.h>
+#include <Qt3DCore/window.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class QAspectEngine;
+
+namespace Quick {
+
+class QT3DQUICKSHARED_EXPORT QuickWindow : public Qt3D::Window
+{
+ Q_OBJECT
+public:
+ enum Status { Null, Ready, Loading, Error };
+
+ explicit QuickWindow(QScreen *screen = 0);
+ ~QuickWindow();
+
+ Status status() const;
+ void setSource(const QUrl& url);
+
+Q_SIGNALS:
+ void statusChanged(Status);
+
+private Q_SLOTS:
+ void continueExecute();
+
+private:
+ QScopedPointer<QQmlEngine> m_engine;
+ QSharedPointer<QQmlComponent> m_component;
+
+};
+
+} // Quick
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_QUICK_QUICKWINDOW_H
diff --git a/src/src.pro b/src/src.pro
index d5bc9c761..9816756ac 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -2,4 +2,5 @@ TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += \
core \
- render
+ render \
+ quick3d
diff --git a/sync.profile b/sync.profile
index e0a379ed7..97e0ab4ad 100644
--- a/sync.profile
+++ b/sync.profile
@@ -1,6 +1,7 @@
%modules = ( # path to module name map
"Qt3DCore" => "$basedir/src/core",
"Qt3DRenderer" => "$basedir/src/render",
+ "Qt3DQuick" => "$basedir/src/quick3d",
);
%moduleheaders = ( # restrict the module headers to those found in relative path
);