summaryrefslogtreecommitdiff
path: root/src/gui/undocommands.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/undocommands.cpp')
-rw-r--r--src/gui/undocommands.cpp48
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();
+}