From 3ed0cb2ab9992d45a4033d4ca930fba4be01bd4f Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Sun, 27 Sep 2020 01:33:31 +0100 Subject: [PATCH] Move search code to seperate function. --- .../projectexplorer/projectexplorer.cpp | 96 ++++++++++++------- app/widget/projectexplorer/projectexplorer.h | 6 ++ 2 files changed, 68 insertions(+), 34 deletions(-) diff --git a/app/widget/projectexplorer/projectexplorer.cpp b/app/widget/projectexplorer/projectexplorer.cpp index b47cbbaa7..3e216ec4b 100644 --- a/app/widget/projectexplorer/projectexplorer.cpp +++ b/app/widget/projectexplorer/projectexplorer.cpp @@ -536,6 +536,43 @@ void ProjectExplorer::DeselectAll() CurrentView()->selectionModel()->clearSelection(); } +QList ProjectExplorer::GetItemNodes(Item* item, Item::Type type) +{ + // Output list list + QList nodes; + + // Get all sequences. + QList sequences = model_.project()->get_items_of_type(Item::kSequence); + // Get item pointer. + ItemPtr item_ptr = item->get_shared_ptr(); + + if (type == Item::kFootage) { + // If no sequences exist we don't need to do anything clever here + if (!sequences.isEmpty()) { + // Footage can contain multiple streams, all of which need to be dealt with + foreach (StreamPtr stream, static_cast(item_ptr.get())->streams()) { + // Check each sequence to see if it contains the footage in question + foreach (ItemPtr seq, sequences) { + Sequence* s = static_cast(seq.get()); + + // Loop through nodes to find our Footage node + foreach (Node* node, s->nodes()) { + // Check if node is of the right type + if (node->IsMedia() && static_cast(node)->type() == stream.get()->type() || + static_cast(node)->type() == Stream::kImage) { + // Check the streams are the same + if (static_cast(node)->footage() == stream) { + nodes.append(node); + } + } + } + } + } + } + } + return nodes; +} + void ProjectExplorer::DeleteSelected() { QList selected = SelectedItems(); @@ -558,53 +595,44 @@ void ProjectExplorer::DeleteSelected() } } + // If this is a footage item, clean up if necessary if (item_ptr->type() == Item::kFootage) { - // Get all sequences - QList sequences = model_.project()->get_items_of_type(Item::kSequence); + + // Check if nodes exists + QList nodes = GetItemNodes(item, Item::kFootage); + if (!nodes.isEmpty()){ + // Loop through Footage nodes + foreach (Node* node, nodes) { - // If no sequences exist we don't need to do anything clever here - if (!sequences.isEmpty()) { - // Footage can contain multiple streams, all of which need to be dealt with - foreach (StreamPtr stream, static_cast(item_ptr.get())->streams()) { - - // Check each sequence to see if it contains the footage in question + // Loop through sequences + QList sequences = model_.project()->get_items_of_type(Item::kSequence); foreach (ItemPtr seq, sequences) { - Sequence* s = static_cast(seq.get()); - // Loop through nodes to find our Footage node - foreach (Node* node, s->nodes()) { + // Check all nodes to see if they're linked + foreach (Node* check_node, s->nodes()) { + // Skip itself + if (nodes.contains(check_node)) { + continue; + } + if (check_node->GetImmediateDependencies().contains(node)) { + QList inputs = check_node->GetInputsIncludingArrays(); - // Check if node is of the right type - if (node->IsMedia() && static_cast(node)->type() == stream.get()->type()) { - // Check the streams are the same - if (static_cast(node)->footage() == stream) { - // Loop through nodes and set any that point to the Footage node to null - foreach (Node* check_node, s->nodes()) { - // Skip itself - if (check_node == node) { - continue; - } - if (check_node->GetImmediateDependencies().contains(node)) { - QList inputs = check_node->GetInputsIncludingArrays(); + foreach (NodeInput* input, inputs) { + foreach (NodeEdgePtr edge, input->edges()) { + Node* connected = edge->output()->parentNode(); - foreach (NodeInput* input, inputs) { - foreach (NodeEdgePtr edge, input->edges()) { - Node* connected = edge->output()->parentNode(); - - if (connected == node) { - input->DisconnectEdge(edge); - } - } - } + if (connected == node) { + input->DisconnectEdge(edge); } } - static_cast(node)->SetFootage(nullptr); - break; } } } } + + // Set footage to be null + static_cast(node)->SetFootage(nullptr); } } } diff --git a/app/widget/projectexplorer/projectexplorer.h b/app/widget/projectexplorer/projectexplorer.h index 2fe097bbd..6ec2f9af9 100644 --- a/app/widget/projectexplorer/projectexplorer.h +++ b/app/widget/projectexplorer/projectexplorer.h @@ -85,6 +85,12 @@ public: void DeleteSelected(); + /** + * @brief Check if an item is in use anywhere and return any relevant input nodes + * kFootage has two streams that need to be handled + */ + QList GetItemNodes(Item* item, Item::Type type); + public slots: void set_view_type(ProjectToolbar::ViewType type);