From 1ca36f064da2a3619f0f8058f48e9f9dc6d07436 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sun, 23 Sep 2018 09:52:35 +0200 Subject: more consistent z-ordering --- src/gui/tikzscene.cpp | 16 ++++++++++++++++ src/gui/tikzscene.h | 1 + src/gui/undocommands.cpp | 10 ++++++++++ 3 files changed, 27 insertions(+) (limited to 'src') diff --git a/src/gui/tikzscene.cpp b/src/gui/tikzscene.cpp index 947620f..39f8b76 100644 --- a/src/gui/tikzscene.cpp +++ b/src/gui/tikzscene.cpp @@ -103,6 +103,8 @@ void TikzScene::graphReplaced() _nodeItems.insert(n, ni); addItem(ni); } + + refreshZIndices(); } void TikzScene::extendSelectionUp() @@ -177,6 +179,20 @@ void TikzScene::extendSelectionRight() } } +void TikzScene::refreshZIndices() +{ + qreal z = 0.0; + foreach (Edge *e, graph()->edges()) { + edgeItems()[e]->setZValue(z); + z += 1.0; + } + + foreach (Node *n, graph()->nodes()) { + nodeItems()[n]->setZValue(z); + z += 1.0; + } +} + void TikzScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (!_enabled) return; diff --git a/src/gui/tikzscene.h b/src/gui/tikzscene.h index 16af125..b7beca9 100644 --- a/src/gui/tikzscene.h +++ b/src/gui/tikzscene.h @@ -80,6 +80,7 @@ public slots: void extendSelectionDown(); void extendSelectionLeft(); void extendSelectionRight(); + void refreshZIndices(); protected: void mousePressEvent(QGraphicsSceneMouseEvent *event) override; diff --git a/src/gui/undocommands.cpp b/src/gui/undocommands.cpp index 2ed5034..7b254d1 100644 --- a/src/gui/undocommands.cpp +++ b/src/gui/undocommands.cpp @@ -157,6 +157,7 @@ void DeleteCommand::undo() if (_selEdges.contains(e)) ei->setSelected(true); } + _scene->refreshZIndices(); GraphUpdateCommand::undo(); } @@ -180,6 +181,7 @@ void DeleteCommand::redo() _scene->graph()->removeNode(n); } + _scene->refreshZIndices(); GraphUpdateCommand::redo(); } @@ -199,6 +201,7 @@ void AddNodeCommand::undo() //_scene->setBounds(_oldBounds); + _scene->refreshZIndices(); GraphUpdateCommand::undo(); } @@ -212,6 +215,7 @@ void AddNodeCommand::redo() //_scene->setBounds(_newBounds); + _scene->refreshZIndices(); GraphUpdateCommand::redo(); } @@ -228,6 +232,7 @@ void AddEdgeCommand::undo() delete ei; _scene->graph()->removeEdge(_edge); + _scene->refreshZIndices(); GraphUpdateCommand::undo(); } @@ -245,6 +250,7 @@ void AddEdgeCommand::redo() ei->stackBefore(_scene->nodeItems()[_scene->graph()->nodes().first()]); } + _scene->refreshZIndices(); GraphUpdateCommand::redo(); } @@ -361,6 +367,7 @@ void PasteCommand::undo() foreach(Node *n, _oldSelectedNodes) _scene->nodeItems()[n]->setSelected(true); foreach(Edge *e, _oldSelectedEdges) _scene->edgeItems()[e]->setSelected(true); + _scene->refreshZIndices(); GraphUpdateCommand::undo(); } @@ -384,6 +391,7 @@ void PasteCommand::redo() ni->setSelected(true); } + _scene->refreshZIndices(); GraphUpdateCommand::redo(); } @@ -428,6 +436,7 @@ void ReplaceGraphCommand::undo() } _scene->tikzDocument()->setGraph(_oldGraph); _scene->graphReplaced(); + GraphUpdateCommand::undo(); } void ReplaceGraphCommand::redo() @@ -439,6 +448,7 @@ void ReplaceGraphCommand::redo() } _scene->tikzDocument()->setGraph(_newGraph); _scene->graphReplaced(); + GraphUpdateCommand::redo(); } ReflectNodesCommand::ReflectNodesCommand(TikzScene *scene, QSet nodes, bool horizontal, QUndoCommand *parent) : -- cgit v1.2.3