diff options
author | Aleks Kissinger <aleks0@gmail.com> | 2018-03-18 11:58:33 -0400 |
---|---|---|
committer | Aleks Kissinger <aleks0@gmail.com> | 2018-03-18 11:58:33 -0400 |
commit | 8b8ea9395bdda4bb1404497ff654b82098084822 (patch) | |
tree | c92d720990686acda5eeba18b028fe1e4b656a25 /src/data | |
parent | 3cea1514203a451c0a8806d276807863b463a78f (diff) |
finally got bboxes working...i think
Diffstat (limited to 'src/data')
-rw-r--r-- | src/data/graph.cpp | 23 | ||||
-rw-r--r-- | src/data/graph.h | 14 |
2 files changed, 27 insertions, 10 deletions
diff --git a/src/data/graph.cpp b/src/data/graph.cpp index 7a5fedc..208cd00 100644 --- a/src/data/graph.cpp +++ b/src/data/graph.cpp @@ -66,6 +66,19 @@ int Graph::maxIntName() return max; } +QRectF Graph::realBbox() +{ + float maxX = 0.0f; + QRectF rect = bbox(); + foreach (Node *n, _nodes) { + rect = rect.united(QRectF(n->point().x()-0.5f, + n->point().y()-0.5f, + 1.0f, 1.0f)); + } + + return rect; +} + QString Graph::freshNodeName() { return QString::number(maxIntName() + 1); @@ -228,14 +241,8 @@ Graph *Graph::copyOfSubgraphWithNodes(QSet<Node *> nds) void Graph::insertGraph(Graph *graph) { QMap<Node*,Node*> nodeTable; - foreach (Node *n, graph->nodes()) { - Node *n1 = n->copy(); - nodeTable.insert(n, n1); - addNode(n1); - } - foreach (Edge *e, graph->edges()) { - addEdge(e->copy(&nodeTable)); - } + foreach (Node *n, graph->nodes()) addNode(n); + foreach (Edge *e, graph->edges()) addEdge(e); } void Graph::setBbox(const QRectF &bbox) diff --git a/src/data/graph.h b/src/data/graph.h index 4d575e4..d00d2b2 100644 --- a/src/data/graph.h +++ b/src/data/graph.h @@ -48,6 +48,15 @@ public: bool hasBbox(); void clearBbox(); + /*! + * \brief realBbox computes the union of the user-defined + * bounding box, and the bounding boxes of the graph's + * contents. + * + * \return + */ + QRectF realBbox(); + QString tikz(); /*! @@ -59,9 +68,10 @@ public: Graph *copyOfSubgraphWithNodes(QSet<Node*> nds); /*! - * \brief insertGraph inserts a copy of the given graph. Prior to calling this + * \brief insertGraph inserts the given graph into "this". Prior to calling this * method, the node names in the given graph should be made fresh via - * "renameApart". + * "renameApart". Note that the parameter "graph" relinquishes ownership of its + * nodes and edges, so it should be not be allowed to exist longer than "this". * \param graph */ void insertGraph(Graph *graph); |