├── .gitignore ├── GeoCircle.cpp ├── GeoCircle.h ├── GeoPie.cpp ├── GeoPie.h ├── GeoPolygon.cpp ├── GeoPolygon.h ├── GeoRect.cpp ├── GeoRect.h ├── GeoStar.cpp ├── GeoStar.h ├── GeoTri.cpp ├── GeoTri.h ├── Geometry.cpp ├── Geometry.h ├── ILoveChina.cpp ├── ILoveChina.h ├── LICENSE ├── Layer.cpp ├── Layer.h ├── Manager.cpp ├── Manager.h ├── Map.cpp ├── Map.h ├── MapPix.cpp ├── MapPix.h ├── Network.cpp ├── Network.h ├── README.md ├── SQLExcute.cpp ├── SQLExcute.h ├── Screenshot.png ├── Screenshot1.png ├── UMapControl.cpp ├── UMapControl.h ├── UMapControl.pro ├── UMapControl.pro.user └── umapcontrol_global.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /GeoCircle.cpp: -------------------------------------------------------------------------------- 1 | #include "GeoCircle.h" 2 | 3 | GeoCircle::GeoCircle(QPointF world, int size, QColor pen, QColor brush) : 4 | Geometry(UM::iGeoCircle, size*0.6, pen, brush) 5 | { 6 | list.append(world); 7 | checkRect(); 8 | } 9 | 10 | QRectF GeoCircle::boundingRect() const 11 | { 12 | return QRectF(-size/2, -size/2, size, size); 13 | } 14 | 15 | QPainterPath GeoCircle::shape() const 16 | { 17 | QPainterPath path; 18 | path.addEllipse(-size/2, -size/2, size, size); 19 | return path; 20 | } 21 | 22 | void GeoCircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) 23 | { 24 | painter->setPen(pen); 25 | painter->setBrush(brush); 26 | painter->setRenderHint(QPainter::Antialiasing); 27 | painter->drawEllipse(-size/2, -size/2, size, size); 28 | if(label.length()) 29 | { 30 | QFont font = painter->font(); 31 | font.setFamily("Microsoft YaHei"); 32 | font.setBold(true); 33 | painter->setFont(font); 34 | painter->setPen(brush); 35 | painter->drawText(-getLabelPixeSize()/2,size+5,label); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /GeoCircle.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright © 2017 UISDO All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions, and the following disclaimer, 10 | * without modification. 11 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12 | * substantially similar to the "NO WARRANTY" disclaimer below 13 | * ("Disclaimer") and any redistribution must be conditioned upon 14 | * including a substantially similar Disclaimer requirement for further 15 | * binary redistribution. 16 | * 3. Neither the names of the above-listed copyright holders nor the names 17 | * of any contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * Alternatively, this software may be distributed under the terms of the 21 | * GNU General Public License ("GPL") version 2 as published by the Free 22 | * Software Foundation. 23 | * 24 | * NO WARRANTY 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 28 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 34 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 | * POSSIBILITY OF SUCH DAMAGES. 36 | */ 37 | 38 | #ifndef GEOCIRCLE_H 39 | #define GEOCIRCLE_H 40 | 41 | #include 42 | #include "Geometry.h" 43 | namespace UM { 44 | class GeoCircle; 45 | } 46 | class UMAPCONTROLSHARED_EXPORT GeoCircle : public Geometry 47 | { 48 | Q_OBJECT 49 | public: 50 | explicit GeoCircle(QPointF world, int size = 80, QColor pen = QColor(Qt::blue), QColor brush = QColor(Qt::yellow)); 51 | protected: 52 | QRectF boundingRect() const Q_DECL_OVERRIDE; 53 | QPainterPath shape() const Q_DECL_OVERRIDE; 54 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE; 55 | signals: 56 | 57 | public slots: 58 | }; 59 | 60 | #endif // GEOCIRCLE_H 61 | -------------------------------------------------------------------------------- /GeoPie.cpp: -------------------------------------------------------------------------------- 1 | #include "GeoPie.h" 2 | #include 3 | 4 | GeoPie::GeoPie(QPointF world, int size, int dir, QColor pen, QColor brush) : 5 | Geometry(UM::iGeoPie, size, pen, brush) 6 | { 7 | list.append(world); 8 | this->dir = dir; 9 | checkRect(); 10 | } 11 | 12 | QRectF GeoPie::boundingRect() const 13 | { 14 | return QRectF(-size/2, -size/2, size, size); 15 | } 16 | 17 | QPainterPath GeoPie::shape() const 18 | { 19 | QPainterPath path; 20 | //path.addRect(-size/2, -size/2, size, size); 21 | QPolygonF polygon; 22 | polygon.append(QPointF(0,0)); 23 | polygon.append(QPointF(-size/6,-size/2)); 24 | polygon.append(QPointF(size/6,-size/2)); 25 | path.addPolygon(polygon); 26 | return path; 27 | } 28 | 29 | void GeoPie::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) 30 | { 31 | painter->setPen(pen); 32 | painter->setBrush(brush); 33 | painter->setRenderHint(QPainter::Antialiasing); 34 | painter->drawPie(-size/2, -size/2, size, size-2,70*16, 40*16); 35 | if(label.length()) 36 | { 37 | QFont font = painter->font(); 38 | font.setFamily("Microsoft YaHei"); 39 | font.setBold(true); 40 | painter->setFont(font); 41 | painter->setPen(brush); 42 | painter->drawText(-getLabelPixeSize()/2,-size/2-5,label); 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /GeoPie.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 UISDO All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions, and the following disclaimer, 9 | * without modification. 10 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer 11 | * substantially similar to the "NO WARRANTY" disclaimer below 12 | * ("Disclaimer") and any redistribution must be conditioned upon 13 | * including a substantially similar Disclaimer requirement for further 14 | * binary redistribution. 15 | * 3. Neither the names of the above-listed copyright holders nor the names 16 | * of any contributors may be used to endorse or promote products derived 17 | * from this software without specific prior written permission. 18 | * 19 | * Alternatively, this software may be distributed under the terms of the 20 | * GNU General Public License ("GPL") version 2 as published by the Free 21 | * Software Foundation. 22 | * 23 | * NO WARRANTY 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGES. 35 | */ 36 | 37 | #ifndef GEOPIE_H 38 | #define GEOPIE_H 39 | 40 | #include 41 | #include 42 | 43 | #include "Geometry.h" 44 | namespace UM { 45 | class GeoPie; 46 | } 47 | class UMAPCONTROLSHARED_EXPORT GeoPie : public Geometry 48 | { 49 | Q_OBJECT 50 | public: 51 | explicit GeoPie(QPointF world, int size = 80, int dir = 0, QColor pen = QColor(Qt::blue), QColor brush = QColor(Qt::yellow)); 52 | protected: 53 | QRectF boundingRect() const Q_DECL_OVERRIDE; 54 | QPainterPath shape() const Q_DECL_OVERRIDE; 55 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE; 56 | signals: 57 | 58 | public slots: 59 | private: 60 | 61 | }; 62 | 63 | #endif // GEOPIE_H 64 | -------------------------------------------------------------------------------- /GeoPolygon.cpp: -------------------------------------------------------------------------------- 1 | #include "GeoPolygon.h" 2 | 3 | GeoPolygon::GeoPolygon(UMapControl *iL, QList * pointList, bool closePath, quint8 lineWidth, QColor pen, QColor brush) : 4 | Geometry(UM::iGeoPolygon,lineWidth, pen, brush),uMap(iL) 5 | { 6 | closeFlag = closePath; 7 | for(int i=0; isize(); i++) 8 | list.append(pointList->at(i)); 9 | checkRect(); 10 | QPointF tl = uMap->worldToScene(QPointF(rect.minX,rect.minY)); 11 | QPointF br = uMap->worldToScene(QPointF(rect.maxX,rect.maxY)); 12 | size = fabs(tl.x()-br.x());//polygonWidth.length(); 13 | pHeight = fabs(tl.y()-br.y());//polygonHeight.length(); 14 | QPointF telta = uMap->worldToScene(QPointF(rect.minX,rect.maxY)); 15 | for(int i=0; iworldToScene(list.at(i))-telta); 17 | } 18 | 19 | QRectF GeoPolygon::boundingRect() const 20 | { 21 | return QRectF(0, 0, size, pHeight); 22 | } 23 | 24 | QPainterPath GeoPolygon::shape() const 25 | { 26 | QPainterPath path; 27 | if(closeFlag) 28 | path.addPolygon(polygon); 29 | return path; 30 | } 31 | 32 | void GeoPolygon::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) 33 | { 34 | QPen xPen(QBrush(pen),lineWidth); 35 | painter->setPen(xPen); 36 | painter->setRenderHint(QPainter::Antialiasing); 37 | if(closeFlag) 38 | painter->setBrush(brush); 39 | QPainterPath path; 40 | path.addPolygon(polygon); 41 | if(closeFlag) 42 | path.closeSubpath(); 43 | painter->drawPath(path); 44 | //多段线就不应该显示标注 45 | if((label.length() && closeFlag) || 46 | (label.length() && polygon.size() == 2 && !closeFlag)) 47 | { 48 | QFont font = painter->font(); 49 | font.setFamily("Microsoft YaHei"); 50 | font.setBold(true); 51 | painter->setFont(font); 52 | painter->setPen(pen); 53 | painter->drawText((size-getLabelPixeSize())/2,pHeight/2,label); 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /GeoPolygon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 UISDO All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions, and the following disclaimer, 9 | * without modification. 10 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer 11 | * substantially similar to the "NO WARRANTY" disclaimer below 12 | * ("Disclaimer") and any redistribution must be conditioned upon 13 | * including a substantially similar Disclaimer requirement for further 14 | * binary redistribution. 15 | * 3. Neither the names of the above-listed copyright holders nor the names 16 | * of any contributors may be used to endorse or promote products derived 17 | * from this software without specific prior written permission. 18 | * 19 | * Alternatively, this software may be distributed under the terms of the 20 | * GNU General Public License ("GPL") version 2 as published by the Free 21 | * Software Foundation. 22 | * 23 | * NO WARRANTY 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGES. 35 | */ 36 | 37 | #ifndef GEOPOLYGON_H 38 | #define GEOPOLYGON_H 39 | 40 | #include 41 | #include "Geometry.h" 42 | #include "UMapControl.h" 43 | namespace UM { 44 | class GeoPolygon; 45 | } 46 | class UMAPCONTROLSHARED_EXPORT GeoPolygon : public Geometry 47 | { 48 | Q_OBJECT 49 | public: 50 | explicit GeoPolygon(UMapControl *iL, QList *pointList, bool closePath = false, quint8 lineWidth = 1, QColor pen = QColor(Qt::red), QColor brush = QColor(Qt::yellow)); 51 | protected: 52 | QRectF boundingRect() const Q_DECL_OVERRIDE; 53 | QPainterPath shape() const Q_DECL_OVERRIDE; 54 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE; 55 | signals: 56 | 57 | public slots: 58 | private: 59 | UMapControl *uMap; 60 | bool needClosePath; 61 | QPolygonF polygon; 62 | int pHeight; 63 | }; 64 | 65 | #endif // GEOCIRCLE_H 66 | -------------------------------------------------------------------------------- /GeoRect.cpp: -------------------------------------------------------------------------------- 1 | #include "GeoRect.h" 2 | 3 | GeoRect::GeoRect(QPointF world, int size, QColor pen, QColor brush) : 4 | Geometry(UM::iGeoRect, size*0.6, pen, brush) 5 | { 6 | list.append(world); 7 | checkRect(); 8 | } 9 | 10 | QRectF GeoRect::boundingRect() const 11 | { 12 | return QRectF(-size/2, -size/2, size, size); 13 | } 14 | 15 | QPainterPath GeoRect::shape() const 16 | { 17 | QPainterPath path; 18 | path.addRect(-size/2, -size/2, size, size); 19 | return path; 20 | } 21 | 22 | void GeoRect::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) 23 | { 24 | painter->setPen(pen); 25 | painter->setBrush(brush); 26 | painter->setRenderHint(QPainter::Antialiasing); 27 | painter->drawRect(-size/2,-size/2,size,size); 28 | if(label.length()) 29 | { 30 | QFont font = painter->font(); 31 | font.setFamily("Microsoft YaHei"); 32 | font.setBold(true); 33 | painter->setFont(font); 34 | painter->setPen(brush); 35 | painter->drawText(-getLabelPixeSize()/2,size+5,label); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /GeoRect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 UISDO All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions, and the following disclaimer, 9 | * without modification. 10 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer 11 | * substantially similar to the "NO WARRANTY" disclaimer below 12 | * ("Disclaimer") and any redistribution must be conditioned upon 13 | * including a substantially similar Disclaimer requirement for further 14 | * binary redistribution. 15 | * 3. Neither the names of the above-listed copyright holders nor the names 16 | * of any contributors may be used to endorse or promote products derived 17 | * from this software without specific prior written permission. 18 | * 19 | * Alternatively, this software may be distributed under the terms of the 20 | * GNU General Public License ("GPL") version 2 as published by the Free 21 | * Software Foundation. 22 | * 23 | * NO WARRANTY 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGES. 35 | */ 36 | 37 | #ifndef GEORECT_H 38 | #define GEORECT_H 39 | 40 | #include 41 | #include "Geometry.h" 42 | namespace UM { 43 | class GeoRect; 44 | } 45 | class UMAPCONTROLSHARED_EXPORT GeoRect : public Geometry 46 | { 47 | Q_OBJECT 48 | public: 49 | explicit GeoRect(QPointF world, int size = 80, QColor pen = QColor(Qt::blue), QColor brush = QColor(Qt::yellow)); 50 | protected: 51 | QRectF boundingRect() const Q_DECL_OVERRIDE; 52 | QPainterPath shape() const Q_DECL_OVERRIDE; 53 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE; 54 | signals: 55 | 56 | public slots: 57 | }; 58 | 59 | #endif // GEORECT_H 60 | -------------------------------------------------------------------------------- /GeoStar.cpp: -------------------------------------------------------------------------------- 1 | #include "GeoStar.h" 2 | 3 | GeoStar::GeoStar(QPointF world, int size, QColor pen, QColor brush) : 4 | Geometry(UM::iGeoStar, size*0.8, pen, brush) 5 | { 6 | list.append(world); 7 | checkRect(); 8 | } 9 | 10 | QRectF GeoStar::boundingRect() const 11 | { 12 | return QRectF(-size/2, -size/2, size, size); 13 | } 14 | 15 | QPainterPath GeoStar::shape() const 16 | { 17 | QPainterPath path; 18 | QPolygonF polygon; 19 | polygon.append(QPointF(0,-size/2));polygon.append(QPointF(-size/8,-size/8)); 20 | polygon.append(QPointF(-size/2,0));polygon.append(QPointF(-size/8,size/8)); 21 | polygon.append(QPointF(0,size/2));polygon.append(QPointF(size/8,size/8)); 22 | polygon.append(QPointF(size/2,0));polygon.append(QPointF(size/8,-size/8)); 23 | path.addPolygon(polygon); 24 | path.closeSubpath(); 25 | return path; 26 | } 27 | 28 | void GeoStar::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) 29 | { 30 | painter->setPen(pen); 31 | painter->setBrush(brush); 32 | painter->setRenderHint(QPainter::Antialiasing); 33 | QPolygonF polygon; 34 | polygon.append(QPointF(0,-size/2));polygon.append(QPointF(-size/8,-size/8)); 35 | polygon.append(QPointF(-size/2,0));polygon.append(QPointF(-size/8,size/8)); 36 | polygon.append(QPointF(0,size/2));polygon.append(QPointF(size/8,size/8)); 37 | polygon.append(QPointF(size/2,0));polygon.append(QPointF(size/8,-size/8)); 38 | painter->drawPolygon(polygon); 39 | if(label.length()) 40 | { 41 | QFont font = painter->font(); 42 | font.setFamily("Microsoft YaHei"); 43 | font.setBold(true); 44 | painter->setFont(font); 45 | painter->setPen(brush); 46 | painter->drawText(-getLabelPixeSize()/2,size,label); 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /GeoStar.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 UISDO All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions, and the following disclaimer, 9 | * without modification. 10 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer 11 | * substantially similar to the "NO WARRANTY" disclaimer below 12 | * ("Disclaimer") and any redistribution must be conditioned upon 13 | * including a substantially similar Disclaimer requirement for further 14 | * binary redistribution. 15 | * 3. Neither the names of the above-listed copyright holders nor the names 16 | * of any contributors may be used to endorse or promote products derived 17 | * from this software without specific prior written permission. 18 | * 19 | * Alternatively, this software may be distributed under the terms of the 20 | * GNU General Public License ("GPL") version 2 as published by the Free 21 | * Software Foundation. 22 | * 23 | * NO WARRANTY 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGES. 35 | */ 36 | 37 | #ifndef GEOSTAR_H 38 | #define GEOSTAR_H 39 | 40 | #include 41 | #include "Geometry.h" 42 | #include 43 | namespace UM { 44 | class GeoStar; 45 | } 46 | class UMAPCONTROLSHARED_EXPORT GeoStar : public Geometry 47 | { 48 | Q_OBJECT 49 | public: 50 | explicit GeoStar(QPointF world, int size = 80, QColor pen = QColor(Qt::blue), QColor brush = QColor(Qt::yellow)); 51 | protected: 52 | QRectF boundingRect() const Q_DECL_OVERRIDE; 53 | QPainterPath shape() const Q_DECL_OVERRIDE; 54 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE; 55 | signals: 56 | 57 | public slots: 58 | }; 59 | 60 | #endif // GEOSTAR_H 61 | -------------------------------------------------------------------------------- /GeoTri.cpp: -------------------------------------------------------------------------------- 1 | #include "GeoTri.h" 2 | 3 | GeoTri::GeoTri(QPointF world, int size, QColor pen, QColor brush) : 4 | Geometry(UM::iGeoTri, size*0.6, pen, brush) 5 | { 6 | list.append(world); 7 | checkRect(); 8 | } 9 | 10 | QRectF GeoTri::boundingRect() const 11 | { 12 | return QRectF(-size/2, -size/2, size, size); 13 | } 14 | 15 | QPainterPath GeoTri::shape() const 16 | { 17 | QPainterPath path; 18 | QPolygonF polygon; 19 | polygon.append(QPointF(0,-size/2)); 20 | polygon.append(QPointF(-size/2,size/2)); 21 | polygon.append(QPointF(size/2,size/2)); 22 | path.addPolygon(polygon); 23 | return path; 24 | } 25 | 26 | void GeoTri::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) 27 | { 28 | painter->setPen(pen); 29 | painter->setBrush(brush); 30 | painter->setRenderHint(QPainter::Antialiasing); 31 | QPolygonF polygon; 32 | polygon.append(QPointF(0,-size/2)); 33 | polygon.append(QPointF(-size/2,size/2)); 34 | polygon.append(QPointF(size/2,size/2)); 35 | painter->drawPolygon(polygon); 36 | if(label.length()) 37 | { 38 | QFont font = painter->font(); 39 | font.setFamily("Microsoft YaHei"); 40 | font.setBold(true); 41 | painter->setFont(font); 42 | painter->setPen(brush); 43 | painter->drawText(-getLabelPixeSize()/2,size+5,label); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /GeoTri.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 UISDO All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions, and the following disclaimer, 9 | * without modification. 10 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer 11 | * substantially similar to the "NO WARRANTY" disclaimer below 12 | * ("Disclaimer") and any redistribution must be conditioned upon 13 | * including a substantially similar Disclaimer requirement for further 14 | * binary redistribution. 15 | * 3. Neither the names of the above-listed copyright holders nor the names 16 | * of any contributors may be used to endorse or promote products derived 17 | * from this software without specific prior written permission. 18 | * 19 | * Alternatively, this software may be distributed under the terms of the 20 | * GNU General Public License ("GPL") version 2 as published by the Free 21 | * Software Foundation. 22 | * 23 | * NO WARRANTY 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGES. 35 | */ 36 | 37 | #ifndef GEOTRI_H 38 | #define GEOTRI_H 39 | 40 | #include 41 | #include 42 | #include "Geometry.h" 43 | namespace UM { 44 | class GeoTri; 45 | } 46 | class UMAPCONTROLSHARED_EXPORT GeoTri : public Geometry 47 | { 48 | Q_OBJECT 49 | public: 50 | explicit GeoTri(QPointF world, int size = 80, QColor pen = QColor(Qt::blue), QColor brush = QColor(Qt::yellow)); 51 | protected: 52 | QRectF boundingRect() const Q_DECL_OVERRIDE; 53 | QPainterPath shape() const Q_DECL_OVERRIDE; 54 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE; 55 | signals: 56 | 57 | public slots: 58 | }; 59 | 60 | #endif // GEOTRI_H 61 | -------------------------------------------------------------------------------- /Geometry.cpp: -------------------------------------------------------------------------------- 1 | #include "Geometry.h" 2 | 3 | Geometry::Geometry(UM::GeoType gType, quint8 lWidth, QColor iPen, QColor iBrush) 4 | { 5 | geoType = gType; 6 | if(gType == UM::iGeoPolygon) 7 | lineWidth = lWidth; 8 | else 9 | size = lWidth; 10 | pen = iPen; 11 | brush = iBrush; 12 | QUuid id = QUuid::createUuid(); 13 | itemID = id.data1; 14 | label = ""; 15 | dir = 0; 16 | closeFlag = false; 17 | rect.maxX = 0; 18 | rect.maxY = 0; 19 | rect.minX = 0; 20 | rect.minY = 0; 21 | } 22 | 23 | UM::UmapGeoRect Geometry::getRect() 24 | { 25 | return rect; 26 | } 27 | 28 | UM::GeoType Geometry::getGeoType() 29 | { 30 | return geoType; 31 | } 32 | 33 | QPointF Geometry::getCenter() 34 | { 35 | return QPointF((rect.maxX + rect.minX)/2,(rect.maxY + rect.minY)/2); 36 | } 37 | 38 | QString Geometry::getPen() 39 | { 40 | return QString("%1_%2_%3").arg(pen.red()).arg(pen.green()).arg(pen.blue()); 41 | } 42 | 43 | QString Geometry::getBrush() 44 | { 45 | return QString("%1_%2_%3").arg(brush.red()).arg(brush.green()).arg(brush.blue()); 46 | } 47 | 48 | QString Geometry::getPoints() 49 | { 50 | QString result = ""; 51 | for(int i=0; i= rect.maxX) rect.maxX = p1.x(); 142 | if(p1.x() <= rect.minX) rect.minX = p1.x(); 143 | if(p1.y() >= rect.maxY) rect.maxY = p1.y(); 144 | if(p1.y() <= rect.minY) rect.minY = p1.y(); 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /Geometry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 UISDO All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions, and the following disclaimer, 9 | * without modification. 10 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer 11 | * substantially similar to the "NO WARRANTY" disclaimer below 12 | * ("Disclaimer") and any redistribution must be conditioned upon 13 | * including a substantially similar Disclaimer requirement for further 14 | * binary redistribution. 15 | * 3. Neither the names of the above-listed copyright holders nor the names 16 | * of any contributors may be used to endorse or promote products derived 17 | * from this software without specific prior written permission. 18 | * 19 | * Alternatively, this software may be distributed under the terms of the 20 | * GNU General Public License ("GPL") version 2 as published by the Free 21 | * Software Foundation. 22 | * 23 | * NO WARRANTY 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGES. 35 | */ 36 | 37 | #ifndef GEOMETRY_H 38 | #define GEOMETRY_H 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #include "umapcontrol_global.h" 49 | 50 | /* 51 | * 图元基类,提供所有点类和面类的基本结构 52 | * */ 53 | namespace UM { 54 | class Geometry; 55 | } 56 | class UMAPCONTROLSHARED_EXPORT Geometry : public QGraphicsObject 57 | { 58 | Q_OBJECT 59 | public: 60 | /* 61 | * 插入图元结构 62 | * */ 63 | typedef struct 64 | { 65 | Geometry * geometry; //图元 66 | QList data; //一行数据放到data列表里 67 | } DataType; 68 | explicit Geometry(UM::GeoType gType,quint8 lWidth, QColor iPen = QColor(Qt::red), QColor iBrush=QColor(Qt::yellow)); 69 | UM::UmapGeoRect getRect(); 70 | UM::GeoType getGeoType(); 71 | QPointF getCenter(); 72 | QString getPen(); 73 | QString getBrush(); 74 | QString getPoints(); 75 | quint8 getLineWidth(); 76 | quint8 getSize(); 77 | quint32 getID(); 78 | int getDir(); 79 | bool getCloseFlag(); 80 | void rotate(int dir); 81 | void setLabel(QString lb); 82 | QString getLabel(); 83 | int getLabelPixeSize(); 84 | void setTempColor(QColor c); 85 | protected: 86 | void checkRect(); 87 | QList list; 88 | UM::GeoType geoType; 89 | QColor pen, brush; 90 | quint8 lineWidth; 91 | int size; 92 | UM::UmapGeoRect rect; 93 | quint32 itemID; 94 | QString label; 95 | int dir; 96 | bool closeFlag; 97 | signals: 98 | 99 | public slots: 100 | }; 101 | 102 | #endif // GEOMETRY_H 103 | -------------------------------------------------------------------------------- /ILoveChina.cpp: -------------------------------------------------------------------------------- 1 | #include "ILoveChina.h" 2 | 3 | ILoveChina::ILoveChina() 4 | { 5 | 6 | } 7 | 8 | QPointF ILoveChina::wgs84TOgcj02(QPointF wgs) 9 | { 10 | if (outOfChina(wgs.x(), wgs.y())) 11 | return QPointF(wgs.x(), wgs.y()); 12 | QPointF d = delta(wgs.x(), wgs.y()); 13 | return QPointF(wgs.x() + d.x(), wgs.y() + d.y()); 14 | } 15 | 16 | QPointF ILoveChina::gcj02Towgs84(QPointF gcj) 17 | { 18 | if (outOfChina(gcj.x(), gcj.y())) 19 | return QPointF(gcj.x(), gcj.y()); 20 | QPointF d = delta(gcj.x(), gcj.y()); 21 | return QPointF(gcj.x() - d.x(),gcj.y() - d.y()); 22 | } 23 | 24 | bool ILoveChina::DelDir(const QString &path) 25 | { 26 | if (path.isEmpty()){ 27 | return false; 28 | } 29 | QDir dir(path); 30 | if(!dir.exists()){ 31 | return true; 32 | } 33 | dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot); //设置过滤 34 | QFileInfoList fileList = dir.entryInfoList(); // 获取所有的文件信息 35 | foreach (QFileInfo file, fileList){ //遍历文件信息 36 | if (file.isFile()){ // 是文件,删除 37 | file.dir().remove(file.fileName()); 38 | }else{ // 递归删除 39 | DelDir(file.absoluteFilePath()); 40 | } 41 | } 42 | return dir.rmpath(dir.absolutePath()); // 删除文件夹 43 | } 44 | 45 | bool ILoveChina::outOfChina(double lon, double lat) 46 | { 47 | if (lon < 72.004 || lon > 137.8347) 48 | return true; 49 | if (lat < 0.8293 || lat > 55.8271) 50 | return true; 51 | return false; 52 | } 53 | 54 | double ILoveChina::transformLat(double x, double y) 55 | { 56 | double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * sqrt(fabs(x)); 57 | ret += (20.0 * sin(6.0 * x * PI) + 20.0 * sin(2.0 * x * PI)) * 2.0 / 3.0; 58 | ret += (20.0 * sin(y * PI) + 40.0 * sin(y / 3.0 * PI)) * 2.0 / 3.0; 59 | ret += (160.0 * sin(y / 12.0 * PI) + 320 * sin(y * PI / 30.0)) * 2.0 / 3.0; 60 | return ret; 61 | } 62 | 63 | double ILoveChina::transformLon(double x, double y) 64 | { 65 | double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(fabs(x)); 66 | ret += (20.0 * sin(6.0 * x * PI) + 20.0 * sin(2.0 * x * PI)) * 2.0 / 3.0; 67 | ret += (20.0 * sin(x * PI) + 40.0 * sin(x / 3.0 * PI)) * 2.0 / 3.0; 68 | ret += (160.0 * sin(x / 12.0 * PI) + 300.0 * sin(x / 30.0 * PI)) * 2.0 / 3.0; 69 | return ret; 70 | } 71 | 72 | QPointF ILoveChina::delta(double lon, double lat) 73 | { 74 | // Krasovsky 1940 75 | // 76 | // a = 6378245.0, 1/f = 298.3 77 | // b = a * (1 - f) 78 | // ee = (a^2 - b^2) / a^2; 79 | double a = 6378245.0; // a: 卫星椭球坐标投影到平面地图坐标系的投影因子。 80 | double ee = 0.00669342162296594323; // ee: 椭球的偏心率。 81 | double dLat = transformLat(lon - 105.0, lat - 35.0); 82 | double dLon = transformLon(lon - 105.0, lat - 35.0); 83 | double radLat = lat / 180.0 * PI; 84 | double magic = sin(radLat); 85 | magic = 1 - ee * magic * magic; 86 | double sqrtMagic = sqrt(magic); 87 | dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * PI); 88 | dLon = (dLon * 180.0) / (a / sqrtMagic * cos(radLat) * PI); 89 | return QPointF(dLon, dLat); 90 | } 91 | -------------------------------------------------------------------------------- /ILoveChina.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 UISDO All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions, and the following disclaimer, 9 | * without modification. 10 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer 11 | * substantially similar to the "NO WARRANTY" disclaimer below 12 | * ("Disclaimer") and any redistribution must be conditioned upon 13 | * including a substantially similar Disclaimer requirement for further 14 | * binary redistribution. 15 | * 3. Neither the names of the above-listed copyright holders nor the names 16 | * of any contributors may be used to endorse or promote products derived 17 | * from this software without specific prior written permission. 18 | * 19 | * Alternatively, this software may be distributed under the terms of the 20 | * GNU General Public License ("GPL") version 2 as published by the Free 21 | * Software Foundation. 22 | * 23 | * NO WARRANTY 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGES. 35 | */ 36 | 37 | #ifndef ILOVECHINA_H 38 | #define ILOVECHINA_H 39 | 40 | #include 41 | #include 42 | 43 | #include "umapcontrol_global.h" 44 | 45 | namespace UM { 46 | class ILoveChina; 47 | } 48 | 49 | /* 50 | * 这个东西嘛,大家都知道在天朝地图偏移问题了,虽然有坑但不影响我爱中国是吧?所以还是叫ILoveChina,虽然代码不是我写的! 51 | * 说白了就是用来把WGS坐标和火星坐标(gcj)相互调教的,可以不用理它 52 | * */ 53 | 54 | class UMAPCONTROLSHARED_EXPORT ILoveChina 55 | { 56 | public: 57 | ILoveChina(); 58 | /* 59 | * 世界WGS坐标转火星坐标 60 | * */ 61 | static QPointF wgs84TOgcj02(QPointF wgs); 62 | /* 63 | * 火星坐标转世界WGS坐标 64 | * */ 65 | static QPointF gcj02Towgs84(QPointF gcj); 66 | /* 67 | * 这个先不管它,可能以后我要用到,先留着 68 | * */ 69 | static bool DelDir(const QString &path); 70 | 71 | private: 72 | static bool outOfChina(double lon, double lat); 73 | static double transformLat(double x, double y); 74 | static double transformLon(double x, double y); 75 | static QPointF delta(double lon, double lat); 76 | }; 77 | 78 | #endif // ILOVECHINA_H 79 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /Layer.cpp: -------------------------------------------------------------------------------- 1 | #include "Layer.h" 2 | 3 | Layer::Layer(UMapControl *parent, QString name, QList *typeList) : uMap(parent), 4 | layerLabel(name),visible(true),selectable(true),sqlExcute(&parent->sqlExcute) 5 | { 6 | /* 7 | * 这是直接创建新图层并写入数据库 8 | * */ 9 | QUuid id = QUuid::createUuid(); 10 | layerID = QString("UISDO%1").arg(id.data1); 11 | UM::Format f; 12 | f.name = "UMID"; 13 | f.type = UM::UMapN; 14 | headType.append(f); 15 | sqlExcute->initLayer(layerID,layerLabel,typeList, &headType); 16 | connect(this, SIGNAL(addGeoToScene(Geometry*)), uMap, SLOT(addGeoToScene(Geometry*))); 17 | } 18 | 19 | Layer::Layer(UMapControl *parent, QString id, QString name, bool visible, bool selectable): 20 | uMap(parent),layerLabel(name),layerID(id),sqlExcute(&parent->sqlExcute) 21 | { 22 | /* 23 | * 这得从数据库里读取表加载成图层 24 | * */ 25 | this->visible = visible; 26 | this->selectable = selectable; 27 | QSqlQuery * query = sqlExcute->checkType(layerID); 28 | while(query->next()) 29 | { 30 | QString value = query->value(1).toString(); 31 | QString type = query->value(2).toString(); 32 | UM::Format t; 33 | t.name = value; 34 | t.type = type == "TEXT" ? UM::UMapT : UM::UMapN; 35 | headType.append(t); 36 | } 37 | delete query; 38 | query = 0; 39 | connect(this, SIGNAL(addGeoToScene(Geometry*)), uMap, SLOT(addGeoToScene(Geometry*))); 40 | } 41 | 42 | Layer::~Layer() 43 | { 44 | sqlExcute->removeLayer(layerID); 45 | } 46 | 47 | QSqlQuery *Layer::searchInfo(QString field, QString text) 48 | { 49 | UM::DataType t = UM::UMapT; 50 | for(int i=0; isearchInfo(layerID,field,t,text); 66 | } 67 | 68 | void Layer::setViewToItem(QString itemID) 69 | { 70 | QSqlQuery * query = sqlExcute->setViewToItem(getLayerID(),itemID); 71 | while(query->next()) 72 | { 73 | bool ok; 74 | double x = query->value(0).toDouble(&ok); 75 | if(!ok) 76 | break; 77 | double y = query->value(1).toDouble(&ok); 78 | if(!ok) 79 | break; 80 | uMap->zoomTo(QPointF(x,y),uMap->zoomLevel()); 81 | break; 82 | } 83 | delete query; 84 | query = 0; 85 | } 86 | 87 | void Layer::addGeo(Geometry::DataType data) 88 | { 89 | QList l; 90 | l.append(data); 91 | addGeos(&l); 92 | } 93 | 94 | void Layer::addGeos(QList *dataList) 95 | { 96 | sqlExcute->addItems(dataList,layerID, &headType); 97 | emit uMap->updateMap(); 98 | } 99 | 100 | QList * Layer::getItems() 101 | { 102 | return &list; 103 | } 104 | 105 | 106 | void Layer::updatLayer(bool *isUpdate) 107 | { 108 | list.clear(); 109 | if(!*isUpdate) 110 | return; 111 | QSqlQuery * query =sqlExcute->updateLayer(layerID); 112 | while(query->next() && *isUpdate) 113 | { 114 | int type = query->value(1).toInt(); 115 | Geometry * g = nullptr; 116 | ILongInfo itemInfo = getInfo(query); 117 | switch (type) { 118 | case UM::iGeoCircle: 119 | g = new GeoCircle(itemInfo.center,itemInfo.size,itemInfo.pen,itemInfo.brush); 120 | break; 121 | case UM::iGeoRect: 122 | g = new GeoRect(itemInfo.center,itemInfo.size,itemInfo.pen,itemInfo.brush); 123 | break; 124 | case UM::iGeoPie: 125 | g = new GeoPie(itemInfo.center,itemInfo.size,itemInfo.flags,itemInfo.pen,itemInfo.brush); 126 | break; 127 | case UM::iGeoStar: 128 | g = new GeoStar(itemInfo.center,itemInfo.size,itemInfo.pen,itemInfo.brush); 129 | break; 130 | case UM::iGeoTri: 131 | g = new GeoTri(itemInfo.center,itemInfo.size,itemInfo.pen,itemInfo.brush); 132 | break; 133 | case UM::iGeoPolygon: 134 | g = new GeoPolygon(uMap,&itemInfo.list,itemInfo.flags,itemInfo.size,itemInfo.pen,itemInfo.brush); 135 | break; 136 | default: 137 | break; 138 | } 139 | if(g && *isUpdate) 140 | { 141 | /* 142 | * 图层顺序不能影响临时图层放在第二层,第三层用来保存GPS位置, 143 | * 所有图层放到第一层,受到刷新顺序的影响 144 | * 第0层是背景层 145 | * */ 146 | g->setZValue(getLayerName() == "UISDO" ? 2 : 1); 147 | if(type == UM::iGeoPolygon) 148 | { 149 | g->setPos(uMap->worldToScene(QPointF(g->getRect().minX,g->getRect().maxY))); 150 | //g->setFlag(QGraphicsItem::ItemIsSelectable); 151 | } 152 | else 153 | { 154 | g->setPos(uMap->worldToScene(itemInfo.center)); 155 | g->setScale(uMap->itemScale); 156 | g->rotate(itemInfo.flags); 157 | } 158 | if(itemInfo.label != "ILONGNULL") 159 | g->setLabel(itemInfo.label); 160 | g->setObjectName(QString("%1_%2").arg(layerID).arg(itemInfo.id)); 161 | emit addGeoToScene(g); 162 | list.append(g); 163 | } 164 | } 165 | delete query; 166 | query = 0; 167 | } 168 | 169 | void Layer::setLabel(QString field) 170 | { 171 | sqlExcute->setLabel(layerID, field); 172 | uMap->updateMap(); 173 | } 174 | 175 | void Layer::updateGeoPenColor(quint32 geoID, QColor c) 176 | { 177 | sqlExcute->updateGeoColor(this->getLayerID(),geoID,"PEN",c); 178 | uMap->updateMap(); 179 | } 180 | 181 | void Layer::updateGeoBrushColor(quint32 geoID, QColor c) 182 | { 183 | sqlExcute->updateGeoColor(this->getLayerID(),geoID,"BRUSH",c); 184 | uMap->updateMap(); 185 | } 186 | 187 | void Layer::removeGeo(QString itemID) 188 | { 189 | sqlExcute->removeItem(getLayerID(), itemID); 190 | uMap->updateMap(); 191 | } 192 | 193 | 194 | QString Layer::getLayerName() 195 | { 196 | return layerLabel; 197 | } 198 | 199 | QString Layer::getLayerID() 200 | { 201 | return layerID; 202 | } 203 | 204 | QList *Layer::getLayerHead() 205 | { 206 | return &headType; 207 | } 208 | 209 | void Layer::setVisible(bool b) 210 | { 211 | visible = b; 212 | sqlExcute->setLayerVisible(layerID, b); 213 | uMap->updateMap(); 214 | } 215 | 216 | bool Layer::isVisible() 217 | { 218 | return visible; 219 | } 220 | 221 | void Layer::setSelectable(bool b) 222 | { 223 | selectable = b; 224 | sqlExcute->setLayerSelectable(layerID, b); 225 | uMap->updateMap(); 226 | } 227 | 228 | bool Layer::isSelectable() 229 | { 230 | return selectable; 231 | } 232 | 233 | QPointF Layer::getItemPosByID(QString itemID) 234 | { 235 | QSqlQuery * query = sqlExcute->getPosByItemID(getLayerID(),itemID); 236 | if(query->next()) 237 | { 238 | return QPointF(query->value(0).toDouble(),query->value(1).toDouble()); 239 | } 240 | return QPointF(0,0); 241 | delete query; 242 | } 243 | 244 | Layer::ILongInfo Layer::getInfo(QSqlQuery *query) 245 | { 246 | /* 247 | * 主要信息有: 248 | * @UMID 与数据的ID关联; 249 | * @TYPE ILongGeoType 枚举图元类型 250 | * @CenterX 图元wgs CenterX 坐标 251 | * @CenterY 图元wgs CenterX 坐标 252 | * @MINX 图元最小wgs X坐标 (点类图元写CenterX相同) 253 | * @MINY 图元最小wgs X坐标 (点类图元写CenterY相同) 254 | * @MAXX 图元最大wgs X坐标 (点类图元写CenterX相同) 255 | * @MAXY 图元最大wgs Y坐标 (点类图元写CenterY相同) 设计两个坐标点只为了非点类图元需要计算边界问题,比如线 256 | * @LABEL 用来显示图标注的, 如果设置显示标注,就从数据表里面把标注内容填充到该字段 默认 ILONGNULL 257 | * @INFO 保存图元GIS信息 258 | * 格式: WGSx1,WGSy1_WGSx2,WGSy2_..._WGSxN,WGSyN 259 | * @FLAGS 点类旋转角度或面类图元闭环(FLAGS==0 线条, FLAGS!=0 多边形) 260 | * @SIZE 多边形或线条线宽或点类图元大小 261 | * @PEN 画笔(R_G_B) 262 | * @BRUSH 画刷(R_G_B) 263 | * 264 | */ 265 | ILongInfo info; 266 | info.id = query->value(0).toDouble(); 267 | info.center = QPointF(query->value(2).toDouble(),query->value(3).toDouble()); 268 | info.label = query->value(8).toString(); 269 | info.list = getGisList(query->value(9).toString()); 270 | info.flags = query->value(10).toInt(); 271 | info.size = query->value(11).toInt(); 272 | QStringList iPen = query->value(12).toString().split('_'); 273 | info.pen = QColor(iPen.at(0).toInt(),iPen.at(1).toInt(),iPen.at(2).toInt()); 274 | iPen = query->value(13).toString().split('_'); 275 | info.brush = QColor(iPen.at(0).toInt(),iPen.at(1).toInt(),iPen.at(2).toInt()); 276 | return info; 277 | } 278 | 279 | QList Layer::getGisList(QString gis) 280 | { 281 | QList l; 282 | QStringList tl = gis.split('_'); 283 | while (!tl.isEmpty()) 284 | { 285 | QString str = tl.first(); 286 | QStringList tmp = str.split(','); 287 | l.append(QPointF(tmp.at(0).toDouble(),tmp.at(1).toDouble())); 288 | tl.removeFirst(); 289 | } 290 | return l; 291 | } 292 | 293 | -------------------------------------------------------------------------------- /Layer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 UISDO All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions, and the following disclaimer, 9 | * without modification. 10 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer 11 | * substantially similar to the "NO WARRANTY" disclaimer below 12 | * ("Disclaimer") and any redistribution must be conditioned upon 13 | * including a substantially similar Disclaimer requirement for further 14 | * binary redistribution. 15 | * 3. Neither the names of the above-listed copyright holders nor the names 16 | * of any contributors may be used to endorse or promote products derived 17 | * from this software without specific prior written permission. 18 | * 19 | * Alternatively, this software may be distributed under the terms of the 20 | * GNU General Public License ("GPL") version 2 as published by the Free 21 | * Software Foundation. 22 | * 23 | * NO WARRANTY 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGES. 35 | */ 36 | #ifndef LAYER_H 37 | #define LAYER_H 38 | 39 | #include 40 | #include 41 | 42 | #include "UMapControl.h" 43 | #include "SQLExcute.h" 44 | #include "Geometry.h" 45 | 46 | /* 47 | * 提供简单的图元管理功能 48 | * */ 49 | namespace UM { 50 | class Layer; 51 | } 52 | class UMapControl; 53 | class UMAPCONTROLSHARED_EXPORT Layer : public QObject 54 | { 55 | Q_OBJECT 56 | public: 57 | 58 | typedef struct 59 | { 60 | quint32 id; 61 | QPointF center; 62 | QString label; 63 | QList list; 64 | int size; 65 | int flags; 66 | QColor pen; 67 | QColor brush; 68 | } ILongInfo; 69 | /* 70 | * 新增图层 71 | * @name 图层名称 72 | * @typeList 图层数据结构 73 | * */ 74 | explicit Layer(UMapControl * parent,QString name, QList * typeList); 75 | /* 76 | * 从数据库里加载图层,所有参数都在数据库管理表里得到 77 | * */ 78 | Layer(UMapControl * parent, QString id, QString name, bool visible, bool selectable); 79 | ~Layer(); 80 | QSqlQuery * searchInfo(QString field, QString text); 81 | void setViewToItem(QString itemID); 82 | void addGeo(Geometry::DataType data); 83 | void addGeos(QList *dataList); 84 | QList *getItems(); 85 | void updatLayer(bool * isUpdate); 86 | void setLabel(QString field = "ILONGNULL"); 87 | void updateGeoPenColor(quint32 geoID, QColor c = QColor(Qt::red)); 88 | void updateGeoBrushColor(quint32 geoID, QColor c = QColor(Qt::yellow)); 89 | void removeGeo(QString itemID); 90 | /* 91 | * 返回图层名称 92 | * */ 93 | QString getLayerName(); 94 | /* 95 | * 返回图层ID,和数据库里的表关联 96 | * */ 97 | QString getLayerID(); 98 | /* 99 | * 设置和返回图层可视状态 100 | * */ 101 | QList *getLayerHead(); 102 | void setVisible(bool b); 103 | bool isVisible(); 104 | /* 105 | * 设置和返回图层可选状态 106 | * */ 107 | void setSelectable(bool b); 108 | bool isSelectable(); 109 | QPointF getItemPosByID(QString itemID); 110 | private: 111 | ILongInfo getInfo(QSqlQuery * query); 112 | QList getGisList(QString gis); 113 | UMapControl * uMap; 114 | QString layerLabel; 115 | /* 116 | * 保存当前图层的图元指针 117 | * */ 118 | //QList list; 119 | QString layerID; 120 | bool visible; 121 | bool selectable; 122 | SQLExcute * sqlExcute; 123 | /* 124 | * 保存当前图层的字段类型,只为了方便导入数据时数据转换检查 125 | * */ 126 | QList headType; 127 | QList list; 128 | 129 | signals: 130 | void addGeoToScene(Geometry *); 131 | public slots: 132 | }; 133 | 134 | #endif // LAYER_H 135 | -------------------------------------------------------------------------------- /Manager.cpp: -------------------------------------------------------------------------------- 1 | #include "Manager.h" 2 | 3 | Manager::Manager(UMapControl *iL, QObject *parent) : QObject(parent),uMap(iL),sqlExcute(&iL->sqlExcute),tempGeo(0) 4 | { 5 | qsrand(QDateTime::currentDateTime().time().second()); 6 | QSqlQuery * query = sqlExcute->initLayerManager(); 7 | while(query->next()) 8 | { 9 | QString id = query->value(0).toString(); 10 | QString name = query->value(1).toString(); 11 | int visible = query->value(2).toInt(); 12 | int selectable = query->value(3).toInt(); 13 | loadLayer(id,name,visible, selectable); 14 | } 15 | delete query; 16 | query = 0; 17 | connect(this, SIGNAL(addGeoToScene(Geometry*)), uMap, SLOT(addGeoToScene(Geometry*))); 18 | } 19 | 20 | QList Manager::getLayers() 21 | { 22 | return list; 23 | } 24 | 25 | Layer *Manager::addLayer(QString name, QList *typeList) 26 | { 27 | QString layerName = checkLayerName(name); 28 | if(name == "UISDO" && layerName != name) 29 | return getLayer(name); 30 | Layer * layer = new Layer(uMap, layerName, typeList); 31 | list.append(layer); 32 | return layer; 33 | } 34 | 35 | Layer *Manager::getLayer(QString name) 36 | { 37 | Layer * l = nullptr; 38 | for(int i=0; igetLayerName() == name) 41 | { 42 | l = list.at(i); 43 | break; 44 | } 45 | } 46 | return l; 47 | } 48 | 49 | Layer *Manager::getLayerByID(QString id) 50 | { 51 | Layer * l = nullptr; 52 | for(int i=0; igetLayerID() == id) 55 | { 56 | l = list.at(i); 57 | break; 58 | } 59 | } 60 | return l; 61 | } 62 | 63 | void Manager::removeLayer(QString name) 64 | { 65 | Layer * l = getLayer(name); 66 | if(name == "UISDO") 67 | { 68 | if(l != nullptr) 69 | sqlExcute->clearLayer(l->getLayerID()); 70 | return; 71 | } 72 | if(l != nullptr) 73 | { 74 | if(name == "UISDO") 75 | sqlExcute->clearLayer(l->getLayerID()); 76 | else 77 | { 78 | list.removeOne(l); 79 | delete l; 80 | } 81 | uMap->updateMap(); 82 | } 83 | } 84 | 85 | void Manager::stopUpdateLayer() 86 | { 87 | isUpdate = false; 88 | } 89 | 90 | void Manager::addTempItem(QPointF world, UM::GeoType type) 91 | { 92 | QColor pen = QColor(qrand()%255,qrand()%255,qrand()%255); 93 | if(!tempGeo) 94 | { 95 | switch (type) { 96 | case UM::iGeoCircle: 97 | tempGeo = new GeoCircle(world,40,pen,pen); 98 | break; 99 | case UM::iGeoRect: 100 | tempGeo = new GeoRect(world,40,pen,pen); 101 | break; 102 | case UM::iGeoPie: 103 | tempGeo = new GeoPie(world,80,0,pen,pen); 104 | break; 105 | case UM::iGeoStar: 106 | tempGeo = new GeoStar(world,40,pen,pen); 107 | break; 108 | case UM::iGeoTri: 109 | tempGeo = new GeoTri(world,40,pen,pen); 110 | break; 111 | default: 112 | break; 113 | } 114 | tempGeo->setPos(uMap->worldToScene(world)); 115 | tempGeo->setScale(uMap->itemScale); 116 | tempGeo->setZValue(3); 117 | emit addGeoToScene(tempGeo); 118 | } 119 | else 120 | { 121 | tempGeo->setTempColor(pen); 122 | tempGeo->setPos(uMap->worldToScene(world)); 123 | } 124 | } 125 | 126 | bool Manager::moveLayer(QString name, bool up) 127 | { 128 | Layer * l = getLayer(name); 129 | if(!l) 130 | return false; 131 | int index = list.indexOf(l); 132 | if(up) 133 | { 134 | if(index == 0) 135 | return false; 136 | list.removeAt(index); 137 | list.insert(index - 1, l); 138 | return true; 139 | } 140 | if(index == list.size()+1) 141 | return false; 142 | list.removeAt(index); 143 | list.insert(index + 1, l); 144 | return true; 145 | } 146 | 147 | void Manager::resetTempGeo() 148 | { 149 | tempGeo = nullptr; 150 | } 151 | 152 | void Manager::updatLayer() 153 | { 154 | isUpdate = true; 155 | for(int i=0; iisVisible() && isUpdate) 158 | { 159 | list.at(i)->updatLayer(&isUpdate); 160 | } 161 | } 162 | this->thread()->exit(); 163 | } 164 | 165 | QString Manager::checkLayerName(QString name) 166 | { 167 | QString tmp = name ; 168 | for(int i=0; igetLayerName() == tmp) 171 | { 172 | tmp.append("*"); 173 | break; 174 | } 175 | } 176 | return name == tmp ? tmp : checkLayerName(tmp); 177 | } 178 | 179 | void Manager::loadLayer(QString id, QString name, bool visible, bool selectable) 180 | { 181 | Layer * layer = new Layer(uMap,id,name,visible,selectable); 182 | list.append(layer); 183 | } 184 | -------------------------------------------------------------------------------- /Manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 UISDO All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions, and the following disclaimer, 9 | * without modification. 10 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer 11 | * substantially similar to the "NO WARRANTY" disclaimer below 12 | * ("Disclaimer") and any redistribution must be conditioned upon 13 | * including a substantially similar Disclaimer requirement for further 14 | * binary redistribution. 15 | * 3. Neither the names of the above-listed copyright holders nor the names 16 | * of any contributors may be used to endorse or promote products derived 17 | * from this software without specific prior written permission. 18 | * 19 | * Alternatively, this software may be distributed under the terms of the 20 | * GNU General Public License ("GPL") version 2 as published by the Free 21 | * Software Foundation. 22 | * 23 | * NO WARRANTY 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGES. 35 | */ 36 | #ifndef MANAGER_H 37 | #define MANAGER_H 38 | 39 | #include 40 | #include 41 | 42 | #include "UMapControl.h" 43 | #include "Layer.h" 44 | #include "SQLExcute.h" 45 | 46 | /* 47 | * 提供简单的图层管理功能 48 | * */ 49 | namespace UM { 50 | class Manager; 51 | } 52 | class UMapControl; 53 | class Layer; 54 | class UMAPCONTROLSHARED_EXPORT Manager : public QObject 55 | { 56 | Q_OBJECT 57 | public: 58 | explicit Manager(UMapControl *iL, QObject * parent = 0); 59 | /* 60 | * 返回所有图层的指针 61 | * */ 62 | QList getLayers(); 63 | /* 64 | * 新增图层,名称@name 65 | * @typeList图层数据结构 66 | * */ 67 | Layer *addLayer(QString name, QList *typeList); 68 | /* 69 | * 通过图层名称@name直接删除图层 70 | * */ 71 | Layer *getLayer(QString name); 72 | Layer *getLayerByID(QString id); 73 | void removeLayer(QString name); 74 | void stopUpdateLayer(); 75 | void addTempItem(QPointF world, UM::GeoType type = UM::iGeoCircle); 76 | bool moveLayer(QString name, bool up = true); 77 | void resetTempGeo(); 78 | private: 79 | /* 80 | * 检查图层名称@name是否在图层管理表里,如果有,就自动在@name后面加*号,暂时这样处理导入多个同名图层 81 | * */ 82 | QString checkLayerName(QString name); 83 | /* 84 | * 从管理表里加载数据库里的图层,所有参数都在管理表里 85 | * */ 86 | void loadLayer(QString id, QString name, bool visible, bool selectable); 87 | UMapControl * uMap; 88 | /* 89 | * 所有图层列表,不用每次去图层管理表读取图层信息 90 | * */ 91 | QList list; 92 | SQLExcute * sqlExcute; 93 | bool isUpdate; 94 | Geometry * tempGeo; 95 | signals: 96 | void addGeoToScene(Geometry *); 97 | public slots: 98 | void updatLayer(); 99 | }; 100 | 101 | #endif // MANAGER_H 102 | -------------------------------------------------------------------------------- /Map.cpp: -------------------------------------------------------------------------------- 1 | #include "Map.h" 2 | 3 | Map::Map(QObject *parent) : QObject(parent) 4 | { 5 | loc.setNumberOptions(QLocale::OmitGroupSeparator); 6 | server = "www.google.cn"; 7 | path = "/maps/vt?lyrs=s@701,r@701&gl=cn&x=%2&y=%3&z=%1"; 8 | param1 = path.indexOf("%1"); 9 | param2 = path.indexOf("%2"); 10 | param3 = path.indexOf("%3"); 11 | int min = param1 < param2 ? param1 : param2; 12 | min = param3 < min ? param3 : min; 13 | int max = param1 > param2 ? param1 : param2; 14 | max = param3 > max ? param3 : max; 15 | int middle = param1+param2+param3-min-max; 16 | order[0][0] = min; 17 | if (min == param1) 18 | order[0][1] = 0; 19 | else if (min == param2) 20 | order[0][1] = 1; 21 | else 22 | order[0][1] = 2; 23 | order[1][0] = middle; 24 | if (middle == param1) 25 | order[1][1] = 0; 26 | else if (middle == param2) 27 | order[1][1] = 1; 28 | else 29 | order[1][1] = 2; 30 | order[2][0] = max; 31 | if (max == param1) 32 | order[2][1] = 0; 33 | else if(max == param2) 34 | order[2][1] = 1; 35 | else 36 | order[2][1] = 2; 37 | } 38 | 39 | QString Map::getServer() 40 | { 41 | return server; 42 | } 43 | 44 | QString Map::getPath() 45 | { 46 | return path; 47 | } 48 | 49 | QString Map::queryTile(int x, int y, int z) 50 | { 51 | int a[3] = {z, x, y}; 52 | return QString(getPath().replace(order[2][0],2, loc.toString(a[order[2][1]])) 53 | .replace(order[1][0],2, loc.toString(a[order[1][1]])) 54 | .replace(order[0][0],2, loc.toString(a[order[0][1]]))); 55 | } 56 | 57 | bool Map::isTileValid(int x, int y, int z) 58 | { 59 | return ( (x<0 || x > (1 << z)-1 || y<0 || y > (1 << z)-1) ? false : true); 60 | } 61 | -------------------------------------------------------------------------------- /Map.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 UISDO All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions, and the following disclaimer, 9 | * without modification. 10 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer 11 | * substantially similar to the "NO WARRANTY" disclaimer below 12 | * ("Disclaimer") and any redistribution must be conditioned upon 13 | * including a substantially similar Disclaimer requirement for further 14 | * binary redistribution. 15 | * 3. Neither the names of the above-listed copyright holders nor the names 16 | * of any contributors may be used to endorse or promote products derived 17 | * from this software without specific prior written permission. 18 | * 19 | * Alternatively, this software may be distributed under the terms of the 20 | * GNU General Public License ("GPL") version 2 as published by the Free 21 | * Software Foundation. 22 | * 23 | * NO WARRANTY 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGES. 35 | */ 36 | 37 | #ifndef MAP_H 38 | #define MAP_H 39 | 40 | #include 41 | #include 42 | 43 | #include "umapcontrol_global.h" 44 | 45 | /* 46 | * 地图供应商管理 47 | * */ 48 | namespace UM { 49 | class Map; 50 | } 51 | class Map : public QObject 52 | { 53 | Q_OBJECT 54 | public: 55 | explicit UMAPCONTROLSHARED_EXPORT Map(QObject *parent = 0); 56 | /* 57 | * 取到地图供应商服务地址 58 | * */ 59 | QString getServer(); 60 | QString getPath(); 61 | /* 62 | * 得到坐标点的瓦片下载地址的path部分,如:/maps/vt?lyrs=s@701,r@701&gl=cn&x=%2&y=%3&z=%1 63 | * */ 64 | QString queryTile(int x, int y, int z); 65 | /* 66 | * 判断瓦片是否有效 67 | * */ 68 | bool isTileValid(int x, int y, int z); 69 | private: 70 | int param1; 71 | int param2; 72 | int param3; 73 | int order[3][2]; 74 | 75 | QString server; 76 | QString path; 77 | 78 | QLocale loc; 79 | signals: 80 | 81 | public slots: 82 | }; 83 | 84 | #endif // MAP_H 85 | -------------------------------------------------------------------------------- /MapPix.cpp: -------------------------------------------------------------------------------- 1 | #include "MapPix.h" 2 | 3 | MapPix::MapPix(QPixmap pix) 4 | { 5 | background = pix; 6 | } 7 | 8 | QRectF MapPix::boundingRect() const 9 | { 10 | return background.rect(); 11 | } 12 | 13 | QPainterPath MapPix::shape() const 14 | { 15 | QPainterPath path; 16 | path.addRect(background.rect()); 17 | return path; 18 | } 19 | 20 | void MapPix::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) 21 | { 22 | painter->drawPixmap(0,0,background); 23 | } 24 | -------------------------------------------------------------------------------- /MapPix.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 UISDO All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions, and the following disclaimer, 9 | * without modification. 10 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer 11 | * substantially similar to the "NO WARRANTY" disclaimer below 12 | * ("Disclaimer") and any redistribution must be conditioned upon 13 | * including a substantially similar Disclaimer requirement for further 14 | * binary redistribution. 15 | * 3. Neither the names of the above-listed copyright holders nor the names 16 | * of any contributors may be used to endorse or promote products derived 17 | * from this software without specific prior written permission. 18 | * 19 | * Alternatively, this software may be distributed under the terms of the 20 | * GNU General Public License ("GPL") version 2 as published by the Free 21 | * Software Foundation. 22 | * 23 | * NO WARRANTY 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGES. 35 | */ 36 | 37 | #ifndef MAPPIX_H 38 | #define MAPPIX_H 39 | 40 | #include 41 | #include 42 | #include 43 | #include "umapcontrol_global.h" 44 | 45 | namespace UM { 46 | class MapPix; 47 | } 48 | class UMAPCONTROLSHARED_EXPORT MapPix : public QGraphicsObject 49 | { 50 | Q_OBJECT 51 | public: 52 | explicit MapPix(QPixmap pix); 53 | protected: 54 | QRectF boundingRect() const Q_DECL_OVERRIDE; 55 | QPainterPath shape() const Q_DECL_OVERRIDE; 56 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE; 57 | signals: 58 | 59 | public slots: 60 | private: 61 | QPixmap background; 62 | }; 63 | 64 | #endif // MAPPIX_H 65 | -------------------------------------------------------------------------------- /Network.cpp: -------------------------------------------------------------------------------- 1 | #include "Network.h" 2 | 3 | Network::Network(UMapControl *iL, QObject *parent) : QObject(parent),list(&iL->list), 4 | manager(new QNetworkAccessManager(this)),isDownloading(false),uMap(iL),sqlExcute(&iL->sqlExcute) 5 | { 6 | connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(requestFinished(QNetworkReply*))); 7 | connect(this,SIGNAL(startAgain()),this,SLOT(start())); 8 | } 9 | 10 | Network::~Network() 11 | { 12 | if(manager) 13 | { 14 | delete manager; 15 | manager = 0; 16 | } 17 | } 18 | 19 | bool Network::getDownloadState() 20 | { 21 | return isDownloading; 22 | } 23 | 24 | QString Network::getUrl(QString host, QString path) 25 | { 26 | QString hostName = host; 27 | QString portNumber = QString("80"); 28 | QRegExp r(".:."); 29 | 30 | if(r.indexIn(host) >= 0) 31 | { 32 | QStringList s = host.split(":"); 33 | hostName = s.at(0); 34 | portNumber = s.at(1); 35 | } 36 | return QString("http://%1:%2%3").arg(hostName).arg(portNumber).arg(path); 37 | } 38 | 39 | UM::TPoint Network::getXYZFromUrl(QString Url) 40 | { 41 | /* 42 | * 感觉这么写很Low,但先这么用着吧 43 | * */ 44 | int xoffset = Url.indexOf("x="); 45 | int yoffset = Url.indexOf("y="); 46 | int zoffset = Url.indexOf("z="); 47 | 48 | int x = Url.mid(xoffset+2,yoffset-(xoffset+3)).toInt(); 49 | int y = Url.mid(yoffset+2,zoffset-(yoffset+3)).toInt(); 50 | int z = Url.mid(zoffset+2,Url.length()).toInt(); 51 | UM::TPoint t; 52 | t.x = x; 53 | t.y = y; 54 | t.z = z; 55 | return t; 56 | } 57 | 58 | void Network::start() 59 | { 60 | if(!list->isEmpty()) 61 | { 62 | isDownloading = true; 63 | QString fullUrl = getUrl(uMap->map.getServer(),list->at(0)); 64 | QNetworkRequest request = QNetworkRequest(QUrl(fullUrl)); 65 | request.setRawHeader("User-Agent", "Mozilla/5.0 (PC; U; Intel; Linux; en) AppleWebKit/420+ (KHTML, like Gecko)"); 66 | manager->get(request); 67 | list->removeFirst(); 68 | emit sendTileCount(list->size()); 69 | return; 70 | } 71 | isDownloading = false; 72 | this->thread()->exit(); 73 | } 74 | 75 | void Network::requestFinished(QNetworkReply *reply) 76 | { 77 | emit startAgain(); 78 | if (!reply) 79 | { 80 | qDebug() << "MapNetwork::requestFinished - reply no longer valid"; 81 | return; 82 | } 83 | if (reply->error() != QNetworkReply::NoError) 84 | { 85 | //qDebug() << "QNetworkReply Error: " << reply->errorString(); 86 | return; 87 | } 88 | QByteArray ax; 89 | if (reply->bytesAvailable()>0) 90 | { 91 | QPixmap pm; 92 | ax = reply->readAll(); 93 | 94 | if (pm.loadFromData(ax) && pm.size().width() > 1 && pm.size().height() > 1) 95 | { 96 | UM::TPoint t = getXYZFromUrl(reply->url().toString()); 97 | /* 98 | * 下载到的瓦片,看看是不是当前场景内,如果是就打印到场景背景图片里 99 | * */ 100 | if(t.z == uMap->zoomLevel()) 101 | { 102 | QPointF br = uMap->mapToScene(QPoint(uMap->width(),uMap->height())); 103 | int x = t.x*DEFAULTTILESIZE; 104 | int y = t.y*DEFAULTTILESIZE; 105 | if(t.x>=uMap->leftTop.x() && x=t.y && y < br.y()) 106 | { 107 | emit addPixGeo(uMap->sceneToWorld(QPointF(x,y)),pm,0); 108 | } 109 | } 110 | /* 111 | * 不管是不是场景里的瓦片,只要有瓦片下完都保存到数据库里,方便下次直接调用嘛是吧 112 | * */ 113 | sqlExcute->insertImage(t.x, t.y, t.z, ax); 114 | } 115 | } 116 | } 117 | 118 | -------------------------------------------------------------------------------- /Network.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 UISDO All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions, and the following disclaimer, 9 | * without modification. 10 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer 11 | * substantially similar to the "NO WARRANTY" disclaimer below 12 | * ("Disclaimer") and any redistribution must be conditioned upon 13 | * including a substantially similar Disclaimer requirement for further 14 | * binary redistribution. 15 | * 3. Neither the names of the above-listed copyright holders nor the names 16 | * of any contributors may be used to endorse or promote products derived 17 | * from this software without specific prior written permission. 18 | * 19 | * Alternatively, this software may be distributed under the terms of the 20 | * GNU General Public License ("GPL") version 2 as published by the Free 21 | * Software Foundation. 22 | * 23 | * NO WARRANTY 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGES. 35 | */ 36 | 37 | #ifndef NETWORK_H 38 | #define NETWORK_H 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include "umapcontrol_global.h" 47 | #include "SQLExcute.h" 48 | #include "UMapControl.h" 49 | 50 | /* 51 | * 提供简单的网络下载能力,主要就是用来下载瓦片的 52 | * */ 53 | namespace UM { 54 | class Network; 55 | } 56 | class UMapControl; 57 | class UMAPCONTROLSHARED_EXPORT Network : public QObject 58 | { 59 | Q_OBJECT 60 | public: 61 | explicit Network(UMapControl *iL , QObject * parent = 0); 62 | ~Network(); 63 | /* 64 | * 判断当前是否有数据在下载了 65 | */ 66 | bool getDownloadState(); 67 | private: 68 | /* 69 | * 从@host和@path里生成瓦片下载地址 70 | */ 71 | QString getUrl(QString host, QString path); 72 | /* 73 | * 从@Url计算出x,y,z坐标 74 | */ 75 | UM::TPoint getXYZFromUrl(QString Url); 76 | /* 77 | * 用来保存所有要下载的瓦片地址了,下完一个山一个 78 | */ 79 | QList *list; 80 | QNetworkAccessManager * manager; 81 | bool isDownloading; 82 | UMapControl *uMap; 83 | SQLExcute * sqlExcute; 84 | signals: 85 | void startAgain(); 86 | void sendTileCount(int); 87 | void addPixGeo(QPointF world, QPixmap pm, quint32 z); 88 | public slots: 89 | void start(); 90 | void requestFinished(QNetworkReply *reply); 91 | }; 92 | 93 | #endif // NETWORK_H 94 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ##### 轻量级跨平台瓦片地图库 2 | 3 | ###### 简单用法: 4 | 5 | ```cpp 6 | #include 7 | 8 | UMapControl * uMap = new UMapControl(this); 9 | //创建图层 10 | QList format; 11 | format << UM::Format{"VALUE1",UMapN} << UM::Format{"VALUE2",UMapT}; 12 | Layer * layer = uMap->addLayer(layerName, &format); 13 | //添加图元 14 | Geometry::DataType t; 15 | t.geometry = new GeoCircle(QPointF(99.70875,27.82188) /* ,80,pen,brush */ ); 16 | t.data << value1 << value2; 17 | layer->addGeo(t); 18 | delete t.geometry; 19 | //也可以用layer->addGeos批量添加图元 20 | //现在只有GeoCircle,GeoRect,GeoPie,GeoStar,GeoTri,GeoPolygon 21 | //GeoPolygon图元用来支持多边形和线条,现在基本用不到,暂时这样设计 22 | //文字图元的话并不想加进去,如果真需要,可以放一个图元显示图元标就可以 23 | ``` 24 | ##### 截图 25 | 26 | ![image](https://github.com/Uisdo/UMapControl/blob/master/Screenshot1.png) 27 | ![image](https://github.com/Uisdo/UMapControl/blob/master/Screenshot.png) 28 | -------------------------------------------------------------------------------- /SQLExcute.cpp: -------------------------------------------------------------------------------- 1 | #include "SQLExcute.h" 2 | 3 | SQLExcute::SQLExcute(QObject *parent) : QObject(parent) 4 | { 5 | QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); 6 | QDir dir; 7 | if(!dir.exists(CONFIGPATH)) 8 | { 9 | dir.mkdir(CONFIGPATH); 10 | } 11 | db.setDatabaseName(CONFIGPATH + "uisdo.com"); 12 | db.transaction(); 13 | db.commit(); 14 | if(!db.open()) 15 | { 16 | qDebug() << "Init SQLITE Open " << db.lastError().text(); 17 | } 18 | QString sql = "CREATE TABLE IF NOT EXISTS UISDO(X INTEGER, Y INTEGER, Z INTEGER, IMAGE LONGBLOB, primary key(X,Y,Z))"; 19 | QSqlQuery query(db); 20 | if(!query.exec(sql)) 21 | { 22 | qDebug() << "CREATE TABLE UISDO " << query.lastError().text(); 23 | } 24 | sql = "CREATE TABLE IF NOT EXISTS UMCONF(NAME TEXT PRIMARY KEY, VALUE INTEGER DEFAULT 0)"; 25 | if(!query.exec(sql)) 26 | { 27 | qDebug() << "CREATE TABLE UMCONF " << query.lastError().text(); 28 | } 29 | } 30 | 31 | void SQLExcute::addItems(QList *dataList, 32 | QString id, QList *headType) 33 | { 34 | QSqlDatabase db; 35 | if(QSqlDatabase::contains("qt_sql_default_connection")) 36 | db = QSqlDatabase::database("qt_sql_default_connection"); 37 | else 38 | db = QSqlDatabase::addDatabase("QSQLITE"); 39 | if(!db.isOpen()) 40 | { 41 | if(!db.open()) 42 | { 43 | qDebug() << db.lastError().text(); 44 | return; 45 | } 46 | } 47 | QSqlQuery query(db); 48 | db.transaction(); 49 | for(int i=0; isize(); i++) 50 | { 51 | Geometry::DataType data = dataList->at(i); 52 | if(data.data.size() + 1 < headType->size()) 53 | { 54 | qDebug() << "data error"; 55 | continue; 56 | } 57 | /* 58 | * 先把数据插入到数据表先 59 | * */ 60 | QString sqlT = ""; 61 | for(int j=1; jsize(); j++) 62 | { 63 | if(headType->at(j).type == UM::UMapN) 64 | { 65 | /* 66 | * 其实感觉没必要检查是不是能转换成数字了,但是我人好嘛,慢点就慢点了 67 | * 等有好办法再说 68 | * */ 69 | bool ok; 70 | qreal result = data.data.at(j-1).toReal(&ok); 71 | if(!ok) 72 | result = 0; 73 | sqlT += QString(" '%1', ").arg(result); 74 | } 75 | else 76 | { 77 | sqlT += " '" + data.data.at(j-1).toString() + "', "; 78 | } 79 | } 80 | sqlT = sqlT.left(sqlT.length()-2); 81 | QString sql = QString("INSERT INTO '%1' VALUES ( '%2', %3 )").arg(id).arg(data.geometry->getID()).arg(sqlT); 82 | if(!query.exec(sql)) 83 | { 84 | /* 85 | * 如果插入数据表失败就没必要插入信息表了,直接跳过处理这个图元了 86 | * */ 87 | qDebug() << query.lastError().text() << sql ; 88 | continue; 89 | } 90 | /* 91 | *创建信息表,专用保存图元的,应该可以直接保存图元,但是现在还不知道怎么弄,就先这样弄吧,以后再想办法改进(个人技术原因),主要信息有: 92 | * @UMID 与数据的ID关联; 93 | * @TYPE ILongGeoType 枚举图元类型 94 | * @CenterX 图元wgs CenterX 坐标 95 | * @CenterY 图元wgs CenterX 坐标 96 | * @MINX 图元最小wgs X坐标 (点类图元写CenterX相同) 97 | * @MINY 图元最小wgs X坐标 (点类图元写CenterY相同) 98 | * @MAXX 图元最大wgs X坐标 (点类图元写CenterX相同) 99 | * @MAXY 图元最大wgs Y坐标 (点类图元写CenterY相同) 设计两个坐标点只为了非点类图元需要计算边界问题,比如线 100 | * @LABEL 用来显示图标注的, 如果设置显示标注,就从数据表里面把标注内容填充到该字段 101 | * @INFO 保存图元GIS信息 102 | * 格式: WGSx1,WGSy1_WGSx2,WGSy2_.o.._WGSxN,WGSyN 103 | * @FLAGS 点类旋转角度或面类图元闭环(FLAGS==0 线条, FLAGS!=0 多边形) 104 | * @SIZE 多边形或线条线宽或点类图元大小 105 | * @PEN 画笔(R_G_B) 106 | * @BRUSH 画刷(R_G_B) 107 | * 108 | */ 109 | QPointF cen = data.geometry->getCenter(); 110 | UM::UmapGeoRect rect = data.geometry->getRect(); 111 | sql = QString("INSERT INTO '%1INFO' VALUES ( '%2', '%3', '%4', '%5', '%6', '%7', '%8', '%9', '%10', '%11', '%12', '%13', '%14', '%15')") 112 | .arg(id).arg(data.geometry->getID()).arg(data.geometry->getGeoType()).arg(cen.x()) 113 | .arg(cen.y()).arg(rect.minX) 114 | .arg(rect.minY).arg(rect.maxX).arg(rect.maxY).arg("ILONGNULL") 115 | //@INFO 116 | .arg(data.geometry->getPoints()) 117 | //@FLAGS 118 | .arg(data.geometry->getGeoType() == UM::iGeoPolygon ? data.geometry->getCloseFlag():data.geometry->getDir()) 119 | //@SIZE 120 | .arg(data.geometry->getGeoType() == UM::iGeoPolygon ? data.geometry->getLineWidth():data.geometry->getSize()) 121 | //@PEN @BRUSH 122 | .arg(data.geometry->getPen()).arg(data.geometry->getBrush()); 123 | if(!query.exec(sql)) 124 | { 125 | /* 126 | * 如果图元信息表插入失败,得删除数据表里对应的数据 127 | * */ 128 | qDebug() << query.lastError().text() << sql ; 129 | sql = QString("DELETE FROM '%1' WHERE UMID = %2 ").arg(id).arg(data.geometry->getID()); 130 | if(!query.exec(sql)) 131 | { 132 | /* 133 | * 如果删除失败,那就出现数据混乱了,可以把图层删除了再导入图层吧 134 | * */ 135 | qDebug() << query.lastError().text() << sql ; 136 | } 137 | } 138 | } 139 | db.commit(); 140 | db.transaction(); 141 | } 142 | 143 | void SQLExcute::removeItem(QString layerID, QString itemID) 144 | { 145 | QString sql = QString("DELETE FROM '%1' WHERE UMID = '%2' ").arg(layerID).arg(itemID); 146 | nonResult(sql, "removeItem "); 147 | sql = QString("DELETE FROM '%1INFO' WHERE UMID = '%2' ").arg(layerID).arg(itemID); 148 | nonResult(sql, "removeItem at info"); 149 | } 150 | 151 | QSqlQuery *SQLExcute::checkImage(int maxX, int minX, int maxY, int minY, int z) 152 | { 153 | QString sql = QString("SELECT * FROM UISDO WHERE X >= %1 and X <= %2 and Y <= %3 and Y >= %4 and Z = %5") 154 | .arg(minX).arg(maxX).arg(maxY).arg(minY).arg(z); 155 | return getResult(sql, "checkImage"); 156 | } 157 | 158 | void SQLExcute::insertImage(int x, int y, int z, QByteArray ax) 159 | { 160 | QSqlDatabase db; 161 | if(QSqlDatabase::contains("qt_sql_default_connection")) 162 | db = QSqlDatabase::database("qt_sql_default_connection"); 163 | else 164 | db = QSqlDatabase::addDatabase("QSQLITE"); 165 | if(!db.isOpen()) 166 | { 167 | if(!db.open()) 168 | { 169 | qDebug() << "insertImage Open " << db.lastError().text(); 170 | return; 171 | } 172 | } 173 | db.transaction(); 174 | QSqlQuery query(db); 175 | query.prepare("REPLACE INTO UISDO VALUES (?,?,?,?)"); 176 | query.addBindValue(x); 177 | query.addBindValue(y); 178 | query.addBindValue(z); 179 | query.addBindValue(ax); 180 | if(!query.exec()) 181 | { 182 | qDebug() << "insertImage query.exec() " << query.lastError().text(); 183 | } 184 | db.commit(); 185 | } 186 | 187 | QSqlQuery *SQLExcute::initLayerManager() 188 | { 189 | QString sql = "CREATE TABLE IF NOT EXISTS ILONGIOLAYER(ID TEXT, NAME TEXT, VISIBLE INTEGER, SELECTABLE INTEGER)"; 190 | nonResult(sql, "initLayerManager"); 191 | sql = "SELECT * FROM ILONGIOLAYER"; 192 | return getResult(sql,"initLayerManager check data"); 193 | } 194 | 195 | QSqlQuery *SQLExcute::checkType(QString id) 196 | { 197 | QString sql = QString(" PRAGMA table_info('%1') ").arg(id); 198 | return getResult(sql,"checkType " + id); 199 | } 200 | 201 | QSqlQuery *SQLExcute::updateLayer(QString id) 202 | { 203 | QString sql = QString("SELECT * FROM '%1INFO'").arg(id); 204 | return getResult(sql,"updat layer"); 205 | } 206 | 207 | void SQLExcute::initLayer(QString id, QString name, QList *typeList, QList *headType) 208 | { 209 | /* 210 | * 在ILONGIOLAYER建立表索引 211 | * 一个图层分成两个表 212 | * 一个表保存数据(数据表) 213 | * 一个表保存图元信息(信息表) 214 | */ 215 | QString sql = QString("INSERT INTO ILONGIOLAYER VALUES ( '%1', '%2', '%3', '%4' )").arg(id).arg(name).arg(1).arg(1); 216 | nonResult(sql, "initLayer1"); 217 | /* 218 | * 读取表数据结构 并创建表 把结构保存在字段类型headType里,方便插入图元数据使用 219 | */ 220 | QString saveSql = ""; 221 | for(int i=0; i< typeList->size(); i++) 222 | { 223 | QString t = QString(" '%1' '%2' , ").arg(typeList->at(i).name).arg(typeList->at(i).type ? "TEXT" : "REAL"); 224 | headType->append(typeList->at(i)); 225 | saveSql += t; 226 | } 227 | saveSql = saveSql.left(saveSql.length() - 2); 228 | /* 229 | * 创建数据表,专用保存导入的数据 230 | */ 231 | sql = QString("CREATE TABLE '%1' (UMID REAL, %2 )").arg(id).arg(saveSql); 232 | nonResult(sql, "initLayer create data table "); 233 | /* 234 | *创建信息表,专用保存图元的,应该可以直接保存图元,但是现在还不知道怎么弄,就先这样弄吧,以后再想办法改进(个人技术原因),主要信息有: 235 | * @UMID 与数据的ID关联; 236 | * @TYPE ILongGeoType 枚举图元类型 237 | * @CenterX 图元wgs CenterX 坐标 238 | * @CenterY 图元wgs CenterX 坐标 239 | * @MINX 图元最小wgs X坐标 (点类图元写CenterX相同) 240 | * @MINY 图元最小wgs X坐标 (点类图元写CenterY相同) 241 | * @MAXX 图元最大wgs X坐标 (点类图元写CenterX相同) 242 | * @MAXY 图元最大wgs Y坐标 (点类图元写CenterY相同) 设计两个坐标点只为了非点类图元需要计算边界问题,比如线 243 | * @LABEL 用来显示图标注的, 如果设置显示标注,就从数据表里面把标注内容填充到该字段 244 | * @INFO 保存图元GIS信息 245 | * 格式: WGSx1,WGSy1_WGSx2,WGSy2_..._WGSxN,WGSyN 246 | * @FLAGS 点类旋转角度或面类图元闭环(FLAGS==0 线条, FLAGS!=0 多边形) 247 | * @SIZE 多边形或线条线宽或点类图元大小 248 | * @PEN 画笔(R_G_B) 249 | * @BRUSH 画刷(R_G_B) 250 | * 251 | */ 252 | sql =QString("CREATE TABLE %1INFO (UMID REAL, TYPE REAL, CenterX REAL, CenterY REAL, " 253 | "MINX REAL, MINY REAL, MAXX REAL, MAXY REAL, LABEL TEXT, INFO TEXT, FLAGS REAL," 254 | "SIZE REAL, PEN TEXT, BRUSH TEXT)").arg(id); 255 | nonResult(sql, "initLayer create info table "); 256 | } 257 | 258 | QSqlQuery *SQLExcute::getItemInfo(QString itemLayerID, QString itemID) 259 | { 260 | QString sql = QString("SELECT * FROM '%1' WHERE UMID = '%2'").arg(itemLayerID).arg(itemID); 261 | return getResult(sql,"getItemInfo"); 262 | } 263 | 264 | QSqlQuery *SQLExcute::searchInfo(QString itemLayerID, QString field, UM::DataType fieldType, QString text) 265 | { 266 | QString sql; 267 | if(fieldType == UM::UMapN) 268 | sql = QString("SELECT UMID, %1 FROM '%2' WHERE %3 = %4").arg(field).arg(itemLayerID).arg(field).arg(text); 269 | else 270 | sql = QString("SELECT UMID, %1 FROM '%2' WHERE %3 like '%%4%'").arg(field).arg(itemLayerID).arg(field).arg(text); 271 | return getResult(sql,"searchInfo"); 272 | } 273 | 274 | QSqlQuery *SQLExcute::setViewToItem(QString layerID, QString itemID) 275 | { 276 | QString sql = QString("SELECT CenterX,CenterY FROM '%1INFO' WHERE UMID = '%2'").arg(layerID).arg(itemID); 277 | return getResult(sql,"setViewToItem"); 278 | } 279 | 280 | QSqlQuery *SQLExcute::getDefaultLoaction() 281 | { 282 | QString sql = "SELECT * FROM UMCONF"; 283 | return getResult(sql,"getDefaultLoaction"); 284 | } 285 | 286 | void SQLExcute::updateGeoColor(QString layerId, quint32 geoID, QString field, QColor color) 287 | { 288 | if(!(field=="PEN" || field=="BRUSH")) 289 | return; 290 | QString c = QString("%1_%2_%3").arg(color.red()).arg(color.green()).arg(color.blue()); 291 | QString sql = QString("UPDATE '%1INFO' SET '%2' = '%3' WHERE UMID = '%4'") 292 | .arg(layerId).arg(field).arg(c).arg(geoID); 293 | nonResult(sql,"updateGeoColor"); 294 | } 295 | 296 | void SQLExcute::updateDefaultLoaction(QPointF world, quint8 level) 297 | { 298 | QString sql = QString("REPLACE INTO UMCONF VALUES ('X', %1)").arg(world.x()); 299 | nonResult(sql, "update x "); 300 | sql = QString("REPLACE INTO UMCONF VALUES ('Y', %1)").arg(world.y()); 301 | nonResult(sql, "update y "); 302 | sql = QString("REPLACE INTO UMCONF VALUES ('LEVEL', %1)").arg(level); 303 | nonResult(sql, "update level "); 304 | } 305 | 306 | void SQLExcute::updateItemLimit(quint32 limit) 307 | { 308 | QString sql = QString("REPLACE INTO UMCONF VALUES ('LIMIT', %1)").arg(limit); 309 | nonResult(sql, "update limit "); 310 | } 311 | 312 | QString SQLExcute::dbPath() 313 | { 314 | return CONFIGPATH + "uisdo.com"; 315 | } 316 | 317 | QSqlQuery *SQLExcute::tilesCount() 318 | { 319 | QString sql = "SELECT COUNT(*) FROM UISDO"; 320 | return getResult(sql,"tilesCount"); 321 | } 322 | 323 | void SQLExcute::removeLayer(QString id) 324 | { 325 | QString sql = QString("DELETE FROM ILONGIOLAYER WHERE ID = '%1' ").arg(id); 326 | nonResult(sql, "removeLayer on ILONGIOLAYER " + id); 327 | sql = QString("DROP TABLE '%1' ").arg(id); 328 | nonResult(sql, "DROP TABLE " + id); 329 | sql = QString("DROP TABLE '%1INFO' ").arg(id); 330 | nonResult(sql, "DROP INFO TABLE " + id); 331 | } 332 | 333 | void SQLExcute::clearLayer(QString id) 334 | { 335 | QString sql = QString("DELETE FROM '%1' ").arg(id); 336 | nonResult(sql, "CLEAR " + id); 337 | sql = QString("DELETE FROM '%1INFO' ").arg(id); 338 | nonResult(sql, "CLEAR INFO TABLE " + id); 339 | } 340 | 341 | void SQLExcute::setLayerVisible(QString id, bool b) 342 | { 343 | QString sql = QString("UPDATE ILONGIOLAYER SET VISIBLE = '%1' WHERE ID = '%2' ").arg(b).arg(id); 344 | nonResult(sql, "setLayerVisible " + id); 345 | } 346 | 347 | void SQLExcute::setLayerSelectable(QString id, bool b) 348 | { 349 | QString sql = QString("UPDATE ILONGIOLAYER SET SELECTABLE = '%1' WHERE ID = '%2' ").arg(b).arg(id); 350 | nonResult(sql, "setLayerVisible " + id); 351 | } 352 | 353 | void SQLExcute::setLabel(QString id, QString field) 354 | { 355 | //ILONGNULL 清除标注 356 | QString sql; 357 | if(field == "ILONGNULL") 358 | sql = QString("UPDATE '%1INFO' SET LABEL = 'ILONGNULL' ").arg(id); 359 | else 360 | sql = QString("UPDATE '%1INFO' SET LABEL = (SELECT %2 FROM '%1' WHERE UMID = '%1INFO'.UMID) ") 361 | .arg(id).arg(field); 362 | nonResult(sql, "setLabel " + id); 363 | } 364 | 365 | QSqlQuery *SQLExcute::getPosByItemID(QString layerID, QString itemID) 366 | { 367 | QString sql = QString("SELECT CenterX,CenterY FROM '%1INFO' WHERE UMID = '%2'").arg(layerID).arg(itemID); 368 | return getResult(sql,"getPosByItemID"); 369 | } 370 | 371 | QSqlQuery *SQLExcute::getResult(QString sql, QString position) 372 | { 373 | QSqlDatabase db; 374 | if(QSqlDatabase::contains("qt_sql_default_connection")) 375 | db = QSqlDatabase::database("qt_sql_default_connection"); 376 | else 377 | db = QSqlDatabase::addDatabase("QSQLITE"); 378 | if(!db.isOpen()) 379 | { 380 | if(!db.open()) 381 | { 382 | qDebug() << position << db.lastError().text(); 383 | return nullptr; 384 | } 385 | } 386 | QSqlQuery * query = new QSqlQuery(db); 387 | if(!query->exec(sql)) 388 | { 389 | qDebug() << position << query->lastError().text(); 390 | return nullptr; 391 | } 392 | return query; 393 | } 394 | 395 | void SQLExcute::nonResult(QString sql, QString position) 396 | { 397 | QSqlDatabase db; 398 | if(QSqlDatabase::contains("qt_sql_default_connection")) 399 | db = QSqlDatabase::database("qt_sql_default_connection"); 400 | else 401 | db = QSqlDatabase::addDatabase("QSQLITE"); 402 | if(!db.isOpen()) 403 | { 404 | if(!db.open()) 405 | { 406 | qDebug() << position << db.lastError().text(); 407 | return; 408 | } 409 | } 410 | db.transaction(); 411 | QSqlQuery query(db); 412 | if(!query.exec(sql)) 413 | { 414 | qDebug() << position << query.lastError().text(); 415 | qDebug() << sql; 416 | } 417 | db.commit(); 418 | } 419 | 420 | 421 | 422 | -------------------------------------------------------------------------------- /SQLExcute.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 UISDO All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions, and the following disclaimer, 9 | * without modification. 10 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer 11 | * substantially similar to the "NO WARRANTY" disclaimer below 12 | * ("Disclaimer") and any redistribution must be conditioned upon 13 | * including a substantially similar Disclaimer requirement for further 14 | * binary redistribution. 15 | * 3. Neither the names of the above-listed copyright holders nor the names 16 | * of any contributors may be used to endorse or promote products derived 17 | * from this software without specific prior written permission. 18 | * 19 | * Alternatively, this software may be distributed under the terms of the 20 | * GNU General Public License ("GPL") version 2 as published by the Free 21 | * Software Foundation. 22 | * 23 | * NO WARRANTY 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGES. 35 | */ 36 | 37 | #ifndef SQLEXCUTE_H 38 | #define SQLEXCUTE_H 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #include "umapcontrol_global.h" 48 | #include "Geometry.h" 49 | 50 | /* 51 | * 第一次面向对象,也是第一次使用c++,所以呢,很多不会的了,反正现在是把所有数据库操作的都放到这个类里了! 52 | * 有用没用都先这么活着,总比不活强多了!~_~,发现我没事我还以自己乐了! 53 | */ 54 | namespace UM { 55 | class SQLExcute; 56 | } 57 | class UMAPCONTROLSHARED_EXPORT SQLExcute : public QObject 58 | { 59 | Q_OBJECT 60 | public: 61 | explicit SQLExcute(QObject *parent = 0); 62 | void addItems(QList *dataList, 63 | QString id, QList *headType); 64 | void removeItem(QString layerID, QString itemID); 65 | /* 66 | * 获取当前场景范围内的所有瓦片并返回QSqlQuery,用完了需要自己删除指针 67 | */ 68 | QSqlQuery * checkImage(int maxX, int minX, int maxY, int minY, int z); 69 | /* 70 | * 把已经下载的瓦片插入数据库中 71 | */ 72 | void insertImage(int x, int y, int z, QByteArray ax); 73 | /* 74 | * 创建图层管理 75 | * 图层表里就只有包含图层的ID,NAME,VISIBLE(图层可视),SELECTABLE(图层可选) 76 | */ 77 | QSqlQuery * initLayerManager(); 78 | /* 79 | * 读取id这个数据表的字段类型,并返回QSqlQuery,这个读取字段类型就是为了,如果数据库里已经有表了,那就得把表的字段类型读取出来, 80 | * 保存到自己的图层里,方便插入图元数据的时候判断数据类型而已,没想到更好的办法,用完了需要自己删除指针 81 | */ 82 | QSqlQuery *checkType(QString id); 83 | QSqlQuery *updateLayer(QString id); 84 | /* 85 | * 创建图层,@id是图层的id,用来做数据库里的表名,在class Layer里自动生成, 86 | * @name 图层名称,创建图层时需要自己指定一个名称, 87 | * @typeList 就是表的数据结构了,有字段名和字段类型 88 | * @headType 就是在图层里用来保存表里所有字段的数据类型 只为了插入图元数据的字段类型选择,为了安全,还是每个数据都做个转换, 89 | * 如果转换失败,基本都是文本转数字失败,就填0,可能影响效率. 90 | */ 91 | void initLayer(QString id, QString name, QList *typeList, QList *headType); 92 | QSqlQuery * getItemInfo(QString itemLayerID, QString itemID); 93 | QSqlQuery * searchInfo(QString itemLayerID, QString field, UM::DataType fieldType,QString text); 94 | QSqlQuery * setViewToItem(QString layerID,QString itemID); 95 | QSqlQuery * getDefaultLoaction(); 96 | void updateGeoColor(QString layerId, quint32 geoID, QString field, QColor color); 97 | void updateDefaultLoaction(QPointF world = DEFAULTLOCATION, quint8 level = DEFAULTZOOMLEVEL); 98 | void updateItemLimit(quint32 limit); 99 | QString dbPath(); 100 | QSqlQuery * tilesCount(); 101 | /* 102 | * 删除图层,@id可以通过图层获得 103 | */ 104 | void removeLayer(QString id); 105 | void clearLayer(QString id); 106 | /* 107 | * 设置图层是否可视 108 | */ 109 | void setLayerVisible(QString id,bool b); 110 | /* 111 | * 设置图层是否可选 112 | */ 113 | void setLayerSelectable(QString id,bool b); 114 | void setLabel(QString id,QString field); 115 | QSqlQuery * getPosByItemID(QString layerID, QString itemID); 116 | private: 117 | /* 118 | * 通用执行有返回结果的@sql语句 119 | * @position 自定义一个信息 如果出错就打印这个信息,还是感觉有点蛋疼,但是现在还没有使用log系统,选这样处理了 120 | */ 121 | QSqlQuery *getResult(QString sql, QString position); 122 | /* 123 | * 通用执行有返回结果的@sql语句 124 | * @position 和getResult一样 125 | */ 126 | void nonResult(QString sql, QString position); 127 | signals: 128 | 129 | public slots: 130 | }; 131 | 132 | #endif // SQLEXCUTE_H 133 | -------------------------------------------------------------------------------- /Screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UIDO/UMapControl/de2adbb834567a27c4ded2fe2827f05256d29463/Screenshot.png -------------------------------------------------------------------------------- /Screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UIDO/UMapControl/de2adbb834567a27c4ded2fe2827f05256d29463/Screenshot1.png -------------------------------------------------------------------------------- /UMapControl.cpp: -------------------------------------------------------------------------------- 1 | #include "UMapControl.h" 2 | 3 | 4 | UMapControl::UMapControl(QWidget *parent) : QGraphicsView(parent),itemScale(1), 5 | currentLevel(DEFAULTZOOMLEVEL),numberOfTiles(tilesOnZoomLevel(currentLevel)), 6 | defaultLocation(DEFAULTLOCATION),net(new Network(this)), 7 | tilesCount(0),currentPos(DEFAULTLOCATION), 8 | satellitesCount(0),GPSAltitude(0),GPSDir(0),hasGps(false),GPSSpeed(0) 9 | { 10 | QSqlQuery * query = sqlExcute.getDefaultLoaction(); 11 | while (query->next()) 12 | { 13 | QString fieldName = query->value(0).toString(); 14 | if(fieldName == "X") 15 | { 16 | defaultLocation.setX(query->value(1).toDouble()); 17 | currentPos.setX(query->value(1).toDouble()); 18 | } 19 | if(fieldName == "Y") 20 | { 21 | defaultLocation.setY(query->value(1).toDouble()); 22 | currentPos.setY(query->value(1).toDouble()); 23 | } 24 | if(fieldName == "LEVEL") 25 | { 26 | currentLevel = query->value(1).toInt(); 27 | numberOfTiles= tilesOnZoomLevel(currentLevel); 28 | } 29 | } 30 | delete query; 31 | //distanceList<<5000000<<2000000<<1000000<<1000000<<1000000<<100000<<100000<<50000<<50000<<10000<<10000<<10000<<1000<<1000<<500<<200<<100<<50<<20; 32 | distanceList<<5000000<<2000000<<1000000<<500000<<200000<<100000<<50000<<20000<<10000<<5000<<2000<<1000<<500<<200<<100<<50<<20<<10<<5; 33 | setStyleSheet("background-color:rgb(236,236,236)"); 34 | setScene(new QGraphicsScene(this)); 35 | /* 36 | * @manager得在QGraphicsScene初始化之后才能使用,所以在这里初始化 37 | * */ 38 | manager = new Manager(this); 39 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 40 | setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff ); 41 | setViewportUpdateMode(FullViewportUpdate); 42 | viewport()->setAttribute(Qt::WA_AcceptTouchEvents); 43 | setSceneRect(viewport()->rect()); 44 | /* 45 | * 处理刷新信号 46 | * */ 47 | connect(this,SIGNAL(viewChangedSignal(bool)),this,SLOT(viewChangedSlot(bool))); 48 | net->moveToThread(&networkThread); 49 | /* 50 | * 处理下载信号 51 | * */ 52 | connect(this,SIGNAL(downloadImage()),net,SLOT(start())); 53 | connect(net,SIGNAL(addPixGeo(QPointF,QPixmap,quint32)),this,SLOT(addPixGeo(QPointF,QPixmap,quint32))); 54 | connect(net,SIGNAL(sendTileCount(int)),this, SLOT(updateTilesCount(int))); 55 | 56 | manager->moveToThread(&updateThread); 57 | connect(this, SIGNAL(updateLayer()), manager, SLOT(updatLayer())); 58 | /* 59 | * 处理当前世界坐标位置信号 60 | * */ 61 | connect(this,SIGNAL(sendLocationPos(QPointF)),this,SLOT(updateLocationPos(QPointF))); 62 | // resetMatrix(); 63 | // scale(0.5,0.5); 64 | QList fm; 65 | fm << UM::Format{"NAME",UM::UMapT} << UM::Format{"VALUE",UM::UMapN}; 66 | tempLayer = manager->addLayer("UISDO", &fm); 67 | } 68 | 69 | UMapControl::~UMapControl() 70 | { 71 | networkThread.exit(0); 72 | while(networkThread.isRunning()) 73 | this->thread()->usleep(100); 74 | updateThread.exit(0); 75 | while(updateThread.isRunning()) 76 | this->thread()->usleep(100); 77 | } 78 | 79 | quint8 UMapControl::maxZoomLevel() 80 | { 81 | return MAXZOOMLEVEL; 82 | } 83 | 84 | quint8 UMapControl::minZoomLevel() 85 | { 86 | return MINZOOMLEVEL; 87 | } 88 | 89 | quint8 UMapControl::zoomLevel() 90 | { 91 | return currentLevel; 92 | } 93 | 94 | void UMapControl::zoomIn() 95 | { 96 | if(checkZoomLevel(currentLevel + 1)) 97 | { 98 | currentLevel++; 99 | zoomOnPos = viewport()->rect().center(); 100 | zoomTo(sceneToWorld(mapToScene(zoomOnPos)),currentLevel,true); 101 | } 102 | } 103 | 104 | void UMapControl::zoomOut() 105 | { 106 | if(checkZoomLevel(currentLevel - 1)) 107 | { 108 | currentLevel--; 109 | zoomOnPos = viewport()->rect().center(); 110 | zoomTo(sceneToWorld(mapToScene(zoomOnPos)),currentLevel,true); 111 | } 112 | } 113 | 114 | QPointF UMapControl::getDefaultLocation() 115 | { 116 | return defaultLocation; 117 | } 118 | 119 | QList UMapControl::getLayers() const 120 | { 121 | return manager->getLayers(); 122 | } 123 | 124 | Layer *UMapControl::getlayer(QString name) const 125 | { 126 | return manager->getLayer(name); 127 | } 128 | 129 | Layer *UMapControl::getLayerByID(QString ID) const 130 | { 131 | return manager->getLayerByID(ID); 132 | } 133 | 134 | Layer *UMapControl::addLayer(QString name, QList *typeList) const 135 | { 136 | if(!typeList->size() || name.isEmpty()) 137 | return nullptr; 138 | return manager->addLayer(name,typeList); 139 | } 140 | 141 | void UMapControl::removeLayer(QString name) 142 | { 143 | manager->removeLayer(name); 144 | } 145 | 146 | void UMapControl::addTempGeo(QPointF world, UM::GeoType type) 147 | { 148 | 149 | Geometry * g = nullptr; 150 | QColor pen = QColor(qrand()%255,qrand()%255,qrand()%255); 151 | QColor brush = QColor(qrand()%255,qrand()%255,qrand()%255); 152 | switch (type) { 153 | case UM::iGeoCircle: 154 | g = new GeoCircle(world,80,pen,brush); 155 | break; 156 | case UM::iGeoRect: 157 | g = new GeoRect(world,80,pen,brush); 158 | break; 159 | case UM::iGeoPie: 160 | g = new GeoPie(world,80,0,pen,brush); 161 | break; 162 | case UM::iGeoStar: 163 | g = new GeoStar(world,80,pen,brush); 164 | break; 165 | case UM::iGeoTri: 166 | g = new GeoTri(world,80,pen,brush); 167 | break; 168 | default: 169 | break; 170 | } 171 | if(g) 172 | { 173 | Geometry::DataType t; 174 | t.geometry = g; 175 | t.data << "Uisdo" << 0; 176 | tempLayer->addGeo(t); 177 | zoomTo(world,zoomLevel()); 178 | delete g; 179 | g = nullptr; 180 | } 181 | } 182 | QPointF UMapControl::worldToScene(QPointF world) 183 | { 184 | world = ILoveChina::wgs84TOgcj02(world); 185 | return QPointF((world.x()+180) * (numberOfTiles*DEFAULTTILESIZE)/360., 186 | (1-(log(tan(PI/4.+degreeToRadian(world.y())/2.)) /PI)) /2. * (numberOfTiles*DEFAULTTILESIZE)); 187 | } 188 | 189 | QPointF UMapControl::sceneToWorld(QPointF scene) 190 | { 191 | 192 | return ILoveChina::gcj02Towgs84(QPointF((scene.x()*(360./(numberOfTiles*DEFAULTTILESIZE)))-180, 193 | radianToDegree(atan(sinh((1-scene.y()*(2./(numberOfTiles*DEFAULTTILESIZE)))*PI))))); 194 | } 195 | 196 | void UMapControl::goToDefaultLocation() 197 | { 198 | zoomTo(defaultLocation,zoomLevel()); 199 | } 200 | 201 | bool UMapControl::moveLayerTo(QString name, bool back) 202 | { 203 | return manager->moveLayer(name, back); 204 | } 205 | 206 | void UMapControl::setViewOffset(int deltaX, int deltaY) 207 | { 208 | setSceneLocation(QPointF(sceneRect().x() + deltaX, sceneRect().y() + deltaY)); 209 | emit viewChangedSignal(true); 210 | } 211 | 212 | void UMapControl::DownloadTiles(quint8 dowloadMaxLevel) 213 | { 214 | if(dowloadMaxLevel < currentLevel) 215 | return; 216 | if(dowloadMaxLevel > MAXZOOMLEVEL) 217 | dowloadMaxLevel = MAXZOOMLEVEL; 218 | //进来得先保存 左上角和右下角的世界坐标位置先 219 | QPointF dowloadTilesTL = sceneToWorld(mapToScene(0,0)); 220 | QPointF dowloadTilesBR = sceneToWorld(mapToScene(viewport()->width(), viewport()->height())); 221 | for(int level=currentLevel; level<=dowloadMaxLevel; level++) 222 | { 223 | QPointF sceneCenter = mapToScene(viewport()->rect().center()); 224 | QPointF leftTopDelta = sceneCenter - worldToScene(dowloadTilesTL); 225 | QPointF rightBottomDelta = worldToScene(dowloadTilesBR) - sceneCenter; 226 | QPoint dMid = QPoint(sceneCenter.x() / DEFAULTTILESIZE,sceneCenter.y() / DEFAULTTILESIZE); 227 | QPoint dTL = QPoint(leftTopDelta.x() / DEFAULTTILESIZE + 1,leftTopDelta.y() / DEFAULTTILESIZE + 1); 228 | int rightTiles = rightBottomDelta.x() / DEFAULTTILESIZE + 1; 229 | int bottomTiles = rightBottomDelta.y() / DEFAULTTILESIZE + 1; 230 | for(int x=-dTL.x()+dMid.x(); x<=rightTiles+dMid.x(); x++) 231 | { 232 | for(int y=-dTL.y()+dMid.y(); y<=bottomTiles+dMid.y(); y++) 233 | { 234 | if(map.isTileValid(x,y,currentLevel)) 235 | { 236 | QString path = map.queryTile(x, y, currentLevel); 237 | list.append(path); 238 | } 239 | 240 | } 241 | } 242 | zoomIn(); 243 | } 244 | } 245 | 246 | QString UMapControl::dbPath() 247 | { 248 | return sqlExcute.dbPath(); 249 | } 250 | 251 | int UMapControl::tilesSize() 252 | { 253 | QSqlQuery * query = sqlExcute.tilesCount(); 254 | int result = 0; 255 | if(query->next()) 256 | result = query->value(0).toInt(); 257 | delete query; 258 | return result; 259 | } 260 | 261 | bool UMapControl::GPSUE() 262 | { 263 | return hasGps; 264 | } 265 | 266 | QPointF UMapControl::currentGPS() 267 | { 268 | return hasGps ? GPSLocation : centerPos; 269 | } 270 | 271 | void UMapControl::updateMap() 272 | { 273 | emit viewChangedSignal(false); 274 | } 275 | 276 | void UMapControl::addPixGeo(QPointF world, QPixmap pm, quint32 z) 277 | { 278 | MapPix * gp = new MapPix(pm); 279 | gp->setZValue(z); 280 | gp->setPos(worldToScene(world)); 281 | scene()->addItem(gp); 282 | } 283 | 284 | 285 | bool UMapControl::viewportEvent(QEvent *event) 286 | { 287 | switch(event->type()) 288 | { 289 | case QEvent::TouchBegin: 290 | case QEvent::TouchUpdate: 291 | case QEvent::TouchEnd: 292 | { 293 | QTouchEvent *touchEvent = static_cast(event); 294 | touchEvent->accept(); 295 | QList touchPoints = touchEvent->touchPoints(); 296 | if (touchPoints.count() == 1) 297 | { 298 | if (touchEvent->touchPointStates() & Qt::TouchPointPressed) 299 | { 300 | zoomOnPos = touchEvent->touchPoints().at(0).pos().toPoint(); 301 | QPointF point = mapToScene(zoomOnPos); 302 | if (scene()->items(point).count() != 0) 303 | { 304 | QList l = scene()->items(point); 305 | for(int i= l.size() - 1; i>=0; i--) 306 | { 307 | Geometry * g = (Geometry *)l.at(i); 308 | QStringList nameList = g->objectName().split('_'); 309 | if(g->objectName().isEmpty() || nameList.size() != 2) 310 | { 311 | l.removeOne(l.at(i)); 312 | continue; 313 | } 314 | Layer * layer = manager->getLayerByID(nameList.at(0)); 315 | if(!layer->isSelectable()) 316 | l.removeOne(l.at(i)); 317 | 318 | } 319 | emit sendItemList(l); 320 | } 321 | } 322 | if (touchEvent->touchPointStates() & Qt::TouchPointMoved) 323 | { 324 | QPoint moveDelta = touchEvent->touchPoints().at(0).pos().toPoint() - zoomOnPos; 325 | setSceneLocation(QPointF(sceneRect().x() - moveDelta.x(),sceneRect().y() - moveDelta.y())); 326 | backgroundPos = backgroundPos + moveDelta; 327 | zoomOnPos = touchEvent->touchPoints().at(0).pos().toPoint(); 328 | } 329 | if (touchEvent->touchPointStates() & Qt::TouchPointReleased) 330 | { 331 | emit viewChangedSignal(true); 332 | } 333 | } 334 | if (touchPoints.count() == 2) 335 | { 336 | setTransformationAnchor(QGraphicsView::AnchorViewCenter); 337 | const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first(); 338 | const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last(); 339 | qreal currentScaleFactor = 340 | QLineF(touchPoint0.pos(), touchPoint1.pos()).length() 341 | / QLineF(touchPoint0.startPos(), touchPoint1.startPos()).length(); 342 | setTransform(QTransform().scale( currentScaleFactor,currentScaleFactor)); 343 | if (touchEvent->touchPointStates() & Qt::TouchPointReleased) { 344 | resetMatrix(); 345 | currentScaleFactor>=1 ? zoomIn() : zoomOut(); 346 | } 347 | } 348 | return true; 349 | } 350 | case QEvent::Wheel: 351 | { 352 | QWheelEvent * wheelEvent = static_cast(event);; 353 | zoomOnPos = wheelEvent->pos(); 354 | wheelEvent->delta() > 0 ? zoomIn() : zoomOut(); 355 | wheelEvent->accept(); 356 | return true; 357 | break; 358 | } 359 | case QEvent::MouseButtonDblClick: 360 | { 361 | QMouseEvent * doubleClickEvent = static_cast(event); 362 | emit doubleClicked(doubleClickEvent->pos()); 363 | doubleClickEvent->accept(); 364 | return true; 365 | } 366 | case QEvent::MouseButtonPress: 367 | { 368 | QMouseEvent * pressEvent = static_cast(event); 369 | pressEvent->accept(); 370 | if(pressEvent->buttons() & Qt::LeftButton) 371 | { 372 | zoomOnPos = pressEvent->pos(); 373 | mouseMove = false; 374 | 375 | QPointF point = mapToScene(pressEvent->pos()); 376 | if (scene()->items(point).count() != 0) 377 | { 378 | QList l = scene()->items(point); 379 | for(int i= l.size() - 1; i>=0; i--) 380 | { 381 | Geometry * g = (Geometry *)l.at(i); 382 | QStringList nameList = g->objectName().split('_'); 383 | if(g->objectName().isEmpty() || nameList.size() != 2) 384 | { 385 | l.removeOne(l.at(i)); 386 | continue; 387 | } 388 | Layer * layer = manager->getLayerByID(nameList.at(0)); 389 | if(!layer->isSelectable()) 390 | l.removeOne(l.at(i)); 391 | 392 | } 393 | emit sendItemList(l); 394 | } 395 | } 396 | return true; 397 | } 398 | case QEvent::MouseMove: 399 | { 400 | QMouseEvent * moveEvent = static_cast(event); 401 | emit sendLocationPos(sceneToWorld(mapToScene(moveEvent->pos()))); 402 | if(moveEvent->buttons() & Qt::LeftButton) 403 | { 404 | 405 | QPoint moveDelta = moveEvent->pos() - zoomOnPos; 406 | //scene()->clear(); 407 | setSceneLocation(QPointF(sceneRect().x() - moveDelta.x(),sceneRect().y() - moveDelta.y())); 408 | backgroundPos = backgroundPos + moveDelta; 409 | zoomOnPos = moveEvent->pos(); 410 | mouseMove = true; 411 | moveEvent->accept(); 412 | /* 413 | * 这段码让托放变得很卡,理想是很美好的。。。。 414 | if(backgroundPos.x()>=0 || backgroundPos.y()>=0 415 | || backgroundPos.x()+background.width()<=viewport()->width() 416 | || backgroundPos.y()+background.height()<=viewport()->height() ) 417 | { 418 | emit viewChangedSignal(true); 419 | } 420 | **/ 421 | } 422 | return true; 423 | } 424 | case QEvent::MouseButtonRelease: 425 | { 426 | QMouseEvent * releaseEvent = static_cast(event); 427 | { 428 | if(releaseEvent->button() & Qt::LeftButton && zoomOnPos != QPoint(0,0) && mouseMove) 429 | { 430 | emit viewChangedSignal(true); 431 | zoomOnPos = QPoint(0,0); 432 | releaseEvent->accept(); 433 | } 434 | } 435 | mouseMove = false; 436 | return true; 437 | } 438 | default: 439 | break; 440 | } 441 | return QGraphicsView::viewportEvent(event); 442 | } 443 | 444 | void UMapControl::drawForeground(QPainter *painter, const QRectF &rect) 445 | { 446 | Q_UNUSED(rect); 447 | painter->save(); 448 | painter->resetTransform(); 449 | painter->setRenderHint(QPainter::Antialiasing); 450 | painter->setPen(QColor(Qt::green)); 451 | QLabel lb; 452 | QPoint p = viewport()->rect().center(); 453 | int line = distanceList.at( zoomLevel()-1) / pow(2.0, MAXZOOMLEVEL-zoomLevel() -1) / 0.597164; 454 | int telta = ((viewport()->width() > viewport()->height() ? viewport()->width() : viewport()->height()) / 2) / line; 455 | for(int i=0; isetPen(QColor( i%2 ? Qt::red : Qt::green)); 458 | painter->drawLine(QPoint(p.x()+i*line,p.y()-5),QPoint(p.x()+i*line,p.y()+5)); 459 | painter->drawLine(QPoint(p.x()-i*line,p.y()-5),QPoint(p.x()-i*line,p.y()+5)); 460 | painter->drawLine(QPoint(p.x()-5,p.y()+i*line),QPoint(p.x()+5,p.y()+i*line)); 461 | painter->drawLine(QPoint(p.x()-5,p.y()-i*line),QPoint(p.x()+5,p.y()-i*line)); 462 | } 463 | QFont font = painter->font(); 464 | font.setBold(true); 465 | painter->setFont(font); 466 | for(int i=1; i<=maxZoomLevel(); i++) 467 | { 468 | painter->setPen(QColor(i == zoomLevel() ? Qt::red : Qt::green)); 469 | painter->drawLine(QPoint(width()/2 - ((maxZoomLevel()/2+1)*5) + i*5,height()-15), 470 | QPoint(width()/2 - ((maxZoomLevel()/2+1)*5) + i*5,height()-25)); 471 | } 472 | painter->setPen(QColor(Qt::green)); 473 | QString distance = QVariant( distanceList.at(zoomLevel()-1) / 1000).toString(); 474 | painter->drawText(QPoint(10,height()-15), QString("%1km").arg(distance)); 475 | QString copyRight("U is do"); 476 | painter->drawText(QPoint((width()-lb.fontMetrics().width(copyRight)-15),height()-15),copyRight); 477 | QString north = centerPos.x() >= 0 ? "N" : "S"; 478 | QString east = centerPos.y() >= 0 ? "E" : "W"; 479 | painter->resetTransform(); 480 | painter->translate(width(),0); 481 | painter->rotate(90); 482 | painter->drawText(QPoint(15,10+lb.fontMetrics().height()),QString("%1%2 %3%4").arg(north) 483 | .arg(fabs(currentPos.x()),0,'g',10).arg(east) 484 | .arg(fabs(currentPos.y()),0,'g',10)); 485 | painter->resetTransform(); 486 | painter->translate(15+lb.fontMetrics().height()/2,15); 487 | painter->rotate(90); 488 | //painter->translate(0,width()-15-lb.fontMetrics().height()); 489 | painter->drawText(QPoint(0,10),QString("A:%1 D:%2 T:%3 L:%4 S:%5") 490 | .arg(GPSAltitude).arg(GPSDir).arg(tilesCount) 491 | .arg(satellitesCount).arg(QString::number(GPSSpeed,'g',2)) ); 492 | painter->restore(); 493 | } 494 | 495 | void UMapControl::resizeEvent(QResizeEvent *event) 496 | { 497 | event->accept(); 498 | zoomTo(defaultLocation,currentLevel); 499 | } 500 | 501 | void UMapControl::keyPressEvent(QKeyEvent *event) 502 | { 503 | //QMessageBox::information(this,"x",QString::number( event->key())); 504 | switch (event->key()) { 505 | case Qt::Key_J: 506 | case Qt::Key_Z: 507 | zoomIn(); 508 | break; 509 | case Qt::Key_K: 510 | case Qt::Key_X: 511 | zoomOut(); 512 | break; 513 | case Qt::Key_VolumeUp: 514 | case Qt::Key_VolumeDown: 515 | emit doubleClicked(viewport()->rect().center()); 516 | break; 517 | case Qt::Key_Up: 518 | case Qt::Key_W: 519 | setViewOffset(0,-10); 520 | break; 521 | case Qt::Key_Down: 522 | case Qt::Key_S: 523 | setViewOffset(0,10); 524 | break; 525 | case Qt::Key_Left: 526 | case Qt::Key_A: 527 | setViewOffset(-10,0); 528 | break; 529 | case Qt::Key_Right: 530 | case Qt::Key_D: 531 | setViewOffset(10,0); 532 | break; 533 | default: 534 | break; 535 | } 536 | } 537 | 538 | 539 | qreal UMapControl::degreeToRadian(qreal value) 540 | { 541 | return value * (PI/180.); 542 | } 543 | 544 | qreal UMapControl::radianToDegree(qreal value) 545 | { 546 | return value * (180./PI); 547 | } 548 | 549 | int UMapControl::tilesOnZoomLevel(quint8 zoomLevel) 550 | { 551 | return int(pow(2.0, zoomLevel)); 552 | } 553 | 554 | void UMapControl::tilesUrlMatrix(bool onlyBackground) 555 | { 556 | quint8 offset = 1; 557 | QPointF sceneCenter = mapToScene(viewport()->rect().center()); 558 | QPointF leftTopDelta = sceneCenter - mapToScene(QPoint(0,0)); 559 | QPointF rightBottomDelta = mapToScene(QPoint(viewport()->width(),viewport()->height())) - sceneCenter; 560 | middle = QPoint(sceneCenter.x() / DEFAULTTILESIZE,sceneCenter.y() / DEFAULTTILESIZE); 561 | leftTop = QPoint(leftTopDelta.x() / DEFAULTTILESIZE + offset,leftTopDelta.y() / DEFAULTTILESIZE + offset); 562 | int rightTiles = rightBottomDelta.x() / DEFAULTTILESIZE + offset; 563 | int bottomTiles = rightBottomDelta.y() / DEFAULTTILESIZE + offset; 564 | backgroundPos = mapFromScene((-leftTop.x()+middle.x())*DEFAULTTILESIZE, 565 | (-leftTop.y()+middle.y())*DEFAULTTILESIZE); 566 | /* 567 | * 先把所有有效的瓦片坐标保存到tList里 568 | * */ 569 | QList tList; 570 | for(int x=-leftTop.x()+middle.x(); x<=rightTiles+middle.x(); x++) 571 | { 572 | for(int y=-leftTop.y()+middle.y(); y<=bottomTiles+middle.y(); y++) 573 | { 574 | if(map.isTileValid(x,y,currentLevel)) 575 | { 576 | tList.append(QPoint(x,y)); 577 | } 578 | 579 | } 580 | } 581 | /* 582 | * 删除背景图层 583 | * */ 584 | if(onlyBackground) 585 | { 586 | QList l =scene()->items(scene()->sceneRect()); 587 | for(int i=0;izValue() == 0) 590 | { 591 | scene()->removeItem(l.at(i)); 592 | delete l.at(i); 593 | } 594 | } 595 | } 596 | else 597 | { 598 | scene()->clear(); 599 | manager->resetTempGeo(); 600 | } 601 | /* 602 | * 再从数据库里读取当前场景有效的瓦片,如果读取失败,直接把@tList里的所有坐标生成path保存到@list里, 603 | * 然后跳到最后启动下载线程 604 | * */ 605 | QSqlQuery * query = sqlExcute.checkImage(leftTop.x()+middle.x(), -rightTiles+middle.x(), 606 | leftTop.y()+middle.y(), -bottomTiles+middle.y(), currentLevel); 607 | bool checkImageError = false; 608 | if(query == nullptr) 609 | { 610 | while(!tList.isEmpty()) 611 | { 612 | QPoint p = tList.first(); 613 | QString path = map.queryTile(p.x(),p.y(),currentLevel); 614 | list.contains(path) ? list.move(list.indexOf(path),0) : list.insert(0,path); 615 | tList.removeFirst(); 616 | } 617 | checkImageError = true; 618 | } 619 | /* 620 | * 如果读取成功,得把瓦片打印到场景的背景图里,并删除@tList里的对就瓦片的坐标 621 | * */ 622 | while (query->next() && !checkImageError) 623 | { 624 | int x = query->value(0).toInt(); 625 | int y = query->value(1).toInt(); 626 | //int z = query->value(2).toInt(); 627 | QPixmap pm; 628 | pm.loadFromData(query->value(3).toByteArray()); 629 | addPixGeo(sceneToWorld(QPointF(x*DEFAULTTILESIZE,y*DEFAULTTILESIZE)),pm,0); 630 | tList.removeOne(QPoint(x,y)); 631 | } 632 | if(query) 633 | { 634 | delete query; 635 | query = 0; 636 | } 637 | /* 638 | * 到了这里,如果tList还没空,那就说明有此瓦片是在数据库里没有的,需要从@tList里把坐标转成path保存到@list里然后启动下载线程 639 | * 之所以用随机数,就是为了影响瓦片的下载顺序,让人看着感觉不是只能从一个方向刷新场景背景的了,没多大用处 640 | * */ 641 | qsrand(QDateTime::currentDateTime().time().second()); 642 | while(!tList.isEmpty() && !checkImageError) 643 | { 644 | int index = qrand() % tList.size(); 645 | QPoint value = tList.at(index); 646 | QString path = map.queryTile(value.x(), value.y(), currentLevel); 647 | list.contains(path) ? list.move(list.indexOf(path),0) : list.insert(0,path); 648 | tList.removeOne(value); 649 | } 650 | if(!networkThread.isRunning()) 651 | networkThread.start(); 652 | if(!net->getDownloadState()) 653 | emit downloadImage(); 654 | } 655 | 656 | void UMapControl::zoomTo(QPointF world, quint8 zoomLevel, bool underMouse) 657 | { 658 | currentLevel = zoomLevel; 659 | numberOfTiles = tilesOnZoomLevel(currentLevel); 660 | itemScale = currentLevel * 1. / MAXZOOMLEVEL ; 661 | setSceneLocation(worldToScene(world) - 662 | (underMouse ? zoomOnPos : viewport()->rect().center()), 663 | true); 664 | 665 | } 666 | 667 | void UMapControl::setSceneLocation(QPointF topLeftPos, bool updateItem) 668 | { 669 | setSceneRect(topLeftPos.x(),topLeftPos.y(),viewport()->width(), viewport()->height()); 670 | centerPos = sceneToWorld(mapToScene(viewport()->rect().center())); 671 | if(updateItem) 672 | emit viewChangedSignal(false); 673 | } 674 | 675 | bool UMapControl::checkZoomLevel(quint8 zoomLevel) 676 | { 677 | return (zoomLevel>=MINZOOMLEVEL && zoomLevel<=MAXZOOMLEVEL); 678 | } 679 | 680 | bool UMapControl::checkWorldCoordinate(QPointF world) 681 | { 682 | return (world.x() >= -180 && world.x() <= 180 && world.y() >= -85 && world.y() <= 85); 683 | } 684 | 685 | void UMapControl::addGeoToScene(Geometry *g) 686 | { 687 | if(g) 688 | scene()->addItem(g); 689 | } 690 | 691 | void UMapControl::viewChangedSlot(bool onlyBackground) 692 | { 693 | manager->stopUpdateLayer(); 694 | tilesUrlMatrix(onlyBackground); 695 | if(!updateThread.isRunning()) 696 | updateThread.start(); 697 | if(onlyBackground) 698 | return; 699 | emit updateLayer(); 700 | /* 701 | * 更新完视图,保存当前视图到数据库 702 | * 本来要退出的时候再保存的,但是发在手机上没用 703 | * */ 704 | sqlExcute.updateDefaultLoaction(centerPos,currentLevel); 705 | } 706 | 707 | void UMapControl::updateTilesCount(int count) 708 | { 709 | tilesCount = count; 710 | viewport()->update(); 711 | } 712 | 713 | void UMapControl::updateLocationPos(QPointF world) 714 | { 715 | currentPos = world; 716 | viewport()->update(); 717 | } 718 | 719 | void UMapControl::updateInfo(QPointF GPSPos, qreal speed, qreal dir, qreal altitude) 720 | { 721 | GPSSpeed = speed; 722 | /* 723 | * 如果有GPS,第一次更新应该要自己跳到GPS位置,不管地图是啥等级 724 | * */ 725 | if(!hasGps) 726 | { 727 | hasGps = true; 728 | zoomTo(GPSPos,zoomLevel()); 729 | } 730 | GPSDir = dir; 731 | currentPos = GPSPos; 732 | GPSLocation = GPSPos; 733 | /* 734 | * 因为如果有GPS的话界面打印出来的应该是GPS位置坐标,没有GPS就打印界面中心点位置坐标 735 | * GPS位置要覆盖中心坐标,也覆盖默认位置坐标,在没有GPS设备上跳转到设置好的默认位置,有GPS就跳到GPS位置 736 | * */ 737 | defaultLocation = GPSPos; 738 | centerPos = GPSPos; 739 | 740 | GPSAltitude = altitude; 741 | manager->addTempItem(GPSPos); 742 | } 743 | 744 | void UMapControl::updateSatellitesCount(int count) 745 | { 746 | satellitesCount = count; 747 | } 748 | 749 | -------------------------------------------------------------------------------- /UMapControl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 UISDO All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions, and the following disclaimer, 9 | * without modification. 10 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer 11 | * substantially similar to the "NO WARRANTY" disclaimer below 12 | * ("Disclaimer") and any redistribution must be conditioned upon 13 | * including a substantially similar Disclaimer requirement for further 14 | * binary redistribution. 15 | * 3. Neither the names of the above-listed copyright holders nor the names 16 | * of any contributors may be used to endorse or promote products derived 17 | * from this software without specific prior written permission. 18 | * 19 | * Alternatively, this software may be distributed under the terms of the 20 | * GNU General Public License ("GPL") version 2 as published by the Free 21 | * Software Foundation. 22 | * 23 | * NO WARRANTY 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGES. 35 | */ 36 | 37 | #ifndef UMAPCONTROL_H 38 | #define UMAPCONTROL_H 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include "umapcontrol_global.h" 53 | #include "Map.h" 54 | #include "Network.h" 55 | #include "ILoveChina.h" 56 | #include "SQLExcute.h" 57 | #include "Manager.h" 58 | #include "Layer.h" 59 | #include "GeoRect.h" 60 | #include "GeoPie.h" 61 | #include "GeoCircle.h" 62 | #include "GeoStar.h" 63 | #include "GeoTri.h" 64 | #include "GeoPolygon.h" 65 | #include "MapPix.h" 66 | 67 | /* 68 | * 提供简单的跨平台的瓦片图层框架功能,反正不会C++,更不会面向对象,用来练activateWindow();手的! 69 | * */ 70 | namespace UM { 71 | class UMapControl; 72 | } 73 | class Network; 74 | class Manager; 75 | class GeoPolygon; 76 | class UMAPCONTROLSHARED_EXPORT UMapControl : public QGraphicsView 77 | { 78 | Q_OBJECT 79 | public: 80 | friend class Manager; 81 | friend class Layer; 82 | friend class Network; 83 | friend class ItemInfo; 84 | 85 | UMapControl(QWidget *parent=0); 86 | ~UMapControl(); 87 | 88 | /***************************************************************************** 89 | * API 90 | * ***************************************************************************/ 91 | 92 | /* 93 | * 最大地图等级 94 | * */ 95 | quint8 maxZoomLevel(); 96 | /* 97 | * 最小地图等级 98 | * */ 99 | quint8 minZoomLevel(); 100 | /* 101 | * 当前地图等级 102 | * */ 103 | quint8 zoomLevel(); 104 | /* 105 | * 放大地图 106 | * */ 107 | void zoomIn(); 108 | /* 109 | * 缩小地图 110 | * */ 111 | void zoomOut(); 112 | /* 113 | * 设置默认的地图加载 114 | * */ 115 | QPointF getDefaultLocation(); 116 | /* 117 | * 返回图层 118 | * */ 119 | QList getLayers() const; 120 | Layer * getlayer(QString name) const; 121 | Layer * getLayerByID(QString ID) const; 122 | /* 123 | * 新增图层 124 | * @name 图层名称 125 | * @typeList 图层数据结构 126 | * */ 127 | Layer *addLayer(QString name, QList *typeList) const; 128 | /* 129 | * 通过图层名称@name删除图层 130 | * */ 131 | void removeLayer(QString name); 132 | void addTempGeo(QPointF world, UM::GeoType type = UM::iGeoCircle); 133 | /* 134 | * 世界坐标和场景坐标相与转换 135 | * */ 136 | QPointF worldToScene(QPointF world); 137 | QPointF sceneToWorld(QPointF scene); 138 | /* 139 | * 跳转到默认位置,可以通过setDefaultLocation设置位置,如果有GPS更新位置,默认位置为GPS当前位置 140 | * */ 141 | void goToDefaultLocation(); 142 | /* 143 | * 上下图层了,好像是可以用的,不过我现在用不到 144 | * */ 145 | bool moveLayerTo(QString name, bool back = false); 146 | /* 147 | * 用来响应按键上下左右移动地图了。。。 148 | * */ 149 | void setViewOffset(int deltaX = 10, int deltaY = -10); 150 | /* 151 | * 下载离线瓦片到数据库中,下载只会从当前地图等级开始下载,下到指定的地图等级 152 | * @dowloadMaxLevel >= 当前地图等级 153 | * */ 154 | void DownloadTiles(quint8 dowloadMaxLevel = MAXZOOMLEVEL); 155 | /* 156 | * 取到数据库位置 157 | * */ 158 | QString dbPath(); 159 | /* 160 | * 查询瓦片数量 161 | * */ 162 | int tilesSize(); 163 | /* 164 | * 是不是GPS设备 165 | * */ 166 | bool GPSUE(); 167 | /* 168 | * 当前GPS位置 169 | * */ 170 | QPointF currentGPS(); 171 | /* 172 | * 提供从外部更新地图函数调用 173 | * */ 174 | 175 | protected: 176 | bool viewportEvent(QEvent *event); 177 | void drawForeground(QPainter *painter, const QRectF &rect); 178 | void resizeEvent(QResizeEvent *event); 179 | void keyPressEvent(QKeyEvent *event); 180 | private: 181 | /* 182 | * 角度和弧度相与转换,没上过高中,数学学得不好,真心不理解弧度,但不影响 183 | * */ 184 | inline qreal degreeToRadian(qreal value); 185 | inline qreal radianToDegree(qreal value); 186 | /* 187 | * 计算当前地图等级@zoomLevel单行或单列共有多少张瓦片了 188 | * */ 189 | int tilesOnZoomLevel(quint8 zoomLevel); 190 | /* 191 | * 计算当前场景内的所有瓦片,并在数据库里查找,如果没找到就下载,如果找到了直接打印到场景背景图片里 192 | * */ 193 | void tilesUrlMatrix(bool onlyBackground); 194 | /* 195 | * 缩放在指定的位置@world和指定的地图等级@zoomLevel 196 | * 因为默认是缩放在场景中心,所以加了个参数@underMouse限制缩放在鼠标下面 197 | * */ 198 | void zoomTo(QPointF world, quint8 zoomLevel, bool underMouse = false); 199 | /* 200 | * 像拿着放大镜看地图一样在地图上移动场景,就当把场景当成是不能放大的放大镜就好 201 | * @topLeftPos 是场景的左上角位置 202 | * @updateItem 因为平移的时候不想刷新图元,刷新的话,压力比较大,所以设置这我参数 203 | * */ 204 | void setSceneLocation(QPointF topLeftPos, bool updateItem = false); 205 | /* 206 | * 检查地图等级@zoomLevel是否有效 207 | * */ 208 | inline bool checkZoomLevel(quint8 zoomLevel); 209 | /* 210 | * 检查世界坐标@world是否有效 211 | * */ 212 | inline bool checkWorldCoordinate(QPointF world); 213 | /* 214 | * item缩放系数 215 | * */ 216 | qreal itemScale; 217 | /* 218 | * 当前地图等级 219 | * */ 220 | quint8 currentLevel; 221 | /* 222 | * 当前地图瓦片数量 223 | * */ 224 | quint32 numberOfTiles; 225 | /* 226 | * 滚动鼠标缩放或鼠标平移地图时候 保存鼠标位置 227 | * */ 228 | QPoint zoomOnPos; 229 | /* 230 | * 保存初始化位置的世界坐标 231 | * */ 232 | QPointF defaultLocation; 233 | /* 234 | * 地图供应商 235 | * */ 236 | Map map; 237 | /* 238 | * 场景背景图片 239 | * */ 240 | QPoint backgroundPos; 241 | /* 242 | * @middle 场景中心的那张瓦片的坐标 243 | * @leftTop 场景左上角的那张瓦片的坐标 244 | * 保存在这里是因为下载完瓦片后需要知道打印在哪 245 | * */ 246 | QPoint middle, leftTop; 247 | /* 248 | * 管理网络服务 249 | * */ 250 | Network * net; 251 | /* 252 | * 管理图层 253 | * */ 254 | Manager * manager; 255 | /* 256 | * 瓦片path列表,下载的时候直接从列表里读取,刷新的时候直接保存在列表里 257 | * */ 258 | QList list; 259 | /* 260 | * 下载瓦片线程 261 | * */ 262 | QThread networkThread; 263 | QThread updateThread; 264 | /* 265 | * 数据库管理 266 | * */ 267 | SQLExcute sqlExcute; 268 | /* 269 | * 下载瓦片时候都触发还剩下多少张瓦片没下,就保存在这里,刷新的时候直接打印到场景前景 270 | * */ 271 | int tilesCount; 272 | /* 273 | * 保存当前鼠标所在的位置对应的世界WGS坐标,刷新的时候直接打印到场景前景 274 | * */ 275 | QPointF currentPos; 276 | 277 | /* 278 | * 保存鼠标按下后是否移动了,如果移动了就更新 279 | * */ 280 | bool mouseMove; 281 | /* 282 | * 默认有一个图层,这个图层可以用来保存 GPS当前坐标和统计GPS数据用 或者是临时点之类的数据 283 | * */ 284 | Layer * tempLayer; 285 | /* 286 | * 如果有GPS数据 用来保存卫星个数 没想那么多,对于有定位设备的设备而已 287 | * */ 288 | int satellitesCount; 289 | /* 290 | * 如果有GPS数据 保存高度 和 方向, 速度现在暂时没有用 291 | * */ 292 | qreal GPSAltitude; 293 | qreal GPSDir; 294 | /* 295 | * 保存比例 296 | * */ 297 | QList distanceList; 298 | /* 299 | * 保存视图中心点,有GPS时保存GPS位置坐标 300 | * */ 301 | QPointF centerPos; 302 | /* 303 | * 保存有没有GPS,默认没有GPS,如果有GPS,打开程序默认跳转到GPS位置 304 | * */ 305 | bool hasGps; 306 | QPointF GPSLocation; 307 | double GPSSpeed; 308 | signals: 309 | void viewChangedSignal(bool); 310 | void downloadImage(); 311 | void sendLocationPos(QPointF); 312 | void doubleClicked(QPoint); 313 | void sendItemList(QList); 314 | void updateLayer(); 315 | public slots: 316 | void viewChangedSlot(bool onlyBackground); 317 | void updateTilesCount(int count); 318 | void updateLocationPos(QPointF world); 319 | void updateInfo(QPointF GPSPos , qreal speed, qreal dir, qreal altitude);//pos, speed, dir,altitude 320 | void updateSatellitesCount(int count); 321 | void addGeoToScene(Geometry * g); 322 | void updateMap(); 323 | /* 324 | * 直接加载图片到地图里,默认加载在最底层@z 325 | * */ 326 | void addPixGeo(QPointF world, QPixmap pm, quint32 z); 327 | }; 328 | 329 | #endif // UMAPCONTROL_H 330 | -------------------------------------------------------------------------------- /UMapControl.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2017-03-21T14:37:35 4 | # 5 | #------------------------------------------------- 6 | 7 | #QT -= gui 8 | QT += widgets network sql 9 | 10 | TARGET = UMapControl 11 | TEMPLATE = lib 12 | DESTDIR = ../bin 13 | DEFINES += UMapControl_LIBRARY 14 | 15 | SOURCES += UMapControl.cpp \ 16 | Map.cpp \ 17 | Network.cpp \ 18 | ILoveChina.cpp \ 19 | SQLExcute.cpp \ 20 | Manager.cpp \ 21 | Layer.cpp \ 22 | Geometry.cpp \ 23 | GeoPie.cpp \ 24 | GeoRect.cpp \ 25 | GeoCircle.cpp \ 26 | GeoStar.cpp \ 27 | GeoTri.cpp \ 28 | GeoPolygon.cpp \ 29 | MapPix.cpp 30 | 31 | HEADERS += UMapControl.h\ 32 | umapcontrol_global.h \ 33 | Map.h \ 34 | Network.h \ 35 | ILoveChina.h \ 36 | SQLExcute.h \ 37 | Manager.h \ 38 | Layer.h \ 39 | Geometry.h \ 40 | GeoPie.h \ 41 | GeoRect.h \ 42 | GeoCircle.h \ 43 | GeoStar.h \ 44 | GeoTri.h \ 45 | GeoPolygon.h \ 46 | MapPix.h 47 | 48 | unix { 49 | target.path = /usr/lib 50 | INSTALLS += target 51 | } 52 | 53 | FORMS += 54 | -------------------------------------------------------------------------------- /UMapControl.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {132b843a-f788-4c55-aff9-458d18a598c6} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 1 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | 60 | ProjectExplorer.Project.Target.0 61 | 62 | Desktop Qt 5.8.0 GCC 64bit 63 | Desktop Qt 5.8.0 GCC 64bit 64 | qt.58.gcc_64_kit 65 | 0 66 | 0 67 | 0 68 | 69 | /home/long/Project/UMapProject/build-UMapControl-Desktop_Qt_5_8_0_GCC_64bit-Debug 70 | 71 | 72 | true 73 | qmake 74 | 75 | QtProjectManager.QMakeBuildStep 76 | true 77 | 78 | false 79 | false 80 | false 81 | 82 | 83 | true 84 | Make 85 | 86 | Qt4ProjectManager.MakeStep 87 | 88 | -w 89 | -r 90 | 91 | false 92 | 93 | 94 | 95 | 2 96 | 构建 97 | 98 | ProjectExplorer.BuildSteps.Build 99 | 100 | 101 | 102 | true 103 | Make 104 | 105 | Qt4ProjectManager.MakeStep 106 | 107 | -w 108 | -r 109 | 110 | true 111 | clean 112 | 113 | 114 | 1 115 | 清理 116 | 117 | ProjectExplorer.BuildSteps.Clean 118 | 119 | 2 120 | false 121 | 122 | Debug 123 | 124 | Qt4ProjectManager.Qt4BuildConfiguration 125 | 2 126 | true 127 | 128 | 129 | /home/long/Project/UMapProject/build-UMapControl-Desktop_Qt_5_8_0_GCC_64bit-Release 130 | 131 | 132 | true 133 | qmake 134 | 135 | QtProjectManager.QMakeBuildStep 136 | false 137 | 138 | false 139 | false 140 | false 141 | 142 | 143 | true 144 | Make 145 | 146 | Qt4ProjectManager.MakeStep 147 | 148 | -w 149 | -r 150 | 151 | false 152 | 153 | 154 | 155 | 2 156 | 构建 157 | 158 | ProjectExplorer.BuildSteps.Build 159 | 160 | 161 | 162 | true 163 | Make 164 | 165 | Qt4ProjectManager.MakeStep 166 | 167 | -w 168 | -r 169 | 170 | true 171 | clean 172 | 173 | 174 | 1 175 | 清理 176 | 177 | ProjectExplorer.BuildSteps.Clean 178 | 179 | 2 180 | false 181 | 182 | Release 183 | 184 | Qt4ProjectManager.Qt4BuildConfiguration 185 | 0 186 | true 187 | 188 | 189 | /home/long/Project/UMapProject/build-UMapControl-Desktop_Qt_5_8_0_GCC_64bit-Profile 190 | 191 | 192 | true 193 | qmake 194 | 195 | QtProjectManager.QMakeBuildStep 196 | true 197 | 198 | false 199 | true 200 | false 201 | 202 | 203 | true 204 | Make 205 | 206 | Qt4ProjectManager.MakeStep 207 | 208 | -w 209 | -r 210 | 211 | false 212 | 213 | 214 | 215 | 2 216 | 构建 217 | 218 | ProjectExplorer.BuildSteps.Build 219 | 220 | 221 | 222 | true 223 | Make 224 | 225 | Qt4ProjectManager.MakeStep 226 | 227 | -w 228 | -r 229 | 230 | true 231 | clean 232 | 233 | 234 | 1 235 | 清理 236 | 237 | ProjectExplorer.BuildSteps.Clean 238 | 239 | 2 240 | false 241 | 242 | Profile 243 | 244 | Qt4ProjectManager.Qt4BuildConfiguration 245 | 0 246 | true 247 | 248 | 3 249 | 250 | 251 | 0 252 | 部署 253 | 254 | ProjectExplorer.BuildSteps.Deploy 255 | 256 | 1 257 | 在本地部署 258 | 259 | ProjectExplorer.DefaultDeployConfiguration 260 | 261 | 1 262 | 263 | 264 | false 265 | false 266 | 1000 267 | 268 | true 269 | 270 | false 271 | false 272 | false 273 | false 274 | true 275 | 0.01 276 | 10 277 | true 278 | 1 279 | 25 280 | 281 | 1 282 | true 283 | false 284 | true 285 | valgrind 286 | 287 | 0 288 | 1 289 | 2 290 | 3 291 | 4 292 | 5 293 | 6 294 | 7 295 | 8 296 | 9 297 | 10 298 | 11 299 | 12 300 | 13 301 | 14 302 | 303 | 2 304 | 305 | 306 | 307 | %{buildDir} 308 | Custom Executable 309 | 310 | ProjectExplorer.CustomExecutableRunConfiguration 311 | 3768 312 | false 313 | true 314 | false 315 | false 316 | true 317 | 318 | 1 319 | 320 | 321 | 322 | ProjectExplorer.Project.Target.1 323 | 324 | Android for armeabi-v7a (GCC 4.9, Qt 5.8.0) 325 | Android for armeabi-v7a (GCC 4.9, Qt 5.8.0) 326 | {0a20af65-9c68-472a-b261-e46743cbd86c} 327 | 0 328 | 0 329 | 0 330 | 331 | /home/long/Project/UMapProject/build-UMapControl-Android_for_armeabi_v7a_GCC_4_9_Qt_5_8_0-Debug 332 | 333 | 334 | true 335 | qmake 336 | 337 | QtProjectManager.QMakeBuildStep 338 | true 339 | 340 | false 341 | false 342 | false 343 | 344 | 345 | true 346 | Make 347 | 348 | Qt4ProjectManager.MakeStep 349 | 350 | -w 351 | -r 352 | 353 | false 354 | 355 | 356 | 357 | 358 | true 359 | Copy application data 360 | 361 | Qt4ProjectManager.AndroidPackageInstallationStep 362 | 363 | 364 | android-25 365 | 366 | true 367 | Build Android APK 368 | 369 | QmakeProjectManager.AndroidBuildApkStep 370 | 2 371 | false 372 | false 373 | 374 | 4 375 | 构建 376 | 377 | ProjectExplorer.BuildSteps.Build 378 | 379 | 380 | 381 | true 382 | Make 383 | 384 | Qt4ProjectManager.MakeStep 385 | 386 | -w 387 | -r 388 | 389 | true 390 | clean 391 | 392 | 393 | 1 394 | 清理 395 | 396 | ProjectExplorer.BuildSteps.Clean 397 | 398 | 2 399 | false 400 | 401 | Debug 402 | 403 | Qt4ProjectManager.Qt4BuildConfiguration 404 | 2 405 | true 406 | 407 | 408 | /home/long/Project/UMapProject/build-UMapControl-Android_for_armeabi_v7a_GCC_4_9_Qt_5_8_0-Release 409 | 410 | 411 | true 412 | qmake 413 | 414 | QtProjectManager.QMakeBuildStep 415 | false 416 | 417 | false 418 | false 419 | false 420 | 421 | 422 | true 423 | Make 424 | 425 | Qt4ProjectManager.MakeStep 426 | 427 | -w 428 | -r 429 | 430 | false 431 | 432 | 433 | 434 | 435 | true 436 | Copy application data 437 | 438 | Qt4ProjectManager.AndroidPackageInstallationStep 439 | 440 | 441 | android-25 442 | 443 | true 444 | Build Android APK 445 | 446 | QmakeProjectManager.AndroidBuildApkStep 447 | 2 448 | false 449 | false 450 | 451 | 4 452 | 构建 453 | 454 | ProjectExplorer.BuildSteps.Build 455 | 456 | 457 | 458 | true 459 | Make 460 | 461 | Qt4ProjectManager.MakeStep 462 | 463 | -w 464 | -r 465 | 466 | true 467 | clean 468 | 469 | 470 | 1 471 | 清理 472 | 473 | ProjectExplorer.BuildSteps.Clean 474 | 475 | 2 476 | false 477 | 478 | Release 479 | 480 | Qt4ProjectManager.Qt4BuildConfiguration 481 | 0 482 | true 483 | 484 | 485 | /home/long/Project/UMapProject/build-UMapControl-Android_for_armeabi_v7a_GCC_4_9_Qt_5_8_0-Profile 486 | 487 | 488 | true 489 | qmake 490 | 491 | QtProjectManager.QMakeBuildStep 492 | true 493 | 494 | false 495 | true 496 | false 497 | 498 | 499 | true 500 | Make 501 | 502 | Qt4ProjectManager.MakeStep 503 | 504 | -w 505 | -r 506 | 507 | false 508 | 509 | 510 | 511 | 512 | true 513 | Copy application data 514 | 515 | Qt4ProjectManager.AndroidPackageInstallationStep 516 | 517 | 518 | android-25 519 | 520 | true 521 | Build Android APK 522 | 523 | QmakeProjectManager.AndroidBuildApkStep 524 | 2 525 | false 526 | false 527 | 528 | 4 529 | 构建 530 | 531 | ProjectExplorer.BuildSteps.Build 532 | 533 | 534 | 535 | true 536 | Make 537 | 538 | Qt4ProjectManager.MakeStep 539 | 540 | -w 541 | -r 542 | 543 | true 544 | clean 545 | 546 | 547 | 1 548 | 清理 549 | 550 | ProjectExplorer.BuildSteps.Clean 551 | 552 | 2 553 | false 554 | 555 | Profile 556 | 557 | Qt4ProjectManager.Qt4BuildConfiguration 558 | 0 559 | true 560 | 561 | 3 562 | 563 | 564 | 565 | true 566 | Deploy to Android device 567 | 568 | Qt4ProjectManager.AndroidDeployQtStep 569 | false 570 | 571 | 1 572 | 部署 573 | 574 | ProjectExplorer.BuildSteps.Deploy 575 | 576 | 1 577 | 部署到Android设备 578 | 部署到Android设备 579 | Qt4ProjectManager.AndroidDeployConfiguration2 580 | 581 | 1 582 | 583 | 584 | false 585 | false 586 | 1000 587 | 588 | true 589 | 590 | false 591 | false 592 | false 593 | false 594 | true 595 | 0.01 596 | 10 597 | true 598 | 1 599 | 25 600 | 601 | 1 602 | true 603 | false 604 | true 605 | valgrind 606 | 607 | 0 608 | 1 609 | 2 610 | 3 611 | 4 612 | 5 613 | 6 614 | 7 615 | 8 616 | 9 617 | 10 618 | 11 619 | 12 620 | 13 621 | 14 622 | 623 | -1 624 | 625 | 626 | 627 | %{buildDir} 628 | Custom Executable 629 | 630 | ProjectExplorer.CustomExecutableRunConfiguration 631 | 3768 632 | false 633 | true 634 | false 635 | false 636 | true 637 | 638 | 1 639 | 640 | 641 | 642 | ProjectExplorer.Project.TargetCount 643 | 2 644 | 645 | 646 | ProjectExplorer.Project.Updater.FileVersion 647 | 18 648 | 649 | 650 | Version 651 | 18 652 | 653 | 654 | -------------------------------------------------------------------------------- /umapcontrol_global.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2017 UISDO All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions, and the following disclaimer, 9 | * without modification. 10 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer 11 | * substantially similar to the "NO WARRANTY" disclaimer below 12 | * ("Disclaimer") and any redistribution must be conditioned upon 13 | * including a substantially similar Disclaimer requirement for further 14 | * binary redistribution. 15 | * 3. Neither the names of the above-listed copyright holders nor the names 16 | * of any contributors may be used to endorse or promote products derived 17 | * from this software without specific prior written permission. 18 | * 19 | * Alternatively, this software may be distributed under the terms of the 20 | * GNU General Public License ("GPL") version 2 as published by the Free 21 | * Software Foundation. 22 | * 23 | * NO WARRANTY 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 27 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 33 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | * POSSIBILITY OF SUCH DAMAGES. 35 | */ 36 | 37 | #ifndef UMAPCONTROL_GLOBAL_H 38 | #define UMAPCONTROL_GLOBAL_H 39 | 40 | #include 41 | #include 42 | 43 | namespace UM { 44 | 45 | #if defined(UMapControl_LIBRARY) 46 | # define UMAPCONTROLSHARED_EXPORT Q_DECL_EXPORT 47 | #else 48 | # define UMAPCONTROLSHARED_EXPORT Q_DECL_IMPORT 49 | #endif 50 | 51 | #define PI 3.14159265358979323846264338327950288419717 52 | #define DEFAULTTILESIZE 256 53 | #define MAXZOOMLEVEL 19 54 | #define MINZOOMLEVEL 1 55 | #define DEFAULTZOOMLEVEL MINZOOMLEVEL 56 | #define DEFAULTLOCATION QPointF(0,0) 57 | #define CONFIGPATH QDir::homePath() + "/.UISDO/" 58 | 59 | typedef struct 60 | { 61 | int x; 62 | int y; 63 | int z; 64 | } TPoint; 65 | /* 66 | * 图元类型就只会为两种, 67 | * 1,点类图元,可以有很多种点类图元,都是以中心点画图元 68 | * 2,面类图元,由多个坐标生成的图元,线条也是面类图元的一种 69 | * */ 70 | typedef enum 71 | { 72 | iGeoNull, //初始化类型 73 | //点类图元 74 | iGeoCircle, //点 圆 75 | iGeoRect, //矩形 76 | iGeoPie, //扁形 77 | iGeoStar, //星星 78 | iGeoTri, //三角 79 | //面类图元 80 | iGeoPolygon,//线段和平面 81 | } GeoType; 82 | 83 | //保存图元的边界 84 | typedef struct 85 | { 86 | qreal minX; 87 | qreal minY; 88 | qreal maxX; 89 | qreal maxY; 90 | } UmapGeoRect; 91 | //数据库字段类型,只设计文本和数值 92 | typedef enum 93 | { 94 | UMapN, 95 | UMapT, 96 | } DataType; 97 | 98 | //图层数据结构,就只有字段名和这字段类型了 99 | typedef struct 100 | { 101 | QString name; 102 | DataType type; 103 | } Format; 104 | 105 | } //namespace 106 | #endif // UMAPCONTROL_GLOBAL_H 107 | --------------------------------------------------------------------------------