many improvements and reimplementations
This commit is contained in:
+41
-11
@@ -27,8 +27,6 @@ namespace olive {
|
||||
NodeGroup::NodeGroup() :
|
||||
output_passthrough_(nullptr)
|
||||
{
|
||||
graph_ = new NodeGraph();
|
||||
graph_->setParent(this);
|
||||
}
|
||||
|
||||
QString NodeGroup::Name() const
|
||||
@@ -57,26 +55,28 @@ QString NodeGroup::Description() const
|
||||
|
||||
void NodeGroup::Retranslate()
|
||||
{
|
||||
foreach (Node *n, graph_->nodes()) {
|
||||
foreach (Node *n, nodes_) {
|
||||
n->Retranslate();
|
||||
}
|
||||
}
|
||||
|
||||
void NodeGroup::AddNode(Node *node)
|
||||
{
|
||||
node->setParent(graph_);
|
||||
nodes_.append(node);
|
||||
|
||||
emit NodeAddedToGroup(node);
|
||||
}
|
||||
|
||||
void NodeGroup::RemoveNode(Node *node, QObject *new_parent)
|
||||
void NodeGroup::RemoveNode(Node *node)
|
||||
{
|
||||
if (node->parent() == graph_) {
|
||||
node->setParent(new_parent);
|
||||
if (nodes_.removeOne(node)) {
|
||||
emit NodeRemovedFromGroup(node);
|
||||
}
|
||||
}
|
||||
|
||||
void NodeGroup::AddInputPassthrough(const NodeInput &input)
|
||||
{
|
||||
Q_ASSERT(graph_->nodes().contains(input.node()));
|
||||
Q_ASSERT(nodes_.contains(input.node()));
|
||||
|
||||
for (auto it=input_passthroughs_.cbegin(); it!=input_passthroughs_.cend(); it++) {
|
||||
if (it.value() == input) {
|
||||
@@ -91,6 +91,8 @@ void NodeGroup::AddInputPassthrough(const NodeInput &input)
|
||||
AddInput(id, input.GetDataType(), input.GetDefaultValue(), input.GetFlags());
|
||||
|
||||
input_passthroughs_.insert(id, input);
|
||||
|
||||
emit InputPassthroughAdded(this, input);
|
||||
}
|
||||
|
||||
void NodeGroup::RemoveInputPassthrough(const NodeInput &input)
|
||||
@@ -99,6 +101,7 @@ void NodeGroup::RemoveInputPassthrough(const NodeInput &input)
|
||||
if (it.value() == input) {
|
||||
RemoveInput(it.key());
|
||||
input_passthroughs_.erase(it);
|
||||
emit InputPassthroughRemoved(this, it.value());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -106,9 +109,11 @@ void NodeGroup::RemoveInputPassthrough(const NodeInput &input)
|
||||
|
||||
void NodeGroup::SetOutputPassthrough(Node *node)
|
||||
{
|
||||
Q_ASSERT(graph_->nodes().contains(node));
|
||||
Q_ASSERT(!node || nodes_.contains(node));
|
||||
|
||||
output_passthrough_ = node;
|
||||
|
||||
emit OutputPassthroughChanged(this, output_passthrough_);
|
||||
}
|
||||
|
||||
QString NodeGroup::GetGroupInputIDFromInput(const NodeInput &input)
|
||||
@@ -135,15 +140,19 @@ bool NodeGroup::ContainsInputPassthrough(const NodeInput &input) const
|
||||
return false;
|
||||
}
|
||||
|
||||
QString NodeGroup::GetInputName(const QString &id) const
|
||||
{
|
||||
return input_passthroughs_.value(id).name();
|
||||
}
|
||||
|
||||
void NodeAddToGroupCommand::redo()
|
||||
{
|
||||
previous_parent_ = node_->parent();
|
||||
group_->AddNode(node_);
|
||||
}
|
||||
|
||||
void NodeAddToGroupCommand::undo()
|
||||
{
|
||||
group_->RemoveNode(node_, previous_parent_);
|
||||
group_->RemoveNode(node_);
|
||||
}
|
||||
|
||||
void NodeGroupSetCustomNameCommand::redo()
|
||||
@@ -174,4 +183,25 @@ void NodeGroupAddInputPassthrough::undo()
|
||||
}
|
||||
}
|
||||
|
||||
void NodeRemoveFromGroupCommand::redo()
|
||||
{
|
||||
group_->RemoveNode(node_);
|
||||
}
|
||||
|
||||
void NodeRemoveFromGroupCommand::undo()
|
||||
{
|
||||
group_->AddNode(node_);
|
||||
}
|
||||
|
||||
void NodeGroupSetOutputPassthrough::redo()
|
||||
{
|
||||
old_output_ = group_->GetOutputPassthrough();
|
||||
group_->SetOutputPassthrough(new_output_);
|
||||
}
|
||||
|
||||
void NodeGroupSetOutputPassthrough::undo()
|
||||
{
|
||||
group_->SetOutputPassthrough(old_output_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+80
-3
@@ -43,12 +43,27 @@ public:
|
||||
|
||||
void AddNode(Node *node);
|
||||
|
||||
void RemoveNode(Node *node, QObject *new_parent = nullptr);
|
||||
void RemoveNode(Node *node);
|
||||
|
||||
bool ContainsNode(Node *node) const
|
||||
{
|
||||
return nodes_.contains(node);
|
||||
}
|
||||
|
||||
const QVector<Node*> &GetNodes() const
|
||||
{
|
||||
return nodes_;
|
||||
}
|
||||
|
||||
void AddInputPassthrough(const NodeInput &input);
|
||||
|
||||
void RemoveInputPassthrough(const NodeInput &input);
|
||||
|
||||
Node *GetOutputPassthrough() const
|
||||
{
|
||||
return output_passthrough_;
|
||||
}
|
||||
|
||||
void SetOutputPassthrough(Node *node);
|
||||
|
||||
const QString &GetCustomName() const
|
||||
@@ -78,8 +93,21 @@ public:
|
||||
|
||||
bool ContainsInputPassthrough(const NodeInput &input) const;
|
||||
|
||||
virtual QString GetInputName(const QString& id) const override;
|
||||
|
||||
signals:
|
||||
void NodeAddedToGroup(Node *node);
|
||||
|
||||
void NodeRemovedFromGroup(Node *node);
|
||||
|
||||
void InputPassthroughAdded(NodeGroup *group, const NodeInput &input);
|
||||
|
||||
void InputPassthroughRemoved(NodeGroup *group, const NodeInput &input);
|
||||
|
||||
void OutputPassthroughChanged(NodeGroup *group, Node *output);
|
||||
|
||||
private:
|
||||
NodeGraph *graph_;
|
||||
QVector<Node*> nodes_;
|
||||
|
||||
QHash<QString, NodeInput> input_passthroughs_;
|
||||
|
||||
@@ -112,7 +140,30 @@ private:
|
||||
|
||||
NodeGroup *group_;
|
||||
|
||||
QObject *previous_parent_;
|
||||
};
|
||||
|
||||
class NodeRemoveFromGroupCommand : public UndoCommand
|
||||
{
|
||||
public:
|
||||
NodeRemoveFromGroupCommand(Node *node, NodeGroup *group) :
|
||||
node_(node),
|
||||
group_(group)
|
||||
{}
|
||||
|
||||
virtual Project * GetRelevantProject() const override
|
||||
{
|
||||
return node_->project();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void redo() override;
|
||||
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
Node *node_;
|
||||
|
||||
NodeGroup *group_;
|
||||
|
||||
};
|
||||
|
||||
@@ -171,6 +222,32 @@ private:
|
||||
|
||||
};
|
||||
|
||||
class NodeGroupSetOutputPassthrough : public UndoCommand
|
||||
{
|
||||
public:
|
||||
NodeGroupSetOutputPassthrough(NodeGroup *group, Node *output) :
|
||||
group_(group),
|
||||
new_output_(output)
|
||||
{}
|
||||
|
||||
virtual Project * GetRelevantProject() const override
|
||||
{
|
||||
return group_->project();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void redo() override;
|
||||
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
NodeGroup *group_;
|
||||
|
||||
Node *new_output_;
|
||||
Node *old_output_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // NODEGROUP_H
|
||||
|
||||
Reference in New Issue
Block a user