From 8e6b42a160408111c0ddb15c119d99c2b1209356 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Tue, 29 Sep 2020 11:31:03 +0100 Subject: [PATCH] Simplify and clean up Remove the Undo code for deleting a clip and replace it with simpler parent/child undo relationship. Move block gathering code to seperate function. It's quite brute force and might lead to issues further down the line with more complex composited node setups. --- app/project/projectviewmodel.cpp | 48 ------------------ app/project/projectviewmodel.h | 26 ---------- .../projectexplorer/projectexplorer.cpp | 50 ++++++++++--------- app/widget/projectexplorer/projectexplorer.h | 5 ++ 4 files changed, 32 insertions(+), 97 deletions(-) diff --git a/app/project/projectviewmodel.cpp b/app/project/projectviewmodel.cpp index 0947a6635..3a94252d6 100644 --- a/app/project/projectviewmodel.cpp +++ b/app/project/projectviewmodel.cpp @@ -642,52 +642,4 @@ void ProjectViewModel::OfflineFootageCommand::undo_internal() } } -ProjectViewModel::DeleteFootageCommand::DeleteFootageCommand(ProjectViewModel *model, ItemPtr item, - QMap nodes, QUndoCommand *parent) - : - UndoCommand(parent), - model_(model), - item_(item), - nodes_(nodes) -{ - deleteCommand_ = new QUndoCommand(); -} - -Project *ProjectViewModel::DeleteFootageCommand::GetRelevantProject() const -{ - return model_->project(); -} - -void ProjectViewModel::DeleteFootageCommand::redo_internal() -{ - QList sequences = model_->project()->get_items_of_type(Item::kSequence); - - blocks_.clear(); - - foreach (ItemPtr seq, sequences) { - 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 - if (node->IsBlock()) { - foreach (Node *input, nodes_.keys()) { - if (node->GetExclusiveDependencies().contains(input)) blocks_.append(static_cast(node)); - } - } - } - } - TimelineWidget::ReplaceBlocksWithGaps(blocks_, true, deleteCommand_); - Core::instance()->undo_stack()->pushIfHasChildren(deleteCommand_); - - parent_ = item_->parent(); - model_->RemoveChild(parent_, item_.get()); -} - -void ProjectViewModel::DeleteFootageCommand::undo_internal() -{ - model_->AddChild(parent_, item_); - deleteCommand_->undo(); -} - - OLIVE_NAMESPACE_EXIT diff --git a/app/project/projectviewmodel.h b/app/project/projectviewmodel.h index 05c2671c8..bd3e068ed 100644 --- a/app/project/projectviewmodel.h +++ b/app/project/projectviewmodel.h @@ -216,32 +216,6 @@ public: QMap nodes_; }; - class DeleteFootageCommand : public UndoCommand { - public: - DeleteFootageCommand(ProjectViewModel* model, ItemPtr item, QMap nodes, - QUndoCommand* parent = nullptr); - - virtual Project* GetRelevantProject() const override; - - protected: - virtual void redo_internal() override; - - virtual void undo_internal() override; - - private: - ProjectViewModel* model_; - - ItemPtr item_; - - Item* parent_; - - QMap nodes_; - - QList blocks_; - - QUndoCommand* deleteCommand_; - }; - private: /** * @brief Retrieve the index of `item` in its parent diff --git a/app/widget/projectexplorer/projectexplorer.cpp b/app/widget/projectexplorer/projectexplorer.cpp index e666ddf1d..26fedcd2d 100644 --- a/app/widget/projectexplorer/projectexplorer.cpp +++ b/app/widget/projectexplorer/projectexplorer.cpp @@ -574,6 +574,31 @@ QMap ProjectExplorer::GetFootageNodes(Item* item) return nodes; } +QList ProjectExplorer::GetFootageBlocks(QList nodes) +{ + // Get all sequences. + QList sequences = model_.project()->get_items_of_type(Item::kSequence); + + QList blocks; + + foreach (ItemPtr seq, sequences) { + 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 + if (node->IsBlock()) { + foreach (Node* input, nodes) { + if (node->GetExclusiveDependencies().contains(input)) { + blocks.append(static_cast(node)); + } + } + } + } + } + + return blocks; +} + ProjectExplorer::FootageDeleteResponse ProjectExplorer::DeleteWarningMessage() { QMessageBox msgBox; @@ -631,31 +656,10 @@ void ProjectExplorer::DeleteSelected() new ProjectViewModel::OfflineFootageCommand(&model_, item_ptr, nodes, command); } if (response == kDelete) { - // Get all sequences. - QList sequences = model_.project()->get_items_of_type(Item::kSequence); - - QList blocks; - - foreach(ItemPtr seq, sequences) { - 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 - if (node->IsBlock()) { - foreach(Node* input, nodes.keys()) { - if(node->GetExclusiveDependencies().contains(input)) - blocks.append(static_cast(node)); - } - } - } - } - //new ProjectViewModel::DeleteFootageCommand(&model_, item_ptr, blocks, command); - QUndoCommand* deleteCommand = new QUndoCommand(command); - TimelineWidget::ReplaceBlocksWithGaps(blocks, true, deleteCommand); - //Core::instance()->undo_stack()->pushIfHasChildren(deleteCommand); + TimelineWidget::ReplaceBlocksWithGaps(GetFootageBlocks(nodes.keys()), true, deleteCommand); + new ProjectViewModel::RemoveItemCommand(&model_, item_ptr, command); } if (response == kCancel) { delete command; diff --git a/app/widget/projectexplorer/projectexplorer.h b/app/widget/projectexplorer/projectexplorer.h index 907da2964..8900fc9de 100644 --- a/app/widget/projectexplorer/projectexplorer.h +++ b/app/widget/projectexplorer/projectexplorer.h @@ -122,6 +122,11 @@ private: */ QMap GetFootageNodes(Item* item); + /** + * @brief Get all the blocks associated with the given footage nodes + */ + QList GetFootageBlocks(QList nodes); + /** * @brief Simple convenience function for adding a view to this stacked widget *