moved timeline undoable commands to using the new NodeAddCommand
Previous iteration used some "magic code" that added clips automatically to the timeline. This was functional but ultimately outside of the undo commands' control meaning nodes could be infinitely added and abandoned. This makes the add process part of the undo command which means it's all undoable as the user would expect.
This commit is contained in:
@@ -49,18 +49,6 @@ void NodeGraph::AddNode(Node *node)
|
||||
emit NodeAdded(node);
|
||||
}
|
||||
|
||||
void NodeGraph::AddNodeWithDependencies(Node *node)
|
||||
{
|
||||
// Add node and its connected nodes to graph
|
||||
AddNode(node);
|
||||
|
||||
// Add all of Block's dependencies
|
||||
QList<Node*> node_dependencies = node->GetDependencies();
|
||||
foreach (Node* dep, node_dependencies) {
|
||||
AddNode(dep);
|
||||
}
|
||||
}
|
||||
|
||||
void NodeGraph::TakeNode(Node *node, QObject* new_parent)
|
||||
{
|
||||
if (!ContainsNode(node)) {
|
||||
@@ -84,21 +72,6 @@ void NodeGraph::TakeNode(Node *node, QObject* new_parent)
|
||||
emit NodeRemoved(node);
|
||||
}
|
||||
|
||||
QList<Node *> NodeGraph::TakeNodeWithItsDependencies(Node *node, QObject *new_parent)
|
||||
{
|
||||
if (!ContainsNode(node)) {
|
||||
return QList<Node*>();
|
||||
}
|
||||
|
||||
QList<Node*> deps = node->GetExclusiveDependencies();
|
||||
|
||||
foreach (Node* d, deps) {
|
||||
TakeNode(d, new_parent);
|
||||
}
|
||||
|
||||
return deps;
|
||||
}
|
||||
|
||||
const QList<Node *> &NodeGraph::nodes()
|
||||
{
|
||||
return node_children_;
|
||||
|
||||
@@ -50,31 +50,11 @@ public:
|
||||
*/
|
||||
void AddNode(Node* node);
|
||||
|
||||
/**
|
||||
* @brief Adds a node to this graph and all nodes connected to its inputs
|
||||
*
|
||||
* Adds the Node to the graph and runs through its inputs adding all of its dependencies (and all of their
|
||||
* dependencies and so forth). The graph takes ownershi of all Nodes added through this process.
|
||||
*/
|
||||
void AddNodeWithDependencies(Node* node);
|
||||
|
||||
/**
|
||||
* @brief Removes a Node from the graph BUT doesn't destroy it. Ownership is passed to `new_parent`.
|
||||
*/
|
||||
void TakeNode(Node* node, QObject* new_parent = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Removes a Node from the graph and its dependencies (ONLY if the dependencies are exclusive to this Node).
|
||||
*
|
||||
* Returns a list of all Nodes that were removed in this process (except the Node used as a parameter)
|
||||
*
|
||||
* Only dependencies that are exclusively dependencies of this Node are removed. If a dependency Node is also
|
||||
* used as the dependency of another Node, it is not removed and not returned in the list.
|
||||
*
|
||||
* Ownership of all Nodes is passed to `new_parent`.
|
||||
*/
|
||||
QList<Node*> TakeNodeWithItsDependencies(Node* node, QObject* new_parent = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Retrieve a complete list of the nodes belonging to this graph
|
||||
*/
|
||||
|
||||
@@ -468,6 +468,16 @@ QVariant Node::InputValueFromTable(NodeInput *input, const NodeValueTable &table
|
||||
return table.Get(find_data_type);
|
||||
}
|
||||
|
||||
const QPointF &Node::GetPosition()
|
||||
{
|
||||
return position_;
|
||||
}
|
||||
|
||||
void Node::SetPosition(const QPointF &pos)
|
||||
{
|
||||
position_ = pos;
|
||||
}
|
||||
|
||||
void Node::AddInput(NodeInput *input)
|
||||
{
|
||||
AddParameter(input);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <QCryptographicHash>
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
#include <QPointF>
|
||||
|
||||
#include "common/rational.h"
|
||||
#include "node/dependency.h"
|
||||
@@ -270,6 +271,10 @@ public:
|
||||
|
||||
virtual QVariant InputValueFromTable(NodeInput* input, const NodeValueTable& table) const;
|
||||
|
||||
const QPointF& GetPosition();
|
||||
|
||||
void SetPosition(const QPointF& pos);
|
||||
|
||||
protected:
|
||||
void AddInput(NodeInput* input);
|
||||
|
||||
@@ -339,6 +344,11 @@ private:
|
||||
*/
|
||||
NodeOutput* output_;
|
||||
|
||||
/**
|
||||
* @brief UI position for NodeViews
|
||||
*/
|
||||
QPointF position_;
|
||||
|
||||
private slots:
|
||||
void InputChanged(rational start, rational end);
|
||||
|
||||
|
||||
@@ -231,17 +231,19 @@ void TrackOutput::PrependBlock(Block *block)
|
||||
|
||||
void TrackOutput::InsertBlockAtIndex(Block *block, int index)
|
||||
{
|
||||
AddBlockToGraph(block);
|
||||
BlockInvalidateCache();
|
||||
|
||||
block_input_->InsertAt(index);
|
||||
NodeParam::ConnectEdge(block->output(),
|
||||
block_input_->At(index));
|
||||
|
||||
UnblockInvalidateCache();
|
||||
|
||||
InvalidateCache(block->in(), track_length());
|
||||
}
|
||||
|
||||
void TrackOutput::AppendBlock(Block *block)
|
||||
{
|
||||
AddBlockToGraph(block);
|
||||
|
||||
BlockInvalidateCache();
|
||||
|
||||
int last_index = block_input_->GetSize();
|
||||
@@ -255,13 +257,6 @@ void TrackOutput::AppendBlock(Block *block)
|
||||
InvalidateCache(block->in(), track_length());
|
||||
}
|
||||
|
||||
void TrackOutput::AddBlockToGraph(Block *block)
|
||||
{
|
||||
// Find the parent graph
|
||||
NodeGraph* graph = static_cast<NodeGraph*>(parent());
|
||||
graph->AddNodeWithDependencies(block);
|
||||
}
|
||||
|
||||
void TrackOutput::BlockInvalidateCache()
|
||||
{
|
||||
block_invalidate_cache_stack_++;
|
||||
@@ -272,14 +267,6 @@ void TrackOutput::UnblockInvalidateCache()
|
||||
block_invalidate_cache_stack_--;
|
||||
}
|
||||
|
||||
void TrackOutput::RemoveBlock(Block *block)
|
||||
{
|
||||
GapBlock* gap = new GapBlock();
|
||||
gap->set_length(block->length());
|
||||
|
||||
ReplaceBlock(block, gap);
|
||||
}
|
||||
|
||||
void TrackOutput::RippleRemoveBlock(Block *block)
|
||||
{
|
||||
BlockInvalidateCache();
|
||||
@@ -293,8 +280,6 @@ void TrackOutput::RippleRemoveBlock(Block *block)
|
||||
UnblockInvalidateCache();
|
||||
|
||||
InvalidateCache(remove_in, track_length());
|
||||
|
||||
// FIXME: Should there be removing the Blocks from the graph?
|
||||
}
|
||||
|
||||
void TrackOutput::ReplaceBlock(Block *old, Block *replace)
|
||||
@@ -303,8 +288,6 @@ void TrackOutput::ReplaceBlock(Block *old, Block *replace)
|
||||
|
||||
BlockInvalidateCache();
|
||||
|
||||
AddBlockToGraph(replace);
|
||||
|
||||
int index_of_old_block = block_cache_.indexOf(old);
|
||||
|
||||
NodeParam::DisconnectEdge(old->output(),
|
||||
|
||||
@@ -98,11 +98,6 @@ public:
|
||||
*/
|
||||
void AppendBlock(Block* block);
|
||||
|
||||
/**
|
||||
* @brief Removes a Block and places a Gap in its place
|
||||
*/
|
||||
void RemoveBlock(Block* block);
|
||||
|
||||
/**
|
||||
* @brief Removes a Block pushing all subsequent Blocks earlier to take up the space
|
||||
*/
|
||||
@@ -119,13 +114,6 @@ public:
|
||||
|
||||
void UnblockInvalidateCache();
|
||||
|
||||
/**
|
||||
* @brief Adds a Block to the parent graph so it can be connected to other Nodes
|
||||
*
|
||||
* Also runs through Node's dependencies (the Nodes whose outputs are connected to this Node's inputs)
|
||||
*/
|
||||
void AddBlockToGraph(Block* block);
|
||||
|
||||
static TrackOutput* TrackFromBlock(Block* block);
|
||||
|
||||
const rational& track_length() const;
|
||||
|
||||
+1
-4
@@ -116,10 +116,7 @@ NodeEdgePtr NodeParam::ConnectEdge(NodeOutput *output, NodeInput *input, bool lo
|
||||
}
|
||||
|
||||
// Ensure both nodes are in the same graph
|
||||
if (output->parentNode()->parent() != input->parentNode()->parent()) {
|
||||
qWarning() << "Tried to connect two nodes that aren't part of the same graph";
|
||||
return nullptr;
|
||||
}
|
||||
Q_ASSERT(output->parentNode()->parent() == input->parentNode()->parent());
|
||||
|
||||
NodeEdgePtr edge = std::make_shared<NodeEdge>(output, input);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user