├── CNAME ├── _config.yml ├── Screenshot.png ├── Screenshot1.png ├── .gitignore ├── GeoRect.h ├── GeoCircle.h ├── GeoTri.h ├── GeoStar.h ├── GeoPie.h ├── GeoPolygon.h ├── Map.h ├── README.md ├── ILoveChina.h ├── GeoRect.cpp ├── ilong.pro ├── GeoCircle.cpp ├── Network.h ├── GeoPie.cpp ├── GeoTri.cpp ├── ilong_global.h ├── Geometry.h ├── Manager.h ├── Map.cpp ├── GeoStar.cpp ├── GeoPolygon.cpp ├── Layer.h ├── ILoveChina.cpp ├── SQLExcute.h ├── Geometry.cpp ├── Network.cpp ├── Manager.cpp ├── ILong.h ├── Layer.cpp ├── SQLExcute.cpp ├── ILong.cpp ├── LICENSE └── ilong.pro.user /CNAME: -------------------------------------------------------------------------------- 1 | ilongio.ilong.io -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-time-machine -------------------------------------------------------------------------------- /Screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilongio/ilong/HEAD/Screenshot.png -------------------------------------------------------------------------------- /Screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilongio/ilong/HEAD/Screenshot1.png -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /GeoRect.h: -------------------------------------------------------------------------------- 1 | #ifndef GEORECT_H 2 | #define GEORECT_H 3 | 4 | #include 5 | #include "Geometry.h" 6 | 7 | class ILONGSHARED_EXPORT GeoRect : public Geometry 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit GeoRect(QPointF world, int size = 80, QColor pen = QColor(Qt::blue), QColor brush = QColor(Qt::yellow)); 12 | protected: 13 | QRectF boundingRect() const Q_DECL_OVERRIDE; 14 | QPainterPath shape() const Q_DECL_OVERRIDE; 15 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE; 16 | signals: 17 | 18 | public slots: 19 | }; 20 | 21 | #endif // GEORECT_H 22 | -------------------------------------------------------------------------------- /GeoCircle.h: -------------------------------------------------------------------------------- 1 | #ifndef GEOCIRCLE_H 2 | #define GEOCIRCLE_H 3 | 4 | #include 5 | #include "Geometry.h" 6 | 7 | class ILONGSHARED_EXPORT GeoCircle : public Geometry 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit GeoCircle(QPointF world, int size = 80, QColor pen = QColor(Qt::blue), QColor brush = QColor(Qt::yellow)); 12 | protected: 13 | QRectF boundingRect() const Q_DECL_OVERRIDE; 14 | QPainterPath shape() const Q_DECL_OVERRIDE; 15 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE; 16 | signals: 17 | 18 | public slots: 19 | }; 20 | 21 | #endif // GEOCIRCLE_H 22 | -------------------------------------------------------------------------------- /GeoTri.h: -------------------------------------------------------------------------------- 1 | #ifndef GEOTRI_H 2 | #define GEOTRI_H 3 | 4 | #include 5 | #include 6 | #include "Geometry.h" 7 | class ILONGSHARED_EXPORT GeoTri : public Geometry 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit GeoTri(QPointF world, int size = 80, QColor pen = QColor(Qt::blue), QColor brush = QColor(Qt::yellow)); 12 | protected: 13 | QRectF boundingRect() const Q_DECL_OVERRIDE; 14 | QPainterPath shape() const Q_DECL_OVERRIDE; 15 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE; 16 | signals: 17 | 18 | public slots: 19 | }; 20 | 21 | #endif // GEOTRI_H 22 | -------------------------------------------------------------------------------- /GeoStar.h: -------------------------------------------------------------------------------- 1 | #ifndef GEOSTAR_H 2 | #define GEOSTAR_H 3 | 4 | #include 5 | #include "Geometry.h" 6 | #include 7 | 8 | class ILONGSHARED_EXPORT GeoStar : public Geometry 9 | { 10 | Q_OBJECT 11 | public: 12 | explicit GeoStar(QPointF world, int size = 80, QColor pen = QColor(Qt::blue), QColor brush = QColor(Qt::yellow)); 13 | protected: 14 | QRectF boundingRect() const Q_DECL_OVERRIDE; 15 | QPainterPath shape() const Q_DECL_OVERRIDE; 16 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE; 17 | signals: 18 | 19 | public slots: 20 | }; 21 | 22 | #endif // GEOSTAR_H 23 | -------------------------------------------------------------------------------- /GeoPie.h: -------------------------------------------------------------------------------- 1 | #ifndef GEOPIE_H 2 | #define GEOPIE_H 3 | 4 | #include 5 | #include 6 | 7 | #include "Geometry.h" 8 | 9 | class ILONGSHARED_EXPORT GeoPie : public Geometry 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit GeoPie(QPointF world, int size = 80, int dir = 0, QColor pen = QColor(Qt::blue), QColor brush = QColor(Qt::yellow)); 14 | protected: 15 | QRectF boundingRect() const Q_DECL_OVERRIDE; 16 | QPainterPath shape() const Q_DECL_OVERRIDE; 17 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE; 18 | signals: 19 | 20 | public slots: 21 | private: 22 | 23 | }; 24 | 25 | #endif // GEOPIE_H 26 | -------------------------------------------------------------------------------- /GeoPolygon.h: -------------------------------------------------------------------------------- 1 | #ifndef GEOPOLYGON_H 2 | #define GEOPOLYGON_H 3 | 4 | #include 5 | #include "Geometry.h" 6 | #include "ILong.h" 7 | 8 | class ILONGSHARED_EXPORT GeoPolygon : public Geometry 9 | { 10 | Q_OBJECT 11 | public: 12 | explicit GeoPolygon(ILong *iL, QList *pointList, bool closePath = false, quint8 lineWidth = 1, QColor pen = QColor(Qt::red), QColor brush = QColor(Qt::yellow)); 13 | protected: 14 | QRectF boundingRect() const Q_DECL_OVERRIDE; 15 | QPainterPath shape() const Q_DECL_OVERRIDE; 16 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE; 17 | signals: 18 | 19 | public slots: 20 | private: 21 | ILong *iLong; 22 | bool needClosePath; 23 | QPolygonF polygon; 24 | int pHeight; 25 | }; 26 | 27 | #endif // GEOCIRCLE_H 28 | -------------------------------------------------------------------------------- /Map.h: -------------------------------------------------------------------------------- 1 | #ifndef MAP_H 2 | #define MAP_H 3 | 4 | #include 5 | #include 6 | 7 | #include "ilong_global.h" 8 | 9 | /* 10 | * 地图供应商管理 11 | * */ 12 | 13 | class Map : public QObject 14 | { 15 | Q_OBJECT 16 | public: 17 | explicit ILONGSHARED_EXPORT Map(QObject *parent = 0); 18 | /* 19 | * 取到地图供应商服务地址 20 | * */ 21 | QString getServer(); 22 | QString getPath(); 23 | /* 24 | * 得到坐标点的瓦片下载地址的path部分,如:/maps/vt?lyrs=s@701,r@701&gl=cn&x=%2&y=%3&z=%1 25 | * */ 26 | QString queryTile(int x, int y, int z); 27 | /* 28 | * 判断瓦片是否有效 29 | * */ 30 | bool isTileValid(int x, int y, int z); 31 | private: 32 | int param1; 33 | int param2; 34 | int param3; 35 | int order[3][2]; 36 | 37 | QString server; 38 | QString path; 39 | 40 | QLocale loc; 41 | signals: 42 | 43 | public slots: 44 | }; 45 | 46 | #endif // MAP_H 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ##### 轻量级跨平台瓦片地图库,练手项目希望有人喜欢。 2 | 3 | ###### 简单用法: 4 | 5 | ```cpp 6 | #include 7 | 8 | ILong * iLong = new ILong(this); 9 | //设置默认加载位置和地图等级 10 | iLong->setDefaultLocation(QPointF(99.70875,27.82188),16); 11 | //创建图层 12 | QList format; 13 | format << LayerFormat{"VALUE1",ILongNUMBER} << LayerFormat{"VALUE2",ILongTEXT}; 14 | Layer * layer = iLong->addLayer(layerName, &format); 15 | //添加图元 16 | Geometry::ILongDataType t; 17 | t.geometry = new GeoCircle(QPointF(99.70875,27.82188) /* ,80,pen,brush */ ); 18 | t.data << value1 << value2; 19 | layer->addGeo(t); 20 | delete t.geometry; 21 | //也可以用layer->addGeos批量添加图元 22 | //现在只有GeoCircle,GeoRect,GeoPie,GeoStar,GeoTri,GeoPolygon 23 | //GeoPolygon图元用来支持多边形和线条,现在基本用不到,暂时这样设计 24 | //文字图元的话并不想加进去,如果真需要,可以放一个图元显示图元标就可以 25 | ``` 26 | ##### 截图 27 | 28 | ![image](https://raw.githubusercontent.com/ilongio/ilong/e9c7bd65b4c838f4aea08cf3db7d562dc8ddc87c/Screenshot.png) 29 | -------------------------------------------------------------------------------- /ILoveChina.h: -------------------------------------------------------------------------------- 1 | #ifndef ILOVECHINA_H 2 | #define ILOVECHINA_H 3 | 4 | #include 5 | #include 6 | 7 | #include "ilong_global.h" 8 | 9 | /* 10 | * 这个东西嘛,大家都知道在天朝地图偏移问题了,虽然有坑但不影响我爱中国是吧?所以还是叫ILoveChina,虽然代码不是我写的! 11 | * 说白了就是用来把WGS坐标和火星坐标(gcj)相互调教的,可以不用理它 12 | * */ 13 | 14 | class ILONGSHARED_EXPORT ILoveChina 15 | { 16 | public: 17 | ILoveChina(); 18 | /* 19 | * 世界WGS坐标转火星坐标 20 | * */ 21 | static QPointF wgs84TOgcj02(QPointF wgs); 22 | /* 23 | * 火星坐标转世界WGS坐标 24 | * */ 25 | static QPointF gcj02Towgs84(QPointF gcj); 26 | /* 27 | * 这个先不管它,可能以后我要用到,先留着 28 | * */ 29 | static bool DelDir(const QString &path); 30 | 31 | private: 32 | static bool outOfChina(double lon, double lat); 33 | static double transformLat(double x, double y); 34 | static double transformLon(double x, double y); 35 | static QPointF delta(double lon, double lat); 36 | }; 37 | 38 | #endif // ILOVECHINA_H 39 | -------------------------------------------------------------------------------- /GeoRect.cpp: -------------------------------------------------------------------------------- 1 | #include "GeoRect.h" 2 | 3 | GeoRect::GeoRect(QPointF world, int size, QColor pen, QColor brush) : 4 | Geometry(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 | -------------------------------------------------------------------------------- /ilong.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 = ilong 11 | TEMPLATE = lib 12 | DESTDIR = ../bin 13 | DEFINES += ILONG_LIBRARY 14 | 15 | SOURCES += ILong.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 | 30 | HEADERS += ILong.h\ 31 | ilong_global.h \ 32 | Map.h \ 33 | Network.h \ 34 | ILoveChina.h \ 35 | SQLExcute.h \ 36 | Manager.h \ 37 | Layer.h \ 38 | Geometry.h \ 39 | GeoPie.h \ 40 | GeoRect.h \ 41 | GeoCircle.h \ 42 | GeoStar.h \ 43 | GeoTri.h \ 44 | GeoPolygon.h 45 | 46 | unix { 47 | target.path = /usr/lib 48 | INSTALLS += target 49 | } 50 | 51 | FORMS += 52 | -------------------------------------------------------------------------------- /GeoCircle.cpp: -------------------------------------------------------------------------------- 1 | #include "GeoCircle.h" 2 | 3 | GeoCircle::GeoCircle(QPointF world, int size, QColor pen, QColor brush) : 4 | Geometry(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 | -------------------------------------------------------------------------------- /Network.h: -------------------------------------------------------------------------------- 1 | #ifndef NETWORK_H 2 | #define NETWORK_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "ILong.h" 11 | #include "SQLExcute.h" 12 | 13 | /* 14 | * 提供简单的网络下载能力,主要就是用来下载瓦片的 15 | * */ 16 | 17 | class ILong; 18 | class ILONGSHARED_EXPORT Network : public QObject 19 | { 20 | Q_OBJECT 21 | public: 22 | explicit Network(ILong *iL , QObject * parent = 0); 23 | ~Network(); 24 | /* 25 | * 判断当前是否有数据在下载了 26 | */ 27 | bool getDownloadState(); 28 | private: 29 | /* 30 | * 从@host和@path里生成瓦片下载地址 31 | */ 32 | QString getUrl(QString host, QString path); 33 | /* 34 | * 从@Url计算出x,y,z坐标 35 | */ 36 | TPoint getXYZFromUrl(QString Url); 37 | /* 38 | * 用来保存所有要下载的瓦片地址了,下完一个山一个 39 | */ 40 | QList *list; 41 | QNetworkAccessManager * manager; 42 | bool isDownloading; 43 | ILong *iLong; 44 | SQLExcute * sqlExcute; 45 | signals: 46 | void startAgain(); 47 | void sendTileCount(int); 48 | void newImage(); 49 | public slots: 50 | void start(); 51 | void requestFinished(QNetworkReply *reply); 52 | }; 53 | 54 | #endif // NETWORK_H 55 | -------------------------------------------------------------------------------- /GeoPie.cpp: -------------------------------------------------------------------------------- 1 | #include "GeoPie.h" 2 | #include 3 | 4 | GeoPie::GeoPie(QPointF world, int size, int dir, QColor pen, QColor brush) : 5 | Geometry(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 | -------------------------------------------------------------------------------- /GeoTri.cpp: -------------------------------------------------------------------------------- 1 | #include "GeoTri.h" 2 | 3 | GeoTri::GeoTri(QPointF world, int size, QColor pen, QColor brush) : 4 | Geometry(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 | -------------------------------------------------------------------------------- /ilong_global.h: -------------------------------------------------------------------------------- 1 | #ifndef ILONG_GLOBAL_H 2 | #define ILONG_GLOBAL_H 3 | 4 | #include 5 | #include 6 | 7 | 8 | #if defined(ILONG_LIBRARY) 9 | # define ILONGSHARED_EXPORT Q_DECL_EXPORT 10 | #else 11 | # define ILONGSHARED_EXPORT Q_DECL_IMPORT 12 | #endif 13 | 14 | #define PI 3.14159265358979323846264338327950288419717 15 | #define DEFAULTITEMLIMITPERLAYER 500 16 | #define DEFAULTTILESIZE 256 17 | #define MAXZOOMLEVEL 19 18 | #define MINZOOMLEVEL 1 19 | #define DEFAULTZOOMLEVEL MINZOOMLEVEL 20 | #define DEFAULTLOCATION QPointF(0,0) 21 | #define CONFIGPATH QDir::homePath() + "/.ilong.io/" 22 | 23 | typedef struct 24 | { 25 | int x; 26 | int y; 27 | int z; 28 | } TPoint; 29 | /* 30 | * 图元类型就只会为两种, 31 | * 1,点类图元,可以有很多种点类图元,都是以中心点画图元 32 | * 2,面类图元,由多个坐标生成的图元,线条也是面类图元的一种 33 | * */ 34 | typedef enum 35 | { 36 | iGeoNull, //初始化类型 37 | //点类图元 38 | iGeoCircle, //点 圆 39 | iGeoRect, //矩形 40 | iGeoPie, //扁形 41 | iGeoStar, //星星 42 | iGeoTri, //三角 43 | //面类图元 44 | iGeoPolygon 45 | } ILongGeoType; 46 | 47 | //保存图元的边界 48 | typedef struct 49 | { 50 | qreal minX; 51 | qreal minY; 52 | qreal maxX; 53 | qreal maxY; 54 | } ILongGeoRect; 55 | //数据库字段类型,只设计文本和数值 56 | typedef enum 57 | { 58 | ILongNUMBER, 59 | ILongTEXT, 60 | } ILongType; 61 | 62 | //图层数据结构,就只有字段名和这字段类型了 63 | typedef struct 64 | { 65 | QString name; 66 | ILongType type; 67 | } LayerFormat; 68 | 69 | #endif // ILONG_GLOBAL_H 70 | -------------------------------------------------------------------------------- /Geometry.h: -------------------------------------------------------------------------------- 1 | #ifndef GEOMETRY_H 2 | #define GEOMETRY_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "ilong_global.h" 13 | 14 | /* 15 | * 图元基类,提供所有点类和面类的基本结构 16 | * */ 17 | 18 | class ILONGSHARED_EXPORT Geometry : public QGraphicsObject 19 | { 20 | Q_OBJECT 21 | public: 22 | /* 23 | * 插入图元结构 24 | * */ 25 | typedef struct 26 | { 27 | Geometry * geometry; //图元 28 | QList data; //一行数据放到data列表里 29 | } ILongDataType; 30 | explicit Geometry(ILongGeoType gType,quint8 lWidth, QColor iPen, QColor iBrush); 31 | ILongGeoRect getRect(); 32 | ILongGeoType getGeoType(); 33 | QPointF getCenter(); 34 | QString getPen(); 35 | QString getBrush(); 36 | QString getPoints(); 37 | quint8 getLineWidth(); 38 | quint8 getSize(); 39 | quint32 getID(); 40 | int getDir(); 41 | bool getCloseFlag(); 42 | void rotate(int dir); 43 | void setLabel(QString lb); 44 | QString getLabel(); 45 | int getLabelPixeSize(); 46 | protected: 47 | void checkRect(); 48 | QList list; 49 | ILongGeoType geoType; 50 | QColor pen, brush; 51 | quint8 lineWidth; 52 | int size; 53 | ILongGeoRect rect; 54 | quint32 itemID; 55 | QString label; 56 | int dir; 57 | bool closeFlag; 58 | signals: 59 | 60 | public slots: 61 | }; 62 | 63 | #endif // GEOMETRY_H 64 | -------------------------------------------------------------------------------- /Manager.h: -------------------------------------------------------------------------------- 1 | #ifndef MANAGER_H 2 | #define MANAGER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "ILong.h" 8 | #include "Layer.h" 9 | #include "SQLExcute.h" 10 | 11 | /* 12 | * 提供简单的图层管理功能 13 | * */ 14 | 15 | class ILong; 16 | class Layer; 17 | class ILONGSHARED_EXPORT Manager : public QObject 18 | { 19 | Q_OBJECT 20 | public: 21 | explicit Manager(ILong *iL, QObject * parent = 0); 22 | /* 23 | * 返回所有图层的指针 24 | * */ 25 | QList getLayers(); 26 | /* 27 | * 新增图层,名称@name 28 | * @typeList图层数据结构 29 | * */ 30 | Layer *addLayer(QString name, QList *typeList); 31 | /* 32 | * 通过图层名称@name直接删除图层 33 | * */ 34 | Layer *getLayer(QString name); 35 | Layer *getLayerByID(QString id); 36 | void removeLayer(QString name); 37 | void stopUpdateLayer(); 38 | void addTempItem(QPointF world, ILongGeoType type = iGeoCircle); 39 | bool moveLayer(QString name, bool up = true); 40 | private: 41 | /* 42 | * 检查图层名称@name是否在图层管理表里,如果有,就自动在@name后面加*号,暂时这样处理导入多个同名图层 43 | * */ 44 | QString checkLayerName(QString name); 45 | /* 46 | * 从管理表里加载数据库里的图层,所有参数都在管理表里 47 | * */ 48 | void loadLayer(QString id, QString name, bool visible, bool selectable); 49 | ILong * iLong; 50 | /* 51 | * 所有图层列表,不用每次去图层管理表读取图层信息 52 | * */ 53 | QList list; 54 | SQLExcute * sqlExcute; 55 | bool isUpdate; 56 | 57 | QPointF tempGeoWorldPos; 58 | ILongGeoType tempGeoType; 59 | signals: 60 | void addGeoToScene(Geometry *); 61 | public slots: 62 | void updatLayer(); 63 | }; 64 | 65 | #endif // MANAGER_H 66 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /GeoStar.cpp: -------------------------------------------------------------------------------- 1 | #include "GeoStar.h" 2 | 3 | GeoStar::GeoStar(QPointF world, int size, QColor pen, QColor brush) : 4 | Geometry(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 | -------------------------------------------------------------------------------- /GeoPolygon.cpp: -------------------------------------------------------------------------------- 1 | #include "GeoPolygon.h" 2 | 3 | GeoPolygon::GeoPolygon(ILong *iL, QList * pointList, bool closePath, quint8 lineWidth, QColor pen, QColor brush) : 4 | Geometry(iGeoPolygon,lineWidth, pen, brush),iLong(iL) 5 | { 6 | closeFlag = closePath; 7 | for(int i=0; isize(); i++) 8 | list.append(pointList->at(i)); 9 | checkRect(); 10 | QPointF tl = iLong->worldToScene(QPointF(rect.minX,rect.minY)); 11 | QPointF br = iLong->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 = iLong->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 | -------------------------------------------------------------------------------- /Layer.h: -------------------------------------------------------------------------------- 1 | #ifndef LAYER_H 2 | #define LAYER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "ILong.h" 8 | #include "SQLExcute.h" 9 | #include "Geometry.h" 10 | 11 | /* 12 | * 提供简单的图元管理功能 13 | * */ 14 | 15 | class ILong; 16 | class ILONGSHARED_EXPORT Layer : public QObject 17 | { 18 | Q_OBJECT 19 | public: 20 | 21 | typedef struct 22 | { 23 | quint32 id; 24 | QPointF center; 25 | QString label; 26 | QList list; 27 | int size; 28 | int flags; 29 | QColor pen; 30 | QColor brush; 31 | } ILongInfo; 32 | /* 33 | * 新增图层 34 | * @name 图层名称 35 | * @typeList 图层数据结构 36 | * */ 37 | explicit Layer(ILong * parent,QString name, QList * typeList); 38 | /* 39 | * 从数据库里加载图层,所有参数都在数据库管理表里得到 40 | * */ 41 | Layer(ILong * parent, QString id, QString name, bool visible, bool selectable); 42 | ~Layer(); 43 | QSqlQuery * searchInfo(QString field, QString text); 44 | void setViewToItem(QString itemID); 45 | void addGeo(Geometry::ILongDataType data); 46 | void addGeos(QList * dataList); 47 | QList *getItems(); 48 | void updatLayer(bool * isUpdate); 49 | void setLabel(QString field = "ILONGNULL"); 50 | void updateGeoPenColor(quint32 geoID, QColor c = QColor(Qt::red)); 51 | void updateGeoBrushColor(quint32 geoID, QColor c = QColor(Qt::yellow)); 52 | void removeGeo(QString itemID); 53 | /* 54 | * 返回图层名称 55 | * */ 56 | QString getLayerName(); 57 | /* 58 | * 返回图层ID,和数据库里的表关联 59 | * */ 60 | QString getLayerID(); 61 | /* 62 | * 设置和返回图层可视状态 63 | * */ 64 | QList *getLayerHead(); 65 | void setVisible(bool b); 66 | bool isVisible(); 67 | /* 68 | * 设置和返回图层可选状态 69 | * */ 70 | void setSelectable(bool b); 71 | bool isSelectable(); 72 | QPointF getItemPosByID(QString itemID); 73 | private: 74 | ILongInfo getInfo(QSqlQuery * query); 75 | QList getGisList(QString gis); 76 | ILong * iLong; 77 | QString layerLabel; 78 | /* 79 | * 保存当前图层的图元指针 80 | * */ 81 | //QList list; 82 | QString layerID; 83 | bool visible; 84 | bool selectable; 85 | SQLExcute * sqlExcute; 86 | /* 87 | * 保存当前图层的字段类型,只为了方便导入数据时数据转换检查 88 | * */ 89 | QList headType; 90 | QList list; 91 | 92 | signals: 93 | void addGeoToScene(Geometry *); 94 | public slots: 95 | }; 96 | 97 | #endif // LAYER_H 98 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /SQLExcute.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLEXCUTE_H 2 | #define SQLEXCUTE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "ilong_global.h" 12 | #include "Geometry.h" 13 | 14 | /* 15 | * 第一次面向对象,也是第一次使用c++,所以呢,很多不会的了,反正现在是把所有数据库操作的都放到这个类里了! 16 | * 有用没用都先这么活着,总比不活强多了!~_~,发现我没事我还以自己乐了! 17 | */ 18 | 19 | class ILONGSHARED_EXPORT SQLExcute : public QObject 20 | { 21 | Q_OBJECT 22 | public: 23 | explicit SQLExcute(QObject *parent = 0); 24 | void addItems(QList *dataList, 25 | QString id, QList *headType); 26 | void removeItem(QString layerID, QString itemID); 27 | /* 28 | * 获取当前场景范围内的所有瓦片并返回QSqlQuery,用完了需要自己删除指针 29 | */ 30 | QSqlQuery * checkImage(int maxX, int minX, int maxY, int minY, int z); 31 | /* 32 | * 把已经下载的瓦片插入数据库中 33 | */ 34 | void insertImage(int x, int y, int z, QByteArray ax); 35 | /* 36 | * 创建图层管理 37 | * 图层表里就只有包含图层的ID,NAME,VISIBLE(图层可视),SELECTABLE(图层可选) 38 | */ 39 | QSqlQuery * initLayerManager(); 40 | /* 41 | * 读取id这个数据表的字段类型,并返回QSqlQuery,这个读取字段类型就是为了,如果数据库里已经有表了,那就得把表的字段类型读取出来, 42 | * 保存到自己的图层里,方便插入图元数据的时候判断数据类型而已,没想到更好的办法,用完了需要自己删除指针 43 | */ 44 | QSqlQuery *checkType(QString id); 45 | QSqlQuery *updateLayer(QString id, QPointF topLeft, QPointF rigthBottom, quint32 limit = 1000); 46 | /* 47 | * 创建图层,@id是图层的id,用来做数据库里的表名,在class Layer里自动生成, 48 | * @name 图层名称,创建图层时需要自己指定一个名称, 49 | * @typeList 就是表的数据结构了,有字段名和字段类型 50 | * @headType 就是在图层里用来保存表里所有字段的数据类型 只为了插入图元数据的字段类型选择,为了安全,还是每个数据都做个转换, 51 | * 如果转换失败,基本都是文本转数字失败,就填0,可能影响效率. 52 | */ 53 | void initLayer(QString id, QString name, QList *typeList, QList *headType); 54 | QSqlQuery * getItemInfo(QString itemLayerID, QString itemID); 55 | QSqlQuery * searchInfo(QString itemLayerID, QString field, ILongType fieldType,QString text); 56 | QSqlQuery * setViewToItem(QString layerID,QString itemID); 57 | QSqlQuery * getDefaultLoaction(); 58 | void updateGeoColor(QString layerId, quint32 geoID, QString field, QColor color); 59 | void updateDefaultLoaction(QPointF world = DEFAULTLOCATION, quint8 level = DEFAULTZOOMLEVEL); 60 | void updateItemLimit(quint32 limit); 61 | void closeDB(); 62 | QString dbPath(); 63 | QSqlQuery * tilesCount(); 64 | /* 65 | * 删除图层,@id可以通过图层获得 66 | */ 67 | void removeLayer(QString id); 68 | void clearLayer(QString id); 69 | /* 70 | * 设置图层是否可视 71 | */ 72 | void setLayerVisible(QString id,bool b); 73 | /* 74 | * 设置图层是否可选 75 | */ 76 | void setLayerSelectable(QString id,bool b); 77 | void setLabel(QString id,QString field); 78 | QSqlQuery * getPosByItemID(QString layerID, QString itemID); 79 | private: 80 | /* 81 | * 通用执行有返回结果的@sql语句 82 | * @position 自定义一个信息 如果出错就打印这个信息,还是感觉有点蛋疼,但是现在还没有使用log系统,选这样处理了 83 | */ 84 | QSqlQuery *getResult(QString sql, QString position); 85 | /* 86 | * 通用执行有返回结果的@sql语句 87 | * @position 和getResult一样 88 | */ 89 | void nonResult(QString sql, QString position); 90 | signals: 91 | 92 | public slots: 93 | }; 94 | 95 | #endif // SQLEXCUTE_H 96 | -------------------------------------------------------------------------------- /Geometry.cpp: -------------------------------------------------------------------------------- 1 | #include "Geometry.h" 2 | 3 | Geometry::Geometry(ILongGeoType gType, quint8 lWidth, QColor iPen, QColor iBrush) 4 | { 5 | geoType = gType; 6 | if(gType == 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 | ILongGeoRect Geometry::getRect() 24 | { 25 | return rect; 26 | } 27 | 28 | ILongGeoType 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(); 135 | if(p1.x() <= rect.minX) rect.minX = p1.x(); 136 | if(p1.y() >= rect.maxY) rect.maxY = p1.y(); 137 | if(p1.y() <= rect.minY) rect.minY = p1.y(); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /Network.cpp: -------------------------------------------------------------------------------- 1 | #include "Network.h" 2 | 3 | Network::Network(ILong *iL, QObject *parent) : QObject(parent),list(&iL->list), 4 | manager(new QNetworkAccessManager(this)),isDownloading(false),iLong(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 | 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 | 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(iLong->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 | TPoint t = getXYZFromUrl(reply->url().toString()); 97 | /* 98 | * 下载到的瓦片,看看是不是当前场景内,如果是就打印到场景背景图片里 99 | * */ 100 | if(t.z == iLong->zoomLevel()) 101 | { 102 | QPoint middle = iLong->middle; 103 | QPoint leftTop = iLong->leftTop; 104 | int x = (t.x+leftTop.x()-middle.x())*DEFAULTTILESIZE; 105 | int y = (t.y+leftTop.y()-middle.y())*DEFAULTTILESIZE; 106 | if(x>=0 && xbackground.width() && y >=0 && y < iLong->background.height()) 107 | { 108 | if(iLong->painMutex.tryLock()) 109 | { 110 | QPainter p(&iLong->background); 111 | p.drawPixmap(x,y,DEFAULTTILESIZE,DEFAULTTILESIZE,pm); 112 | p.end(); 113 | iLong->painMutex.unlock(); 114 | } 115 | emit newImage(); 116 | } 117 | } 118 | /* 119 | * 不管是不是场景里的瓦片,只要有瓦片下完都保存到数据库里,方便下次直接调用嘛是吧 120 | * */ 121 | sqlExcute->insertImage(t.x, t.y, t.z, ax); 122 | } 123 | } 124 | } 125 | 126 | -------------------------------------------------------------------------------- /Manager.cpp: -------------------------------------------------------------------------------- 1 | #include "Manager.h" 2 | 3 | Manager::Manager(ILong *iL, QObject *parent) : QObject(parent),iLong(iL),sqlExcute(&iL->sqlExcute) 4 | { 5 | QSqlQuery * query = sqlExcute->initLayerManager(); 6 | while(query->next()) 7 | { 8 | QString id = query->value(0).toString(); 9 | QString name = query->value(1).toString(); 10 | int visible = query->value(2).toInt(); 11 | int selectable = query->value(3).toInt(); 12 | loadLayer(id,name,visible, selectable); 13 | } 14 | delete query; 15 | query = 0; 16 | connect(this, SIGNAL(addGeoToScene(Geometry*)), iLong, SLOT(addGeoToScene(Geometry*))); 17 | } 18 | 19 | QList Manager::getLayers() 20 | { 21 | return list; 22 | } 23 | 24 | Layer *Manager::addLayer(QString name, QList *typeList) 25 | { 26 | QString layerName = checkLayerName(name); 27 | if(name == "iLongio" && layerName != name) 28 | return getLayer(name); 29 | Layer * layer = new Layer(iLong, layerName, typeList); 30 | list.append(layer); 31 | return layer; 32 | } 33 | 34 | Layer *Manager::getLayer(QString name) 35 | { 36 | Layer * l = nullptr; 37 | for(int i=0; igetLayerName() == name) 40 | { 41 | l = list.at(i); 42 | break; 43 | } 44 | } 45 | return l; 46 | } 47 | 48 | Layer *Manager::getLayerByID(QString id) 49 | { 50 | Layer * l = nullptr; 51 | for(int i=0; igetLayerID() == id) 54 | { 55 | l = list.at(i); 56 | break; 57 | } 58 | } 59 | return l; 60 | } 61 | 62 | void Manager::removeLayer(QString name) 63 | { 64 | Layer * l = getLayer(name); 65 | if(name == "iLongio") 66 | { 67 | if(l != nullptr) 68 | sqlExcute->clearLayer(l->getLayerID()); 69 | return; 70 | } 71 | if(l != nullptr) 72 | { 73 | if(name == "iLongio") 74 | sqlExcute->clearLayer(l->getLayerID()); 75 | else 76 | { 77 | list.removeOne(l); 78 | delete l; 79 | } 80 | updatLayer(); 81 | } 82 | } 83 | 84 | void Manager::stopUpdateLayer() 85 | { 86 | isUpdate = false; 87 | iLong->scene()->clear(); 88 | } 89 | 90 | void Manager::addTempItem(QPointF world, ILongGeoType type) 91 | { 92 | qsrand(QDateTime::currentDateTime().time().second()); 93 | tempGeoType = type; 94 | tempGeoWorldPos = world; 95 | QColor pen = QColor(qrand()%255,qrand()%255,qrand()%255); 96 | Geometry * g = nullptr; 97 | switch (tempGeoType) { 98 | case iGeoCircle: 99 | g = new GeoCircle(tempGeoWorldPos,40,pen,pen); 100 | break; 101 | case iGeoRect: 102 | g = new GeoRect(tempGeoWorldPos,40,pen,pen); 103 | break; 104 | case iGeoPie: 105 | g = new GeoPie(tempGeoWorldPos,80,0,pen,pen); 106 | break; 107 | case iGeoStar: 108 | g = new GeoStar(tempGeoWorldPos,40,pen,pen); 109 | break; 110 | case iGeoTri: 111 | g = new GeoTri(tempGeoWorldPos,40,pen,pen); 112 | break; 113 | default: 114 | break; 115 | } 116 | if(g) 117 | { 118 | g->setPos(iLong->worldToScene(tempGeoWorldPos)); 119 | g->setScale(iLong->itemScale); 120 | //iLong->scene()->addItem(tempGeo); 121 | emit addGeoToScene(g); 122 | } 123 | } 124 | 125 | bool Manager::moveLayer(QString name, bool up) 126 | { 127 | Layer * l = getLayer(name); 128 | if(!l) 129 | return false; 130 | int index = list.indexOf(l); 131 | if(up) 132 | { 133 | if(index == 0) 134 | return false; 135 | list.removeAt(index); 136 | list.insert(index - 1, l); 137 | return true; 138 | } 139 | if(index == list.size()+1) 140 | return false; 141 | list.removeAt(index); 142 | list.insert(index + 1, l); 143 | return true; 144 | } 145 | 146 | void Manager::updatLayer() 147 | { 148 | isUpdate = true; 149 | //iLong->scene()->clear(); 150 | for(int i=0; iisVisible() && isUpdate) 153 | { 154 | list.at(i)->updatLayer(&isUpdate); 155 | } 156 | } 157 | addTempItem(tempGeoWorldPos,tempGeoType); 158 | this->thread()->exit(); 159 | } 160 | 161 | QString Manager::checkLayerName(QString name) 162 | { 163 | QString tmp = name ; 164 | for(int i=0; igetLayerName() == tmp) 167 | { 168 | tmp.append("*"); 169 | break; 170 | } 171 | } 172 | return name == tmp ? tmp : checkLayerName(tmp); 173 | } 174 | 175 | void Manager::loadLayer(QString id, QString name, bool visible, bool selectable) 176 | { 177 | Layer * layer = new Layer(iLong,id,name,visible,selectable); 178 | list.append(layer); 179 | } 180 | -------------------------------------------------------------------------------- /ILong.h: -------------------------------------------------------------------------------- 1 | #ifndef ILONG_H 2 | #define ILONG_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "ilong_global.h" 17 | #include "Map.h" 18 | #include "Network.h" 19 | #include "ILoveChina.h" 20 | #include "SQLExcute.h" 21 | #include "Manager.h" 22 | #include "Layer.h" 23 | #include "GeoRect.h" 24 | #include "GeoPie.h" 25 | #include "GeoCircle.h" 26 | #include "GeoStar.h" 27 | #include "GeoTri.h" 28 | #include "GeoPolygon.h" 29 | 30 | /* 31 | * 提供简单的跨平台的瓦片图层框架功能,反正不会C++,更不会面向对象,用来练activateWindow();手的! 32 | * */ 33 | 34 | class Network; 35 | class Manager; 36 | class GeoPolygon; 37 | class ILONGSHARED_EXPORT ILong : public QGraphicsView 38 | { 39 | Q_OBJECT 40 | public: 41 | friend class Manager; 42 | friend class Layer; 43 | friend class Network; 44 | friend class ItemInfo; 45 | 46 | ILong(QWidget *parent=0); 47 | ~ILong(); 48 | 49 | /***************************************************************************** 50 | * API 51 | * ***************************************************************************/ 52 | 53 | /* 54 | * 最大地图等级 55 | * */ 56 | quint8 maxZoomLevel(); 57 | /* 58 | * 最小地图等级 59 | * */ 60 | quint8 minZoomLevel(); 61 | /* 62 | * 当前地图等级 63 | * */ 64 | quint8 zoomLevel(); 65 | /* 66 | * 放大地图 67 | * */ 68 | void zoomIn(); 69 | /* 70 | * 缩小地图 71 | * */ 72 | void zoomOut(); 73 | /* 74 | * 设置默认的地图加载 75 | * @worldCoordinate 位置 76 | * @zoomLevel 地图等级 77 | * */ 78 | void setDefaultLocation(QPointF worldCoordinate, quint8 zoomLevel); 79 | QPointF getDefaultLocation(); 80 | /* 81 | * 返回图层 82 | * */ 83 | QList getLayers() const; 84 | Layer * getlayer(QString name) const; 85 | Layer * getLayerByID(QString ID) const; 86 | /* 87 | * 新增图层 88 | * @name 图层名称 89 | * @typeList 图层数据结构 90 | * */ 91 | Layer *addLayer(QString name, QList *typeList) const; 92 | /* 93 | * 通过图层名称@name删除图层 94 | * */ 95 | void removeLayer(QString name); 96 | void addTempGeo(QPointF world, ILongGeoType type = iGeoCircle); 97 | /* 98 | * 世界坐标和场景坐标相与转换 99 | * */ 100 | QPointF worldToScene(QPointF world); 101 | QPointF sceneToWorld(QPointF scene); 102 | /* 103 | * 设置或返回一个图层的最大图元个数@limit, 一个图层图元太多意义不大 104 | * */ 105 | void setItemLimit(quint32 limit = DEFAULTITEMLIMITPERLAYER); 106 | quint32 getItemLimit(); 107 | /* 108 | * 跳转到默认位置,可以通过setDefaultLocation设置位置,如果有GPS更新位置,默认位置为GPS当前位置 109 | * */ 110 | void goToDefaultLocation(); 111 | /* 112 | * 上下图层了,好像是可以用的,不过我现在用不到 113 | * */ 114 | bool moveLayerTo(QString name, bool back = false); 115 | /* 116 | * 用来响应按键上下左右移动地图了。。。 117 | * */ 118 | void setViewOffset(int deltaX = 10, int deltaY = -10); 119 | /* 120 | * 下载离线瓦片到数据库中,下载只会从当前地图等级开始下载,下到指定的地图等级 121 | * @dowloadMaxLevel >= 当前地图等级 122 | * */ 123 | void DownloadTiles(quint8 dowloadMaxLevel = MAXZOOMLEVEL); 124 | /* 125 | * 取到数据库位置 126 | * */ 127 | QString dbPath(); 128 | /* 129 | * 查询瓦片数量 130 | * */ 131 | int tilesSize(); 132 | /* 133 | * 是不是GPS设备 134 | * */ 135 | bool GPSUE(); 136 | /* 137 | * 当前GPS位置 138 | * */ 139 | QPointF currentGPS(); 140 | /* 141 | * 提供从外部更新地图函数调用 142 | * */ 143 | void updateMap(); 144 | protected: 145 | bool viewportEvent(QEvent *event); 146 | void drawBackground(QPainter *p, const QRectF &rect); 147 | void drawForeground(QPainter *painter, const QRectF &rect); 148 | void resizeEvent(QResizeEvent *event); 149 | void keyPressEvent(QKeyEvent *event); 150 | private: 151 | /* 152 | * 角度和弧度相与转换,没上过高中,数学学得不好,真心不理解弧度,但不影响 153 | * */ 154 | inline qreal degreeToRadian(qreal value); 155 | inline qreal radianToDegree(qreal value); 156 | /* 157 | * 计算当前地图等级@zoomLevel单行或单列共有多少张瓦片了 158 | * */ 159 | int tilesOnZoomLevel(quint8 zoomLevel); 160 | /* 161 | * 计算当前场景内的所有瓦片,并在数据库里查找,如果没找到就下载,如果找到了直接打印到场景背景图片里 162 | * */ 163 | void tilesUrlMatrix(); 164 | /* 165 | * 缩放在指定的位置@world和指定的地图等级@zoomLevel 166 | * 因为默认是缩放在场景中心,所以加了个参数@underMouse限制缩放在鼠标下面 167 | * */ 168 | void zoomTo(QPointF world, quint8 zoomLevel, bool underMouse = false); 169 | /* 170 | * 像拿着放大镜看地图一样在地图上移动场景,就当把场景当成是不能放大的放大镜就好 171 | * @topLeftPos 是场景的左上角位置 172 | * @updateItem 因为平移的时候不想刷新图元,刷新的话,压力比较大,所以设置这我参数 173 | * */ 174 | void setSceneLocation(QPointF topLeftPos, bool updateItem = false); 175 | /* 176 | * 检查地图等级@zoomLevel是否有效 177 | * */ 178 | inline bool checkZoomLevel(quint8 zoomLevel); 179 | /* 180 | * 检查世界坐标@world是否有效 181 | * */ 182 | inline bool checkWorldCoordinate(QPointF world); 183 | /* 184 | * item缩放系数 185 | * */ 186 | qreal itemScale; 187 | /* 188 | * 当前地图等级 189 | * */ 190 | quint8 currentLevel; 191 | /* 192 | * 当前地图瓦片数量 193 | * */ 194 | quint32 numberOfTiles; 195 | /* 196 | * 滚动鼠标缩放或鼠标平移地图时候 保存鼠标位置 197 | * */ 198 | QPoint zoomOnPos; 199 | /* 200 | * 保存初始化位置的世界坐标 201 | * */ 202 | QPointF defaultLocation; 203 | /* 204 | * 地图供应商 205 | * */ 206 | Map map; 207 | /* 208 | * 场景背景图片 209 | * */ 210 | QPixmap background; 211 | /* 212 | * 场景背景图片打印位置 213 | * */ 214 | QPoint backgroundPos; 215 | /* 216 | * @middle 场景中心的那张瓦片的坐标 217 | * @leftTop 场景左上角的那张瓦片的坐标 218 | * 保存在这里是因为下载完瓦片后需要知道打印在哪 219 | * */ 220 | QPoint middle, leftTop; 221 | /* 222 | * 管理网络服务 223 | * */ 224 | Network * net; 225 | /* 226 | * 管理图层 227 | * */ 228 | Manager * manager; 229 | /* 230 | * 瓦片path列表,下载的时候直接从列表里读取,刷新的时候直接保存在列表里 231 | * */ 232 | QList list; 233 | /* 234 | * 下载瓦片线程 235 | * */ 236 | QThread networkThread; 237 | QThread updateThread; 238 | /* 239 | * 数据库管理 240 | * */ 241 | SQLExcute sqlExcute; 242 | /* 243 | * 下载瓦片时候都触发还剩下多少张瓦片没下,就保存在这里,刷新的时候直接打印到场景前景 244 | * */ 245 | int tilesCount; 246 | /* 247 | * 保存当前鼠标所在的位置对应的世界WGS坐标,刷新的时候直接打印到场景前景 248 | * */ 249 | QPointF currentPos; 250 | 251 | quint32 itemLimit; 252 | /* 253 | * 保存鼠标按下后是否移动了,如果移动了就更新 254 | * */ 255 | bool mouseMove; 256 | /* 257 | * 默认有一个图层,这个图层可以用来保存 GPS当前坐标和统计GPS数据用 或者是临时点之类的数据 258 | * */ 259 | Layer * tempLayer; 260 | /* 261 | * 如果有GPS数据 用来保存卫星个数 没想那么多,对于有定位设备的设备而已 262 | * */ 263 | int satellitesCount; 264 | /* 265 | * 如果有GPS数据 保存高度 和 方向, 速度现在暂时没有用 266 | * */ 267 | qreal GPSAltitude; 268 | qreal GPSDir; 269 | /* 270 | * 保存比例 271 | * */ 272 | QList distanceList; 273 | /* 274 | * 保存视图中心点,有GPS时保存GPS位置坐标 275 | * */ 276 | QPointF centerPos; 277 | /* 278 | * 保存有没有GPS,默认没有GPS,如果有GPS,打开程序默认跳转到GPS位置 279 | * */ 280 | bool hasGps; 281 | QPointF GPSLocation; 282 | QMutex painMutex; 283 | double GPSSpeed; 284 | signals: 285 | void viewChangedSignal(bool); 286 | void downloadImage(); 287 | void sendLocationPos(QPointF); 288 | void doubleClicked(QPoint); 289 | void sendItemList(QList); 290 | void updateLayer(); 291 | public slots: 292 | void viewChangedSlot(bool onlyBackground); 293 | void newImage(); 294 | void updateTilesCount(int count); 295 | void updateLocationPos(QPointF world); 296 | void updateInfo(QPointF GPSPos , qreal speed, qreal dir, qreal altitude);//pos, speed, dir,altitude 297 | void updateSatellitesCount(int count); 298 | void addGeoToScene(Geometry * g); 299 | }; 300 | 301 | #endif // ILONG_H 302 | -------------------------------------------------------------------------------- /Layer.cpp: -------------------------------------------------------------------------------- 1 | #include "Layer.h" 2 | 3 | Layer::Layer(ILong *parent, QString name, QList *typeList) : iLong(parent), 4 | layerLabel(name),visible(true),selectable(true),sqlExcute(&parent->sqlExcute) 5 | { 6 | /* 7 | * 这是直接创建新图层并写入数据库 8 | * */ 9 | QUuid id = QUuid::createUuid(); 10 | layerID = QString("ILONGIO%1").arg(id.data1); 11 | LayerFormat f; 12 | f.name = "ILONGID"; 13 | f.type = ILongNUMBER; 14 | headType.append(f); 15 | sqlExcute->initLayer(layerID,layerLabel,typeList, &headType); 16 | connect(this, SIGNAL(addGeoToScene(Geometry*)), iLong, SLOT(addGeoToScene(Geometry*))); 17 | } 18 | 19 | Layer::Layer(ILong * parent,QString id, QString name, bool visible, bool selectable): 20 | iLong(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 | LayerFormat t; 33 | t.name = value; 34 | t.type = type == "TEXT" ? ILongTEXT : ILongNUMBER; 35 | headType.append(t); 36 | } 37 | delete query; 38 | query = 0; 39 | connect(this, SIGNAL(addGeoToScene(Geometry*)), iLong, 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 | ILongType t = ILongTEXT; 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 | iLong->zoomTo(QPointF(x,y),iLong->zoomLevel()); 81 | break; 82 | } 83 | delete query; 84 | query = 0; 85 | } 86 | 87 | void Layer::addGeo(Geometry::ILongDataType 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 | } 98 | 99 | QList * Layer::getItems() 100 | { 101 | return &list; 102 | } 103 | 104 | 105 | void Layer::updatLayer(bool *isUpdate) 106 | { 107 | list.clear(); 108 | if(!*isUpdate) 109 | return; 110 | QPointF leftTop = iLong->sceneToWorld(iLong->mapToScene(QPoint(0,0))); 111 | QPointF rightBottom = iLong->sceneToWorld(iLong->mapToScene(QPoint(iLong->viewport()->width(), 112 | iLong->viewport()->height()))); 113 | QSqlQuery * query =sqlExcute->updateLayer(layerID,leftTop,rightBottom, iLong->getItemLimit()); 114 | while(query->next() && *isUpdate) 115 | { 116 | int type = query->value(1).toInt(); 117 | Geometry * g = nullptr; 118 | ILongInfo itemInfo = getInfo(query); 119 | switch (type) { 120 | case iGeoCircle: 121 | g = new GeoCircle(itemInfo.center,itemInfo.size,itemInfo.pen,itemInfo.brush); 122 | break; 123 | case iGeoRect: 124 | g = new GeoRect(itemInfo.center,itemInfo.size,itemInfo.pen,itemInfo.brush); 125 | break; 126 | case iGeoPie: 127 | g = new GeoPie(itemInfo.center,itemInfo.size,itemInfo.flags,itemInfo.pen,itemInfo.brush); 128 | break; 129 | case iGeoStar: 130 | g = new GeoStar(itemInfo.center,itemInfo.size,itemInfo.pen,itemInfo.brush); 131 | break; 132 | case iGeoTri: 133 | g = new GeoTri(itemInfo.center,itemInfo.size,itemInfo.pen,itemInfo.brush); 134 | break; 135 | case iGeoPolygon: 136 | g = new GeoPolygon(iLong,&itemInfo.list,itemInfo.flags,itemInfo.size,itemInfo.pen,itemInfo.brush); 137 | break; 138 | default: 139 | break; 140 | } 141 | if(g && *isUpdate) 142 | { 143 | if(type == iGeoPolygon) 144 | { 145 | g->setPos(iLong->worldToScene(QPointF(g->getRect().minX,g->getRect().maxY))); 146 | //g->setFlag(QGraphicsItem::ItemIsSelectable); 147 | } 148 | else 149 | { 150 | g->setPos(iLong->worldToScene(itemInfo.center)); 151 | g->setScale(iLong->itemScale); 152 | g->rotate(itemInfo.flags); 153 | } 154 | if(itemInfo.label != "ILONGNULL") 155 | g->setLabel(itemInfo.label); 156 | g->setObjectName(QString("%1_%2").arg(layerID).arg(itemInfo.id)); 157 | //iLong->scene()->addItem(g); 158 | emit addGeoToScene(g); 159 | list.append(g); 160 | } 161 | } 162 | delete query; 163 | query = 0; 164 | } 165 | 166 | void Layer::setLabel(QString field) 167 | { 168 | sqlExcute->setLabel(layerID, field); 169 | } 170 | 171 | void Layer::updateGeoPenColor(quint32 geoID, QColor c) 172 | { 173 | sqlExcute->updateGeoColor(this->getLayerID(),geoID,"PEN",c); 174 | } 175 | 176 | void Layer::updateGeoBrushColor(quint32 geoID, QColor c) 177 | { 178 | sqlExcute->updateGeoColor(this->getLayerID(),geoID,"BRUSH",c); 179 | } 180 | 181 | void Layer::removeGeo(QString itemID) 182 | { 183 | sqlExcute->removeItem(getLayerID(), itemID); 184 | } 185 | 186 | 187 | QString Layer::getLayerName() 188 | { 189 | return layerLabel; 190 | } 191 | 192 | QString Layer::getLayerID() 193 | { 194 | return layerID; 195 | } 196 | 197 | QList *Layer::getLayerHead() 198 | { 199 | return &headType; 200 | } 201 | 202 | void Layer::setVisible(bool b) 203 | { 204 | visible = b; 205 | sqlExcute->setLayerVisible(layerID, b); 206 | } 207 | 208 | bool Layer::isVisible() 209 | { 210 | return visible; 211 | } 212 | 213 | void Layer::setSelectable(bool b) 214 | { 215 | selectable = b; 216 | sqlExcute->setLayerSelectable(layerID, b); 217 | } 218 | 219 | bool Layer::isSelectable() 220 | { 221 | return selectable; 222 | } 223 | 224 | QPointF Layer::getItemPosByID(QString itemID) 225 | { 226 | QSqlQuery * query = sqlExcute->getPosByItemID(getLayerID(),itemID); 227 | if(query->next()) 228 | { 229 | return QPointF(query->value(0).toDouble(),query->value(1).toDouble()); 230 | } 231 | return QPointF(0,0); 232 | delete query; 233 | } 234 | 235 | Layer::ILongInfo Layer::getInfo(QSqlQuery *query) 236 | { 237 | /* 238 | * 主要信息有: 239 | * @ILONGID 与数据的ID关联; 240 | * @TYPE ILongGeoType 枚举图元类型 241 | * @CenterX 图元wgs CenterX 坐标 242 | * @CenterY 图元wgs CenterX 坐标 243 | * @MINX 图元最小wgs X坐标 (点类图元写CenterX相同) 244 | * @MINY 图元最小wgs X坐标 (点类图元写CenterY相同) 245 | * @MAXX 图元最大wgs X坐标 (点类图元写CenterX相同) 246 | * @MAXY 图元最大wgs Y坐标 (点类图元写CenterY相同) 设计两个坐标点只为了非点类图元需要计算边界问题,比如线 247 | * @LABEL 用来显示图标注的, 如果设置显示标注,就从数据表里面把标注内容填充到该字段 默认 ILONGNULL 248 | * @INFO 保存图元GIS信息 249 | * 格式: WGSx1,WGSy1_WGSx2,WGSy2_..._WGSxN,WGSyN 250 | * @FLAGS 点类旋转角度或面类图元闭环(FLAGS==0 线条, FLAGS!=0 多边形) 251 | * @SIZE 多边形或线条线宽或点类图元大小 252 | * @PEN 画笔(R_G_B) 253 | * @BRUSH 画刷(R_G_B) 254 | * 255 | */ 256 | ILongInfo info; 257 | info.id = query->value(0).toDouble(); 258 | info.center = QPointF(query->value(2).toDouble(),query->value(3).toDouble()); 259 | info.label = query->value(8).toString(); 260 | info.list = getGisList(query->value(9).toString()); 261 | info.flags = query->value(10).toInt(); 262 | info.size = query->value(11).toInt(); 263 | QStringList iPen = query->value(12).toString().split('_'); 264 | info.pen = QColor(iPen.at(0).toInt(),iPen.at(1).toInt(),iPen.at(2).toInt()); 265 | iPen = query->value(13).toString().split('_'); 266 | info.brush = QColor(iPen.at(0).toInt(),iPen.at(1).toInt(),iPen.at(2).toInt()); 267 | return info; 268 | } 269 | 270 | QList Layer::getGisList(QString gis) 271 | { 272 | QList l; 273 | QStringList tl = gis.split('_'); 274 | while (!tl.isEmpty()) 275 | { 276 | QString str = tl.first(); 277 | QStringList tmp = str.split(','); 278 | l.append(QPointF(tmp.at(0).toDouble(),tmp.at(1).toDouble())); 279 | tl.removeFirst(); 280 | } 281 | return l; 282 | } 283 | 284 | -------------------------------------------------------------------------------- /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 + "ilong.io"); 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 ILONGIO(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 ILONGIO " << query.lastError().text(); 23 | } 24 | sql = "CREATE TABLE IF NOT EXISTS ILONGCONF(NAME TEXT PRIMARY KEY, VALUE INTEGER DEFAULT 0)"; 25 | if(!query.exec(sql)) 26 | { 27 | qDebug() << "CREATE TABLE ILONGCONF " << 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::ILongDataType 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 == ILongNUMBER) 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 | * @ILONGID 与数据的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 | ILongGeoRect 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() == iGeoPolygon ? data.geometry->getCloseFlag():data.geometry->getDir()) 119 | //@SIZE 120 | .arg(data.geometry->getGeoType() == 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 ILONGID = %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 ILONGID = '%2' ").arg(layerID).arg(itemID); 146 | nonResult(sql, "removeItem "); 147 | sql = QString("DELETE FROM '%1INFO' WHERE ILONGID = '%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 ILONGIO 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 ILONGIO 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, QPointF topLeft, QPointF rigthBottom, quint32 limit) 202 | { 203 | QString t = QString("NOT ( MINX > %1 OR MAXX < %2 OR MINY > %3 OR MAXY < %4 )") 204 | .arg(rigthBottom.x()).arg(topLeft.x()).arg(topLeft.y()).arg(rigthBottom.y()); 205 | QString sql = QString("SELECT * FROM '%1INFO' WHERE %2 GROUP BY RANDOM() LIMIT 0,%3") 206 | .arg(id).arg(t).arg(limit); 207 | return getResult(sql,"updat layer"); 208 | } 209 | 210 | void SQLExcute::initLayer(QString id, QString name, QList * typeList, QList * headType) 211 | { 212 | /* 213 | * 在ILONGIOLAYER建立表索引 214 | * 一个图层分成两个表 215 | * 一个表保存数据(数据表) 216 | * 一个表保存图元信息(信息表) 217 | */ 218 | QString sql = QString("INSERT INTO ILONGIOLAYER VALUES ( '%1', '%2', '%3', '%4' )").arg(id).arg(name).arg(1).arg(0); 219 | nonResult(sql, "initLayer1"); 220 | /* 221 | * 读取表数据结构 并创建表 把结构保存在字段类型headType里,方便插入图元数据使用 222 | */ 223 | QString saveSql = ""; 224 | for(int i=0; i< typeList->size(); i++) 225 | { 226 | QString t = QString(" '%1' '%2' , ").arg(typeList->at(i).name).arg(typeList->at(i).type ? "TEXT" : "REAL"); 227 | headType->append(typeList->at(i)); 228 | saveSql += t; 229 | } 230 | saveSql = saveSql.left(saveSql.length() - 2); 231 | /* 232 | * 创建数据表,专用保存导入的数据 233 | */ 234 | sql = QString("CREATE TABLE '%1' (ILONGID REAL, %2 )").arg(id).arg(saveSql); 235 | nonResult(sql, "initLayer create data table "); 236 | /* 237 | *创建信息表,专用保存图元的,应该可以直接保存图元,但是现在还不知道怎么弄,就先这样弄吧,以后再想办法改进(个人技术原因),主要信息有: 238 | * @ILONGID 与数据的ID关联; 239 | * @TYPE ILongGeoType 枚举图元类型 240 | * @CenterX 图元wgs CenterX 坐标 241 | * @CenterY 图元wgs CenterX 坐标 242 | * @MINX 图元最小wgs X坐标 (点类图元写CenterX相同) 243 | * @MINY 图元最小wgs X坐标 (点类图元写CenterY相同) 244 | * @MAXX 图元最大wgs X坐标 (点类图元写CenterX相同) 245 | * @MAXY 图元最大wgs Y坐标 (点类图元写CenterY相同) 设计两个坐标点只为了非点类图元需要计算边界问题,比如线 246 | * @LABEL 用来显示图标注的, 如果设置显示标注,就从数据表里面把标注内容填充到该字段 247 | * @INFO 保存图元GIS信息 248 | * 格式: WGSx1,WGSy1_WGSx2,WGSy2_..._WGSxN,WGSyN 249 | * @FLAGS 点类旋转角度或面类图元闭环(FLAGS==0 线条, FLAGS!=0 多边形) 250 | * @SIZE 多边形或线条线宽或点类图元大小 251 | * @PEN 画笔(R_G_B) 252 | * @BRUSH 画刷(R_G_B) 253 | * 254 | */ 255 | sql =QString("CREATE TABLE %1INFO (ILONGID REAL, TYPE REAL, CenterX REAL, CenterY REAL, " 256 | "MINX REAL, MINY REAL, MAXX REAL, MAXY REAL, LABEL TEXT, INFO TEXT, FLAGS REAL," 257 | "SIZE REAL, PEN TEXT, BRUSH TEXT)").arg(id); 258 | nonResult(sql, "initLayer create info table "); 259 | } 260 | 261 | QSqlQuery *SQLExcute::getItemInfo(QString itemLayerID, QString itemID) 262 | { 263 | QString sql = QString("SELECT * FROM '%1' WHERE ILONGID = '%2'").arg(itemLayerID).arg(itemID); 264 | return getResult(sql,"getItemInfo"); 265 | } 266 | 267 | QSqlQuery *SQLExcute::searchInfo(QString itemLayerID, QString field, ILongType fieldType, QString text) 268 | { 269 | QString sql; 270 | if(fieldType == ILongNUMBER) 271 | sql = QString("SELECT ILONGID, %1 FROM '%2' WHERE %3 = %4").arg(field).arg(itemLayerID).arg(field).arg(text); 272 | else 273 | sql = QString("SELECT ILONGID, %1 FROM '%2' WHERE %3 like '%%4%'").arg(field).arg(itemLayerID).arg(field).arg(text); 274 | return getResult(sql,"searchInfo"); 275 | } 276 | 277 | QSqlQuery *SQLExcute::setViewToItem(QString layerID, QString itemID) 278 | { 279 | QString sql = QString("SELECT CenterX,CenterY FROM '%1INFO' WHERE ILONGID = '%2'").arg(layerID).arg(itemID); 280 | return getResult(sql,"setViewToItem"); 281 | } 282 | 283 | QSqlQuery *SQLExcute::getDefaultLoaction() 284 | { 285 | QString sql = "SELECT * FROM ILONGCONF"; 286 | return getResult(sql,"getDefaultLoaction"); 287 | } 288 | 289 | void SQLExcute::updateGeoColor(QString layerId, quint32 geoID, QString field, QColor color) 290 | { 291 | if(!(field=="PEN" || field=="BRUSH")) 292 | return; 293 | QString c = QString("%1_%2_%3").arg(color.red()).arg(color.green()).arg(color.blue()); 294 | QString sql = QString("UPDATE '%1INFO' SET '%2' = '%3' WHERE ILONGID = '%4'") 295 | .arg(layerId).arg(field).arg(c).arg(geoID); 296 | nonResult(sql,"updateGeoColor"); 297 | } 298 | 299 | void SQLExcute::updateDefaultLoaction(QPointF world, quint8 level) 300 | { 301 | QString sql = QString("REPLACE INTO ILONGCONF VALUES ('X', %1)").arg(world.x()); 302 | nonResult(sql, "update x "); 303 | sql = QString("REPLACE INTO ILONGCONF VALUES ('Y', %1)").arg(world.y()); 304 | nonResult(sql, "update y "); 305 | sql = QString("REPLACE INTO ILONGCONF VALUES ('LEVEL', %1)").arg(level); 306 | nonResult(sql, "update level "); 307 | } 308 | 309 | void SQLExcute::updateItemLimit(quint32 limit) 310 | { 311 | QString sql = QString("REPLACE INTO ILONGCONF VALUES ('LIMIT', %1)").arg(limit); 312 | nonResult(sql, "update limit "); 313 | } 314 | 315 | void SQLExcute::closeDB() 316 | { 317 | QSqlDatabase db; 318 | if(QSqlDatabase::contains("qt_sql_default_connection")) 319 | db = QSqlDatabase::database("qt_sql_default_connection"); 320 | else 321 | db = QSqlDatabase::addDatabase("QSQLITE"); 322 | if(db.isOpen()) 323 | { 324 | db.commit(); 325 | db.close(); 326 | } 327 | } 328 | 329 | QString SQLExcute::dbPath() 330 | { 331 | return CONFIGPATH + "ilong.io"; 332 | } 333 | 334 | QSqlQuery *SQLExcute::tilesCount() 335 | { 336 | QString sql = "SELECT COUNT(*) FROM ILONGIO"; 337 | return getResult(sql,"tilesCount"); 338 | } 339 | 340 | void SQLExcute::removeLayer(QString id) 341 | { 342 | QString sql = QString("DELETE FROM ILONGIOLAYER WHERE ID = '%1' ").arg(id); 343 | nonResult(sql, "removeLayer on ILONGIOLAYER " + id); 344 | sql = QString("DROP TABLE '%1' ").arg(id); 345 | nonResult(sql, "DROP TABLE " + id); 346 | sql = QString("DROP TABLE '%1INFO' ").arg(id); 347 | nonResult(sql, "DROP INFO TABLE " + id); 348 | } 349 | 350 | void SQLExcute::clearLayer(QString id) 351 | { 352 | QString sql = QString("DELETE FROM '%1' ").arg(id); 353 | nonResult(sql, "CLEAR " + id); 354 | sql = QString("DELETE FROM '%1INFO' ").arg(id); 355 | nonResult(sql, "CLEAR INFO TABLE " + id); 356 | } 357 | 358 | void SQLExcute::setLayerVisible(QString id, bool b) 359 | { 360 | QString sql = QString("UPDATE ILONGIOLAYER SET VISIBLE = '%1' WHERE ID = '%2' ").arg(b).arg(id); 361 | nonResult(sql, "setLayerVisible " + id); 362 | } 363 | 364 | void SQLExcute::setLayerSelectable(QString id, bool b) 365 | { 366 | QString sql = QString("UPDATE ILONGIOLAYER SET SELECTABLE = '%1' WHERE ID = '%2' ").arg(b).arg(id); 367 | nonResult(sql, "setLayerVisible " + id); 368 | } 369 | 370 | void SQLExcute::setLabel(QString id, QString field) 371 | { 372 | //ILONGNULL 清除标注 373 | QString sql; 374 | if(field == "ILONGNULL") 375 | sql = QString("UPDATE '%1INFO' SET LABEL = 'ILONGNULL' ").arg(id); 376 | else 377 | sql = QString("UPDATE '%1INFO' SET LABEL = (SELECT %2 FROM '%1' WHERE ILONGID = '%1INFO'.ILONGID) ") 378 | .arg(id).arg(field); 379 | nonResult(sql, "setLabel " + id); 380 | } 381 | 382 | QSqlQuery *SQLExcute::getPosByItemID(QString layerID, QString itemID) 383 | { 384 | QString sql = QString("SELECT CenterX,CenterY FROM '%1INFO' WHERE ILONGID = '%2'").arg(layerID).arg(itemID); 385 | return getResult(sql,"getPosByItemID"); 386 | } 387 | 388 | QSqlQuery *SQLExcute::getResult(QString sql, QString position) 389 | { 390 | QSqlDatabase db; 391 | if(QSqlDatabase::contains("qt_sql_default_connection")) 392 | db = QSqlDatabase::database("qt_sql_default_connection"); 393 | else 394 | db = QSqlDatabase::addDatabase("QSQLITE"); 395 | if(!db.isOpen()) 396 | { 397 | if(!db.open()) 398 | { 399 | qDebug() << position << db.lastError().text(); 400 | return nullptr; 401 | } 402 | } 403 | QSqlQuery * query = new QSqlQuery(db); 404 | if(!query->exec(sql)) 405 | { 406 | qDebug() << position << query->lastError().text(); 407 | return nullptr; 408 | } 409 | return query; 410 | } 411 | 412 | void SQLExcute::nonResult(QString sql, QString position) 413 | { 414 | QSqlDatabase db; 415 | if(QSqlDatabase::contains("qt_sql_default_connection")) 416 | db = QSqlDatabase::database("qt_sql_default_connection"); 417 | else 418 | db = QSqlDatabase::addDatabase("QSQLITE"); 419 | if(!db.isOpen()) 420 | { 421 | if(!db.open()) 422 | { 423 | qDebug() << position << db.lastError().text(); 424 | return; 425 | } 426 | } 427 | db.transaction(); 428 | QSqlQuery query(db); 429 | if(!query.exec(sql)) 430 | { 431 | qDebug() << position << query.lastError().text(); 432 | qDebug() << sql; 433 | } 434 | db.commit(); 435 | } 436 | 437 | 438 | 439 | -------------------------------------------------------------------------------- /ILong.cpp: -------------------------------------------------------------------------------- 1 | #include "ILong.h" 2 | 3 | 4 | ILong::ILong(QWidget *parent) : QGraphicsView(parent),itemScale(1), 5 | currentLevel(DEFAULTZOOMLEVEL),numberOfTiles(tilesOnZoomLevel(currentLevel)), 6 | defaultLocation(DEFAULTLOCATION),net(new Network(this)), 7 | tilesCount(0),currentPos(DEFAULTLOCATION),itemLimit(DEFAULTITEMLIMITPERLAYER), 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 | if(fieldName == "LIMIT") 30 | { 31 | itemLimit = query->value(1).toInt(); 32 | } 33 | } 34 | delete query; 35 | //distanceList<<5000000<<2000000<<1000000<<1000000<<1000000<<100000<<100000<<50000<<50000<<10000<<10000<<10000<<1000<<1000<<500<<200<<100<<50<<20; 36 | distanceList<<5000000<<2000000<<1000000<<500000<<200000<<100000<<50000<<20000<<10000<<5000<<2000<<1000<<500<<200<<100<<50<<20<<10<<5; 37 | setStyleSheet("background-color:rgb(236,236,236)"); 38 | setScene(new QGraphicsScene(this)); 39 | /* 40 | * @manager得在QGraphicsScene初始化之后才能使用,所以在这里初始化 41 | * */ 42 | manager = new Manager(this); 43 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 44 | setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff ); 45 | setViewportUpdateMode(FullViewportUpdate); 46 | centerOn(0,0); 47 | //grabGesture(Qt::PinchGesture); 48 | //viewport()->setAttribute(Qt::WA_AcceptTouchEvents); 49 | //viewport()->grabGesture(Qt::PinchGesture); 50 | setSceneRect(viewport()->rect()); 51 | /* 52 | * 处理刷新信号 53 | * */ 54 | connect(this,SIGNAL(viewChangedSignal(bool)),this,SLOT(viewChangedSlot(bool))); 55 | net->moveToThread(&networkThread); 56 | /* 57 | * 处理下载信号 58 | * */ 59 | connect(this,SIGNAL(downloadImage()),net,SLOT(start())); 60 | connect(net,SIGNAL(newImage()),this,SLOT(newImage())); 61 | connect(net,SIGNAL(sendTileCount(int)),this, SLOT(updateTilesCount(int))); 62 | 63 | manager->moveToThread(&updateThread); 64 | connect(this, SIGNAL(updateLayer()), manager, SLOT(updatLayer())); 65 | /* 66 | * 处理当前世界坐标位置信号 67 | * */ 68 | connect(this,SIGNAL(sendLocationPos(QPointF)),this,SLOT(updateLocationPos(QPointF))); 69 | // resetMatrix(); 70 | // scale(0.5,0.5); 71 | QList fm; 72 | fm << LayerFormat{"NAME",ILongTEXT} << LayerFormat{"VALUE",ILongNUMBER}; 73 | tempLayer = manager->addLayer("iLongio", &fm); 74 | // QList l; 75 | // l.append(QPointF(99.7319,27.8306)); 76 | // l.append(QPointF(99.0115,27.6178)); 77 | // Geometry::ILongDataType tttt; 78 | // tttt.geometry = new GeoPolygon(this,&l); 79 | // tttt.data<<"xxx"<<0; 80 | // tempLayer->addGeo(tttt); 81 | } 82 | 83 | ILong::~ILong() 84 | { 85 | networkThread.exit(0); 86 | while(networkThread.isRunning()) 87 | this->thread()->usleep(100); 88 | updateThread.exit(0); 89 | while(updateThread.isRunning()) 90 | this->thread()->usleep(100); 91 | } 92 | 93 | quint8 ILong::maxZoomLevel() 94 | { 95 | return MAXZOOMLEVEL; 96 | } 97 | 98 | quint8 ILong::minZoomLevel() 99 | { 100 | return MINZOOMLEVEL; 101 | } 102 | 103 | quint8 ILong::zoomLevel() 104 | { 105 | return currentLevel; 106 | } 107 | 108 | void ILong::zoomIn() 109 | { 110 | if(checkZoomLevel(currentLevel + 1)) 111 | { 112 | currentLevel++; 113 | zoomOnPos = viewport()->rect().center(); 114 | zoomTo(sceneToWorld(mapToScene(zoomOnPos)),currentLevel,true); 115 | } 116 | } 117 | 118 | void ILong::zoomOut() 119 | { 120 | if(checkZoomLevel(currentLevel - 1)) 121 | { 122 | currentLevel--; 123 | zoomOnPos = viewport()->rect().center(); 124 | zoomTo(sceneToWorld(mapToScene(zoomOnPos)),currentLevel,true); 125 | } 126 | } 127 | 128 | void ILong::setDefaultLocation(QPointF worldCoordinate, quint8 zoomLevel) 129 | { 130 | if(checkWorldCoordinate(worldCoordinate) && checkZoomLevel(zoomLevel)) 131 | { 132 | defaultLocation = worldCoordinate; 133 | currentLevel = zoomLevel; 134 | } 135 | sqlExcute.updateDefaultLoaction(defaultLocation,currentLevel); 136 | zoomTo(defaultLocation,currentLevel); 137 | } 138 | 139 | QPointF ILong::getDefaultLocation() 140 | { 141 | return defaultLocation; 142 | } 143 | 144 | QList ILong::getLayers() const 145 | { 146 | return manager->getLayers(); 147 | } 148 | 149 | Layer *ILong::getlayer(QString name) const 150 | { 151 | return manager->getLayer(name); 152 | } 153 | 154 | Layer *ILong::getLayerByID(QString ID) const 155 | { 156 | return manager->getLayerByID(ID); 157 | } 158 | 159 | Layer *ILong::addLayer(QString name, QList *typeList) const 160 | { 161 | if(!typeList->size() || name.isEmpty()) 162 | return nullptr; 163 | return manager->addLayer(name,typeList); 164 | } 165 | 166 | void ILong::removeLayer(QString name) 167 | { 168 | manager->removeLayer(name); 169 | } 170 | 171 | void ILong::addTempGeo(QPointF world, ILongGeoType type) 172 | { 173 | 174 | Geometry * g = nullptr; 175 | QColor pen = QColor(qrand()%255,qrand()%255,qrand()%255); 176 | QColor brush = QColor(qrand()%255,qrand()%255,qrand()%255); 177 | switch (type) { 178 | case iGeoCircle: 179 | g = new GeoCircle(world,80,pen,brush); 180 | break; 181 | case iGeoRect: 182 | g = new GeoRect(world,80,pen,brush); 183 | break; 184 | case iGeoPie: 185 | g = new GeoPie(world,80,0,pen,brush); 186 | break; 187 | case iGeoStar: 188 | g = new GeoStar(world,80,pen,brush); 189 | break; 190 | case iGeoTri: 191 | g = new GeoTri(world,80,pen,brush); 192 | break; 193 | default: 194 | break; 195 | } 196 | if(g) 197 | { 198 | Geometry::ILongDataType t; 199 | t.geometry = g; 200 | t.data << "iLong" << 0; 201 | tempLayer->addGeo(t); 202 | zoomTo(world,zoomLevel()); 203 | delete g; 204 | g = nullptr; 205 | } 206 | } 207 | QPointF ILong::worldToScene(QPointF world) 208 | { 209 | world = ILoveChina::wgs84TOgcj02(world); 210 | return QPointF((world.x()+180) * (numberOfTiles*DEFAULTTILESIZE)/360., 211 | (1-(log(tan(PI/4.+degreeToRadian(world.y())/2.)) /PI)) /2. * (numberOfTiles*DEFAULTTILESIZE)); 212 | } 213 | 214 | QPointF ILong::sceneToWorld(QPointF scene) 215 | { 216 | 217 | return ILoveChina::gcj02Towgs84(QPointF((scene.x()*(360./(numberOfTiles*DEFAULTTILESIZE)))-180, 218 | radianToDegree(atan(sinh((1-scene.y()*(2./(numberOfTiles*DEFAULTTILESIZE)))*PI))))); 219 | } 220 | 221 | void ILong::setItemLimit(quint32 limit) 222 | { 223 | itemLimit = limit; 224 | sqlExcute.updateItemLimit(limit); 225 | } 226 | 227 | quint32 ILong::getItemLimit() 228 | { 229 | return itemLimit; 230 | } 231 | 232 | void ILong::goToDefaultLocation() 233 | { 234 | zoomTo(defaultLocation,zoomLevel()); 235 | } 236 | 237 | bool ILong::moveLayerTo(QString name, bool back) 238 | { 239 | return manager->moveLayer(name, back); 240 | } 241 | 242 | void ILong::setViewOffset(int deltaX, int deltaY) 243 | { 244 | setSceneLocation(QPointF(sceneRect().x() + deltaX, sceneRect().y() + deltaY)); 245 | emit viewChangedSignal(true); 246 | } 247 | 248 | void ILong::DownloadTiles(quint8 dowloadMaxLevel) 249 | { 250 | if(dowloadMaxLevel < currentLevel) 251 | return; 252 | if(dowloadMaxLevel > MAXZOOMLEVEL) 253 | dowloadMaxLevel = MAXZOOMLEVEL; 254 | //进来得先保存 左上角和右下角的世界坐标位置先 255 | QPointF dowloadTilesTL = sceneToWorld(mapToScene(0,0)); 256 | QPointF dowloadTilesBR = sceneToWorld(mapToScene(viewport()->width(), viewport()->height())); 257 | for(int level=currentLevel; level<=dowloadMaxLevel; level++) 258 | { 259 | QPointF sceneCenter = mapToScene(viewport()->rect().center()); 260 | QPointF leftTopDelta = sceneCenter - worldToScene(dowloadTilesTL); 261 | QPointF rightBottomDelta = worldToScene(dowloadTilesBR) - sceneCenter; 262 | QPoint dMid = QPoint(sceneCenter.x() / DEFAULTTILESIZE,sceneCenter.y() / DEFAULTTILESIZE); 263 | QPoint dTL = QPoint(leftTopDelta.x() / DEFAULTTILESIZE + 1,leftTopDelta.y() / DEFAULTTILESIZE + 1); 264 | int rightTiles = rightBottomDelta.x() / DEFAULTTILESIZE + 1; 265 | int bottomTiles = rightBottomDelta.y() / DEFAULTTILESIZE + 1; 266 | for(int x=-dTL.x()+dMid.x(); x<=rightTiles+dMid.x(); x++) 267 | { 268 | for(int y=-dTL.y()+dMid.y(); y<=bottomTiles+dMid.y(); y++) 269 | { 270 | if(map.isTileValid(x,y,currentLevel)) 271 | { 272 | QString path = map.queryTile(x, y, currentLevel); 273 | list.append(path); 274 | } 275 | 276 | } 277 | } 278 | zoomIn(); 279 | } 280 | } 281 | 282 | QString ILong::dbPath() 283 | { 284 | return sqlExcute.dbPath(); 285 | } 286 | 287 | int ILong::tilesSize() 288 | { 289 | QSqlQuery * query = sqlExcute.tilesCount(); 290 | int result = 0; 291 | if(query->next()) 292 | result = query->value(0).toInt(); 293 | delete query; 294 | return result; 295 | } 296 | 297 | bool ILong::GPSUE() 298 | { 299 | return hasGps; 300 | } 301 | 302 | QPointF ILong::currentGPS() 303 | { 304 | return hasGps ? GPSLocation : centerPos; 305 | } 306 | 307 | void ILong::updateMap() 308 | { 309 | emit viewChangedSignal(false); 310 | } 311 | 312 | 313 | bool ILong::viewportEvent(QEvent *event) 314 | { 315 | switch(event->type()) 316 | { 317 | case QEvent::Wheel: 318 | { 319 | QWheelEvent * wheelEvent = static_cast(event);; 320 | zoomOnPos = wheelEvent->pos(); 321 | wheelEvent->delta() > 0 ? zoomIn() : zoomOut(); 322 | wheelEvent->accept(); 323 | return true; 324 | break; 325 | } 326 | case QEvent::MouseButtonDblClick: 327 | { 328 | QMouseEvent * doubleClickEvent = static_cast(event); 329 | emit doubleClicked(doubleClickEvent->pos()); 330 | doubleClickEvent->accept(); 331 | return true; 332 | } 333 | case QEvent::MouseButtonPress: 334 | { 335 | QMouseEvent * pressEvent = static_cast(event); 336 | pressEvent->accept(); 337 | if(pressEvent->buttons() & Qt::LeftButton) 338 | { 339 | zoomOnPos = pressEvent->pos(); 340 | mouseMove = false; 341 | 342 | QPointF point = mapToScene(pressEvent->pos()); 343 | if (scene()->items(point).count() != 0) 344 | { 345 | QList l = scene()->items(point); 346 | for(int i= l.size() - 1; i>=0; i--) 347 | { 348 | Geometry * g = (Geometry *)l.at(i); 349 | QStringList nameList = g->objectName().split('_'); 350 | if(g->objectName().isEmpty() || nameList.size() != 2) 351 | { 352 | l.removeOne(l.at(i)); 353 | continue; 354 | } 355 | Layer * layer = manager->getLayerByID(nameList.at(0)); 356 | if(!layer->isSelectable()) 357 | l.removeOne(l.at(i)); 358 | 359 | } 360 | emit sendItemList(l); 361 | } 362 | } 363 | return true; 364 | } 365 | case QEvent::MouseMove: 366 | { 367 | QMouseEvent * moveEvent = static_cast(event); 368 | emit sendLocationPos(sceneToWorld(mapToScene(moveEvent->pos()))); 369 | if(moveEvent->buttons() & Qt::LeftButton) 370 | { 371 | 372 | QPoint moveDelta = moveEvent->pos() - zoomOnPos; 373 | scene()->clear(); 374 | setSceneLocation(QPointF(sceneRect().x() - moveDelta.x(),sceneRect().y() - moveDelta.y())); 375 | backgroundPos = backgroundPos + moveDelta; 376 | zoomOnPos = moveEvent->pos(); 377 | mouseMove = true; 378 | moveEvent->accept(); 379 | /* 380 | * 这段码让托放变得很卡,理想是很美好的。。。。 381 | if(backgroundPos.x()>=0 || backgroundPos.y()>=0 382 | || backgroundPos.x()+background.width()<=viewport()->width() 383 | || backgroundPos.y()+background.height()<=viewport()->height() ) 384 | { 385 | emit viewChangedSignal(true); 386 | } 387 | **/ 388 | } 389 | return true; 390 | } 391 | case QEvent::MouseButtonRelease: 392 | { 393 | QMouseEvent * releaseEvent = static_cast(event); 394 | { 395 | if(releaseEvent->button() & Qt::LeftButton && zoomOnPos != QPoint(0,0) && mouseMove) 396 | { 397 | emit viewChangedSignal(false); 398 | zoomOnPos = QPoint(0,0); 399 | releaseEvent->accept(); 400 | } 401 | } 402 | mouseMove = false; 403 | return true; 404 | } 405 | default: 406 | break; 407 | } 408 | return QGraphicsView::viewportEvent(event); 409 | } 410 | 411 | void ILong::drawBackground(QPainter *p, const QRectF &rect) 412 | { 413 | Q_UNUSED(rect); 414 | p->save(); 415 | p->resetTransform(); 416 | p->setRenderHint(QPainter::Antialiasing); 417 | p->drawPixmap(backgroundPos,background); 418 | p->restore(); 419 | } 420 | 421 | void ILong::drawForeground(QPainter *painter, const QRectF &rect) 422 | { 423 | Q_UNUSED(rect); 424 | painter->save(); 425 | painter->resetTransform(); 426 | painter->setRenderHint(QPainter::Antialiasing); 427 | painter->setPen(QColor(Qt::green)); 428 | QLabel lb; 429 | QPoint p = viewport()->rect().center(); 430 | int line = distanceList.at( zoomLevel()-1) / pow(2.0, MAXZOOMLEVEL-zoomLevel() -1) / 0.597164; 431 | int telta = ((viewport()->width() > viewport()->height() ? viewport()->width() : viewport()->height()) / 2) / line; 432 | for(int i=0; isetPen(QColor( i%2 ? Qt::red : Qt::green)); 435 | painter->drawLine(QPoint(p.x()+i*line,p.y()-5),QPoint(p.x()+i*line,p.y()+5)); 436 | painter->drawLine(QPoint(p.x()-i*line,p.y()-5),QPoint(p.x()-i*line,p.y()+5)); 437 | painter->drawLine(QPoint(p.x()-5,p.y()+i*line),QPoint(p.x()+5,p.y()+i*line)); 438 | painter->drawLine(QPoint(p.x()-5,p.y()-i*line),QPoint(p.x()+5,p.y()-i*line)); 439 | } 440 | QFont font = painter->font(); 441 | font.setBold(true); 442 | painter->setFont(font); 443 | for(int i=1; i<=maxZoomLevel(); i++) 444 | { 445 | painter->setPen(QColor(i == zoomLevel() ? Qt::red : Qt::green)); 446 | painter->drawLine(QPoint(width()/2 - ((maxZoomLevel()/2+1)*5) + i*5,height()-15), 447 | QPoint(width()/2 - ((maxZoomLevel()/2+1)*5) + i*5,height()-25)); 448 | } 449 | painter->setPen(QColor(Qt::green)); 450 | QString distance = QVariant( distanceList.at(zoomLevel()-1) / 1000).toString(); 451 | painter->drawText(QPoint(10,height()-15), QString("%1km").arg(distance)); 452 | QString copyRight("iLong.io"); 453 | painter->drawText(QPoint((width()-lb.fontMetrics().width(copyRight)-15),height()-15),copyRight); 454 | QString north = centerPos.x() >= 0 ? "N" : "S"; 455 | QString east = centerPos.y() >= 0 ? "E" : "W"; 456 | painter->resetTransform(); 457 | painter->translate(width(),0); 458 | painter->rotate(90); 459 | painter->drawText(QPoint(15,10+lb.fontMetrics().height()),QString("%1%2 %3%4").arg(north) 460 | .arg(fabs(currentPos.x()),0,'g',10).arg(east) 461 | .arg(fabs(currentPos.y()),0,'g',10)); 462 | painter->resetTransform(); 463 | painter->translate(15+lb.fontMetrics().height()/2,15); 464 | painter->rotate(90); 465 | //painter->translate(0,width()-15-lb.fontMetrics().height()); 466 | painter->drawText(QPoint(0,10),QString("A:%1 D:%2 T:%3 L:%4 S:%5") 467 | .arg(GPSAltitude).arg(GPSDir).arg(tilesCount) 468 | .arg(satellitesCount).arg(QString::number(GPSSpeed,'g',2)) ); 469 | painter->restore(); 470 | } 471 | 472 | void ILong::resizeEvent(QResizeEvent *event) 473 | { 474 | event->accept(); 475 | zoomTo(defaultLocation,currentLevel); 476 | } 477 | 478 | void ILong::keyPressEvent(QKeyEvent *event) 479 | { 480 | //QMessageBox::information(this,"x",QString::number( event->key())); 481 | switch (event->key()) { 482 | case Qt::Key_J: 483 | case Qt::Key_Z: 484 | case Qt::Key_VolumeUp: 485 | zoomIn(); 486 | break; 487 | case Qt::Key_K: 488 | case Qt::Key_X: 489 | case Qt::Key_VolumeDown: 490 | zoomOut(); 491 | break; 492 | case Qt::Key_Up: 493 | case Qt::Key_W: 494 | setViewOffset(0,-10); 495 | break; 496 | case Qt::Key_Down: 497 | case Qt::Key_S: 498 | setViewOffset(0,10); 499 | break; 500 | case Qt::Key_Left: 501 | case Qt::Key_A: 502 | setViewOffset(-10,0); 503 | break; 504 | case Qt::Key_Right: 505 | case Qt::Key_D: 506 | setViewOffset(10,0); 507 | break; 508 | default: 509 | break; 510 | } 511 | } 512 | 513 | 514 | qreal ILong::degreeToRadian(qreal value) 515 | { 516 | return value * (PI/180.); 517 | } 518 | 519 | qreal ILong::radianToDegree(qreal value) 520 | { 521 | return value * (180./PI); 522 | } 523 | 524 | int ILong::tilesOnZoomLevel(quint8 zoomLevel) 525 | { 526 | return int(pow(2.0, zoomLevel)); 527 | } 528 | 529 | void ILong::tilesUrlMatrix() 530 | { 531 | quint8 offset = 1; 532 | QPointF sceneCenter = mapToScene(viewport()->rect().center()); 533 | QPointF leftTopDelta = sceneCenter - mapToScene(QPoint(0,0)); 534 | QPointF rightBottomDelta = mapToScene(QPoint(viewport()->width(),viewport()->height())) - sceneCenter; 535 | middle = QPoint(sceneCenter.x() / DEFAULTTILESIZE,sceneCenter.y() / DEFAULTTILESIZE); 536 | leftTop = QPoint(leftTopDelta.x() / DEFAULTTILESIZE + offset,leftTopDelta.y() / DEFAULTTILESIZE + offset); 537 | int rightTiles = rightBottomDelta.x() / DEFAULTTILESIZE + offset; 538 | int bottomTiles = rightBottomDelta.y() / DEFAULTTILESIZE + offset; 539 | background = QPixmap((leftTop.x() + rightTiles + offset) * DEFAULTTILESIZE, 540 | (leftTop.y() + bottomTiles + offset) * DEFAULTTILESIZE); 541 | background.fill(QColor::fromRgb(236,236,236)); 542 | backgroundPos = mapFromScene((-leftTop.x()+middle.x())*DEFAULTTILESIZE, 543 | (-leftTop.y()+middle.y())*DEFAULTTILESIZE); 544 | /* 545 | * 先把所有有效的瓦片坐标保存到tList里 546 | * */ 547 | QList tList; 548 | for(int x=-leftTop.x()+middle.x(); x<=rightTiles+middle.x(); x++) 549 | { 550 | for(int y=-leftTop.y()+middle.y(); y<=bottomTiles+middle.y(); y++) 551 | { 552 | if(map.isTileValid(x,y,currentLevel)) 553 | { 554 | tList.append(QPoint(x,y)); 555 | } 556 | 557 | } 558 | } 559 | /* 560 | * 再从数据库里读取当前场景有效的瓦片,如果读取失败,直接把@tList里的所有坐标生成path保存到@list里, 561 | * 然后跳到最后启动下载线程 562 | * */ 563 | QSqlQuery * query = sqlExcute.checkImage(leftTop.x()+middle.x(), -rightTiles+middle.x(), 564 | leftTop.y()+middle.y(), -bottomTiles+middle.y(), currentLevel); 565 | bool checkImageError = false; 566 | if(query == nullptr) 567 | { 568 | while(!tList.isEmpty()) 569 | { 570 | QPoint p = tList.first(); 571 | QString path = map.queryTile(p.x(),p.y(),currentLevel); 572 | list.contains(path) ? list.move(list.indexOf(path),0) : list.insert(0,path); 573 | tList.removeFirst(); 574 | } 575 | checkImageError = true; 576 | } 577 | /* 578 | * 如果读取成功,得把瓦片打印到场景的背景图里,并删除@tList里的对就瓦片的坐标 579 | * */ 580 | while (query->next() && !checkImageError) 581 | { 582 | int x = query->value(0).toInt(); 583 | int y = query->value(1).toInt(); 584 | //int z = query->value(2).toInt(); 585 | QPixmap pm; 586 | pm.loadFromData(query->value(3).toByteArray()); 587 | if(painMutex.tryLock()) 588 | { 589 | QPainter painter(&background); 590 | painter.drawPixmap((x+leftTop.x()-middle.x())*DEFAULTTILESIZE 591 | ,(y+leftTop.y()-middle.y())*DEFAULTTILESIZE 592 | ,DEFAULTTILESIZE,DEFAULTTILESIZE,pm); 593 | painter.end(); 594 | painMutex.unlock(); 595 | } 596 | tList.removeOne(QPoint(x,y)); 597 | } 598 | if(query) 599 | { 600 | delete query; 601 | query = 0; 602 | } 603 | /* 604 | * 到了这里,如果tList还没空,那就说明有此瓦片是在数据库里没有的,需要从@tList里把坐标转成path保存到@list里然后启动下载线程 605 | * 之所以用随机数,就是为了影响瓦片的下载顺序,让人看着感觉不是只能从一个方向刷新场景背景的了,没多大用处 606 | * */ 607 | qsrand(QDateTime::currentDateTime().time().second()); 608 | while(!tList.isEmpty() && !checkImageError) 609 | { 610 | int index = qrand() % tList.size(); 611 | QPoint value = tList.at(index); 612 | QString path = map.queryTile(value.x(), value.y(), currentLevel); 613 | list.contains(path) ? list.move(list.indexOf(path),0) : list.insert(0,path); 614 | tList.removeOne(value); 615 | } 616 | if(!networkThread.isRunning()) 617 | networkThread.start(); 618 | if(!net->getDownloadState()) 619 | emit downloadImage(); 620 | } 621 | 622 | void ILong::zoomTo(QPointF world, quint8 zoomLevel, bool underMouse) 623 | { 624 | currentLevel = zoomLevel; 625 | numberOfTiles = tilesOnZoomLevel(currentLevel); 626 | itemScale = currentLevel * 1. / MAXZOOMLEVEL ; 627 | setSceneLocation(worldToScene(world) - 628 | (underMouse ? zoomOnPos : viewport()->rect().center()), 629 | true); 630 | 631 | } 632 | 633 | void ILong::setSceneLocation(QPointF topLeftPos, bool updateItem) 634 | { 635 | setSceneRect(topLeftPos.x(),topLeftPos.y(),viewport()->width(), viewport()->height()); 636 | centerPos = sceneToWorld(mapToScene(viewport()->rect().center())); 637 | if(updateItem) 638 | emit viewChangedSignal(false); 639 | } 640 | 641 | bool ILong::checkZoomLevel(quint8 zoomLevel) 642 | { 643 | return (zoomLevel>=MINZOOMLEVEL && zoomLevel<=MAXZOOMLEVEL); 644 | } 645 | 646 | bool ILong::checkWorldCoordinate(QPointF world) 647 | { 648 | return (world.x() >= -180 && world.x() <= 180 && world.y() >= -85 && world.y() <= 85); 649 | } 650 | 651 | void ILong::addGeoToScene(Geometry *g) 652 | { 653 | if(g) 654 | scene()->addItem(g); 655 | } 656 | 657 | void ILong::viewChangedSlot(bool onlyBackground) 658 | { 659 | manager->stopUpdateLayer(); 660 | tilesUrlMatrix(); 661 | if(!updateThread.isRunning()) 662 | updateThread.start(); 663 | if(onlyBackground) 664 | return; 665 | emit updateLayer(); 666 | /* 667 | * 更新完视图,保存当前视图到数据库 668 | * 本来要退出的时候再保存的,但是发在手机上没用 669 | * */ 670 | sqlExcute.updateDefaultLoaction(centerPos,currentLevel); 671 | } 672 | 673 | void ILong::newImage() 674 | { 675 | viewport()->update(); 676 | } 677 | 678 | void ILong::updateTilesCount(int count) 679 | { 680 | tilesCount = count; 681 | viewport()->update(); 682 | } 683 | 684 | void ILong::updateLocationPos(QPointF world) 685 | { 686 | currentPos = world; 687 | viewport()->update(); 688 | } 689 | 690 | void ILong::updateInfo(QPointF GPSPos, qreal speed, qreal dir, qreal altitude) 691 | { 692 | GPSSpeed = speed; 693 | /* 694 | * 如果有GPS,第一次更新应该要自己跳到GPS位置,不管地图是啥等级 695 | * */ 696 | if(!hasGps) 697 | { 698 | hasGps = true; 699 | zoomTo(GPSPos,zoomLevel()); 700 | } 701 | GPSDir = dir; 702 | currentPos = GPSPos; 703 | GPSLocation = GPSPos; 704 | /* 705 | * 因为如果有GPS的话界面打印出来的应该是GPS位置坐标,没有GPS就打印界面中心点位置坐标 706 | * GPS位置要覆盖中心坐标,也覆盖默认位置坐标,在没有GPS设备上跳转到设置好的默认位置,有GPS就跳到GPS位置 707 | * */ 708 | defaultLocation = GPSPos; 709 | centerPos = GPSPos; 710 | 711 | GPSAltitude = altitude; 712 | manager->addTempItem(GPSPos); 713 | } 714 | 715 | void ILong::updateSatellitesCount(int count) 716 | { 717 | satellitesCount = count; 718 | } 719 | 720 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /ilong.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {22cffa64-bc00-4fcb-ad32-bbbb0043c96a} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 1 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.7.0 GCC 64bit 63 | Desktop Qt 5.7.0 GCC 64bit 64 | qt.57.gcc_64_kit 65 | 1 66 | 0 67 | 0 68 | 69 | /home/long/CodeX/ILONGPROJECT/build-ilong-Desktop_Qt_5_7_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 | Build 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 | Clean 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/CodeX/ILONGPROJECT/build-ilong-Desktop_Qt_5_7_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 | Build 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 | Clean 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/CodeX/ILONGPROJECT/build-ilong-Desktop_Qt_5_7_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 | Build 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 | Clean 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 | Deploy 253 | 254 | ProjectExplorer.BuildSteps.Deploy 255 | 256 | 1 257 | Deploy locally 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.7.0) 325 | Android for armeabi-v7a (GCC 4.9, Qt 5.7.0) 326 | {3f3c527b-3dd0-4614-bb47-c1711e5900ab} 327 | 1 328 | 0 329 | 0 330 | 331 | /home/long/CodeX/ILONGPROJECT/build-ilong-Android_for_armeabi_v7a_GCC_4_9_Qt_5_7_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 | true 372 | false 373 | 374 | 4 375 | Build 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 | Clean 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/CodeX/ILONGPROJECT/build-ilong-Android_for_armeabi_v7a_GCC_4_9_Qt_5_7_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 | true 449 | false 450 | 451 | 4 452 | Build 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 | Clean 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/CodeX/ILONGPROJECT/build-ilong-Android_for_armeabi_v7a_GCC_4_9_Qt_5_7_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 | true 526 | false 527 | 528 | 4 529 | Build 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 | Clean 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 | Deploy 573 | 574 | ProjectExplorer.BuildSteps.Deploy 575 | 576 | 1 577 | Deploy to Android device 578 | Deploy to Android device 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 | ilong 624 | 625 | Qt4ProjectManager.AndroidRunConfiguration:/home/long/CodeX/ILONGPROJECT/ilong/ilong.pro 626 | ilong.pro 627 | 3768 628 | false 629 | true 630 | false 631 | false 632 | true 633 | 634 | 1 635 | 636 | 637 | 638 | ProjectExplorer.Project.TargetCount 639 | 2 640 | 641 | 642 | ProjectExplorer.Project.Updater.FileVersion 643 | 18 644 | 645 | 646 | Version 647 | 18 648 | 649 | 650 | --------------------------------------------------------------------------------