-
Notifications
You must be signed in to change notification settings - Fork 0
/
Patch.cpp
97 lines (83 loc) · 1.81 KB
/
Patch.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
/*
* Patch.cpp
*
* Created on: Jun 9, 2010
* Author: Vincent
*/
#include "Patch.h"
QDataStream & operator<<(QDataStream & stream, const Patch & patch) {
stream << (qint32) patch.getType();
switch (patch.getType()) {
case Patch::PATCH_NULL:
break;
case Patch::PATCH_ELLIPSE:
case Patch::PATCH_RECTANGLE:
stream << patch.getRectangle();
break;
case Patch::PATCH_POLYGON:
stream << patch.getPolygon();
break;
}
return stream;
}
QDataStream & operator>>(QDataStream & stream, Patch & patch) {
qint32 patchType;
stream >> patchType;
QRect rect;
QPolygon polygon;
switch ((Patch::PatchType) patchType) {
case Patch::PATCH_NULL:
break;
case Patch::PATCH_ELLIPSE:
case Patch::PATCH_RECTANGLE:
stream >> rect;
patch.setRectangle(rect);
break;
case Patch::PATCH_POLYGON:
stream >> polygon;
patch.setPolygon(polygon);
break;
}
return stream;
}
QDataStream & operator<<(QDataStream & stream, const PatchList & patchList) {
for (qint32 i = 0; i < patchList.size(); ++i) {
stream << patchList[i];
}
return stream;
}
QDataStream & operator>>(QDataStream & stream, PatchList & patchList) {
patchList.clear();
for (qint32 i = 0; i < patchList.size(); ++i) {
Patch patch;
stream >> patch;
patchList.append(patch);
}
return stream;
}
Patch::Patch(PatchType type) :
type(type) {
}
Patch::~Patch() {
}
void Patch::setType(PatchType type) {
this->type = type;
}
Patch::PatchType Patch::getType() const {
return type;
}
void Patch::setPolygon(const QPolygon & polygon) {
this->polygon = polygon;
}
void Patch::setRectangle(const QRect & rectangle) {
this->rectangle = rectangle;
}
const QPolygon & Patch::getPolygon() const {
return this->polygon;
}
const QRect & Patch::getRectangle() const {
return this->rectangle;
}
const QRect & Patch::getEllipse() const {
return getRectangle();
}