diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2016-04-10 13:01:02 +0100 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2016-04-12 12:46:17 +0000 |
commit | 1226b25ff68d3e8516207a02816daa2ce7155098 (patch) | |
tree | f7041ede9dafeab5cfa274abbe3f3d8e47806fb6 /src | |
parent | c822a614a7f42582476f614a91cc5b08bb712ab7 (diff) |
Add QNodeCreatedChangeGenerator helper
This can then be used by the QAspectEngine to create creation changes
at startup and by QNodePrivate to generate creation changes for dynamic
objects at runtime.
Change-Id: Idf13fc249de7238a8c5803634a825bd86bc3c52a
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/aspects/qaspectengine.cpp | 19 | ||||
-rw-r--r-- | src/core/aspects/qaspectengine_p.h | 1 | ||||
-rw-r--r-- | src/core/nodes/nodes.pri | 6 | ||||
-rw-r--r-- | src/core/nodes/qnode.h | 1 | ||||
-rw-r--r-- | src/core/nodes/qnodecreatedchangegenerator.cpp | 52 | ||||
-rw-r--r-- | src/core/nodes/qnodecreatedchangegenerator_p.h | 89 |
6 files changed, 149 insertions, 19 deletions
diff --git a/src/core/aspects/qaspectengine.cpp b/src/core/aspects/qaspectengine.cpp index 6a33c4536..769973632 100644 --- a/src/core/aspects/qaspectengine.cpp +++ b/src/core/aspects/qaspectengine.cpp @@ -56,6 +56,7 @@ #include "qentity.h" #include "qcomponent.h" #include <Qt3DCore/private/qeventfilterservice_p.h> +#include <Qt3DCore/private/qnodecreatedchangegenerator_p.h> #include <Qt3DCore/private/qservicelocator_p.h> QT_BEGIN_NAMESPACE @@ -100,22 +101,8 @@ void QAspectEnginePrivate::initEntity(QEntity *entity) void QAspectEnginePrivate::generateCreationChanges(QNode *root) { - m_creationChanges.clear(); - QNodeVisitor creationVisitor; - creationVisitor.traverse(root, this, &QAspectEnginePrivate::createCreationChange); -} - -void QAspectEnginePrivate::createCreationChange(QNode *node) -{ - const auto creationChange = node->createNodeCreationChange(); - m_creationChanges.push_back(creationChange); - - // Store the metaobject of the node in the QNode so that we have it available - // to us during destruction in the QNode destructor. This allows us to send - // the QNodeId and the metaobject as typeinfo to the backend aspects so they - // in turn can find the correct QBackendNodeMapper object to handle the destruction - // of the corresponding backend nodes. - QNodePrivate::get(node)->m_typeInfo = const_cast<QMetaObject*>(creationChange->metaObject()); + const QNodeCreatedChangeGenerator generator(root); + m_creationChanges = generator.creationChanges(); } QAspectEngine::QAspectEngine(QObject *parent) diff --git a/src/core/aspects/qaspectengine_p.h b/src/core/aspects/qaspectengine_p.h index 7a46d5cc2..b2b88d266 100644 --- a/src/core/aspects/qaspectengine_p.h +++ b/src/core/aspects/qaspectengine_p.h @@ -90,7 +90,6 @@ public: void initEntity(QEntity *entity); void generateCreationChanges(QNode *rootNode); - void createCreationChange(QNode *node); // visitor function QVector<QNodeCreatedChangeBasePtr> m_creationChanges; }; diff --git a/src/core/nodes/nodes.pri b/src/core/nodes/nodes.pri index 56e90b2fd..872352bf1 100644 --- a/src/core/nodes/nodes.pri +++ b/src/core/nodes/nodes.pri @@ -13,7 +13,8 @@ HEADERS += \ $$PWD/qnodevisitor_p.h \ $$PWD/qabstractnodefactory.h \ $$PWD/propertychangehandler_p.h \ - $$PWD/qdestructionidandtypecollector_p.h + $$PWD/qdestructionidandtypecollector_p.h \ + $$PWD/qnodecreatedchangegenerator_p.h SOURCES += \ $$PWD/qnode.cpp \ @@ -24,4 +25,5 @@ SOURCES += \ $$PWD/qnodevisitor.cpp \ $$PWD/qabstractnodefactory.cpp \ $$PWD/propertychangehandler.cpp \ - $$PWD/qdestructionidandtypecollector.cpp + $$PWD/qdestructionidandtypecollector.cpp \ + $$PWD/qnodecreatedchangegenerator.cpp diff --git a/src/core/nodes/qnode.h b/src/core/nodes/qnode.h index 86ddeb39c..595992604 100644 --- a/src/core/nodes/qnode.h +++ b/src/core/nodes/qnode.h @@ -126,6 +126,7 @@ private: friend class QAspectEngine; friend class QAspectEnginePrivate; + friend class QNodeCreatedChangeGenerator; friend class QPostman; friend class QScene; }; diff --git a/src/core/nodes/qnodecreatedchangegenerator.cpp b/src/core/nodes/qnodecreatedchangegenerator.cpp new file mode 100644 index 000000000..c350c866a --- /dev/null +++ b/src/core/nodes/qnodecreatedchangegenerator.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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: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$ +** +****************************************************************************/ + +#include "qnodecreatedchangegenerator_p.h" +#include <Qt3DCore/private/qnodevisitor_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { + +QNodeCreatedChangeGenerator::QNodeCreatedChangeGenerator(QNode *rootNode) +{ + QNodeVisitor visitor; + visitor.traverse(rootNode, this, &QNodeCreatedChangeGenerator::createCreationChange); +} + +} // namespace Qt3DCore + +QT_END_NAMESPACE diff --git a/src/core/nodes/qnodecreatedchangegenerator_p.h b/src/core/nodes/qnodecreatedchangegenerator_p.h new file mode 100644 index 000000000..9e4dedafe --- /dev/null +++ b/src/core/nodes/qnodecreatedchangegenerator_p.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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: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 QT3DCORE_QNODECREATEDCHANGEGENERATOR_H +#define QT3DCORE_QNODECREATEDCHANGEGENERATOR_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 <Qt3DCore/qt3dcore_global.h> +#include <Qt3DCore/qnode.h> +#include <Qt3DCore/qnodecreatedchange.h> +#include <Qt3DCore/private/qnode_p.h> +#include <QtCore/qvector.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { + +class QNodeCreatedChangeGenerator +{ +public: + QNodeCreatedChangeGenerator(QNode *rootNode); + + QVector<QNodeCreatedChangeBasePtr> creationChanges() const { return m_creationChanges; } + +private: + void createCreationChange(QNode *node) + { + const auto creationChange = node->createNodeCreationChange(); + m_creationChanges.push_back(creationChange); + + // Store the metaobject of the node in the QNode so that we have it available + // to us during destruction in the QNode destructor. This allows us to send + // the QNodeId and the metaobject as typeinfo to the backend aspects so they + // in turn can find the correct QBackendNodeMapper object to handle the destruction + // of the corresponding backend nodes. + QNodePrivate::get(node)->m_typeInfo = const_cast<QMetaObject*>(creationChange->metaObject()); + } + + QVector<QNodeCreatedChangeBasePtr> m_creationChanges; +}; + +} // namespace Qt3DCore + +QT_END_NAMESPACE + +#endif // QT3DCORE_QNODECREATEDCHANGEGENERATOR_H |