diff options
author | Aleks Kissinger <aleks0@gmail.com> | 2020-04-18 15:30:31 +0100 |
---|---|---|
committer | Aleks Kissinger <aleks0@gmail.com> | 2020-04-18 15:30:31 +0100 |
commit | ef07176e5c5c8e2aa9ea5a380000302234f2934c (patch) | |
tree | db68c161dc6efec268b84e4c4209922294b3c718 /src | |
parent | 08ce6c91fd37c904362a5ec6f054bcd3ee061b74 (diff) |
deleting works correctly with paths
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/tikzscene.cpp | 33 | ||||
-rw-r--r-- | src/gui/undocommands.cpp | 9 | ||||
-rw-r--r-- | src/gui/undocommands.h | 6 |
3 files changed, 29 insertions, 19 deletions
diff --git a/src/gui/tikzscene.cpp b/src/gui/tikzscene.cpp index e510931..9da8639 100644 --- a/src/gui/tikzscene.cpp +++ b/src/gui/tikzscene.cpp @@ -250,13 +250,18 @@ void TikzScene::mergeNodes() Node *n = _tikzDocument->graph()->nodes()[i]; if (m1.contains(n)) delNodes.insert(i, n); } + + QSet<Path*> delPaths; for (int i = 0; i < _tikzDocument->graph()->edges().length(); ++i) { Edge *e = _tikzDocument->graph()->edges()[i]; - if (m1.contains(e->source()) || m1.contains(e->target())) delEdges.insert(i, e); + if (m1.contains(e->source()) || m1.contains(e->target())) { + delEdges.insert(i, e); + if (e->path()) delPaths << e->path(); + } } - DeleteCommand *cmd = new DeleteCommand(this, delNodes, delEdges, - selNodes, selEdges); - _tikzDocument->undoStack()->push(cmd); + _tikzDocument->undoStack()->push(new SplitPathCommand(this, delPaths)); + _tikzDocument->undoStack()->push(new DeleteCommand(this, delNodes, delEdges, + selNodes, selEdges)); _tikzDocument->undoStack()->endMacro(); } @@ -410,10 +415,9 @@ void TikzScene::splitPath() } } - QVector<Path*> paths; + QSet<Path*> paths; foreach (Edge *e, edges) { - Path *p = e->path(); - if (p && !paths.contains(p)) paths << p; + if (e->path()) paths << e->path(); } _tikzDocument->undoStack()->push(new SplitPathCommand(this, paths)); @@ -1121,6 +1125,7 @@ void TikzScene::deleteSelectedItems() QMap<int,Node*> deleteNodes; QMap<int,Edge*> deleteEdges; + QSet<Path*> deletePaths; for (int i = 0; i < _tikzDocument->graph()->nodes().length(); ++i) { Node *n = _tikzDocument->graph()->nodes()[i]; @@ -1131,14 +1136,20 @@ void TikzScene::deleteSelectedItems() Edge *e = _tikzDocument->graph()->edges()[i]; if (selEdges.contains(e) || selNodes.contains(e->source()) || - selNodes.contains(e->target())) deleteEdges.insert(i, e); + selNodes.contains(e->target())) + { + if (e->path()) deletePaths << e->path(); + deleteEdges.insert(i, e); + } } //qDebug() << "nodes:" << deleteNodes; //qDebug() << "edges:" << deleteEdges; - DeleteCommand *cmd = new DeleteCommand(this, deleteNodes, deleteEdges, - selNodes, selEdges); - _tikzDocument->undoStack()->push(cmd); + _tikzDocument->undoStack()->beginMacro("Delete"); + _tikzDocument->undoStack()->push(new SplitPathCommand(this, deletePaths)); + _tikzDocument->undoStack()->push(new DeleteCommand(this, deleteNodes, deleteEdges, + selNodes, selEdges)); + _tikzDocument->undoStack()->endMacro(); } void TikzScene::copyToClipboard() diff --git a/src/gui/undocommands.cpp b/src/gui/undocommands.cpp index 3b1109e..35345de 100644 --- a/src/gui/undocommands.cpp +++ b/src/gui/undocommands.cpp @@ -685,18 +685,17 @@ void MakePathCommand::redo() } SplitPathCommand::SplitPathCommand(TikzScene *scene, - const QVector<Path *> &paths, + const QSet<Path *> &paths, QUndoCommand *parent) : GraphUpdateCommand(scene, parent), _paths(paths) { - foreach (Path *p, paths) _edgeLists << p->edges(); + foreach (Path *p, paths) _edgeLists[p] = p->edges(); } void SplitPathCommand::undo() { - for (int i = 0; i < _paths.length(); ++i) { - Path *p = _paths[i]; - foreach (Edge *e, _edgeLists[i]) { + foreach (Path *p, _paths) { + foreach (Edge *e, _edgeLists[p]) { p->addEdge(e); } diff --git a/src/gui/undocommands.h b/src/gui/undocommands.h index 00b9a40..c10eecc 100644 --- a/src/gui/undocommands.h +++ b/src/gui/undocommands.h @@ -275,15 +275,15 @@ class SplitPathCommand : public GraphUpdateCommand { public: explicit SplitPathCommand(TikzScene *scene, - const QVector<Path*> &paths, + const QSet<Path*> &paths, QUndoCommand *parent = nullptr); void undo() override; void redo() override; private: - QVector<Path*> _paths; + QSet<Path*> _paths; // keep a copy of the edge lists so they can be added back to each path in undo() - QVector<QVector<Edge*>> _edgeLists; + QMap<Path*,QVector<Edge*>> _edgeLists; }; #endif // UNDOCOMMANDS_H |