summaryrefslogtreecommitdiffstats
path: root/src/core/nodes
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2018-01-19 15:34:58 +0100
committerPaul Lemire <paul.lemire@kdab.com>2018-02-21 07:04:30 +0000
commit0fd16cf43fc94344ab7944379f3dd9645156a4fd (patch)
tree517cc1455baf02399b442173721ec97976e527b0 /src/core/nodes
parentba3c6bc0ffcbc9987eab2027102d9972de4592bb (diff)
QParameter: add bookkeeping of QNode values
Change-Id: I0a7334907e4b34df6955fb24832958b674d7b62b Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/core/nodes')
-rw-r--r--src/core/nodes/qnode_p.h21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/core/nodes/qnode_p.h b/src/core/nodes/qnode_p.h
index c203b342f..73893cc1e 100644
--- a/src/core/nodes/qnode_p.h
+++ b/src/core/nodes/qnode_p.h
@@ -108,13 +108,13 @@ public:
static void nodePtrDeleter(QNode *q);
template<typename Caller, typename NodeType>
- using DestructionFunction = void (Caller::*)(NodeType *);
+ using DestructionFunctionPointer = void (Caller::*)(NodeType *);
template<typename Caller, typename NodeType, typename PropertyType>
- void registerDestructionHelper(NodeType *, DestructionFunction<Caller, NodeType>, PropertyType);
+ void registerDestructionHelper(NodeType *, DestructionFunctionPointer<Caller, NodeType>, PropertyType);
template<typename Caller, typename NodeType>
- void registerDestructionHelper(NodeType *node, DestructionFunction<Caller, NodeType> func, NodeType *&)
+ void registerDestructionHelper(NodeType *node, DestructionFunctionPointer<Caller, NodeType> func, NodeType *&)
{
// If the node is destoyed, we make sure not to keep a dangling pointer to it
Q_Q(QNode);
@@ -123,7 +123,7 @@ public:
}
template<typename Caller, typename NodeType>
- void registerDestructionHelper(NodeType *node, DestructionFunction<Caller, NodeType> func, QVector<NodeType*> &)
+ void registerDestructionHelper(NodeType *node, DestructionFunctionPointer<Caller, NodeType> func, QVector<NodeType*> &)
{
// If the node is destoyed, we make sure not to keep a dangling pointer to it
Q_Q(QNode);
@@ -131,6 +131,19 @@ public:
m_destructionConnections.insert(node, QObject::connect(node, &QNode::nodeDestroyed, f));
}
+ template<typename Caller, typename ValueType>
+ using DestructionFunctionValue = void (Caller::*)(const ValueType&);
+
+ template<typename Caller, typename NodeType, typename ValueType>
+ void registerDestructionHelper(NodeType *node, DestructionFunctionValue<Caller, ValueType> func, NodeType *&,
+ const ValueType &resetValue)
+ {
+ // If the node is destoyed, we make sure not to keep a dangling pointer to it
+ Q_Q(QNode);
+ auto f = [q, func, resetValue]() { (static_cast<Caller *>(q)->*func)(resetValue); };
+ m_destructionConnections.insert(node, QObject::connect(node, &QNode::nodeDestroyed, f));
+ }
+
void unregisterDestructionHelper(QNode *node)
{
QObject::disconnect(m_destructionConnections.take(node));