groups: started revision

- Removed UUIDs since we already have ptrs
- Changed input passthroughs from map to list so they'll always be added in the same order
- Fixed group copy on duplication
- Fixed group copy on clip split
This commit is contained in:
itsmattkc
2022-04-03 19:18:39 -07:00
parent 49e622ac0f
commit afaf6bcf92
12 changed files with 174 additions and 82 deletions
+16 -24
View File
@@ -63,18 +63,23 @@ QString NodeGroup::AddInputPassthrough(const NodeInput &input, const InputFlags
Q_ASSERT(ContextContainsNode(input.node()));
for (auto it=input_passthroughs_.cbegin(); it!=input_passthroughs_.cend(); it++) {
if (it.value() == input) {
if (it->second == input) {
// Already passing this input through
return it.key();
return it->first;
}
}
// Add input
QString id = GetGroupInputIDFromInput(input);
QString id = input.input();
int i = 2;
while (HasInputWithID(id)) {
id = QStringLiteral("%1_%2").arg(input.name(), QString::number(i));
i++;
}
AddInput(id, input.GetDataType(), input.GetDefaultValue(), input.GetFlags() | flags);
input_passthroughs_.insert(id, input);
input_passthroughs_.append({id, input});
emit InputPassthroughAdded(this, input);
@@ -83,11 +88,11 @@ QString NodeGroup::AddInputPassthrough(const NodeInput &input, const InputFlags
void NodeGroup::RemoveInputPassthrough(const NodeInput &input)
{
for (auto it=input_passthroughs_.cbegin(); it!=input_passthroughs_.cend(); it++) {
if (it.value() == input) {
RemoveInput(it.key());
for (auto it=input_passthroughs_.begin(); it!=input_passthroughs_.end(); it++) {
if (it->second == input) {
RemoveInput(it->first);
emit InputPassthroughRemoved(this, it->second);
input_passthroughs_.erase(it);
emit InputPassthroughRemoved(this, it.value());
break;
}
}
@@ -102,23 +107,10 @@ void NodeGroup::SetOutputPassthrough(Node *node)
emit OutputPassthroughChanged(this, output_passthrough_);
}
QString NodeGroup::GetGroupInputIDFromInput(const NodeInput &input)
{
QCryptographicHash hash(QCryptographicHash::Sha1);
hash.addData(input.node()->GetUUID().toByteArray());
hash.addData(input.input().toUtf8());
hash.addData((const char*) &input.element(), sizeof(input.element()));
return QString::fromLatin1(hash.result().toHex());
}
bool NodeGroup::ContainsInputPassthrough(const NodeInput &input) const
{
for (auto it=input_passthroughs_.cbegin(); it!=input_passthroughs_.cend(); it++) {
if (it.value() == input) {
if (it->second == input) {
return true;
}
}
@@ -135,7 +127,7 @@ QString NodeGroup::GetInputName(const QString &id) const
}
// Call GetInputName of passed through node, which may be another group
NodeInput pass = input_passthroughs_.value(id);
NodeInput pass = GetInputFromID(id);
return pass.node()->GetInputName(pass.input());
}
@@ -149,7 +141,7 @@ NodeInput NodeGroup::ResolveInput(NodeInput input)
bool NodeGroup::GetInner(NodeInput *input)
{
if (NodeGroup *g = dynamic_cast<NodeGroup*>(input->node())) {
const NodeInput &passthrough = g->GetInputPassthroughs().value(input->input());
const NodeInput &passthrough = g->GetInputFromID(input->input());
input->set_node(passthrough.node());
input->set_input(passthrough.input());
return true;