@@ -581,13 +581,17 @@ bool GraphViewer::is_item_static(QGraphicsItem *item)
581
581
this ->static_items .end ());
582
582
}
583
583
584
- void GraphViewer::json_from (nlohmann::json json)
584
+ void GraphViewer::json_from (nlohmann::json json,
585
+ bool clear_existing_content,
586
+ const std::string &prefix_id)
585
587
{
586
588
// generate graph from json data
587
- this ->clear ();
588
-
589
- this ->id = json[" id" ];
590
- this ->current_link_type = json[" current_link_type" ].get <LinkType>();
589
+ if (clear_existing_content)
590
+ {
591
+ this ->clear ();
592
+ this ->id = json[" id" ];
593
+ this ->current_link_type = json[" current_link_type" ].get <LinkType>();
594
+ }
591
595
592
596
if (!json[" groups" ].is_null ())
593
597
{
@@ -603,7 +607,7 @@ void GraphViewer::json_from(nlohmann::json json)
603
607
{
604
608
for (auto &json_node : json[" nodes" ])
605
609
{
606
- std::string nid = json_node[" id" ];
610
+ std::string nid = prefix_id + json_node[" id" ]. get <std::string>() ;
607
611
608
612
float x = json_node[" scene_position.x" ];
609
613
float y = json_node[" scene_position.y" ];
@@ -623,8 +627,8 @@ void GraphViewer::json_from(nlohmann::json json)
623
627
{
624
628
for (auto &json_link : json[" links" ])
625
629
{
626
- std::string node_out_id = json_link[" node_out_id" ];
627
- std::string node_in_id = json_link[" node_in_id" ];
630
+ std::string node_out_id = prefix_id + json_link[" node_out_id" ]. get <std::string>() ;
631
+ std::string node_in_id = prefix_id + json_link[" node_in_id" ]. get <std::string>() ;
628
632
std::string port_out_id = json_link[" port_out_id" ];
629
633
std::string port_in_id = json_link[" port_in_id" ];
630
634
0 commit comments