GraphItem.h
1.77 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
#ifndef GRAPHITEM_H
#define GRAPHITEM_H
#include "stdafx.h"
#include "NodeItem.h"
#include "EdgeItem.h"
using namespace std;
using namespace boost;
//enum GRAPH_LAYOUT {
// RANDOM_LAYOUT,
// CIRCLE_LAYOUT,
// //KAMADA_KAWAI_LAYOUT,
// FRUCHTERMAN_REINGOLD_LAYOUT //slow
//};
/**
* Constants
*/
//const int LAYOUT_MODE = GRAPH_LAYOUT::RANDOM_LAYOUT;
//const int SCREEN_SIZE = 300;
//const int NODE_LIMIT = 100;
//const boost::regex paper_reg("(conf|journals).*");
enum vertex_position_t { vertex_position };
enum vertex_type_t { vertex_type };
namespace boost {
BOOST_INSTALL_PROPERTY(vertex, position);
BOOST_INSTALL_PROPERTY(vertex, type);
}
typedef square_topology<>::point_type point;
struct simple_edge {
int first, second;
};
typedef boost::property<vertex_index_t, int,
boost::property<vertex_name_t, std::string,
boost::property<vertex_position_t, point,
boost::property<vertex_type_t, int>>>
> VertexProperties;
typedef adjacency_list<
listS, //outEdgeList
listS, //VertexList
undirectedS,
//vertex properties
VertexProperties,
//edge properties
boost::property<edge_weight_t, double>
> Graph;
class GraphItem
: public QGraphicsItem
{
public:
GraphItem(ifstream& fin);
//overrides
QRectF boundingRect() const override;
QPainterPath shape() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
//methods
void path_highlighting(std::string start, std::string end);
void reset_color();
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
private:
Graph *graph = nullptr;
QList<NodeItem *> nodeList;
QList<EdgeItem *> edgeList;
};
#endif // GRAPHITEM_H