summaryrefslogtreecommitdiff
path: root/src/location/labs
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
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')
-rw-r--r--src/location/labs/labs.pri1
-rw-r--r--src/location/labs/qdeclarativenavigator.cpp37
-rw-r--r--src/location/labs/qdeclarativenavigator_p.h2
-rw-r--r--src/location/labs/qdeclarativenavigator_p_p.h13
4 files changed, 45 insertions, 8 deletions
diff --git a/src/location/labs/labs.pri b/src/location/labs/labs.pri
index 2da5e90d..79a22700 100644
--- a/src/location/labs/labs.pri
+++ b/src/location/labs/labs.pri
@@ -1,3 +1,4 @@
+QT += positioningquick-private
INCLUDEPATH += labs
PRIVATE_HEADERS += $$files($$PWD/*.h) $$files($$PWD/qsg/*.h)
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
diff --git a/src/location/labs/qdeclarativenavigator_p.h b/src/location/labs/qdeclarativenavigator_p.h
index 3c9a4653..0373bf57 100644
--- a/src/location/labs/qdeclarativenavigator_p.h
+++ b/src/location/labs/qdeclarativenavigator_p.h
@@ -136,6 +136,8 @@ private slots:
private:
QScopedPointer<QDeclarativeNavigatorPrivate> d_ptr;
+
+ friend class QDeclarativeNavigatorPrivate;
};
QT_END_NAMESPACE
diff --git a/src/location/labs/qdeclarativenavigator_p_p.h b/src/location/labs/qdeclarativenavigator_p_p.h
index 0485ee69..c4198714 100644
--- a/src/location/labs/qdeclarativenavigator_p_p.h
+++ b/src/location/labs/qdeclarativenavigator_p_p.h
@@ -50,6 +50,8 @@
#include <QtCore/qlist.h>
#include <QtLocation/private/qlocationglobal_p.h>
+#include <QtCore/qpointer.h>
+#include <QtLocation/qgeoroute.h>
QT_BEGIN_NAMESPACE
@@ -67,13 +69,16 @@ class Q_LOCATION_PRIVATE_EXPORT QDeclarativeNavigatorPrivate
public:
QDeclarativeNavigatorPrivate(QParameterizableObject *q_);
+ void updateReadyState();
+
QParameterizableObject *q = nullptr;
QNavigationManager *m_navigationManager = nullptr;
QDeclarativeGeoServiceProvider *m_plugin = nullptr;
- QDeclarativeGeoMap *m_map = nullptr;
- QDeclarativeGeoRoute *m_route = nullptr;
- QDeclarativePositionSource *m_positionSource = nullptr;
- QDeclarativeGeoRoute *m_currentRoute = nullptr;
+ QPointer<QDeclarativeGeoMap> m_map;
+ QPointer<QDeclarativeGeoRoute> m_route;
+ QGeoRoute m_geoRoute;
+ QPointer<QDeclarativePositionSource> m_positionSource;
+ QPointer<QDeclarativeGeoRoute> m_currentRoute;
QList<QGeoMapParameter *> m_parameters;
int m_currentSegment = 0;
bool m_active = false;