summaryrefslogtreecommitdiff
path: root/src/location/declarativemaps/qdeclarativegeomapquickitem.cpp
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2017-02-24 00:01:08 +0100
committerPaolo Angelelli <paolo.angelelli@qt.io>2017-03-08 10:00:49 +0000
commit919c4415d0dc06177d8f3c2a300549d62a8dcdd4 (patch)
tree4dae16cee274abc4910474f8a8c4be0fda09a0bc /src/location/declarativemaps/qdeclarativegeomapquickitem.cpp
parent34c474703f6761a2dafecb219da51c66ebd4709a (diff)
downloadqtlocation-919c4415d0dc06177d8f3c2a300549d62a8dcdd4.tar.gz
Fix MapQuickItem when zoomLevel is set
This patch fixes the behavior of MapQuickItem when the zoomLevel is set, that is it makes behave the qquickitem as if it would be on the map, instead of on the screen. Change-Id: Ibb8a6000e2f6a37a68c32df001fc8565079a6f70 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/location/declarativemaps/qdeclarativegeomapquickitem.cpp')
-rw-r--r--src/location/declarativemaps/qdeclarativegeomapquickitem.cpp41
1 files changed, 36 insertions, 5 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomapquickitem.cpp b/src/location/declarativemaps/qdeclarativegeomapquickitem.cpp
index 4fab18cb..5a10f39f 100644
--- a/src/location/declarativemaps/qdeclarativegeomapquickitem.cpp
+++ b/src/location/declarativemaps/qdeclarativegeomapquickitem.cpp
@@ -115,9 +115,25 @@ QT_BEGIN_NAMESPACE
\image api-mapquickitem.png
*/
+QMapQuickItemMatrix4x4::QMapQuickItemMatrix4x4(QObject *parent) : QQuickTransform(parent) { }
+
+void QMapQuickItemMatrix4x4::setMatrix(const QMatrix4x4 &matrix)
+{
+ if (m_matrix == matrix)
+ return;
+ m_matrix = matrix;
+ update();
+}
+
+void QMapQuickItemMatrix4x4::applyTo(QMatrix4x4 *matrix) const
+{
+ *matrix *= m_matrix;
+}
+
+
QDeclarativeGeoMapQuickItem::QDeclarativeGeoMapQuickItem(QQuickItem *parent)
: QDeclarativeGeoMapItemBase(parent), zoomLevel_(0.0),
- mapAndSourceItemSet_(false), updatingGeometry_(false)
+ mapAndSourceItemSet_(false), updatingGeometry_(false), matrix_(nullptr)
{
setFlag(ItemHasContents, true);
opacityContainer_ = new QQuickItem(this);
@@ -177,7 +193,13 @@ void QDeclarativeGeoMapQuickItem::geometryChanged(const QRectF &newGeometry, con
return;
}
- QGeoCoordinate newCoordinate = map()->geoProjection().itemPositionToCoordinate(QDoubleVector2D(x(), y()) + (scaleFactor() * QDoubleVector2D(anchorPoint_)), false);
+ QGeoCoordinate newCoordinate;
+ // with zoomLevel set the anchorPoint has to be factored into the transformation to properly transform around it.
+ if (zoomLevel_ != 0.0)
+ newCoordinate = map()->geoProjection().itemPositionToCoordinate(QDoubleVector2D(x(), y()), false);
+ else
+ newCoordinate = map()->geoProjection().itemPositionToCoordinate(QDoubleVector2D(x(), y()) + QDoubleVector2D(anchorPoint_), false);
+
if (newCoordinate.isValid())
setCoordinate(newCoordinate);
@@ -337,11 +359,20 @@ void QDeclarativeGeoMapQuickItem::updatePolish()
opacityContainer_->setOpacity(zoomLevelOpacity());
- sourceItem_.data()->setScale(scaleFactor());
- sourceItem_.data()->setPosition(QPointF(0,0));
setWidth(sourceItem_.data()->width());
setHeight(sourceItem_.data()->height());
- setPositionOnMap(coordinate(), scaleFactor() * anchorPoint_);
+ if (zoomLevel_ != 0.0) { // zoom level initialized to 0.0. If it's different, it has been set explicitly.
+ if (!matrix_) {
+ matrix_ = new QMapQuickItemMatrix4x4(this);
+ matrix_->appendToItem(opacityContainer_);
+ }
+ matrix_->setMatrix(map()->geoProjection().quickItemTransformation(coordinate(), anchorPoint_, zoomLevel_));
+ setPositionOnMap(coordinate(), QPointF(0,0));
+ } else {
+ if (matrix_)
+ matrix_->setMatrix(QMatrix4x4());
+ setPositionOnMap(coordinate(), anchorPoint_);
+ }
}
/*!