GraphTool  1.0
Tool for analyzing and graphically visualizing code dependencies for Ericsson.
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
graph_model_item.h
1 #ifndef GUI_GRAPH_MODEL_ITEM_H_
2 #define GUI_GRAPH_MODEL_ITEM_H_
3 
4 #include <QVariant>
5 #include <QList>
6 #include <QColor>
7 #include <QDebug>
8 
9 #include <vector>
10 
23  public:
30  enum column_index { NAME,
31  DEPENDENCIES,
32  DEPENDENTS,
33  MODULES,
34  FILES,
35  DEGREE,
36  CIRCULAR,
37  SELF_REF,
38  XPOS,
39  YPOS,
40  ABSOLUTE,
41  IN_RUN_BLOCK,
42  MEM_TYPE, //Only when this item represents an edge(dependency). a dependency_type enum value
43  COLOR,
44  OPACITY,
45  EDGE_COLOR,
46  EDGE_OPACITY,
47  NUM_COLS };
48 
51  virtual ~GraphModelItem();
52 
56  GraphModelItem* child(int row);
60  int childCount() const;
61 
63  int columnCount() const;
64 
66  int row() const;
67 
69  virtual QVariant data(int column) const;
70 
72  void set_xy(int x, int y);
73 
76  void set_circular(bool circular);
77 
80  bool circular() const;
81 
83  void set_num_of_modules(uint);
84 
86  void set_degree(uint);
87 
89  void set_num_of_files(uint);
90 
91  // Set the opactiy
92  void set_opacity(int opacity);
93 
94  // Set the color
95  void set_color(QColor color);
96 
97  void set_edge_opacity(int opacity);
98  void set_edge_color(QColor color);
99 
103  void set_mem_type(std::string type);
104 
105  protected:
106  /* Tree mode specific member */
107  GraphModelItem* parent_item_;
108 
109  private:
110  /* Tree mode specific members */
111  // Hierarchical data ie. with regards to the tree
112  QList<GraphModelItem*> child_items_;
113 
114  /* General members */
115  bool circular_;
116  int x_;
117  int y_;
118  uint num_of_modules_;
119  uint degree_;
120  uint num_of_files_;
121  int opacity_;
122  QColor color_;
123  int edge_opacity_;
124  QColor edge_color_;
125 
126 
127  // If this item is an edge, this variable states
128  // which type of dependency it represents (check Dependency::DependencyType enum)
129  std::string mem_type_;
130 };
131 
138 template<typename NodeType, typename EdgeType> class GenericGraphModelItem : public GraphModelItem {
139  public:
144  GenericGraphModelItem(NodeType* node, std::vector<EdgeType*>* edges, std::vector<EdgeType*>* incoming_edges, GraphModelItem* parent = 0, EdgeType* parent_edge = 0)
145  : GraphModelItem(parent), edges_(edges), incoming_edges_(incoming_edges) {
146  parent_edge_ = parent_edge;
147  node_ = node;
148  }
149 
151  delete edges_;
152  delete incoming_edges_;
153  }
154 
156  NodeType* node() {
157  return node_;
158  }
159 
161  std::vector<EdgeType*>* edges() {
162  return edges_;
163  }
164 
166  std::vector<EdgeType*>* incoming_edges() {
167  return incoming_edges_;
168  }
169 
171  bool self_referential() const {
173  dynamic_cast<GenericGraphModelItem<NodeType,EdgeType>*>(parent_item_);
174 
175  if(p == NULL) return false;
176 
177  return (p ->node_ == node_);
178  }
179 
182  // referential or not.
183  virtual QVariant data(int column) const {
184  switch(column) {
185  case SELF_REF:
186  return self_referential();
187  default:
188  return GraphModelItem::data(column);
189  }
190  }
191 
192  protected:
194  NodeType* node_;
196  EdgeType* parent_edge_;
198  std::vector<EdgeType*>* edges_;
200  std::vector<EdgeType*>* incoming_edges_;
201 };
202 
203 #endif
void set_degree(uint)
Set the degree of this item.
Definition: graph_model_item.cc:110
void set_mem_type(std::string type)
Definition: graph_model_item.cc:134
NodeType * node()
Return the underlying node.
Definition: graph_model_item.h:156
int columnCount() const
Return the number of columns in this node (see the num above.
Definition: graph_model_item.cc:45
void set_xy(int x, int y)
Set the x,y coordinate properties for this node.
Definition: graph_model_item.cc:89
bool circular() const
Definition: graph_model_item.cc:98
GraphModelItem * parent()
Returns the parent of this node.
Definition: graph_model_item.cc:102
column_index
Definition: graph_model_item.h:30
std::vector< EdgeType * > * edges()
Return the list of edge datas belonging to this node.
Definition: graph_model_item.h:161
int childCount() const
Return the number of child columns in this node.
Definition: graph_model_item.cc:34
void set_circular(bool circular)
Definition: graph_model_item.cc:94
GenericGraphModelItem(NodeType *node, std::vector< EdgeType * > *edges, std::vector< EdgeType * > *incoming_edges, GraphModelItem *parent=0, EdgeType *parent_edge=0)
Definition: graph_model_item.h:144
int row() const
Return the row number this node has.
Definition: graph_model_item.cc:38
void set_num_of_files(uint)
Set the number of files for this item.
Definition: graph_model_item.cc:114
virtual QVariant data(int column) const
Fetch a specific property (column, see the Enum above) for this node.
Definition: graph_model_item.cc:49
bool self_referential() const
Whether this is a node that is a child of itself.
Definition: graph_model_item.h:171
Definition: graph_model_item.h:22
Definition: graph_model_item.h:138
void appendChild(GraphModelItem *child)
Append a child to this node.
Definition: graph_model_item.cc:26
std::vector< EdgeType * > * edges_
List of all outgoing edges (non-hierarchical data)
Definition: graph_model_item.h:198
std::vector< EdgeType * > * incoming_edges()
Return the list of edge datas belonging to this node.
Definition: graph_model_item.h:166
std::vector< EdgeType * > * incoming_edges_
List of all incoming edges (non-hierarchical data)
Definition: graph_model_item.h:200
EdgeType * parent_edge_
The edge that was used to reach this node in the tree.
Definition: graph_model_item.h:196
virtual QVariant data(int column) const
Definition: graph_model_item.h:183
void set_num_of_modules(uint)
Set the number of modules for this item.
Definition: graph_model_item.cc:106
GraphModelItem * child(int row)
Returns a specific child (the one identified by row number row) of this node.
Definition: graph_model_item.cc:30
NodeType * node_
Information about underlying graph.
Definition: graph_model_item.h:194
GraphModelItem(GraphModelItem *parent=0)
If this is not in a tree, you can leave the parent as 0.
Definition: graph_model_item.cc:6