summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2019-01-12 15:01:41 +0100
committerAleks Kissinger <aleks0@gmail.com>2019-01-12 15:11:00 +0100
commitd49cde5d0b948f24aa7b3bd9ad9b3b63333f2281 (patch)
tree573a28adec900d892ab14c2bc4a4902d61985d81
parent8fe8ff000d48460583f542b932d8af3e3d3ae008 (diff)
reverse edge direction
-rw-r--r--src/data/edge.cpp12
-rw-r--r--src/data/edge.h2
-rw-r--r--src/gui/mainmenu.cpp6
-rw-r--r--src/gui/mainmenu.h1
-rw-r--r--src/gui/mainmenu.ui9
-rw-r--r--src/gui/tikzscene.cpp19
-rw-r--r--src/gui/tikzscene.h2
-rw-r--r--src/gui/undocommands.cpp30
-rw-r--r--src/gui/undocommands.h11
-rw-r--r--src/tikzit.h2
-rw-r--r--tikzit.pro2
11 files changed, 94 insertions, 2 deletions
diff --git a/src/data/edge.cpp b/src/data/edge.cpp
index fcd9959..4803547 100644
--- a/src/data/edge.cpp
+++ b/src/data/edge.cpp
@@ -365,6 +365,18 @@ void Edge::setWeight(qreal weight)
_weight = weight;
}
+void Edge::reverse()
+{
+ Node *n = _source;
+ _source = _target;
+ _target = n;
+ int a = _inAngle;
+ _inAngle = _outAngle;
+ _outAngle = a;
+ _bend = -_bend;
+ updateData();
+}
+
int Edge::tikzLine() const
{
return _tikzLine;
diff --git a/src/data/edge.h b/src/data/edge.h
index 909824b..954145f 100644
--- a/src/data/edge.h
+++ b/src/data/edge.h
@@ -81,6 +81,8 @@ public:
void setOutAngle(int outAngle);
void setWeight(qreal weight);
+ void reverse();
+
int tikzLine() const;
void setTikzLine(int tikzLine);
diff --git a/src/gui/mainmenu.cpp b/src/gui/mainmenu.cpp
index 6f4f8db..d291390 100644
--- a/src/gui/mainmenu.cpp
+++ b/src/gui/mainmenu.cpp
@@ -227,6 +227,12 @@ void MainMenu::on_actionExtendRight_triggered()
tikzit->activeWindow()->tikzScene()->extendSelectionRight();
}
+void MainMenu::on_actionReverse_Edge_Direction_triggered()
+{
+ if (tikzit->activeWindow() != 0)
+ tikzit->activeWindow()->tikzScene()->reverseSelectedEdges();
+}
+
// Tikz
void MainMenu::on_actionParse_triggered()
diff --git a/src/gui/mainmenu.h b/src/gui/mainmenu.h
index 4d672cd..287019c 100644
--- a/src/gui/mainmenu.h
+++ b/src/gui/mainmenu.h
@@ -65,6 +65,7 @@ public slots:
void on_actionExtendDown_triggered();
void on_actionExtendLeft_triggered();
void on_actionExtendRight_triggered();
+ void on_actionReverse_Edge_Direction_triggered();
// Tools
void on_actionParse_triggered();
diff --git a/src/gui/mainmenu.ui b/src/gui/mainmenu.ui
index 08067aa..ddba6f0 100644
--- a/src/gui/mainmenu.ui
+++ b/src/gui/mainmenu.ui
@@ -72,6 +72,7 @@
<addaction name="separator"/>
<addaction name="menuReorder"/>
<addaction name="menuTransform"/>
+ <addaction name="actionReverse_Edge_Direction"/>
</widget>
<widget class="QMenu" name="menuTikz">
<property name="title">
@@ -365,6 +366,14 @@
<string>Preferences...</string>
</property>
</action>
+ <action name="actionReverse_Edge_Direction">
+ <property name="text">
+ <string>Reverse Edge Direction</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+/</string>
+ </property>
+ </action>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuView"/>
diff --git a/src/gui/tikzscene.cpp b/src/gui/tikzscene.cpp
index 4d14f43..9ef4c20 100644
--- a/src/gui/tikzscene.cpp
+++ b/src/gui/tikzscene.cpp
@@ -212,6 +212,25 @@ void TikzScene::reorderSelection(bool toFront)
_tikzDocument->undoStack()->push(cmd);
}
+void TikzScene::reverseSelectedEdges()
+{
+ // grab all the edges which are either selected themselves, or where
+ // both their source and target nodes are selected
+ QSet<Edge*> es;
+ foreach (Edge *e, graph()->edges()) {
+ if ((_edgeItems[e] && _edgeItems[e]->isSelected()) ||
+ (_nodeItems[e->source()] && _nodeItems[e->target()] &&
+ _nodeItems[e->source()]->isSelected() &&
+ _nodeItems[e->target()]->isSelected()))
+ {
+ es << e;
+ }
+ }
+
+ ReverseEdgesCommand *cmd = new ReverseEdgesCommand(this, es);
+ _tikzDocument->undoStack()->push(cmd);
+}
+
void TikzScene::refreshZIndices()
{
qreal z = 0.0;
diff --git a/src/gui/tikzscene.h b/src/gui/tikzscene.h
index 3e46f6d..e2068eb 100644
--- a/src/gui/tikzscene.h
+++ b/src/gui/tikzscene.h
@@ -77,6 +77,8 @@ public:
void reorderSelection(bool toFront);
+ void reverseSelectedEdges();
+
void getSelection(QSet<Node*> &selNodes, QSet<Edge*> &selEdges);
QSet<Node*> getSelectedNodes();
diff --git a/src/gui/undocommands.cpp b/src/gui/undocommands.cpp
index 82b9455..91509ed 100644
--- a/src/gui/undocommands.cpp
+++ b/src/gui/undocommands.cpp
@@ -539,3 +539,33 @@ void ReorderCommand::redo()
_scene->refreshZIndices();
GraphUpdateCommand::redo();
}
+
+ReverseEdgesCommand::ReverseEdgesCommand(TikzScene *scene,
+ QSet<Edge *> edgeSet,
+ QUndoCommand *parent) :
+ GraphUpdateCommand(scene, parent), _edgeSet(edgeSet)
+{
+}
+
+void ReverseEdgesCommand::undo()
+{
+ EdgeItem *ei;
+ foreach (Edge *e, _edgeSet) {
+ e->reverse();
+ ei = _scene->edgeItems()[e];
+ if (ei) ei->readPos();
+ }
+ GraphUpdateCommand::undo();
+}
+
+void ReverseEdgesCommand::redo()
+{
+ EdgeItem *ei;
+ foreach (Edge *e, _edgeSet) {
+ e->reverse();
+ ei = _scene->edgeItems()[e];
+ if (ei) ei->readPos();
+ }
+ GraphUpdateCommand::redo();
+}
+
diff --git a/src/gui/undocommands.h b/src/gui/undocommands.h
index ff51c90..42fed30 100644
--- a/src/gui/undocommands.h
+++ b/src/gui/undocommands.h
@@ -78,6 +78,17 @@ private:
int _newOutAngle;
};
+class ReverseEdgesCommand : public GraphUpdateCommand
+{
+public:
+ explicit ReverseEdgesCommand(TikzScene *scene, QSet<Edge*> edgeSet,
+ QUndoCommand *parent = nullptr);
+ void undo() override;
+ void redo() override;
+private:
+ QSet<Edge*> _edgeSet;
+};
+
class DeleteCommand : public GraphUpdateCommand
{
public:
diff --git a/src/tikzit.h b/src/tikzit.h
index 743e3f0..855efeb 100644
--- a/src/tikzit.h
+++ b/src/tikzit.h
@@ -49,7 +49,7 @@
#ifndef TIKZIT_H
#define TIKZIT_H
-#define TIKZIT_VERSION "2.1.1"
+#define TIKZIT_VERSION "2.1.2"
#include "mainwindow.h"
#include "mainmenu.h"
diff --git a/tikzit.pro b/tikzit.pro
index b7b155d..db1773c 100644
--- a/tikzit.pro
+++ b/tikzit.pro
@@ -2,7 +2,7 @@
QT += core gui widgets network
-VERSION = 2.1.1
+VERSION = 2.1.2
test {
CONFIG += testcase