-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grid.cpp
92 lines (77 loc) · 1.58 KB
/
Grid.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
/*
* Grid.cpp
*
* Created on: Jun 9, 2010
* Author: Vincent
*/
#include "Grid.h"
QDataStream & operator<<(QDataStream & stream, const Grid & grid) {
stream << (qint32) grid.getType();
stream << (qint32) grid.getGeometries().size();
switch (grid.getType()) {
case Grid::GRID_NULL:
break;
case Grid::GRID_ELLIPSE:
case Grid::GRID_RECTANGLE:
for (qint32 i = 0; i < grid.getGeometries().size(); ++i) {
stream << grid.getGeometries()[i];
}
break;
}
return stream;
}
QDataStream & operator>>(QDataStream & stream, Grid & grid) {
qint32 gridType, gsize;
stream >> gridType;
stream >> gsize;
grid.setType((Grid::GridType) gridType);
grid.clear();
switch (gridType) {
case Grid::GRID_NULL:
break;
case Grid::GRID_ELLIPSE:
case Grid::GRID_RECTANGLE:
for (qint32 i = 0; i < gsize; ++i) {
QRect geometry;
stream >> geometry;
grid.appendGeometry(geometry);
}
break;
}
return stream;
}
Grid::Grid(Grid::GridType type) {
this->type = type;
}
Grid::~Grid() {
}
void Grid::setType(Grid::GridType type) {
this->type = type;
}
Grid::GridType Grid::getType() const {
return type;
}
void Grid::setGeometries(const QList<QRect> & grid) {
this->grid = grid;
}
void Grid::appendGeometry(const QRect & geometry) {
this->grid << geometry;
}
void Grid::clear() {
grid.clear();
}
QList<QRect> Grid::getGeometries() const {
return grid;
}
qint32 Grid::size() const {
return grid.size();
}
const QRect & Grid::operator[](qint32 i) const {
return grid[i];
}
QRect & Grid::operator[](qint32 i) {
return grid[i];
}
void Grid::remove(qint32 i) {
grid.removeAt(i);
}