summaryrefslogtreecommitdiffstats
path: root/src/core/nodes/qnode_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/nodes/qnode_p.h')
-rw-r--r--src/core/nodes/qnode_p.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/core/nodes/qnode_p.h b/src/core/nodes/qnode_p.h
index 5aa4c5328..ddea912f0 100644
--- a/src/core/nodes/qnode_p.h
+++ b/src/core/nodes/qnode_p.h
@@ -54,6 +54,7 @@
#include <Qt3DCore/qnode.h>
#include <functional>
+#include <vector>
#include <Qt3DCore/private/propertychangehandler_p.h>
#include <Qt3DCore/private/qchangearbiter_p.h>
@@ -139,6 +140,24 @@ public:
m_destructionConnections.push_back({node, QObject::connect(node, &QNode::nodeDestroyed, f)});
}
+ template<typename Caller, typename NodeType>
+ void registerDestructionHelper(NodeType *node, DestructionFunctionPointer<Caller, NodeType> func, QList<NodeType*> &)
+ {
+ // If the node is destoyed, we make sure not to keep a dangling pointer to it
+ Q_Q(QNode);
+ auto f = [q, func, node]() { (static_cast<Caller *>(q)->*func)(node); };
+ m_destructionConnections.push_back({node, QObject::connect(node, &QNode::nodeDestroyed, f)});
+ }
+
+ template<typename Caller, typename NodeType>
+ void registerDestructionHelper(NodeType *node, DestructionFunctionPointer<Caller, NodeType> func, std::vector<NodeType*> &)
+ {
+ // If the node is destoyed, we make sure not to keep a dangling pointer to it
+ Q_Q(QNode);
+ auto f = [q, func, node]() { (static_cast<Caller *>(q)->*func)(node); };
+ m_destructionConnections.push_back({node, QObject::connect(node, &QNode::nodeDestroyed, f)});
+ }
+
template<typename Caller, typename ValueType>
using DestructionFunctionValue = void (Caller::*)(const ValueType&);