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.
This commit is contained in:
Thomas Wilshaw
2020-09-29 11:31:03 +01:00
parent aef9078598
commit 8e6b42a160
4 changed files with 32 additions and 97 deletions
-48
View File
@@ -642,52 +642,4 @@ void ProjectViewModel::OfflineFootageCommand::undo_internal()
}
}
ProjectViewModel::DeleteFootageCommand::DeleteFootageCommand(ProjectViewModel *model, ItemPtr item,
QMap<Node *, StreamPtr> 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<ItemPtr> sequences = model_->project()->get_items_of_type(Item::kSequence);
blocks_.clear();
foreach (ItemPtr seq, sequences) {
Sequence *s = static_cast<Sequence *>(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<Block *>(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
-26
View File
@@ -216,32 +216,6 @@ public:
QMap<Node*, StreamPtr> nodes_;
};
class DeleteFootageCommand : public UndoCommand {
public:
DeleteFootageCommand(ProjectViewModel* model, ItemPtr item, QMap<Node*, StreamPtr> 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<Node*, StreamPtr> nodes_;
QList<Block*> blocks_;
QUndoCommand* deleteCommand_;
};
private:
/**
* @brief Retrieve the index of `item` in its parent
+27 -23
View File
@@ -574,6 +574,31 @@ QMap<Node*, StreamPtr> ProjectExplorer::GetFootageNodes(Item* item)
return nodes;
}
QList<Block*> ProjectExplorer::GetFootageBlocks(QList<Node*> nodes)
{
// Get all sequences.
QList<ItemPtr> sequences = model_.project()->get_items_of_type(Item::kSequence);
QList<Block*> blocks;
foreach (ItemPtr seq, sequences) {
Sequence* s = static_cast<Sequence*>(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<Block*>(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<ItemPtr> sequences = model_.project()->get_items_of_type(Item::kSequence);
QList<Block*> blocks;
foreach(ItemPtr seq, sequences) {
Sequence* s = static_cast<Sequence*>(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<Block*>(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;
@@ -122,6 +122,11 @@ private:
*/
QMap<Node*, StreamPtr> GetFootageNodes(Item* item);
/**
* @brief Get all the blocks associated with the given footage nodes
*/
QList<Block*> GetFootageBlocks(QList<Node*> nodes);
/**
* @brief Simple convenience function for adding a view to this stacked widget
*