Rev 391 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
305 | 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 LAYERMANAGER_H |
||
27 | #define LAYERMANAGER_H |
||
28 | |||
29 | #include <QObject> |
||
30 | #include <QMap> |
||
31 | #include <QListIterator> |
||
32 | #include "layer.h" |
||
33 | #include "mapadapter.h" |
||
34 | #include "mapcontrol.h" |
||
35 | |||
36 | namespace qmapcontrol |
||
37 | { |
||
38 | class Layer; |
||
39 | class MapAdapter; |
||
40 | class MapControl; |
||
41 | |||
42 | class LayerManager; |
||
43 | |||
44 | //! Handles Layers and viewport related settings |
||
45 | /*! |
||
46 | * This class handles internally all layers which were added to the MapControl. |
||
47 | * It also stores values for scrolling. |
||
48 | * It initiates the creation of a new offscreen image and on zooming the zoom images gets here created. |
||
49 | * @author Kai Winter <kaiwinter@gmx.de> |
||
50 | */ |
||
51 | class LayerManager : public QObject |
||
52 | { |
||
53 | Q_OBJECT |
||
54 | |||
55 | public: |
||
56 | LayerManager(MapControl*, QSize); |
||
57 | ~LayerManager(); |
||
58 | |||
59 | //! returns the coordinate of the center of the map |
||
60 | /*! |
||
61 | * @return returns the coordinate of the middle of the screen |
||
62 | */ |
||
63 | QPointF currentCoordinate() const; |
||
64 | |||
65 | //! returns the current offscreen image |
||
66 | /*! |
||
67 | * @return the current offscreen image |
||
68 | */ |
||
69 | QPixmap getImage() const; |
||
70 | |||
71 | //! returns the layer with the given name |
||
72 | /*! |
||
73 | * @param layername name of the wanted layer |
||
74 | * @return the layer with the given name |
||
75 | */ |
||
76 | Layer* layer(const QString&) const; |
||
77 | |||
78 | //! returns the base layer |
||
79 | /*! |
||
80 | * This will return the base layer of the LayerManager. |
||
81 | * The base layer is the one which is used to do internal coordinate calculations. |
||
82 | * @return the base layer |
||
83 | */ |
||
84 | Layer* layer() const; |
||
85 | |||
86 | //! returns the names of all layers |
||
87 | /*! |
||
88 | * @return returns a QList with the names of all layers |
||
89 | */ |
||
90 | QList<QString> layers() const; |
||
91 | |||
92 | //! sets the middle of the map to the given coordinate |
||
93 | /*! |
||
94 | * @param coordinate the coordinate which the view´s middle should be set to |
||
95 | */ |
||
96 | void setView(const QPointF& coordinate); |
||
97 | |||
98 | //! sets the view, so all coordinates are visible |
||
99 | /*! |
||
100 | * @param coordinates the Coorinates which should be visible |
||
101 | */ |
||
102 | void setView(const QList<QPointF> coordinates); |
||
103 | |||
104 | //! sets the view and zooms in, so all coordinates are visible |
||
105 | /*! |
||
106 | * The code of setting the view to multiple coordinates is "brute force" and pretty slow. |
||
107 | * Have to be reworked. |
||
108 | * @param coordinates the Coorinates which should be visible |
||
109 | */ |
||
110 | void setViewAndZoomIn (const QList<QPointF> coordinates); |
||
111 | |||
112 | //! zooms in one step |
||
113 | void zoomIn(); |
||
114 | |||
115 | //! zooms out one step |
||
116 | void zoomOut(); |
||
117 | |||
118 | //! sets the given zoomlevel |
||
119 | /*! |
||
120 | * @param zoomlevel the zoomlevel |
||
121 | */ |
||
122 | void setZoom(int zoomlevel); |
||
123 | |||
124 | //! The Viewport of the display |
||
125 | /*! |
||
126 | * Returns the visible viewport in world coordinates |
||
127 | * @return the visible viewport in world coordinates |
||
128 | */ |
||
129 | QRectF getViewport() const; |
||
130 | |||
131 | //! scrolls the view |
||
132 | /*! |
||
133 | * Scrolls the view by the given value in pixels and in display coordinates |
||
134 | * @param offset the distance which the view should be scrolled |
||
135 | */ |
||
136 | void scrollView(const QPoint& offset); |
||
137 | |||
138 | //! forwards mouseevents to the layers |
||
139 | /*! |
||
140 | * This method is invoked by the MapControl which receives Mouse Events. |
||
141 | * These events are forwarded to the layers, so they can check for clicked geometries. |
||
142 | * @param evnt the mouse event |
||
143 | */ |
||
144 | void mouseEvent(const QMouseEvent* evnt); |
||
145 | |||
146 | //! returns the middle of the map in projection coordinates |
||
147 | /*! |
||
148 | * |
||
149 | * @return the middle of the map in projection coordinates |
||
150 | */ |
||
151 | QPoint getMapmiddle_px() const; |
||
152 | |||
153 | void forceRedraw(); |
||
154 | void removeZoomImage(); |
||
155 | |||
156 | //! adds a layer |
||
157 | /*! |
||
158 | * If multiple layers are added, they are painted in the added order. |
||
159 | * @param layer the layer which should be added |
||
160 | */ |
||
161 | void addLayer(Layer* layer); |
||
162 | |||
163 | //! returns the current zoom level |
||
164 | /*! |
||
165 | * @return returns the current zoom level |
||
166 | */ |
||
167 | int currentZoom() const; |
||
168 | |||
169 | void drawGeoms(QPainter* painter); |
||
170 | void drawImage(QPainter* painter); |
||
171 | |||
172 | private: |
||
173 | LayerManager& operator=(const LayerManager& rhs); |
||
174 | LayerManager(const LayerManager& old); |
||
175 | //! This method have to be invoked to draw a new offscreen image |
||
176 | /*! |
||
177 | * @param clearImage if the current offscreeen image should be cleared |
||
178 | * @param showZoomImage if a zoom image should be painted |
||
179 | */ |
||
180 | void newOffscreenImage(bool clearImage=true, bool showZoomImage=true); |
||
181 | inline bool checkOffscreen() const; |
||
182 | inline bool containsAll(QList<QPointF> coordinates) const; |
||
183 | inline void moveWidgets(); |
||
184 | inline void setMiddle(QList<QPointF> coordinates); |
||
185 | |||
186 | MapControl* mapcontrol; |
||
187 | QPoint screenmiddle; // middle of the screen |
||
188 | QPoint scroll; // scrollvalue of the offscreen image |
||
189 | QPoint zoomImageScroll; // scrollvalue of the zoom image |
||
190 | |||
191 | QSize size; // widget size |
||
192 | QSize offSize; // size of the offscreen image |
||
193 | |||
194 | QPixmap composedOffscreenImage; |
||
195 | QPixmap composedOffscreenImage2; |
||
196 | QPixmap zoomImage; |
||
197 | |||
198 | QList<Layer*> mylayers; |
||
199 | |||
200 | QPoint mapmiddle_px; // projection-display coordinates |
||
201 | QPointF mapmiddle; // world coordinate |
||
202 | |||
203 | QMutex scrollMutex; |
||
204 | QPoint whilenewscroll; |
||
205 | mutable QMutex refreshMutex; |
||
206 | |||
207 | public slots: |
||
208 | void updateRequest(QRectF rect); |
||
209 | void updateRequest(); |
||
210 | void resize(QSize newSize); |
||
211 | }; |
||
212 | } |
||
213 | #endif |