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.cpp140
1 files changed, 136 insertions, 4 deletions
diff --git a/src/gui/undocommands.cpp b/src/gui/undocommands.cpp
index c5c26af..35345de 100644
--- a/src/gui/undocommands.cpp
+++ b/src/gui/undocommands.cpp
@@ -102,6 +102,9 @@ void EdgeBendCommand::undo()
foreach(EdgeItem *ei, _scene->edgeItems()) {
if (ei->edge() == _edge) {
ei->readPos();
+
+ Path *p = ei->edge()->path();
+ if (p) _scene->pathItems()[p]->readPos();
break;
}
}
@@ -118,6 +121,9 @@ void EdgeBendCommand::redo()
foreach(EdgeItem *ei, _scene->edgeItems()) {
if (ei->edge() == _edge) {
ei->readPos();
+
+ Path *p = ei->edge()->path();
+ if (p) _scene->pathItems()[p]->readPos();
break;
}
}
@@ -287,6 +293,9 @@ void ChangeEdgeModeCommand::undo()
// FIXME: this act strangely sometimes
_edge->setBasicBendMode(!_edge->basicBendMode());
_scene->edgeItems()[_edge]->readPos();
+ Path *p = _edge->path();
+ if (p) _scene->pathItems()[p]->readPos();
+
GraphUpdateCommand::undo();
}
@@ -294,6 +303,9 @@ void ChangeEdgeModeCommand::redo()
{
_edge->setBasicBendMode(!_edge->basicBendMode());
_scene->edgeItems()[_edge]->readPos();
+ Path *p = _edge->path();
+ if (p) _scene->pathItems()[p]->readPos();
+
GraphUpdateCommand::redo();
}
@@ -369,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);
@@ -399,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);
@@ -488,7 +516,7 @@ void ReflectNodesCommand::undo()
}
}
- _scene->refreshAdjacentEdges(_nodes.toList());
+ _scene->refreshAdjacentEdges(_nodes.values());
GraphUpdateCommand::undo();
}
@@ -501,7 +529,7 @@ void ReflectNodesCommand::redo()
}
}
- _scene->refreshAdjacentEdges(_nodes.toList());
+ _scene->refreshAdjacentEdges(_nodes.values());
GraphUpdateCommand::redo();
}
@@ -520,7 +548,7 @@ void RotateNodesCommand::undo()
}
}
- _scene->refreshAdjacentEdges(_nodes.toList());
+ _scene->refreshAdjacentEdges(_nodes.values());
GraphUpdateCommand::undo();
}
@@ -533,7 +561,7 @@ void RotateNodesCommand::redo()
}
}
- _scene->refreshAdjacentEdges(_nodes.toList());
+ _scene->refreshAdjacentEdges(_nodes.values());
GraphUpdateCommand::redo();
}
@@ -594,3 +622,107 @@ 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();
+
+ PathItem *pi = _scene->pathItems()[p];
+ _scene->removeItem(pi);
+ _scene->pathItems().remove(p);
+ delete pi;
+
+ 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());
+ }
+ }
+
+ _scene->refreshZIndices();
+ 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);
+
+ PathItem *pi = new PathItem(p);
+ _scene->addItem(pi);
+ _scene->pathItems().insert(p, pi);
+ pi->readPos();
+
+ _scene->refreshZIndices();
+ GraphUpdateCommand::redo();
+}
+
+SplitPathCommand::SplitPathCommand(TikzScene *scene,
+ const QSet<Path *> &paths,
+ QUndoCommand *parent) :
+ GraphUpdateCommand(scene, parent), _paths(paths)
+{
+ foreach (Path *p, paths) _edgeLists[p] = p->edges();
+}
+
+void SplitPathCommand::undo()
+{
+ foreach (Path *p, _paths) {
+ foreach (Edge *e, _edgeLists[p]) {
+ 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();
+}