You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

249 lines
7.0 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. *
  3. * This file is part of QMapControl,
  4. * an open-source cross-platform map widget
  5. *
  6. * Copyright (C) 2007 - 2008 Kai Winter
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * Contact e-mail: kaiwinter@gmx.de
  22. * Program URL : http://qmapcontrol.sourceforge.net/
  23. *
  24. */
  25. #ifndef LAYERMANAGER_H
  26. #define LAYERMANAGER_H
  27. #include "qmapcontrol_global.h"
  28. #include <QtCore/QObject>
  29. #include <QtCore/QMap>
  30. #include <QtCore/QListIterator>
  31. #include <QtCore/QRectF>
  32. #include "layer.h"
  33. #include "mapadapter.h"
  34. //#include "mapcontrol.h"
  35. class MapControl;
  36. //! Handles Layers and viewport related settings
  37. /*!
  38. * This class handles internally all layers which were added to the MapControl.
  39. * It also stores values for scrolling.
  40. * It initiates the creation of a new offscreen image and on zooming the zoom images gets here created.
  41. * @author Kai Winter <kaiwinter@gmx.de>
  42. */
  43. class LayerManager : public QObject {
  44. // Q_OBJECT
  45. public:
  46. LayerManager(QWidget*, QSize);
  47. ~LayerManager();
  48. //! returns the coordinate of the center of the map
  49. /*!
  50. * @return returns the coordinate of the middle of the screen
  51. */
  52. QPointF currentCoordinate() const;
  53. //! returns the current offscreen image
  54. /*!
  55. * @return the current offscreen image
  56. */
  57. QPixmap getImage() const;
  58. //! returns the layer with the given name
  59. /*!
  60. * @param layername name of the wanted layer
  61. * @return the layer with the given name
  62. */
  63. Layer* layer(const QString&) const;
  64. //! returns the base layer
  65. /*!
  66. * This will return the base layer of the LayerManager.
  67. * The base layer is the one which is used to do internal coordinate calculations.
  68. * @return the base layer
  69. */
  70. Layer* layer() const;
  71. //! returns the names of all layers
  72. /*!
  73. * @return returns a QList with the names of all layers
  74. */
  75. QList<QString> layers() const;
  76. //! sets the middle of the map to the given coordinate
  77. /*!
  78. * @param coordinate the coordinate which the view´s middle should be set to
  79. */
  80. void setView(const QPointF& coordinate);
  81. //! sets the view, so all coordinates are visible
  82. /*!
  83. * @param coordinates the Coorinates which should be visible
  84. */
  85. void setView(const QList<QPointF> coordinates);
  86. //! sets the view and zooms in, so all coordinates are visible
  87. /*!
  88. * The code of setting the view to multiple coordinates is "brute force" and pretty slow.
  89. * Have to be reworked.
  90. * @param coordinates the Coorinates which should be visible
  91. */
  92. void setViewAndZoomIn (const QList<QPointF> coordinates);
  93. //! zooms in one step
  94. void zoomIn();
  95. //! zooms out one step
  96. void zoomOut();
  97. //! return min Zoom Level
  98. int minZoom();
  99. //! return max Zoom Level
  100. int maxZoom();
  101. //! sets the given zoomlevel
  102. /*!
  103. * @param zoomlevel the zoomlevel
  104. */
  105. void setZoom(int zoomlevel);
  106. //! The Viewport of the display
  107. /*!
  108. * Returns the visible viewport in world coordinates
  109. * @return the visible viewport in world coordinates
  110. */
  111. QRectF getViewport() const;
  112. //! scrolls the view
  113. /*!
  114. * Scrolls the view by the given value in pixels and in display coordinates
  115. * @param offset the distance which the view should be scrolled
  116. */
  117. void scrollView(const QPoint& offset);
  118. //! forwards mouseevents to the layers
  119. /*!
  120. * This method is invoked by the MapControl which receives Mouse Events.
  121. * These events are forwarded to the layers, so they can check for clicked geometries.
  122. * @param evnt the mouse event
  123. */
  124. void mouseEvent(const QMouseEvent* evnt);
  125. //! returns the middle of the map in projection coordinates
  126. /*!
  127. *
  128. * @return the middle of the map in projection coordinates
  129. */
  130. QPoint getMapmiddle_px() const;
  131. void forceRedraw();
  132. void removeZoomImage();
  133. //! adds a layer
  134. /*!
  135. * If multiple layers are added, they are painted in the added order.
  136. * @param layer the layer which should be added
  137. */
  138. void addLayer(Layer* layer);
  139. //! removes a layer
  140. /*!
  141. * Removes a layer and redraws existing layers
  142. * @param layer the layer which should be removed
  143. */
  144. void removeLayer( Layer* layer );
  145. //! returns the current zoom level
  146. /*!
  147. * @return returns the current zoom level
  148. */
  149. int currentZoom() const;
  150. void drawGeoms(QPainter* painter);
  151. void drawImage(QPainter* painter);
  152. //! Set whether to enable a view bounding box
  153. /*!
  154. *
  155. * @param usebounds enable/disable use of bounding box
  156. */
  157. void setUseBoundingBox( bool usebounds );
  158. //! Check if bounding box is being used
  159. /*!
  160. *
  161. * @return if bounding box is being used
  162. */
  163. bool isBoundingBoxEnabled();
  164. //! Set constraints for bounding box
  165. /*!
  166. *
  167. * @param rect specified bounds for view to stay within
  168. */
  169. void setBoundingBox( QRectF &rect );
  170. //! Get current bounding box
  171. /*!
  172. *
  173. * @return bounding box
  174. */
  175. QRectF getBoundingBox();
  176. private:
  177. LayerManager& operator=(const LayerManager& rhs);
  178. LayerManager(const LayerManager& old);
  179. //! This method have to be invoked to draw a new offscreen image
  180. /*!
  181. * @param clearImage if the current offscreeen image should be cleared
  182. * @param showZoomImage if a zoom image should be painted
  183. */
  184. void newOffscreenImage(bool clearImage=true, bool showZoomImage=true);
  185. inline bool checkOffscreen() const;
  186. inline bool containsAll(QList<QPointF> coordinates) const;
  187. inline void moveWidgets();
  188. inline void setMiddle(QList<QPointF> coordinates);
  189. QWidget* mapcontrol;
  190. QPoint screenmiddle; // middle of the screen
  191. QPoint scroll; // scrollvalue of the offscreen image
  192. QPoint zoomImageScroll; // scrollvalue of the zoom image
  193. QSize size; // widget size
  194. QSize offSize; // size of the offscreen image
  195. QPixmap composedOffscreenImage;
  196. QPixmap zoomImage;
  197. QList<Layer*> mylayers;
  198. QPoint mapmiddle_px; // projection-display coordinates
  199. QPointF mapmiddle; // world coordinate
  200. QPoint whilenewscroll;
  201. QRectF boundingBox; // limit viewing area if desired
  202. bool useBoundingBox;
  203. public slots:
  204. void updateRequest(QRectF rect);
  205. void updateRequest();
  206. void resize(QSize newSize);
  207. };
  208. #endif