summaryrefslogtreecommitdiff
path: root/src/data
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
parent92d09d474eecb5bb48857408095e9c8564fe4337 (diff)
reflection
Diffstat (limited to 'src/data')
-rw-r--r--src/data/edgestyle.h2
-rw-r--r--src/data/graph.cpp60
-rw-r--r--src/data/graph.h12
-rw-r--r--src/data/nodestyle.h2
4 files changed, 73 insertions, 3 deletions
diff --git a/src/data/edgestyle.h b/src/data/edgestyle.h
index 069545e..eac060a 100644
--- a/src/data/edgestyle.h
+++ b/src/data/edgestyle.h
@@ -45,7 +45,7 @@ public:
ArrowTipStyle arrowTail() const;
DrawStyle drawStyle() const;
- QPen pen() const;
+ QPen pen() const override;
QPainterPath path() const override;
QPainterPath palettePath() const override;
QIcon icon() const override;
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;
diff --git a/src/data/graph.h b/src/data/graph.h
index 82e1f95..e9e2218 100644
--- a/src/data/graph.h
+++ b/src/data/graph.h
@@ -46,7 +46,8 @@ public:
void addEdge(Edge *e, int index);
void removeEdge(Edge *e);
int maxIntName();
- QString freshNodeName();
+ QRectF boundsForNodes(QSet<Node*> ns);
+ QString freshNodeName();
/*!
* \brief renameApart assigns fresh names to all of the nodes in "this",
@@ -93,6 +94,15 @@ public:
* \param graph
*/
void insertGraph(Graph *graph);
+
+ /*!
+ * \brief reflectNodes flips the given set of nodes horizontally or vertically,
+ * depending on the value of the second parameter.
+ * \param nds a set of nodes to flip
+ * \param horizontal a boolean determining whether to flip horizontally or
+ * vertically
+ */
+ void reflectNodes(QSet<Node*> nds, bool horizontal);
signals:
public slots:
diff --git a/src/data/nodestyle.h b/src/data/nodestyle.h
index 5eeef9b..c6fc0f6 100644
--- a/src/data/nodestyle.h
+++ b/src/data/nodestyle.h
@@ -39,7 +39,7 @@ public:
QColor fillColor() const;
QBrush brush() const;
- QPainterPath path() const;
+ QPainterPath path() const override;
Shape shape() const;
QPainterPath palettePath() const override;