diff options
author | Aleks Kissinger <aleks0@gmail.com> | 2020-04-13 14:40:07 +0100 |
---|---|---|
committer | Aleks Kissinger <aleks0@gmail.com> | 2020-04-13 14:40:07 +0100 |
commit | 6dda16a24dfe7cbd0d90b77c57f1cf789210feb5 (patch) | |
tree | 7748bbbe8e484af230481ff092fcf7268c6af24b /src/gui/undocommands.cpp | |
parent | b48731917964d263175716a29a58d965cb726798 (diff) |
ability to make paths from edges
Diffstat (limited to 'src/gui/undocommands.cpp')
-rw-r--r-- | src/gui/undocommands.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/gui/undocommands.cpp b/src/gui/undocommands.cpp index 9a1ef34..a07f251 100644 --- a/src/gui/undocommands.cpp +++ b/src/gui/undocommands.cpp @@ -594,3 +594,51 @@ void ReverseEdgesCommand::redo() GraphUpdateCommand::redo(); } + +MakePathCommand::MakePathCommand(TikzScene *scene, + const QVector<Edge *> &edgeList, + const QMap<Edge *, GraphElementData *> &oldEdgeData, + QUndoCommand *parent) : + GraphUpdateCommand(scene, parent), + _edgeList(edgeList), _oldEdgeData(oldEdgeData) +{ +} + +void MakePathCommand::undo() +{ + Path *p = _edgeList.first()->path(); + p->removeEdges(); + _scene->graph()->removePath(p); + + foreach (Edge *e, _edgeList) { + if (e != _edgeList.first()) { + // setData transfers ownership, so make a copy + e->setData(_oldEdgeData[e]->copy()); + } + } + + GraphUpdateCommand::undo(); +} + +void MakePathCommand::redo() +{ + GraphElementData *npd = _edgeList.first()->data()->nonPathData(); + GraphElementData *d; + + Path *p = new Path(); + foreach (Edge *e, _edgeList) { + p->addEdge(e); + + if (e != _edgeList.first()) { + d = e->data()->pathData(); + d->mergeData(npd); + e->setData(d); + } + } + + delete npd; + + _scene->graph()->addPath(p); + + GraphUpdateCommand::redo(); +} |