From a71df11fa657b373a404b5907550d82326d6dc07 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Tue, 29 Sep 2020 13:29:59 +0100 Subject: [PATCH] Deal with composite blocks If a block relies on mulitple inputs (i.e. a composite) then don't delete these from the timeline. We catch these inputs afterwards. --- .../projectexplorer/projectexplorer.cpp | 41 ++++++++++++++++--- app/widget/projectexplorer/projectexplorer.h | 6 +-- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/app/widget/projectexplorer/projectexplorer.cpp b/app/widget/projectexplorer/projectexplorer.cpp index fecb0ac6f..54b27d5da 100644 --- a/app/widget/projectexplorer/projectexplorer.cpp +++ b/app/widget/projectexplorer/projectexplorer.cpp @@ -38,6 +38,7 @@ #include "widget/menu/menushared.h" #include "window/mainwindow/mainwindow.h" #include "widget/timelinewidget/timelinewidget.h" +#include "widget/nodeview/nodeviewundo.h" OLIVE_NAMESPACE_ENTER @@ -585,13 +586,23 @@ QList ProjectExplorer::GetFootageBlocks(QList nodes) Sequence* s = static_cast(seq.get()); // Loop through nodes in sequence foreach (Node* node, s->nodes()) { - // For each Block see if it is linked to one of the Footage nodes add it to the delete list + // For each Block see if it solely depends on one of our input nodes and if so add to the block list if (node->IsBlock()) { - foreach (Node* input, nodes) { - if (node->GetDependencies().contains(input)) { - blocks.append(static_cast(node)); + int footage_deps = 0; + + QList dependancies = node->GetDependencies(); + QSet intersection = QSet(dependancies.begin(), dependancies.end()) + .intersect(QSet(nodes.begin(), nodes.end())); + if (!intersection.isEmpty()) { + foreach (Node* dep, dependancies) { + if (dep->IsMedia()) { + footage_deps++; + } + } + if (footage_deps == 1) { + blocks.append(static_cast(node)); + } } - } } } } @@ -658,8 +669,26 @@ void ProjectExplorer::DeleteSelected() if (response == kDelete) { QUndoCommand* deleteCommand = new QUndoCommand(command); TimelineWidget::ReplaceBlocksWithGaps(GetFootageBlocks(nodes.keys()), true, deleteCommand); - new ProjectViewModel::RemoveItemCommand(&model_, item_ptr, command); + //Core::instance()->undo_stack()->pushIfHasChildren(command); + + // Catch any input nodes we missed do to complex composites etc. + + QList sequences = model_.project()->get_items_of_type(Item::kSequence); + + QList nodes_to_delete; + foreach (ItemPtr seq, sequences) { + Sequence* s = static_cast(seq.get()); + foreach (Node* node, s->nodes()) { + if (node->IsMedia()) { + if (nodes.contains(node)) { + nodes_to_delete.append(node); + } + } + } + QUndoCommand* deleteNodesCommand = new QUndoCommand(deleteCommand); + new NodeRemoveCommand(static_cast(s), nodes_to_delete, deleteNodesCommand); + } } if (response == kCancel) { delete command; diff --git a/app/widget/projectexplorer/projectexplorer.h b/app/widget/projectexplorer/projectexplorer.h index a91af4cd2..d393959fa 100644 --- a/app/widget/projectexplorer/projectexplorer.h +++ b/app/widget/projectexplorer/projectexplorer.h @@ -123,9 +123,9 @@ private: QMap GetFootageNodes(Item* item); /** - * @brief Get all the blocks associated with the given footage nodes - * - * Currently quite brute force. + * @brief Get all the blocks that solely rely on an input node + * + * Ignores blocks that depend on multiple inputs */ QList GetFootageBlocks(QList nodes);