[kgraphviewer-devel] Syntax error in .dot file (plus big thankyou)
Ivan Brezina
ibre5041 at ibrezina.net
Tue Oct 11 20:50:11 UTC 2011
Hi all,
first of all I would like to thank you for all the work you made on
kgraphviewer.
I'm about to use a part of it in another GNU project - Tora
(http://torasql.com/).
I spent a lot of time looking for some example of integrating graphwiz
with QT,
and your project is the best one can find on the Internet.
Would you mind if I used part of kgraphviewer as generic planar graph
visualization widget?
Would you accept patches that remove dependency on legacy QT3?
BTW: I've found that in some cases kgraphviewer produces .dot files
whose are not
syntactically correct. Command dot complains about syntax error but
processes them anyway.
For example this file has syntax error in it:
digraph "unnamed" {
graph [fontsize="11",id="unnamed"]
subgraph cluster_X1 {id="cluster_X1",label="X1",cluster_X1_T1_1
[comment="T1",fontsize="10",id="cluster_X1_T1_1",label="T1",name="T1"];
}
}
While this one is correct:
digraph "unnamed" {
graph [fontsize="11",id="unnamed"]
subgraph cluster_X1 {
graph[id="cluster_X1",label="X1"]
cluster_X1_T1_1
[comment="T1",fontsize="10",id="cluster_X1_T1_1",label="T1",name="T1"];
}
}
This patch adds graph declaration onto subgraph:
--- /home/ivan/devel/fragments/kgraphviewer/src/part/graphsubgraph.cpp
2011-10-11 21:38:03.942174147 +0200
+++ ../../src/ermodel/graphsubgraph.cpp 2011-10-11 21:23:14.554748779 +0200
@@ -283,8 +279,11 @@
QTextStream& operator<<(QTextStream& s, const GraphSubgraph& sg)
{
- s << "subgraph " << sg.id() << " {"
- << dynamic_cast<const GraphElement&>(sg);
+ s << "subgraph " << sg.id() << " {" << endl
+ << "graph [ "
+ << dynamic_cast<const GraphElement&>(sg)
+ << " ]" << endl;
+
foreach (const GraphElement* el, sg.content())
{
s << *(dynamic_cast<const GraphNode*>(el));
-- end --
This patch removes trailing comma in attributes list:
--- graphelement.cpp.orig 2011-10-11 22:42:17.712174781 +0200
+++ graphelement.cpp 2011-10-11 22:48:21.732174841 +0200
@@ -177,10 +177,12 @@
{
QMap<QString,QString>::const_iterator it, it_end;
it = n.attributes().begin(); it_end = n.attributes().end();
+ bool firstAttr = true;
for (;it != it_end; it++)
{
- if (!it.value().isEmpty())
- {
+ if (it.value().isEmpty())
+ continue;
+
if (it.key() == "label")
{
QString label = it.value();
@@ -188,7 +190,11 @@
{
label.replace(QRegExp("\n"),"\\n");
// kDebug() << it.key() << "=\"" << label << "\",";
- s << it.key() << "=\"" << label << "\",";
+ if (firstAttr)
+ firstAttr = false;
+ else
+ s << ',';
+ s << it.key() << "=\"" << label << '"';
}
}
else if (it.key() == "_draw_" || it.key() == "_ldraw_")
@@ -198,8 +204,11 @@
{
// kDebug() << it.key() << it.value();
- s << it.key() << "=\"" << it.value() << "\",";
- }
+ if (firstAttr)
+ firstAttr = false;
+ else
+ s << ',';
+ s << it.key() << "=\"" << it.value() << '"';
}
}
return s;
-- end --
Ivan
More information about the kgraphviewer-devel
mailing list