forked from ilongio/ilong
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeometry.cpp
139 lines (121 loc) · 2.55 KB
/
Geometry.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
#include "Geometry.h"
Geometry::Geometry(ILongGeoType gType, quint8 lWidth, QColor iPen, QColor iBrush)
{
geoType = gType;
if(gType == iGeoPolygon)
lineWidth = lWidth;
else
size = lWidth;
pen = iPen;
brush = iBrush;
QUuid id = QUuid::createUuid();
itemID = id.data1;
label = "";
dir = 0;
closeFlag = false;
rect.maxX = 0;
rect.maxY = 0;
rect.minX = 0;
rect.minY = 0;
}
ILongGeoRect Geometry::getRect()
{
return rect;
}
ILongGeoType Geometry::getGeoType()
{
return geoType;
}
QPointF Geometry::getCenter()
{
return QPointF((rect.maxX + rect.minX)/2,(rect.maxY + rect.minY)/2);
}
QString Geometry::getPen()
{
return QString("%1_%2_%3").arg(pen.red()).arg(pen.green()).arg(pen.blue());
}
QString Geometry::getBrush()
{
return QString("%1_%2_%3").arg(brush.red()).arg(brush.green()).arg(brush.blue());
}
QString Geometry::getPoints()
{
QString result = "";
for(int i=0; i<list.size(); i++)
{
QPointF p = list.at(i);
result += QString("%1,%2_").arg(QString::number(p.x(),'g',10))
.arg(QString::number(p.y(),'g',10));
}
return result.left(result.length()-1);
}
quint8 Geometry::getLineWidth()
{
return lineWidth;
}
quint8 Geometry::getSize()
{
return size;
}
quint32 Geometry::getID()
{
return itemID;
}
int Geometry::getDir()
{
return dir;
}
bool Geometry::getCloseFlag()
{
return closeFlag;
}
void Geometry::rotate(int dir)
{
setTransform(QTransform().rotate(dir), true);
}
void Geometry::setLabel(QString lb)
{
label = lb;
}
QString Geometry::getLabel()
{
return label;
}
int Geometry::getLabelPixeSize()
{
QLabel lb;
return lb.fontMetrics().width(label);
}
void Geometry::checkRect()
{
if(list.size() == 0)
{
list.append(QPointF(0,0));
list.append(QPointF(0,0));
}
if(list.size() == 1)
{
if(geoType != iGeoPolygon)
{
rect.minX = list.at(0).x();
rect.minY = list.at(0).y();
rect.maxX = list.at(0).x();
rect.maxY = list.at(0).y();
return;
}
list.append(list.at(0));
}
QPointF p1 = list.at(0);
rect.minX = p1.x();
rect.minY = p1.y();
rect.maxX = p1.x();
rect.maxY = p1.y();
for(int i=1; i<list.size(); i++)
{
p1 = list.at(i);
if(p1.x() >= rect.maxX) rect.maxX = p1.x();
if(p1.x() <= rect.minX) rect.minX = p1.x();
if(p1.y() >= rect.maxY) rect.maxY = p1.y();
if(p1.y() <= rect.minY) rect.minY = p1.y();
}
}