implemented saving/loading for groups

This commit is contained in:
itsmattkc
2021-12-28 21:52:28 -08:00
parent 74d9c43ff5
commit a4934f1d47
14 changed files with 170 additions and 94 deletions
+11
View File
@@ -54,6 +54,7 @@
namespace olive {
QList<Node*> NodeFactory::library_;
QVector<int> NodeFactory::hidden_;
void NodeFactory::Initialize()
{
@@ -65,6 +66,9 @@ void NodeFactory::Initialize()
library_.append(created_node);
}
hidden_.append(kTextGeneratorLegacy);
hidden_.append(kGroupNode);
}
void NodeFactory::Destroy()
@@ -86,6 +90,11 @@ Menu *NodeFactory::CreateMenu(QWidget* parent, bool create_none_item, Node::Cate
continue;
}
if (hidden_.contains(i)) {
// Skip this node
continue;
}
// Make sure nodes are up-to-date with the current translation
n->Retranslate();
@@ -241,6 +250,8 @@ Node *NodeFactory::CreateFromFactoryIndex(const NodeFactory::InternalID &id)
return new SubtitleBlock();
case kShapeGenerator:
return new ShapeNode();
case kGroupNode:
return new NodeGroup();
case kInternalNodeCount:
break;
+3
View File
@@ -61,6 +61,7 @@ public:
kTimeRemapNode,
kSubtitleBlock,
kShapeGenerator,
kGroupNode,
// Count value
kInternalNodeCount
@@ -87,6 +88,8 @@ public:
private:
static QList<Node*> library_;
static QVector<int> hidden_;
};
}
+52 -10
View File
@@ -24,6 +24,8 @@
namespace olive {
#define super Node
NodeGroup::NodeGroup() :
output_passthrough_(nullptr)
{
@@ -31,11 +33,7 @@ NodeGroup::NodeGroup() :
QString NodeGroup::Name() const
{
if (custom_name_.isEmpty()) {
return tr("Group");
} else {
return custom_name_;
}
return tr("Group");
}
QString NodeGroup::id() const
@@ -131,15 +129,59 @@ QString NodeGroup::GetInputName(const QString &id) const
return input_passthroughs_.value(id).name();
}
void NodeGroupSetCustomNameCommand::redo()
bool NodeGroup::LoadCustom(QXmlStreamReader *reader, XMLNodeData &xml_node_data, uint version, const QAtomicInt *cancelled)
{
old_name_ = group_->GetCustomName();
group_->SetCustomName(new_name_);
if (reader->name() == QStringLiteral("inputpassthroughs")) {
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("inputpassthrough")) {
XMLNodeData::GroupLink link;
link.group = this;
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("node")) {
link.input_node = reader->readElementText().toULongLong();
} else if (reader->name() == QStringLiteral("input")) {
link.input_id = reader->readElementText();
} else if (reader->name() == QStringLiteral("element")) {
link.input_element = reader->readElementText().toInt();
} else {
reader->skipCurrentElement();
}
}
xml_node_data.group_input_links.append(link);
} else {
reader->skipCurrentElement();
}
}
return true;
} else if (reader->name() == QStringLiteral("outputpassthrough")) {
xml_node_data.group_output_links.insert(this, reader->readElementText().toULongLong());
return true;
} else {
return super::LoadCustom(reader, xml_node_data, version, cancelled);
}
}
void NodeGroupSetCustomNameCommand::undo()
void NodeGroup::SaveCustom(QXmlStreamWriter *writer) const
{
group_->SetCustomName(old_name_);
super::SaveCustom(writer);
writer->writeStartElement(QStringLiteral("inputpassthroughs"));
foreach (const NodeInput &ip, input_passthroughs_) {
writer->writeStartElement(QStringLiteral("inputpassthrough"));
writer->writeTextElement(QStringLiteral("node"), QString::number(reinterpret_cast<quintptr>(ip.node())));
writer->writeTextElement(QStringLiteral("input"), ip.input());
writer->writeTextElement(QStringLiteral("element"), QString::number(ip.element()));
writer->writeEndElement(); // input
}
writer->writeEndElement(); // inputpassthroughs
writer->writeTextElement(QStringLiteral("outputpassthrough"), QString::number(reinterpret_cast<quintptr>(output_passthrough_)));
}
void NodeGroupAddInputPassthrough::redo()
+5 -47
View File
@@ -52,24 +52,6 @@ public:
void SetOutputPassthrough(Node *node);
const QString &GetCustomName() const
{
return custom_name_;
}
void SetCustomName(const QString &name)
{
custom_name_ = name;
// NOTE: Not technically the right signal, but should achieve the right goal
emit LabelChanged(custom_name_);
}
void ClearCustomName()
{
custom_name_.clear();
}
static QString GetGroupInputIDFromInput(const NodeInput &input);
const QHash<QString, NodeInput> &GetInputPassthroughs() const
@@ -88,40 +70,16 @@ signals:
void OutputPassthroughChanged(NodeGroup *group, Node *output);
protected:
virtual bool LoadCustom(QXmlStreamReader* reader, XMLNodeData& xml_node_data, uint version, const QAtomicInt* cancelled) override;
virtual void SaveCustom(QXmlStreamWriter* writer) const override;
private:
QHash<QString, NodeInput> input_passthroughs_;
Node *output_passthrough_;
QString custom_name_;
};
class NodeGroupSetCustomNameCommand : public UndoCommand
{
public:
NodeGroupSetCustomNameCommand(NodeGroup *group, const QString &name) :
group_(group),
new_name_(name)
{}
virtual Project * GetRelevantProject() const override
{
return group_->project();
}
protected:
virtual void redo() override;
virtual void undo() override;
private:
NodeGroup *group_;
QString old_name_;
QString new_name_;
};
class NodeGroupAddInputPassthrough : public UndoCommand
+1 -6
View File
@@ -205,12 +205,7 @@ QVector<Node *> NodeCopyPasteService::PasteNodesFromClipboard(NodeGraph *graph,
}
// Make connections
if (!xml_node_data.desired_connections.isEmpty()) {
XMLConnectNodes(xml_node_data, data_version, command);
}
// Link blocks
XMLLinkBlocks(xml_node_data);
xml_node_data.PostConnect(data_version, command);
// Process contexts
for (auto it=pasted_contexts.cbegin(); it!=pasted_contexts.cend(); it++) {
+1 -4
View File
@@ -193,10 +193,7 @@ void Project::Load(QXmlStreamReader *reader, MainWindowLayoutInfo* layout, uint
}
// Make connections
XMLConnectNodes(xml_node_data, version);
// Link blocks
XMLLinkBlocks(xml_node_data);
xml_node_data.PostConnect(version);
}
void Project::Save(QXmlStreamWriter *writer) const