summaryrefslogtreecommitdiff
path: root/src/data/graph.cpp
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2018-07-20 14:19:08 +0200
committerAleks Kissinger <aleks0@gmail.com>2018-07-20 14:19:08 +0200
commit7bdf1bbb2b65612bd3f349562ca622f28dc1abff (patch)
tree1cc9383a6cd8e6b3201920f48de072b48d09c1f0 /src/data/graph.cpp
parent92d09d474eecb5bb48857408095e9c8564fe4337 (diff)
reflection
Diffstat (limited to 'src/data/graph.cpp')
-rw-r--r--src/data/graph.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/data/graph.cpp b/src/data/graph.cpp
index 7ed3e91..3123485 100644
--- a/src/data/graph.cpp
+++ b/src/data/graph.cpp
@@ -98,6 +98,29 @@ QRectF Graph::realBbox()
return rect;
}
+QRectF Graph::boundsForNodes(QSet<Node*>nds) {
+ QPointF p;
+ QPointF tl;
+ QPointF br;
+ bool hasPoints = false;
+ foreach (Node *n, nds) {
+ p = n->point();
+ if (!hasPoints) {
+ hasPoints = true;
+ tl = p;
+ br = p;
+ } else {
+ if (p.x() < tl.x()) tl.setX(p.x());
+ if (p.y() > tl.y()) tl.setY(p.y());
+ if (p.x() > br.x()) br.setX(p.x());
+ if (p.y() < br.y()) br.setY(p.y());
+ }
+ }
+
+ QRectF rect(tl, br);
+ return rect;
+}
+
QString Graph::freshNodeName()
{
return QString::number(maxIntName() + 1);
@@ -267,6 +290,43 @@ void Graph::insertGraph(Graph *graph)
foreach (Edge *e, graph->edges()) addEdge(e);
}
+void Graph::reflectNodes(QSet<Node*> nds, bool horizontal)
+{
+ QRectF bds = boundsForNodes(nds);
+ float ctr;
+ if (horizontal) ctr = bds.center().x();
+ else ctr = bds.center().y();
+
+ QPointF p;
+ foreach(Node *n, nds) {
+ p = n->point();
+ if (horizontal) p.setX(2 * ctr - p.x());
+ else p.setY(2 * ctr - p.y());
+ n->setPoint(p);
+ }
+
+ foreach (Edge *e, _edges) {
+ if (nds.contains(e->source()) && nds.contains(e->target())) {
+ if (!e->basicBendMode()) {
+ if (horizontal) {
+ if (e->inAngle() < 0) e->setInAngle(-180 - e->inAngle());
+ else e->setInAngle(180 - e->inAngle());
+
+ if (e->outAngle() < 0) e->setOutAngle(-180 - e->outAngle());
+ else e->setOutAngle(180 - e->outAngle());
+ }
+ else {
+ e->setInAngle(-e->inAngle());
+ e->setOutAngle(-e->outAngle());
+ }
+ }
+ else {
+ e->setBend(-e->bend());
+ }
+ }
+ }
+}
+
void Graph::setBbox(const QRectF &bbox)
{
_bbox = bbox;