⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maps.h

📁 给予QT的qps开源最新源码
💻 H
字号:
/*
   qpegps is a program for displaying a map centered at the current longitude/
   latitude as read from a gps receiver.

   Copyright (C) 2002 Ralf Haselmeier <Ralf.Haselmeier@gmx.de>

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 */

#ifndef MAPS_H
#define MAPS_H

#include <qsocket.h>
#include <qvbox.h>
#include <qhbox.h>
#include <qtextview.h>
#include <qlineedit.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qtextstream.h>
#include <qtimer.h>
#include <qpixmap.h>
#include <qpainter.h>
#include <qfileinfo.h>
#include <qdir.h>
#include <qmap.h> 
#include <qsortedlist.h>
#include <qimage.h>
#include <qvector.h>
#include <math.h>
#include <stdlib.h>

#include "qpegps.h"
#include "gpsdata.h"

class MapSelector;

class MapBase : public QObject
{
   Q_OBJECT

   // ----- METHODS -----
   public:
      MapBase(QString & mapInfo, const QString &subdir = "");
      MapBase();
      ~MapBase();

      static MapBase* newMap(QString &mapType, QString &mapInfo, const QString &subdir = "");

      int operator==(MapBase&);
      int operator<(MapBase&);
      int operator>(MapBase&);

      // lg,lt in RAD !!!
      virtual bool calcxy(double * x, double * y, const Position & pos) =  0;
      virtual bool calcPos(Position & pos, double x, double y) =  0;
	  
	   virtual void draw(QPixmap *viewer, const Position & pos)=0;
	   virtual void addTrack(Track *track, QColor &color, int size)=0;

      bool isInside(const Position & pos);
      double coverage(double x, double y, int width, int height);
      virtual QString getParameterStr() = 0;
      virtual QString getInfo() = 0;
      QString name();

   // ----- MEMBERS -----
   public:
      QString projection;
      double scale;
      int mapSizeX, mapSizeY;
      Position limitNorthWest;
      Position limitSouthEast;

      static MapSelector *mapSelector;
 protected:
      QString mapDir;
      QString mapName;

      friend class MapSelector;
};

class MapImage : public MapBase
{
    Q_OBJECT

   // ----- METHODS -----
   public:
      MapImage(QString & mapInfo,const QString &subdir = "");
      MapImage();
      ~MapImage();


      bool load();
	   void unload();
	   void draw(QPixmap *viewer, const Position &pos);
	   void addTrack(Track *track, QColor &color, int size);

   protected:
      void setLimits();

   // ----- MEMBERS -----
   public:
      QPixmap *pixmap;
};

class MapLin : public MapImage
{
   Q_OBJECT

   // ----- METHODS -----
   public:
      MapLin(QString & mapInfo, const QString &subdir = "");
      MapLin() : MapImage() { projection = "LINEAR"; }
      ~MapLin() {}

      bool calcxy(double * x, double * y, const Position & pos);
      bool calcPos(Position & pos, double x, double y);
      QString getInfo();
      QString getParameterStr();

   // ----- MEMBERS -----
   public:
      Position pos1, pos2;
      int	x1, y1;
      int	x2, y2;
};

class MapCEA : public MapImage
{
   Q_OBJECT

   // ----- METHODS -----
   public:
      MapCEA(QString & mapInfo, const QString &subdir = "");
      MapCEA() : MapImage() { projection = "CEA"; }
      ~MapCEA() {}

      bool calcxy(double * x, double * y, const Position & pos);
      bool calcPos(Position & pos, double x, double y);
      QString getInfo();
      QString getParameterStr();

   // ---- MEMBERS -----
   public:
      int	x1, y1;
      int	x2, y2;

   private:
      double xlon1, ylat1, xlon2, ylat2;
};

class MapUTM : public MapImage
{
   Q_OBJECT

   // ----- METHODS -----
   public:
      MapUTM(QString & mapInfo, bool, const QString &subdir = "");
      MapUTM(bool);
      ~MapUTM() {}

      bool calcxy(double * x, double * y, const Position & pos);
      bool calcPos(Position & pos, double x, double y);
      QString getInfo();
      QString getParameterStr();

      void UTMtoLL(double UTMNorthing, double UTMEasting,
            QString UTMZone, Position & pos, double & stdLon );

   // ----- MEMBERS -----
   public:
      int	x1, y1;
      int	x2, y2;
      QString utmZone;
      double utmNorthing1, utmEasting1, utmNorthing2, utmEasting2;
      double stdLon;

   private:
      double xlon1, ylat1, xlon2, ylat2;
      bool universal;
};

class MapMercator : public MapImage
{
   Q_OBJECT

   // ----- METHODS -----
   public:
      MapMercator(QString & mapInfo, const QString &subdir = "");
      MapMercator() : MapImage() { projection = "MERCATOR"; }
      ~MapMercator() {}

      bool calcxy(double * x, double * y, const Position & pos);
      bool calcPos(Position & pos, double x, double y);
      QString getInfo();
      QString getParameterStr();

   // ----- MEMBERS -----
   public:
      int	x1, y1;
      int	x2, y2;

   private:
      double xlon1, ylat1, xlon2, ylat2;
};

class MapLambert : public MapImage
{
   Q_OBJECT

   // ----- METHODS -----
   public:
      MapLambert(QString & mapInfo, const QString &subdir = "");
      MapLambert() : MapImage() { projection = "LAMBERT"; }
      ~MapLambert() {}

      bool calcxy(double * x, double * y, const Position & pos);
      bool calcPos(Position & pos, double x, double y);
      QString getInfo();
      QString getParameterStr();

   // ----- MEMBERS -----
   public:
      int	x1, y1;
      int	x2, y2;
      double std1Lat;
      double std2Lat;
      double refLon;

   private:
      double F, p0;
      double xlon1, ylat1, xlon2, ylat2;
      double n;
      double n_sign;
};


#define PIXELFACT 2817.947378

class MapFritz : public MapImage
{
   Q_OBJECT

   // ----- METHODS -----
   public:
      MapFritz(QString & mapInfo, const QString &subdir = "");
      MapFritz() : MapImage() { projection = "FRITZ"; }
      ~MapFritz() {}

      bool calcxy(double * x, double * y, const Position & pos);
      bool calcPos(Position & pos, double x, double y);
      QString getInfo();
      QString getParameterStr();

      double calcR(double lat);

   // ----- MEMBERS -----
   public:
      int mapSizeX2;
      int mapSizeY2;
      Position center;

   private:
      static double Ra[201];
      Position zero;
      double pixelfact;
};

class QMapVector : public QVector<MapBase>
{
   // ----- METHODS -----
   public:
    int	 compareItems( Item s1, Item s2 );
//    virtual int compareItems ( MapBase *d1, MapBase *d2 );
};


class MapTiled : public MapBase
{
    Q_OBJECT

   // ----- METHODS -----
   public:
      MapTiled(QString & mapInfo, const QString &subdir = "");
      MapTiled() : MapBase() { projection = "TILED"; }
      ~MapTiled();

      bool calcxy(double * x, double * y, const Position & pos);
      bool calcPos(Position & pos, double x, double y);
      QString getInfo();
      QString getParameterStr();

	   void draw(QPixmap *viewer, const Position &pos);
      void addTrack(Track *, QColor &, int){}; // nothing to do

  // ----- MEMBERS -----
   public:
      int tileSizeX;
      int tileSizeY;
      QMapVector maps;
      QArray<int> mapLimitsX;
      QArray<int> mapLimitsY;
};


class MapSelector : public QObject
{
    Q_OBJECT

   // ----- METHODS -----
   public:
      MapSelector(Qpegps *app/*, QString *mapPath*/);
	   ~MapSelector();
	 
      void writeMapFile();
      void clearMaps();
      void drawMap(QPixmap *viewer, const Position & pos);
      bool canLessDetail() { return (actMap && actMap->scale < actMapList.last()->scale); };
      bool canMoreDetail() { return (actMap && actMap->scale > actMapList.first()->scale); };
      double scale() const { return (selectedScale); };
      bool isMap() const { return actMap!=NULL; };
      MapBase *currentMap() const { return actMap; };

      MapBase *find(QString &mapName);
      MapBase *first() { return maps.first(); };
      MapBase *next() { return maps.next(); };
      MapBase *at(uint i) { return maps.at(i); };

      void addMap(MapBase *newmap){ maps.append(newmap); };
      void delMap(uint i){ maps.remove(i); };
      void delMap(MapBase *delmap);;

      void readMaps(const QString &subdir = "");
      bool searchMap(const Position & pos/*, int maxMaps*/);
      void selectMap(const Position & pos, QRect rect);
      bool loadMapImage(MapImage *map);
      inline QString &mapPathStr() {return mapOptions.mapPathStr;}

   public slots:
      void reReadMaps();
      void chooseLessDetailedMap();
      void chooseMoreDetailedMap();
      void showAvailableMaps();
      void clearMapsLoaded();
      void updateMapsLoaded();

   // ----- MEMBERS -----
   public:
      MapOptions mapOptions;

   protected:
      Qpegps *application;				
      MapBase *actMap;					// actual map
      QImage *currentMapImg;
      QImage *tempImg;
      QSortedList<MapBase> maps;			// whole maps list
      QSortedList<MapBase> actMapList;	// maps covering the current position
      QMap<MapImage *,int> mapsLoaded;  // list of maps loaded (image maps)
      double selectedScale;
      QTimer *timer;

   signals:
      void mapsChanged();
};

#endif // MAPS_H

// end of file

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -