1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2018 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 | #ifndef QGEOTILEDMAPSCENE_P_P_H |
37 | #define QGEOTILEDMAPSCENE_P_P_H |
38 | |
39 | // |
40 | // W A R N I N G |
41 | // ------------- |
42 | // |
43 | // This file is not part of the Qt API. It exists purely as an |
44 | // implementation detail. This header file may change from version to |
45 | // version without notice, or even be removed. |
46 | // |
47 | // We mean it. |
48 | // |
49 | |
50 | #include "qgeotiledmapscene_p.h" |
51 | #include <QtCore/private/qobject_p.h> |
52 | #include <QtPositioning/private/qdoublevector3d_p.h> |
53 | #include <QtQuick/QSGImageNode> |
54 | #include <QtQuick/private/qsgdefaultimagenode_p.h> |
55 | #include <QtQuick/QQuickWindow> |
56 | #include "qgeocameradata_p.h" |
57 | #include "qgeotilespec_p.h" |
58 | |
59 | QT_BEGIN_NAMESPACE |
60 | |
61 | class Q_LOCATION_PRIVATE_EXPORT QGeoTiledMapTileContainerNode : public QSGTransformNode |
62 | { |
63 | public: |
64 | void addChild(const QGeoTileSpec &spec, QSGImageNode *node) |
65 | { |
66 | tiles.insert(akey: spec, avalue: node); |
67 | appendChildNode(node); |
68 | } |
69 | QHash<QGeoTileSpec, QSGImageNode *> tiles; |
70 | }; |
71 | |
72 | class Q_LOCATION_PRIVATE_EXPORT QGeoTiledMapRootNode : public QSGClipNode |
73 | { |
74 | public: |
75 | QGeoTiledMapRootNode() |
76 | : isTextureLinear(false) |
77 | , geometry(QSGGeometry::defaultAttributes_Point2D(), 4) |
78 | , root(new QSGTransformNode()) |
79 | , tiles(new QGeoTiledMapTileContainerNode()) |
80 | , wrapLeft(new QGeoTiledMapTileContainerNode()) |
81 | , wrapRight(new QGeoTiledMapTileContainerNode()) |
82 | { |
83 | setIsRectangular(true); |
84 | setGeometry(&geometry); |
85 | root->appendChildNode(node: tiles); |
86 | root->appendChildNode(node: wrapLeft); |
87 | root->appendChildNode(node: wrapRight); |
88 | appendChildNode(node: root); |
89 | } |
90 | |
91 | ~QGeoTiledMapRootNode() |
92 | { |
93 | qDeleteAll(c: textures); |
94 | } |
95 | |
96 | void setClipRect(const QRect &rect) |
97 | { |
98 | if (rect != clipRect) { |
99 | QSGGeometry::updateRectGeometry(g: &geometry, rect); |
100 | QSGClipNode::setClipRect(rect); |
101 | clipRect = rect; |
102 | markDirty(bits: DirtyGeometry); |
103 | } |
104 | } |
105 | |
106 | void updateTiles(QGeoTiledMapTileContainerNode *root, |
107 | QGeoTiledMapScenePrivate *d, |
108 | double camAdjust, |
109 | QQuickWindow *window, |
110 | bool ogl); |
111 | |
112 | bool isTextureLinear; |
113 | |
114 | QSGGeometry geometry; |
115 | QRect clipRect; |
116 | |
117 | QSGTransformNode *root; |
118 | |
119 | QGeoTiledMapTileContainerNode *tiles; // The majority of the tiles |
120 | QGeoTiledMapTileContainerNode *wrapLeft; // When zoomed out, the tiles that wrap around on the left. |
121 | QGeoTiledMapTileContainerNode *wrapRight; // When zoomed out, the tiles that wrap around on the right |
122 | |
123 | QHash<QGeoTileSpec, QSGTexture *> textures; |
124 | |
125 | #ifdef QT_LOCATION_DEBUG |
126 | double m_sideLengthPixel; |
127 | QMap<double, QList<QGeoTileSpec>> m_droppedTiles; |
128 | #endif |
129 | }; |
130 | |
131 | class Q_LOCATION_PRIVATE_EXPORT QGeoTiledMapScenePrivate : public QObjectPrivate |
132 | { |
133 | Q_DECLARE_PUBLIC(QGeoTiledMapScene) |
134 | public: |
135 | QGeoTiledMapScenePrivate(); |
136 | ~QGeoTiledMapScenePrivate(); |
137 | |
138 | void addTile(const QGeoTileSpec &spec, QSharedPointer<QGeoTileTexture> texture); |
139 | |
140 | void setVisibleTiles(const QSet<QGeoTileSpec> &visibleTiles); |
141 | void removeTiles(const QSet<QGeoTileSpec> &oldTiles); |
142 | bool buildGeometry(const QGeoTileSpec &spec, QSGImageNode *imageNode, bool &overzooming); |
143 | void updateTileBounds(const QSet<QGeoTileSpec> &tiles); |
144 | void setupCamera(); |
145 | inline bool isTiltedOrRotated() { return (m_cameraData.tilt() > 0.0) || (m_cameraData.bearing() > 0.0); } |
146 | |
147 | public: |
148 | |
149 | QSize m_screenSize; // in pixels |
150 | int m_tileSize; // the pixel resolution for each tile |
151 | QGeoCameraData m_cameraData; |
152 | QRectF m_visibleArea; |
153 | QSet<QGeoTileSpec> m_visibleTiles; |
154 | |
155 | QDoubleVector3D m_cameraUp; |
156 | QDoubleVector3D m_cameraEye; |
157 | QDoubleVector3D m_cameraCenter; |
158 | QMatrix4x4 m_projectionMatrix; |
159 | |
160 | // scales up the tile geometry and the camera altitude, resulting in no visible effect |
161 | // other than to control the accuracy of the render by keeping the values in a sensible range |
162 | double m_scaleFactor; |
163 | |
164 | // rounded down, positive zoom is zooming in, corresponding to reduced altitude |
165 | int m_intZoomLevel; |
166 | |
167 | // mercatorToGrid transform |
168 | // the number of tiles in each direction for the whole map (earth) at the current zoom level. |
169 | // it is 1<<zoomLevel |
170 | int m_sideLength; |
171 | double m_mapEdgeSize; |
172 | |
173 | QHash<QGeoTileSpec, QSharedPointer<QGeoTileTexture> > m_textures; |
174 | QVector<QGeoTileSpec> m_updatedTextures; |
175 | |
176 | // tilesToGrid transform |
177 | int m_minTileX; // the minimum tile index, i.e. 0 to sideLength which is 1<< zoomLevel |
178 | int m_minTileY; |
179 | int m_maxTileX; |
180 | int m_maxTileY; |
181 | int m_tileXWrapsBelow; // the wrap point as a tile index |
182 | bool m_linearScaling; |
183 | bool m_dropTextures; |
184 | |
185 | #ifdef QT_LOCATION_DEBUG |
186 | double m_sideLengthPixel; |
187 | QGeoTiledMapRootNode *m_mapRoot = nullptr; |
188 | #endif |
189 | }; |
190 | |
191 | QT_END_NAMESPACE |
192 | |
193 | #endif // QGEOTILEDMAPSCENE_P_P_H |
194 | |