summaryrefslogtreecommitdiff
path: root/src/location/labs/qdeclarativenavigator.cpp
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2018-05-31 10:44:12 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2018-06-08 09:22:01 +0000
commite45ded979d7838847b7fe057f0a2d6c15b517de2 (patch)
tree63fab46ba63a7b96183e1634d77fb94bab8debcb /src/location/labs/qdeclarativenavigator.cpp
parent1768efa1761ec8fb54a734a4297a29b3d591d8ae (diff)
downloadqtlocation-e45ded979d7838847b7fe057f0a2d6c15b517de2.tar.gz
Use QPointer to avoid dangling QDeclarativeGeoRoute in NavigatorPrivate
QDeclarativeNavigator::setRoute takes a QDeclarativeGeoRoute. This type is not COW, and could be destroyed by the user or the route model. This patch stores it inside a QPointer. It also stores the contained QGeoRoute, that is what the navigation engines are supposed to use to perform navigation, and is COW. Task-number: QTBUG-68536 Change-Id: I73fb79faeb3ac9efefcbd778ee106d29fbf26658 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/location/labs/qdeclarativenavigator.cpp')
-rw-r--r--src/location/labs/qdeclarativenavigator.cpp37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/location/labs/qdeclarativenavigator.cpp b/src/location/labs/qdeclarativenavigator.cpp
index bcb74c90..5fe36bb8 100644
--- a/src/location/labs/qdeclarativenavigator.cpp
+++ b/src/location/labs/qdeclarativenavigator.cpp
@@ -37,6 +37,7 @@
#include <QtLocation/private/qdeclarativegeoroute_p.h>
#include <QtLocation/private/qdeclarativegeoroutemodel_p.h>
#include <QtLocation/private/qdeclarativegeoroutesegment_p.h>
+#include <QtPositioningQuick/private/qdeclarativepositionsource_p.h>
#include <QtQml/qqmlinfo.h>
QT_BEGIN_NAMESPACE
@@ -165,6 +166,12 @@ QDeclarativeNavigatorPrivate::QDeclarativeNavigatorPrivate(QParameterizableObjec
{
}
+void QDeclarativeNavigatorPrivate::updateReadyState()
+{
+ qobject_cast<QDeclarativeNavigator *>(q)->updateReadyState();
+}
+
+
QDeclarativeNavigator::QDeclarativeNavigator(QObject *parent)
: QParameterizableObject(parent), d_ptr(new QDeclarativeNavigatorPrivate(this))
@@ -195,10 +202,16 @@ QDeclarativeGeoServiceProvider *QDeclarativeNavigator::plugin() const
void QDeclarativeNavigator::setMap(QDeclarativeGeoMap *map)
{
- if (d_ptr->m_map) // set once prop
+ if (d_ptr->m_map || !map) // set once prop
return;
d_ptr->m_map = map;
+ QDeclarativeNavigatorPrivate *dptr = d_ptr.data();
+ connect(map, &QObject::destroyed,
+ [this, dptr]() {
+ this->mapChanged();
+ dptr->updateReadyState();
+ });
emit mapChanged();
updateReadyState();
}
@@ -219,6 +232,15 @@ void QDeclarativeNavigator::setRoute(QDeclarativeGeoRoute *route)
setActive(false); // Stop current session
d_ptr->m_route = route;
+ d_ptr->m_geoRoute = route ? route->route() : QGeoRoute();
+ if (route) {
+ connect(route, &QObject::destroyed,
+ [this]() {
+ // Do not stop navigation if route disappears. d_ptr->m_geoRoute will still be valid.
+ // Engines can stop navigation if desired.
+ this->routeChanged();
+ });
+ }
emit routeChanged();
updateReadyState();
}
@@ -230,10 +252,17 @@ QDeclarativeGeoRoute *QDeclarativeNavigator::route() const
void QDeclarativeNavigator::setPositionSource(QDeclarativePositionSource *positionSource)
{
- if (d_ptr->m_positionSource) // set once prop
+ if (d_ptr->m_positionSource || !positionSource) // set once prop
return;
d_ptr->m_positionSource = positionSource;
+ QDeclarativeNavigatorPrivate *dptr = d_ptr.data();
+ QObject::connect(positionSource, &QObject::destroyed,
+ [this, dptr]() {
+ this->positionSourceChanged();
+ dptr->updateReadyState();
+ }
+ );
emit positionSourceChanged();
updateReadyState();
}
@@ -258,8 +287,8 @@ bool QDeclarativeNavigator::navigatorReady() const
QDeclarativeGeoRoute *QDeclarativeNavigator::currentRoute() const
{
if (!d_ptr->m_ready || !d_ptr->m_navigationManager->active())
- return d_ptr->m_route;
- return d_ptr->m_currentRoute;
+ return d_ptr->m_route.data();
+ return d_ptr->m_currentRoute.data();
}
int QDeclarativeNavigator::currentSegment() const