summaryrefslogtreecommitdiff
path: root/src/location/quickmapitems/qdeclarativerectanglemapitem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/location/quickmapitems/qdeclarativerectanglemapitem.cpp')
-rw-r--r--src/location/quickmapitems/qdeclarativerectanglemapitem.cpp94
1 files changed, 84 insertions, 10 deletions
diff --git a/src/location/quickmapitems/qdeclarativerectanglemapitem.cpp b/src/location/quickmapitems/qdeclarativerectanglemapitem.cpp
index b7f3cdda..eae60410 100644
--- a/src/location/quickmapitems/qdeclarativerectanglemapitem.cpp
+++ b/src/location/quickmapitems/qdeclarativerectanglemapitem.cpp
@@ -312,22 +312,56 @@ void QDeclarativeRectangleMapItem::geometryChange(const QRectF &newGeometry, con
// call to this function.
}
-QDeclarativeRectangleMapItemPrivate::~QDeclarativeRectangleMapItemPrivate() {}
+QDeclarativeRectangleMapItemPrivate::QDeclarativeRectangleMapItemPrivate(QDeclarativeRectangleMapItem &rect)
+ : m_rect(rect)
+{
+}
+
+QDeclarativeRectangleMapItemPrivate::~QDeclarativeRectangleMapItemPrivate()
+{
+}
+
+QDeclarativeRectangleMapItemPrivateCPU::QDeclarativeRectangleMapItemPrivateCPU(QDeclarativeRectangleMapItem &rect)
+ : QDeclarativeRectangleMapItemPrivate(rect)
+{
+#ifdef MAPITEMS_USE_SHAPES
+ m_shape = new QQuickShape(&m_rect);
+ m_shape->setObjectName("_qt_map_item_shape");
+ m_shape->setZ(-1);
+ m_shape->setContainsMode(QQuickShape::FillContains);
+
+ m_shapePath = new QQuickShapePath(m_shape);
+ m_painterPath = new QDeclarativeGeoMapPainterPath(m_shapePath);
-QDeclarativeRectangleMapItemPrivateCPU::~QDeclarativeRectangleMapItemPrivateCPU() {}
+ auto pathElements = m_shapePath->pathElements();
+ pathElements.append(&pathElements, m_painterPath);
+
+ auto shapePaths = m_shape->data();
+ shapePaths.append(&shapePaths, m_shapePath);
+#endif
+}
+
+QDeclarativeRectangleMapItemPrivateCPU::~QDeclarativeRectangleMapItemPrivateCPU()
+{
+#ifdef MAPITEMS_USE_SHAPES
+ delete m_shape;
+#endif
+}
void QDeclarativeRectangleMapItemPrivateCPU::updatePolish()
{
if (!m_rect.topLeft().isValid() || !m_rect.bottomRight().isValid()) {
m_geometry.clear();
- m_borderGeometry.clear();
m_rect.setWidth(0);
m_rect.setHeight(0);
+#ifdef MAPITEMS_USE_SHAPES
+ m_shape->setVisible(false);
+#else
+ m_borderGeometry.clear();
+#endif
return;
}
- const QGeoProjectionWebMercator &p = static_cast<const QGeoProjectionWebMercator&>(m_rect.map()->geoProjection());
-
QScopedValueRollback<bool> rollback(m_rect.m_updatingGeometry);
m_rect.m_updatingGeometry = true;
@@ -335,12 +369,15 @@ void QDeclarativeRectangleMapItemPrivateCPU::updatePolish()
const QList<QDoubleVector2D> pathMercator_ = QGeoMapItemGeometry::pathMercator(perimeter);
m_geometry.setPreserveGeometry(true, m_rect.m_rectangle.topLeft());
m_geometry.updateSourcePoints(*m_rect.map(), pathMercator_);
+
+#ifndef MAPITEMS_USE_SHAPES
m_geometry.updateScreenPoints(*m_rect.map(), m_rect.m_border.width());
+ const QGeoProjectionWebMercator &p = static_cast<const QGeoProjectionWebMercator&>(m_rect.map()->geoProjection());
QList<QGeoMapItemGeometry *> geoms;
geoms << &m_geometry;
- m_borderGeometry.clear();
+ m_borderGeometry.clear();
if (m_rect.m_border.color().alpha() != 0 && m_rect.m_border.width() > 0) {
QList<QDoubleVector2D> closedPath = pathMercator_;
closedPath << closedPath.first();
@@ -357,24 +394,55 @@ void QDeclarativeRectangleMapItemPrivateCPU::updatePolish()
borderLeftBoundWrapped = p.geoToWrappedMapProjection(geometryOrigin);
m_borderGeometry.pathToScreen(*m_rect.map(), clippedPaths, borderLeftBoundWrapped);
m_borderGeometry.updateScreenPoints(*m_rect.map(), m_rect.m_border.width());
-
geoms << &m_borderGeometry;
} else {
m_borderGeometry.clear();
}
}
-
- QRectF combined = QGeoMapItemGeometry::translateToCommonOrigin(geoms);
+#endif
+
+#ifdef MAPITEMS_USE_SHAPES
+ m_rect.setShapeTriangulationScale(m_shape, m_geometry.maxCoord());
+
+ const bool hasBorder = m_rect.m_border.color().alpha() != 0 && m_rect.m_border.width() > 0;
+ m_shapePath->setStrokeColor(hasBorder ? m_rect.m_border.color() : Qt::transparent);
+ const float borderWidth = hasBorder ? m_rect.m_border.width() : 0.0f;
+ m_shapePath->setStrokeWidth(hasBorder ? borderWidth : -1.0f);
+ m_shapePath->setFillColor(m_rect.color());
+
+ const QRectF bb = m_geometry.sourceBoundingBox();
+ QPainterPath path = m_geometry.srcPath();
+ path.translate(-bb.left() + borderWidth, -bb.top() + borderWidth);
+ path.closeSubpath();
+ m_painterPath->setPath(path);
+
+ m_rect.setSize(bb.size() + QSize(2 * borderWidth, 2 * borderWidth));
+ m_shape->setSize(m_rect.size());
+ m_shape->setOpacity(m_rect.zoomLevelOpacity());
+ m_shape->setVisible(true);
+
+ m_rect.setPositionOnMap(m_geometry.origin(), -1 * bb.topLeft() + QPointF(borderWidth, borderWidth));
+#else
+ const QRectF combined = QGeoMapItemGeometry::translateToCommonOrigin(geoms);
m_rect.setWidth(combined.width() + 2 * m_rect.m_border.width()); // ToDo: fix this! 2 is incorrect
m_rect.setHeight(combined.height() + 2 * m_rect.m_border.width());
-
m_rect.setPositionOnMap(m_geometry.origin(), m_geometry.firstPointOffset());
+#endif
}
QSGNode *QDeclarativeRectangleMapItemPrivateCPU::updateMapItemPaintNode(QSGNode *oldNode,
QQuickItem::UpdatePaintNodeData *data)
{
Q_UNUSED(data);
+#ifdef MAPITEMS_USE_SHAPES
+ delete oldNode;
+ if (m_geometry.isScreenDirty() || m_rect.m_dirtyMaterial) {
+ m_geometry.setPreserveGeometry(false);
+ m_geometry.markClean();
+ m_rect.m_dirtyMaterial = false;
+ }
+ return nullptr;
+#else
if (!m_node || !oldNode) {
m_node = new MapPolygonNode();
if (oldNode) {
@@ -394,12 +462,18 @@ QSGNode *QDeclarativeRectangleMapItemPrivateCPU::updateMapItemPaintNode(QSGNode
m_borderGeometry.markClean();
m_rect.m_dirtyMaterial = false;
}
+
return m_node;
+#endif
}
bool QDeclarativeRectangleMapItemPrivateCPU::contains(const QPointF &point) const
{
+#ifdef MAPITEMS_USE_SHAPES
+ return m_shape->contains(m_rect.mapToItem(m_shape, point));
+#else
return (m_geometry.contains(point) || m_borderGeometry.contains(point));
+#endif
}
QT_END_NAMESPACE