Replace custom unlink with BlockUnlinkAllCommand

Re-use existing unlink command and move all the unlinking code to
NodeRemoveCommand to cover all bases (deletion of a block in the
timeline or in the node editor).
This commit is contained in:
Thomas Wilshaw
2020-09-30 18:14:11 +01:00
parent e09afd7f68
commit 9d27d557cd
4 changed files with 12 additions and 19 deletions
+10 -12
View File
@@ -158,10 +158,9 @@ void NodeRemoveCommand::redo_internal()
if (n->IsBlock()) { if (n->IsBlock()) {
Block *b = static_cast<Block *>(n); Block *b = static_cast<Block *>(n);
if (b->HasLinks()) { if (b->HasLinks()) {
linked_blocks_.insert(b, b->linked_clips().toList()); BlockUnlinkAllCommand *unlink_command = new BlockUnlinkAllCommand(b);
foreach(Block * link, b->linked_clips()) { unlink_command->redo();
b->Unlink(b, link); block_unlink_commands_.append(unlink_command);
}
} }
} }
graph_->TakeNode(n, &memory_manager_); graph_->TakeNode(n, &memory_manager_);
@@ -173,13 +172,12 @@ void NodeRemoveCommand::undo_internal()
// Re-add nodes to graph // Re-add nodes to graph
foreach (Node* n, nodes_) { foreach (Node* n, nodes_) {
graph_->AddNode(n); graph_->AddNode(n);
// If the node is a block re-link any previous links }
if (n->IsBlock()) {
Block *b = static_cast<Block *>(n); // Relink any blocks that were unlinked
foreach(Block * link, linked_blocks_[b]) { foreach(BlockUnlinkAllCommand* command, block_unlink_commands_) {
b->Link(b, link); command->undo();
} delete command;
}
} }
// Re-connect edges // Re-connect edges
@@ -188,7 +186,7 @@ void NodeRemoveCommand::undo_internal()
} }
edges_.clear(); edges_.clear();
linked_blocks_.clear(); block_unlink_commands_.clear();
} }
Project *NodeRemoveCommand::GetRelevantProject() const Project *NodeRemoveCommand::GetRelevantProject() const
+2 -1
View File
@@ -27,6 +27,7 @@
#include "node/node.h" #include "node/node.h"
#include "nodeviewitem.h" #include "nodeviewitem.h"
#include "undo/undocommand.h" #include "undo/undocommand.h"
#include "widget/timelinewidget/undo/undo.h"
OLIVE_NAMESPACE_ENTER OLIVE_NAMESPACE_ENTER
@@ -112,7 +113,7 @@ private:
NodeGraph* graph_; NodeGraph* graph_;
QList<Node*> nodes_; QList<Node*> nodes_;
QList<NodeEdgePtr> edges_; QList<NodeEdgePtr> edges_;
QMap<Block*, QList<Block*>> linked_blocks_; QList<BlockUnlinkAllCommand*> block_unlink_commands_;
}; };
class NodeRemoveWithExclusiveDeps : public UndoCommand { class NodeRemoveWithExclusiveDeps : public UndoCommand {
@@ -494,8 +494,6 @@ void TimelineWidget::ReplaceBlocksWithGaps(const QList<Block *> &blocks,
new TrackReplaceBlockWithGapCommand(original_track, b, command); new TrackReplaceBlockWithGapCommand(original_track, b, command);
if (remove_from_graph) { if (remove_from_graph) {
new BlockUnlinkAllCommand(b, command);
new NodeRemoveWithExclusiveDeps(static_cast<NodeGraph*>(b->parent()), b, command); new NodeRemoveWithExclusiveDeps(static_cast<NodeGraph*>(b->parent()), b, command);
} }
} }
-4
View File
@@ -243,10 +243,6 @@ void TrackRippleRemoveAreaCommand::redo_internal()
foreach (Block* remove_block, removed_blocks_) { foreach (Block* remove_block, removed_blocks_) {
track_->RippleRemoveBlock(remove_block); track_->RippleRemoveBlock(remove_block);
BlockUnlinkAllCommand* unlink_command = new BlockUnlinkAllCommand(remove_block);
unlink_command->redo();
remove_block_commands_.append(unlink_command);
NodeRemoveWithExclusiveDeps* remove_command = new NodeRemoveWithExclusiveDeps(static_cast<NodeGraph*>(remove_block->parent()), remove_block); NodeRemoveWithExclusiveDeps* remove_command = new NodeRemoveWithExclusiveDeps(static_cast<NodeGraph*>(remove_block->parent()), remove_block);
remove_command->redo(); remove_command->redo();
remove_block_commands_.append(remove_command); remove_block_commands_.append(remove_command);