Make Offlining footage an UndoCommand
Created a new UndoCommand in ProjectViewModel that set the footage input to a nullptr and resets it to the correct stream on undo.
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include <QUrl>
|
||||
|
||||
#include "core.h"
|
||||
#include "node/input/media/media.h"
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
@@ -603,4 +604,41 @@ void ProjectViewModel::RemoveItemCommand::undo_internal()
|
||||
model_->AddChild(parent_, item_);
|
||||
}
|
||||
|
||||
ProjectViewModel::OfflineFootageCommand::OfflineFootageCommand(ProjectViewModel* model, ItemPtr item,
|
||||
QMap<Node*, StreamPtr> nodes, QUndoCommand* parent) :
|
||||
UndoCommand(parent),
|
||||
model_(model),
|
||||
item_(item),
|
||||
nodes_(nodes)
|
||||
{
|
||||
}
|
||||
|
||||
Project *ProjectViewModel::OfflineFootageCommand::GetRelevantProject() const
|
||||
{
|
||||
return model_->project();
|
||||
}
|
||||
|
||||
void ProjectViewModel::OfflineFootageCommand::redo_internal()
|
||||
{
|
||||
QMap<Node *, StreamPtr>::const_iterator it = nodes_.constBegin();
|
||||
while (it != nodes_.constEnd()) {
|
||||
static_cast<MediaInput *>(it.key())->SetFootage(nullptr);
|
||||
++it;
|
||||
}
|
||||
|
||||
parent_ = item_->parent();
|
||||
model_->RemoveChild(parent_, item_.get());
|
||||
}
|
||||
|
||||
void ProjectViewModel::OfflineFootageCommand::undo_internal()
|
||||
{
|
||||
model_->AddChild(parent_, item_);
|
||||
|
||||
QMap<Node *, StreamPtr>::const_iterator it = nodes_.constBegin();
|
||||
while (it != nodes_.constEnd()) {
|
||||
static_cast<MediaInput *>(it.key())->SetFootage(it.value());
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -194,6 +194,27 @@ public:
|
||||
|
||||
};
|
||||
|
||||
class OfflineFootageCommand : public UndoCommand {
|
||||
public:
|
||||
OfflineFootageCommand(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_;
|
||||
};
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Retrieve the index of `item` in its parent
|
||||
|
||||
@@ -537,11 +537,11 @@ void ProjectExplorer::DeselectAll()
|
||||
CurrentView()->selectionModel()->clearSelection();
|
||||
}
|
||||
|
||||
QList<Node*> ProjectExplorer::GetFootageNodes(Item* item)
|
||||
QMap<Node*, StreamPtr> ProjectExplorer::GetFootageNodes(Item* item)
|
||||
{
|
||||
// Output list list
|
||||
QList<Node*> nodes;
|
||||
|
||||
QMap<Node*, StreamPtr> nodes;
|
||||
|
||||
// Get all sequences.
|
||||
QList<ItemPtr> sequences = model_.project()->get_items_of_type(Item::kSequence);
|
||||
// Get item pointer.
|
||||
@@ -562,7 +562,7 @@ QList<Node*> ProjectExplorer::GetFootageNodes(Item* item)
|
||||
if (node->IsMedia()){
|
||||
// Check the streams are the same
|
||||
if (static_cast<MediaInput*>(node)->footage() == stream) {
|
||||
nodes.append(node);
|
||||
nodes.insert(node, stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -615,29 +615,32 @@ void ProjectExplorer::DeleteSelected()
|
||||
if (Core::instance()->main_window()->IsSequenceOpen(s)) {
|
||||
Core::instance()->main_window()->CloseSequence(s);
|
||||
}
|
||||
|
||||
new ProjectViewModel::RemoveItemCommand(&model_, item_ptr, command);
|
||||
}
|
||||
|
||||
// If this is a footage item, clean up if necessary
|
||||
if (item_ptr->type() == Item::kFootage) {
|
||||
|
||||
// Check if nodes exists
|
||||
QList<Node*> nodes = GetFootageNodes(item);
|
||||
QMap<Node*, StreamPtr> nodes = GetFootageNodes(item);
|
||||
if (!nodes.isEmpty()){
|
||||
// Warn user and ask them what to do
|
||||
FootageDeleteResponse response = DeleteWarningMessage();
|
||||
if (response == kOffline) {
|
||||
// Loop through Footage nodes
|
||||
foreach (Node* node, nodes) {
|
||||
// Set footage to be null
|
||||
static_cast<MediaInput*>(node)->SetFootage(nullptr);
|
||||
}
|
||||
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);
|
||||
|
||||
}
|
||||
if (response == kCancel) {
|
||||
delete command;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new ProjectViewModel::RemoveItemCommand(&model_, item_ptr, command);
|
||||
}
|
||||
|
||||
Core::instance()->undo_stack()->pushIfHasChildren(command);
|
||||
|
||||
@@ -119,7 +119,7 @@ private:
|
||||
* @brief Check if an item is in use anywhere and return any relevant input nodes
|
||||
* Returns a QList as Footage has two streams that need to be handled
|
||||
*/
|
||||
QList<Node*> GetFootageNodes(Item* item);
|
||||
QMap<Node*, StreamPtr> GetFootageNodes(Item* item);
|
||||
|
||||
/**
|
||||
* @brief Simple convenience function for adding a view to this stacked widget
|
||||
|
||||
Reference in New Issue
Block a user