-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvertex.cpp
156 lines (128 loc) · 4.43 KB
/
vertex.cpp
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
#include "vertex.h"
#include <fstream>
/********************************************************************************************************/
//Constructor and Destructor
/********************************************************************************************************/
Vertex::Vertex(QPoint newPoint){
flow_sum = 0;
rect.setRect(newPoint.x(), newPoint.y(), 50, 50);
id = 0;
color.setRgb(255,255,255); //white color as default
}
/*The copy construtor*/
Vertex::Vertex(Vertex* toCopy){
*this = *toCopy;
}
/********************************************************************************************************/
//set functions
/********************************************************************************************************/
void Vertex::setRad(int newRad){
rad = newRad;
}
void Vertex::setFlowSum(int newFlowSum){
flow_sum = newFlowSum;
}
void Vertex::setId(int newId)
{
id = newId;
}
void Vertex::setPoint(QPoint newPoint){
rect.moveTo(newPoint.x(), newPoint.y());
}
void Vertex::setColor(QColor newColor){
color = newColor;
}
void Vertex::setRectSize(QSize newRectSize){
rect.setSize(newRectSize);
}
void Vertex::setRect(QRect newRect){
rect = newRect;
}
/********************************************************************************************************/
//get functions
/********************************************************************************************************/
int Vertex::getRad(){
return rad;
}
int Vertex::getFlowSum(){
return flow_sum;
}
int Vertex::getId()
{
return id;
}
QPoint Vertex::getPoint(){
QPoint rectPoint(rect.x(), rect.y());
return rectPoint;
}
QColor Vertex::getColor(){
return color;
}
QRect Vertex::getRect()
{
return rect;
}
QPoint Vertex::getCenterPoint()
{
return rect.center();
}
/********************************************************************************************************/
//update functions
/********************************************************************************************************/
void Vertex::updateVertexPosition(QPoint newPoint){
setPoint(newPoint);
}
void Vertex::updateVertexInformations(int newRad, QColor newColor){
if (newRad) rad = newRad;
color = newColor;
}
/********************************************************************************************************/
//Sobrecarga de Operadores
/********************************************************************************************************/
bool Vertex::operator ==(Vertex *right){
if ( (id == right->id) && (rad == right->rad) && (flow_sum == right->flow_sum) ){
if ( (rect == right->rect) && (color == right->color) )
return true;
}
return false;
}
bool Vertex::operator !=(Vertex *right){
if ( (id != right->id) && (rad != right->rad) && (flow_sum != right->flow_sum) ){
if ( (rect == right->rect) && (color != right->color) )
return true;
}
return false;
}
void Vertex::operator =(Vertex *right){
id = right->id;
rad = right->rad;
flow_sum = right->flow_sum;
rect = right->rect;
color = right->color;
}
std::ostream& operator <<(std::ostream& os, const Vertex& right){
os << "[ ";
os << right.id << " , ";
os << right.flow_sum << " , ";
os << "( " << right.rect.x() << " , " << right.rect.y() << ")" << ",";
os << "( " << right.color.red() << " , " << right.color.green() << " , " << right.color.blue() << ")" << ",";
os << "]";
return os;
}
std::istream& operator >>(std::istream& is, Vertex& right){
char marks[3]; //just to get the marks writen by the ostream
int x,y;
int r,g,b;
is >> marks;
is >> right.id >> marks;
is >> right.flow_sum >> marks;
is >> marks >> x;
is >> marks >> y;
right.setPoint(QPoint(x,y));
is >> marks;
is >> r >> marks;
is >> g >> marks;
is >> b;
right.setColor(QColor(r,g,b,255));
return is;
}