[kgraphviewer-devel] [PATCH 2/2] Support newer graphviz cgraph library.
Reimar Döffinger
Reimar.Doeffinger at gmx.de
Sat Mar 1 23:06:51 UTC 2014
Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
---
cmake/FindGraphViz.cmake | 6 +++---
src/part/CMakeLists.txt | 2 +-
src/part/dotgraph.cpp | 50 +++++++++++++++++++++----------------------
src/part/graphedge.cpp | 8 +++----
src/part/graphexporter.cpp | 16 +++++++-------
src/part/graphnode.cpp | 12 +++++------
src/part/graphsubgraph.cpp | 26 +++++++++++-----------
src/part/loadagraphthread.cpp | 2 +-
8 files changed, 59 insertions(+), 63 deletions(-)
diff --git a/cmake/FindGraphViz.cmake b/cmake/FindGraphViz.cmake
index a2852df..21f349c 100644
--- a/cmake/FindGraphViz.cmake
+++ b/cmake/FindGraphViz.cmake
@@ -29,7 +29,7 @@
if ( NOT WIN32 )
find_package(PkgConfig)
- pkg_check_modules( graphviz ${REQUIRED} libgvc libcdt libgraph libpathplan )
+ pkg_check_modules( graphviz ${REQUIRED} libgvc libcdt libcgraph libpathplan )
if ( graphviz_FOUND )
set ( graphviz_INCLUDE_DIRECTORIES ${graphviz_INCLUDE_DIRS} )
endif ( graphviz_FOUND )
@@ -66,7 +66,7 @@ find_library( graphviz_CDT_LIBRARY
)
find_library( graphviz_GRAPH_LIBRARY
- NAMES graph
+ NAMES cgraph
PATHS
${graphviz_LIBRARY_DIRS}
/usr/local/lib64
@@ -162,4 +162,4 @@ include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set GRAPHVIZ_FOUND to TRUE if
# all listed variables are TRUE
-find_package_handle_standard_args(GraphViz DEFAULT_MSG graphviz_LIBRARIES graphviz_INCLUDE_DIRECTORIES)
\ No newline at end of file
+find_package_handle_standard_args(GraphViz DEFAULT_MSG graphviz_LIBRARIES graphviz_INCLUDE_DIRECTORIES)
diff --git a/src/part/CMakeLists.txt b/src/part/CMakeLists.txt
index 6377add..7b7913c 100644
--- a/src/part/CMakeLists.txt
+++ b/src/part/CMakeLists.txt
@@ -28,7 +28,7 @@ set( kgraphviewerpart_PART_SRCS kgraphviewer_part.cpp )
kde4_add_plugin(kgraphviewerpart ${kgraphviewerpart_PART_SRCS})
add_definitions(-DQT_STL)
-target_link_libraries(kgraphviewerpart ${KDE4_KPARTS_LIBS} gvc graph pathplan cdt kgraphviewerlib)
+target_link_libraries(kgraphviewerpart ${KDE4_KPARTS_LIBS} gvc cgraph pathplan cdt kgraphviewerlib)
install( TARGETS kgraphviewerpart DESTINATION ${PLUGIN_INSTALL_DIR})
diff --git a/src/part/dotgraph.cpp b/src/part/dotgraph.cpp
index b9f2b9b..bb4a58a 100644
--- a/src/part/dotgraph.cpp
+++ b/src/part/dotgraph.cpp
@@ -416,27 +416,25 @@ void DotGraph::updateWithGraph(graph_t* newGraph)
setRenderOperations(ops);
- Agsym_t *attr = agfstattr(newGraph);
+ Agsym_t *attr = agnxtattr(newGraph, AGRAPH, NULL);
while(attr)
{
- kDebug() << newGraph->name << ":" << attr->name << agxget(newGraph,attr->index);
- m_attributes[attr->name] = agxget(newGraph,attr->index);
- attr = agnxtattr(newGraph,attr);
+ kDebug() << agnameof(newGraph) << ":" << attr->name << agxget(newGraph,attr);
+ m_attributes[attr->name] = agxget(newGraph,attr);
+ attr = agnxtattr(newGraph, AGRAPH, attr);
}
// copy subgraphs
- for (edge_t* e = agfstout(newGraph->meta_node->graph, newGraph->meta_node); e;
- e = agnxtout(newGraph->meta_node->graph, e))
+ for (graph_t* sg = agfstsubg(newGraph); sg; sg = agnxtsubg(sg))
{
- graph_t* sg = agusergraph(e->head);
- kDebug() << "subgraph:" << sg->name;
- if (subgraphs().contains(sg->name))
+ kDebug() << "subgraph:" << agnameof(sg);
+ if (subgraphs().contains(agnameof(sg)))
{
kDebug() << "known";
// ???
// nodes()[ngn->name]->setZ(ngn->z());
- subgraphs()[sg->name]->updateWithSubgraph(sg);
- if (subgraphs()[sg->name]->canvasElement()!=0)
+ subgraphs()[agnameof(sg)]->updateWithSubgraph(sg);
+ if (subgraphs()[agnameof(sg)]->canvasElement()!=0)
{
// nodes()[ngn->id()]->canvasElement()->setGh(m_height);
}
@@ -446,7 +444,7 @@ void DotGraph::updateWithGraph(graph_t* newGraph)
kDebug() << "new";
GraphSubgraph* newsg = new GraphSubgraph(sg);
// kDebug() << "new created";
- subgraphs().insert(sg->name, newsg);
+ subgraphs().insert(agnameof(sg), newsg);
// kDebug() << "new inserted";
}
@@ -459,14 +457,14 @@ void DotGraph::updateWithGraph(graph_t* newGraph)
while (ngn != NULL)
// foreach (GraphNode* ngn, newGraph.nodes())
{
- kDebug() << "node " << ngn->name;
- if (nodes().contains(ngn->name))
+ kDebug() << "node " << agnameof(ngn);
+ if (nodes().contains(agnameof(ngn)))
{
kDebug() << "known";
// ???
// nodes()[ngn->name]->setZ(ngn->z());
- nodes()[ngn->name]->updateWithNode(ngn);
- if (nodes()[ngn->name]->canvasElement()!=0)
+ nodes()[agnameof(ngn)]->updateWithNode(ngn);
+ if (nodes()[agnameof(ngn)]->canvasElement()!=0)
{
// nodes()[ngn->id()]->canvasElement()->setGh(m_height);
}
@@ -476,7 +474,7 @@ void DotGraph::updateWithGraph(graph_t* newGraph)
kDebug() << "new";
GraphNode* newgn = new GraphNode(ngn);
// kDebug() << "new created";
- nodes().insert(ngn->name, newgn);
+ nodes().insert(agnameof(ngn), newgn);
// kDebug() << "new inserted";
}
@@ -484,11 +482,11 @@ void DotGraph::updateWithGraph(graph_t* newGraph)
edge_t* nge = agfstout(newGraph, ngn);
while (nge != NULL)
{
- kDebug() << "edge " << nge->id;
- QString edgeName = QString(nge->head->name) + nge->tail->name;
+// kDebug() << "edge " << nge->id;
+ QString edgeName = QString(agnameof(aghead(nge))) + agnameof(agtail(nge));
if (edges().contains(edgeName))
{
- kDebug() << "edge known" << nge->id;
+// kDebug() << "edge known" << nge->id;
// edges()[nge->name]->setZ(nge->z());
edges()[edgeName]->updateWithEdge(nge);
if (edges()[edgeName]->canvasEdge()!=0)
@@ -503,20 +501,20 @@ void DotGraph::updateWithGraph(graph_t* newGraph)
GraphEdge* newEdge = new GraphEdge();
newEdge->setId(edgeName);
newEdge->updateWithEdge(nge);
- if (elementNamed(nge->tail->name) == 0)
+ if (elementNamed(agnameof(agtail(nge))) == 0)
{
GraphNode* newgn = new GraphNode();
// kDebug() << "new created";
- nodes().insert(nge->tail->name, newgn);
+ nodes().insert(agnameof(agtail(nge)), newgn);
}
- newEdge->setFromNode(elementNamed(nge->tail->name));
- if (elementNamed(nge->head->name) == 0)
+ newEdge->setFromNode(elementNamed(agnameof(agtail(nge))));
+ if (elementNamed(agnameof(aghead(nge))) == 0)
{
GraphNode* newgn = new GraphNode();
// kDebug() << "new created";
- nodes().insert(nge->head->name, newgn);
+ nodes().insert(agnameof(aghead(nge)), newgn);
}
- newEdge->setToNode(elementNamed(nge->head->name));
+ newEdge->setToNode(elementNamed(agnameof(aghead(nge))));
edges().insert(edgeName, newEdge);
}
}
diff --git a/src/part/graphedge.cpp b/src/part/graphedge.cpp
index 8453064..a52c31c 100644
--- a/src/part/graphedge.cpp
+++ b/src/part/graphedge.cpp
@@ -141,12 +141,12 @@ void GraphEdge::updateWithEdge(edge_t* edge)
kDebug() << "element renderOperations size is now " << ops.size();
}
setRenderOperations(ops);
- Agsym_t *attr = agfstattr(edge);
+ Agsym_t *attr = agnxtattr(agraphof(agtail(edge)), AGEDGE, NULL);
while(attr)
{
- kDebug() /*<< edge->name*/ << ":" << attr->name << agxget(edge,attr->index);
- m_attributes[attr->name] = agxget(edge,attr->index);
- attr = agnxtattr(edge,attr);
+ kDebug() /*<< edge->name*/ << ":" << attr->name << agxget(edge,attr);
+ m_attributes[attr->name] = agxget(edge,attr);
+ attr = agnxtattr(agraphof(agtail(edge)), AGEDGE, attr);
}
}
diff --git a/src/part/graphexporter.cpp b/src/part/graphexporter.cpp
index 31ae678..fe345f6 100644
--- a/src/part/graphexporter.cpp
+++ b/src/part/graphexporter.cpp
@@ -118,11 +118,11 @@ QString GraphExporter::writeDot(const DotGraph* graph, const QString& fileName)
graph_t* GraphExporter::exportToGraphviz(const DotGraph* graph)
{
- int type = graph->directed()
- ?(graph->strict()?AGDIGRAPHSTRICT:AGDIGRAPH)
- :(graph->strict()?AGRAPHSTRICT:AGRAPH);
+ Agdesc_t type = Agstrictundirected;
+ type.directed = graph->directed();
+ type.strict = graph->strict();
- graph_t* agraph = agopen((graph->id()!="\"\"")?graph->id().toUtf8().data():QString("unnamed").toUtf8().data(), type);
+ graph_t* agraph = agopen((graph->id()!="\"\"")?graph->id().toUtf8().data():QString("unnamed").toUtf8().data(), type, NULL);
QTextStream stream;
graph->exportToGraphviz(agraph);
@@ -134,7 +134,7 @@ graph_t* GraphExporter::exportToGraphviz(const DotGraph* graph)
sit != graph->subgraphs().end(); ++sit )
{
const GraphSubgraph& s = **sit;
- graph_t* subgraph = agsubg(agraph, s.id().toUtf8().data());
+ graph_t* subgraph = agsubg(agraph, s.id().toUtf8().data(), 1);
s.exportToGraphviz(subgraph);
}
@@ -142,7 +142,7 @@ graph_t* GraphExporter::exportToGraphviz(const DotGraph* graph)
GraphNodeMap::const_iterator nit;
foreach (GraphNode* n, graph->nodes())
{
- node_t* node = agnode(agraph, n->id().toUtf8().data());
+ node_t* node = agnode(agraph, n->id().toUtf8().data(), 1);
n->exportToGraphviz(node);
}
@@ -151,8 +151,8 @@ graph_t* GraphExporter::exportToGraphviz(const DotGraph* graph)
foreach (GraphEdge* e, graph->edges())
{
kDebug() << "writing edge" << e->id();
- edge_t* edge = agedge(agraph, agnode(agraph, e->fromNode()->id().toUtf8().data()),
- agnode(agraph, e->toNode()->id().toUtf8().data()));
+ edge_t* edge = agedge(agraph, agnode(agraph, e->fromNode()->id().toUtf8().data(), 0),
+ agnode(agraph, e->toNode()->id().toUtf8().data(), 0), NULL, 1);
e->exportToGraphviz(edge);
}
diff --git a/src/part/graphnode.cpp b/src/part/graphnode.cpp
index cc283aa..250dc81 100644
--- a/src/part/graphnode.cpp
+++ b/src/part/graphnode.cpp
@@ -78,8 +78,8 @@ void GraphNode::updateWithNode(const GraphNode& node)
void GraphNode::updateWithNode(node_t* node)
{
- kDebug() << node->name;
- m_attributes["id"] = node->name;
+ kDebug() << agnameof(node);
+ m_attributes["id"] = agnameof(node);
m_attributes["label"] = ND_label(node)->text;
DotRenderOpVec ops;
@@ -99,12 +99,12 @@ void GraphNode::updateWithNode(node_t* node)
setRenderOperations(ops);
- Agsym_t *attr = agfstattr(node);
+ Agsym_t *attr = agnxtattr(agraphof(node), AGNODE, NULL);
while(attr)
{
- kDebug() << node->name << ":" << attr->name << agxget(node,attr->index);
- m_attributes[attr->name] = agxget(node,attr->index);
- attr = agnxtattr(node,attr);
+ kDebug() << agnameof(node) << ":" << attr->name << agxget(node,attr);
+ m_attributes[attr->name] = agxget(node,attr);
+ attr = agnxtattr(agraphof(node), AGNODE, attr);
}
}
diff --git a/src/part/graphsubgraph.cpp b/src/part/graphsubgraph.cpp
index 82e63cd..eb11084 100644
--- a/src/part/graphsubgraph.cpp
+++ b/src/part/graphsubgraph.cpp
@@ -102,8 +102,8 @@ void GraphSubgraph::updateWithSubgraph(const GraphSubgraph& subgraph)
void GraphSubgraph::updateWithSubgraph(graph_t* subgraph)
{
- kDebug() << subgraph->name;
- m_attributes["id"] = subgraph->name;
+ kDebug() << agnameof(subgraph);
+ m_attributes["id"] = agnameof(subgraph);
if (GD_label(subgraph))
m_attributes["label"] = GD_label(subgraph)->text;
@@ -124,27 +124,25 @@ void GraphSubgraph::updateWithSubgraph(graph_t* subgraph)
setRenderOperations(ops);
- Agsym_t *attr = agfstattr(subgraph);
+ Agsym_t *attr = agnxtattr(subgraph, AGRAPH, NULL);
while(attr)
{
- kDebug() << subgraph->name << ":" << attr->name << agxget(subgraph,attr->index);
- m_attributes[attr->name] = agxget(subgraph,attr->index);
- attr = agnxtattr(subgraph,attr);
+ kDebug() << agnameof(subgraph) << ":" << attr->name << agxget(subgraph,attr);
+ m_attributes[attr->name] = agxget(subgraph,attr);
+ attr = agnxtattr(subgraph, AGRAPH, attr);
}
- for (edge_t* e = agfstout(subgraph->meta_node->graph, subgraph->meta_node); e;
- e = agnxtout(subgraph->meta_node->graph, e))
+ for (graph_t* sg = agfstsubg(subgraph); sg; sg = agnxtsubg(sg))
{
- graph_t* sg = agusergraph(e->head);
- kDebug() << "subsubgraph:" << sg->name;
- if ( subgraphs().contains(sg->name))
+ kDebug() << "subsubgraph:" << agnameof(sg);
+ if ( subgraphs().contains(agnameof(sg)))
{
kDebug() << "known subsubgraph";
// ???
// nodes()[ngn->name]->setZ(ngn->z());
- subgraphs()[sg->name]->updateWithSubgraph(sg);
- if (subgraphs()[sg->name]->canvasElement()!=0)
+ subgraphs()[agnameof(sg)]->updateWithSubgraph(sg);
+ if (subgraphs()[agnameof(sg)]->canvasElement()!=0)
{
// nodes()[ngn->id()]->canvasElement()->setGh(m_height);
}
@@ -154,7 +152,7 @@ void GraphSubgraph::updateWithSubgraph(graph_t* subgraph)
kDebug() << "new subsubgraph";
GraphSubgraph* newsg = new GraphSubgraph(sg);
// kDebug() << "new created";
- subgraphs().insert(sg->name, newsg);
+ subgraphs().insert(agnameof(sg), newsg);
// kDebug() << "new inserted";
}
diff --git a/src/part/loadagraphthread.cpp b/src/part/loadagraphthread.cpp
index 1d56bdc..d8bf378 100644
--- a/src/part/loadagraphthread.cpp
+++ b/src/part/loadagraphthread.cpp
@@ -28,7 +28,7 @@ void LoadAGraphThread::run()
FILE* fp;
gvc = gvContext();
fp = fopen(m_dotFileName.toUtf8().data(), "r");
- m_g = agread(fp);
+ m_g = agread(fp, NULL);
}
void LoadAGraphThread::loadFile(const QString& dotFileName)
--
1.9.0
More information about the kgraphviewer-devel
mailing list