From e333ef9cb80e40637235198f9c113fa8cfe0fceb Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Mon, 13 Apr 2020 16:54:08 +0100 Subject: split path works --- src/gui/undocommands.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/gui/undocommands.cpp') diff --git a/src/gui/undocommands.cpp b/src/gui/undocommands.cpp index 87d5a13..9771f44 100644 --- a/src/gui/undocommands.cpp +++ b/src/gui/undocommands.cpp @@ -667,3 +667,47 @@ void MakePathCommand::redo() _scene->refreshZIndices(); GraphUpdateCommand::redo(); } + +SplitPathCommand::SplitPathCommand(TikzScene *scene, + const QVector &paths, + QUndoCommand *parent) : + GraphUpdateCommand(scene, parent), _paths(paths) +{ + foreach (Path *p, paths) _edgeLists << p->edges(); +} + +void SplitPathCommand::undo() +{ + for (int i = 0; i < _paths.length(); ++i) { + Path *p = _paths[i]; + foreach (Edge *e, _edgeLists[i]) { + p->addEdge(e); + } + + _scene->graph()->addPath(p); + + PathItem *pi = new PathItem(p); + _scene->addItem(pi); + _scene->pathItems().insert(p, pi); + pi->readPos(); + } + + _scene->refreshZIndices(); + GraphUpdateCommand::undo(); +} + +void SplitPathCommand::redo() +{ + foreach (Path *p, _paths) { + PathItem *pi = _scene->pathItems()[p]; + _scene->removeItem(pi); + _scene->pathItems().remove(p); + delete pi; + + p->removeEdges(); + _scene->graph()->removePath(p); + } + + _scene->refreshZIndices(); + GraphUpdateCommand::redo(); +} -- cgit v1.2.3