summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-06-12 03:00:35 +0200
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-06-12 03:00:36 +0200
commit7a7d355ac603283d05610e584d7c923e1d4caae0 (patch)
tree2b1e0991391b4fea05c9830e3831712bc0d6d26e /src
parentaff3782a97cb7b120b5586194acd1816c08abe79 (diff)
parent71bc98bf309ce433afb80344a7356e13b310c5c5 (diff)
downloadqtlocation-7a7d355ac603283d05610e584d7c923e1d4caae0.tar.gz
Merge remote-tracking branch 'origin/5.11' into dev
Change-Id: Id27e5a31f3a72eac38b976d546a1f733226cd5ae
Diffstat (limited to 'src')
-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
-rw-r--r--src/location/maps/qgeoroute.cpp4
-rw-r--r--src/location/maps/qgeorouterequest.cpp5
-rw-r--r--src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp56
-rw-r--r--src/plugins/position/position.pro2
-rw-r--r--src/positioning/qlocationutils.cpp63
-rw-r--r--src/positioning/qlocationutils_p.h36
-rw-r--r--src/src.pro2
11 files changed, 151 insertions, 70 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;
diff --git a/src/location/maps/qgeoroute.cpp b/src/location/maps/qgeoroute.cpp
index 979c1667..8d62dceb 100644
--- a/src/location/maps/qgeoroute.cpp
+++ b/src/location/maps/qgeoroute.cpp
@@ -340,8 +340,8 @@ bool QGeoRoutePrivate::equals(const QGeoRoutePrivate &other) const
&& (travelTime() == other.travelTime())
&& (distance() == other.distance())
&& (travelMode() == other.travelMode())
- && (path() == other.path()))
- && (metadata() == other.metadata());
+ && (path() == other.path())
+ && (metadata() == other.metadata()));
}
void QGeoRoutePrivate::setId(const QString &id)
diff --git a/src/location/maps/qgeorouterequest.cpp b/src/location/maps/qgeorouterequest.cpp
index a252b101..57fbe207 100644
--- a/src/location/maps/qgeorouterequest.cpp
+++ b/src/location/maps/qgeorouterequest.cpp
@@ -263,7 +263,8 @@ QGeoRouteRequest &QGeoRouteRequest::operator= (const QGeoRouteRequest & other)
*/
bool QGeoRouteRequest::operator ==(const QGeoRouteRequest &other) const
{
- return (d_ptr.constData() == other.d_ptr.constData());
+ return ( (d_ptr.constData() == other.d_ptr.constData())
+ || (*d_ptr) == (*other.d_ptr));
}
/*!
@@ -271,7 +272,7 @@ bool QGeoRouteRequest::operator ==(const QGeoRouteRequest &other) const
*/
bool QGeoRouteRequest::operator !=(const QGeoRouteRequest &other) const
{
- return (d_ptr.constData() != other.d_ptr.constData());
+ return !(operator==(other));
}
/*!
diff --git a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp
index 964f94f5..6c47d3ee 100644
--- a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp
+++ b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp
@@ -45,14 +45,14 @@
namespace {
-QString formatPropertyName(QString *name)
+QByteArray formatPropertyName(const QByteArray &name)
{
+ QString nameAsString = QString::fromLatin1(name);
static const QRegularExpression camelCaseRegex(QStringLiteral("([a-z0-9])([A-Z])"));
-
- return name->replace(camelCaseRegex, QStringLiteral("\\1-\\2")).toLower();
+ return nameAsString.replace(camelCaseRegex, QStringLiteral("\\1-\\2")).toLower().toLatin1();
}
-bool isImmutableProperty(const QString &name)
+bool isImmutableProperty(const QByteArray &name)
{
return name == QStringLiteral("type") || name == QStringLiteral("layer");
}
@@ -167,6 +167,16 @@ QMapbox::Feature featureFromMapItem(QDeclarativeGeoMapItemBase *item)
}
}
+QList<QByteArray> getAllPropertyNamesList(QObject *object)
+{
+ const QMetaObject *metaObject = object->metaObject();
+ QList<QByteArray> propertyNames(object->dynamicPropertyNames());
+ for (int i = metaObject->propertyOffset(); i < metaObject->propertyCount(); ++i) {
+ propertyNames.append(metaObject->property(i).name());
+ }
+ return propertyNames;
+}
+
} // namespace
@@ -261,22 +271,20 @@ QList<QSharedPointer<QMapboxGLStyleChange>> QMapboxGLStyleSetLayoutProperty::fro
QList<QSharedPointer<QMapboxGLStyleChange>> changes;
- // Offset objectName and type properties.
- for (int i = 2; i < param->metaObject()->propertyCount(); ++i) {
- QString name = param->metaObject()->property(i).name();
-
- if (isImmutableProperty(name))
+ QList<QByteArray> propertyNames = getAllPropertyNamesList(param);
+ for (const QByteArray &propertyName : propertyNames) {
+ if (isImmutableProperty(propertyName))
continue;
auto layout = new QMapboxGLStyleSetLayoutProperty();
- layout->m_value = param->property(name.toLatin1());
+ layout->m_value = param->property(propertyName);
if (layout->m_value.canConvert<QJSValue>()) {
layout->m_value = layout->m_value.value<QJSValue>().toVariant();
}
layout->m_layer = param->property("layer").toString();
- layout->m_property = formatPropertyName(&name);
+ layout->m_property = formatPropertyName(propertyName);
changes << QSharedPointer<QMapboxGLStyleChange>(layout);
}
@@ -340,22 +348,20 @@ QList<QSharedPointer<QMapboxGLStyleChange>> QMapboxGLStyleSetPaintProperty::from
QList<QSharedPointer<QMapboxGLStyleChange>> changes;
- // Offset objectName and type properties.
- for (int i = 2; i < param->metaObject()->propertyCount(); ++i) {
- QString name = param->metaObject()->property(i).name();
-
- if (isImmutableProperty(name))
+ QList<QByteArray> propertyNames = getAllPropertyNamesList(param);
+ for (const QByteArray &propertyName : propertyNames) {
+ if (isImmutableProperty(propertyName))
continue;
auto paint = new QMapboxGLStyleSetPaintProperty();
- paint->m_value = param->property(name.toLatin1());
+ paint->m_value = param->property(propertyName);
if (paint->m_value.canConvert<QJSValue>()) {
paint->m_value = paint->m_value.value<QJSValue>().toVariant();
}
paint->m_layer = param->property("layer").toString();
- paint->m_property = formatPropertyName(&name);
+ paint->m_property = formatPropertyName(propertyName);
changes << QSharedPointer<QMapboxGLStyleChange>(paint);
}
@@ -464,14 +470,16 @@ QSharedPointer<QMapboxGLStyleChange> QMapboxGLStyleAddLayer::fromMapParameter(QG
static const QStringList layerProperties = QStringList()
<< QStringLiteral("name") << QStringLiteral("layerType") << QStringLiteral("before");
- // Offset objectName and type properties.
- for (int i = 2; i < param->metaObject()->propertyCount(); ++i) {
- QString name = param->metaObject()->property(i).name();
- QVariant value = param->property(name.toLatin1());
+ QList<QByteArray> propertyNames = getAllPropertyNamesList(param);
+ for (const QByteArray &propertyName : propertyNames) {
+ if (isImmutableProperty(propertyName))
+ continue;
+
+ const QVariant value = param->property(propertyName);
- switch (layerProperties.indexOf(name)) {
+ switch (layerProperties.indexOf(propertyName)) {
case -1:
- layer->m_params[formatPropertyName(&name)] = value;
+ layer->m_params[formatPropertyName(propertyName)] = value;
break;
case 0: // name
layer->m_params[QStringLiteral("id")] = value;
diff --git a/src/plugins/position/position.pro b/src/plugins/position/position.pro
index 1687a9d2..b9832ff4 100644
--- a/src/plugins/position/position.pro
+++ b/src/plugins/position/position.pro
@@ -8,7 +8,7 @@ qtConfig(winrt_geolocation):SUBDIRS += winrt
qtHaveModule(simulator):SUBDIRS += simulator
osx|ios|tvos:SUBDIRS += corelocation
android:SUBDIRS += android
-win32:qtHaveModule(serialport):SUBDIRS += serialnmea
+qtHaveModule(serialport):SUBDIRS += serialnmea
SUBDIRS += \
positionpoll
diff --git a/src/positioning/qlocationutils.cpp b/src/positioning/qlocationutils.cpp
index 5304392b..f5062eb6 100644
--- a/src/positioning/qlocationutils.cpp
+++ b/src/positioning/qlocationutils.cpp
@@ -258,6 +258,32 @@ static void qlocationutils_readZda(const char *data, int size, QGeoPositionInfo
info->setTimestamp(QDateTime(date, time, Qt::UTC));
}
+QLocationUtils::NmeaSentence QLocationUtils::getNmeaSentenceType(const char *data, int size)
+{
+ if (size < 6 || data[0] != '$' || !hasValidNmeaChecksum(data, size))
+ return NmeaSentenceInvalid;
+
+ if (data[3] == 'G' && data[4] == 'G' && data[5] == 'A')
+ return NmeaSentenceGGA;
+
+ if (data[3] == 'G' && data[4] == 'S' && data[5] == 'A')
+ return NmeaSentenceGSA;
+
+ if (data[3] == 'G' && data[4] == 'L' && data[5] == 'L')
+ return NmeaSentenceGLL;
+
+ if (data[3] == 'R' && data[4] == 'M' && data[5] == 'C')
+ return NmeaSentenceRMC;
+
+ if (data[3] == 'V' && data[4] == 'T' && data[5] == 'G')
+ return NmeaSentenceVTG;
+
+ if (data[3] == 'Z' && data[4] == 'D' && data[5] == 'A')
+ return NmeaSentenceZDA;
+
+ return NmeaSentenceInvalid;
+}
+
bool QLocationUtils::getPosInfoFromNmea(const char *data, int size, QGeoPositionInfo *info,
double uere, bool *hasFix)
{
@@ -266,7 +292,9 @@ bool QLocationUtils::getPosInfoFromNmea(const char *data, int size, QGeoPosition
if (hasFix)
*hasFix = false;
- if (size < 6 || data[0] != '$' || !hasValidNmeaChecksum(data, size))
+
+ NmeaSentence nmeaType = getNmeaSentenceType(data, size);
+ if (nmeaType == NmeaSentenceInvalid)
return false;
// Adjust size so that * and following characters are not parsed by the following functions.
@@ -277,43 +305,28 @@ bool QLocationUtils::getPosInfoFromNmea(const char *data, int size, QGeoPosition
}
}
- if (data[3] == 'G' && data[4] == 'G' && data[5] == 'A') {
- // "$--GGA" sentence.
+ switch (nmeaType) {
+ case NmeaSentenceGGA:
qlocationutils_readGga(data, size, info, uere, hasFix);
return true;
- }
-
- if (data[3] == 'G' && data[4] == 'S' && data[5] == 'A') {
- // "$--GSA" sentence.
+ case NmeaSentenceGSA:
qlocationutils_readGsa(data, size, info, uere, hasFix);
return true;
- }
-
- if (data[3] == 'G' && data[4] == 'L' && data[5] == 'L') {
- // "$--GLL" sentence.
+ case NmeaSentenceGLL:
qlocationutils_readGll(data, size, info, hasFix);
return true;
- }
-
- if (data[3] == 'R' && data[4] == 'M' && data[5] == 'C') {
- // "$--RMC" sentence.
+ case NmeaSentenceRMC:
qlocationutils_readRmc(data, size, info, hasFix);
return true;
- }
-
- if (data[3] == 'V' && data[4] == 'T' && data[5] == 'G') {
- // "$--VTG" sentence.
+ case NmeaSentenceVTG:
qlocationutils_readVtg(data, size, info, hasFix);
return true;
- }
-
- if (data[3] == 'Z' && data[4] == 'D' && data[5] == 'A') {
- // "$--ZDA" sentence.
+ case NmeaSentenceZDA:
qlocationutils_readZda(data, size, info, hasFix);
return true;
+ default:
+ return false;
}
-
- return false;
}
bool QLocationUtils::hasValidNmeaChecksum(const char *data, int size)
diff --git a/src/positioning/qlocationutils_p.h b/src/positioning/qlocationutils_p.h
index 69cf0fee..d9e6524a 100644
--- a/src/positioning/qlocationutils_p.h
+++ b/src/positioning/qlocationutils_p.h
@@ -54,6 +54,7 @@
#include <math.h> // needed for non-std:: versions of functions
#include <qmath.h>
#include <QtPositioning/QGeoCoordinate>
+#include <QtPositioning/private/qpositioningglobal_p.h>
static const double offsetEpsilon = 1e-12; // = 0.000000000001
static const double leftOffset = -180.0 + offsetEpsilon;
@@ -64,7 +65,7 @@ class QTime;
class QByteArray;
class QGeoPositionInfo;
-class QLocationUtils
+class Q_POSITIONING_PRIVATE_EXPORT QLocationUtils
{
public:
enum CardinalDirection {
@@ -86,6 +87,16 @@ public:
CardinalNNW
};
+ enum NmeaSentence {
+ NmeaSentenceInvalid,
+ NmeaSentenceGGA, // Fix information
+ NmeaSentenceGSA, // Overall Satellite data, such as HDOP and VDOP
+ NmeaSentenceGLL, // Lat/Lon data
+ NmeaSentenceRMC, // Recommended minimum data for gps
+ NmeaSentenceVTG, // Vector track an Speed over the Ground
+ NmeaSentenceZDA // Date and Time
+ };
+
inline static bool isValidLat(double lat) {
return lat >= -90.0 && lat <= 90.0;
}
@@ -246,6 +257,11 @@ public:
}
/*
+ returns the NMEA sentence type.
+ */
+ static NmeaSentence getNmeaSentenceType(const char *data, int size);
+
+ /*
Creates a QGeoPositionInfo from a GGA, GLL, RMC, VTG or ZDA sentence.
Note:
@@ -254,25 +270,31 @@ public:
- RMC reports date with a two-digit year so in this case the year
is assumed to be after the year 2000.
*/
- Q_AUTOTEST_EXPORT static bool getPosInfoFromNmea(const char *data, int size,
- QGeoPositionInfo *info, double uere,
- bool *hasFix = 0);
+ static bool getPosInfoFromNmea(const char *data,
+ int size,
+ QGeoPositionInfo *info, double uere,
+ bool *hasFix = nullptr);
/*
Returns true if the given NMEA sentence has a valid checksum.
*/
- Q_AUTOTEST_EXPORT static bool hasValidNmeaChecksum(const char *data, int size);
+ static bool hasValidNmeaChecksum(const char *data, int size);
/*
Returns time from a string in hhmmss or hhmmss.z+ format.
*/
- Q_AUTOTEST_EXPORT static bool getNmeaTime(const QByteArray &bytes, QTime *time);
+ static bool getNmeaTime(const QByteArray &bytes, QTime *time);
/*
Accepts for example ("2734.7964", 'S', "15306.0124", 'E') and returns the
lat-long values. Fails if lat or long fail isValidLat() or isValidLong().
*/
- Q_AUTOTEST_EXPORT static bool getNmeaLatLong(const QByteArray &latString, char latDirection, const QByteArray &lngString, char lngDirection, double *lat, double *lon);
+ static bool getNmeaLatLong(const QByteArray &latString,
+ char latDirection,
+ const QByteArray &lngString,
+ char lngDirection,
+ double *lat,
+ double *lon);
};
QT_END_NAMESPACE
diff --git a/src/src.pro b/src/src.pro
index 87ea7983..417e2272 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -17,7 +17,7 @@ positioning.depends = clip2tri
qtHaveModule(quick) {
SUBDIRS += positioningquick location
positioningquick.depends += positioning
- location.depends += positioning clip2tri
+ location.depends += positioningquick clip2tri
plugins.depends += location