summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2009-08-12 07:06:38 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-08-12 07:06:38 (GMT)
commit1d3de98158b9409fa63e2e7cf8d3ca8b77f26285 (patch)
tree6c76f29182bb1f865deea1843a9bd74d12c66855 /src
parente2436e25b066ed8236b9cba3483d4a0b87500c91 (diff)
downloadQt-1d3de98158b9409fa63e2e7cf8d3ca8b77f26285.zip
Qt-1d3de98158b9409fa63e2e7cf8d3ca8b77f26285.tar.gz
Qt-1d3de98158b9409fa63e2e7cf8d3ca8b77f26285.tar.bz2
Added Graph::connections().
This gives a list of all "edges" in the graph, but each edge is specified as a pair of vertices, since you cannot easily know the two AnchorVertex'es of an EdgeData. Added some debug stuff.
Diffstat (limited to 'src')
-rw-r--r--src/gui/graphicsview/qgraph_p.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/gui/graphicsview/qgraph_p.h b/src/gui/graphicsview/qgraph_p.h
index 053114b..3abbe3b 100644
--- a/src/gui/graphicsview/qgraph_p.h
+++ b/src/gui/graphicsview/qgraph_p.h
@@ -30,6 +30,14 @@ public:
return column.key();
}
+ inline Vertex *from() const {
+ return row.key();
+ }
+
+ inline Vertex *to() const {
+ return column.key();
+ }
+
inline bool operator==(const const_iterator &o) const { return !(*this != o); }
inline bool operator!=(const const_iterator &o) const {
if (row == g->m_graph.end()) {
@@ -83,6 +91,15 @@ public:
void createEdge(Vertex *first, Vertex *second, EdgeData *data)
{
// Creates a bidirectional edge
+#if 0
+ qDebug("Graph::createEdge(): %s",
+ qPrintable(QString::fromAscii("%1-%2")
+ .arg(first->toString()).arg(second->toString())));
+#endif
+ if (edgeData(first, second)) {
+ qWarning(qPrintable(QString::fromAscii("%1-%2 already has an edge")
+ .arg(first->toString()).arg(second->toString())));
+ }
createDirectedEdge(first, second, data);
createDirectedEdge(second, first, data);
}
@@ -90,6 +107,11 @@ public:
void removeEdge(Vertex *first, Vertex *second)
{
// Removes a bidirectional edge
+#if 0
+ qDebug("Graph::removeEdge(): %s",
+ qPrintable(QString::fromAscii("%1-%2")
+ .arg(first->toString()).arg(second->toString())));
+#endif
EdgeData *data = edgeData(first, second);
removeDirectedEdge(first, second);
removeDirectedEdge(second, first);
@@ -98,6 +120,11 @@ public:
EdgeData *takeEdge(Vertex* first, Vertex* second)
{
+#if 0
+ qDebug("Graph::takeEdge(): %s",
+ qPrintable(QString::fromAscii("%1-%2")
+ .arg(first->toString()).arg(second->toString())));
+#endif
// Removes a bidirectional edge
EdgeData *data = edgeData(first, second);
if (data) {
@@ -129,6 +156,19 @@ public:
return setOfVertices;
}
+ QList<QPair<Vertex*, Vertex*> > connections() const {
+ QList<QPair<Vertex*, Vertex*> > conns;
+ for (const_iterator it = constBegin(); it != constEnd(); ++it) {
+ Vertex *from = it.from();
+ Vertex *to = it.to();
+ // do not return (from,to) *and* (to,from)
+ if (from < to) {
+ conns.append(qMakePair(from, to));
+ }
+ }
+ return conns;
+ }
+
QString serializeToDot() { // traversal
QString strVertices;
QString edges;