nodes: implementing saving/loading node positions from project file
This commit is contained in:
+12
-1
@@ -26,15 +26,25 @@
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
Node* XMLLoadNode(QXmlStreamReader* reader) {
|
||||
Node* XMLLoadNode(QXmlStreamReader* reader)
|
||||
{
|
||||
QString node_id;
|
||||
quintptr node_ptr = 0;
|
||||
QPointF node_pos;
|
||||
|
||||
XMLAttributeLoop(reader, attr) {
|
||||
if (attr.name() == QStringLiteral("id")) {
|
||||
node_id = attr.value().toString();
|
||||
} else if (attr.name() == QStringLiteral("ptr")) {
|
||||
node_ptr = attr.value().toULongLong();
|
||||
} else if (attr.name() == QStringLiteral("pos")) {
|
||||
QStringList pos = attr.value().toString().split(':');
|
||||
|
||||
// Protection in case this file has been messed with
|
||||
if (pos.size() == 2) {
|
||||
node_pos.setX(pos.at(0).toDouble());
|
||||
node_pos.setY(pos.at(1).toDouble());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +57,7 @@ Node* XMLLoadNode(QXmlStreamReader* reader) {
|
||||
|
||||
if (node) {
|
||||
node->setProperty("xml_ptr", node_ptr);
|
||||
node->SetPosition(node_pos);
|
||||
} else {
|
||||
qWarning() << "Failed to load" << node_id << "- no node with that ID is installed";
|
||||
}
|
||||
|
||||
+5
-1
@@ -103,6 +103,10 @@ void Node::Save(QXmlStreamWriter *writer, const QString &custom_name) const
|
||||
|
||||
writer->writeAttribute(QStringLiteral("ptr"), QString::number(reinterpret_cast<quintptr>(this)));
|
||||
|
||||
writer->writeAttribute(QStringLiteral("pos"),
|
||||
QStringLiteral("%1:%2").arg(QString::number(GetPosition().x()),
|
||||
QString::number(GetPosition().y())));
|
||||
|
||||
foreach (NodeParam* param, parameters()) {
|
||||
param->Save(writer);
|
||||
}
|
||||
@@ -550,7 +554,7 @@ NodeValue Node::InputValueFromTable(NodeInput *input, NodeValueDatabase &db, boo
|
||||
}
|
||||
}
|
||||
|
||||
const QPointF &Node::GetPosition()
|
||||
const QPointF &Node::GetPosition() const
|
||||
{
|
||||
return position_;
|
||||
}
|
||||
|
||||
+1
-1
@@ -342,7 +342,7 @@ public:
|
||||
|
||||
virtual NodeValue InputValueFromTable(NodeInput* input, NodeValueDatabase &db, bool take) const;
|
||||
|
||||
const QPointF& GetPosition();
|
||||
const QPointF& GetPosition() const;
|
||||
|
||||
void SetPosition(const QPointF& pos);
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ void NodeViewItem::SetNode(Node *n)
|
||||
}
|
||||
}
|
||||
|
||||
setPos(node_->GetPosition());
|
||||
SetNodePosition(node_->GetPosition());
|
||||
}
|
||||
|
||||
update();
|
||||
|
||||
@@ -159,8 +159,8 @@ void NodeViewScene::AddNode(Node* node)
|
||||
{
|
||||
NodeViewItem* item = new NodeViewItem();
|
||||
|
||||
item->SetNode(node);
|
||||
item->SetFlowDirection(direction_);
|
||||
item->SetNode(node);
|
||||
|
||||
addItem(item);
|
||||
item_map_.insert(node, item);
|
||||
|
||||
Reference in New Issue
Block a user