PaperGraphWidget.cpp
2.08 KB
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
#include "PaperGraphWidget.h"
#include "NodeItem.h"
#include "GraphicsView.h"
#include <string>
PaperGraphWidget::PaperGraphWidget(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
initscene();
View *view = new View("temp view");
view->view()->setScene(scene);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(view);
setLayout(layout);
setWindowTitle(tr("dblp paper graph visualization"));
}
void PaperGraphWidget::print_graph(const Graph & graph)
{
//print graph
typedef square_topology<> Topology;
typedef typename Topology::point_type Point;
const int rect_sz = 4;
auto position = get(vertex_position, graph);
auto label = get(vertex_name, graph);
//print edges
typename graph_traits<Graph>::edge_iterator ei, ei_end;
typedef boost::graph_traits<Graph>::vertex_descriptor VertexDescriptor;
VertexDescriptor u, v;
for (boost::tie(ei, ei_end)=edges(graph); ei!=ei_end; ++ei) {
u = source(*ei, graph);
v = target(*ei, graph);
Point p1 = position[u];
Point p2 = position[v];
/*line = scene->addLine(
p1[0], p1[1],
p2[0], p2[1],
QPen(Qt::black)
);*/
//QGraphicsItem *edge =
// new EdgeItem(p1[0], p1[1], p2[0], p2[1]);
//edge->setPos(QPointF(p1[0], p1[1]));
//scene->addItem(edge);
scene->addLine(p1[0], p1[1], p2[0], p2[1], QPen(Qt::black, 0));
}
//print nodes
typename graph_traits<Graph>::vertex_iterator vi, vi_end;
for (boost::tie(vi, vi_end)=vertices(graph); vi!=vi_end; ++vi) {
//Point p = position[*vi];
//rectangle = scene->addRect(
// p[0], p[1], rect_sz, rect_sz,
// QPen(Qt::black),
// QBrush(Qt::green));
Point p = position[*vi];
std::string name = label[*vi];
QGraphicsItem *node = new NodeItem(p[0], p[1], QString(name.c_str()));
node->setPos(QPointF(p[0], p[1]));
scene->addItem(node);
}
}
void PaperGraphWidget::initscene()
{
scene = new QGraphicsScene(this);
//int x = 0, y;
//for (int i=-11000; i<11000; i+=110) {
// ++x;
// y = 0;
// for (int j=-7000; j<7000; j+=70) {
// ++y;
// QGraphicsItem *item = new NodeItem(x, y);
// item->setPos(QPointF(i, j));
// scene->addItem(item);
// }
//}
}