summaryrefslogtreecommitdiff
path: root/src/location/declarativemaps/qdeclarativegeomap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/location/declarativemaps/qdeclarativegeomap.cpp')
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap.cpp207
1 files changed, 94 insertions, 113 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp
index 34885f54..b9f62fad 100644
--- a/src/location/declarativemaps/qdeclarativegeomap.cpp
+++ b/src/location/declarativemaps/qdeclarativegeomap.cpp
@@ -51,6 +51,7 @@
#include <QtQuick/QSGRectangleNode>
#include <QtQuick/private/qquickwindow_p.h>
#include <QtQml/qqmlinfo.h>
+#include <QtQuick/private/qquickitem_p.h>
#include <cmath>
#ifndef M_PI
@@ -187,8 +188,6 @@ QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent)
setFlags(QQuickItem::ItemHasContents | QQuickItem::ItemClipsChildrenToShape);
setFiltersChildMouseEvents(true);
- connect(this, SIGNAL(childrenChanged()), this, SLOT(onMapChildrenChanged()), Qt::QueuedConnection);
-
m_activeMapType = new QDeclarativeGeoMapType(QGeoMapType(QGeoMapType::NoMap,
tr("No Map"),
tr("No Map"),
@@ -254,77 +253,13 @@ QDeclarativeGeoMap::~QDeclarativeGeoMap()
}
m_mapItemGroups.clear();
- delete m_copyrights.data();
+ if (m_copyrights.data())
+ delete m_copyrights.data();
m_copyrights.clear();
delete m_map;
}
-/*!
- \internal
-*/
-void QDeclarativeGeoMap::onMapChildrenChanged()
-{
- if (!m_componentCompleted || !m_map)
- return;
-
- int maxChildZ = 0;
- QObjectList kids = children();
- bool foundCopyrights = false;
-
- for (int i = 0; i < kids.size(); ++i) {
- QDeclarativeGeoMapCopyrightNotice *copyrights = qobject_cast<QDeclarativeGeoMapCopyrightNotice *>(kids.at(i));
- if (copyrights) {
- foundCopyrights = true;
- } else {
- QDeclarativeGeoMapItemBase *mapItem = qobject_cast<QDeclarativeGeoMapItemBase *>(kids.at(i));
- if (mapItem) {
- if (mapItem->z() > maxChildZ)
- maxChildZ = mapItem->z();
- }
- }
- }
-
- QDeclarativeGeoMapCopyrightNotice *copyrights = m_copyrights.data();
- // if copyrights object not found within the map's children
- if (!foundCopyrights) {
- // if copyrights object was deleted!
- if (!copyrights) {
- // create a new one and set its parent, re-assign it to the weak pointer, then connect the copyrights-change signal
- m_copyrights = new QDeclarativeGeoMapCopyrightNotice(this);
- m_copyrights->onCopyrightsStyleSheetChanged(m_map->copyrightsStyleSheet());
-
- copyrights = m_copyrights.data();
-
- connect(m_map, SIGNAL(copyrightsChanged(QImage)),
- copyrights, SLOT(copyrightsChanged(QImage)));
- connect(m_map, SIGNAL(copyrightsChanged(QImage)),
- this, SIGNAL(copyrightsChanged(QImage)));
-
- connect(m_map, SIGNAL(copyrightsChanged(QString)),
- copyrights, SLOT(copyrightsChanged(QString)));
- connect(m_map, SIGNAL(copyrightsChanged(QString)),
- this, SIGNAL(copyrightsChanged(QString)));
-
- connect(m_map, SIGNAL(copyrightsStyleSheetChanged(QString)),
- copyrights, SLOT(onCopyrightsStyleSheetChanged(QString)));
-
- connect(copyrights, SIGNAL(linkActivated(QString)),
- this, SIGNAL(copyrightLinkActivated(QString)));
-
- // set visibility of copyright notice
- copyrights->setCopyrightsVisible(m_copyrightsVisible);
-
- } else {
- // just re-set its parent.
- copyrights->setParent(this);
- }
- }
-
- // put the copyrights notice object at the highest z order
- copyrights->setCopyrightsZ(maxChildZ + 1);
-}
-
static QDeclarativeGeoMapType *findMapType(const QList<QDeclarativeGeoMapType *> &types, const QGeoMapType &type)
{
for (int i = 0; i < types.size(); ++i)
@@ -438,7 +373,7 @@ void QDeclarativeGeoMap::initialize()
emit mapReadyChanged(true);
- if (m_copyrights)
+ if (m_copyrights) // To not update during initialize()
update();
}
@@ -735,7 +670,6 @@ void QDeclarativeGeoMap::onCameraCapabilitiesChanged(const QGeoCameraCapabilitie
}
}
-
/*!
\internal
this function will only be ever called once
@@ -747,6 +681,12 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
if (!m_map)
return;
+ /* COPY NOTICE SETUP */
+ m_copyrights = new QDeclarativeGeoMapCopyrightNotice(this);
+ m_copyrights->setCopyrightsZ(m_maxChildZ + 1);
+ m_copyrights->setCopyrightsVisible(m_copyrightsVisible);
+ m_copyrights->setMapSource(this);
+
m_gestureArea->setMap(m_map);
QList<QGeoMapType> types = m_mappingManager->supportedMapTypes();
@@ -795,40 +735,26 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
QOverload<const QImage &>::of(&QGeoMap::copyrightsChanged),
[&copyrightImage](const QImage &copy){ copyrightImage = copy; });
m_map->setViewportSize(QSize(width(), height()));
- initialize();
+ initialize(); // This emits the caught signals above
QObject::disconnect(copyrightStringCatcherConnection);
QObject::disconnect(copyrightImageCatcherConnection);
}
- m_copyrights = new QDeclarativeGeoMapCopyrightNotice(this);
- m_copyrights->onCopyrightsStyleSheetChanged(m_map->copyrightsStyleSheet());
- connect(m_map, SIGNAL(copyrightsChanged(QImage)),
- m_copyrights.data(), SLOT(copyrightsChanged(QImage)));
+ /* COPYRIGHT SIGNALS REWIRING */
connect(m_map, SIGNAL(copyrightsChanged(QImage)),
this, SIGNAL(copyrightsChanged(QImage)));
-
- connect(m_map, SIGNAL(copyrightsChanged(QString)),
- m_copyrights.data(), SLOT(copyrightsChanged(QString)));
connect(m_map, SIGNAL(copyrightsChanged(QString)),
this, SIGNAL(copyrightsChanged(QString)));
-
if (!copyrightString.isEmpty())
emit m_map->copyrightsChanged(copyrightString);
else if (!copyrightImage.isNull())
emit m_map->copyrightsChanged(copyrightImage);
- connect(m_map, SIGNAL(copyrightsStyleSheetChanged(QString)),
- m_copyrights.data(), SLOT(onCopyrightsStyleSheetChanged(QString)));
- connect(m_copyrights.data(), SIGNAL(linkActivated(QString)),
- this, SIGNAL(copyrightLinkActivated(QString)));
connect(m_map, &QGeoMap::sgNodeChanged, this, &QQuickItem::update);
connect(m_map, &QGeoMap::cameraCapabilitiesChanged, this, &QDeclarativeGeoMap::onCameraCapabilitiesChanged);
- // set visibility of copyright notice
- m_copyrights->setCopyrightsVisible(m_copyrightsVisible);
-
// This prefetches a buffer around the map
m_map->prefetchData();
@@ -1152,7 +1078,7 @@ void QDeclarativeGeoMap::setMinimumFieldOfView(qreal minimumFieldOfView, bool us
}
/*!
- \qmlproperty bool QtLocation::Map::minimumFieldOfView
+ \qmlproperty real QtLocation::Map::minimumFieldOfView
This property holds the minimum valid field of view for the map, in degrees.
@@ -1189,7 +1115,7 @@ void QDeclarativeGeoMap::setMaximumFieldOfView(qreal maximumFieldOfView, bool us
}
/*!
- \qmlproperty bool QtLocation::Map::maximumFieldOfView
+ \qmlproperty real QtLocation::Map::maximumFieldOfView
This property holds the maximum valid field of view for the map, in degrees.
@@ -1207,7 +1133,7 @@ qreal QDeclarativeGeoMap::maximumFieldOfView() const
}
/*!
- \qmlproperty bool QtLocation::Map::minimumTilt
+ \qmlproperty real QtLocation::Map::minimumTilt
This property holds the minimum valid tilt for the map, in degrees.
@@ -1244,7 +1170,7 @@ void QDeclarativeGeoMap::setMaximumTilt(qreal maximumTilt, bool userSet)
}
/*!
- \qmlproperty bool QtLocation::Map::maximumTilt
+ \qmlproperty real QtLocation::Map::maximumTilt
This property holds the maximum valid tilt for the map, in degrees.
@@ -1412,7 +1338,7 @@ QColor QDeclarativeGeoMap::color() const
}
/*!
- \qmlproperty color QtLocation::Map::mapReady
+ \qmlproperty bool QtLocation::Map::mapReady
This property holds whether the map has been successfully initialized and is ready to be used.
Some methods, such as \l fromCoordinate and \l toCoordinate, will not work before the map is ready.
@@ -1647,6 +1573,27 @@ QGeoServiceProvider::Error QDeclarativeGeoMap::error() const
return m_error;
}
+void QDeclarativeGeoMap::itemChange(ItemChange change, const ItemChangeData &value)
+{
+ if (change == ItemChildAddedChange) {
+ QQuickItem *child = value.item;
+ QQuickItem *mapItem = qobject_cast<QDeclarativeGeoMapItemBase *>(child);
+ if (!mapItem)
+ mapItem = qobject_cast<QDeclarativeGeoMapItemGroup *>(child);
+
+ if (mapItem) {
+ qreal z = mapItem->z();
+ if (z > m_maxChildZ) { // Ignore children removal
+ m_maxChildZ = z;
+ // put the copyrights notice object at the highest z order
+ if (m_copyrights)
+ m_copyrights->setCopyrightsZ(m_maxChildZ + 1);
+ }
+ }
+ }
+ QQuickItem::itemChange(change, value);
+}
+
/*!
\internal
*/
@@ -1679,6 +1626,32 @@ bool QDeclarativeGeoMap::isInteractive()
return (m_gestureArea->enabled() && m_gestureArea->acceptedGestures()) || m_gestureArea->isActive();
}
+void QDeclarativeGeoMap::attachCopyrightNotice(bool initialVisibility)
+{
+ if (initialVisibility) {
+ ++m_copyNoticesVisible;
+ if (m_map)
+ m_map->setCopyrightVisible(m_copyNoticesVisible > 0);
+ }
+}
+
+void QDeclarativeGeoMap::detachCopyrightNotice(bool currentVisibility)
+{
+ if (currentVisibility) {
+ --m_copyNoticesVisible;
+ if (m_map)
+ m_map->setCopyrightVisible(m_copyNoticesVisible > 0);
+ }
+}
+
+void QDeclarativeGeoMap::onAttachedCopyrightNoticeVisibilityChanged()
+{
+ QDeclarativeGeoMapCopyrightNotice *copy = static_cast<QDeclarativeGeoMapCopyrightNotice *>(sender());
+ m_copyNoticesVisible += ( int(copy->copyrightsVisible()) * 2 - 1);
+ if (m_map)
+ m_map->setCopyrightVisible(m_copyNoticesVisible > 0);
+}
+
/*!
\internal
*/
@@ -2129,10 +2102,10 @@ void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine, bool onlyVisib
if (m_mapItems.size() == 0)
return;
- double minX = 0;
- double maxX = 0;
- double minY = 0;
- double maxY = 0;
+ double minX = qInf();
+ double maxX = -qInf();
+ double minY = qInf();
+ double maxY = -qInf();
double topLeftX = 0;
double topLeftY = 0;
double bottomRightX = 0;
@@ -2149,13 +2122,11 @@ void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine, bool onlyVisib
continue;
// skip quick items in the first pass and refine the fit later
- if (refine) {
- QDeclarativeGeoMapQuickItem *quickItem =
- qobject_cast<QDeclarativeGeoMapQuickItem*>(item);
- if (quickItem) {
+ QDeclarativeGeoMapQuickItem *quickItem =
+ qobject_cast<QDeclarativeGeoMapQuickItem*>(item);
+ if (refine && quickItem) {
haveQuickItem = true;
continue;
- }
}
// Force map items to update immediately. Needed to ensure correct item size and positions
// when recursively calling this function.
@@ -2163,25 +2134,35 @@ void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine, bool onlyVisib
// in relation to
// a) fitViewportToMapItems
// b) presence of MouseArea
+ //
+ // This is also legacy code. It must be updated to not operate on screen sizes.
if (item->isPolishScheduled())
item->updatePolish();
- topLeftX = item->position().x();
- topLeftY = item->position().y();
- bottomRightX = topLeftX + item->width();
- bottomRightY = topLeftY + item->height();
+ if (quickItem && quickItem->matrix_ && !quickItem->matrix_->m_matrix.isIdentity()) {
+ // TODO: recalculate the center/zoom level so that the item becomes projectable again
+ if (quickItem->zoomLevel() == 0.0) // the item is unprojectable, should be skipped.
+ continue;
- if (itemCount == 0) {
- minX = topLeftX;
- maxX = bottomRightX;
- minY = topLeftY;
- maxY = bottomRightY;
+ QRectF brect = item->boundingRect();
+ brect = quickItem->matrix_->m_matrix.mapRect(brect);
+ QPointF transformedPosition = quickItem->matrix_->m_matrix * item->position();
+ topLeftX = transformedPosition.x();
+ topLeftY = transformedPosition.y();
+ bottomRightX = topLeftX + brect.width();
+ bottomRightY = topLeftY + brect.height();
} else {
- minX = qMin(minX, topLeftX);
- maxX = qMax(maxX, bottomRightX);
- minY = qMin(minY, topLeftY);
- maxY = qMax(maxY, bottomRightY);
+ topLeftX = item->position().x();
+ topLeftY = item->position().y();
+ bottomRightX = topLeftX + item->width();
+ bottomRightY = topLeftY + item->height();
}
+
+ minX = qMin(minX, topLeftX);
+ maxX = qMax(maxX, bottomRightX);
+ minY = qMin(minY, topLeftY);
+ maxY = qMax(maxY, bottomRightY);
+
++itemCount;
}