summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2016-04-12 15:23:26 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2016-04-23 11:14:34 +0000
commit6d508fa954a2d90e90dff5a2e509aecd13b18f8f (patch)
tree32c788c4c637d6c9660706fc652f6515da3b4559 /src/core
parent0542f1614aa6d50c4c9809fb0ce5f1adb5666d67 (diff)
QNode: make cleanup a private slot
QT3D_CLONEABLE now implements a default dtor that calls _q_ cleanup QT3D_CLONEABLE_CUSTOM_DTOR is used for classes that really need to implement their own dtor but they need to invoke _q_cleanup manually Change-Id: I2937a3b9edeb5a763749f0044360d78ab4461a5e Task-number: QTBUG-51464 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/nodes/qentity.cpp2
-rw-r--r--src/core/nodes/qentity.h2
-rw-r--r--src/core/nodes/qnode.cpp42
-rw-r--r--src/core/nodes/qnode.h15
-rw-r--r--src/core/nodes/qnode_p.h1
-rw-r--r--src/core/transforms/qtransform.cpp8
-rw-r--r--src/core/transforms/qtransform.h1
7 files changed, 38 insertions, 33 deletions
diff --git a/src/core/nodes/qentity.cpp b/src/core/nodes/qentity.cpp
index 5dd88680c..2e84e9d69 100644
--- a/src/core/nodes/qentity.cpp
+++ b/src/core/nodes/qentity.cpp
@@ -98,7 +98,7 @@ QEntity::~QEntity()
for (QComponent *comp : components)
removeComponent(comp);
- QNode::cleanup();
+ QMetaObject::invokeMethod(this, "_q_cleanup", Qt::DirectConnection);
// If all children are removed
// That includes the components that are parented by this entity
diff --git a/src/core/nodes/qentity.h b/src/core/nodes/qentity.h
index a84758857..0560ae256 100644
--- a/src/core/nodes/qentity.h
+++ b/src/core/nodes/qentity.h
@@ -74,7 +74,7 @@ protected:
private:
Q_DECLARE_PRIVATE(QEntity)
- QT3D_CLONEABLE(QEntity)
+ QT3D_CLONEABLE_CUSTOM_DTOR(QEntity)
QNodeCreatedChangeBasePtr createNodeCreationChange() const Q_DECL_OVERRIDE;
};
diff --git a/src/core/nodes/qnode.cpp b/src/core/nodes/qnode.cpp
index f144bb6a5..9f31630a6 100644
--- a/src/core/nodes/qnode.cpp
+++ b/src/core/nodes/qnode.cpp
@@ -191,6 +191,28 @@ void QNodePrivate::_q_removeChild(QNode *childNode)
}
}
+/*!
+ * This methods can only be called once and takes care of notyfing the backend
+ * aspects that the current Qt3DCore::QNode instance is about to be destroyed.
+ *
+ * \note It must be called by the destructor of every class subclassing
+ * QNode that is clonable (using the QT3D_CLONEABLE macro).
+ *
+ * \internal
+ */
+void QNodePrivate::_q_cleanup()
+{
+ if (!m_wasCleanedUp) {
+ m_wasCleanedUp = true;
+ Q_Q(QNode);
+ qCDebug(Nodes) << Q_FUNC_INFO << q;
+ if (q->parentNode())
+ QNodePrivate::get(q->parentNode())->_q_removeChild(q);
+ // Root element has no parent and therefore we cannot
+ // call parent->_q_removeChild();
+ }
+}
+
void QNodePrivate::registerNotifiedProperties()
{
Q_Q(QNode);
@@ -699,26 +721,6 @@ QNode *QNode::clone(QNode *node)
return clonedNode;
}
-/*!
- * This methods can only be called once and takes care of notyfing the backend
- * aspects that the current Qt3DCore::QNode instance is about to be destroyed.
- *
- * \note It must be called by the destructor of every class subclassing
- * QNode that is clonable (using the QT3D_CLONEABLE macro).
- */
-void QNode::cleanup()
-{
- Q_D(QNode);
- if (!d->m_wasCleanedUp) {
- d->m_wasCleanedUp = true;
- qCDebug(Nodes) << Q_FUNC_INFO << this;
- if (parentNode())
- QNodePrivate::get(parentNode())->_q_removeChild(this);
- // Root element has no parent and therefore we cannot
- // call parent->_q_removeChild();
- }
-}
-
QNodeCreatedChangeBasePtr QNode::createNodeCreationChange() const
{
// TODO: Remove the qDebug() from this default implementation
diff --git a/src/core/nodes/qnode.h b/src/core/nodes/qnode.h
index dc4736df2..cf9ec46a7 100644
--- a/src/core/nodes/qnode.h
+++ b/src/core/nodes/qnode.h
@@ -68,8 +68,20 @@ typedef QSharedPointer<QNode> QNodePtr;
Class *clone_ = Qt3DCore::QAbstractNodeFactory::createNode<Class>(QT3DCORE_QUOTE(Class)); \
clone_->copy(this); \
return clone_; \
+ } \
+ public: \
+ virtual ~Class() { \
+ QMetaObject::invokeMethod(this, "_q_cleanup", Qt::DirectConnection); \
}
+#define QT3D_CLONEABLE_CUSTOM_DTOR(Class) \
+ friend class Qt3DCore::QAbstractNodeFactory; \
+ QNode *doClone() const Q_DECL_OVERRIDE { \
+ Class *clone_ = Qt3DCore::QAbstractNodeFactory::createNode<Class>(QT3DCORE_QUOTE(Class)); \
+ clone_->copy(this); \
+ return clone_; \
+ } \
+
// Each QNode subclass should call QNode::cleanup in it dtor
// QNode::cleanup checks that a flags wasn't set to true,
// sets it to true and sends a clone to the backend
@@ -109,8 +121,6 @@ protected:
virtual void copy(const QNode *ref);
virtual void sceneChangeEvent(const QSceneChangePtr &change);
- void cleanup();
-
private:
Q_DECLARE_PRIVATE(QNode)
virtual QNode *doClone() const = 0;
@@ -123,6 +133,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_addChild(Qt3DCore::QNode *))
Q_PRIVATE_SLOT(d_func(), void _q_removeChild(Qt3DCore::QNode *))
+ Q_PRIVATE_SLOT(d_func(), void _q_cleanup())
friend class QAspectEngine;
friend class QAspectEnginePrivate;
diff --git a/src/core/nodes/qnode_p.h b/src/core/nodes/qnode_p.h
index 8fab0817a..3b0ee3773 100644
--- a/src/core/nodes/qnode_p.h
+++ b/src/core/nodes/qnode_p.h
@@ -99,6 +99,7 @@ public:
private:
void _q_addChild(QNode *childNode);
void _q_removeChild(QNode *childNode);
+ void _q_cleanup();
void registerNotifiedProperties();
void unregisterNotifiedProperties();
void propertyChanged(int propertyIndex);
diff --git a/src/core/transforms/qtransform.cpp b/src/core/transforms/qtransform.cpp
index 4b5ea1977..960cce33c 100644
--- a/src/core/transforms/qtransform.cpp
+++ b/src/core/transforms/qtransform.cpp
@@ -186,14 +186,6 @@ QTransform::QTransform(QTransformPrivate &dd, QNode *parent)
{
}
-QTransform::~QTransform()
-{
- QNode::cleanup();
-}
-
-/*!
- * Copies \a ref.
- */
void QTransform::copy(const QNode *ref)
{
QComponent::copy(ref);
diff --git a/src/core/transforms/qtransform.h b/src/core/transforms/qtransform.h
index c77217e07..e8dab0758 100644
--- a/src/core/transforms/qtransform.h
+++ b/src/core/transforms/qtransform.h
@@ -65,7 +65,6 @@ class QT3DCORESHARED_EXPORT QTransform : public QComponent
public:
explicit QTransform(QNode *parent = Q_NULLPTR);
- ~QTransform();
float scale() const;
QVector3D scale3D() const;