@@ -358,7 +358,10 @@ void AbstractNodeGraph::loadGraphV0(const QVariantMap &data) {
358358 GraphNode *node = nodeCreate (type, index);
359359 if (node) {
360360 node->setPosition (Vector2 (n[gOldX ].toInt (), n[gOldY ].toInt ()));
361- loadUserValues (node, n[gOldValues ].toMap ());
361+
362+ node->blockSignals (true );
363+ node->loadUserData (n[gOldValues ].toMap ());
364+ node->blockSignals (false );
362365 }
363366 }
364367
@@ -394,49 +397,7 @@ void AbstractNodeGraph::loadGraphV11(const QDomElement &parent) {
394397 QString type = nodeElement.attribute (gType );
395398 GraphNode *node = nodeCreate (type, index);
396399 if (node) {
397- node->setPosition (Vector2 (nodeElement.attribute (gX ).toInt (),
398- nodeElement.attribute (gY ).toInt ()));
399-
400- QVariantMap values;
401- QDomElement valueElement = nodeElement.firstChildElement (" value" );
402- while (!valueElement.isNull ()) {
403- QString type = valueElement.attribute (gType );
404- QString name = valueElement.attribute (gName );
405- if (type == " bool" ) {
406- values[name] = (valueElement.text () == " true" );
407- } else if (type == " int" ) {
408- values[name] = valueElement.text ().toInt ();
409- } else if (type == " float" ) {
410- values[name] = valueElement.text ().toFloat ();
411- } else if (type == " string" ) {
412- values[name] = valueElement.text ();
413- } else if (type == " Vector2" || type == " Vector3" || type == " Vector4" ) {
414- QVariantList list;
415- list.push_back (type);
416- for (auto &it : valueElement.text ().split (" , " )) {
417- list.push_back (it.toFloat ());
418- }
419- values[name] = list;
420- } else if (type == " Template" ) {
421- QVariantList list;
422- list.push_back (type);
423- for (auto &it : valueElement.text ().split (" , " )) {
424- list.push_back (it);
425- }
426- values[name] = list;
427- } else if (type == " Color" ) {
428- QVariantList list;
429- list.push_back (type);
430- for (auto &it : valueElement.text ().split (" , " )) {
431- list.push_back (it);
432- }
433- values[name] = list;
434- }
435-
436- valueElement = valueElement.nextSiblingElement ();
437- }
438-
439- loadUserValues (node, values);
400+ node->fromXml (nodeElement);
440401 }
441402
442403 nodeElement = nodeElement.nextSiblingElement ();
@@ -474,58 +435,15 @@ void AbstractNodeGraph::onNodesLoaded() {
474435void AbstractNodeGraph::saveGraph (QDomElement parent, QDomDocument xml) const {
475436 QDomElement graph = xml.createElement (gGraph );
476437
477- QVariantList nodes;
478438 QVariantList links;
479439
480- for (GraphNode *it : qAsConst (m_nodes)) {
481- nodes.push_back (saveNode (it));
482- links.append (saveLinks (it));
483- }
484-
485440 QDomElement nodesElement = xml.createElement (gNodes );
486- for (auto &node : nodes ) {
487- QDomElement nodeElement = xml. createElement ( gNode );
441+ for (auto &node : qAsConst (m_nodes) ) {
442+ QDomElement nodeElement = node-> toXml (xml );
488443
489- QVariantMap fields = node.toMap ();
490- for (auto &key : fields.keys ()) {
491- if (key.toLower () == gValues ) {
492- QVariantMap values = fields.value (key).toMap ();
493-
494- for (auto &value : values.keys ()) {
495- QDomElement valueElement = xml.createElement (" value" );
496- valueElement.setAttribute (gName , value);
497-
498- QVariant v = values.value (value);
499- switch (v.type ()) {
500- case QVariant::List: {
501- QVariantList list = v.toList ();
502- QString type = list.front ().toString ();
503- valueElement.setAttribute (gType , type);
504- list.pop_front ();
505- QString pack;
506- for (auto &it : list) {
507- pack += it.toString () + " , " ;
508- }
509- pack.resize (pack.size () - 2 );
510- valueElement.appendChild (xml.createTextNode (pack));
511- } break ;
512- default : {
513- QString type = v.typeName ();
514- if (type == " QString" ) {
515- type = " string" ;
516- }
517- valueElement.setAttribute (gType , type);
518- valueElement.appendChild (xml.createTextNode (v.toString ()));
519- } break ;
520- }
521-
522- nodeElement.appendChild (valueElement);
523- }
524- } else {
525- nodeElement.setAttribute (key, fields.value (key).toString ());
526- }
527- }
528444 nodesElement.appendChild (nodeElement);
445+
446+ links.append (saveLinks (node));
529447 }
530448
531449 QDomElement linksElement = xml.createElement (gLinks );
@@ -546,20 +464,6 @@ void AbstractNodeGraph::saveGraph(QDomElement parent, QDomDocument xml) const {
546464 parent.appendChild (graph);
547465}
548466
549- QVariantMap AbstractNodeGraph::saveNode (GraphNode *node) const {
550- QVariantMap result;
551- result[gType ] = node->typeName ().c_str ();
552- result[gX ] = (int )node->position ().x ;
553- result[gY ] = (int )node->position ().y ;
554- result[gIndex ] = AbstractNodeGraph::node (node);
555-
556- QVariantMap values;
557- saveUserValues (node, values);
558- result[gValues ] = values;
559-
560- return result;
561- }
562-
563467QVariantList AbstractNodeGraph::saveLinks (GraphNode *node) const {
564468 QVariantList result;
565469
@@ -598,16 +502,6 @@ void AbstractNodeGraph::reportMessage(GraphNode *node, const QString &text) {
598502 emit messageReported (AbstractNodeGraph::node (node), text);
599503}
600504
601- void AbstractNodeGraph::loadUserValues (GraphNode *node, const QVariantMap &values) {
602- node->blockSignals (true );
603- node->loadUserData (values);
604- node->blockSignals (false );
605- }
606-
607- void AbstractNodeGraph::saveUserValues (GraphNode *node, QVariantMap &values) const {
608- node->saveUserData (values);
609- }
610-
611505void AbstractNodeGraph::createLink (int sender, int oport, int receiver, int iport) {
612506 UndoManager::instance ()->push (new CreateLink (sender, oport, receiver, iport, this ));
613507}
@@ -630,7 +524,7 @@ void AbstractNodeGraph::copyNodes(const std::vector<int32_t> &selection) {
630524 GraphNode *node = m_nodes.at (it);
631525
632526 if (node) {
633- array.push_back (QJsonValue::fromVariant (saveNode ( node)));
527+ array.push_back (QJsonValue::fromVariant (node-> toVariant ( )));
634528 }
635529 }
636530
@@ -718,7 +612,7 @@ void DeleteNodes::redo() {
718612
719613 QVariantList nodes;
720614 for (auto it : list) {
721- nodes.push_back (m_graph-> saveNode (it ));
615+ nodes.push_back (it-> toVariant ( ));
722616 m_graph->nodeDelete (it);
723617 }
724618
@@ -762,7 +656,10 @@ void PasteNodes::redo () {
762656 int deltaX = maxX - n[gX ].toInt ();
763657 int deltaY = maxY - n[gY ].toInt ();
764658 node->setPosition (Vector2 (m_x + deltaX, m_y + deltaY));
765- m_graph->loadUserValues (node, n[gValues ].toMap ());
659+
660+ node->blockSignals (true );
661+ node->loadUserData (n[gValues ].toMap ());
662+ node->blockSignals (false );
766663
767664 m_list.push_back (index);
768665 }
0 commit comments