100QDeclarativeRectangleMapItem::QDeclarativeRectangleMapItem(QQuickItem *parent)
101 : QDeclarativeGeoMapItemBase(parent), m_border(
this),
102 m_d(
new QDeclarativeRectangleMapItemPrivateCPU(*
this))
105 m_itemType = QGeoMap::MapRectangle;
106 setFlag(ItemHasContents,
true);
107 QObject::connect(&m_border, &QDeclarativeMapLineProperties::colorChanged,
108 this, &QDeclarativeRectangleMapItem::onLinePropertiesChanged);
109 QObject::connect(&m_border, &QDeclarativeMapLineProperties::widthChanged,
110 this, &QDeclarativeRectangleMapItem::onLinePropertiesChanged);
151void QDeclarativeRectangleMapItem::setTopLeft(
const QGeoCoordinate &topLeft)
153 if (m_rectangle.topLeft() == topLeft)
156 m_rectangle.setTopLeft(topLeft);
157 m_d->onGeoGeometryChanged();
158 emit topLeftChanged(topLeft);
185void QDeclarativeRectangleMapItem::setBottomRight(
const QGeoCoordinate &bottomRight)
187 if (m_rectangle.bottomRight() == bottomRight)
190 m_rectangle.setBottomRight(bottomRight);
191 m_d->onGeoGeometryChanged();
192 emit bottomRightChanged(bottomRight);
271void QDeclarativeRectangleMapItem::setGeoShape(
const QGeoShape &shape)
273 if (shape == m_rectangle)
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;
281 m_d->onGeoGeometryChanged();
283 emit topLeftChanged(m_rectangle.topLeft());
285 emit bottomRightChanged(m_rectangle.bottomRight());
291void QDeclarativeRectangleMapItem::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
293 if (!map() || !m_rectangle.isValid() || m_updatingGeometry || newGeometry.topLeft() == oldGeometry.topLeft()) {
294 QDeclarativeGeoMapItemBase::geometryChange(newGeometry, oldGeometry);
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())
302 double offsetLongi = newCenter.longitude() - oldCenter.longitude();
303 double offsetLati = newCenter.latitude() - oldCenter.latitude();
304 if (offsetLati == 0.0 && offsetLongi == 0.0)
307 m_rectangle.translate(offsetLati, offsetLongi);
308 m_d->onItemGeometryChanged();
309 emit topLeftChanged(m_rectangle.topLeft());
310 emit bottomRightChanged(m_rectangle.bottomRight());
325QDeclarativeRectangleMapItemPrivateCPU::QDeclarativeRectangleMapItemPrivateCPU(QDeclarativeRectangleMapItem &rect)
326 : QDeclarativeRectangleMapItemPrivate(rect)
328 m_shape =
new QQuickShape(&m_rect);
329 m_shape->setObjectName(
"_qt_map_item_shape");
331 m_shape->setContainsMode(QQuickShape::FillContains);
333 m_shapePath =
new QQuickShapePath(m_shape);
334 m_painterPath =
new QDeclarativeGeoMapPainterPath(m_shapePath);
336 auto pathElements = m_shapePath->pathElements();
337 pathElements.append(&pathElements, m_painterPath);
339 auto shapePaths = m_shape->data();
340 shapePaths.append(&shapePaths, m_shapePath);
348void QDeclarativeRectangleMapItemPrivateCPU::updatePolish()
350 if (!m_rect.topLeft().isValid() || !m_rect.bottomRight().isValid()) {
354 m_shape->setVisible(
false);
358 QScopedValueRollback<
bool> rollback(m_rect.m_updatingGeometry);
359 m_rect.m_updatingGeometry =
true;
361 QList<QGeoCoordinate> perimeter = QGeoMapItemGeometry::path(m_rect.m_rectangle);
363 if (m_rect.referenceSurface() == QLocation::ReferenceSurface::Globe) {
364 perimeter = QDeclarativeGeoMapItemUtils::greaterCirclePath(perimeter,
365 QDeclarativeGeoMapItemUtils::ClosedPath);
368 const QList<QDoubleVector2D> pathMercator = QGeoMapItemGeometry::pathMercator(perimeter);
370 m_geometry.updateSourcePoints(*m_rect.map(), QList<QList<QDoubleVector2D>>{pathMercator},
371 m_rect.referenceSurface() == QLocation::ReferenceSurface::Globe ? QGeoMapPolygonGeometry::WrapAround :
372 QGeoMapPolygonGeometry::Duplicate);
373 m_rect.setShapeTriangulationScale(m_shape, m_geometry.maxCoord());
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);
379 m_shapePath->setFillColor(m_rect.color());
381 const QRectF bb = m_geometry.sourceBoundingBox();
382 QPainterPath path = m_geometry.srcPath();
383 path.translate(-bb.left() + borderWidth, -bb.top() + borderWidth);
385 m_painterPath->setPath(path);
387 m_rect.setSize(bb.size() + QSize(2 * borderWidth, 2 * borderWidth));
388 m_shape->setSize(m_rect.size());
389 m_shape->setOpacity(m_rect.zoomLevelOpacity());
390 m_shape->setVisible(
true);
392 m_rect.setPositionOnMap(m_geometry.origin(), -1 * bb.topLeft() + QPointF(borderWidth, borderWidth));