summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2020-09-23 10:20:12 +0200
committerMike Krus <mike.krus@kdab.com>2020-09-24 08:57:37 +0100
commitc54025b31c1fb02d325f6e78ccfb3f40504efced (patch)
treea7637fb72ef11182ed84002c87cb1ee7c71970b8 /src
parent6cd776b87fa64527429d7dafe48beb2a13868232 (diff)
Add QNodePrivate::registerDestructionHelper for std::vector containers
Ideally should support generic containers but clang seems to fail to generate the symbol on the mac. Change-Id: Ic1d6d815ab9aff60a97b3b0047228f55d7efe158 Reviewed-by: Paul Lemire <paul.lemire@kdab.com> (cherry picked from commit 5a33b94b348e5c65155b526e7746d9fe45560959)
Diffstat (limited to 'src')
-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&);