summaryrefslogtreecommitdiff
path: root/src/data
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2018-08-01 17:23:00 +0200
committerAleks Kissinger <aleks0@gmail.com>2018-08-01 17:23:00 +0200
commit74551d71e128efe0f105b52e84420555b70b9f6d (patch)
treea582fb097fa559bca18313a442440c5e744fe654 /src/data
parent7f074813bdb2bfca2f7a9933e7c922132197aaba (diff)
added rotation
Diffstat (limited to 'src/data')
-rw-r--r--src/data/graph.cpp38
-rw-r--r--src/data/graph.h8
2 files changed, 46 insertions, 0 deletions
diff --git a/src/data/graph.cpp b/src/data/graph.cpp
index 3123485..7d71ceb 100644
--- a/src/data/graph.cpp
+++ b/src/data/graph.cpp
@@ -327,6 +327,44 @@ void Graph::reflectNodes(QSet<Node*> nds, bool horizontal)
}
}
+void Graph::rotateNodes(QSet<Node*> nds, bool clockwise)
+{
+ QRectF bds = boundsForNodes(nds);
+ // QPointF ctr = bds.center();
+ // ctr.setX((float)floor(ctr.x() * 4.0f) / 4.0f);
+ // ctr.setY((float)floor(ctr.y() * 4.0f) / 4.0f);
+ float sign = (clockwise) ? 1.0f : -1.0f;
+
+ QPointF p;
+ // float dx, dy;
+ foreach(Node *n, nds) {
+ p = n->point();
+ // dx = p.x() - ctr.x();
+ // dy = p.y() - ctr.y();
+ n->setPoint(QPointF(sign * p.y(), -sign * p.x()));
+ }
+
+ int newIn, newOut;
+ foreach (Edge *e, _edges) {
+ if (nds.contains(e->source()) && nds.contains(e->target())) {
+ // update angles if necessary. Note that "basic" bends are computed based
+ // on node position, so they don't need to be updated.
+ if (!e->basicBendMode()) {
+ newIn = e->inAngle() - sign * 90;
+ newOut = e->outAngle() - sign * 90;
+
+ // normalise the angle to be within (-180,180]
+ if (newIn > 180) newIn -= 360;
+ else if (newIn <= -180) newIn += 360;
+ if (newOut > 180) newOut -= 360;
+ else if (newOut <= -180) newOut += 360;
+ e->setInAngle(newIn);
+ e->setOutAngle(newOut);
+ }
+ }
+ }
+}
+
void Graph::setBbox(const QRectF &bbox)
{
_bbox = bbox;
diff --git a/src/data/graph.h b/src/data/graph.h
index e9e2218..404fd8c 100644
--- a/src/data/graph.h
+++ b/src/data/graph.h
@@ -103,6 +103,14 @@ public:
* vertically
*/
void reflectNodes(QSet<Node*> nds, bool horizontal);
+
+ /*!
+ * \brief rotateNodes rotates the given set of nodes clockwise or counter-clockwise,
+ * depending on the value of the second parameter.
+ * \param nds a set of nodes to flip
+ * \param clockwose a boolean determining whether to rotate clockwise or counter-clockwise
+ */
+ void rotateNodes(QSet<Node*> nds, bool clockwise);
signals:
public slots: