summaryrefslogtreecommitdiff
path: root/src/location/declarativemaps/qdeclarativegeomap.cpp
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli.qt@gmail.com>2019-11-27 15:37:07 +0100
committerpaolo <paolo.angelelli.qt@gmail.com>2020-02-11 11:46:08 +0100
commitd055098540df99a5d426360e9322c659e678e5ee (patch)
treee7e43a057b7e06814e2ef11eeddc52a4aac06cdb /src/location/declarativemaps/qdeclarativegeomap.cpp
parent614d67be158e3ef8443c1b7f3126303cfcf4becc (diff)
downloadqtlocation-d055098540df99a5d426360e9322c659e678e5ee.tar.gz
Enable mercator-to-screen projection in GLSL
With this change, all the geo-to-screen conversion, and the triangulation operations for geo polylines and geo polygon are performed either at set time or in the shader. A separate bounding box geometry is processed in the old way to provide a correct QtQuick Item geometry, that can be used for nesting mouse areas, performing translations, input event delivery, etc. With this approach, performance are improved by more than one order of magnitude in average, but complex geometries will of course benefit more. It also adds correct rendering support for polygons with holes, previously only rendered correctly by the MapboxGL plugin. The polyline shader has basic miter joins. The miter is skipped if the angle is too sharp to avoid complicating the implementation. This shader introduces some glitches when the polyline is minified, for which the real fix is to have LOD for the geometry, and render simplified geometries at low zoom levels (added in a subsequent patch). Note: this approach, at least in its current implementation, does not support enabling layers on individual items, only on the Map element. Task-number: QTBUG-49303 Task-number: QTBUG-38459 Change-Id: I0c2dc0bf364d32f74ca7c4014f6d66e6219c8ae4 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'src/location/declarativemaps/qdeclarativegeomap.cpp')
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp
index 6a2d82e8..fc282829 100644
--- a/src/location/declarativemaps/qdeclarativegeomap.cpp
+++ b/src/location/declarativemaps/qdeclarativegeomap.cpp
@@ -198,7 +198,7 @@ QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent)
setAcceptHoverEvents(false);
setAcceptedMouseButtons(Qt::LeftButton);
setFlags(QQuickItem::ItemHasContents | QQuickItem::ItemClipsChildrenToShape);
- setFiltersChildMouseEvents(true);
+ setFiltersChildMouseEvents(true); // needed for childMouseEventFilter to work.
m_activeMapType = new QDeclarativeGeoMapType(QGeoMapType(QGeoMapType::NoMap,
tr("No Map"),
@@ -707,7 +707,8 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
emit m_map->copyrightsChanged(copyrightImage);
- connect(m_map.data(), &QGeoMap::sgNodeChanged, this, &QQuickItem::update);
+ connect(window(), &QQuickWindow::beforeSynchronizing, this, &QDeclarativeGeoMap::updateItemToWindowTransform, Qt::DirectConnection);
+ connect(m_map.data(), &QGeoMap::sgNodeChanged, this, &QDeclarativeGeoMap::onSGNodeChanged);
connect(m_map.data(), &QGeoMap::cameraCapabilitiesChanged, this, &QDeclarativeGeoMap::onCameraCapabilitiesChanged);
// This prefetches a buffer around the map
@@ -2175,6 +2176,38 @@ bool QDeclarativeGeoMap::removeMapItemView_real(QDeclarativeGeoMapItemView *item
return removeMapItemGroup_real(itemView); // at this point, all delegate instances have been removed.
}
+void QDeclarativeGeoMap::updateItemToWindowTransform()
+{
+ if (!m_initialized)
+ return;
+
+ // Update itemToWindowTransform into QGeoProjection
+ const QTransform item2WindowOld = m_map->geoProjection().itemToWindowTransform();
+ QTransform item2Window = QQuickItemPrivate::get(this)->itemToWindowTransform();
+ if (!property("layer").isNull() && property("layer").value<QObject *>()->property("enabled").toBool())
+ item2Window.reset(); // When layer is enabled, the item is rendered offscreen with no transformation, then the layer is applied
+
+ m_map->setItemToWindowTransform(item2Window);
+
+ // This method is called at every redraw, including those redraws not generated by
+ // sgNodeChanged.
+ // In these cases, *if* the item2windowTransform has changed (e.g., if transformation of
+ // the item or one of its ancestors changed), a forced update of the map items using accelerated
+ // GL implementation has to be performed in order to have them pulling the updated itemToWindowTransform.
+ if (!m_sgNodeHasChanged && item2WindowOld != item2Window) {
+ for (auto i: qAsConst(m_mapItems))
+ i->setMaterialDirty();
+ }
+
+ m_sgNodeHasChanged = false;
+}
+
+void QDeclarativeGeoMap::onSGNodeChanged()
+{
+ m_sgNodeHasChanged = true;
+ update();
+}
+
/*!
\qmlmethod void QtLocation::Map::addMapItemView(MapItemView itemView)