From de2adbb834567a27c4ded2fe2827f05256d29463 Mon Sep 17 00:00:00 2001 From: U is do Date: Wed, 26 Jul 2017 22:46:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=B8=B4=E6=97=B6=E7=82=B9?= =?UTF-8?q?=E5=92=8C=E8=83=8C=E6=99=AF=E5=9B=BE=E7=89=87=E5=86=85=E5=AD=98?= =?UTF-8?q?=E6=B3=84=E6=BC=8F=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?GPS=E4=B8=B4=E6=97=B6=E7=82=B9=E7=AE=97=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E5=A4=84=E7=90=86=E8=A7=A6=E6=91=B8=E7=BC=A9=E6=94=BE=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E8=BF=98=E6=98=AF=E4=B8=8D=E6=9D=82=E5=86=99=EF=BC=8C?= =?UTF-8?q?=E5=85=88=E6=94=BE=E7=9D=80=E5=87=A0=E5=A4=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Geometry.cpp | 7 ++++++ Geometry.h | 1 + Manager.cpp | 62 ++++++++++++++++++++++++++----------------------- Manager.h | 4 +--- UMapControl.cpp | 2 ++ 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/Geometry.cpp b/Geometry.cpp index 680ce2a..9b6592c 100644 --- a/Geometry.cpp +++ b/Geometry.cpp @@ -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) diff --git a/Geometry.h b/Geometry.h index 78224ff..c22c5c5 100644 --- a/Geometry.h +++ b/Geometry.h @@ -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 list; diff --git a/Manager.cpp b/Manager.cpp index 0c932a0..dba7ffd 100644 --- a/Manager.cpp +++ b/Manager.cpp @@ -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()) { @@ -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) @@ -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; iupdatLayer(&isUpdate); } } - addTempItem(tempGeoWorldPos,tempGeoType); this->thread()->exit(); } diff --git a/Manager.h b/Manager.h index 7375e18..65c623d 100644 --- a/Manager.h +++ b/Manager.h @@ -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后面加*号,暂时这样处理导入多个同名图层 @@ -90,9 +91,6 @@ class UMAPCONTROLSHARED_EXPORT Manager : public QObject QList list; SQLExcute * sqlExcute; bool isUpdate; - - QPointF tempGeoWorldPos; - UM::GeoType tempGeoType; Geometry * tempGeo; signals: void addGeoToScene(Geometry *); diff --git a/UMapControl.cpp b/UMapControl.cpp index d452ed6..58a3f64 100644 --- a/UMapControl.cpp +++ b/UMapControl.cpp @@ -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里,