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
qdeclarativerectanglemapitem.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
6
7#include <QtCore/QScopedValueRollback>
8#include <QPainterPath>
9#include <qnumeric.h>
10#include <QRectF>
11#include <QPointF>
12
13#include <QtLocation/private/qgeomap_p.h>
14#include <QtPositioning/private/qlocationutils_p.h>
15#include <QtPositioning/private/qwebmercator_p.h>
16#include <QtPositioning/private/qdoublevector2d_p.h>
17
19
112
116
121{
123 if (!map)
124 return;
125 m_d->onMapSet();
126}
127
141{
142 return &m_border;
143}
144
152{
153 if (m_rectangle.topLeft() == topLeft)
154 return;
155
156 m_rectangle.setTopLeft(topLeft);
157 m_d->onGeoGeometryChanged();
159}
160
162{
163 return m_rectangle.topLeft();
164}
165
170{
171 m_d->markSourceDirtyAndUpdate();
172}
173
175{
176 m_d->onLinePropertiesChanged();
177}
178
186{
187 if (m_rectangle.bottomRight() == bottomRight)
188 return;
189
190 m_rectangle.setBottomRight(bottomRight);
191 m_d->onGeoGeometryChanged();
193}
194
196{
197 return m_rectangle.bottomRight();
198}
199
207{
208 return m_color;
209}
210
212{
213 if (m_color == color)
214 return;
215 m_color = color;
217 emit colorChanged(m_color);
218}
219
234{
235 return m_d->updateMapItemPaintNode(oldNode, data);
236}
237
242{
243 if (!map() || map()->geoProjection().projectionType() != QGeoProjection::ProjectionWebMercator)
244 return;
245 m_d->updatePolish();
246}
247
252{
253 if (event.mapSize.width() <= 0 || event.mapSize.height() <= 0)
254 return;
255 m_d->afterViewportChanged();
256}
257
262{
263 return m_d->contains(point);
264}
265
267{
268 return m_rectangle;
269}
270
272{
273 if (shape == m_rectangle)
274 return;
275
276 const QGeoRectangle rectangle = m_rectangle.boundingGeoRectangle();
277 const bool tlHasChanged = rectangle.topLeft() != m_rectangle.topLeft();
278 const bool brHasChanged = rectangle.bottomRight() != m_rectangle.bottomRight();
279 m_rectangle = rectangle;
280
281 m_d->onGeoGeometryChanged();
282 if (tlHasChanged)
283 emit topLeftChanged(m_rectangle.topLeft());
284 if (brHasChanged)
285 emit bottomRightChanged(m_rectangle.bottomRight());
286}
287
291void QDeclarativeRectangleMapItem::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
292{
293 if (!map() || !m_rectangle.isValid() || m_updatingGeometry || newGeometry.topLeft() == oldGeometry.topLeft()) {
294 QDeclarativeGeoMapItemBase::geometryChange(newGeometry, oldGeometry);
295 return;
296 }
297 // TODO: change the algorithm to preserve the distances and size
298 QGeoCoordinate newCenter = map()->geoProjection().itemPositionToCoordinate(QDoubleVector2D(newGeometry.center()), false);
299 QGeoCoordinate oldCenter = map()->geoProjection().itemPositionToCoordinate(QDoubleVector2D(oldGeometry.center()), false);
300 if (!newCenter.isValid() || !oldCenter.isValid())
301 return;
302 double offsetLongi = newCenter.longitude() - oldCenter.longitude();
303 double offsetLati = newCenter.latitude() - oldCenter.latitude();
304 if (offsetLati == 0.0 && offsetLongi == 0.0)
305 return;
306
307 m_rectangle.translate(offsetLati, offsetLongi);
308 m_d->onItemGeometryChanged();
309 emit topLeftChanged(m_rectangle.topLeft());
310 emit bottomRightChanged(m_rectangle.bottomRight());
311
312 // Not calling QDeclarativeGeoMapItemBase::geometryChange() as it will be called from a nested
313 // call to this function.
314}
315
320
324
327{
328 m_shape = new QQuickShape(&m_rect);
329 m_shape->setObjectName("_qt_map_item_shape");
330 m_shape->setZ(-1);
332
335
336 auto pathElements = m_shapePath->pathElements();
337 pathElements.append(&pathElements, m_painterPath);
338
339 auto shapePaths = m_shape->data();
340 shapePaths.append(&shapePaths, m_shapePath);
341}
342
347
349{
350 if (!m_rect.topLeft().isValid() || !m_rect.bottomRight().isValid()) {
352 m_rect.setWidth(0);
353 m_rect.setHeight(0);
354 m_shape->setVisible(false);
355 return;
356 }
357
358 QScopedValueRollback<bool> rollback(m_rect.m_updatingGeometry);
359 m_rect.m_updatingGeometry = true;
360
361 QList<QGeoCoordinate> perimeter = QGeoMapItemGeometry::path(m_rect.m_rectangle);
362
366 }
367
368 const QList<QDoubleVector2D> pathMercator = QGeoMapItemGeometry::pathMercator(perimeter);
369
370 m_geometry.updateSourcePoints(*m_rect.map(), QList<QList<QDoubleVector2D>>{pathMercator},
374
375 const bool hasBorder = m_rect.m_border.color().alpha() != 0 && m_rect.m_border.width() > 0;
376 m_shapePath->setStrokeColor(hasBorder ? m_rect.m_border.color() : Qt::transparent);
377 const float borderWidth = hasBorder ? m_rect.m_border.width() : 0.0f;
378 m_shapePath->setStrokeWidth(hasBorder ? borderWidth : -1.0f);
380
383 path.translate(-bb.left() + borderWidth, -bb.top() + borderWidth);
384 path.closeSubpath();
386
387 m_rect.setSize(bb.size() + QSize(2 * borderWidth, 2 * borderWidth));
390 m_shape->setVisible(true);
391
392 m_rect.setPositionOnMap(m_geometry.origin(), -1 * bb.topLeft() + QPointF(borderWidth, borderWidth));
393}
394
405
407{
408 return m_shape->contains(m_rect.mapToItem(m_shape, point));
409}
410
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
int alpha() const noexcept
Returns the alpha color component of this color.
Definition qcolor.cpp:1466
virtual void setPositionOnMap(const QGeoCoordinate &coordinate, const QPointF &offset)
void setShapeTriangulationScale(QQuickShape *shape, qreal maxCoord) const
virtual void setMap(QDeclarativeGeoMap *quickMap, QGeoMap *map)
QLocation::ReferenceSurface referenceSurface
QDeclarativeGeoMap * quickMap() const
void setPath(const QPainterPath &path)
void widthChanged(qreal width)
void colorChanged(const QColor &color)
QDeclarativeRectangleMapItemPrivateCPU(QDeclarativeRectangleMapItem &rect)
QSGNode * updateMapItemPaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *data) override
bool contains(const QPointF &point) const override
QDeclarativeRectangleMapItemPrivate(QDeclarativeRectangleMapItem &rect)
void bottomRightChanged(const QGeoCoordinate &bottomRight)
void setTopLeft(const QGeoCoordinate &center)
\qmlproperty coordinate MapRectangle::topLeft
const QGeoShape & geoShape() const override
void setBottomRight(const QGeoCoordinate &center)
\qmlproperty coordinate MapRectangle::bottomRight
void topLeftChanged(const QGeoCoordinate &topLeft)
bool contains(const QPointF &point) const override
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void setMap(QDeclarativeGeoMap *quickMap, QGeoMap *map) override
QDeclarativeMapLineProperties * border
\qmlpropertygroup Location::MapRectangle::border \qmlproperty int MapRectangle::border....
void afterViewportChanged(const QGeoMapViewportChangeEvent &event) override
QDeclarativeRectangleMapItem(QQuickItem *parent=nullptr)
\qmltype MapRectangle \instantiates QDeclarativeRectangleMapItem \inqmlmodule QtLocation
void setGeoShape(const QGeoShape &shape) override
QSGNode * updateMapItemPaintNode(QSGNode *, UpdatePaintNodeData *) override
\qmlproperty real MapRectangle::opacity
\inmodule QtPositioning
bool isValid
This property holds the validity of this geo coordinate.
static QList< QDoubleVector2D > pathMercator(const QList< QGeoCoordinate > &p)
static QList< QGeoCoordinate > path(const QGeoRectangle &rect)
QRectF sourceBoundingBox() const
const QGeoCoordinate & origin() const
void updateSourcePoints(const QGeoMap &map, const QList< QList< QDoubleVector2D > > &path, MapBorderBehaviour wrapping=Duplicate)
const QGeoProjection & geoProjection() const
Definition qgeomap.cpp:164
@ MapRectangle
Definition qgeomap_p.h:48
virtual QGeoCoordinate itemPositionToCoordinate(const QDoubleVector2D &pos, bool clipToViewport=true) const =0
\inmodule QtPositioning
QGeoCoordinate topLeft
This property holds the top left coordinate of this geo rectangle.
QGeoCoordinate bottomRight
This property holds the bottom right coordinate of this geo rectangle.
void setTopLeft(const QGeoCoordinate &topLeft)
Sets the top left coordinate of this geo rectangle to topLeft.
void setBottomRight(const QGeoCoordinate &bottomRight)
Sets the bottom right coordinate of this geo rectangle to bottomRight.
Q_INVOKABLE void translate(double degreesLatitude, double degreesLongitude)
Translates this geo rectangle by degreesLatitude northwards and degreesLongitude eastwards.
\inmodule QtPositioning
Definition qgeoshape.h:17
bool isValid
This property holds the validity of the geo shape.
Definition qgeoshape.h:20
Q_INVOKABLE QGeoRectangle boundingGeoRectangle() const
Returns a QGeoRectangle representing the geographical bounding rectangle of the geo shape,...
Definition qlist.h:75
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
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
Definition qobject.h:127
\inmodule QtGui
void translate(qreal dx, qreal dy)
Translates all elements in the path by ({dx}, {dy}).
\inmodule QtCore\reentrant
Definition qpoint.h:217
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
void setOpacity(qreal)
void setSize(const QSizeF &size)
void setFlag(Flag flag, bool enabled=true)
Enables the specified flag for this item if enabled is true; if enabled is false, the flag is disable...
virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
Q_INVOKABLE QPointF mapToItem(const QQuickItem *item, const QPointF &point) const
Maps the given point in this item's coordinate system to the equivalent point within item's coordinat...
void setHeight(qreal)
QSizeF size() const
void setVisible(bool)
void setZ(qreal)
void setWidth(qreal)
QQmlListProperty< QQuickPathElement > pathElements
\qmlproperty list<PathElement> QtQuick::Path::pathElements This property holds the objects composing ...
void setStrokeColor(const QColor &color)
void setStrokeWidth(qreal w)
void setFillColor(const QColor &color)
bool contains(const QPointF &point) const override
\qmlmethod bool QtQuick::Item::contains(point point)
void setContainsMode(ContainsMode containsMode)
FINALQQmlListProperty< QObject > data
\qmlproperty list<Object> QtQuick.Shapes::Shape::data
\inmodule QtCore\reentrant
Definition qrect.h:484
constexpr QPointF topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:511
constexpr QPointF center() const noexcept
Returns the center point of the rectangle.
Definition qrect.h:699
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
Definition qsgnode.h:37
\inmodule QtCore
Definition qsize.h:25
#define this
Definition dialogs.cpp:9
QMap< QString, QString > map
[6]
void colorChanged()
rect
[4]
QList< QGeoCoordinate > greaterCirclePath(const QList< QGeoCoordinate > &cornerPoints, greaterCirclePathForm form, int N)
Combined button and popup list for selecting options.
@ transparent
Definition qnamespace.h:47
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint color
[2]
struct _cl_event * event
GLsizei const GLchar *const * path
#define emit
#define Q_UNUSED(x)