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.

221 lines
7.4 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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 LAYER_H
  26. #define LAYER_H
  27. #include "qmapcontrol_global.h"
  28. #include <QtCore/QObject>
  29. #include <QtCore/QDebug>
  30. #include <QtGui/QPainter>
  31. #include <QtGui/QMouseEvent>
  32. #include "mapadapter.h"
  33. //#include "layermanager.h"
  34. //#include "imagemanager.h"
  35. #include "geometry.h"
  36. #include "point.h"
  37. #include "wmsmapadapter.h"
  38. #include "tilemapadapter.h"
  39. class ImageManager;
  40. class LayerManager;
  41. //! Layer class
  42. /*!
  43. * There are two different layer types:
  44. * - MapLayer: Displays Maps, but also Geometries. The configuration for displaying maps have to be done in the MapAdapter
  45. * - GeometryLayer: Only displays Geometry objects.
  46. *
  47. * MapLayers also can display Geometry objects. The difference to the GeometryLayer is the repainting. Objects that are
  48. * added to a MapLayer are "baken" on the map. This means, when you change it´s position for example the changes are
  49. * not visible until a new offscreen image has been drawn. If you have "static" Geometries which won´t change their
  50. * position this is fine. But if you want to change the objects position or pen you should use a GeometryLayer. Those
  51. * are repainted immediately on changes.
  52. * You can either use this class and give a layertype on creation or you can use the classes MapLayer and GeometryLayer.
  53. *
  54. * @author Kai Winter <kaiwinter@gmx.de>
  55. */
  56. class Layer : public QObject {
  57. //Q_OBJECT
  58. public:
  59. friend class LayerManager;
  60. //! sets the type of a layer, see Layer class doc for further information
  61. enum LayerType
  62. {
  63. MapLayer, /*!< uses the MapAdapter to display maps, only gets refreshed when a new offscreen image is needed */
  64. GeometryLayer /*!< gets refreshed everytime when a geometry changes */
  65. };
  66. //! Layer default constructor
  67. /*!
  68. * This is used to construct a layer.
  69. */
  70. Layer();
  71. //! Layer constructor
  72. /*!
  73. * This is used to construct a layer.
  74. *
  75. * @param layername The name of the Layer
  76. * @param mapadapter The MapAdapter which does coordinate translation and Query-String-Forming
  77. * @param layertype The above explained LayerType
  78. * @param takeevents Should the Layer receive MouseEvents? This is set to true by default. Setting it to false could
  79. * be something like a "speed up hint"
  80. */
  81. Layer(QString layername, MapAdapter* mapadapter, enum LayerType layertype, bool takeevents=true);
  82. virtual ~Layer();
  83. //! returns the layer's name
  84. /*!
  85. * @return the name of this layer
  86. */
  87. QString layername() const;
  88. //! returns the layer´s MapAdapter
  89. /*!
  90. * This method returns the MapAdapter of this Layer, which can be useful
  91. * to do coordinate transformations.
  92. * @return the MapAdapter which us used by this Layer
  93. */
  94. MapAdapter* mapadapter();
  95. //! adds a Geometry object to this Layer
  96. /*!
  97. * Please notice the different LayerTypes (MapLayer and GeometryLayer) and the differences
  98. * @param geometry the new Geometry
  99. */
  100. void addGeometry(Geometry* geometry);
  101. //! removes the Geometry object from this Layer
  102. /*!
  103. * This method removes a Geometry object from this Layer.
  104. * NOTE: this method does not delete the object unless qDeleteObject is set
  105. * @param qDeleteObject cleans up memory of object after removal
  106. */
  107. void removeGeometry(Geometry* geometry, bool qDeleteObject = false);
  108. //! removes all Geometry objects from this Layer
  109. /*!
  110. * This method removes all Geometry objects from this Layer.
  111. * NOTE: this method does not delete the object unless qDeleteObject is set
  112. * @param qDeleteObject cleans up memory of object after removal
  113. */
  114. void clearGeometries( bool qDeleteObject = false);
  115. //! returns all Geometry objects from this Layer
  116. /*!
  117. * This method removes all Geometry objects from this Layer.
  118. * @return a list of geometries that are on this Layer
  119. */
  120. QList<Geometry*>& getGeometries();
  121. //! returns true if Layer contains geometry
  122. /*!
  123. * This method returns if a Geometry objects is on this Layer.
  124. */
  125. bool containsGeometry( Geometry* geometry );
  126. //! allow moving a geometry to the top of the list (drawing last)
  127. /*!
  128. * This method re-order the Geometry objects so the desired
  129. * geometry is drawn last and visible above all geometries
  130. */
  131. void sendGeometryToFront( Geometry* geometry );
  132. //! allow moving a geometry to the top of the list (drawing last)
  133. /*!
  134. * This method re-order the Geometry objects so the desired
  135. * geometry is drawn first and under all other geometries
  136. */
  137. void sendGeometryToBack( Geometry* geometry );
  138. //! return true if the layer is visible
  139. /*!
  140. * @return if the layer is visible
  141. */
  142. bool isVisible() const;
  143. //! returns the LayerType of the Layer
  144. /*!
  145. * There are two LayerTypes: MapLayer and GeometryLayer
  146. * @return the LayerType of this Layer
  147. */
  148. Layer::LayerType layertype() const;
  149. void setMapAdapter(MapAdapter* mapadapter);
  150. void setImageManager(ImageManager* qImageManager);
  151. private:
  152. void moveWidgets(const QPoint mapmiddle_px) const;
  153. void drawYourImage(QPainter* painter, const QPoint mapmiddle_px) const;
  154. void drawYourGeometries(QPainter* painter, const QPoint mapmiddle_px, QRect viewport) const;
  155. void setSize(QSize size);
  156. QRect offscreenViewport() const;
  157. bool takesMouseEvents() const;
  158. void mouseEvent(const QMouseEvent*, const QPoint mapmiddle_px);
  159. void zoomIn() const;
  160. void zoomOut() const;
  161. void _draw(QPainter* painter, const QPoint mapmiddle_px) const;
  162. bool visible;
  163. QString mylayername;
  164. LayerType mylayertype;
  165. QSize size;
  166. QPoint screenmiddle;
  167. QList<Geometry*> geometries;
  168. MapAdapter* mapAdapter;
  169. bool takeevents;
  170. mutable QRect myoffscreenViewport;
  171. ImageManager* m_ImageManager;
  172. signals:
  173. //! This signal is emitted when a Geometry is clicked
  174. /*!
  175. * A Geometry is clickable, if the containing layer is clickable.
  176. * The layer emits a signal for every clicked geometry
  177. * @param geometry The clicked Geometry
  178. * @param point The coordinate (in widget coordinates) of the click
  179. */
  180. void geometryClicked(Geometry* geometry, QPoint point);
  181. void updateRequest(QRectF rect);
  182. void updateRequest();
  183. public slots:
  184. //! if visible is true, the layer is made visible
  185. /*!
  186. * @param visible if the layer should be visible
  187. */
  188. void setVisible(bool visible);
  189. };
  190. #endif