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