forked from UIDO/UMapControl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Manager.cpp
183 lines (170 loc) · 4.11 KB
/
Manager.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include "Manager.h"
Manager::Manager(UMapControl *iL, QObject *parent) : QObject(parent),uMap(iL),sqlExcute(&iL->sqlExcute),tempGeo(0)
{
qsrand(QDateTime::currentDateTime().time().second());
QSqlQuery * query = sqlExcute->initLayerManager();
while(query->next())
{
QString id = query->value(0).toString();
QString name = query->value(1).toString();
int visible = query->value(2).toInt();
int selectable = query->value(3).toInt();
loadLayer(id,name,visible, selectable);
}
delete query;
query = 0;
connect(this, SIGNAL(addGeoToScene(Geometry*)), uMap, SLOT(addGeoToScene(Geometry*)));
}
QList<Layer *> Manager::getLayers()
{
return list;
}
Layer *Manager::addLayer(QString name, QList<UM::Format> *typeList)
{
QString layerName = checkLayerName(name);
if(name == "UISDO" && layerName != name)
return getLayer(name);
Layer * layer = new Layer(uMap, layerName, typeList);
list.append(layer);
return layer;
}
Layer *Manager::getLayer(QString name)
{
Layer * l = nullptr;
for(int i=0; i<list.size(); i++)
{
if(list.at(i)->getLayerName() == name)
{
l = list.at(i);
break;
}
}
return l;
}
Layer *Manager::getLayerByID(QString id)
{
Layer * l = nullptr;
for(int i=0; i<list.size(); i++)
{
if(list.at(i)->getLayerID() == id)
{
l = list.at(i);
break;
}
}
return l;
}
void Manager::removeLayer(QString name)
{
Layer * l = getLayer(name);
if(name == "UISDO")
{
if(l != nullptr)
sqlExcute->clearLayer(l->getLayerID());
return;
}
if(l != nullptr)
{
if(name == "UISDO")
sqlExcute->clearLayer(l->getLayerID());
else
{
list.removeOne(l);
delete l;
}
uMap->updateMap();
}
}
void Manager::stopUpdateLayer()
{
isUpdate = false;
}
void Manager::addTempItem(QPointF world, UM::GeoType type)
{
QColor pen = QColor(qrand()%255,qrand()%255,qrand()%255);
if(!tempGeo)
{
switch (type) {
case UM::iGeoCircle:
tempGeo = new GeoCircle(world,40,pen,pen);
break;
case UM::iGeoRect:
tempGeo = new GeoRect(world,40,pen,pen);
break;
case UM::iGeoPie:
tempGeo = new GeoPie(world,80,0,pen,pen);
break;
case UM::iGeoStar:
tempGeo = new GeoStar(world,40,pen,pen);
break;
case UM::iGeoTri:
tempGeo = new GeoTri(world,40,pen,pen);
break;
default:
break;
}
tempGeo->setPos(uMap->worldToScene(world));
tempGeo->setScale(uMap->itemScale);
tempGeo->setZValue(3);
emit addGeoToScene(tempGeo);
}
else
{
tempGeo->setTempColor(pen);
tempGeo->setPos(uMap->worldToScene(world));
}
}
bool Manager::moveLayer(QString name, bool up)
{
Layer * l = getLayer(name);
if(!l)
return false;
int index = list.indexOf(l);
if(up)
{
if(index == 0)
return false;
list.removeAt(index);
list.insert(index - 1, l);
return true;
}
if(index == list.size()+1)
return false;
list.removeAt(index);
list.insert(index + 1, l);
return true;
}
void Manager::resetTempGeo()
{
tempGeo = nullptr;
}
void Manager::updatLayer()
{
isUpdate = true;
for(int i=0; i<list.size() && isUpdate; i++)
{
if(list.at(i)->isVisible() && isUpdate)
{
list.at(i)->updatLayer(&isUpdate);
}
}
this->thread()->exit();
}
QString Manager::checkLayerName(QString name)
{
QString tmp = name ;
for(int i=0; i<list.size(); i++)
{
if(list.at(i)->getLayerName() == tmp)
{
tmp.append("*");
break;
}
}
return name == tmp ? tmp : checkLayerName(tmp);
}
void Manager::loadLayer(QString id, QString name, bool visible, bool selectable)
{
Layer * layer = new Layer(uMap,id,name,visible,selectable);
list.append(layer);
}