From 08ce6c91fd37c904362a5ec6f054bcd3ee061b74 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sat, 18 Apr 2020 15:09:39 +0100 Subject: fixed pasting for paths --- src/data/graph.cpp | 26 +++++++++++++++++++++++++- src/gui/undocommands.cpp | 16 ++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/data/graph.cpp b/src/data/graph.cpp index 979423e..74de24d 100644 --- a/src/data/graph.cpp +++ b/src/data/graph.cpp @@ -360,9 +360,33 @@ Graph *Graph::copyOfSubgraphWithNodes(QSet nds) g->addNode(n1); } } + + QMap edgeTable; foreach (Edge *e, edges()) { if (nds.contains(e->source()) && nds.contains(e->target())) { - g->addEdge(e->copy(&nodeTable)); + Edge *e1 = e->copy(&nodeTable); + g->addEdge(e1); + edgeTable.insert(e,e1); + } + } + + // add a copy of a path to the new graph if all of the edges are there + foreach (Path *p, paths()) { + bool allEdges = true; + Path *p1 = new Path(); + foreach (Edge *e1, p->edges()) { + if (edgeTable.contains(e1)) { + p1->addEdge(edgeTable[e1]); + } else { + allEdges = false; + break; + } + } + if (allEdges) { + g->addPath(p1); + } else { + p1->removeEdges(); + delete p1; } } diff --git a/src/gui/undocommands.cpp b/src/gui/undocommands.cpp index 9771f44..3b1109e 100644 --- a/src/gui/undocommands.cpp +++ b/src/gui/undocommands.cpp @@ -381,6 +381,16 @@ void PasteCommand::undo() { _scene->clearSelection(); + foreach (Path *p, _graph->paths()) { + PathItem *pi = _scene->pathItems()[p]; + _scene->pathItems().remove(p); + _scene->removeItem(pi); + delete pi; + + p->removeEdges(); + _scene->graph()->removePath(p); + } + foreach (Edge *e, _graph->edges()) { EdgeItem *ei = _scene->edgeItems()[e]; _scene->edgeItems().remove(e); @@ -411,6 +421,12 @@ void PasteCommand::redo() _scene->clearSelection(); _scene->graph()->insertGraph(_graph); + foreach (Path *p, _graph->paths()) { + PathItem *pi = new PathItem(p); + _scene->pathItems().insert(p, pi); + _scene->addItem(pi); + } + foreach (Edge *e, _graph->edges()) { e->attachStyle(); // in case styles have changed EdgeItem *ei = new EdgeItem(e); -- cgit v1.2.3