[kgraphviewer-devel] [KGraphViewer] e5d43b0: Consistent lower case file naming for all files

Kevin Funk krf at electrostorm.net
Fri Dec 10 18:49:04 CET 2010


	A	 src/kgraphviz/support/fontscache.h	 [License: UNKNOWN]


	A	 src/kgraphviz/support/fontscache.cpp	 [License: UNKNOWN]


	A	 src/kgraphviz/support/dotgraphparsinghelper.h	 [License: UNKNOWN]


	A	 src/kgraphviz/support/dotgraphparsinghelper.cpp	 [License: UNKNOWN]

commit e5d43b01d287f26d0b21bea2ec8c359dabe7bec2
Author: Kevin Funk <krf at electrostorm.net>
Date:   Fri Dec 10 18:44:46 2010 +0100

    Consistent lower case file naming for all files

diff --git a/src/kgraphviz/CMakeLists.txt b/src/kgraphviz/CMakeLists.txt
index c2ee72c..65b2ce6 100644
--- a/src/kgraphviz/CMakeLists.txt
+++ b/src/kgraphviz/CMakeLists.txt
@@ -31,8 +31,8 @@ set( kgraphvz_LIB_SRCS
   support/layoutagraphthread.cpp
   support/dot2qtconsts.cpp
   support/dotgrammar.cpp
-  support/DotGraphParsingHelper.cpp
-  support/FontsCache.cpp
+  support/dotgraphparsinghelper.cpp
+  support/fontscache.cpp
 )
 
 kde4_add_library(kgraphviz SHARED ${kgraphvz_LIB_SRCS})
diff --git a/src/kgraphviz/canvasedge.cpp b/src/kgraphviz/canvasedge.cpp
index c6aaf8e..1104b9b 100644
--- a/src/kgraphviz/canvasedge.cpp
+++ b/src/kgraphviz/canvasedge.cpp
@@ -31,7 +31,7 @@
 #include "graphedge.h"
 #include "support/dotdefaults.h"
 #include "support/dot2qtconsts.h"
-#include "support/FontsCache.h"
+#include "support/fontscache.h"
 
 #include <KAction>
 #include <KDebug>
diff --git a/src/kgraphviz/canvaselement.cpp b/src/kgraphviz/canvaselement.cpp
index 94c6eb3..f5aa2c7 100644
--- a/src/kgraphviz/canvaselement.cpp
+++ b/src/kgraphviz/canvaselement.cpp
@@ -22,7 +22,7 @@
 #include "graphelement.h"
 #include "support/dotdefaults.h"
 #include "support/dot2qtconsts.h"
-#include "support/FontsCache.h"
+#include "support/fontscache.h"
 
 #include <stdlib.h>
 #include <math.h>
diff --git a/src/kgraphviz/canvasnode.cpp b/src/kgraphviz/canvasnode.cpp
index ab37cc4..c84e518 100644
--- a/src/kgraphviz/canvasnode.cpp
+++ b/src/kgraphviz/canvasnode.cpp
@@ -34,7 +34,6 @@
 #include "graphnode.h"
 #include "support/dotdefaults.h"
 #include "support/dot2qtconsts.h"
-#include "support/FontsCache.h"
 
 #include <stdlib.h>
 #include <math.h>
diff --git a/src/kgraphviz/dotgraph.cpp b/src/kgraphviz/dotgraph.cpp
index 27150f6..4d7bf01 100644
--- a/src/kgraphviz/dotgraph.cpp
+++ b/src/kgraphviz/dotgraph.cpp
@@ -23,7 +23,7 @@
 #include "canvasnode.h"
 #include "canvassubgraph.h"
 #include "support/dotgrammar.h"
-#include "support/DotGraphParsingHelper.h"
+#include "support/dotgraphparsinghelper.h"
 
 #include <math.h>
 #include <iostream>
diff --git a/src/kgraphviz/dotgraphview.cpp b/src/kgraphviz/dotgraphview.cpp
index 5d73c8d..4f25fa4 100644
--- a/src/kgraphviz/dotgraphview.cpp
+++ b/src/kgraphviz/dotgraphview.cpp
@@ -45,7 +45,7 @@
 
 #include "graphexporter.h"
 #include "support/dot2qtconsts.h"
-#include "support/FontsCache.h"
+#include "support/fontscache.h"
 #include "support/loadagraphthread.h"
 #include "support/layoutagraphthread.h"
 
diff --git a/src/kgraphviz/support/DotGraphParsingHelper.cpp b/src/kgraphviz/support/DotGraphParsingHelper.cpp
deleted file mode 100644
index 0be9e81..0000000
--- a/src/kgraphviz/support/DotGraphParsingHelper.cpp
+++ /dev/null
@@ -1,344 +0,0 @@
-/* This file is part of KGraphViewer.
-   Copyright (C) 2006-2007 Gael de Chalendar <kleag at free.fr>
-
-   KGraphViewer is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public
-   License as published by the Free Software Foundation, version 2.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA
-*/
-
-
-#include "DotGraphParsingHelper.h"
-#include "dotgraph.h"
-#include "dotgrammar.h"
-#include "dotdefaults.h"
-//#include "graphsubgraph.h"
-#include "graphnode.h"
-#include "graphedge.h"
-
-#include <boost/throw_exception.hpp>
-#include <boost/spirit/core.hpp>
-#include <boost/spirit/utility/distinct.hpp>
-#include <boost/spirit/utility/loops.hpp>
-#include <boost/spirit/utility/confix.hpp>
-
-
-#include <iostream>
-
-#include <kdebug.h>
-    
-#include <QFile>
-#include<QUuid>
-
-using namespace std;
-
-extern KGraphViewer::DotGraphParsingHelper* phelper;
-
-namespace KGraphViewer
-{
-#define KGV_MAX_ITEMS_TO_LOAD std::numeric_limits<int>::max()
-
-DotGraphParsingHelper::DotGraphParsingHelper():
-  attrid(),
-  valid(),
-  attributed(),
-  subgraphid(),
-  uniq(0),
-  attributes(),
-  graphAttributes(),
-  nodesAttributes(),
-  edgesAttributes(),
-  graphAttributesStack(),
-  nodesAttributesStack(),
-  edgesAttributesStack(),
-  edgebounds(),
-  z(0),
-  maxZ(0),
-  graph(0),
-  gs(0),
-  gn(0),
-  ge(0)
-{
-}
-
-void DotGraphParsingHelper::setgraphelementattributes(GraphElement* ge, const AttributesMap& attributes)
-{
-  AttributesMap::const_iterator it, it_end;
-  it = attributes.begin(); it_end = attributes.end();
-  for (; it != it_end; it++)
-  {
-//     kDebug() << "    " << QString::fromStdString((*it).first) << "\t=\t'" << QString::fromStdString((*it).second) <<"'";
-    if ((*it).first=="label")
-    {
-      QString label = QString::fromUtf8((*it).second.c_str());
-      label.replace("\\n","\n");
-      (*ge).attributes()["label"] = label;
-    }
-    else
-    {
-      (*ge).attributes()[QString::fromStdString((*it).first)] =
-      QString::fromStdString((*it).second);
-    }
-  }
-  
-  if (attributes.find("_draw_") != attributes.end())
-  {
-    parse_renderop((attributes.find("_draw_"))->second, ge->renderOperations());
-//     kDebug() << "element renderOperations size is now " << ge->renderOperations().size();
-  }
-  if (attributes.find("_ldraw_") != attributes.end())
-  {
-    parse_renderop(attributes.find("_ldraw_")->second, ge->renderOperations());
-//     kDebug() << "element renderOperations size is now " << ge->renderOperations().size();
-  }
-  if (attributes.find("_hldraw_") != attributes.end())
-  {
-    parse_renderop(attributes.find("_hldraw_")->second, ge->renderOperations());
-//     kDebug() << "element renderOperations size is now " << ge->renderOperations().size();
-  }
-  if (attributes.find("_tldraw_") != attributes.end())
-  {
-    parse_renderop(attributes.find("_tldraw_")->second, ge->renderOperations());
-//     kDebug() << "element renderOperations size is now " << ge->renderOperations().size();
-  }
-}
-
-void DotGraphParsingHelper::setgraphattributes()
-{
-//   kDebug() << "Attributes for graph are : ";
-  setgraphelementattributes(graph, graphAttributes);
-}
-
-void DotGraphParsingHelper::setsubgraphattributes()
-{
-//   kDebug() << "Attributes for subgraph are : ";
-  gs->setZ(z);
-//   kDebug() << "z="<<gs->z();
-  setgraphelementattributes(gs, graphAttributes);
-}
-
-void DotGraphParsingHelper::setnodeattributes()
-{
-//   kDebug() << "setnodeattributes with z = " << z;
-  
-  if (gn == 0)
-  {
-//     kDebug() << "gn is null";
-    return;
-  }
-//   kDebug() << "Attributes for node " << gn->id() << " are : ";
-  gn->setZ(z+1);
-//   kDebug() << "z="<<gn->z();
-  setgraphelementattributes(gn, nodesAttributes);
-}
-
-void DotGraphParsingHelper::setedgeattributes()
-{
-//   kDebug() << "setedgeattributeswith z = " << z;
-  
-//   kDebug() << "Attributes for edge " << ge->fromNode()->id() << "->" << ge->toNode()->id() << " are : ";
-  ge->setZ(z+1);
-//   kDebug() << "z="<<ge->z();
-  setgraphelementattributes(ge, edgesAttributes);
-  
-  if (edgesAttributes.find("_tdraw_") != edgesAttributes.end())
-  {
-    parse_renderop(edgesAttributes["_tdraw_"], ge->renderOperations());
-//     kDebug() << "edge renderOperations size is now " << ge->renderOperations().size();
-    DotRenderOpVec::const_iterator it, it_end;
-    it = ge->renderOperations().constBegin(); it_end = ge->renderOperations().constEnd();
-    for (; it != it_end; it++)
-      ge->arrowheads().push_back(*it);
-  }
-  if (edgesAttributes.find("_hdraw_") != edgesAttributes.end())
-  {
-    parse_renderop(edgesAttributes["_hdraw_"], ge->renderOperations());
-//     kDebug() << "edge renderOperations size is now " << ge->renderOperations().size();
-    DotRenderOpVec::const_iterator it, it_end;
-    it = ge->renderOperations().constBegin(); it_end = ge->renderOperations().constEnd();
-    for (; it != it_end; it++)
-      ge->arrowheads().push_back(*it);
-  }
-}
-
-void DotGraphParsingHelper::setattributedlist()
-{
-// //   kDebug() << "Setting attributes list for " << QString::fromStdString(attributed);
-  if (attributed == "graph")
-  {
-    if (attributes.find("bb") != attributes.end())
-    {
-      std::vector< int > v;
-      parse_integers(attributes["bb"].c_str(), v);
-      if (v.size()>=4)
-      {
-//         kDebug() << "setting width and height to " << v[2] << v[3];
-        graph->width(v[2]);
-        graph->height(v[3]);
-      }
-    }
-    AttributesMap::const_iterator it, it_end;
-    it = attributes.begin(); it_end = attributes.end();
-    for (; it != it_end; it++)
-    {
-//       kDebug() << "    " << QString::fromStdString((*it).first) << " = " <<  QString::fromStdString((*it).second);
-      graphAttributes[(*it).first] = (*it).second;
-    }
-  }
-  else if (attributed == "node")
-  {
-    AttributesMap::const_iterator it, it_end;
-    it = attributes.begin(); it_end = attributes.end();
-    for (; it != it_end; it++)
-    {
-//       kDebug() << "    " << QString::fromStdString((*it).first) << " = " <<  QString::fromStdString((*it).second);
-      nodesAttributes[(*it).first] = (*it).second;
-    }
-  }
-  else if (attributed == "edge")
-  {
-    AttributesMap::const_iterator it, it_end;
-    it = attributes.begin(); it_end = attributes.end();
-    for (; it != it_end; it++)
-    {
-//       kDebug() << "    " << QString::fromStdString((*it).first) << " = " <<  QString::fromStdString((*it).second);
-      edgesAttributes[(*it).first] = (*it).second;
-    }
-  }
-  attributes.clear();
-}
-
-void DotGraphParsingHelper::createnode(const std::string& nodeid)
-{
-  QString id = QString::fromStdString(nodeid); 
-//   kDebug() << id;
-  gn = dynamic_cast<GraphNode*>(graph->elementNamed(id));
-  if (gn==0 && graph->nodes().size() < KGV_MAX_ITEMS_TO_LOAD)
-  {
-//     kDebug() << "Creating a new node" << z << (void*)gs;
-    gn = new GraphNode();
-    gn->setId(id);
-//     gn->label(QString::fromStdString(nodeid));
-    if (z>0 && gs != 0)
-    {
-//       kDebug() << "Adding node" << id << "in subgraph" << gs->id();
-      gs->content().push_back(gn);
-    }
-    else
-    {
-//       kDebug() << "Adding node" << id;
-      graph->nodes()[id] = gn;
-    }
-  }
-  edgebounds.clear();
-}
-
-void DotGraphParsingHelper::createsubgraph()
-{
-//   kDebug() ;
-  if (phelper)
-  {
-    std::string str = phelper->subgraphid;
-    if (str.empty())
-    {
-      std::ostringstream oss;
-      oss << "kgv_id_" << phelper->uniq++;
-      str = oss.str();
-    }
-//     kDebug() << QString::fromStdString(str);
-    if (graph->subgraphs().find(QString::fromStdString(str)) == graph->subgraphs().end())
-    {
-//       kDebug() << "Creating a new subgraph";
-      gs = new GraphSubgraph();
-      gs->setId(QString::fromStdString(str));
-//       gs->label(QString::fromStdString(str)); 
-      graph->subgraphs().insert(QString::fromStdString(str), gs);
-//       kDebug() << "there is now"<<graph->subgraphs().size()<<"subgraphs in" << graph;
-    }
-    else
-    {
-//       kDebug() << "Found existing subgraph";
-      gs = *(graph->subgraphs().find(QString::fromStdString(str)));
-    }
-    phelper->subgraphid = "";
-  }
-}
-
-void DotGraphParsingHelper::createedges()
-{
-//   kDebug();
-  std::string node1Name, node2Name;
-  node1Name = edgebounds.front();
-  edgebounds.pop_front();
-  while (!edgebounds.empty())
-  {
-    node2Name = edgebounds.front();
-    edgebounds.pop_front();
-
-    if (graph->nodes().size() >= KGV_MAX_ITEMS_TO_LOAD || graph->edges().size() >= KGV_MAX_ITEMS_TO_LOAD)
-    {
-      return;
-    }
-//     kDebug() << QString::fromStdString(node1Name) << ", " << QString::fromStdString(node2Name);
-    ge = new GraphEdge();
-    GraphElement* gn1 = graph->elementNamed(QString::fromStdString(node1Name));
-    if (gn1 == 0)
-    {
-//       kDebug() << "new node 1";
-      gn1 = new GraphNode();
-      gn1->setId(QString::fromStdString(node1Name));
-      graph->nodes()[QString::fromStdString(node1Name)] = dynamic_cast<GraphNode*>(gn1);
-    }
-    GraphElement* gn2 = graph->elementNamed(QString::fromStdString(node2Name));
-    if (gn2 == 0)
-    {
-//       kDebug() << "new node 2";
-      gn2 = new GraphNode();
-      gn2->setId(QString::fromStdString(node2Name));
-      graph->nodes()[QString::fromStdString(node2Name)] = dynamic_cast<GraphNode*>(gn2);
-    }
-//     kDebug() << "Found gn1="<<gn1<<" and gn2=" << gn2;
-    if (gn1 == 0 || gn2 == 0)
-    {
-      kError() << "Unable to find or create edge bound(s) gn1=" << gn1 << "; gn2=" << gn2;
-    }
-    ge->setFromNode(gn1);
-    ge->setToNode(gn2);
-//     kDebug() << ge->fromNode()->id() << " -> " << ge->toNode()->id();
-    setedgeattributes();
-//     kDebug() << ge->id();
-    if (ge->id().isEmpty())
-    {
-      ge->setId(QString::fromStdString(node1Name)+QString::fromStdString(node2Name)+QUuid::createUuid().toString().remove('{').remove('}').remove('-'));
-    }
-//     kDebug() << ge->id();
-//     kDebug() << "num before=" << graph->edges().size();
-    graph->edges().insert(ge->id(), ge);
-//     kDebug() << "num after=" << graph->edges().size();
-
-
-    node1Name = node2Name;
-  }
-  edgebounds.clear();
-}
-
-void DotGraphParsingHelper::finalactions()
-{
-  GraphEdgeMap::iterator it, it_end;
-  it = graph->edges().begin(); it_end = graph->edges().end();
-  for (; it != it_end; it++)
-  {
-    (*it)->setZ(maxZ+1);
-  }
-}
-
-}
diff --git a/src/kgraphviz/support/DotGraphParsingHelper.h b/src/kgraphviz/support/DotGraphParsingHelper.h
deleted file mode 100644
index 465bcf1..0000000
--- a/src/kgraphviz/support/DotGraphParsingHelper.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/* This file is part of KGraphViewer.
-   Copyright (C) 2006-2007 Gael de Chalendar <kleag at free.fr>
-
-   KGraphViewer is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public
-   License as published by the Free Software Foundation, version 2.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA
-*/
-
-#ifndef DOT_GRAPHPARSINGHELPER_H
-#define DOT_GRAPHPARSINGHELPER_H
-
-#include <map>
-#include <list>
-#include <string>
-
-namespace KGraphViewer
-{
-class DotGraph;
-class GraphSubgraph;
-class GraphNode;
-class GraphEdge;
-class GraphElement;
-
-struct DotGraphParsingHelper
-{
-  typedef std::map< std::string, std::string > AttributesMap;
-
-  DotGraphParsingHelper();
-
-  void createnode(const std::string& nodeid);
-  void createsubgraph();
-  void setgraphattributes();
-  void setsubgraphattributes();
-      void setnodeattributes();
-  void setedgeattributes();
-  void setattributedlist();
-  void createedges();
-  void edgebound(const std::string& bound) {edgebounds.push_back(bound);}
-  void finalactions();
-  void setgraphelementattributes(GraphElement* ge, const AttributesMap& attributes);
-
-  std::string attrid;
-  std::string valid;
-  std::string attributed;
-  std::string subgraphid;
-  
-  unsigned int uniq;
-  
-  AttributesMap attributes;
-  AttributesMap graphAttributes;
-  AttributesMap nodesAttributes;
-  AttributesMap edgesAttributes;
-  std::list< AttributesMap > graphAttributesStack;
-  std::list< AttributesMap > nodesAttributesStack;
-  std::list< AttributesMap > edgesAttributesStack;
-  
-  std::list< std::string > edgebounds;
-  
-  unsigned int z;
-  unsigned int maxZ;
-  
-  DotGraph* graph;
-  
-  GraphSubgraph* gs;
-  GraphNode* gn;
-  GraphEdge* ge;
-};
-
-}
-
-#endif
-
-
-
diff --git a/src/kgraphviz/support/FontsCache.cpp b/src/kgraphviz/support/FontsCache.cpp
deleted file mode 100644
index d60078d..0000000
--- a/src/kgraphviz/support/FontsCache.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-/* This file is part of KGraphViewer.
-   Copyright (C) 2005-2007 Gael de Chalendar <kleag at free.fr>
-
-   KGraphViewer is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public
-   License as published by the Free Software Foundation, version 2.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA
-*/
-
-
-#include "FontsCache.h"
-
-#include "dot2qtconsts.h"
-
-FontsCache::~FontsCache()
-{
-  FontsCache::iterator it, it_end;
-  it = begin(); it_end = end();
-  for (; it != it_end; it++)
-  {
-    delete (*it);
-  }
-}
-
-QFont* FontsCache::cachedFont(const QFont& font)
-{
-  if (find(font.key()) == end())
-  {
-    (*this)[font.key()] = new QFont(font);
-  }
-  return (*this)[font.key()];
-}
-
-QFont* FontsCache::fromName(const QString& fontName)
-{
-  if (m_namesToFonts.find(fontName) == m_namesToFonts.end())
-  {
-    QFont font(Dot2QtConsts::componentData().qtFont(fontName));
-    m_namesToFonts[fontName] = cachedFont(font);
-  }
-  return m_namesToFonts[fontName];
-}
diff --git a/src/kgraphviz/support/FontsCache.h b/src/kgraphviz/support/FontsCache.h
deleted file mode 100644
index 41af3b9..0000000
--- a/src/kgraphviz/support/FontsCache.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* This file is part of KGraphViewer.
-   Copyright (C) 2005-2007 Gael de Chalendar <kleag at free.fr>
-
-   KGraphViewer is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public
-   License as published by the Free Software Foundation, version 2.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA
-*/
-
-
-#ifndef KGRAPHVIEWER_FONTSCACHE_H
-#define KGRAPHVIEWER_FONTSCACHE_H
-
-#include "Singleton.h"
-
-#include <qfont.h>
-#include <qmap.h>
-#include <qstring.h>
-
-/**
- * This is a map of fonts used in KgraphViewer
- *
- * @short A fonts map
- * @author Gaël de Chalendar <kleag at free.fr>
- */
-class FontsCache : 
-  public Singleton<FontsCache>,
-  public QMap<QString, QFont*>
-{
-friend class Singleton<FontsCache>;
-
-public:
-  virtual ~FontsCache();
-
-  QFont* cachedFont(const QFont& font);
-  QFont* fromName(const QString& font);
-
-private:
-  FontsCache() {}
-
-  QMap<QString, QFont*> m_namesToFonts;
-};
-
-#endif
diff --git a/src/kgraphviz/support/dotgrammar.cpp b/src/kgraphviz/support/dotgrammar.cpp
index 9225238..f5965ea 100644
--- a/src/kgraphviz/support/dotgrammar.cpp
+++ b/src/kgraphviz/support/dotgrammar.cpp
@@ -21,7 +21,7 @@
 #include "dotdefaults.h"
 #include "graphnode.h"
 #include "graphedge.h"
-#include "DotGraphParsingHelper.h"
+#include "dotgraphparsinghelper.h"
 
 #include <iostream>
 
diff --git a/src/kgraphviz/support/dotgraphparsinghelper.cpp b/src/kgraphviz/support/dotgraphparsinghelper.cpp
new file mode 100644
index 0000000..a982525
--- /dev/null
+++ b/src/kgraphviz/support/dotgraphparsinghelper.cpp
@@ -0,0 +1,343 @@
+/* This file is part of KGraphViewer.
+   Copyright (C) 2006-2007 Gael de Chalendar <kleag at free.fr>
+
+   KGraphViewer is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public
+   License as published by the Free Software Foundation, version 2.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA
+*/
+
+
+#include "dotgraphparsinghelper.h"
+
+#include "dotgraph.h"
+#include "dotgrammar.h"
+#include "dotdefaults.h"
+#include "graphnode.h"
+#include "graphedge.h"
+
+#include <boost/throw_exception.hpp>
+#include <boost/spirit/core.hpp>
+#include <boost/spirit/utility/distinct.hpp>
+#include <boost/spirit/utility/loops.hpp>
+#include <boost/spirit/utility/confix.hpp>
+
+#include <iostream>
+
+#include <kdebug.h>
+
+#include <QFile>
+#include <QUuid>
+
+using namespace std;
+
+extern KGraphViewer::DotGraphParsingHelper* phelper;
+
+namespace KGraphViewer
+{
+#define KGV_MAX_ITEMS_TO_LOAD std::numeric_limits<int>::max()
+
+DotGraphParsingHelper::DotGraphParsingHelper():
+  attrid(),
+  valid(),
+  attributed(),
+  subgraphid(),
+  uniq(0),
+  attributes(),
+  graphAttributes(),
+  nodesAttributes(),
+  edgesAttributes(),
+  graphAttributesStack(),
+  nodesAttributesStack(),
+  edgesAttributesStack(),
+  edgebounds(),
+  z(0),
+  maxZ(0),
+  graph(0),
+  gs(0),
+  gn(0),
+  ge(0)
+{
+}
+
+void DotGraphParsingHelper::setgraphelementattributes(GraphElement* ge, const AttributesMap& attributes)
+{
+  AttributesMap::const_iterator it, it_end;
+  it = attributes.begin(); it_end = attributes.end();
+  for (; it != it_end; it++)
+  {
+//     kDebug() << "    " << QString::fromStdString((*it).first) << "\t=\t'" << QString::fromStdString((*it).second) <<"'";
+    if ((*it).first=="label")
+    {
+      QString label = QString::fromUtf8((*it).second.c_str());
+      label.replace("\\n","\n");
+      (*ge).attributes()["label"] = label;
+    }
+    else
+    {
+      (*ge).attributes()[QString::fromStdString((*it).first)] =
+      QString::fromStdString((*it).second);
+    }
+  }
+  
+  if (attributes.find("_draw_") != attributes.end())
+  {
+    parse_renderop((attributes.find("_draw_"))->second, ge->renderOperations());
+//     kDebug() << "element renderOperations size is now " << ge->renderOperations().size();
+  }
+  if (attributes.find("_ldraw_") != attributes.end())
+  {
+    parse_renderop(attributes.find("_ldraw_")->second, ge->renderOperations());
+//     kDebug() << "element renderOperations size is now " << ge->renderOperations().size();
+  }
+  if (attributes.find("_hldraw_") != attributes.end())
+  {
+    parse_renderop(attributes.find("_hldraw_")->second, ge->renderOperations());
+//     kDebug() << "element renderOperations size is now " << ge->renderOperations().size();
+  }
+  if (attributes.find("_tldraw_") != attributes.end())
+  {
+    parse_renderop(attributes.find("_tldraw_")->second, ge->renderOperations());
+//     kDebug() << "element renderOperations size is now " << ge->renderOperations().size();
+  }
+}
+
+void DotGraphParsingHelper::setgraphattributes()
+{
+//   kDebug() << "Attributes for graph are : ";
+  setgraphelementattributes(graph, graphAttributes);
+}
+
+void DotGraphParsingHelper::setsubgraphattributes()
+{
+//   kDebug() << "Attributes for subgraph are : ";
+  gs->setZ(z);
+//   kDebug() << "z="<<gs->z();
+  setgraphelementattributes(gs, graphAttributes);
+}
+
+void DotGraphParsingHelper::setnodeattributes()
+{
+//   kDebug() << "setnodeattributes with z = " << z;
+  
+  if (gn == 0)
+  {
+//     kDebug() << "gn is null";
+    return;
+  }
+//   kDebug() << "Attributes for node " << gn->id() << " are : ";
+  gn->setZ(z+1);
+//   kDebug() << "z="<<gn->z();
+  setgraphelementattributes(gn, nodesAttributes);
+}
+
+void DotGraphParsingHelper::setedgeattributes()
+{
+//   kDebug() << "setedgeattributeswith z = " << z;
+  
+//   kDebug() << "Attributes for edge " << ge->fromNode()->id() << "->" << ge->toNode()->id() << " are : ";
+  ge->setZ(z+1);
+//   kDebug() << "z="<<ge->z();
+  setgraphelementattributes(ge, edgesAttributes);
+  
+  if (edgesAttributes.find("_tdraw_") != edgesAttributes.end())
+  {
+    parse_renderop(edgesAttributes["_tdraw_"], ge->renderOperations());
+//     kDebug() << "edge renderOperations size is now " << ge->renderOperations().size();
+    DotRenderOpVec::const_iterator it, it_end;
+    it = ge->renderOperations().constBegin(); it_end = ge->renderOperations().constEnd();
+    for (; it != it_end; it++)
+      ge->arrowheads().push_back(*it);
+  }
+  if (edgesAttributes.find("_hdraw_") != edgesAttributes.end())
+  {
+    parse_renderop(edgesAttributes["_hdraw_"], ge->renderOperations());
+//     kDebug() << "edge renderOperations size is now " << ge->renderOperations().size();
+    DotRenderOpVec::const_iterator it, it_end;
+    it = ge->renderOperations().constBegin(); it_end = ge->renderOperations().constEnd();
+    for (; it != it_end; it++)
+      ge->arrowheads().push_back(*it);
+  }
+}
+
+void DotGraphParsingHelper::setattributedlist()
+{
+// //   kDebug() << "Setting attributes list for " << QString::fromStdString(attributed);
+  if (attributed == "graph")
+  {
+    if (attributes.find("bb") != attributes.end())
+    {
+      std::vector< int > v;
+      parse_integers(attributes["bb"].c_str(), v);
+      if (v.size()>=4)
+      {
+//         kDebug() << "setting width and height to " << v[2] << v[3];
+        graph->width(v[2]);
+        graph->height(v[3]);
+      }
+    }
+    AttributesMap::const_iterator it, it_end;
+    it = attributes.begin(); it_end = attributes.end();
+    for (; it != it_end; it++)
+    {
+//       kDebug() << "    " << QString::fromStdString((*it).first) << " = " <<  QString::fromStdString((*it).second);
+      graphAttributes[(*it).first] = (*it).second;
+    }
+  }
+  else if (attributed == "node")
+  {
+    AttributesMap::const_iterator it, it_end;
+    it = attributes.begin(); it_end = attributes.end();
+    for (; it != it_end; it++)
+    {
+//       kDebug() << "    " << QString::fromStdString((*it).first) << " = " <<  QString::fromStdString((*it).second);
+      nodesAttributes[(*it).first] = (*it).second;
+    }
+  }
+  else if (attributed == "edge")
+  {
+    AttributesMap::const_iterator it, it_end;
+    it = attributes.begin(); it_end = attributes.end();
+    for (; it != it_end; it++)
+    {
+//       kDebug() << "    " << QString::fromStdString((*it).first) << " = " <<  QString::fromStdString((*it).second);
+      edgesAttributes[(*it).first] = (*it).second;
+    }
+  }
+  attributes.clear();
+}
+
+void DotGraphParsingHelper::createnode(const std::string& nodeid)
+{
+  QString id = QString::fromStdString(nodeid); 
+//   kDebug() << id;
+  gn = dynamic_cast<GraphNode*>(graph->elementNamed(id));
+  if (gn==0 && graph->nodes().size() < KGV_MAX_ITEMS_TO_LOAD)
+  {
+//     kDebug() << "Creating a new node" << z << (void*)gs;
+    gn = new GraphNode();
+    gn->setId(id);
+//     gn->label(QString::fromStdString(nodeid));
+    if (z>0 && gs != 0)
+    {
+//       kDebug() << "Adding node" << id << "in subgraph" << gs->id();
+      gs->content().push_back(gn);
+    }
+    else
+    {
+//       kDebug() << "Adding node" << id;
+      graph->nodes()[id] = gn;
+    }
+  }
+  edgebounds.clear();
+}
+
+void DotGraphParsingHelper::createsubgraph()
+{
+//   kDebug() ;
+  if (phelper)
+  {
+    std::string str = phelper->subgraphid;
+    if (str.empty())
+    {
+      std::ostringstream oss;
+      oss << "kgv_id_" << phelper->uniq++;
+      str = oss.str();
+    }
+//     kDebug() << QString::fromStdString(str);
+    if (graph->subgraphs().find(QString::fromStdString(str)) == graph->subgraphs().end())
+    {
+//       kDebug() << "Creating a new subgraph";
+      gs = new GraphSubgraph();
+      gs->setId(QString::fromStdString(str));
+//       gs->label(QString::fromStdString(str)); 
+      graph->subgraphs().insert(QString::fromStdString(str), gs);
+//       kDebug() << "there is now"<<graph->subgraphs().size()<<"subgraphs in" << graph;
+    }
+    else
+    {
+//       kDebug() << "Found existing subgraph";
+      gs = *(graph->subgraphs().find(QString::fromStdString(str)));
+    }
+    phelper->subgraphid = "";
+  }
+}
+
+void DotGraphParsingHelper::createedges()
+{
+//   kDebug();
+  std::string node1Name, node2Name;
+  node1Name = edgebounds.front();
+  edgebounds.pop_front();
+  while (!edgebounds.empty())
+  {
+    node2Name = edgebounds.front();
+    edgebounds.pop_front();
+
+    if (graph->nodes().size() >= KGV_MAX_ITEMS_TO_LOAD || graph->edges().size() >= KGV_MAX_ITEMS_TO_LOAD)
+    {
+      return;
+    }
+//     kDebug() << QString::fromStdString(node1Name) << ", " << QString::fromStdString(node2Name);
+    ge = new GraphEdge();
+    GraphElement* gn1 = graph->elementNamed(QString::fromStdString(node1Name));
+    if (gn1 == 0)
+    {
+//       kDebug() << "new node 1";
+      gn1 = new GraphNode();
+      gn1->setId(QString::fromStdString(node1Name));
+      graph->nodes()[QString::fromStdString(node1Name)] = dynamic_cast<GraphNode*>(gn1);
+    }
+    GraphElement* gn2 = graph->elementNamed(QString::fromStdString(node2Name));
+    if (gn2 == 0)
+    {
+//       kDebug() << "new node 2";
+      gn2 = new GraphNode();
+      gn2->setId(QString::fromStdString(node2Name));
+      graph->nodes()[QString::fromStdString(node2Name)] = dynamic_cast<GraphNode*>(gn2);
+    }
+//     kDebug() << "Found gn1="<<gn1<<" and gn2=" << gn2;
+    if (gn1 == 0 || gn2 == 0)
+    {
+      kError() << "Unable to find or create edge bound(s) gn1=" << gn1 << "; gn2=" << gn2;
+    }
+    ge->setFromNode(gn1);
+    ge->setToNode(gn2);
+//     kDebug() << ge->fromNode()->id() << " -> " << ge->toNode()->id();
+    setedgeattributes();
+//     kDebug() << ge->id();
+    if (ge->id().isEmpty())
+    {
+      ge->setId(QString::fromStdString(node1Name)+QString::fromStdString(node2Name)+QUuid::createUuid().toString().remove('{').remove('}').remove('-'));
+    }
+//     kDebug() << ge->id();
+//     kDebug() << "num before=" << graph->edges().size();
+    graph->edges().insert(ge->id(), ge);
+//     kDebug() << "num after=" << graph->edges().size();
+
+
+    node1Name = node2Name;
+  }
+  edgebounds.clear();
+}
+
+void DotGraphParsingHelper::finalactions()
+{
+  GraphEdgeMap::iterator it, it_end;
+  it = graph->edges().begin(); it_end = graph->edges().end();
+  for (; it != it_end; it++)
+  {
+    (*it)->setZ(maxZ+1);
+  }
+}
+
+}
diff --git a/src/kgraphviz/support/dotgraphparsinghelper.h b/src/kgraphviz/support/dotgraphparsinghelper.h
new file mode 100644
index 0000000..465bcf1
--- /dev/null
+++ b/src/kgraphviz/support/dotgraphparsinghelper.h
@@ -0,0 +1,84 @@
+/* This file is part of KGraphViewer.
+   Copyright (C) 2006-2007 Gael de Chalendar <kleag at free.fr>
+
+   KGraphViewer is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public
+   License as published by the Free Software Foundation, version 2.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA
+*/
+
+#ifndef DOT_GRAPHPARSINGHELPER_H
+#define DOT_GRAPHPARSINGHELPER_H
+
+#include <map>
+#include <list>
+#include <string>
+
+namespace KGraphViewer
+{
+class DotGraph;
+class GraphSubgraph;
+class GraphNode;
+class GraphEdge;
+class GraphElement;
+
+struct DotGraphParsingHelper
+{
+  typedef std::map< std::string, std::string > AttributesMap;
+
+  DotGraphParsingHelper();
+
+  void createnode(const std::string& nodeid);
+  void createsubgraph();
+  void setgraphattributes();
+  void setsubgraphattributes();
+      void setnodeattributes();
+  void setedgeattributes();
+  void setattributedlist();
+  void createedges();
+  void edgebound(const std::string& bound) {edgebounds.push_back(bound);}
+  void finalactions();
+  void setgraphelementattributes(GraphElement* ge, const AttributesMap& attributes);
+
+  std::string attrid;
+  std::string valid;
+  std::string attributed;
+  std::string subgraphid;
+  
+  unsigned int uniq;
+  
+  AttributesMap attributes;
+  AttributesMap graphAttributes;
+  AttributesMap nodesAttributes;
+  AttributesMap edgesAttributes;
+  std::list< AttributesMap > graphAttributesStack;
+  std::list< AttributesMap > nodesAttributesStack;
+  std::list< AttributesMap > edgesAttributesStack;
+  
+  std::list< std::string > edgebounds;
+  
+  unsigned int z;
+  unsigned int maxZ;
+  
+  DotGraph* graph;
+  
+  GraphSubgraph* gs;
+  GraphNode* gn;
+  GraphEdge* ge;
+};
+
+}
+
+#endif
+
+
+
diff --git a/src/kgraphviz/support/fontscache.cpp b/src/kgraphviz/support/fontscache.cpp
new file mode 100644
index 0000000..0ccd773
--- /dev/null
+++ b/src/kgraphviz/support/fontscache.cpp
@@ -0,0 +1,51 @@
+/* This file is part of KGraphViewer.
+   Copyright (C) 2005-2007 Gael de Chalendar <kleag at free.fr>
+
+   KGraphViewer is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public
+   License as published by the Free Software Foundation, version 2.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA
+*/
+
+
+#include "fontscache.h"
+
+#include "dot2qtconsts.h"
+
+FontsCache::~FontsCache()
+{
+  FontsCache::iterator it, it_end;
+  it = begin(); it_end = end();
+  for (; it != it_end; it++)
+  {
+    delete (*it);
+  }
+}
+
+QFont* FontsCache::cachedFont(const QFont& font)
+{
+  if (find(font.key()) == end())
+  {
+    (*this)[font.key()] = new QFont(font);
+  }
+  return (*this)[font.key()];
+}
+
+QFont* FontsCache::fromName(const QString& fontName)
+{
+  if (m_namesToFonts.find(fontName) == m_namesToFonts.end())
+  {
+    QFont font(Dot2QtConsts::componentData().qtFont(fontName));
+    m_namesToFonts[fontName] = cachedFont(font);
+  }
+  return m_namesToFonts[fontName];
+}
diff --git a/src/kgraphviz/support/fontscache.h b/src/kgraphviz/support/fontscache.h
new file mode 100644
index 0000000..41af3b9
--- /dev/null
+++ b/src/kgraphviz/support/fontscache.h
@@ -0,0 +1,53 @@
+/* This file is part of KGraphViewer.
+   Copyright (C) 2005-2007 Gael de Chalendar <kleag at free.fr>
+
+   KGraphViewer is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public
+   License as published by the Free Software Foundation, version 2.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA
+*/
+
+
+#ifndef KGRAPHVIEWER_FONTSCACHE_H
+#define KGRAPHVIEWER_FONTSCACHE_H
+
+#include "Singleton.h"
+
+#include <qfont.h>
+#include <qmap.h>
+#include <qstring.h>
+
+/**
+ * This is a map of fonts used in KgraphViewer
+ *
+ * @short A fonts map
+ * @author Gaël de Chalendar <kleag at free.fr>
+ */
+class FontsCache : 
+  public Singleton<FontsCache>,
+  public QMap<QString, QFont*>
+{
+friend class Singleton<FontsCache>;
+
+public:
+  virtual ~FontsCache();
+
+  QFont* cachedFont(const QFont& font);
+  QFont* fromName(const QString& font);
+
+private:
+  FontsCache() {}
+
+  QMap<QString, QFont*> m_namesToFonts;
+};
+
+#endif


More information about the kgraphviewer-devel mailing list