From 7d94302712e30ad7bd54306efd995f45b4c5ea44 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Thu, 10 Jan 2019 16:52:40 +0100 Subject: [PATCH] ui: Remove virtual nodes in depth graph edges when moving nodes (issue #639) --- .../component/controller/GraphController.cpp | 21 ++++++++++++ .../qt/view/graphElements/QtGraphEdge.cpp | 5 +++ .../qt/view/graphElements/QtGraphEdge.h | 1 + .../qt/view/graphElements/QtGraphNode.cpp | 1 + testing/graph_view/data/depth_graph_tests.cpp | 34 ++++++++++++++++++- 5 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index 8f77989e..11848d3d 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -516,6 +516,27 @@ void GraphController::handleMessage(MessageGraphNodeMove* message) { node->position += message->delta; + if (m_graph->getTrailMode() != Graph::TRAIL_NONE) + { + std::set childNodeIds; + for (const std::pair& p : m_topLevelAncestorIds) + { + if (p.second == message->tokenId) + { + childNodeIds.insert(p.first); + } + } + + for (std::shared_ptr edge : m_dummyEdges) + { + if (childNodeIds.find(edge->ownerId) != childNodeIds.end() || + childNodeIds.find(edge->targetId) != childNodeIds.end()) + { + edge->path.clear(); + } + } + } + if (message->isReplayed()) { buildGraph(message, GraphView::GraphParams()); diff --git a/src/lib_gui/qt/view/graphElements/QtGraphEdge.cpp b/src/lib_gui/qt/view/graphElements/QtGraphEdge.cpp index ff180212..aa033019 100644 --- a/src/lib_gui/qt/view/graphElements/QtGraphEdge.cpp +++ b/src/lib_gui/qt/view/graphElements/QtGraphEdge.cpp @@ -492,3 +492,8 @@ void QtGraphEdge::setUseBezier(bool useBezier) m_useBezier = useBezier; m_isHorizontal = true; } + +void QtGraphEdge::clearPath() +{ + m_path.clear(); +} diff --git a/src/lib_gui/qt/view/graphElements/QtGraphEdge.h b/src/lib_gui/qt/view/graphElements/QtGraphEdge.h index 2a654c50..010f7da1 100644 --- a/src/lib_gui/qt/view/graphElements/QtGraphEdge.h +++ b/src/lib_gui/qt/view/graphElements/QtGraphEdge.h @@ -58,6 +58,7 @@ public: void setIsTrailEdge(std::vector path, bool horizontal); void setUseBezier(bool useBezier); + void clearPath(); protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent* event); diff --git a/src/lib_gui/qt/view/graphElements/QtGraphNode.cpp b/src/lib_gui/qt/view/graphElements/QtGraphNode.cpp index b5289d88..49843f72 100644 --- a/src/lib_gui/qt/view/graphElements/QtGraphNode.cpp +++ b/src/lib_gui/qt/view/graphElements/QtGraphNode.cpp @@ -506,6 +506,7 @@ void QtGraphNode::notifyEdgesAfterMove() forEachEdge( [](QtGraphEdge* edge) { + edge->clearPath(); edge->updateLine(); } ); diff --git a/testing/graph_view/data/depth_graph_tests.cpp b/testing/graph_view/data/depth_graph_tests.cpp index 88f120ad..11c60847 100644 --- a/testing/graph_view/data/depth_graph_tests.cpp +++ b/testing/graph_view/data/depth_graph_tests.cpp @@ -151,6 +151,38 @@ void level_5_func() // END ------------------------------------------------------------------------ +// TEST: virtual nodes removed when moving nodes +// START ---------------------------------------------------------------------- + +namespace virtual_nodes +{ +void func1(); // <- ACTION 1: activate +void func2(); +void func3(); +void func4(); + +struct Parent +{ + static void func5(); +}; + +void func1() { func2(); Parent::func5(); } +void func2() { func3(); } +void func3() { func4(); Parent::func5(); } +void func4() { Parent::func5(); } +void func5() { } +} + +// ACTION 2: show callee graph +// ACTION 3: move func5 above node func2 +// RESULT 3: virtual nodes are removed from the graph routes + +// ACTION 4: activate func4 +// ACTION 5: undo +// RESULT 5: the depth graph is restored with the virtual nodes removed + +// END ------------------------------------------------------------------------ + // TEST: pentagram graph // START ---------------------------------------------------------------------- @@ -170,7 +202,7 @@ void func4() { func1(); func2(); func3(); func4(); func5(); } void func5() { func1(); func2(); func3(); func4(); func5(); } } -// ACTION 2: show caller and calle graph +// ACTION 2: show caller and callee graph // RESULT 2: layout works without crash // END ------------------------------------------------------------------------