1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2015 The Qt Company Ltd. |
4 | ** Contact: http://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtLocation module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at http://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or later as published by the Free |
28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
29 | ** the packaging of this file. Please review the following information to |
30 | ** ensure the GNU General Public License version 2.0 requirements will be |
31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
32 | ** |
33 | ** $QT_END_LICENSE$ |
34 | ** |
35 | ****************************************************************************/ |
36 | |
37 | #ifndef QDECLARATIVEGEOMAP_H |
38 | #define QDECLARATIVEGEOMAP_H |
39 | |
40 | // |
41 | // W A R N I N G |
42 | // ------------- |
43 | // |
44 | // This file is not part of the Qt API. It exists purely as an |
45 | // implementation detail. This header file may change from version to |
46 | // version without notice, or even be removed. |
47 | // |
48 | // We mean it. |
49 | // |
50 | |
51 | #include <QtLocation/private/qlocationglobal_p.h> |
52 | #include <QtLocation/private/qdeclarativegeomapitemview_p.h> |
53 | #include <QtLocation/private/qquickgeomapgesturearea_p.h> |
54 | #include <QtLocation/private/qdeclarativegeomapitemgroup_p.h> |
55 | #include <QtLocation/qgeoserviceprovider.h> |
56 | #include <QtLocation/private/qgeocameradata_p.h> |
57 | #include <QtLocation/private/qgeocameracapabilities_p.h> |
58 | #include <QtQuick/QQuickItem> |
59 | #include <QtCore/QList> |
60 | #include <QtCore/QPointer> |
61 | #include <QtGui/QColor> |
62 | #include <QtPositioning/qgeorectangle.h> |
63 | #include <QtLocation/private/qgeomap_p.h> |
64 | #include <QtQuick/private/qquickitemchangelistener_p.h> |
65 | |
66 | QT_BEGIN_NAMESPACE |
67 | |
68 | class QDeclarativeGeoServiceProvider; |
69 | class QDeclarativeGeoMapType; |
70 | class QDeclarativeGeoMapCopyrightNotice; |
71 | class QDeclarativeGeoMapParameter; |
72 | |
73 | class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoMap : public QQuickItem |
74 | { |
75 | Q_OBJECT |
76 | Q_ENUMS(QGeoServiceProvider::Error) |
77 | Q_PROPERTY(QQuickGeoMapGestureArea *gesture READ gesture CONSTANT) |
78 | Q_PROPERTY(QDeclarativeGeoServiceProvider *plugin READ plugin WRITE setPlugin NOTIFY pluginChanged) |
79 | Q_PROPERTY(qreal minimumZoomLevel READ minimumZoomLevel WRITE setMinimumZoomLevel NOTIFY minimumZoomLevelChanged) |
80 | Q_PROPERTY(qreal maximumZoomLevel READ maximumZoomLevel WRITE setMaximumZoomLevel NOTIFY maximumZoomLevelChanged) |
81 | Q_PROPERTY(qreal zoomLevel READ zoomLevel WRITE setZoomLevel NOTIFY zoomLevelChanged) |
82 | |
83 | Q_PROPERTY(qreal tilt READ tilt WRITE setTilt NOTIFY tiltChanged) |
84 | Q_PROPERTY(qreal minimumTilt READ minimumTilt WRITE setMinimumTilt NOTIFY minimumTiltChanged) |
85 | Q_PROPERTY(qreal maximumTilt READ maximumTilt WRITE setMaximumTilt NOTIFY maximumTiltChanged) |
86 | |
87 | Q_PROPERTY(qreal bearing READ bearing WRITE setBearing NOTIFY bearingChanged) |
88 | |
89 | Q_PROPERTY(qreal fieldOfView READ fieldOfView WRITE setFieldOfView NOTIFY fieldOfViewChanged) |
90 | Q_PROPERTY(qreal minimumFieldOfView READ minimumFieldOfView WRITE setMinimumFieldOfView NOTIFY minimumFieldOfViewChanged) |
91 | Q_PROPERTY(qreal maximumFieldOfView READ maximumFieldOfView WRITE setMaximumFieldOfView NOTIFY minimumFieldOfViewChanged) |
92 | |
93 | Q_PROPERTY(QDeclarativeGeoMapType *activeMapType READ activeMapType WRITE setActiveMapType NOTIFY activeMapTypeChanged) |
94 | Q_PROPERTY(QQmlListProperty<QDeclarativeGeoMapType> supportedMapTypes READ supportedMapTypes NOTIFY supportedMapTypesChanged) |
95 | Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter NOTIFY centerChanged) |
96 | Q_PROPERTY(QList<QObject *> mapItems READ mapItems NOTIFY mapItemsChanged) |
97 | Q_PROPERTY(QList<QObject *> mapParameters READ mapParameters) |
98 | Q_PROPERTY(QGeoServiceProvider::Error error READ error NOTIFY errorChanged) |
99 | Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged) |
100 | Q_PROPERTY(QGeoShape visibleRegion READ visibleRegion WRITE setVisibleRegion NOTIFY visibleRegionChanged) |
101 | Q_PROPERTY(bool copyrightsVisible READ copyrightsVisible WRITE setCopyrightsVisible NOTIFY copyrightsVisibleChanged) |
102 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
103 | Q_PROPERTY(bool mapReady READ mapReady NOTIFY mapReadyChanged) |
104 | Q_PROPERTY(QRectF visibleArea READ visibleArea WRITE setVisibleArea NOTIFY visibleAreaChanged REVISION 12) |
105 | Q_INTERFACES(QQmlParserStatus) |
106 | |
107 | public: |
108 | |
109 | explicit QDeclarativeGeoMap(QQuickItem *parent = 0); |
110 | ~QDeclarativeGeoMap(); |
111 | |
112 | void setPlugin(QDeclarativeGeoServiceProvider *plugin); |
113 | QDeclarativeGeoServiceProvider *plugin() const; |
114 | |
115 | void setActiveMapType(QDeclarativeGeoMapType *mapType); |
116 | QDeclarativeGeoMapType *activeMapType() const; |
117 | |
118 | void setMinimumZoomLevel(qreal minimumZoomLevel, bool userSet = true); |
119 | qreal minimumZoomLevel() const; |
120 | qreal implicitMinimumZoomLevel() const; |
121 | qreal effectiveMinimumZoomLevel() const; |
122 | |
123 | void setMaximumZoomLevel(qreal maximumZoomLevel, bool userSet = true); |
124 | qreal maximumZoomLevel() const; |
125 | |
126 | void setZoomLevel(qreal zoomLevel); |
127 | qreal zoomLevel() const; |
128 | |
129 | void setBearing(qreal bearing); |
130 | qreal bearing() const; |
131 | |
132 | void setTilt(qreal tilt); |
133 | qreal tilt() const; |
134 | void setMinimumTilt(qreal minimumTilt, bool userSet = true); |
135 | qreal minimumTilt() const; |
136 | void setMaximumTilt(qreal maximumTilt, bool userSet = true); |
137 | qreal maximumTilt() const; |
138 | |
139 | void setFieldOfView(qreal fieldOfView); |
140 | qreal fieldOfView() const; |
141 | void setMinimumFieldOfView(qreal minimumFieldOfView, bool userSet = true); |
142 | qreal minimumFieldOfView() const; |
143 | void setMaximumFieldOfView(qreal maximumFieldOfView, bool userSet = true); |
144 | qreal maximumFieldOfView() const; |
145 | |
146 | void setCenter(const QGeoCoordinate ¢er); |
147 | QGeoCoordinate center() const; |
148 | |
149 | void setVisibleRegion(const QGeoShape &shape); |
150 | QGeoShape visibleRegion() const; |
151 | |
152 | void setCopyrightsVisible(bool visible); |
153 | bool copyrightsVisible() const; |
154 | |
155 | void setColor(const QColor &color); |
156 | QColor color() const; |
157 | |
158 | QRectF visibleArea() const; |
159 | void setVisibleArea(const QRectF &visibleArea); |
160 | |
161 | bool mapReady() const; |
162 | |
163 | QQmlListProperty<QDeclarativeGeoMapType> supportedMapTypes(); |
164 | |
165 | Q_INVOKABLE void setBearing(qreal bearing, const QGeoCoordinate &coordinate); |
166 | Q_INVOKABLE void alignCoordinateToPoint(const QGeoCoordinate &coordinate, const QPointF &point); |
167 | |
168 | Q_INVOKABLE void removeMapItem(QDeclarativeGeoMapItemBase *item); |
169 | Q_INVOKABLE void addMapItem(QDeclarativeGeoMapItemBase *item); |
170 | |
171 | Q_INVOKABLE void addMapItemGroup(QDeclarativeGeoMapItemGroup *itemGroup); |
172 | Q_INVOKABLE void removeMapItemGroup(QDeclarativeGeoMapItemGroup *itemGroup); |
173 | |
174 | Q_INVOKABLE void removeMapItemView(QDeclarativeGeoMapItemView *itemView); |
175 | Q_INVOKABLE void addMapItemView(QDeclarativeGeoMapItemView *itemView); |
176 | |
177 | Q_INVOKABLE void clearMapItems(); |
178 | QList<QObject *> mapItems(); |
179 | |
180 | Q_INVOKABLE void addMapParameter(QDeclarativeGeoMapParameter *parameter); |
181 | Q_INVOKABLE void removeMapParameter(QDeclarativeGeoMapParameter *parameter); |
182 | Q_INVOKABLE void clearMapParameters(); |
183 | QList<QObject *> mapParameters(); |
184 | |
185 | void addMapObject(QGeoMapObject *object); // Not invokable as currently meant to be used through a main MapObjectView |
186 | void removeMapObject(QGeoMapObject *object); |
187 | void clearMapObjects(); |
188 | QList<QGeoMapObject *> mapObjects(); |
189 | |
190 | |
191 | Q_INVOKABLE QGeoCoordinate toCoordinate(const QPointF &position, bool clipToViewPort = true) const; |
192 | Q_INVOKABLE QPointF fromCoordinate(const QGeoCoordinate &coordinate, bool clipToViewPort = true) const; |
193 | |
194 | QQuickGeoMapGestureArea *gesture(); |
195 | |
196 | Q_INVOKABLE void fitViewportToMapItems(const QVariantList &items = {}); |
197 | Q_INVOKABLE void fitViewportToVisibleMapItems(); |
198 | Q_INVOKABLE void pan(int dx, int dy); |
199 | Q_INVOKABLE void prefetchData(); // optional hint for prefetch |
200 | Q_INVOKABLE void clearData(); |
201 | Q_REVISION(13) Q_INVOKABLE void fitViewportToGeoShape(const QGeoShape &shape, QVariant margins); |
202 | void fitViewportToGeoShape(const QGeoShape &shape, const QMargins &borders = QMargins(10, 10, 10, 10)); |
203 | |
204 | QString errorString() const; |
205 | QGeoServiceProvider::Error error() const; |
206 | QGeoMap* map() const; |
207 | |
208 | // From QQuickItem |
209 | void itemChange(ItemChange, const ItemChangeData &) override; |
210 | |
211 | Q_SIGNALS: |
212 | void pluginChanged(QDeclarativeGeoServiceProvider *plugin); |
213 | void zoomLevelChanged(qreal zoomLevel); |
214 | void centerChanged(const QGeoCoordinate &coordinate); |
215 | void activeMapTypeChanged(); |
216 | void supportedMapTypesChanged(); |
217 | void minimumZoomLevelChanged(); |
218 | void maximumZoomLevelChanged(); |
219 | void mapItemsChanged(); |
220 | void errorChanged(); |
221 | void copyrightLinkActivated(const QString &link); |
222 | void copyrightsVisibleChanged(bool visible); |
223 | void colorChanged(const QColor &color); |
224 | void bearingChanged(qreal bearing); |
225 | void tiltChanged(qreal tilt); |
226 | void fieldOfViewChanged(qreal fieldOfView); |
227 | void minimumTiltChanged(qreal minimumTilt); |
228 | void maximumTiltChanged(qreal maximumTilt); |
229 | void minimumFieldOfViewChanged(qreal minimumFieldOfView); |
230 | void maximumFieldOfViewChanged(qreal maximumFieldOfView); |
231 | void copyrightsChanged(const QImage ©rightsImage); |
232 | void copyrightsChanged(const QString ©rightsHtml); |
233 | void mapReadyChanged(bool ready); |
234 | Q_REVISION(11) void mapObjectsChanged(); |
235 | void visibleAreaChanged(); |
236 | Q_REVISION(14) void visibleRegionChanged(); |
237 | |
238 | protected: |
239 | void mousePressEvent(QMouseEvent *event) override ; |
240 | void mouseMoveEvent(QMouseEvent *event) override ; |
241 | void mouseReleaseEvent(QMouseEvent *event) override ; |
242 | void mouseUngrabEvent() override ; |
243 | void touchUngrabEvent() override; |
244 | void touchEvent(QTouchEvent *event) override ; |
245 | #if QT_CONFIG(wheelevent) |
246 | void wheelEvent(QWheelEvent *event) override ; |
247 | #endif |
248 | |
249 | bool childMouseEventFilter(QQuickItem *item, QEvent *event) override; |
250 | bool sendMouseEvent(QMouseEvent *event); |
251 | bool sendTouchEvent(QTouchEvent *event); |
252 | |
253 | void componentComplete() override; |
254 | QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override; |
255 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; |
256 | |
257 | void setError(QGeoServiceProvider::Error error, const QString &errorString); |
258 | void initialize(); |
259 | void setZoomLevel(qreal zoomLevel, bool overzoom); |
260 | bool addMapChild(QObject *child); |
261 | bool removeMapChild(QObject *child); |
262 | bool isGroupNested(QDeclarativeGeoMapItemGroup *group); |
263 | |
264 | bool addMapItem_real(QDeclarativeGeoMapItemBase *item); |
265 | bool removeMapItem_real(QDeclarativeGeoMapItemBase *item); |
266 | bool addMapItemGroup_real(QDeclarativeGeoMapItemGroup *itemGroup); |
267 | bool removeMapItemGroup_real(QDeclarativeGeoMapItemGroup *itemGroup); |
268 | bool addMapItemView_real(QDeclarativeGeoMapItemView *itemView); |
269 | bool removeMapItemView_real(QDeclarativeGeoMapItemView *itemView); |
270 | void updateItemToWindowTransform(); |
271 | void onSGNodeChanged(); |
272 | |
273 | private Q_SLOTS: |
274 | void mappingManagerInitialized(); |
275 | void pluginReady(); |
276 | void onSupportedMapTypesChanged(); |
277 | void onCameraCapabilitiesChanged(const QGeoCameraCapabilities &oldCameraCapabilities); |
278 | void onAttachedCopyrightNoticeVisibilityChanged(); |
279 | void onCameraDataChanged(const QGeoCameraData &cameraData); |
280 | |
281 | private: |
282 | void setupMapView(QDeclarativeGeoMapItemView *view); |
283 | void populateMap(); |
284 | void populateParameters(); |
285 | void fitViewportToMapItemsRefine(const QList<QPointer<QDeclarativeGeoMapItemBase> > &mapItems, bool refine, bool onlyVisible); |
286 | bool isInteractive(); |
287 | void attachCopyrightNotice(bool initialVisibility); |
288 | void detachCopyrightNotice(bool currentVisibility); |
289 | QMargins mapMargins() const; |
290 | |
291 | private: |
292 | QDeclarativeGeoServiceProvider *m_plugin; |
293 | QGeoMappingManager *m_mappingManager; |
294 | QDeclarativeGeoMapType *m_activeMapType; |
295 | QList<QDeclarativeGeoMapType *> m_supportedMapTypes; |
296 | QList<QDeclarativeGeoMapItemView *> m_mapViews; |
297 | QQuickGeoMapGestureArea *m_gestureArea; |
298 | QPointer<QGeoMap> m_map; |
299 | QPointer<QDeclarativeGeoMapCopyrightNotice> m_copyrights; |
300 | QList<QPointer<QDeclarativeGeoMapItemBase> > m_mapItems; |
301 | QList<QPointer<QDeclarativeGeoMapItemGroup> > m_mapItemGroups; |
302 | QString m_errorString; |
303 | QGeoServiceProvider::Error m_error; |
304 | QGeoRectangle m_visibleRegion; |
305 | QColor m_color; |
306 | QGeoCameraData m_cameraData; |
307 | bool m_componentCompleted; |
308 | bool m_pendingFitViewport; |
309 | bool m_copyrightsVisible; |
310 | double m_maximumViewportLatitude; |
311 | double m_minimumViewportLatitude = 0.0; |
312 | bool m_initialized; |
313 | bool m_sgNodeHasChanged = false; |
314 | QList<QDeclarativeGeoMapParameter *> m_mapParameters; |
315 | QList<QGeoMapObject*> m_pendingMapObjects; // Used only in the initialization phase |
316 | QGeoCameraCapabilities m_cameraCapabilities; |
317 | qreal m_userMinimumZoomLevel; |
318 | qreal m_userMaximumZoomLevel; |
319 | |
320 | qreal m_minimumTilt; |
321 | qreal m_maximumTilt; |
322 | qreal m_userMinimumTilt; |
323 | qreal m_userMaximumTilt; |
324 | |
325 | qreal m_minimumFieldOfView; |
326 | qreal m_maximumFieldOfView; |
327 | qreal m_userMinimumFieldOfView; |
328 | qreal m_userMaximumFieldOfView; |
329 | |
330 | int m_copyNoticesVisible = 0; |
331 | qreal m_maxChildZ = 0; |
332 | QRectF m_visibleArea; |
333 | |
334 | |
335 | friend class QDeclarativeGeoMapItem; |
336 | friend class QDeclarativeGeoMapItemView; |
337 | friend class QQuickGeoMapGestureArea; |
338 | friend class QDeclarativeGeoMapCopyrightNotice; |
339 | Q_DISABLE_COPY(QDeclarativeGeoMap) |
340 | }; |
341 | |
342 | |
343 | QT_END_NAMESPACE |
344 | |
345 | QML_DECLARE_TYPE(QDeclarativeGeoMap) |
346 | |
347 | #endif |
348 | |