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