Skip to content

Commit

Permalink
修正临时点和背景图片内存泄漏问题,修正GPS临时点算法,处理触摸缩放问题还是不杂写,先放着几天
Browse files Browse the repository at this point in the history
  • Loading branch information
uisdo committed Jul 26, 2017
1 parent 2d4b287 commit de2adbb
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 32 deletions.
7 changes: 7 additions & 0 deletions Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ int Geometry::getLabelPixeSize()
return lb.fontMetrics().width(label);
}

void Geometry::setTempColor(QColor c)
{
brush = c;
pen = c;
update();
}

void Geometry::checkRect()
{
if(list.size() == 0)
Expand Down
1 change: 1 addition & 0 deletions Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class UMAPCONTROLSHARED_EXPORT Geometry : public QGraphicsObject
void setLabel(QString lb);
QString getLabel();
int getLabelPixeSize();
void setTempColor(QColor c);
protected:
void checkRect();
QList<QPointF> list;
Expand Down
62 changes: 33 additions & 29 deletions Manager.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "Manager.h"

Manager::Manager(UMapControl *iL, QObject *parent) : QObject(parent),uMap(iL),sqlExcute(&iL->sqlExcute)
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())
{
Expand Down Expand Up @@ -88,38 +89,38 @@ void Manager::stopUpdateLayer()

void Manager::addTempItem(QPointF world, UM::GeoType type)
{
if(tempGeo)
uMap->scene()->removeItem(tempGeo);
qsrand(QDateTime::currentDateTime().time().second());
tempGeoType = type;
tempGeoWorldPos = world;
QColor pen = QColor(qrand()%255,qrand()%255,qrand()%255);
switch (tempGeoType) {
case UM::iGeoCircle:
tempGeo = new GeoCircle(tempGeoWorldPos,40,pen,pen);
break;
case UM::iGeoRect:
tempGeo = new GeoRect(tempGeoWorldPos,40,pen,pen);
break;
case UM::iGeoPie:
tempGeo = new GeoPie(tempGeoWorldPos,80,0,pen,pen);
break;
case UM::iGeoStar:
tempGeo = new GeoStar(tempGeoWorldPos,40,pen,pen);
break;
case UM::iGeoTri:
tempGeo = new GeoTri(tempGeoWorldPos,40,pen,pen);
break;
default:
break;
}
if(tempGeo)
if(!tempGeo)
{
tempGeo->setPos(uMap->worldToScene(tempGeoWorldPos));
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)
Expand All @@ -143,9 +144,13 @@ bool Manager::moveLayer(QString name, bool up)
return true;
}

void Manager::updatLayer()
void Manager::resetTempGeo()
{
tempGeo = nullptr;
}

void Manager::updatLayer()
{
isUpdate = true;
for(int i=0; i<list.size() && isUpdate; i++)
{
Expand All @@ -154,7 +159,6 @@ void Manager::updatLayer()
list.at(i)->updatLayer(&isUpdate);
}
}
addTempItem(tempGeoWorldPos,tempGeoType);
this->thread()->exit();
}

Expand Down
4 changes: 1 addition & 3 deletions Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class UMAPCONTROLSHARED_EXPORT Manager : public QObject
void stopUpdateLayer();
void addTempItem(QPointF world, UM::GeoType type = UM::iGeoCircle);
bool moveLayer(QString name, bool up = true);
void resetTempGeo();
private:
/*
* 检查图层名称@name是否在图层管理表里,如果有,就自动在@name后面加*号,暂时这样处理导入多个同名图层
Expand All @@ -90,9 +91,6 @@ class UMAPCONTROLSHARED_EXPORT Manager : public QObject
QList<Layer *> list;
SQLExcute * sqlExcute;
bool isUpdate;

QPointF tempGeoWorldPos;
UM::GeoType tempGeoType;
Geometry * tempGeo;
signals:
void addGeoToScene(Geometry *);
Expand Down
2 changes: 2 additions & 0 deletions UMapControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,14 @@ void UMapControl::tilesUrlMatrix(bool onlyBackground)
if(l.at(i)->zValue() == 0)
{
scene()->removeItem(l.at(i));
delete l.at(i);
}
}
}
else
{
scene()->clear();
manager->resetTempGeo();
}
/*
* 再从数据库里读取当前场景有效的瓦片,如果读取失败,直接把@tList里的所有坐标生成path保存到@list里,
Expand Down

0 comments on commit de2adbb

Please sign in to comment.