-
Notifications
You must be signed in to change notification settings - Fork 6
/
qgraph.h
167 lines (110 loc) · 3.71 KB
/
qgraph.h
1
2
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* Author: Arvin Schnell <aschnell@suse.de>
*
* Licence: GPL V2
*/
/*
* Modified by: Zoltan Borok-Nagy <boroknagyz@gmail.com>
* 2010-03
*/
#ifndef QGRAPH_H
#define QGRAPH_H
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsPathItem>
#include <QPicture>
#include <QContextMenuEvent>
#include <QMouseEvent>
#include <QList>
#include <graphviz/gvc.h>
/**
* The QGraph widget shows a graph layouted by graphviz in a
* QGraphicsView/QGraphicsScene.
*/
class QNode;
class QGraph : public QGraphicsView
{
Q_OBJECT
public:
QGraph(QWidget *parent = 0);
//QGraph(const QString& filename, const QString& layoutAlgorithm, QWidget* parent = 0);
//QGraph(graph_t* graph, QWidget* parent = 0);
virtual ~QGraph();
virtual void renderGraph(GVC_t* gvc, graph_t* graph, const QString& layoutAlgorithm);
virtual void renderGraph(graph_t* graph);
virtual void layout(const QString& layoutAlgorithm);
virtual QGraphicsScene* getScene() { return scene; }
QColor getColorOfNode(const QString& id) const;
QNode* getNodeById(const QString& id) const;
void clearGraph();
graph_t* getGraph() { return theGraph; }
public slots:
void colorNode(const QString& nodeId, const QColor &color);
void colorAllNode(const QColor& color);
bool follow(bool on);
signals:
void backgroundContextMenuEvent(QContextMenuEvent* event);
void nodeContextMenuEvent(QContextMenuEvent* event, const QString& name);
void nodeDoubleClickEvent(QMouseEvent* event, QString name);
void nodeClicked(QString name);
private slots:
void nodeClick(QNode* node);
//virtual void BuildGraph();
protected:
void keyPressEvent(QKeyEvent* event);
void wheelEvent(QWheelEvent* event);
void contextMenuEvent(QContextMenuEvent* event);
void mouseDoubleClickEvent(QMouseEvent* event);
private:
void init();
void scaleView(qreal scaleFactor);
QGraphicsScene* scene;
QString activeNode;
QList<QNode*> nodeList;
QRectF graphRect;
bool mFollow;
QPointF gToQ(const point& p, bool upside_down = true) const;
QPointF gToQ(const pointf& p, bool upside_down = true) const;
QString aggetToQString(void* obj, const char* name, const QString& fallback) const;
QColor aggetToQColor(void* obj, const char* name, const QColor& fallback) const;
Qt::PenStyle aggetToQPenStyle(void* obj, const char* name, const Qt::PenStyle fallback) const;
QPainterPath makeShape(node_t* node) const;
QPolygonF makeShapeHelper(node_t* node) const;
QPainterPath makeBezier(const bezier& bezier) const;
void drawLabel(const textlabel_t* textlabel, QPainter* painter) const;
void drawArrow(const QLineF& line, const QColor& color, QPainter* painter) const;
private:
graph_t *theGraph;
GVC_t *theGvc;
};
class QNode : public QObject, public QGraphicsPathItem
{
Q_OBJECT
public:
QNode(const QPainterPath& path, const QPicture& picture, const QString id_,
const QString &text_, node_t *node_);
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
void mousePressEvent( QGraphicsSceneMouseEvent * );
QString getText() { return text; }
void setText(const QString &n) { text = n; }
QString getId() const { return id; }
node_t* getNode() { return node; }
signals:
void clicked(QNode *);
private:
QPicture picture;
QString text;
QString id;
private:
node_t *node;
};
class QEdge : public QGraphicsPathItem
{
public:
QEdge(const QPainterPath& path, const QPicture& picture);
QRectF boundingRect() const;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
private:
QPicture picture;
};
#endif