101QDeclarativeRectangleMapItem::QDeclarativeRectangleMapItem(QQuickItem *parent)
102 : QDeclarativeGeoMapItemBase(parent), m_border(
this),
103 m_d(
new QDeclarativeRectangleMapItemPrivateCPU(*
this))
106 m_itemType = QGeoMap::MapRectangle;
107 setFlag(ItemHasContents,
true);
108 QObject::connect(&m_border, &QDeclarativeMapLineProperties::colorChanged,
109 this, &QDeclarativeRectangleMapItem::onLinePropertiesChanged);
110 QObject::connect(&m_border, &QDeclarativeMapLineProperties::widthChanged,
111 this, &QDeclarativeRectangleMapItem::onLinePropertiesChanged);
152void QDeclarativeRectangleMapItem::setTopLeft(
const QGeoCoordinate &topLeft)
154 if (m_rectangle.topLeft() == topLeft)
157 m_rectangle.setTopLeft(topLeft);
158 m_d->onGeoGeometryChanged();
159 emit topLeftChanged(topLeft);
186void QDeclarativeRectangleMapItem::setBottomRight(
const QGeoCoordinate &bottomRight)
188 if (m_rectangle.bottomRight() == bottomRight)
191 m_rectangle.setBottomRight(bottomRight);
192 m_d->onGeoGeometryChanged();
193 emit bottomRightChanged(bottomRight);
272void QDeclarativeRectangleMapItem::setGeoShape(
const QGeoShape &shape)
274 if (shape == m_rectangle)
277 const QGeoRectangle rectangle = m_rectangle.boundingGeoRectangle();
278 const bool tlHasChanged = rectangle.topLeft() != m_rectangle.topLeft();
279 const bool brHasChanged = rectangle.bottomRight() != m_rectangle.bottomRight();
280 m_rectangle = rectangle;
282 m_d->onGeoGeometryChanged();
284 emit topLeftChanged(m_rectangle.topLeft());
286 emit bottomRightChanged(m_rectangle.bottomRight());
292void QDeclarativeRectangleMapItem::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
294 if (!map() || !m_rectangle.isValid() || m_updatingGeometry || newGeometry.topLeft() == oldGeometry.topLeft()) {
295 QDeclarativeGeoMapItemBase::geometryChange(newGeometry, oldGeometry);
299 QGeoCoordinate newCenter = map()->geoProjection().itemPositionToCoordinate(QDoubleVector2D(newGeometry.center()),
false);
300 QGeoCoordinate oldCenter = map()->geoProjection().itemPositionToCoordinate(QDoubleVector2D(oldGeometry.center()),
false);
301 if (!newCenter.isValid() || !oldCenter.isValid())
303 double offsetLongi = newCenter.longitude() - oldCenter.longitude();
304 double offsetLati = newCenter.latitude() - oldCenter.latitude();
305 if (offsetLati == 0.0 && offsetLongi == 0.0)
308 m_rectangle.translate(offsetLati, offsetLongi);
309 m_d->onItemGeometryChanged();
310 emit topLeftChanged(m_rectangle.topLeft());
311 emit bottomRightChanged(m_rectangle.bottomRight());
326QDeclarativeRectangleMapItemPrivateCPU::QDeclarativeRectangleMapItemPrivateCPU(QDeclarativeRectangleMapItem &rect)
327 : QDeclarativeRectangleMapItemPrivate(rect)
329 m_shape =
new QQuickShape(&m_rect);
330 m_shape->setObjectName(
"_qt_map_item_shape");
332 m_shape->setContainsMode(QQuickShape::FillContains);
334 m_shapePath =
new QQuickShapePath(m_shape);
335 m_painterPath =
new QDeclarativeGeoMapPainterPath(m_shapePath);
337 auto pathElements = m_shapePath->pathElements();
338 pathElements.append(&pathElements, m_painterPath);
340 auto shapePaths = m_shape->data();
341 shapePaths.append(&shapePaths, m_shapePath);
349void QDeclarativeRectangleMapItemPrivateCPU::updatePolish()
351 if (!m_rect.topLeft().isValid() || !m_rect.bottomRight().isValid()) {
355 m_shape->setVisible(
false);
359 QScopedValueRollback<
bool> rollback(m_rect.m_updatingGeometry);
360 m_rect.m_updatingGeometry =
true;
362 QList<QGeoCoordinate> perimeter = QGeoMapItemGeometry::path(m_rect.m_rectangle);
364 if (m_rect.referenceSurface() == QLocation::ReferenceSurface::Globe) {
365 perimeter = QDeclarativeGeoMapItemUtils::greaterCirclePath(perimeter,
366 QDeclarativeGeoMapItemUtils::ClosedPath);
369 const QList<QDoubleVector2D> pathMercator = QGeoMapItemGeometry::pathMercator(perimeter);
371 m_geometry.updateSourcePoints(*m_rect.map(), QList<QList<QDoubleVector2D>>{pathMercator},
372 m_rect.referenceSurface() == QLocation::ReferenceSurface::Globe ? QGeoMapPolygonGeometry::WrapAround :
373 QGeoMapPolygonGeometry::Duplicate);
374 m_rect.setShapeTriangulationScale(m_shape, m_geometry.maxCoord());
376 const bool hasBorder = m_rect.m_border.color().alpha() != 0 && m_rect.m_border.width() > 0;
377 m_shapePath->setStrokeColor(hasBorder ? m_rect.m_border.color() : Qt::transparent);
378 const float borderWidth = hasBorder ? m_rect.m_border.width() : 0.0f;
379 m_shapePath->setStrokeWidth(hasBorder ? borderWidth : -1.0f);
380 m_shapePath->setFillColor(m_rect.color());
382 const QRectF bb = m_geometry.sourceBoundingBox();
383 QPainterPath path = m_geometry.srcPath();
384 path.translate(-bb.left() + borderWidth, -bb.top() + borderWidth);
386 m_painterPath->setPath(path);
388 m_rect.setSize(bb.size() + QSize(2 * borderWidth, 2 * borderWidth));
389 m_shape->setSize(m_rect.size());
390 m_shape->setOpacity(m_rect.zoomLevelOpacity());
391 m_shape->setVisible(
true);
393 m_rect.setPositionOnMap(m_geometry.origin(), -1 * bb.topLeft() + QPointF(borderWidth, borderWidth));