fixed node removals

This commit is contained in:
itsmattkc
2021-01-22 19:23:20 +11:00
parent b114bf98c9
commit d9019f9cb1
8 changed files with 138 additions and 70 deletions
+2 -2
View File
@@ -31,7 +31,7 @@ void NodeConnectable::ConnectEdge(Node *output, NodeInput *input, int element)
// Connection exists
if (std::find(output->output_connections_.begin(), output->output_connections_.end(), conn_to_in) != output->output_connections_.end()) {
qDebug() << "Ignored connect that already exists";
qDebug() << "Ignored connect that already exists:" << output << input->parent() << input->id() << element;
return;
}
@@ -53,7 +53,7 @@ void NodeConnectable::DisconnectEdge(Node *output, NodeInput *input, int element
// Connection exists
if (std::find(output->output_connections_.begin(), output->output_connections_.end(), conn_to_in) == output->output_connections_.end()) {
qDebug() << "Ignored disconnect that doesn't exist";
qDebug() << "Ignored disconnect that doesn't exist:" << output << input->parent() << input->id() << element;
return;
}
-29
View File
@@ -193,35 +193,6 @@ QBrush Node::brush(qreal top, qreal bottom) const
}
}
void Node::RemoveNodesAndExclusiveDependencies(Node *node, QUndoCommand *command)
{
// Remove main node
RemoveNodeAndDisconnect(node, command);
// Remove exclusive dependencies
QVector<Node*> deps = node->GetExclusiveDependencies();
foreach (Node* d, deps) {
RemoveNodeAndDisconnect(d, command);
}
}
void Node::RemoveNodeAndDisconnect(Node *node, QUndoCommand *command)
{
// Disconnect everything
foreach (const InputConnection& conn, node->output_connections()) {
new NodeEdgeRemoveCommand(node, conn.input, conn.element, command);
}
foreach (NodeInput* input, node->inputs_) {
for (auto it=input->edges().cbegin(); it!=input->edges().cend(); it++) {
new NodeEdgeRemoveCommand(it->second, input, it->first, command);
}
}
// Remove node
new NodeRemoveCommand(node, command);
}
NodeValueTable Node::Value(NodeValueDatabase &value) const
{
return value.Merge();
-4
View File
@@ -193,10 +193,6 @@ public:
return inputs_;
}
static void RemoveNodesAndExclusiveDependencies(Node* node, QUndoCommand* command);
static void RemoveNodeAndDisconnect(Node* node, QUndoCommand* command);
/**
* @brief Return the index of a parameter
* @return Parameter index or -1 if this parameter is not part of this Node
+1 -1
View File
@@ -139,7 +139,7 @@ void NodeView::DeleteSelected()
if (!selected_nodes.isEmpty()) {
foreach (Node* node, selected_nodes) {
Node::RemoveNodeAndDisconnect(node, command);
new NodeRemoveAndDisconnectCommand(node, command);
}
}
}
+23 -22
View File
@@ -21,6 +21,7 @@
#include "nodeviewundo.h"
#include "project/item/sequence/sequence.h"
#include "widget/timelinewidget/timelineundo.h"
namespace olive {
@@ -94,28 +95,6 @@ Project *NodeAddCommand::GetRelevantProject() const
return graph_->project();
}
NodeRemoveCommand::NodeRemoveCommand(Node *node, QUndoCommand *parent) :
UndoCommand(parent),
graph_(node->parent()),
node_(node)
{
}
void NodeRemoveCommand::redo_internal()
{
node_->setParent(&memory_manager_);
}
void NodeRemoveCommand::undo_internal()
{
node_->setParent(graph_);
}
Project *NodeRemoveCommand::GetRelevantProject() const
{
return static_cast<Sequence*>(graph_)->project();
}
NodeCopyInputsCommand::NodeCopyInputsCommand(Node *src, Node *dest, bool include_connections, QUndoCommand *parent) :
QUndoCommand(parent),
src_(src),
@@ -129,4 +108,26 @@ void NodeCopyInputsCommand::redo()
Node::CopyInputs(src_, dest_, include_connections_);
}
void NodeRemoveAndDisconnectCommand::prep()
{
command_ = new QUndoCommand();
// If this is a block, remove all links
Block* block = dynamic_cast<Block*>(node_);
if (block) {
new BlockUnlinkAllCommand(block, command_);
}
// Disconnect everything
foreach (const Node::InputConnection& conn, node_->edges()) {
new NodeEdgeRemoveCommand(node_, conn.input, conn.element, command_);
}
foreach (NodeInput* input, node_->inputs()) {
for (auto it=input->edges().cbegin(); it!=input->edges().cend(); it++) {
new NodeEdgeRemoveCommand(it->second, input, it->first, command_);
}
}
}
}
+109 -7
View File
@@ -90,22 +90,124 @@ private:
Node* node_;
};
class NodeRemoveCommand : public UndoCommand {
class NodeRemoveAndDisconnectCommand : public UndoCommand {
public:
NodeRemoveCommand(Node* node,
QUndoCommand* parent = nullptr);
NodeRemoveAndDisconnectCommand(Node* node, QUndoCommand* parent = nullptr) :
UndoCommand(parent),
node_(node),
graph_(nullptr),
command_(nullptr),
prepped_(false)
{
}
virtual Project* GetRelevantProject() const override;
virtual ~NodeRemoveAndDisconnectCommand() override
{
delete command_;
}
virtual Project* GetRelevantProject() const override
{
if (graph_) {
return graph_->project();
} else {
return node_->parent()->project();
}
}
protected:
virtual void redo_internal() override;
virtual void undo_internal() override;
virtual void redo_internal() override
{
if (!prepped_) {
prep();
prepped_ = true;
}
command_->redo();
graph_ = node_->parent();
node_->setParent(&memory_manager_);
}
virtual void undo_internal() override
{
node_->setParent(graph_);
graph_ = nullptr;
command_->undo();
}
private:
void prep();
QObject memory_manager_;
NodeGraph* graph_;
Node* node_;
NodeGraph* graph_;
QUndoCommand* command_;
bool prepped_;
};
class NodeRemoveWithExclusiveDependenciesAndDisconnect : public UndoCommand {
public:
NodeRemoveWithExclusiveDependenciesAndDisconnect(Node* node, QUndoCommand* parent = nullptr) :
UndoCommand(parent),
node_(node),
command_(nullptr),
prepped_(false)
{
}
virtual ~NodeRemoveWithExclusiveDependenciesAndDisconnect() override
{
delete command_;
}
virtual Project* GetRelevantProject() const override
{
if (command_) {
return static_cast<const NodeRemoveAndDisconnectCommand*>(command_->child(0))->GetRelevantProject();
} else {
return node_->parent()->project();
}
}
protected:
virtual void redo_internal() override
{
if (!prepped_) {
prep();
prepped_ = true;
}
command_->redo();
}
virtual void undo_internal() override
{
command_->undo();
}
private:
void prep()
{
command_ = new QUndoCommand();
new NodeRemoveAndDisconnectCommand(node_, command_);
// Remove exclusive dependencies
QVector<Node*> deps = node_->GetExclusiveDependencies();
foreach (Node* d, deps) {
new NodeRemoveAndDisconnectCommand(d, command_);
}
}
Node* node_;
QUndoCommand* command_;
bool prepped_;
};
+1 -3
View File
@@ -48,9 +48,7 @@ inline bool NodeCanBeRemoved(Node* n)
inline QUndoCommand* CreateRemoveCommand(Node* n)
{
QUndoCommand* command = new QUndoCommand();
Node::RemoveNodesAndExclusiveDependencies(n, command);
return command;
return new NodeRemoveWithExclusiveDependenciesAndDisconnect(n);
}
inline QUndoCommand* CreateAndRunRemoveCommand(Node* n)
+2 -2
View File
@@ -435,7 +435,7 @@ void TimelineWidget::ReplaceBlocksWithGaps(const QVector<Block *> &blocks,
new TrackReplaceBlockWithGapCommand(original_track, b, command);
if (remove_from_graph) {
Node::RemoveNodesAndExclusiveDependencies(b, command);
new NodeRemoveWithExclusiveDependenciesAndDisconnect(b, command);
}
}
}
@@ -471,7 +471,7 @@ void TimelineWidget::DeleteSelected(bool ripple)
foreach (TransitionBlock* transition, transitions_to_delete) {
new TransitionRemoveCommand(transition, command);
Node::RemoveNodesAndExclusiveDependencies(transition, command);
new NodeRemoveWithExclusiveDependenciesAndDisconnect(transition, command);
}
// Replace clips with gaps (effectively deleting them)