[kgraphviewer-devel] [kgraphviewer] src/part: An attribute ID is not allowed for subgraph. But graph in subgraph can have it's own ID.

Milian Wolff mail at milianw.de
Fri Mar 16 15:48:05 UTC 2012


Git commit 182e4de7f13dfa557a58ed9b626e058d7605547c by Milian Wolff.
Committed on 16/03/2012 at 16:47.
Pushed by mwolff into branch 'master'.

An attribute ID is not allowed for subgraph. But graph in subgraph can have it's own ID.

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"];
}
}

REVIEW: 102968

Many thanks to Ivan Brezina for this patch

M  +12   -3    src/part/graphelement.cpp
M  +4    -2    src/part/graphsubgraph.cpp

http://commits.kde.org/kgraphviewer/182e4de7f13dfa557a58ed9b626e058d7605547c

diff --git a/src/part/graphelement.cpp b/src/part/graphelement.cpp
index bc409f8..679eccb 100644
--- a/src/part/graphelement.cpp
+++ b/src/part/graphelement.cpp
@@ -176,6 +176,7 @@ void GraphElement::exportToGraphviz(void* element) const
 QTextStream& operator<<(QTextStream& s, const GraphElement& n)
 {
   QMap<QString,QString>::const_iterator it, it_end;
+  bool firstAttr = true;
   it = n.attributes().begin(); it_end = n.attributes().end();
   for (;it != it_end; it++)
   {
@@ -188,7 +189,11 @@ QTextStream& operator<<(QTextStream& s, const GraphElement& n)
         {
           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_")
@@ -197,8 +202,12 @@ QTextStream& operator<<(QTextStream& s, const GraphElement& n)
       else if (n.originalAttributes().isEmpty() || n.originalAttributes().contains(it.key()))
       {
 //         kDebug() << it.key() << it.value();
-        
-          s << it.key() << "=\"" << it.value() << "\",";
+
+          if (firstAttr)
+	    firstAttr = false;
+          else
+	    s << ',';
+          s << it.key() << "=\"" << it.value() << '"';
       }
     }
   }
diff --git a/src/part/graphsubgraph.cpp b/src/part/graphsubgraph.cpp
index 07bc8db..82e63cd 100644
--- a/src/part/graphsubgraph.cpp
+++ b/src/part/graphsubgraph.cpp
@@ -283,8 +283,10 @@ void GraphSubgraph::retrieveSelectedElementsIds(QList<QString> selection)
 
 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));


More information about the kgraphviewer-devel mailing list