many improvements and reimplementations

This commit is contained in:
itsmattkc
2021-11-29 21:22:49 -08:00
parent 495b07fc55
commit 239a019690
21 changed files with 874 additions and 495 deletions
+16
View File
@@ -74,6 +74,12 @@ void NodeGraph::childEvent(QChildEvent *event)
connect(node, &Node::ValueChanged, this, &NodeGraph::ValueChanged, Qt::DirectConnection);
connect(node, &Node::InputValueHintChanged, this, &NodeGraph::InputValueHintChanged, Qt::DirectConnection);
if (NodeGroup *group = dynamic_cast<NodeGroup*>(node)) {
connect(group, &NodeGroup::InputPassthroughAdded, this, &NodeGraph::GroupAddedInputPassthrough, Qt::DirectConnection);
connect(group, &NodeGroup::InputPassthroughRemoved, this, &NodeGraph::GroupRemovedInputPassthrough, Qt::DirectConnection);
connect(group, &NodeGroup::OutputPassthroughChanged, this, &NodeGraph::GroupChangedOutputPassthrough, Qt::DirectConnection);
}
emit NodeAdded(node);
emit node->AddedToGraph(this);
@@ -87,12 +93,22 @@ void NodeGraph::childEvent(QChildEvent *event)
disconnect(node, &Node::ValueChanged, this, &NodeGraph::ValueChanged);
disconnect(node, &Node::InputValueHintChanged, this, &NodeGraph::InputValueHintChanged);
if (NodeGroup *group = dynamic_cast<NodeGroup*>(node)) {
disconnect(group, &NodeGroup::InputPassthroughAdded, this, &NodeGraph::GroupAddedInputPassthrough);
disconnect(group, &NodeGroup::InputPassthroughRemoved, this, &NodeGraph::GroupRemovedInputPassthrough);
disconnect(group, &NodeGroup::OutputPassthroughChanged, this, &NodeGraph::GroupChangedOutputPassthrough);
}
emit NodeRemoved(node);
emit node->RemovedFromGraph(this);
// Remove from any contexts
foreach (Node *context, node_children_) {
context->RemoveNodeFromContext(node);
if (NodeGroup *group = dynamic_cast<NodeGroup*>(context)) {
group->RemoveNode(node);
}
}
}
}
+5 -2
View File
@@ -21,6 +21,7 @@
#ifndef NODEGRAPH_H
#define NODEGRAPH_H
#include "node/group/group.h"
#include "node/node.h"
namespace olive {
@@ -84,9 +85,11 @@ signals:
void InputValueHintChanged(const NodeInput& input);
void NodePositionAdded(Node *node, Node *relative, const QPointF &position);
void GroupAddedInputPassthrough(NodeGroup *group, const NodeInput &input);
void NodePositionRemoved(Node *node, Node *relative);
void GroupRemovedInputPassthrough(NodeGroup *group, const NodeInput &input);
void GroupChangedOutputPassthrough(NodeGroup *group, Node *output);
protected:
void AddDefaultNode(Node* n)
+41 -11
View File
@@ -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
View File
@@ -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
+42 -25
View File
@@ -1610,7 +1610,9 @@ void Node::CopyValuesOfElement(const Node *src, Node *dst, const QString &input,
dst->SetSplitStandardValue(input, src->GetSplitStandardValue(input, src_element), dst_element);
// Copy keyframes
dst->GetImmediate(input, dst_element)->delete_all_keyframes();
if (NodeInputImmediate *immediate = dst->GetImmediate(input, dst_element)) {
immediate->delete_all_keyframes();
}
foreach (const NodeKeyframeTrack& track, src->GetImmediate(input, src_element)->keyframe_tracks()) {
foreach (NodeKeyframe* key, track) {
key->copy(dst_element, dst);
@@ -2366,15 +2368,13 @@ Project *Node::ArrayResizeCommand::GetRelevantProject() const
void NodeSetPositionCommand::redo()
{
if (!(added_ = !context_->ContextContainsNode(node_))) {
added_ = !context_->ContextContainsNode(node_);
if (!added_) {
old_pos_ = context_->GetNodePositionDataInContext(node_);
}
if (added_) {
context_->SetNodePositionInContext(node_, pos_);
} else {
move(context_, node_, pos_.position - old_pos_.position, move_deps_);
}
context_->SetNodePositionInContext(node_, pos_);
}
void NodeSetPositionCommand::undo()
@@ -2382,23 +2382,7 @@ void NodeSetPositionCommand::undo()
if (added_) {
context_->RemoveNodeFromContext(node_);
} else {
move(context_, node_, old_pos_.position - pos_.position, move_deps_);
}
}
void NodeSetPositionCommand::move(Node *context, Node *node, const QPointF &diff, bool recursive)
{
QPointF p = context->GetNodePositionInContext(node);
p += diff;
context->SetNodePositionInContext(node, p);
if (recursive) {
for (auto it=node->input_connections().cbegin(); it!=node->input_connections().cend(); it++) {
Node *output = it->second;
if (context->ContextContainsNode(output)) {
move(context, output, diff, recursive);
}
}
context_->SetNodePositionInContext(node_, old_pos_);
}
}
@@ -2407,7 +2391,7 @@ void NodeRemovePositionFromContextCommand::redo()
contained_ = context_->ContextContainsNode(node_);
if (contained_) {
old_pos_ = context_->GetNodePositionInContext(node_);
old_pos_ = context_->GetNodePositionDataInContext(node_);
context_->RemoveNodeFromContext(node_);
}
}
@@ -2486,4 +2470,37 @@ void Node::ValueHint::Save(QXmlStreamWriter *writer) const
writer->writeTextElement(QStringLiteral("tag"), tag_);
}
void NodeSetPositionAndDependenciesRecursivelyCommand::prepare()
{
move_recursively(node_, pos_.position - context_->GetNodePositionDataInContext(node_).position);
}
void NodeSetPositionAndDependenciesRecursivelyCommand::redo()
{
for (auto it=commands_.cbegin(); it!=commands_.cend(); it++) {
(*it)->redo_now();
}
}
void NodeSetPositionAndDependenciesRecursivelyCommand::undo()
{
for (auto it=commands_.crbegin(); it!=commands_.crend(); it++) {
(*it)->undo_now();
}
}
void NodeSetPositionAndDependenciesRecursivelyCommand::move_recursively(Node *node, const QPointF &diff)
{
Node::Position pos = context_->GetNodePositionDataInContext(node);
pos += diff;
commands_.append(new NodeSetPositionCommand(node_, context_, pos));
for (auto it=node->input_connections().cbegin(); it!=node->input_connections().cend(); it++) {
Node *output = it->second;
if (context_->ContextContainsNode(output)) {
move_recursively(output, diff);
}
}
}
}
+33 -7
View File
@@ -320,7 +320,7 @@ public:
static void DisconnectEdge(Node *output, const NodeInput& input);
QString GetInputName(const QString& id) const;
virtual QString GetInputName(const QString& id) const;
void LoadInput(QXmlStreamReader* reader, XMLNodeData &xml_node_data, const QAtomicInt *cancelled);
void SaveInput(QXmlStreamWriter* writer, const QString& id) const;
@@ -1420,12 +1420,11 @@ using NodePtr = std::shared_ptr<Node>;
class NodeSetPositionCommand : public UndoCommand
{
public:
NodeSetPositionCommand(Node* node, Node* context, const Node::Position& pos, bool move_dependencies_relatively = false)
NodeSetPositionCommand(Node* node, Node* context, const Node::Position& pos)
{
node_ = node;
context_ = context;
pos_ = pos;
move_deps_ = move_dependencies_relatively;
}
virtual Project* GetRelevantProject() const override
@@ -1439,14 +1438,41 @@ protected:
virtual void undo() override;
private:
static void move(Node *context, Node *node, const QPointF &diff, bool recursive);
Node* node_;
Node* context_;
Node::Position pos_;
Node::Position old_pos_;
bool added_;
bool move_deps_;
};
class NodeSetPositionAndDependenciesRecursivelyCommand : public UndoCommand{
public:
NodeSetPositionAndDependenciesRecursivelyCommand(Node* node, Node* context, const Node::Position& pos) :
node_(node),
context_(context),
pos_(pos)
{}
virtual Project* GetRelevantProject() const override
{
return node_->project();
}
protected:
virtual void prepare() override;
virtual void redo() override;
virtual void undo() override;
private:
void move_recursively(Node *node, const QPointF &diff);
Node* node_;
Node* context_;
Node::Position pos_;
QVector<UndoCommand*> commands_;
};
@@ -1474,7 +1500,7 @@ private:
Node *context_;
QPointF old_pos_;
Node::Position old_pos_;
bool contained_;
+9
View File
@@ -150,6 +150,15 @@ QVariant NodeInput::GetSplitDefaultValueForTrack(int track) const
}
}
int NodeInput::GetArraySize() const
{
if (IsValid() && element_ == -1) {
return node_->InputArraySize(input_);
} else {
return 0;
}
}
uint qHash(const NodeInput &i)
{
return qHash(i.node()) ^ qHash(i.input()) ^ qHash(i.element());
+12
View File
@@ -134,6 +134,16 @@ public:
return element_;
}
void set_node(Node *node)
{
node_ = node;
}
void set_input(const QString &input)
{
input_ = input;
}
void set_element(int e)
{
element_ = e;
@@ -172,6 +182,8 @@ public:
QVariant GetSplitDefaultValueForTrack(int track) const;
int GetArraySize() const;
void Reset()
{
*this = NodeInput();