Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qdeclarativegeomapitembase.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include "qgeocameradata_p.h"
6
7#include <QtQml/QQmlInfo>
8#include <QtQuick/QSGOpacityNode>
9
10#include <QtQuick/private/qquickmousearea_p.h>
11#include <QtQuick/private/qquickitem_p.h>
12#include <QtPositioning/private/qdoublevector2d_p.h>
13#include <QtLocation/private/qgeomap_p.h>
14#include <QtLocation/private/qgeoprojection_p.h>
15
16#include <QtQuickShapes/private/qquickshape_p_p.h>
17
19
21 : QQuickItem(parent)
22{
25 // Changing opacity on a mapItemGroup should affect also the opacity on the children.
26 // This must be notified to plugins, if they are to render the item.
28}
29
37
42{
43 const QList<QQuickItem *> kids = childItems();
44 if (kids.size() > 0) {
45 bool printedWarning = false;
46 for (auto *i : kids) {
47 if (i->flags() & QQuickItem::ItemHasContents
48 && !qobject_cast<QQuickMouseArea *>(i)
49 && i->objectName() != QStringLiteral("_qt_map_item_shape"))
50 {
51 if (!printedWarning) {
52 qmlWarning(this) << "Geographic map items do not support child items";
53 printedWarning = true;
54 }
55
56 qmlWarning(i) << "deleting this child";
57 i->deleteLater();
58 }
59 }
60 }
61}
62
67{
68 if (quickMap == quickMap_)
69 return;
70 if (quickMap && quickMap_)
71 return; // don't allow association to more than one map
72
73 quickMap_ = quickMap;
74 map_ = map;
75
76 if (map_ && quickMap_) {
77 // For performance reasons we're not connecting map_'s and quickMap_'s signals to this.
78 // Rather, the handling of cameraDataChanged, visibleAreaChanged, heightChanged and widthChanged is done explicitly in QDeclarativeGeoMap by directly calling methods on the items.
79 // See QTBUG-76950
80 lastMapSize_ = QSizeF(quickMap_->width(), quickMap_->height());
81 lastCameraData_ = map_->cameraData();
82 }
83}
84
88void QDeclarativeGeoMapItemBase::baseCameraDataChanged(const QGeoCameraData &cameraData)
89{
91 evt.cameraData = cameraData;
92 evt.mapSize = QSizeF(quickMap_->width(), quickMap_->height());
93
94 if (evt.mapSize != lastMapSize_)
95 evt.mapSizeChanged = true;
96
97 if (cameraData.bearing() != lastCameraData_.bearing())
98 evt.bearingChanged = true;
99 if (cameraData.center() != lastCameraData_.center())
100 evt.centerChanged = true;
101 if (cameraData.roll() != lastCameraData_.roll())
102 evt.rollChanged = true;
103 if (cameraData.tilt() != lastCameraData_.tilt())
104 evt.tiltChanged = true;
105 if (cameraData.zoomLevel() != lastCameraData_.zoomLevel())
106 evt.zoomLevelChanged = true;
107
108 lastMapSize_ = evt.mapSize;
109 lastCameraData_ = cameraData;
110
112}
113
114void QDeclarativeGeoMapItemBase::visibleAreaChanged()
115{
117 evt.mapSize = QSizeF(quickMap_->width(), quickMap_->height());
119}
120
125{
126 if (!map_ || !quickMap_)
127 return;
128
130 if (map()->geoProjection().projectionType() == QGeoProjection::ProjectionWebMercator) {
131 const QGeoProjectionWebMercator &p = static_cast<const QGeoProjectionWebMercator&>(map()->geoProjection());
132 QDoubleVector2D wrappedProjection = p.geoToWrappedMapProjection(coordinate);
133 if (!p.isProjectable(wrappedProjection))
134 return;
135 pos = p.wrappedMapProjectionToItemPosition(wrappedProjection);
136 } else {
137 pos = map()->geoProjection().coordinateToItemPosition(coordinate, false);
138 if (qIsNaN(pos.x()))
139 return;
140 }
141
142 QPointF topLeft = pos.toPointF() - offset;
143
144 setPosition(topLeft);
145}
146
148{
149 return m_autoFadeIn;
150}
151
152static const double opacityRampMin = 1.5;
153static const double opacityRampMax = 2.5;
154
156{
157 if (fadeIn == m_autoFadeIn)
158 return;
159 m_autoFadeIn = fadeIn;
160 if (quickMap_ && quickMap_->zoomLevel() < opacityRampMax)
162}
163
165{
166 return m_referenceSurface;
167}
168
170{
171 if (referenceSurface == m_referenceSurface)
172 return;
173 m_referenceSurface = referenceSurface;
175 updatePolish();
176}
177
179{
180 return m_lodThreshold;
181}
182
184{
185 if (lt == m_lodThreshold)
186 return;
187 m_lodThreshold = lt;
188 update();
189}
190
198unsigned int QDeclarativeGeoMapItemBase::zoomForLOD(int zoom) const
199{
200 if (zoom >= m_lodThreshold)
201 return 30; // some arbitrarily large zoom
202 return uint(zoom);
203}
204
209{
210 if (!m_autoFadeIn) // Consider skipping the opacity node instead.
211 return 1.0;
212 else if (quickMap_->zoomLevel() > opacityRampMax)
213 return 1.0;
214 else if (quickMap_->zoomLevel() > opacityRampMin)
215 return quickMap_->zoomLevel() - opacityRampMin;
216 else
217 return 0.0;
218}
219
221{
222 const qreal zoom = qMax(0.01, quickMap_->zoomLevel());
223 qreal scale = 1 / zoom;
224
225 // cater also for QTriangulator's 65536 coordinate limit due to the fixed point math
226 qint64 coord = qint64(maxCoord);
227 const qint64 COORD_LIMIT = (1 << 21) / 32; // 65536 (where 32 is Q_FIXED_POINT_SCALE)
228 while (coord > COORD_LIMIT) {
229 coord /= COORD_LIMIT;
230 scale /= COORD_LIMIT;
231 }
232
233 QQuickShapePrivate::get(shape)->triangulationScale = scale;
234}
235
240{
241 if (!map_ || !quickMap_ || map_->supportedMapItemTypes() & itemType()) {
242 if (oldNode)
243 delete oldNode;
244 oldNode = nullptr;
245 return nullptr;
246 }
247
248 QSGOpacityNode *opn = static_cast<QSGOpacityNode *>(oldNode);
249 if (!opn)
250 opn = new QSGOpacityNode();
251
252 opn->setOpacity(zoomLevelOpacity());
253
254 QSGNode *oldN = opn->childCount() ? opn->firstChild() : 0;
255 opn->removeAllChildNodes();
256 if (opn->opacity() > 0.0) {
257 QSGNode *n = this->updateMapItemPaintNode(oldN, pd);
258 if (n)
259 opn->appendChildNode(n);
260 } else {
261 delete oldN;
262 }
263
264 return opn;
265}
266
271{
272 delete oldNode;
273 return nullptr;
274}
275
283{
284 if (parentGroup_)
285 return parentGroup_->mapItemOpacity() * opacity();
286 return opacity();
287}
288
290{
291 parentGroup_ = &parentGroup;
292 if (parentGroup_) {
295 }
296}
297
299{
300 return QQuickItemPrivate::get(this)->polishScheduled;
301}
302
308
virtual void afterViewportChanged(const QGeoMapViewportChangeEvent &event)=0
QSGNode * updatePaintNode(QSGNode *, UpdatePaintNodeData *) override
virtual void setPositionOnMap(const QGeoCoordinate &coordinate, const QPointF &offset)
virtual QSGNode * updateMapItemPaintNode(QSGNode *, UpdatePaintNodeData *)
void setParentGroup(QDeclarativeGeoMapItemGroup &parentGroup)
void setShapeTriangulationScale(QQuickShape *shape, qreal maxCoord) const
QDeclarativeGeoMapItemBase(QQuickItem *parent=nullptr)
virtual void setMap(QDeclarativeGeoMap *quickMap, QGeoMap *map)
QLocation::ReferenceSurface referenceSurface
void setReferenceSurface(QLocation::ReferenceSurface referenceSurface)
QDeclarativeGeoMap * quickMap() const
unsigned int zoomForLOD(int zoom) const
Q_INVOKABLE void removeMapItem(QDeclarativeGeoMapItemBase *item)
\qmlmethod void QtLocation::Map::removeMapItem(MapItem item)
double zoomLevel() const
double tilt() const
double roll() const
double bearing() const
QGeoCoordinate center() const
\inmodule QtPositioning
const QGeoProjection & geoProjection() const
Definition qgeomap.cpp:164
ItemTypes supportedMapItemTypes() const
Definition qgeomap.cpp:191
const QGeoCameraData & cameraData() const
Definition qgeomap.cpp:111
virtual QDoubleVector2D coordinateToItemPosition(const QGeoCoordinate &coordinate, bool clipToViewport=true) const =0
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
\inmodule QtCore\reentrant
Definition qpoint.h:217
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
QList< QQuickItem * > childItems() const
Returns the children of this item.
void opacityChanged()
qreal width
This property holds the width of this item.
Definition qquickitem.h:75
void childrenChanged()
qreal height
This property holds the height of this item.
Definition qquickitem.h:76
virtual void updatePolish()
This function should perform any layout as required for this item.
qreal scale
\qmlproperty real QtQuick::Item::scale This property holds the scale factor for this item.
Definition qquickitem.h:107
qreal opacity
\qmlproperty real QtQuick::Item::opacity
Definition qquickitem.h:78
void update()
Schedules a call to updatePaintNode() for this item.
void polish()
Schedules a polish event for this item.
static QQuickShapePrivate * get(QQuickShape *item)
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
Definition qsgnode.h:37
int childCount() const
Returns the number of child nodes.
Definition qsgnode.cpp:556
The QSGOpacityNode class is used to change opacity of nodes.
Definition qsgnode.h:276
\inmodule QtCore
Definition qsize.h:208
QMap< QString, QString > map
[6]
Combined button and popup list for selecting options.
static const double opacityRampMax
static const double opacityRampMin
bool qIsNaN(qfloat16 f) noexcept
Definition qfloat16.h:284
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
n void setPosition(void) \n\
GLenum GLuint GLintptr offset
GLfloat n
GLuint coord
GLfloat GLfloat p
[1]
GLenum GLenum GLenum GLenum GLenum scale
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
#define QStringLiteral(str)
#define emit
unsigned int uint
Definition qtypes.h:34
long long qint64
Definition qtypes.h:60
double qreal
Definition qtypes.h:187
myObject disconnect()
[26]