GraphTool  1.0
Tool for analyzing and graphically visualizing code dependencies for Ericsson.
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
node_widget.h
1 
7 #ifndef GUI_NODE_WIDGET_H_
8 #define GUI_NODE_WIDGET_H_
9 
10 #include <QGraphicsEllipseItem>
11 #include <QPainter>
12 #include <QDebug>
13 #include <QWidget>
14 #include <QGraphicsItem>
15 #include <iostream>
16 #include <QGraphicsScene>
17 #include <QObject>
18 #include <QStyleOptionGraphicsItem>
19 #include <set>
20 #include "edge_widget.h"
21 
22 class EdgeWidget;
23 
25 struct CompareEdgeByNodes : public std::binary_function<EdgeWidget*, EdgeWidget*, bool> {
26  bool operator()(EdgeWidget* a, EdgeWidget* b) const;
27 };
28 
29 class NodeWidget : public QGraphicsItem {
30 
31  public:
32 
37  NodeWidget(const QString& node_text, QGraphicsItem * parent = 0);
38 
43 
49  void set_marked(bool marked);
50 
55  bool is_marked();
56 
61  void set_color(QColor);
62 
67  void set_opacity(int);
68 
73  QColor color();
74 
79  int opacity();
80 
85  QPainterPath shape() const;
86 
91  QRectF boundingRect() const;
92 
96  void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
97 
102  void add_edge(EdgeWidget* w);
103 
108  QString node_text();
109 
114  qreal height();
115 
120  qreal width();
121 
125  void unmark_path();
126 
130  void mark_path();
131 
132  QModelIndex get_index_in_model();
133 
134  void set_index_in_model(QModelIndex);
135 
136  protected:
138  QVariant itemChange(GraphicsItemChange change, const QVariant &value);
139 
141  void mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * event );
142 
144  void mousePressEvent ( QGraphicsSceneMouseEvent * event );
145 
146  private:
147 
153  void force_update(NodeWidget*, bool);
154 
161  void force_update(EdgeWidget*, bool);
162 
163  QString node_text_;
164  QColor color_;
165  int opacity_;
166  qreal height_;
167  qreal width_;
168  qreal pen_width_;
169  bool is_marked_;
170  QModelIndex index_;
171 
172  typedef std::set<EdgeWidget*, CompareEdgeByNodes> edge_list_;
173  edge_list_ edges;
174 };
175 
176 #endif
void add_edge(EdgeWidget *w)
Keep a list of edges in order to notify the edges when this item changes.
Definition: node_widget.cc:90
Definition: node_widget.h:29
void mousePressEvent(QGraphicsSceneMouseEvent *event)
Event handler for mouse clicks.
Definition: node_widget.cc:136
NodeWidget(const QString &node_text, QGraphicsItem *parent=0)
Definition: node_widget.cc:7
QColor color()
Definition: node_widget.cc:111
int opacity()
Definition: node_widget.cc:115
qreal width()
Definition: node_widget.cc:128
void set_marked(bool marked)
Definition: node_widget.cc:98
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
Event handler for double clicks.
Definition: node_widget.cc:132
QVariant itemChange(GraphicsItemChange change, const QVariant &value)
Event handler for changes to the item.
Definition: node_widget.cc:143
Definition: edge_widget.h:22
QString node_text()
Accessor functions.
Definition: node_widget.cc:120
Comparator used when adding edges to set.
Definition: node_widget.h:25
qreal height()
Definition: node_widget.cc:124
QPainterPath shape() const
The outline of the node.
Definition: node_widget.cc:34
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Paints the node.
Definition: node_widget.cc:50
void mark_path()
Definition: node_widget.cc:167
bool is_marked()
Definition: node_widget.cc:94
~NodeWidget()
Definition: node_widget.h:42
void set_opacity(int)
Definition: node_widget.cc:106
void unmark_path()
Definition: node_widget.cc:187
void set_color(QColor)
Definition: node_widget.cc:102
QRectF boundingRect() const
Required methods for drawing.
Definition: node_widget.cc:29