node importing down
This commit is contained in:
+21
-3
@@ -87,17 +87,35 @@ int Node::IndexOfParameter(NodeParam *param)
|
||||
return children().indexOf(param);
|
||||
}
|
||||
|
||||
QList<Node *> Node::GetDependencies()
|
||||
{
|
||||
QList<NodeParam*> params = parameters();
|
||||
/**
|
||||
* @brief Recursively collects dependencies of Node `n` and appends them to QList `list`
|
||||
*/
|
||||
void GetDependenciesInternal(Node* n, QList<Node*>& list) {
|
||||
QList<NodeParam*> params = n->parameters();
|
||||
|
||||
foreach (NodeParam* p, params) {
|
||||
if (p->type() == NodeParam::kInput) {
|
||||
QVector<NodeEdgePtr> param_edges = p->edges();
|
||||
|
||||
foreach (NodeEdgePtr edge, param_edges) {
|
||||
Node* connected_node = edge->output()->parent();
|
||||
|
||||
list.append(connected_node);
|
||||
GetDependenciesInternal(connected_node, list);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QList<Node *> Node::GetDependencies()
|
||||
{
|
||||
QList<Node *> node_list;
|
||||
|
||||
GetDependenciesInternal(this, node_list);
|
||||
|
||||
return node_list;
|
||||
}
|
||||
|
||||
QVariant Node::PtrToValue(void *ptr)
|
||||
{
|
||||
return reinterpret_cast<quintptr>(ptr);
|
||||
|
||||
+1
-1
@@ -109,7 +109,7 @@ public:
|
||||
int IndexOfParameter(NodeParam* param);
|
||||
|
||||
/**
|
||||
* @brief Return a list of all Nodes that this Node's inputs are connected to
|
||||
* @brief Return a list of all Nodes that this Node's inputs are connected to (does not include this Node)
|
||||
*/
|
||||
QList<Node*> GetDependencies();
|
||||
|
||||
|
||||
@@ -174,31 +174,39 @@ void TimelineOutput::InsertBlock(Block *block, int index)
|
||||
NodeGraph* graph = static_cast<NodeGraph*>(parent());
|
||||
graph->AddNode(block);
|
||||
|
||||
// FIXME: We'll probably want to add more nodes than this?
|
||||
// Add all of Block's dependencies
|
||||
QList<Node*> block_dependencies = block->GetDependencies();
|
||||
foreach (Node* dep, block_dependencies) {
|
||||
graph->AddNode(dep);
|
||||
}
|
||||
|
||||
if (block_cache_.isEmpty()) {
|
||||
|
||||
// If there are no blocks connected, the index doesn't matter. Just connect it.
|
||||
Block::ConnectBlocks(block, this);
|
||||
|
||||
} else if (index == 0) {
|
||||
|
||||
// Prepend block before all others
|
||||
// If the index is 0, it goes at the very beginning
|
||||
Block::ConnectBlocks(block, block_cache_.first());
|
||||
|
||||
} else {
|
||||
|
||||
// Insert block between
|
||||
// Otherwise, the block goes between two other blocks somehow
|
||||
Block* before;
|
||||
Block* after;
|
||||
|
||||
if (index < block_cache_.size()) {
|
||||
// The block goes somewhere in between some set of two blocks
|
||||
before = block_cache_.at(index - 1);
|
||||
after = block_cache_.at(index);
|
||||
} else {
|
||||
// The block goes at the very end
|
||||
before = block_cache_.last();
|
||||
after = this;
|
||||
}
|
||||
|
||||
// Connect blocks correctly
|
||||
Block::DisconnectBlocks(before, after);
|
||||
Block::ConnectBlocks(before, block);
|
||||
Block::ConnectBlocks(block, after);
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
|
||||
#include <QMimeData>
|
||||
|
||||
#include "node/input/media/media.h"
|
||||
|
||||
TimelineView::ImportTool::ImportTool(TimelineView *parent) :
|
||||
Tool(parent)
|
||||
{
|
||||
@@ -103,9 +105,15 @@ void TimelineView::ImportTool::DragDrop(QDropEvent *event)
|
||||
if (parent()->HasGhosts()) {
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
ClipBlock* clip = new ClipBlock();
|
||||
MediaInput* media = new MediaInput();
|
||||
|
||||
clip->set_length(ghost->Out() - ghost->In());
|
||||
media->SetFootage(ghost->stream()->footage());
|
||||
|
||||
NodeParam::ConnectEdge(media->texture_output(), clip->texture_input());
|
||||
|
||||
// FIXME: If this doesn't have a TimelineOutput node attached, this is a memory leak. Maybe switching nodes to
|
||||
// shared ptrs would be a better idea.
|
||||
emit parent()->RequestInsertBlock(clip, 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user