graphhandler.cpp 4.75 KB
Newer Older
1 2
#include "graphhandler.h"

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
class EdgeRelationMapper
{
  public:
    EdgeRelationMapper()
    {
      m_map.insert("public-inheritance",    IChildNode::PublicInheritance);
      m_map.insert("protected-inheritance", IChildNode::ProtectedInheritance);
      m_map.insert("private-inheritance",   IChildNode::PrivateInheritance);
      m_map.insert("usage",                 IChildNode::Usage);
      m_map.insert("template-instance",     IChildNode::TemplateInstance);
    }
    IChildNode::NodeRelation stringToNodeRelation(const QString &nrStr)
    {
      return m_map[nrStr];
    }
  private:
    QMap<QString,IChildNode::NodeRelation> m_map;
};

static EdgeRelationMapper *s_edgeRelationMapper;

void graphhandler_init()
{
  s_edgeRelationMapper = new EdgeRelationMapper;
}

void graphhandler_exit()
{
  delete s_edgeRelationMapper;
}

//------------------------------------------------------------------------

36 37 38 39 40 41
GraphHandler::GraphHandler(IBaseHandler *parent,const char *endTag)
   : m_parent(parent)
{
  addEndHandler(endTag,this,&GraphHandler::endGraph);
  addStartHandler("node",this,&GraphHandler::startNode);
  m_nodes.setAutoDelete(TRUE);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
42
  m_nodeDict = new QDict<NodeHandler>(1009);
43 44 45 46
}

GraphHandler::~GraphHandler()
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
47
  delete m_nodeDict;
48 49 50 51
}

void GraphHandler::startGraph(const QXmlAttributes &)
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
52
  debug(2,"startGraph\n");
53 54 55 56 57
  m_parent->setDelegate(this);
}

void GraphHandler::endGraph()
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
58
  debug(2,"endGraph\n");
59 60 61 62 63 64 65 66
  m_parent->setDelegate(0);
}

void GraphHandler::startNode(const QXmlAttributes &attrib)
{
  NodeHandler *n = new NodeHandler(this);
  n->startNode(attrib);
  m_nodes.append(n);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
67
  m_nodeDict->insert(attrib.value("id").utf8(),n);
68 69 70 71 72 73 74
}

INodeIterator *GraphHandler::nodes() const
{
  return new NodeIterator(*this);
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
75 76
NodeHandler *GraphHandler::getNodeById(const QString &id) const
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
77
  return m_nodeDict->find(id.utf8());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
78 79
}

80 81
//------------------------------------------------------------------------

Dimitri van Heesch's avatar
Dimitri van Heesch committed
82 83
NodeHandler::NodeHandler(GraphHandler *gh)
   : m_parent(gh), m_graph(gh)
84 85 86 87 88 89
{
  addEndHandler("node",this,&NodeHandler::endNode);
  addStartHandler("link",this,&NodeHandler::startLink);
  addEndHandler("link",this,&NodeHandler::endLink);
  addStartHandler("label",this,&NodeHandler::startLabel);
  addEndHandler("label",this,&NodeHandler::endLabel);
90 91
  addStartHandler("childnode",this,&NodeHandler::startChildNode);
  m_children.setAutoDelete(TRUE);
92 93 94 95 96 97 98 99
}

NodeHandler::~NodeHandler()
{
}

void NodeHandler::startNode(const QXmlAttributes &attrib)
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
100
  debug(2,"startNode\n");
101 102 103 104 105 106
  m_parent->setDelegate(this);
  m_id = attrib.value("id");
}

void NodeHandler::endNode()
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
107
  debug(2,"endNode\n");
108 109 110 111 112
  m_parent->setDelegate(0);
}

void NodeHandler::startLink(const QXmlAttributes &attrib)
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
113
  m_link = attrib.value("refid");
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
}

void NodeHandler::endLink()
{
}

void NodeHandler::startLabel(const QXmlAttributes &/*attrib*/)
{
  m_curString="";
}

void NodeHandler::endLabel()
{
  m_label = m_curString;
}

130 131
void NodeHandler::startChildNode(const QXmlAttributes &attrib)
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
132
  ChildNodeHandler *cnh = new ChildNodeHandler(this,m_graph);
133 134 135 136 137 138 139 140 141 142 143
  cnh->startChildNode(attrib);
  m_children.append(cnh);
}
  
IChildNodeIterator *NodeHandler::children() const 
{ 
  return new ChildNodeIterator(*this); 
}

//------------------------------------------------------------------------

Dimitri van Heesch's avatar
Dimitri van Heesch committed
144 145
ChildNodeHandler::ChildNodeHandler(IBaseHandler *parent,GraphHandler *gh)
  : m_parent(parent), m_graph(gh)
146
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
147
  addEndHandler("childnode",this,&ChildNodeHandler::endChildNode);
148 149 150 151 152 153 154 155 156 157
  addStartHandler("edgelabel",this,&ChildNodeHandler::startEdgeLabel);
  m_edgeLabels.setAutoDelete(TRUE);
}

ChildNodeHandler::~ChildNodeHandler()
{
}

void ChildNodeHandler::startChildNode(const QXmlAttributes &attrib)
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
158
  debug(2,"startChildNode\n");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
159
  m_id             = attrib.value("refid");
160 161 162 163 164 165 166
  m_relationString = attrib.value("relation");
  m_relation       = s_edgeRelationMapper->stringToNodeRelation(m_relationString);
  m_parent->setDelegate(this);
}

void ChildNodeHandler::endChildNode()
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
167
  debug(2,"endChildNode\n");
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
  m_parent->setDelegate(0);
}


void ChildNodeHandler::startEdgeLabel(const QXmlAttributes &attrib)
{
  EdgeLabelHandler *elh = new EdgeLabelHandler(this);
  elh->startEdgeLabel(attrib);
  m_edgeLabels.append(elh);
}

IEdgeLabelIterator *ChildNodeHandler::edgeLabels() const
{
  return new EdgeLabelIterator(*this);
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
184 185 186 187
INode *ChildNodeHandler::node() const
{
  return m_graph->getNodeById(m_id);
}
188 189 190 191 192 193

//-----------------------------------------------------------------------

EdgeLabelHandler::EdgeLabelHandler(IBaseHandler *parent)
  : m_parent(parent)
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
194
  addEndHandler("edgelabel",this,&EdgeLabelHandler::endEdgeLabel);
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
}

EdgeLabelHandler::~EdgeLabelHandler()
{
}

void EdgeLabelHandler::startEdgeLabel(const QXmlAttributes &)
{
  m_parent->setDelegate(this);
  m_curString="";
}

void EdgeLabelHandler::endEdgeLabel()
{
  m_label=m_curString;
  m_parent->setDelegate(0);
}

213 214 215 216