00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #include <QVDirectedGraph>
00026
00027 bool operator<(const QVGraphLink &link1, const QVGraphLink &link2)
00028 {
00029 if (link1.x() < link2.x())
00030 return true;
00031
00032 if (link1.x() > link2.x())
00033 return false;
00034
00035 return link1.y() < link2.y();
00036 };
00037
00038 #include<QFile>
00039 #include<QTextStream>
00040 bool writeGraphToDotFile(const QString &fileName, const QVDirectedGraph<QString> &graph, const QStringList &nodeLabels)
00041 {
00042 Q_ASSERT(nodeLabels.empty() or (graph.numNodes() == nodeLabels.count()));
00043
00044 QFile file(fileName);
00045 if (not file.open(QIODevice::WriteOnly | QIODevice::Text))
00046 return false;
00047
00048 QString result;
00049
00050 result += "digraph StringGraph {\n";
00051 result += "node [shape=ellipse,color=black,style=bold];\n";
00052 result += "edge [arrowhead=open];\n";
00053
00054 for(int i = 0; i < graph.numNodes(); i++)
00055 result += "node" + QString::number(i) + QString(" [label=\"") + ((nodeLabels.empty())?("node" + QString::number(i)):nodeLabels[i]) + "\"];\n";
00056
00057 foreach(QVGraphLink link, graph.keys())
00058 result += "node" + QString::number(link.x()) + " -> node" + QString::number(link.y()) + " [label=\"" + graph[link] + "\"];\n";
00059
00060 result += "}";
00061
00062 QTextStream out(&file);
00063 out << qPrintable(result) << QString("\n");
00064 file.close();
00065
00066 return true;
00067 }
00068
00069