From b1535b73b7a6d6de39086354095dab46fe8f308d Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sat, 23 Nov 2019 08:48:59 +0900 Subject: [PATCH] implemented clear() function for nodegraphs Added a convenient (destructive) way of emptying a NodeGraph completely. --- app/node/graph.cpp | 10 +++++++++- app/node/graph.h | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/node/graph.cpp b/app/node/graph.cpp index da4e9bc17..c2901ec0a 100644 --- a/app/node/graph.cpp +++ b/app/node/graph.cpp @@ -25,6 +25,14 @@ NodeGraph::NodeGraph() } +void NodeGraph::Clear() +{ + foreach (Node* node, node_children_) { + delete node; + } + node_children_.clear(); +} + void NodeGraph::AddNode(Node *node) { if (ContainsNode(node)) { @@ -91,7 +99,7 @@ QList NodeGraph::TakeNodeWithItsDependencies(Node *node, QObject *new_pa return deps; } -QList NodeGraph::nodes() +const QList &NodeGraph::nodes() { return node_children_; } diff --git a/app/node/graph.h b/app/node/graph.h index 7144be466..d7a159b94 100644 --- a/app/node/graph.h +++ b/app/node/graph.h @@ -37,6 +37,11 @@ public: */ NodeGraph(); + /** + * @brief Destructively destroys all nodes in the graph + */ + void Clear(); + /** * @brief Add a node to this graph * @@ -73,7 +78,7 @@ public: /** * @brief Retrieve a complete list of the nodes belonging to this graph */ - QList nodes(); + const QList& nodes(); /** * @brief Returns whether a certain Node is in the graph or not