Commit d49cde5d authored by Aleks Kissinger's avatar Aleks Kissinger

reverse edge direction

parent 8fe8ff00
......@@ -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;
......
......@@ -81,6 +81,8 @@ public:
void setOutAngle(int outAngle);
void setWeight(qreal weight);
void reverse();
int tikzLine() const;
void setTikzLine(int tikzLine);
......
......@@ -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()
......
......@@ -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();
......
......@@ -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"/>
......
......@@ -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;
......
......@@ -77,6 +77,8 @@ public:
void reorderSelection(bool toFront);
void reverseSelectedEdges();
void getSelection(QSet<Node*> &selNodes, QSet<Edge*> &selEdges);
QSet<Node*> getSelectedNodes();
......
......@@ -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();
}
......@@ -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:
......
......@@ -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"
......
......@@ -2,7 +2,7 @@
QT += core gui widgets network
VERSION = 2.1.1
VERSION = 2.1.2
test {
CONFIG += testcase
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment