summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/aspects/qaspectengine.cpp10
-rw-r--r--src/core/core-components/qabstracteffect.cpp8
-rw-r--r--src/core/core-components/qabstractmaterial.cpp8
-rw-r--r--src/core/core-components/qabstractmesh.cpp10
-rw-r--r--src/core/core-components/qabstractmesh.h8
-rw-r--r--src/core/core-components/qabstractmesh_p.h4
-rw-r--r--src/core/core-components/qabstractrenderpass.cpp8
-rw-r--r--src/core/core-components/qabstractrenderpass_p.h2
-rw-r--r--src/core/core-components/qabstracttechnique.cpp8
-rw-r--r--src/core/core-components/qcameralens.cpp60
-rw-r--r--src/core/core-components/qcameralens.h8
-rw-r--r--src/core/core-components/qcameralens_p.h4
-rw-r--r--src/core/nodes/nodevisitor.cpp12
-rw-r--r--src/core/nodes/qcomponent.cpp16
-rw-r--r--src/core/nodes/qcomponent.h11
-rw-r--r--src/core/nodes/qcomponent_p.h2
-rw-r--r--src/core/nodes/qentity.cpp67
-rw-r--r--src/core/nodes/qentity.h77
-rw-r--r--src/core/nodes/qentity_p.h2
-rw-r--r--src/core/nodes/qnode.cpp318
-rw-r--r--src/core/nodes/qnode.h46
-rw-r--r--src/core/nodes/qnode_p.h37
-rw-r--r--src/core/qpostman.cpp1
-rw-r--r--src/core/qscene.cpp24
-rw-r--r--src/core/qscene.h7
-rw-r--r--src/core/qsceneinterface.h4
-rw-r--r--src/core/transforms/qabstracttransform.h5
-rw-r--r--src/core/transforms/qabstracttransform_p.h1
-rw-r--r--src/core/transforms/qlookattransform.cpp25
-rw-r--r--src/core/transforms/qlookattransform.h3
-rw-r--r--src/core/transforms/qlookattransform_p.h3
-rw-r--r--src/core/transforms/qmatrixtransform.cpp22
-rw-r--r--src/core/transforms/qmatrixtransform.h4
-rw-r--r--src/core/transforms/qmatrixtransform_p.h2
-rw-r--r--src/core/transforms/qrotatetransform.cpp22
-rw-r--r--src/core/transforms/qrotatetransform.h8
-rw-r--r--src/core/transforms/qrotatetransform_p.h2
-rw-r--r--src/core/transforms/qscaletransform.cpp20
-rw-r--r--src/core/transforms/qscaletransform.h8
-rw-r--r--src/core/transforms/qscaletransform_p.h2
-rw-r--r--src/core/transforms/qtransform.cpp26
-rw-r--r--src/core/transforms/qtransform.h7
-rw-r--r--src/core/transforms/qtransform_p.h2
-rw-r--r--src/core/transforms/qtranslatetransform.cpp16
-rw-r--r--src/core/transforms/qtranslatetransform.h8
-rw-r--r--src/core/transforms/qtranslatetransform_p.h2
46 files changed, 425 insertions, 525 deletions
diff --git a/src/core/aspects/qaspectengine.cpp b/src/core/aspects/qaspectengine.cpp
index 5b88037ee..f22492e95 100644
--- a/src/core/aspects/qaspectengine.cpp
+++ b/src/core/aspects/qaspectengine.cpp
@@ -52,6 +52,7 @@
#include <private/qpostman_p.h>
#include "qscene.h"
#include <private/qaspectengine_p.h>
+#include <private/qnode_p.h>
#include "qentity.h"
#include "qcomponent.h"
@@ -92,15 +93,18 @@ QAspectEngine::QAspectEngine(QAspectEnginePrivate &dd, QObject *parent)
void QAspectEngine::initNodeTree(QNode *node) const
{
Q_D(const QAspectEngine);
- node->setScene(d->m_scene);
+ node->d_func()->setScene(d->m_scene);
d->m_scene->addObservable(node);
QEntity *entity = qobject_cast<QEntity *>(node);
if (entity != Q_NULLPTR)
Q_FOREACH (QComponent *comp, entity->components())
d->m_scene->addEntityForComponent(comp->uuid(), entity->uuid());
- Q_FOREACH (QNode *c, node->children())
- initNodeTree(c);
+ Q_FOREACH (QObject *c, node->children()) {
+ QNode *childNode = qobject_cast<QNode *>(c);
+ if (childNode != Q_NULLPTR)
+ initNodeTree(childNode);
+ }
}
void QAspectEngine::initialize()
diff --git a/src/core/core-components/qabstracteffect.cpp b/src/core/core-components/qabstracteffect.cpp
index 0c722cc1e..5de20afd6 100644
--- a/src/core/core-components/qabstracteffect.cpp
+++ b/src/core/core-components/qabstracteffect.cpp
@@ -93,14 +93,14 @@ void QAbstractEffect::addTechnique(QAbstractTechnique *t)
// Or not previously added as a child of the current node so that
// 1) The backend gets notified about it's creation
// 2) When the current node is destroyed, tit gets destroyed as well
- if (!t->parent() || t->parent() == this)
- QNode::addChild(t);
+ if (!t->parent())
+ t->setParent(this);
if (d->m_changeArbiter != Q_NULLPTR) {
QScenePropertyChangePtr e(new QScenePropertyChange(NodeAdded, this));
e->setPropertyName(QByteArrayLiteral("technique"));
e->setValue(QVariant::fromValue(t));
- notifyObservers(e);
+ d->notifyObservers(e);
}
}
}
@@ -117,7 +117,7 @@ void QAbstractEffect::removeTechnique(QAbstractTechnique *t)
QScenePropertyChangePtr e(new QScenePropertyChange(NodeRemoved, this));
e->setPropertyName(QByteArrayLiteral("technique"));
e->setValue(QVariant::fromValue(t->uuid()));
- notifyObservers(e);
+ d->notifyObservers(e);
}
d->m_techniques.removeOne(t);
}
diff --git a/src/core/core-components/qabstractmaterial.cpp b/src/core/core-components/qabstractmaterial.cpp
index 7ef03ba0b..b5c3aa5f4 100644
--- a/src/core/core-components/qabstractmaterial.cpp
+++ b/src/core/core-components/qabstractmaterial.cpp
@@ -92,7 +92,7 @@ void QAbstractMaterial::setEffect(QAbstractEffect *effect)
QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, this));
change->setPropertyName(QByteArrayLiteral("effect"));
change->setValue(QVariant::fromValue(d->m_effect));
- notifyObservers(change);
+ d->notifyObservers(change);
}
d->m_effect = effect;
@@ -102,14 +102,14 @@ void QAbstractMaterial::setEffect(QAbstractEffect *effect)
// Or not previously added as a child of the current node so that
// 1) The backend gets notified about it's creation
// 2) When the current node is destroyed, it gets destroyed as well
- if (!effect->parent() || effect->parent() == this)
- QNode::addChild(effect);
+ if (!effect->parent())
+ effect->setParent(this);
if (d->m_changeArbiter != Q_NULLPTR) {
QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, this));
change->setPropertyName(QByteArrayLiteral("effect"));
change->setValue(QVariant::fromValue(effect));
- notifyObservers(change);
+ d->notifyObservers(change);
}
}
}
diff --git a/src/core/core-components/qabstractmesh.cpp b/src/core/core-components/qabstractmesh.cpp
index edb59c0b2..7cf960cb0 100644
--- a/src/core/core-components/qabstractmesh.cpp
+++ b/src/core/core-components/qabstractmesh.cpp
@@ -66,6 +66,14 @@ QAbstractMeshPrivate::QAbstractMeshPrivate(QAbstractMesh *qq)
{
}
+void QAbstractMeshPrivate::copy(const QNodePrivate *ref)
+{
+ QNodePrivate::copy(ref);
+ const QAbstractMeshPrivate *abstractMesh = static_cast<const QAbstractMeshPrivate *>(ref);
+ m_uuid = abstractMesh->m_uuid;
+ m_dirty = abstractMesh->m_dirty;
+}
+
QAbstractMesh::QAbstractMesh(QNode *parent)
: QComponent(*new QAbstractMeshPrivate(this), parent)
@@ -92,7 +100,7 @@ void QAbstractMesh::setDirty(bool dirty)
QScenePropertyChangePtr change(new QScenePropertyChange(ComponentUpdated, this));
change->setPropertyName(QByteArrayLiteral("meshFunctor"));
change->setValue(QVariant::fromValue(meshFunctor()));
- notifyObservers(change);
+ d->notifyObservers(change);
// TO DO see if we can clear the d->m_dirty on request.
// This would allow to send a single notification for classes that have several property changes occur
// over a single given frame or maybe that's the job of the QChangeArbiter
diff --git a/src/core/core-components/qabstractmesh.h b/src/core/core-components/qabstractmesh.h
index 68f160789..3a6725ccd 100644
--- a/src/core/core-components/qabstractmesh.h
+++ b/src/core/core-components/qabstractmesh.h
@@ -43,6 +43,7 @@
#define QT3D_QABSTRACTMESH_H
#include <Qt3DCore/qcomponent.h>
+#include <QSharedPointer>
#include <QUuid>
QT_BEGIN_NAMESPACE
@@ -76,12 +77,11 @@ public:
virtual QAbstractMeshFunctorPtr meshFunctor() const = 0;
-Q_SIGNALS:
- void sourceChanged();
-
protected:
- Q_DECLARE_PRIVATE(QAbstractMesh)
QAbstractMesh(QAbstractMeshPrivate &dd, QNode *parent = 0);
+
+private:
+ Q_DECLARE_PRIVATE(QAbstractMesh)
};
} // Qt3D
diff --git a/src/core/core-components/qabstractmesh_p.h b/src/core/core-components/qabstractmesh_p.h
index caf3249f2..3ef172bee 100644
--- a/src/core/core-components/qabstractmesh_p.h
+++ b/src/core/core-components/qabstractmesh_p.h
@@ -60,9 +60,11 @@ class QT3DCORESHARED_EXPORT QAbstractMeshPrivate : public QComponentPrivate
public:
QAbstractMeshPrivate(QAbstractMesh *qq);
+ virtual void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE;
+
Q_DECLARE_PUBLIC(QAbstractMesh)
- const QUuid m_uuid;
+ QUuid m_uuid;
bool m_dirty;
};
diff --git a/src/core/core-components/qabstractrenderpass.cpp b/src/core/core-components/qabstractrenderpass.cpp
index 6b4c81f87..6484f1701 100644
--- a/src/core/core-components/qabstractrenderpass.cpp
+++ b/src/core/core-components/qabstractrenderpass.cpp
@@ -93,7 +93,7 @@ void QAbstractRenderPass::setShaderProgram(QAbstractShader *shaderProgram)
QScenePropertyChangePtr e(new QScenePropertyChange(NodeRemoved, this));
e->setPropertyName(QByteArrayLiteral("shaderProgram"));
e->setValue(QVariant::fromValue(d->m_shader->uuid()));
- notifyObservers(e);
+ d->notifyObservers(e);
}
d->m_shader = shaderProgram;
@@ -103,14 +103,14 @@ void QAbstractRenderPass::setShaderProgram(QAbstractShader *shaderProgram)
// Or not previously added as a child of the current node so that
// 1) The backend gets notified about it's creation
// 2) When the current node is destroyed, it gets destroyed as well
- if (!shaderProgram->parent() || shaderProgram->parent() == this)
- QNode::addChild(shaderProgram);
+ if (!shaderProgram->parent())
+ shaderProgram->setParent(this);
if (d->m_changeArbiter != Q_NULLPTR) {
QScenePropertyChangePtr e(new QScenePropertyChange(NodeAdded, this));
e->setPropertyName(QByteArrayLiteral("shaderProgram"));
e->setValue(QVariant::fromValue(shaderProgram->uuid()));
- notifyObservers(e);
+ d->notifyObservers(e);
}
}
}
diff --git a/src/core/core-components/qabstractrenderpass_p.h b/src/core/core-components/qabstractrenderpass_p.h
index ffc1f75b4..13045de0f 100644
--- a/src/core/core-components/qabstractrenderpass_p.h
+++ b/src/core/core-components/qabstractrenderpass_p.h
@@ -43,12 +43,12 @@
#define QT3D_QABSTRACTRENDERPASS_P_H
#include <private/qnode_p.h>
+#include <Qt3DCore/qabstractrenderpass.h>
QT_BEGIN_NAMESPACE
namespace Qt3D {
-class QAbstractRenderPass;
class QAbstractShader;
class QT3DCORESHARED_EXPORT QAbstractRenderPassPrivate : public QNodePrivate
diff --git a/src/core/core-components/qabstracttechnique.cpp b/src/core/core-components/qabstracttechnique.cpp
index 12bc2e7a0..d9c9f04b1 100644
--- a/src/core/core-components/qabstracttechnique.cpp
+++ b/src/core/core-components/qabstracttechnique.cpp
@@ -98,14 +98,14 @@ void QAbstractTechnique::addPass(QAbstractRenderPass *pass)
// Or not previously added as a child of the current node so that
// 1) The backend gets notified about it's creation
// 2) When the current node is destroyed, it gets destroyed as well
- if (!pass->parent() || pass->parent() == this)
- QNode::addChild(pass);
+ if (!pass->parent())
+ pass->setParent(this);
if (d->m_changeArbiter != Q_NULLPTR) {
QScenePropertyChangePtr e(new QScenePropertyChange(NodeAdded, this));
e->setPropertyName(QByteArrayLiteral("pass"));
e->setValue(QVariant::fromValue(pass));
- notifyObservers(e);
+ d->notifyObservers(e);
}
}
}
@@ -122,7 +122,7 @@ void QAbstractTechnique::removePass(QAbstractRenderPass *pass)
QScenePropertyChangePtr e(new QScenePropertyChange(NodeRemoved, this));
e->setPropertyName(QByteArrayLiteral("pass"));
e->setValue(QVariant::fromValue(pass->uuid()));
- notifyObservers(e);
+ d->notifyObservers(e);
}
d->m_renderPasses.removeOne(pass);
}
diff --git a/src/core/core-components/qcameralens.cpp b/src/core/core-components/qcameralens.cpp
index 154ae13b5..aa06ee27d 100644
--- a/src/core/core-components/qcameralens.cpp
+++ b/src/core/core-components/qcameralens.cpp
@@ -47,16 +47,16 @@ QT_BEGIN_NAMESPACE
namespace Qt3D {
QCameraLensPrivate::QCameraLensPrivate(QCameraLens *qq)
- : QComponentPrivate(qq)
- , m_projectionType(QCameraLens::OrthogonalProjection)
- , m_nearPlane(0.1f)
- , m_farPlane(1024.0f)
- , m_fieldOfView(25.0f)
- , m_aspectRatio(1.0f)
- , m_left(-0.5f)
- , m_right(0.5f)
- , m_bottom(-0.5f)
- , m_top(0.5f)
+ : QComponentPrivate(qq)
+ , m_projectionType(QCameraLens::OrthogonalProjection)
+ , m_nearPlane(0.1f)
+ , m_farPlane(1024.0f)
+ , m_fieldOfView(25.0f)
+ , m_aspectRatio(1.0f)
+ , m_left(-0.5f)
+ , m_right(0.5f)
+ , m_bottom(-0.5f)
+ , m_top(0.5f)
{
}
@@ -68,23 +68,20 @@ QCameraLens::QCameraLens(QNode *parent)
d->updateProjectionMatrix();
}
-void QCameraLens::copy(const QNode *ref)
+void QCameraLensPrivate::copy(const QNodePrivate *ref)
{
- Q_D(QCameraLens);
- QComponent::copy(ref);
- const QCameraLens *lens = qobject_cast<const QCameraLens *>(ref);
- if (lens != Q_NULLPTR) {
- d->m_projectionType = lens->projectionType();
- d->m_nearPlane = lens->nearPlane();
- d->m_farPlane = lens->farPlane();
- d->m_fieldOfView = lens->fieldOfView();
- d->m_aspectRatio = lens->aspectRatio();
- d->m_left = lens->left();
- d->m_right = lens->right();
- d->m_bottom = lens->bottom();
- d->m_top = lens->top();
- d->updateProjectionMatrix();
- }
+ QComponentPrivate::copy(ref);
+ const QCameraLensPrivate *lens = static_cast<const QCameraLensPrivate *>(ref);
+ m_projectionType = lens->m_projectionType;
+ m_nearPlane = lens->m_nearPlane;
+ m_farPlane = lens->m_farPlane;
+ m_fieldOfView = lens->m_fieldOfView;
+ m_aspectRatio = lens->m_aspectRatio;
+ m_left = lens->m_left;
+ m_right = lens->m_right;
+ m_bottom = lens->m_bottom;
+ m_top = lens->m_top;
+ m_projectionMatrix = lens->m_projectionMatrix;
}
QCameraLens::QCameraLens(QCameraLensPrivate &dd, QNode *parent)
@@ -94,11 +91,10 @@ QCameraLens::QCameraLens(QCameraLensPrivate &dd, QNode *parent)
d->updateOrthogonalProjection();
}
-QCameraLens *QCameraLens::doClone(bool isClone) const
+QCameraLens *QCameraLens::doClone() const
{
QCameraLens *clone = new QCameraLens();
- clone->copy(this);
- clone->d_func()->m_isClone = isClone;
+ clone->d_func()->copy(d_func());
return clone;
}
@@ -119,8 +115,8 @@ QCameraLens::ProjectionType QCameraLens::projectionType() const
}
void QCameraLens::setOrthographicProjection( float left, float right,
- float bottom, float top,
- float nearPlane, float farPlane )
+ float bottom, float top,
+ float nearPlane, float farPlane )
{
Q_D(QCameraLens);
d->m_left = left;
@@ -134,7 +130,7 @@ void QCameraLens::setOrthographicProjection( float left, float right,
}
void QCameraLens::setPerspectiveProjection( float fieldOfView, float aspectRatio,
- float nearPlane, float farPlane )
+ float nearPlane, float farPlane )
{
Q_D(QCameraLens);
d->m_fieldOfView = fieldOfView;
diff --git a/src/core/core-components/qcameralens.h b/src/core/core-components/qcameralens.h
index 25399c49f..f6a5e4f4c 100644
--- a/src/core/core-components/qcameralens.h
+++ b/src/core/core-components/qcameralens.h
@@ -74,8 +74,6 @@ class QT3DCORESHARED_EXPORT QCameraLens : public QComponent
public:
explicit QCameraLens(QNode *parent = 0);
- void copy(const QNode *ref) Q_DECL_OVERRIDE;
-
enum ProjectionType {
OrthogonalProjection,
PerspectiveProjection
@@ -131,9 +129,11 @@ Q_SIGNALS:
void projectionMatrixChanged();
protected:
- Q_DECLARE_PRIVATE(QCameraLens)
QCameraLens(QCameraLensPrivate &dd, QNode *parent = 0);
- QCameraLens *doClone(bool isClone = true) const Q_DECL_OVERRIDE;
+
+private:
+ Q_DECLARE_PRIVATE(QCameraLens)
+ QCameraLens *doClone() const Q_DECL_OVERRIDE;
};
} // Qt3D
diff --git a/src/core/core-components/qcameralens_p.h b/src/core/core-components/qcameralens_p.h
index 9a3fa6f42..c92279445 100644
--- a/src/core/core-components/qcameralens_p.h
+++ b/src/core/core-components/qcameralens_p.h
@@ -58,6 +58,8 @@ class QT3DCORESHARED_EXPORT QCameraLensPrivate : public QComponentPrivate
public:
QCameraLensPrivate(QCameraLens *qq);
+ void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE;
+
inline void updateProjectionMatrix()
{
switch (m_projectionType) {
@@ -78,7 +80,7 @@ public:
QScenePropertyChangePtr propertyChange(new QScenePropertyChange(ComponentUpdated, q));
propertyChange->setPropertyName(QByteArrayLiteral("projectionMatrix"));
propertyChange->setValue(QVariant::fromValue(m_projectionMatrix));
- q->notifyObservers(propertyChange);
+ QNodePrivate::notifyObservers(propertyChange);
}
}
diff --git a/src/core/nodes/nodevisitor.cpp b/src/core/nodes/nodevisitor.cpp
index ac25fc488..f830b6bb4 100644
--- a/src/core/nodes/nodevisitor.cpp
+++ b/src/core/nodes/nodevisitor.cpp
@@ -62,9 +62,7 @@ void NodeVisitor::traverse(QNode *rootNode)
m_path = NodeList() << rootNode;
m_matrixStack.clear();
- QEntity* rootEntity = rootNode->asEntity();
-
-// m_matrixStack.append(rootEntity ? rootEntity->matrix() : QMatrix4x4());
+ QEntity* rootEntity = qobject_cast<QEntity *>(rootNode);
if (rootEntity)
visitEntity(rootEntity);
@@ -110,15 +108,17 @@ void NodeVisitor::visitEntity(QEntity *nd)
void NodeVisitor::traverseChildren()
{
- foreach (QNode* n, currentNode()->children()) {
- outerVisitNode(n);
+ foreach (QObject *n, currentNode()->children()) {
+ QNode *node = qobject_cast<QNode *>(n);
+ if (node != Q_NULLPTR)
+ outerVisitNode(node);
} // of children iteration
}
void NodeVisitor::outerVisitNode(QNode *n)
{
m_path.append(n);
- QEntity* e = n->asEntity();
+ QEntity* e = qobject_cast<QEntity *>(n);
if (e) {
visitEntity(e);
m_path.pop_back();
diff --git a/src/core/nodes/qcomponent.cpp b/src/core/nodes/qcomponent.cpp
index 562466549..27aa1da37 100644
--- a/src/core/nodes/qcomponent.cpp
+++ b/src/core/nodes/qcomponent.cpp
@@ -48,7 +48,6 @@ namespace Qt3D {
QComponentPrivate::QComponentPrivate(QComponent *qq)
: QNodePrivate(qq)
- , m_enabled(true)
{
}
@@ -62,21 +61,6 @@ QComponent::QComponent(QComponentPrivate &dd, QNode *parent)
{
}
-void QComponent::setEnabled(bool enabled)
-{
- Q_D(QComponent);
- if (d->m_enabled != enabled) {
- d->m_enabled = enabled;
- emit enabledChanged();
- }
-}
-
-bool QComponent::isEnabled() const
-{
- Q_D(const QComponent);
- return d->m_enabled;
-}
-
} // namespace Qt3D
QT_END_NAMESPACE
diff --git a/src/core/nodes/qcomponent.h b/src/core/nodes/qcomponent.h
index c76dbc6c1..81089d46c 100644
--- a/src/core/nodes/qcomponent.h
+++ b/src/core/nodes/qcomponent.h
@@ -55,20 +55,13 @@ class QT3DCORESHARED_EXPORT QComponent : public QNode
{
Q_OBJECT
- Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
-
public:
explicit QComponent(QNode *parent = 0);
- void setEnabled(bool enabled);
- bool isEnabled() const;
-
-Q_SIGNALS:
- void enabledChanged();
-
protected:
- Q_DECLARE_PRIVATE(QComponent)
QComponent(QComponentPrivate &dd, QNode *parent = 0);
+private:
+ Q_DECLARE_PRIVATE(QComponent)
};
} // namespace Qt3D
diff --git a/src/core/nodes/qcomponent_p.h b/src/core/nodes/qcomponent_p.h
index da27f6b7d..83c755138 100644
--- a/src/core/nodes/qcomponent_p.h
+++ b/src/core/nodes/qcomponent_p.h
@@ -55,8 +55,6 @@ public:
explicit QComponentPrivate(QComponent *qq);
Q_DECLARE_PUBLIC(QComponent)
-
- bool m_enabled;
};
}
diff --git a/src/core/nodes/qentity.cpp b/src/core/nodes/qentity.cpp
index 4314bdd6a..5d0144677 100644
--- a/src/core/nodes/qentity.cpp
+++ b/src/core/nodes/qentity.cpp
@@ -42,6 +42,7 @@
#include "qentity.h"
#include "qentity_p.h"
#include "qcomponent.h"
+#include "qcomponent_p.h"
#include "qabstracttransform.h"
#include "qmatrixtransform.h"
@@ -77,28 +78,24 @@ QEntity::QEntity(QEntityPrivate &dd, QNode *parent)
{
}
-QEntity *QEntity::doClone(bool isClone) const
+QEntity *QEntity::doClone() const
{
Q_D(const QEntity);
QEntity *clone = new QEntity();
- clone->copy(this);
- clone->d_func()->m_isClone = isClone;
+ clone->d_func()->copy(d_func());
Q_FOREACH (QComponent *c, d->m_components) {
- QNode *ccclone = c->clone(isClone);
+ QNode *ccclone = QNodePrivate::get(c)->clone();
clone->addComponent(qobject_cast<QComponent *>(ccclone));
}
return clone;
}
-void QEntity::copy(const QNode *ref)
+void QEntityPrivate::copy(const QNodePrivate *ref)
{
- Q_D(QEntity);
- QNode::copy(ref);
- const QEntity *entity = qobject_cast<const QEntity *>(ref);
- if (entity != Q_NULLPTR) {
- d->m_enabled = entity->d_func()->m_enabled;
- d->m_visible = entity->d_func()->m_visible;
- }
+ QNodePrivate::copy(ref);
+ const QEntityPrivate *entity = static_cast<const QEntityPrivate *>(ref);
+ m_enabled = entity->m_enabled;
+ m_visible = entity->m_visible;
}
QList<QComponent *> QEntity::components() const
@@ -116,36 +113,34 @@ void QEntity::addComponent(QComponent *comp)
d->m_components.append(comp);
// We only set the Entity as the Component's parent when it has no parent
// This will be the case mostly on C++ but rarely in QML
- if (!comp->parent() || comp->parent() == this)
- addChild(comp);
+ if (!comp->parent())
+ comp->setParent(this);
- if (!isClone() && !comp->isClone() && d->m_scene != Q_NULLPTR)
+ if (d->m_scene != Q_NULLPTR)
d->m_scene->addEntityForComponent(comp->uuid(), d->m_uuid);
- if (!isClone() && !comp->isClone() && d->m_changeArbiter != Q_NULLPTR) {
+ if (d->m_changeArbiter != Q_NULLPTR) {
QScenePropertyChangePtr propertyChange(new QScenePropertyChange(ComponentAdded, this));
propertyChange->setPropertyName(QByteArrayLiteral("component"));
- propertyChange->setValue(QVariant::fromValue(QNodePtr(comp->clone())));
- notifyObservers(propertyChange);
+ propertyChange->setValue(QVariant::fromValue(QNodePtr(QNodePrivate::get(comp)->clone(), &QNodePrivate::nodePtrDeleter)));
+ d->notifyObservers(propertyChange);
}
}
-// As in most cases Components are children of the Entity
-// They shouldn't therefore also be called in the removeAllChildren of QNode
-// How to handle QML inline declaration however ?
void QEntity::removeComponent(QComponent *comp)
{
Q_CHECK_PTR(comp);
qCDebug(Nodes) << Q_FUNC_INFO << comp;
Q_D(QEntity);
- if (!isClone() && !comp->isClone() && d->m_changeArbiter != Q_NULLPTR) {
+
+ if (d->m_changeArbiter != Q_NULLPTR) {
QScenePropertyChangePtr propertyChange(new QScenePropertyChange(ComponentRemoved, this));
- propertyChange->setValue(QVariant::fromValue(QNodePtr(comp->clone())));
+ propertyChange->setValue(QVariant::fromValue(QNodePtr(QNodePrivate::get(comp)->clone(), &QNodePrivate::nodePtrDeleter)));
propertyChange->setPropertyName(QByteArrayLiteral("component"));
- notifyObservers(propertyChange);
+ d->notifyObservers(propertyChange);
}
- if (!isClone() && !comp->isClone() && d->m_scene != Q_NULLPTR)
+ if (d->m_scene != Q_NULLPTR)
d->m_scene->removeEntityForComponent(comp->uuid(), d->m_uuid);
d->m_components.removeOne(comp);
@@ -158,25 +153,10 @@ void QEntity::removeAllComponents()
removeComponent(comp);
}
-bool QEntity::isEnabled() const
-{
- Q_D(const QEntity);
- return d->m_enabled;
-}
-
-void QEntity::setEnabled(bool on)
-{
- Q_D(QEntity);
- if (d->m_enabled != on) {
- d->m_enabled = on;
- emit enabledChanged();
- }
-}
-
QEntity *QEntity::parentEntity()
{
QNode *parentNode = QNode::parentNode();
- QEntity *parentEntity = qobject_cast<QEntity*>(parentNode);
+ QEntity *parentEntity = qobject_cast<QEntity *>(parentNode);
while (parentEntity == Q_NULLPTR && parentNode != Q_NULLPTR) {
parentNode = parentNode->parentNode();
@@ -185,11 +165,6 @@ QEntity *QEntity::parentEntity()
return parentEntity;
}
-QEntity *QEntity::asEntity()
-{
- return this;
-}
-
} // namespace Qt3D
QT_END_NAMESPACE
diff --git a/src/core/nodes/qentity.h b/src/core/nodes/qentity.h
index d937f98f6..1242e2d36 100644
--- a/src/core/nodes/qentity.h
+++ b/src/core/nodes/qentity.h
@@ -60,93 +60,24 @@ class QT3DCORESHARED_EXPORT QEntity : public QNode
{
Q_OBJECT
- Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
-
public:
explicit QEntity(QNode *parent = 0);
virtual ~QEntity();
ComponentList components() const;
- virtual void copy(const QNode *ref) Q_DECL_OVERRIDE;
-
- template <class T>
- QList<T*> componentsOfType() const
- {
- QList<T*> result;
- Q_FOREACH (QComponent* comp, components()) {
- T* i = qobject_cast<T*>(comp);
- if (i)
- result.append(i);
- }
-
- return result;
- }
-
- template <class T>
- static T* findComponentInTree(QNode* root)
- {
- if (!root)
- return Q_NULLPTR;
-
- if (root->asEntity()) {
- Q_FOREACH (QComponent* comp, root->asEntity()->components()) {
- T* i = qobject_cast<T*>(comp);
- if (i)
- return i;
- } // of component iteration
- } // of is-entity
-
- Q_FOREACH (QNode* child, root->children()) {
- T* i = findComponentInTree<T>(child);
- if (i)
- return i;
- } // of child nodes iteration
-
- return Q_NULLPTR;
- }
-
- template <class T>
- static T* findEntityInTree(QNode* root)
- {
- if (!root)
- return Q_NULLPTR;
-
- if (root->asEntity()) {
- Q_FOREACH (QNode* child, root->children()) {
- if (!qobject_cast<QEntity*>(child))
- continue;
- T* i = qobject_cast<T*>(child);
- if (i)
- return i;
- } // of child iteration
- } // of is-entity
-
- Q_FOREACH (QNode* child, root->children()) {
- T* i = findEntityInTree<T>(child);
- if (i)
- return i;
- } // of child nodes iteration
-
- return Q_NULLPTR;
- }
void addComponent(QComponent *comp);
void removeComponent(QComponent *comp);
void removeAllComponents();
- bool isEnabled() const;
- void setEnabled(bool on);
-
QEntity *parentEntity();
- QEntity *asEntity() Q_DECL_OVERRIDE;
-
-Q_SIGNALS:
- void enabledChanged();
protected:
- Q_DECLARE_PRIVATE(QEntity)
QEntity(QEntityPrivate &dd, QNode *parent = 0);
- QEntity *doClone(bool isClone = true) const Q_DECL_OVERRIDE;
+
+private:
+ Q_DECLARE_PRIVATE(QEntity)
+ QEntity *doClone() const Q_DECL_OVERRIDE;
};
} // namespace Qt3D
diff --git a/src/core/nodes/qentity_p.h b/src/core/nodes/qentity_p.h
index e883aa93c..20e51d251 100644
--- a/src/core/nodes/qentity_p.h
+++ b/src/core/nodes/qentity_p.h
@@ -57,6 +57,8 @@ public :
Q_DECLARE_PUBLIC(QEntity)
+ void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE;
+
ComponentList m_components;
bool m_visible;
diff --git a/src/core/nodes/qnode.cpp b/src/core/nodes/qnode.cpp
index 2d2271432..d54adc72c 100644
--- a/src/core/nodes/qnode.cpp
+++ b/src/core/nodes/qnode.cpp
@@ -47,6 +47,7 @@
#include <Qt3DCore/qaspectengine.h>
#include <Qt3DCore/qsceneinterface.h>
#include <QEvent>
+#include <QChildEvent>
#include <QMetaObject>
#include <QMetaProperty>
#include "corelogging.h"
@@ -56,223 +57,153 @@ QT_BEGIN_NAMESPACE
namespace Qt3D {
+QHash<QUuid, QNode *> QNodePrivate::m_clonesLookupTable = QHash<QUuid, QNode *>();
+
QNodePrivate::QNodePrivate(QNode *qq)
: QObjectPrivate()
, m_changeArbiter(Q_NULLPTR)
, m_scene(Q_NULLPTR)
, m_uuid(QUuid::createUuid())
- , m_isClone(false)
{
q_ptr = qq;
}
-QNode::QNode(QNode *parent)
- : QObject(*new QNodePrivate(this), parent)
-{
-}
-
-QNode::QNode(QNodePrivate &dd, QNode *parent)
- : QObject(dd, parent)
-{
-}
-
-QNode::~QNode()
-{
- // TO DO should unregister itself from the QChangeArbiter
- removeAllChildren();
-}
-
-void QNode::dump()
+void QNodePrivate::copy(const QNodePrivate *ref)
{
- const QMetaObject *meta = metaObject();
- QStringList result;
- for (int i = 0; i < meta->propertyCount(); ++i) {
- const QMetaProperty metaProperty = meta->property(i);
- const QVariant value = property(metaProperty.name());
- result += QString(QStringLiteral("%1 %2 = %3;"))
- .arg(QString::fromLatin1(metaProperty.typeName()))
- .arg(QString::fromLatin1(metaProperty.name()))
- .arg(value.toString());
- }
-
- qCDebug(Nodes) << result.join(QStringLiteral("\n"));
-
- foreach (QObject *child, children()) {
- QNode *node = qobject_cast<QNode *>(child);
- if (!node)
- continue;
- node->dump();
+ if (ref != Q_NULLPTR) {
+ m_uuid = ref->m_uuid;
}
}
-const QUuid QNode::uuid() const
+// Called by QEvent::childAdded
+void QNodePrivate::addChild(QNode *childNode)
{
- Q_D(const QNode);
- return d->m_uuid;
-}
-NodeList QNode::children() const
-{
- Q_D(const QNode);
- return d->m_children;
-}
-
-void QNode::addChild(QNode *childNode)
-{
Q_ASSERT(childNode);
- Q_D(QNode);
- if (childNode == this)
- return ;
- if (d->m_children.contains(childNode))
+ if (childNode == q_ptr)
return ;
- d->m_children.append(childNode);
- childNode->setParent(this);
- childNode->setScene(scene());
+ // Set the scene
+ childNode->d_func()->setScene(m_scene);
- if (!isClone() && !childNode->isClone() && d->m_scene != Q_NULLPTR)
- d->m_scene->addObservable(childNode);
+ // addObservable set the QChangeArbiter
+ if (m_scene != Q_NULLPTR)
+ m_scene->addObservable(childNode);
- if (!isClone() && !childNode->isClone() && d->m_changeArbiter != Q_NULLPTR) {
- QScenePropertyChangePtr e(new QScenePropertyChange(NodeCreated, this));
+ // We notify only if we have a QChangeArbiter
+ if (m_changeArbiter != Q_NULLPTR) {
+ QScenePropertyChangePtr e(new QScenePropertyChange(NodeCreated, qobject_cast<QNode *>(q_ptr)));
e->setPropertyName(QByteArrayLiteral("node"));
// We need to clone the parent of the childNode we send
QNode *parentClone = clone();
QNode *childClone = Q_NULLPTR;
- Q_FOREACH (QNode *clone, parentClone->children()) {
- if (clone->uuid() == childNode->uuid()) {
+ Q_FOREACH (QObject *c, parentClone->children()) {
+ QNode *clone = qobject_cast<QNode *>(c);
+ if (clone != Q_NULLPTR && clone->uuid() == childNode->uuid()) {
childClone = clone;
break;
}
}
- e->setValue(QVariant::fromValue(QNodePtr(childClone)));
+ e->setValue(QVariant::fromValue(QNodePtr(childClone, &QNodePrivate::nodePtrDeleter)));
notifyObservers(e);
- childNode->registerObserver(d->m_changeArbiter);
}
}
-void QNode::removeChild(QNode *childNode)
+// Called by QEvent::childRemoved
+void QNodePrivate::removeChild(QNode *childNode)
{
Q_ASSERT(childNode);
- if (childNode->parent() != this)
+ if (childNode->parent() != q_ptr)
qCWarning(Nodes) << Q_FUNC_INFO << "not a child of " << this;
- Q_D(QNode);
-
- if (!isClone() && !childNode->isClone() && d->m_scene != Q_NULLPTR)
- d->m_scene->removeObservable(childNode);
-
// Notify only if child isn't a clone
- if (!isClone() && !childNode->isClone() && d->m_changeArbiter != Q_NULLPTR) {
- QScenePropertyChangePtr e(new QScenePropertyChange(NodeAboutToBeDeleted, this));
+ if (m_changeArbiter != Q_NULLPTR) {
+ QScenePropertyChangePtr e(new QScenePropertyChange(NodeAboutToBeDeleted, qobject_cast<QNode *>(q_ptr)));
e->setPropertyName(QByteArrayLiteral("node"));
// We need to clone the parent of the childNode we send
QNode *parentClone = clone();
QNode *childClone = Q_NULLPTR;
- Q_FOREACH (QNode *clone, parentClone->children()) {
- if (clone->uuid() == childNode->uuid()) {
+ Q_FOREACH (QObject *c, parentClone->children()) {
+ QNode *clone = qobject_cast<QNode *>(c);
+ if (clone != Q_NULLPTR && clone->uuid() == childNode->uuid()) {
childClone = clone;
break;
}
}
- e->setValue(QVariant::fromValue(QNodePtr(childClone)));
+ e->setValue(QVariant::fromValue(QNodePtr(childClone, &QNodePrivate::nodePtrDeleter)));
notifyObservers(e);
- childNode->unregisterObserver(d->m_changeArbiter);
}
- d->m_children.removeOne(childNode);
- if (!childNode->isClone())
- childNode->setParent(Q_NULLPTR);
- childNode->setScene(Q_NULLPTR);
+ if (m_scene != Q_NULLPTR)
+ m_scene->removeObservable(childNode);
+ childNode->d_func()->setScene(Q_NULLPTR);
}
// In most cases isClone is true so that the clone isn't handled like
// a real node. If there is a need for a real clone, set isClone to false
// eg When a subtree built in the backend needs to be cloned
// in the main thread to be added to the scene graph
-QNode *QNode::clone(bool isClone)
+QNode *QNodePrivate::clone()
{
- Q_D(QNode);
static int clearLock = 0;
-
clearLock++;
- if (d->m_scene == Q_NULLPTR)
- return Q_NULLPTR;
-
- QNode *clonedNode = d->m_scene->lookupClone(uuid());
+ // We keep a reference of clones for the current subtree
+ // In order to preserve relationships when multiple entities
+ // reference the same component
+ QNode *clonedNode = QNodePrivate::m_clonesLookupTable.value(m_uuid);
if (clonedNode == Q_NULLPTR) {
- clonedNode = doClone(isClone);
+ clonedNode = qobject_cast<QNode *>(q_ptr)->doClone();
// doClone, returns new instance with content copied
// and relationships added
- d->m_scene->addCloneLookup(clonedNode);
+ QNodePrivate::m_clonesLookupTable.insert(clonedNode->uuid(), clonedNode);
}
- Q_FOREACH (QNode *c, children()) {
- QNode *cclone = c->clone(isClone);
- clonedNode->addChild(cclone);
+ Q_FOREACH (QObject *c, q_ptr->children()) {
+ QNode *childNode = qobject_cast<QNode *>(c);
+ if (childNode != Q_NULLPTR) {
+ QNode *cclone = childNode->d_func()->clone();
+ if (cclone != Q_NULLPTR)
+ cclone->setParent(clonedNode);
+ }
}
if (--clearLock == 0)
- d->m_scene->clearCloneLookup();
- return clonedNode;
-}
+ QNodePrivate::m_clonesLookupTable.clear();
-void QNode::copy(const QNode *ref)
-{
- Q_D(QNode);
- d->m_uuid = ref->uuid();
- d->m_changeArbiter = ref->d_func()->m_changeArbiter;
- d->m_scene = ref->d_func()->m_scene;
- setObjectName(ref->objectName());
-}
-
-bool QNode::isClone() const
-{
- Q_D(const QNode);
- return d->m_isClone;
-}
-
-void QNode::removeAllChildren()
-{
- Q_FOREACH (QObject *child, children())
- if (qobject_cast<QNode *>(child))
- removeChild(qobject_cast<QNode *>(child));
-}
-
-QEntity *QNode::asEntity()
-{
- return Q_NULLPTR;
+ return clonedNode;
}
-QNode *QNode::parentNode() const
+void QNodePrivate::removeAllChildren()
{
- return qobject_cast<QNode*>(parent());
+ Q_FOREACH (QObject *child, q_ptr->children()) {
+ QNode *childNode = qobject_cast<QNode *>(child);
+ if (childNode != Q_NULLPTR)
+ removeChild(childNode);
+ }
}
// Called in the QAspectThread context
-void QNode::registerObserver(QObserverInterface *observer)
+void QNodePrivate::registerObserver(QObserverInterface *observer)
{
Q_CHECK_PTR(observer);
// For now we only care about the QChangeArbiter observing us
QChangeArbiter *changeArbiter = dynamic_cast<QChangeArbiter *>(observer);
if (changeArbiter) {
- Q_D(QNode);
- QWriteLocker locker(&d->m_observerLock);
- d->m_changeArbiter = changeArbiter;
+ QWriteLocker locker(&m_observerLock);
+ m_changeArbiter = changeArbiter;
}
}
-void QNode::unregisterObserver(QObserverInterface *observer)
+void QNodePrivate::unregisterObserver(QObserverInterface *observer)
{
Q_CHECK_PTR(observer);
// For now we only care about the QChangeArbiter observing us
- Q_D(QNode);
QChangeArbiter *changeArbiter = dynamic_cast<QChangeArbiter *>(observer);
- if (changeArbiter == d->m_changeArbiter) {
- QWriteLocker locker(&d->m_observerLock);
- d->m_changeArbiter = Q_NULLPTR;
+ if (changeArbiter == m_changeArbiter) {
+ QWriteLocker locker(&m_observerLock);
+ m_changeArbiter = Q_NULLPTR;
}
}
@@ -281,36 +212,33 @@ void QNode::sceneChangeEvent(const QSceneChangePtr &)
qWarning() << Q_FUNC_INFO << "sceneChangeEvent should have been subclassed";
}
-void QNode::setScene(QSceneInterface *scene)
+void QNodePrivate::setScene(QSceneInterface *scene)
{
- Q_D(QNode);
- if (d->m_scene != scene)
- d->m_scene = scene;
+ if (m_scene != scene)
+ m_scene = scene;
}
-QSceneInterface *QNode::scene() const
+QSceneInterface *QNodePrivate::scene() const
{
- Q_D(const QNode);
- return d->m_scene;
+ return m_scene;
}
-void QNode::notifyPropertyChange(const QByteArray &name, const QVariant &value)
+void QNodePrivate::notifyPropertyChange(const QByteArray &name, const QVariant &value)
{
// TODO: Review change types. Is there any need to distinguish between NodeUpdated, ComponentUpdated?
// They're both just property changes
- QScenePropertyChangePtr e(new QScenePropertyChange(NodeUpdated, this));
+ QScenePropertyChangePtr e(new QScenePropertyChange(NodeUpdated, qobject_cast<QNode *>(q_ptr)));
e->setPropertyName(name);
e->setValue(value);
notifyObservers(e);
}
// Called by the main thread
-void QNode::notifyObservers(const QSceneChangePtr &change)
+void QNodePrivate::notifyObservers(const QSceneChangePtr &change)
{
Q_CHECK_PTR(change);
- Q_D(QNode);
- QReadLocker locker(&d->m_observerLock);
- QChangeArbiter *changeArbiter = d->m_changeArbiter;
+ QReadLocker locker(&m_observerLock);
+ QChangeArbiter *changeArbiter = m_changeArbiter;
locker.unlock();
// There is a deadlock issue as sceneChangeEventWithLock locks the QChangeArbiter's mutex
// while d->m_observerLock is locked by the locker right above.
@@ -321,6 +249,108 @@ void QNode::notifyObservers(const QSceneChangePtr &change)
changeArbiter->sceneChangeEventWithLock(change);
}
+// Inserts this tree into the main Scene tree.
+// Needed when SceneLoaders provide a cloned tree from the backend
+// and need to insert it in the main scene tree
+// QNode *root;
+// QNode *subtree;
+// QNodePrivate::get(root)->insertTree(subtree);
+
+void QNodePrivate::insertTree(QNode *treeRoot, int depth)
+{
+ if (m_scene != Q_NULLPTR) {
+ treeRoot->d_func()->setScene(m_scene);
+ m_scene->addObservable(treeRoot);
+ }
+
+ Q_FOREACH (QObject *c, treeRoot->children()) {
+ QNode *n = Q_NULLPTR;
+ if ((n = qobject_cast<QNode *>(c)) != Q_NULLPTR)
+ insertTree(n, depth + 1);
+ }
+
+ if (depth == 0)
+ treeRoot->setParent(q_ptr);
+}
+
+QNodePrivate *QNodePrivate::get(QNode *q)
+{
+ return q->d_func();
+}
+
+void QNodePrivate::nodePtrDeleter(QNode *q)
+{
+ QObject *p = q->parent();
+ if (p == Q_NULLPTR)
+ p = q;
+ p->deleteLater();
+}
+
+QNode::QNode(QNode *parent)
+ : QObject(*new QNodePrivate(this), parent)
+{
+ // We rely on QEvent::childAdded to be triggered on the parent
+ // So we don't actually need to invoke a method or anything
+ // to add ourselve with the parent
+}
+
+QNode::QNode(QNodePrivate &dd, QNode *parent)
+ : QObject(dd, parent)
+{
+}
+
+void QNode::copy(const QNode *ref)
+{
+ if (ref != Q_NULLPTR)
+ d_func()->copy(QNodePrivate::get(const_cast<QNode *>(ref)));
+}
+
+QNode::~QNode()
+{
+}
+
+const QUuid QNode::uuid() const
+{
+ Q_D(const QNode);
+ return d->m_uuid;
+}
+
+QNode *QNode::parentNode() const
+{
+ return qobject_cast<QNode*>(parent());
+}
+
+bool QNode::event(QEvent *e)
+{
+ Q_D(QNode);
+
+ switch (e->type()) {
+
+ case QEvent::ChildAdded: {
+ QNode *childNode = qobject_cast<QNode *>(static_cast<QChildEvent *>(e)->child());
+ if (childNode != Q_NULLPTR) {
+ d->addChild(childNode);
+ }
+ break;
+ }
+
+ case QEvent::ChildRemoved: {
+ QNode *childNode = qobject_cast<QNode *>(static_cast<QChildEvent *>(e)->child());
+ if (childNode != Q_NULLPTR) {
+ d->removeChild(childNode);
+ }
+ break;
+ }
+
+ default:
+ break;
+
+ } // switch
+
+ return QObject::event(e);
+}
+
} // namespace Qt3D
+
QT_END_NAMESPACE
diff --git a/src/core/nodes/qnode.h b/src/core/nodes/qnode.h
index 8d80e0d35..239f3cef0 100644
--- a/src/core/nodes/qnode.h
+++ b/src/core/nodes/qnode.h
@@ -44,11 +44,8 @@
#include <QObject>
#include <Qt3DCore/qt3dcore_global.h>
-#include <Qt3DCore/qobservableinterface.h>
-#include <Qt3DCore/qchangearbiter.h>
-
-#include <QReadWriteLock>
#include <QUuid>
+#include <Qt3DCore/qscenechange.h>
QT_BEGIN_NAMESPACE
@@ -63,48 +60,29 @@ class QSceneInterface;
typedef QList<QNode *> NodeList;
typedef QSharedPointer<QNode> QNodePtr;
-class QT3DCORESHARED_EXPORT QNode : public QObject, public QObservableInterface
+class QT3DCORESHARED_EXPORT QNode : public QObject
{
Q_OBJECT
-
public:
explicit QNode(QNode *parent = 0);
~QNode();
- void dump();
-
const QUuid uuid() const;
-
- NodeList children() const;
- void addChild(QNode *childNode);
- void removeChild(QNode *childNode);
-
- QNode *clone(bool isClone = true);
- virtual void copy(const QNode *ref);
-
- bool isClone() const;
-
- void removeAllChildren();
-
- virtual QEntity* asEntity();
-
QNode *parentNode() const;
- void registerObserver(QObserverInterface *observer) Q_DECL_OVERRIDE;
- void unregisterObserver(QObserverInterface *observer) Q_DECL_OVERRIDE;
-
- virtual void sceneChangeEvent(const QSceneChangePtr &change);
-
- void setScene(QSceneInterface *scene);
- QSceneInterface *scene() const;
-
protected:
- void notifyPropertyChange(const QByteArray &name, const QVariant &value);
- virtual void notifyObservers(const QSceneChangePtr &change);
- virtual QNode *doClone(bool isClone = true) const = 0;
+ QNode(QNodePrivate &dd, QNode *parent = 0);
+ virtual void copy(const QNode *ref);
+ virtual void sceneChangeEvent(const QSceneChangePtr &change);
+ bool event(QEvent *e) Q_DECL_OVERRIDE;
+private:
Q_DECLARE_PRIVATE(QNode)
- QNode(QNodePrivate &dd, QNode *parent = 0);
+ virtual QNode *doClone() const = 0;
+
+ friend class QAspectEngine;
+ friend class QPostman;
+ friend class QScene;
};
} // namespace Qt3D
diff --git a/src/core/nodes/qnode_p.h b/src/core/nodes/qnode_p.h
index f6c7749e3..8bebd7bd6 100644
--- a/src/core/nodes/qnode_p.h
+++ b/src/core/nodes/qnode_p.h
@@ -42,9 +42,12 @@
#ifndef QT3D_QNODE_P_H
#define QT3D_QNODE_P_H
-#include <Qt3DCore/qt3dcore_global.h>
#include <private/qobject_p.h>
+#include <QReadWriteLock>
+#include <Qt3DCore/qt3dcore_global.h>
#include <Qt3DCore/qnode.h>
+#include <Qt3DCore/qobservableinterface.h>
+#include <Qt3DCore/qchangearbiter.h>
QT_BEGIN_NAMESPACE
@@ -53,14 +56,29 @@ namespace Qt3D {
class QNode;
class QAspectEngine;
-class QT3DCORESHARED_EXPORT QNodePrivate : public QObjectPrivate
+class QT3DCORESHARED_EXPORT QNodePrivate : public QObjectPrivate, public QObservableInterface
{
public:
QNodePrivate(QNode *qq);
- Q_DECLARE_PUBLIC(QNode)
+ // Clone should only be made in the main thread
+ QNode *clone();
+
+ virtual void copy(const QNodePrivate *ref);
+
+
+ void setScene(QSceneInterface *scene);
+ QSceneInterface *scene() const;
+
+ void registerObserver(QObserverInterface *observer) Q_DECL_OVERRIDE;
+ void unregisterObserver(QObserverInterface *observer) Q_DECL_OVERRIDE;
- NodeList m_children;
+ void notifyPropertyChange(const QByteArray &name, const QVariant &value);
+ virtual void notifyObservers(const QSceneChangePtr &change);
+
+ void insertTree(QNode *treeRoot, int depth = 0);
+
+ Q_DECLARE_PUBLIC(QNode)
// For now this just protects access to the m_changeArbiter.
// Later on we may decide to extend support for multiple observers.
@@ -68,7 +86,16 @@ public:
QChangeArbiter *m_changeArbiter;
QSceneInterface *m_scene;
mutable QUuid m_uuid;
- bool m_isClone;
+
+ static QNodePrivate *get(QNode *q);
+ static void nodePtrDeleter(QNode *q);
+
+private:
+ void addChild(QNode *childNode);
+ void removeChild(QNode *childNode);
+ void removeAllChildren();
+
+ static QHash<QUuid, QNode *> m_clonesLookupTable;
};
} // namespace Qt3D
diff --git a/src/core/qpostman.cpp b/src/core/qpostman.cpp
index 9a2272baf..027a372a3 100644
--- a/src/core/qpostman.cpp
+++ b/src/core/qpostman.cpp
@@ -45,6 +45,7 @@
#include <Qt3DCore/qbackendscenepropertychange.h>
#include <Qt3DCore/qscene.h>
#include <Qt3DCore/qnode.h>
+#include <Qt3DCore/private/qnode_p.h>
QT_BEGIN_NAMESPACE
diff --git a/src/core/qscene.cpp b/src/core/qscene.cpp
index 4715cb961..458633135 100644
--- a/src/core/qscene.cpp
+++ b/src/core/qscene.cpp
@@ -44,6 +44,8 @@
#include <QReadLocker>
#include <Qt3DCore/qnode.h>
#include <Qt3DCore/qchangearbiter.h>
+#include <Qt3DCore/qobservableinterface.h>
+#include <Qt3DCore/private/qnode_p.h>
QT_BEGIN_NAMESPACE
@@ -94,7 +96,7 @@ void QScene::addObservable(QNode *observable)
QWriteLocker lock(&d->m_lock);
d->m_nodeLookupTable.insert(observable->uuid(), observable);
if (d->m_arbiter != Q_NULLPTR)
- observable->registerObserver(d->m_arbiter);
+ observable->d_func()->registerObserver(d->m_arbiter);
}
}
@@ -125,7 +127,7 @@ void QScene::removeObservable(QNode *observable)
d->m_observablesLookupTable.remove(nodeUuid);
d->m_nodeLookupTable.remove(nodeUuid);
if (d->m_arbiter != Q_NULLPTR)
- observable->unregisterObserver(d->m_arbiter);
+ observable->d_func()->unregisterObserver(d->m_arbiter);
}
}
@@ -179,24 +181,6 @@ void QScene::removeEntityForComponent(const QUuid &componentUuid, const QUuid &e
d->m_componentToEntities.remove(componentUuid, entityUuid);
}
-QNode *QScene::lookupClone(const QUuid &id) const
-{
- Q_D(const QScene);
- return d->m_clonesLookupTable.value(id);
-}
-
-void QScene::addCloneLookup(QNode *clone)
-{
- Q_D(QScene);
- d->m_clonesLookupTable.insert(clone->uuid(), clone);
-}
-
-void QScene::clearCloneLookup()
-{
- Q_D(QScene);
- d->m_clonesLookupTable.clear();
-}
-
} // Qt3D
QT_END_NAMESPACE
diff --git a/src/core/qscene.h b/src/core/qscene.h
index fd4c1977c..e3b1296c7 100644
--- a/src/core/qscene.h
+++ b/src/core/qscene.h
@@ -62,8 +62,10 @@ public:
void removeObservable(QObservableInterface *observable, const QUuid &uuid) Q_DECL_OVERRIDE;
void removeObservable(QNode *observable) Q_DECL_OVERRIDE;
QObservableList lookupObservables(const QUuid &uuid) const Q_DECL_OVERRIDE;
+
QNode *lookupNode(const QUuid &uuid) const Q_DECL_OVERRIDE;
QUuid nodeIdFromObservable(QObservableInterface *observable) const Q_DECL_OVERRIDE;
+
void setArbiter(QChangeArbiter *arbiter) Q_DECL_OVERRIDE;
// Component -> Entities
@@ -71,11 +73,6 @@ public:
void addEntityForComponent(const QUuid &componentUuid, const QUuid &entityUuid) Q_DECL_OVERRIDE;
void removeEntityForComponent(const QUuid &componentUuid, const QUuid &entityUuid) Q_DECL_OVERRIDE;
- // QNode -> QNode *children
- QNode *lookupClone(const QUuid &id) const Q_DECL_OVERRIDE;
- void addCloneLookup(QNode *clone) Q_DECL_OVERRIDE;
- void clearCloneLookup() Q_DECL_OVERRIDE;
-
private:
Q_DECLARE_PRIVATE(QScene)
QScenePrivate *d_ptr;
diff --git a/src/core/qsceneinterface.h b/src/core/qsceneinterface.h
index ea5b8e729..2a1f2dd3f 100644
--- a/src/core/qsceneinterface.h
+++ b/src/core/qsceneinterface.h
@@ -74,10 +74,6 @@ public:
virtual QList<QUuid> entitiesForComponent(const QUuid &componentUuid) const = 0;
virtual void addEntityForComponent(const QUuid &componentUuid, const QUuid &entityUuid) = 0;
virtual void removeEntityForComponent(const QUuid &componentUuid, const QUuid &entityUuid) = 0;
-
- virtual QNode *lookupClone(const QUuid &id) const = 0;
- virtual void addCloneLookup(QNode *clone) = 0;
- virtual void clearCloneLookup() = 0;
};
} // Qt3D
diff --git a/src/core/transforms/qabstracttransform.h b/src/core/transforms/qabstracttransform.h
index de5e16ed2..c0a2bd593 100644
--- a/src/core/transforms/qabstracttransform.h
+++ b/src/core/transforms/qabstracttransform.h
@@ -65,9 +65,12 @@ public:
virtual QMatrix4x4 transformMatrix() const = 0;
Q_SIGNALS:
void transformMatrixChanged();
+
protected:
- Q_DECLARE_PRIVATE(QAbstractTransform)
QAbstractTransform(QAbstractTransformPrivate &dd, QNode *parent = 0);
+
+private:
+ Q_DECLARE_PRIVATE(QAbstractTransform)
};
} // namespace Qt3D
diff --git a/src/core/transforms/qabstracttransform_p.h b/src/core/transforms/qabstracttransform_p.h
index d296ef233..0f44dc823 100644
--- a/src/core/transforms/qabstracttransform_p.h
+++ b/src/core/transforms/qabstracttransform_p.h
@@ -44,6 +44,7 @@
#include <private/qnode_p.h>
#include <Qt3DCore/qt3dcore_global.h>
+#include <Qt3DCore/qabstracttransform.h>
QT_BEGIN_NAMESPACE
diff --git a/src/core/transforms/qlookattransform.cpp b/src/core/transforms/qlookattransform.cpp
index ebd3298ac..b80d52ae3 100644
--- a/src/core/transforms/qlookattransform.cpp
+++ b/src/core/transforms/qlookattransform.cpp
@@ -57,18 +57,15 @@ QLookAtTransform::QLookAtTransform(QNode *parent)
{
}
-void QLookAtTransform::copy(const QNode *ref)
+void QLookAtTransformPrivate::copy(const QNodePrivate *ref)
{
- Q_D(QLookAtTransform);
- QAbstractTransform::copy(ref);
- const QLookAtTransform *transform = qobject_cast<const QLookAtTransform *>(ref);
- if (transform != Q_NULLPTR) {
- d->m_matrix = transformMatrix();
- d->m_position = position();
- d->m_upVector = upVector();
- d->m_viewCenter = viewCenter();
- d->m_viewVector = viewVector();
- }
+ QAbstractTransformPrivate::copy(ref);
+ const QLookAtTransformPrivate *transform = static_cast<const QLookAtTransformPrivate *>(ref);
+ m_matrix = transform->m_matrix;
+ m_position = transform->m_position;
+ m_upVector = transform->m_upVector;
+ m_viewCenter = transform->m_viewCenter;
+ m_viewVector = transform->m_viewVector;
}
QLookAtTransform::QLookAtTransform(QLookAtTransformPrivate &dd, QNode *parent)
@@ -76,11 +73,11 @@ QLookAtTransform::QLookAtTransform(QLookAtTransformPrivate &dd, QNode *parent)
{
}
-QLookAtTransform *QLookAtTransform::doClone(bool isClone) const
+QLookAtTransform *QLookAtTransform::doClone() const
{
+ Q_D(const QLookAtTransform);
QLookAtTransform *clone = new QLookAtTransform();
- clone->copy(this);
- clone->d_func()->m_isClone = isClone;
+ clone->d_func()->copy(d);
return clone;
}
diff --git a/src/core/transforms/qlookattransform.h b/src/core/transforms/qlookattransform.h
index 2707a1498..be04784cc 100644
--- a/src/core/transforms/qlookattransform.h
+++ b/src/core/transforms/qlookattransform.h
@@ -64,7 +64,6 @@ class QT3DCORESHARED_EXPORT QLookAtTransform : public Qt3D::QAbstractTransform
public:
explicit QLookAtTransform(QNode *parent = 0);
- void copy(const QNode *ref) Q_DECL_OVERRIDE;
QMatrix4x4 transformMatrix() const Q_DECL_OVERRIDE;
void setPosition(const QVector3D &position);
@@ -88,7 +87,7 @@ Q_SIGNALS:
protected:
Q_DECLARE_PRIVATE(QLookAtTransform)
QLookAtTransform(QLookAtTransformPrivate &dd, QNode *parent = 0);
- QLookAtTransform *doClone(bool isClone = true) const Q_DECL_OVERRIDE;
+ QLookAtTransform *doClone() const Q_DECL_OVERRIDE;
};
} // namespace Qt3D
diff --git a/src/core/transforms/qlookattransform_p.h b/src/core/transforms/qlookattransform_p.h
index e5f480ba0..f377afabc 100644
--- a/src/core/transforms/qlookattransform_p.h
+++ b/src/core/transforms/qlookattransform_p.h
@@ -54,6 +54,9 @@ public :
QLookAtTransformPrivate(QLookAtTransform *qq);
Q_DECLARE_PUBLIC(QLookAtTransform)
+
+ void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE;
+
mutable QMatrix4x4 m_matrix;
QVector3D m_position;
QVector3D m_upVector;
diff --git a/src/core/transforms/qmatrixtransform.cpp b/src/core/transforms/qmatrixtransform.cpp
index 024f03ee9..313dcf551 100644
--- a/src/core/transforms/qmatrixtransform.cpp
+++ b/src/core/transforms/qmatrixtransform.cpp
@@ -56,11 +56,17 @@ QMatrixTransform::QMatrixTransform(QMatrixTransformPrivate &dd, QNode *parent)
{
}
-QMatrixTransform *QMatrixTransform::doClone(bool isClone) const
+void QMatrixTransformPrivate::copy(const QNodePrivate *ref)
+{
+ QAbstractTransformPrivate::copy(ref);
+ const QMatrixTransformPrivate *matrix = static_cast<const QMatrixTransformPrivate *>(ref);
+ m_matrix = matrix->m_matrix;
+}
+
+QMatrixTransform *QMatrixTransform::doClone() const
{
QMatrixTransform *clone = new QMatrixTransform();
- clone->copy(this);
- clone->d_func()->m_isClone = isClone;
+ clone->d_func()->copy(d_func());
return clone;
}
@@ -97,16 +103,6 @@ QMatrix4x4 QMatrixTransform::transformMatrix() const
return matrix();
}
-void QMatrixTransform::copy(const QNode *ref)
-{
- Q_D(QMatrixTransform);
- QAbstractTransform::copy(ref);
- const QMatrixTransform *matrix = qobject_cast<const QMatrixTransform *>(ref);
- if (ref != Q_NULLPTR) {
- d->m_matrix = matrix->matrix();
- }
-}
-
} // namespace Qt3D
QT_END_NAMESPACE
diff --git a/src/core/transforms/qmatrixtransform.h b/src/core/transforms/qmatrixtransform.h
index e8fba4aef..e0063c70c 100644
--- a/src/core/transforms/qmatrixtransform.h
+++ b/src/core/transforms/qmatrixtransform.h
@@ -61,8 +61,6 @@ public:
explicit QMatrixTransform(QNode *parent = 0);
QMatrixTransform(const QMatrix4x4& m, QNode *parent = 0);
- void copy(const QNode *ref) Q_DECL_OVERRIDE;
-
QMatrix4x4 matrix() const;
void setMatrix(const QMatrix4x4 &matrix);
@@ -74,7 +72,7 @@ Q_SIGNALS:
protected:
Q_DECLARE_PRIVATE(QMatrixTransform)
QMatrixTransform(QMatrixTransformPrivate &dd, QNode *parent = 0);
- QMatrixTransform *doClone(bool isClone = true) const Q_DECL_OVERRIDE;
+ QMatrixTransform *doClone() const Q_DECL_OVERRIDE;
};
} // namespace Qt3D
diff --git a/src/core/transforms/qmatrixtransform_p.h b/src/core/transforms/qmatrixtransform_p.h
index 7be1e972a..fc0ad3a96 100644
--- a/src/core/transforms/qmatrixtransform_p.h
+++ b/src/core/transforms/qmatrixtransform_p.h
@@ -55,6 +55,8 @@ class QMatrixTransformPrivate : public QAbstractTransformPrivate
public:
QMatrixTransformPrivate(QMatrixTransform *qq);
+ void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE;
+
Q_DECLARE_PUBLIC(QMatrixTransform)
QMatrix4x4 m_matrix;
};
diff --git a/src/core/transforms/qrotatetransform.cpp b/src/core/transforms/qrotatetransform.cpp
index 8adb620fb..b7a939729 100644
--- a/src/core/transforms/qrotatetransform.cpp
+++ b/src/core/transforms/qrotatetransform.cpp
@@ -60,20 +60,17 @@ QRotateTransformPrivate::QRotateTransformPrivate(QRotateTransform *qq)
{
}
-QRotateTransform::QRotateTransform(QNode *parent)
- : QAbstractTransform(*new QRotateTransformPrivate(this), parent)
+void QRotateTransformPrivate::copy(const QNodePrivate *ref)
{
+ QAbstractTransformPrivate::copy(ref);
+ const QRotateTransformPrivate *transform = static_cast<const QRotateTransformPrivate *>(ref);
+ m_axis = transform->m_axis;
+ m_angleDeg = transform->m_angleDeg;
}
-void QRotateTransform::copy(const QNode *ref)
+QRotateTransform::QRotateTransform(QNode *parent)
+ : QAbstractTransform(*new QRotateTransformPrivate(this), parent)
{
- Q_D(QRotateTransform);
- QAbstractTransform::copy(ref);
- const QRotateTransform *transform = qobject_cast<const QRotateTransform *>(ref);
- if (ref != Q_NULLPTR) {
- d->m_axis = transform->axis();
- d->m_angleDeg = transform->angleDeg();
- }
}
QRotateTransform::QRotateTransform(QRotateTransformPrivate &dd, QNode *parent)
@@ -81,11 +78,10 @@ QRotateTransform::QRotateTransform(QRotateTransformPrivate &dd, QNode *parent)
{
}
-QRotateTransform *QRotateTransform::doClone(bool isClone) const
+QRotateTransform *QRotateTransform::doClone() const
{
QRotateTransform *clone = new QRotateTransform();
- clone->copy(this);
- clone->d_func()->m_isClone = isClone;
+ clone->d_func()->copy(d_func());
return clone;
}
diff --git a/src/core/transforms/qrotatetransform.h b/src/core/transforms/qrotatetransform.h
index 1c6bea033..4416c5c24 100644
--- a/src/core/transforms/qrotatetransform.h
+++ b/src/core/transforms/qrotatetransform.h
@@ -63,8 +63,6 @@ class QT3DCORESHARED_EXPORT QRotateTransform : public QAbstractTransform
public:
explicit QRotateTransform(QNode *parent = 0);
- void copy(const QNode *ref) Q_DECL_OVERRIDE;
-
float angleDeg() const;
float angleRad() const;
QVector3D axis() const;
@@ -80,9 +78,11 @@ Q_SIGNALS:
void angleChanged();
protected:
- Q_DECLARE_PRIVATE(QRotateTransform)
QRotateTransform(QRotateTransformPrivate &dd, QNode *parent = 0);
- QRotateTransform *doClone(bool isClone = true) const Q_DECL_OVERRIDE;
+
+private:
+ Q_DECLARE_PRIVATE(QRotateTransform)
+ QRotateTransform *doClone() const Q_DECL_OVERRIDE;
};
} // namespace Qt3D
diff --git a/src/core/transforms/qrotatetransform_p.h b/src/core/transforms/qrotatetransform_p.h
index e4e2cf9df..765fb5ba0 100644
--- a/src/core/transforms/qrotatetransform_p.h
+++ b/src/core/transforms/qrotatetransform_p.h
@@ -57,6 +57,8 @@ public:
Q_DECLARE_PUBLIC(QRotateTransform)
+ void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE;
+
float m_angleDeg;
QVector3D m_axis;
};
diff --git a/src/core/transforms/qscaletransform.cpp b/src/core/transforms/qscaletransform.cpp
index 60d711db6..a2cb02358 100644
--- a/src/core/transforms/qscaletransform.cpp
+++ b/src/core/transforms/qscaletransform.cpp
@@ -53,19 +53,16 @@ QScaleTransformPrivate::QScaleTransformPrivate(QScaleTransform *qq)
{
}
-QScaleTransform::QScaleTransform(QNode *parent) :
- QAbstractTransform(*new QScaleTransformPrivate(this), parent)
+void QScaleTransformPrivate::copy(const QNodePrivate *ref)
{
+ QAbstractTransformPrivate::copy(ref);
+ const QScaleTransformPrivate *transform = static_cast<const QScaleTransformPrivate *>(ref);
+ m_scale3D = transform->m_scale3D;
}
-void QScaleTransform::copy(const QNode *ref)
+QScaleTransform::QScaleTransform(QNode *parent) :
+ QAbstractTransform(*new QScaleTransformPrivate(this), parent)
{
- Q_D(QScaleTransform);
- QAbstractTransform::copy(ref);
- const QScaleTransform *transform = qobject_cast<const QScaleTransform *>(ref);
- if (ref != Q_NULLPTR) {
- d->m_scale3D = transform->scale3D();
- }
}
QScaleTransform::QScaleTransform(QScaleTransformPrivate &dd, QNode *parent)
@@ -73,11 +70,10 @@ QScaleTransform::QScaleTransform(QScaleTransformPrivate &dd, QNode *parent)
{
}
-QScaleTransform *QScaleTransform::doClone(bool isClone) const
+QScaleTransform *QScaleTransform::doClone() const
{
QScaleTransform *clone = new QScaleTransform();
- clone->copy(this);
- clone->d_func()->m_isClone = isClone;
+ clone->d_func()->copy(d_func());
return clone;
}
diff --git a/src/core/transforms/qscaletransform.h b/src/core/transforms/qscaletransform.h
index 2b6cfd96e..7bd2ccb9b 100644
--- a/src/core/transforms/qscaletransform.h
+++ b/src/core/transforms/qscaletransform.h
@@ -59,8 +59,6 @@ class QT3DCORESHARED_EXPORT QScaleTransform : public QAbstractTransform
public:
explicit QScaleTransform(QNode *parent = 0);
- void copy(const QNode *ref) Q_DECL_OVERRIDE;
-
QVector3D scale3D() const;
void setScale3D(const QVector3D &scale3D);
@@ -74,9 +72,11 @@ Q_SIGNALS:
void scaleChanged();
protected:
- Q_DECLARE_PRIVATE(QScaleTransform)
QScaleTransform(QScaleTransformPrivate &dd, QNode *parent = 0);
- QScaleTransform *doClone(bool isClone = true) const Q_DECL_OVERRIDE;
+
+private:
+ Q_DECLARE_PRIVATE(QScaleTransform)
+ QScaleTransform *doClone() const Q_DECL_OVERRIDE;
};
} // Qt3D
diff --git a/src/core/transforms/qscaletransform_p.h b/src/core/transforms/qscaletransform_p.h
index c631b6b54..63f6afa62 100644
--- a/src/core/transforms/qscaletransform_p.h
+++ b/src/core/transforms/qscaletransform_p.h
@@ -54,6 +54,8 @@ class QScaleTransformPrivate : public QAbstractTransformPrivate
public:
QScaleTransformPrivate(QScaleTransform *qq);
+ void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE;
+
Q_DECLARE_PUBLIC(QScaleTransform)
QVector3D m_scale3D;
};
diff --git a/src/core/transforms/qtransform.cpp b/src/core/transforms/qtransform.cpp
index be83559e0..92b9390ea 100644
--- a/src/core/transforms/qtransform.cpp
+++ b/src/core/transforms/qtransform.cpp
@@ -41,6 +41,7 @@
#include "qtransform.h"
#include "qtransform_p.h"
+#include "qabstracttransform_p.h"
#include <Qt3DCore/qscenepropertychange.h>
#include <qmatrixtransform.h>
@@ -57,6 +58,13 @@ QTransformPrivate::QTransformPrivate(QTransform *qq)
{
}
+void QTransformPrivate::copy(const QNodePrivate *ref)
+{
+ QComponentPrivate::copy(ref);
+ const QTransformPrivate *transform = static_cast<const QTransformPrivate *>(ref);
+ m_matrix = transform->m_matrix;
+}
+
QTransform::QTransform(QNode *parent)
: Qt3D::QComponent(*new QTransformPrivate(this), parent)
{
@@ -81,28 +89,18 @@ QTransform::QTransform(QAbstractTransform *transform, QNode *parent)
appendTransform(transform);
}
-void QTransform::copy(const QNode *ref)
-{
- Q_D(QTransform);
- QComponent::copy(ref);
- const QTransform *transform = qobject_cast<const QTransform *>(ref);
- if (transform != Q_NULLPTR) {
- d->m_matrix = transform->matrix();
- emit matrixChanged();
- }
-}
-
QTransform::QTransform(QTransformPrivate &dd, QNode *parent)
: QComponent(dd, parent)
{
}
-QTransform *QTransform::doClone(bool isClone) const
+QTransform *QTransform::doClone() const
{
Q_D(const QTransform);
QTransform *clone = new QTransform();
+ clone->d_func()->copy(d_func());
Q_FOREACH (QAbstractTransform *t, d->m_transforms)
- clone->appendTransform(qobject_cast<QAbstractTransform *>(t->clone()));
+ clone->appendTransform(qobject_cast<QAbstractTransform *>(QNodePrivate::get(t)->clone()));
return clone;
}
@@ -115,7 +113,7 @@ void QTransform::setTransformsDirty()
QScenePropertyChangePtr e(new QScenePropertyChange(ComponentUpdated, this));
e->setPropertyName(QByteArrayLiteral("matrix"));
e->setValue(matrix());
- notifyObservers(e);
+ d->notifyObservers(e);
}
}
emit matrixChanged();
diff --git a/src/core/transforms/qtransform.h b/src/core/transforms/qtransform.h
index 8cf18a4da..ea58e15d0 100644
--- a/src/core/transforms/qtransform.h
+++ b/src/core/transforms/qtransform.h
@@ -64,8 +64,6 @@ public:
QTransform(QList<QAbstractTransform *> transforms, QNode *parent = 0);
QTransform(QAbstractTransform *transform, QNode *parent = 0);
- void copy(const QNode *ref) Q_DECL_OVERRIDE;
-
QMatrix4x4 matrix() const;
void setMatrix(const QMatrix4x4 &m);
@@ -96,10 +94,11 @@ Q_SIGNALS:
protected:
QMatrix4x4 applyTransforms() const;
QList<QAbstractTransform *> transformList() const;
+ QTransform(QTransformPrivate &dd, QNode *parent = 0);
+private:
Q_DECLARE_PRIVATE(QTransform)
- QTransform(QTransformPrivate &dd, QNode *parent = 0);
- QTransform *doClone(bool isClone = true) const Q_DECL_OVERRIDE;
+ QTransform *doClone() const Q_DECL_OVERRIDE;
};
} // namespace Qt3D
diff --git a/src/core/transforms/qtransform_p.h b/src/core/transforms/qtransform_p.h
index ebd490fe0..f8b03dfb1 100644
--- a/src/core/transforms/qtransform_p.h
+++ b/src/core/transforms/qtransform_p.h
@@ -56,6 +56,8 @@ class QTransformPrivate : public QComponentPrivate
public:
QTransformPrivate(QTransform *qq);
+ void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE;
+
Q_DECLARE_PUBLIC(QTransform)
mutable QAtomicInt m_transformsDirty;
diff --git a/src/core/transforms/qtranslatetransform.cpp b/src/core/transforms/qtranslatetransform.cpp
index 0440fa690..0697fad89 100644
--- a/src/core/transforms/qtranslatetransform.cpp
+++ b/src/core/transforms/qtranslatetransform.cpp
@@ -57,14 +57,11 @@ QTranslateTransform::QTranslateTransform(QNode *parent)
{
}
-void QTranslateTransform::copy(const QNode *ref)
+void QTranslateTransformPrivate::copy(const QNodePrivate *ref)
{
- Q_D(QTranslateTransform);
- QAbstractTransform::copy(ref);
- const QTranslateTransform *transform = qobject_cast<const QTranslateTransform *>(ref);
- if (transform != Q_NULLPTR) {
- d->m_translation = transform->translation();
- }
+ QAbstractTransformPrivate::copy(ref);
+ const QTranslateTransformPrivate *transform = static_cast<const QTranslateTransformPrivate *>(ref);
+ m_translation = transform->m_translation;
}
@@ -73,11 +70,10 @@ QTranslateTransform::QTranslateTransform(QTranslateTransformPrivate &dd, QNode *
{
}
-QTranslateTransform *QTranslateTransform::doClone(bool isClone) const
+QTranslateTransform *QTranslateTransform::doClone() const
{
QTranslateTransform *clone = new QTranslateTransform();
- clone->copy(this);
- clone->d_func()->m_isClone = isClone;
+ clone->d_func()->copy(d_func());
return clone;
}
diff --git a/src/core/transforms/qtranslatetransform.h b/src/core/transforms/qtranslatetransform.h
index 6994a05b1..e64ba3c15 100644
--- a/src/core/transforms/qtranslatetransform.h
+++ b/src/core/transforms/qtranslatetransform.h
@@ -65,8 +65,6 @@ class QT3DCORESHARED_EXPORT QTranslateTransform : public QAbstractTransform
public:
explicit QTranslateTransform(QNode *parent = 0);
- void copy(const QNode *ref) Q_DECL_OVERRIDE;
-
float dx() const;
float dy() const;
float dz() const;
@@ -86,9 +84,11 @@ Q_SIGNALS:
void translateChanged();
protected:
- Q_DECLARE_PRIVATE(QTranslateTransform)
QTranslateTransform(QTranslateTransformPrivate &dd, QNode *parent = 0);
- QTranslateTransform *doClone(bool isClone) const Q_DECL_OVERRIDE;
+
+private:
+ Q_DECLARE_PRIVATE(QTranslateTransform)
+ QTranslateTransform *doClone() const Q_DECL_OVERRIDE;
};
} // namespace Qt3D
diff --git a/src/core/transforms/qtranslatetransform_p.h b/src/core/transforms/qtranslatetransform_p.h
index 4c942c644..18a8d3d7e 100644
--- a/src/core/transforms/qtranslatetransform_p.h
+++ b/src/core/transforms/qtranslatetransform_p.h
@@ -55,6 +55,8 @@ public:
QTranslateTransformPrivate(QTranslateTransform *qq);
Q_DECLARE_PUBLIC(QTranslateTransform)
+ void copy(const QNodePrivate *ref) Q_DECL_OVERRIDE;
+
QVector3D m_translation;
};