move undo files around for better organization
This commit is contained in:
@@ -33,8 +33,6 @@ set(OLIVE_SOURCES
|
||||
widget/nodeview/nodeviewscene.h
|
||||
widget/nodeview/nodeviewtoolbar.cpp
|
||||
widget/nodeview/nodeviewtoolbar.h
|
||||
widget/nodeview/nodeviewundo.cpp
|
||||
widget/nodeview/nodeviewundo.h
|
||||
widget/nodeview/nodewidget.cpp
|
||||
widget/nodeview/nodewidget.h
|
||||
PARENT_SCOPE
|
||||
|
||||
@@ -28,11 +28,11 @@
|
||||
#include <QScrollBar>
|
||||
#include <QToolTip>
|
||||
|
||||
#include "nodeviewundo.h"
|
||||
#include "node/audio/volume/volume.h"
|
||||
#include "node/distort/transform/transformdistortnode.h"
|
||||
#include "node/factory.h"
|
||||
#include "node/group/group.h"
|
||||
#include "node/nodeundo.h"
|
||||
#include "node/project/serializer/serializer.h"
|
||||
#include "node/traverser.h"
|
||||
#include "ui/icons/icons.h"
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
#include <QGraphicsTextItem>
|
||||
|
||||
#include "node/node.h"
|
||||
#include "node/nodeundo.h"
|
||||
#include "nodeviewcommon.h"
|
||||
#include "nodeviewedge.h"
|
||||
#include "nodeviewundo.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
#include "common/qtutils.h"
|
||||
#include "config/config.h"
|
||||
#include "core.h"
|
||||
#include "node/nodeundo.h"
|
||||
#include "nodeview.h"
|
||||
#include "nodeviewscene.h"
|
||||
#include "nodeviewundo.h"
|
||||
#include "ui/colorcoding.h"
|
||||
#include "ui/icons/icons.h"
|
||||
#include "window/mainwindow/mainwindow.h"
|
||||
|
||||
@@ -1,290 +0,0 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "nodeviewundo.h"
|
||||
|
||||
#include "node/project/sequence/sequence.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
NodeEdgeAddCommand::NodeEdgeAddCommand(Node *output, const NodeInput &input) :
|
||||
output_(output),
|
||||
input_(input),
|
||||
remove_command_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
NodeEdgeAddCommand::~NodeEdgeAddCommand()
|
||||
{
|
||||
delete remove_command_;
|
||||
}
|
||||
|
||||
void NodeEdgeAddCommand::redo()
|
||||
{
|
||||
if (input_.IsConnected()) {
|
||||
if (!remove_command_) {
|
||||
remove_command_ = new NodeEdgeRemoveCommand(input_.GetConnectedOutput(), input_);
|
||||
}
|
||||
|
||||
remove_command_->redo_now();
|
||||
}
|
||||
|
||||
Node::ConnectEdge(output_, input_);
|
||||
}
|
||||
|
||||
void NodeEdgeAddCommand::undo()
|
||||
{
|
||||
Node::DisconnectEdge(output_, input_);
|
||||
|
||||
if (remove_command_) {
|
||||
remove_command_->undo_now();
|
||||
}
|
||||
}
|
||||
|
||||
Project *NodeEdgeAddCommand::GetRelevantProject() const
|
||||
{
|
||||
return output_->project();
|
||||
}
|
||||
|
||||
NodeEdgeRemoveCommand::NodeEdgeRemoveCommand(Node *output, const NodeInput &input) :
|
||||
output_(output),
|
||||
input_(input)
|
||||
{
|
||||
}
|
||||
|
||||
void NodeEdgeRemoveCommand::redo()
|
||||
{
|
||||
Node::DisconnectEdge(output_, input_);
|
||||
}
|
||||
|
||||
void NodeEdgeRemoveCommand::undo()
|
||||
{
|
||||
Node::ConnectEdge(output_, input_);
|
||||
}
|
||||
|
||||
Project *NodeEdgeRemoveCommand::GetRelevantProject() const
|
||||
{
|
||||
return output_->project();
|
||||
}
|
||||
|
||||
NodeAddCommand::NodeAddCommand(Project *graph, Node *node) :
|
||||
graph_(graph),
|
||||
node_(node)
|
||||
{
|
||||
// Ensures that when this command is destroyed, if redo() is never called again, the node will be destroyed too
|
||||
node_->setParent(&memory_manager_);
|
||||
}
|
||||
|
||||
void NodeAddCommand::PushToThread(QThread *thread)
|
||||
{
|
||||
memory_manager_.moveToThread(thread);
|
||||
}
|
||||
|
||||
void NodeAddCommand::redo()
|
||||
{
|
||||
node_->setParent(graph_);
|
||||
}
|
||||
|
||||
void NodeAddCommand::undo()
|
||||
{
|
||||
node_->setParent(&memory_manager_);
|
||||
}
|
||||
|
||||
Project *NodeAddCommand::GetRelevantProject() const
|
||||
{
|
||||
return dynamic_cast<Project*>(graph_);
|
||||
}
|
||||
|
||||
void NodeRemoveAndDisconnectCommand::prepare()
|
||||
{
|
||||
command_ = new MultiUndoCommand();
|
||||
|
||||
// If this is a block, remove all links
|
||||
if (node_->HasLinks()) {
|
||||
command_->add_child(new NodeUnlinkAllCommand(node_));
|
||||
}
|
||||
|
||||
// Disconnect everything
|
||||
for (auto it=node_->input_connections().cbegin(); it!=node_->input_connections().cend(); it++) {
|
||||
command_->add_child(new NodeEdgeRemoveCommand(it->second, it->first));
|
||||
}
|
||||
|
||||
for (const Node::OutputConnection& conn : node_->output_connections()) {
|
||||
command_->add_child(new NodeEdgeRemoveCommand(conn.first, conn.second));
|
||||
}
|
||||
|
||||
command_->add_child(new NodeRemovePositionFromAllContextsCommand(node_));
|
||||
}
|
||||
|
||||
void NodeRenameCommand::AddNode(Node *node, const QString &new_name)
|
||||
{
|
||||
nodes_.append(node);
|
||||
new_labels_.append(new_name);
|
||||
old_labels_.append(node->GetLabel());
|
||||
}
|
||||
|
||||
void NodeRenameCommand::redo()
|
||||
{
|
||||
for (int i=0; i<nodes_.size(); i++) {
|
||||
nodes_.at(i)->SetLabel(new_labels_.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
void NodeRenameCommand::undo()
|
||||
{
|
||||
for (int i=0; i<nodes_.size(); i++) {
|
||||
nodes_.at(i)->SetLabel(old_labels_.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
Project *NodeRenameCommand::GetRelevantProject() const
|
||||
{
|
||||
return nodes_.isEmpty() ? nullptr : nodes_.first()->project();
|
||||
}
|
||||
|
||||
NodeOverrideColorCommand::NodeOverrideColorCommand(Node *node, int index) :
|
||||
node_(node),
|
||||
new_index_(index)
|
||||
{
|
||||
}
|
||||
|
||||
Project *NodeOverrideColorCommand::GetRelevantProject() const
|
||||
{
|
||||
return node_->project();
|
||||
}
|
||||
|
||||
void NodeOverrideColorCommand::redo()
|
||||
{
|
||||
old_index_ = node_->GetOverrideColor();
|
||||
node_->SetOverrideColor(new_index_);
|
||||
}
|
||||
|
||||
void NodeOverrideColorCommand::undo()
|
||||
{
|
||||
node_->SetOverrideColor(old_index_);
|
||||
}
|
||||
|
||||
NodeViewDeleteCommand::NodeViewDeleteCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void NodeViewDeleteCommand::AddNode(Node *node, Node *context)
|
||||
{
|
||||
if (ContainsNode(node, context)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Node::ContextPair p = {node, context};
|
||||
nodes_.append(p);
|
||||
|
||||
for (auto it=node->input_connections().cbegin(); it!=node->input_connections().cend(); it++) {
|
||||
if (context->ContextContainsNode(it->second)) {
|
||||
AddEdge(it->second, it->first);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it=node->output_connections().cbegin(); it!=node->output_connections().cend(); it++) {
|
||||
if (context->ContextContainsNode(it->second.node())) {
|
||||
AddEdge(it->first, it->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NodeViewDeleteCommand::AddEdge(Node *output, const NodeInput &input)
|
||||
{
|
||||
foreach (const Node::OutputConnection &edge, edges_) {
|
||||
if (edge.first == output && edge.second == input) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
edges_.append({output, input});
|
||||
}
|
||||
|
||||
bool NodeViewDeleteCommand::ContainsNode(Node *node, Node *context)
|
||||
{
|
||||
foreach (const Node::ContextPair &pair, nodes_) {
|
||||
if (pair.node == node && pair.context == context) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Project *NodeViewDeleteCommand::GetRelevantProject() const
|
||||
{
|
||||
if (!nodes_.isEmpty()) {
|
||||
return nodes_.first().node->project();
|
||||
}
|
||||
|
||||
if (!edges_.isEmpty()) {
|
||||
return edges_.first().first->project();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void NodeViewDeleteCommand::redo()
|
||||
{
|
||||
foreach (const Node::OutputConnection &edge, edges_) {
|
||||
Node::DisconnectEdge(edge.first, edge.second);
|
||||
}
|
||||
|
||||
foreach (const Node::ContextPair &pair, nodes_) {
|
||||
RemovedNode rn;
|
||||
|
||||
rn.node = pair.node;
|
||||
rn.context = pair.context;
|
||||
rn.pos = rn.context->GetNodePositionInContext(rn.node);
|
||||
|
||||
rn.context->RemoveNodeFromContext(rn.node);
|
||||
|
||||
// If node is no longer in any contexts and is not connected to anything, remove it
|
||||
if (rn.node->parent()->GetNumberOfContextsNodeIsIn(rn.node, true) == 0
|
||||
&& rn.node->input_connections().empty()
|
||||
&& rn.node->output_connections().empty()) {
|
||||
rn.removed_from_graph = rn.node->parent();
|
||||
rn.node->setParent(&memory_manager_);
|
||||
} else {
|
||||
rn.removed_from_graph = nullptr;
|
||||
}
|
||||
|
||||
removed_nodes_.append(rn);
|
||||
}
|
||||
}
|
||||
|
||||
void NodeViewDeleteCommand::undo()
|
||||
{
|
||||
for (auto rn=removed_nodes_.crbegin(); rn!=removed_nodes_.crend(); rn++) {
|
||||
if (rn->removed_from_graph) {
|
||||
rn->node->setParent(rn->removed_from_graph);
|
||||
}
|
||||
|
||||
rn->context->SetNodePositionInContext(rn->node, rn->pos);
|
||||
}
|
||||
removed_nodes_.clear();
|
||||
|
||||
for (auto edge=edges_.crbegin(); edge!=edges_.crend(); edge++) {
|
||||
Node::ConnectEdge(edge->first, edge->second);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,385 +0,0 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef NODEVIEWUNDO_H
|
||||
#define NODEVIEWUNDO_H
|
||||
|
||||
#include "node/node.h"
|
||||
#include "node/project.h"
|
||||
#include "undo/undocommand.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
/**
|
||||
* @brief An undoable command for disconnecting two NodeParams
|
||||
*
|
||||
* Can be considered a UndoCommand wrapper for NodeParam::DisonnectEdge()/
|
||||
*/
|
||||
class NodeEdgeRemoveCommand : public UndoCommand {
|
||||
public:
|
||||
NodeEdgeRemoveCommand(Node *output, const NodeInput& input);
|
||||
|
||||
virtual Project* GetRelevantProject() const override;
|
||||
|
||||
protected:
|
||||
virtual void redo() override;
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
Node *output_;
|
||||
NodeInput input_;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief An undoable command for connecting two NodeParams together
|
||||
*
|
||||
* Can be considered a UndoCommand wrapper for NodeParam::ConnectEdge()/
|
||||
*/
|
||||
class NodeEdgeAddCommand : public UndoCommand {
|
||||
public:
|
||||
NodeEdgeAddCommand(Node *output, const NodeInput& input);
|
||||
|
||||
virtual ~NodeEdgeAddCommand() override;
|
||||
|
||||
virtual Project* GetRelevantProject() const override;
|
||||
|
||||
protected:
|
||||
virtual void redo() override;
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
Node *output_;
|
||||
NodeInput input_;
|
||||
|
||||
NodeEdgeRemoveCommand* remove_command_;
|
||||
|
||||
};
|
||||
|
||||
class NodeAddCommand : public UndoCommand {
|
||||
public:
|
||||
NodeAddCommand(Project* graph, Node* node);
|
||||
|
||||
void PushToThread(QThread* thread);
|
||||
|
||||
virtual Project* GetRelevantProject() const override;
|
||||
|
||||
protected:
|
||||
virtual void redo() override;
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
QObject memory_manager_;
|
||||
|
||||
Project* graph_;
|
||||
Node* node_;
|
||||
};
|
||||
|
||||
class NodeRemoveAndDisconnectCommand : public UndoCommand {
|
||||
public:
|
||||
NodeRemoveAndDisconnectCommand(Node* node) :
|
||||
node_(node),
|
||||
graph_(nullptr),
|
||||
command_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~NodeRemoveAndDisconnectCommand() override
|
||||
{
|
||||
delete command_;
|
||||
}
|
||||
|
||||
virtual Project* GetRelevantProject() const override
|
||||
{
|
||||
return graph_;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void prepare() override;
|
||||
|
||||
virtual void redo() override
|
||||
{
|
||||
command_->redo_now();
|
||||
|
||||
graph_ = node_->parent();
|
||||
node_->setParent(&memory_manager_);
|
||||
}
|
||||
|
||||
virtual void undo() override
|
||||
{
|
||||
node_->setParent(graph_);
|
||||
graph_ = nullptr;
|
||||
|
||||
command_->undo_now();
|
||||
}
|
||||
|
||||
private:
|
||||
QObject memory_manager_;
|
||||
|
||||
Node* node_;
|
||||
Project* graph_;
|
||||
|
||||
MultiUndoCommand* command_;
|
||||
|
||||
};
|
||||
|
||||
class NodeRemoveWithExclusiveDependenciesAndDisconnect : public UndoCommand {
|
||||
public:
|
||||
NodeRemoveWithExclusiveDependenciesAndDisconnect(Node* node) :
|
||||
node_(node),
|
||||
command_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~NodeRemoveWithExclusiveDependenciesAndDisconnect() override
|
||||
{
|
||||
delete command_;
|
||||
}
|
||||
|
||||
virtual Project* GetRelevantProject() const override
|
||||
{
|
||||
if (command_) {
|
||||
return static_cast<const NodeRemoveAndDisconnectCommand*>(command_->child(0))->GetRelevantProject();
|
||||
} else {
|
||||
return node_->project();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void prepare() override
|
||||
{
|
||||
command_ = new MultiUndoCommand();
|
||||
|
||||
command_->add_child(new NodeRemoveAndDisconnectCommand(node_));
|
||||
|
||||
// Remove exclusive dependencies
|
||||
QVector<Node*> deps = node_->GetExclusiveDependencies();
|
||||
foreach (Node* d, deps) {
|
||||
command_->add_child(new NodeRemoveAndDisconnectCommand(d));
|
||||
}
|
||||
}
|
||||
|
||||
virtual void redo() override
|
||||
{
|
||||
command_->redo_now();
|
||||
}
|
||||
|
||||
virtual void undo() override
|
||||
{
|
||||
command_->undo_now();
|
||||
}
|
||||
|
||||
private:
|
||||
Node* node_;
|
||||
MultiUndoCommand* command_;
|
||||
|
||||
};
|
||||
|
||||
class NodeLinkCommand : public UndoCommand {
|
||||
public:
|
||||
NodeLinkCommand(Node* a, Node* b, bool link) :
|
||||
a_(a),
|
||||
b_(b),
|
||||
link_(link)
|
||||
{
|
||||
}
|
||||
|
||||
virtual Project* GetRelevantProject() const override
|
||||
{
|
||||
return a_->project();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void redo() override
|
||||
{
|
||||
if (link_) {
|
||||
done_ = Node::Link(a_, b_);
|
||||
} else {
|
||||
done_ = Node::Unlink(a_, b_);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void undo() override
|
||||
{
|
||||
if (done_) {
|
||||
if (link_) {
|
||||
Node::Unlink(a_, b_);
|
||||
} else {
|
||||
Node::Link(a_, b_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Node* a_;
|
||||
Node* b_;
|
||||
bool link_;
|
||||
bool done_;
|
||||
|
||||
};
|
||||
|
||||
class NodeUnlinkAllCommand : public UndoCommand {
|
||||
public:
|
||||
NodeUnlinkAllCommand(Node* node) :
|
||||
node_(node)
|
||||
{
|
||||
}
|
||||
|
||||
virtual Project* GetRelevantProject() const override
|
||||
{
|
||||
return node_->project();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void redo() override
|
||||
{
|
||||
unlinked_ = node_->links();
|
||||
|
||||
foreach (Node* link, unlinked_) {
|
||||
Node::Unlink(node_, link);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void undo() override
|
||||
{
|
||||
foreach (Node* link, unlinked_) {
|
||||
Node::Link(node_, link);
|
||||
}
|
||||
|
||||
unlinked_.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
Node* node_;
|
||||
|
||||
QVector<Node*> unlinked_;
|
||||
|
||||
};
|
||||
|
||||
class NodeLinkManyCommand : public MultiUndoCommand {
|
||||
public:
|
||||
NodeLinkManyCommand(const QVector<Node*> nodes, bool link) :
|
||||
nodes_(nodes)
|
||||
{
|
||||
foreach (Node* a, nodes_) {
|
||||
foreach (Node* b, nodes_) {
|
||||
if (a != b) {
|
||||
add_child(new NodeLinkCommand(a, b, link));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual Project* GetRelevantProject() const override
|
||||
{
|
||||
return nodes_.first()->project();
|
||||
}
|
||||
|
||||
private:
|
||||
QVector<Node*> nodes_;
|
||||
|
||||
};
|
||||
|
||||
class NodeRenameCommand : public UndoCommand
|
||||
{
|
||||
public:
|
||||
NodeRenameCommand() = default;
|
||||
NodeRenameCommand(Node* node, const QString& new_name)
|
||||
{
|
||||
AddNode(node, new_name);
|
||||
}
|
||||
|
||||
void AddNode(Node* node, const QString& new_name);
|
||||
|
||||
virtual Project * GetRelevantProject() const override;
|
||||
|
||||
protected:
|
||||
virtual void redo() override;
|
||||
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
QVector<Node*> nodes_;
|
||||
|
||||
QStringList new_labels_;
|
||||
QStringList old_labels_;
|
||||
|
||||
};
|
||||
|
||||
class NodeOverrideColorCommand : public UndoCommand
|
||||
{
|
||||
public:
|
||||
NodeOverrideColorCommand(Node *node, int index);
|
||||
|
||||
virtual Project * GetRelevantProject() const override;
|
||||
|
||||
protected:
|
||||
virtual void redo() override;
|
||||
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
Node *node_;
|
||||
|
||||
int old_index_;
|
||||
|
||||
int new_index_;
|
||||
|
||||
};
|
||||
|
||||
class NodeViewDeleteCommand : public UndoCommand
|
||||
{
|
||||
public:
|
||||
NodeViewDeleteCommand();
|
||||
|
||||
void AddNode(Node *node, Node *context);
|
||||
|
||||
void AddEdge(Node *output, const NodeInput &input);
|
||||
|
||||
bool ContainsNode(Node *node, Node *context);
|
||||
|
||||
virtual Project * GetRelevantProject() const override;
|
||||
|
||||
protected:
|
||||
virtual void redo() override;
|
||||
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
QVector<Node::ContextPair> nodes_;
|
||||
|
||||
QVector<Node::OutputConnection> edges_;
|
||||
|
||||
struct RemovedNode {
|
||||
Node *node;
|
||||
Node *context;
|
||||
QPointF pos;
|
||||
Project *removed_from_graph;
|
||||
};
|
||||
|
||||
QVector<RemovedNode> removed_nodes_;
|
||||
|
||||
QObject memory_manager_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // NODEVIEWUNDO_H
|
||||
Reference in New Issue
Block a user