summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--src/plugins/position/android/src/jnipositioning.cpp71
-rw-r--r--src/positioning/qgeocoordinate.cpp28
-rw-r--r--tests/applications/positioning_backend/logwidget.cpp46
-rw-r--r--tests/applications/positioning_backend/logwidget.h47
-rw-r--r--tests/applications/positioning_backend/main.cpp7
-rw-r--r--tests/applications/positioning_backend/positioning_backend.pro6
-rw-r--r--tests/applications/positioning_backend/widget.cpp5
-rw-r--r--tests/applications/positioning_backend/widget.h5
9 files changed, 184 insertions, 34 deletions
diff --git a/.gitignore b/.gitignore
index 5b60c37d..a4fa8e34 100644
--- a/.gitignore
+++ b/.gitignore
@@ -85,6 +85,9 @@ tst_*.log
tst_*.debug
tst_*~
+# Android temporary files
+*so-deployment-settings.json
+
# xemacs temporary files
*.flc
diff --git a/src/plugins/position/android/src/jnipositioning.cpp b/src/plugins/position/android/src/jnipositioning.cpp
index 9bef8d36..7d138ce4 100644
--- a/src/plugins/position/android/src/jnipositioning.cpp
+++ b/src/plugins/position/android/src/jnipositioning.cpp
@@ -51,8 +51,8 @@
#include "jnipositioning.h"
-static JavaVM *javaVM = 0;
-jclass positioningClass;
+static JavaVM *javaVM = nullptr;
+static jclass positioningClass;
static jmethodID providerListMethodId;
static jmethodID lastKnownPositionMethodId;
@@ -78,10 +78,10 @@ namespace AndroidPositioning {
AttachedJNIEnv()
{
attached = false;
- if (javaVM && javaVM->GetEnv((void**)&jniEnv, JNI_VERSION_1_6) < 0) {
- if (javaVM->AttachCurrentThread(&jniEnv, NULL) < 0) {
+ if (javaVM && javaVM->GetEnv(reinterpret_cast<void**>(&jniEnv), JNI_VERSION_1_6) < 0) {
+ if (javaVM->AttachCurrentThread(&jniEnv, nullptr) < 0) {
__android_log_print(ANDROID_LOG_ERROR, logTag, "AttachCurrentThread failed");
- jniEnv = 0;
+ jniEnv = nullptr;
return;
}
attached = true;
@@ -109,7 +109,7 @@ namespace AndroidPositioning {
QGeoPositionInfoSourceAndroid *src = qobject_cast<QGeoPositionInfoSourceAndroid *>(obj);
Q_ASSERT(src);
do {
- key = QRandomGenerator::global()->generate();
+ key = qAbs(int(QRandomGenerator::global()->generate()));
} while (idToPosSource()->contains(key));
idToPosSource()->insert(key, src);
@@ -117,7 +117,7 @@ namespace AndroidPositioning {
QGeoSatelliteInfoSourceAndroid *src = qobject_cast<QGeoSatelliteInfoSourceAndroid *>(obj);
Q_ASSERT(src);
do {
- key = QRandomGenerator::global()->generate();
+ key = qAbs(int(QRandomGenerator::global()->generate()));
} while (idToSatSource()->contains(key));
idToSatSource()->insert(key, src);
@@ -142,16 +142,15 @@ namespace AndroidPositioning {
QGeoPositionInfoSource::PositioningMethods availableProviders()
{
- QGeoPositionInfoSource::PositioningMethods ret =
- static_cast<QGeoPositionInfoSource::PositioningMethods>(0);
+ QGeoPositionInfoSource::PositioningMethods ret = QGeoPositionInfoSource::NoPositioningMethods;
AttachedJNIEnv env;
if (!env.jniEnv)
return ret;
jintArray jProviders = static_cast<jintArray>(env.jniEnv->CallStaticObjectMethod(
positioningClass, providerListMethodId));
- jint *providers = env.jniEnv->GetIntArrayElements(jProviders, 0);
- const uint size = env.jniEnv->GetArrayLength(jProviders);
- for (uint i = 0; i < size; i++) {
+ jint *providers = env.jniEnv->GetIntArrayElements(jProviders, nullptr);
+ const int size = env.jniEnv->GetArrayLength(jProviders);
+ for (int i = 0; i < size; i++) {
switch (providers[i]) {
case PROVIDER_GPS:
ret |= QGeoPositionInfoSource::SatellitePositioningMethods;
@@ -182,17 +181,17 @@ namespace AndroidPositioning {
const char *name,
const char *sig)
{
- jmethodID id = 0;
- int offset_name = qstrlen(name);
- int offset_signal = qstrlen(sig);
- QByteArray key(offset_name + offset_signal, Qt::Uninitialized);
+ jmethodID id = nullptr;
+ uint offset_name = qstrlen(name);
+ uint offset_signal = qstrlen(sig);
+ QByteArray key(int(offset_name + offset_signal), Qt::Uninitialized);
memcpy(key.data(), name, offset_name);
memcpy(key.data()+offset_name, sig, offset_signal);
QHash<QByteArray, jmethodID>::iterator it = cachedMethodID->find(key);
if (it == cachedMethodID->end()) {
id = env->GetMethodID(clazz, name, sig);
if (env->ExceptionCheck()) {
- id = 0;
+ id = nullptr;
#ifdef QT_DEBUG
env->ExceptionDescribe();
#endif // QT_DEBUG
@@ -235,22 +234,38 @@ namespace AndroidPositioning {
jlong timestamp = jniEnv->CallLongMethod(location, mid);
info.setTimestamp(QDateTime::fromMSecsSinceEpoch(timestamp, Qt::UTC));
- //accuracy
+ //horizontal accuracy
mid = getCachedMethodID(jniEnv, thisClass, "hasAccuracy", "()Z");
attributeExists = jniEnv->CallBooleanMethod(location, mid);
if (attributeExists) {
mid = getCachedMethodID(jniEnv, thisClass, "getAccuracy", "()F");
jfloat accuracy = jniEnv->CallFloatMethod(location, mid);
- info.setAttribute(QGeoPositionInfo::HorizontalAccuracy, accuracy);
+ info.setAttribute(QGeoPositionInfo::HorizontalAccuracy, qreal(accuracy));
}
+ //vertical accuracy
+ mid = getCachedMethodID(jniEnv, thisClass, "hasVerticalAccuracy", "()Z");
+ if (mid) {
+ attributeExists = jniEnv->CallBooleanMethod(location, mid);
+ if (attributeExists) {
+ mid = getCachedMethodID(jniEnv, thisClass, "getVerticalAccuracyMeters", "()F");
+ if (mid) {
+ jfloat accuracy = jniEnv->CallFloatMethod(location, mid);
+ info.setAttribute(QGeoPositionInfo::VerticalAccuracy, qreal(accuracy));
+ }
+ }
+ }
+
+ if (!mid)
+ jniEnv->ExceptionClear();
+
//ground speed
mid = getCachedMethodID(jniEnv, thisClass, "hasSpeed", "()Z");
attributeExists = jniEnv->CallBooleanMethod(location, mid);
if (attributeExists) {
mid = getCachedMethodID(jniEnv, thisClass, "getSpeed", "()F");
jfloat speed = jniEnv->CallFloatMethod(location, mid);
- info.setAttribute(QGeoPositionInfo::GroundSpeed, speed);
+ info.setAttribute(QGeoPositionInfo::GroundSpeed, qreal(speed));
}
//bearing
@@ -259,7 +274,7 @@ namespace AndroidPositioning {
if (attributeExists) {
mid = getCachedMethodID(jniEnv, thisClass, "getBearing", "()F");
jfloat bearing = jniEnv->CallFloatMethod(location, mid);
- info.setAttribute(QGeoPositionInfo::Direction, bearing);
+ info.setAttribute(QGeoPositionInfo::Direction, qreal(bearing));
}
jniEnv->DeleteLocalRef(thisClass);
@@ -288,7 +303,7 @@ namespace AndroidPositioning {
//signal strength
jmethodID mid = getCachedMethodID(jniEnv, thisClass, "getSnr", "()F");
jfloat snr = jniEnv->CallFloatMethod(element, mid);
- info.setSignalStrength((int)snr);
+ info.setSignalStrength(int(snr));
//ignore any satellite with no signal whatsoever
if (qFuzzyIsNull(snr))
@@ -307,12 +322,12 @@ namespace AndroidPositioning {
//azimuth
mid = getCachedMethodID(jniEnv, thisClass, "getAzimuth", "()F");
jfloat azimuth = jniEnv->CallFloatMethod(element, mid);
- info.setAttribute(QGeoSatelliteInfo::Azimuth, azimuth);
+ info.setAttribute(QGeoSatelliteInfo::Azimuth, qreal(azimuth));
//elevation
mid = getCachedMethodID(jniEnv, thisClass, "getElevation", "()F");
jfloat elevation = jniEnv->CallFloatMethod(element, mid);
- info.setAttribute(QGeoSatelliteInfo::Elevation, elevation);
+ info.setAttribute(QGeoSatelliteInfo::Elevation, qreal(elevation));
//used in a fix
mid = getCachedMethodID(jniEnv, thisClass, "usedInFix", "()Z");
@@ -339,7 +354,7 @@ namespace AndroidPositioning {
jobject location = env.jniEnv->CallStaticObjectMethod(positioningClass,
lastKnownPositionMethodId,
fromSatellitePositioningMethodsOnly);
- if (location == 0)
+ if (location == nullptr)
return QGeoPositionInfo();
const QGeoPositionInfo info = positionInfoFromJavaLocation(env.jniEnv, location);
@@ -520,7 +535,7 @@ static void satelliteUpdated(JNIEnv *env, jobject /*thiz*/, jobjectArray satelli
QGeoSatelliteInfoSourceAndroid *source = AndroidPositioning::idToSatSource()->value(androidClassKey);
if (!source) {
- qFatal("satelliteUpdated: source == 0");
+ qWarning("satelliteUpdated: source == 0");
return;
}
@@ -587,8 +602,8 @@ Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void * /*reserved*/)
__android_log_print(ANDROID_LOG_INFO, logTag, "Positioning start");
UnionJNIEnvToVoid uenv;
- uenv.venv = NULL;
- javaVM = 0;
+ uenv.venv = nullptr;
+ javaVM = nullptr;
if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_4) != JNI_OK) {
__android_log_print(ANDROID_LOG_FATAL, logTag, "GetEnv failed");
diff --git a/src/positioning/qgeocoordinate.cpp b/src/positioning/qgeocoordinate.cpp
index 80904d7c..f3d3ef9c 100644
--- a/src/positioning/qgeocoordinate.cpp
+++ b/src/positioning/qgeocoordinate.cpp
@@ -44,11 +44,28 @@
#include <QHash>
#include <QDataStream>
#include <QDebug>
+#include <QMetaType>
#include <qnumeric.h>
#include <qmath.h>
QT_BEGIN_NAMESPACE
+
+struct CoordinateStreamOperators
+{
+ CoordinateStreamOperators()
+ {
+#ifndef QT_NO_DATASTREAM
+ qRegisterMetaTypeStreamOperators<QGeoCoordinate>();
+#endif
+#ifndef QT_NO_DEBUG_STREAM
+ QMetaType::registerDebugStreamOperator<QGeoCoordinate>();
+#endif
+ }
+};
+Q_GLOBAL_STATIC(CoordinateStreamOperators, initStreamOperators);
+
+
static const double qgeocoordinate_EARTH_MEAN_RADIUS = 6371.0072;
@@ -201,6 +218,9 @@ QGeoMercatorCoordinatePrivate::~QGeoMercatorCoordinatePrivate()
QGeoCoordinate::QGeoCoordinate()
: d(new QGeoCoordinatePrivate)
{
+#ifndef QT_NO_DATASTREAM
+ initStreamOperators();
+#endif
}
/*!
@@ -215,6 +235,10 @@ QGeoCoordinate::QGeoCoordinate()
QGeoCoordinate::QGeoCoordinate(double latitude, double longitude)
: d(new QGeoCoordinatePrivate)
{
+#ifndef QT_NO_DATASTREAM
+ initStreamOperators();
+#endif
+
if (QLocationUtils::isValidLat(latitude) && QLocationUtils::isValidLong(longitude)) {
d->lat = latitude;
d->lng = longitude;
@@ -236,6 +260,10 @@ QGeoCoordinate::QGeoCoordinate(double latitude, double longitude)
QGeoCoordinate::QGeoCoordinate(double latitude, double longitude, double altitude)
: d(new QGeoCoordinatePrivate)
{
+#ifndef QT_NO_DATASTREAM
+ initStreamOperators();
+#endif
+
if (QLocationUtils::isValidLat(latitude) && QLocationUtils::isValidLong(longitude)) {
d->lat = latitude;
d->lng = longitude;
diff --git a/tests/applications/positioning_backend/logwidget.cpp b/tests/applications/positioning_backend/logwidget.cpp
new file mode 100644
index 00000000..5ec47230
--- /dev/null
+++ b/tests/applications/positioning_backend/logwidget.cpp
@@ -0,0 +1,46 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtPositioning module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "logwidget.h"
+#include <QVBoxLayout>
+
+LogWidget::LogWidget(QWidget *parent) : QWidget(parent)
+{
+ QVBoxLayout *verticalLayout = new QVBoxLayout(this);
+ verticalLayout->setSpacing(6);
+ verticalLayout->setContentsMargins(11, 11, 11, 11);
+ verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
+
+ editor = new QPlainTextEdit(this);
+ verticalLayout->addWidget(editor);
+}
+
+void LogWidget::appendLog(const QString &line)
+{
+ editor->appendPlainText(line);
+}
diff --git a/tests/applications/positioning_backend/logwidget.h b/tests/applications/positioning_backend/logwidget.h
new file mode 100644
index 00000000..f6a3eb44
--- /dev/null
+++ b/tests/applications/positioning_backend/logwidget.h
@@ -0,0 +1,47 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtPositioning module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef LOGWIDGET_H
+#define LOGWIDGET_H
+
+#include <QtWidgets/qwidget.h>
+#include <QtWidgets/qplaintextedit.h>
+
+class LogWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit LogWidget(QWidget *parent = nullptr);
+
+ void appendLog(const QString &line);
+
+private:
+ QPlainTextEdit *editor;
+};
+
+#endif // LOGWIDGET_H
diff --git a/tests/applications/positioning_backend/main.cpp b/tests/applications/positioning_backend/main.cpp
index 930f1c9c..52115556 100644
--- a/tests/applications/positioning_backend/main.cpp
+++ b/tests/applications/positioning_backend/main.cpp
@@ -26,6 +26,7 @@
**
****************************************************************************/
#include "widget.h"
+#include "logwidget.h"
#include <QLabel>
#include <QApplication>
@@ -34,14 +35,16 @@ int main(int argc, char *argv[])
{
QApplication a(argc, argv);
- Widget *w1 = new Widget;
- Widget *w2 = new Widget;
+ LogWidget *log = new LogWidget;
+ Widget *w1 = new Widget(log);
+ Widget *w2 = new Widget(log);
QTabWidget tabWidget;
tabWidget.setTabPosition(QTabWidget::South);
tabWidget.addTab(w1, "Instance 1");
tabWidget.addTab(w2, "Instance 2");
+ tabWidget.addTab(log, "Logs");
tabWidget.show();
return a.exec();
diff --git a/tests/applications/positioning_backend/positioning_backend.pro b/tests/applications/positioning_backend/positioning_backend.pro
index 410dbc86..4ba9e7c8 100644
--- a/tests/applications/positioning_backend/positioning_backend.pro
+++ b/tests/applications/positioning_backend/positioning_backend.pro
@@ -5,9 +5,11 @@ TEMPLATE = app
SOURCES += main.cpp\
- widget.cpp
+ widget.cpp \
+ logwidget.cpp
-HEADERS += widget.h
+HEADERS += widget.h \
+ logwidget.h
FORMS += widget.ui
diff --git a/tests/applications/positioning_backend/widget.cpp b/tests/applications/positioning_backend/widget.cpp
index 93a42a80..ae39187d 100644
--- a/tests/applications/positioning_backend/widget.cpp
+++ b/tests/applications/positioning_backend/widget.cpp
@@ -30,8 +30,9 @@
#include <QGeoPositionInfoSource>
#include <QDebug>
-Widget::Widget(QWidget *parent) :
+Widget::Widget(LogWidget *logWidget, QWidget *parent) :
QWidget(parent),
+ log(logWidget),
ui(new Ui::Widget)
{
ui->setupUi(this);
@@ -81,6 +82,8 @@ void Widget::positionUpdated(QGeoPositionInfo gpsPos)
ui->labelSpeed->setText(QString::number(gpsPos.attribute(QGeoPositionInfo::GroundSpeed)));
else
ui->labelSpeed->setText(QStringLiteral("N/A"));
+
+ log->appendLog(coord.toString());
}
void Widget::positionTimedOut()
diff --git a/tests/applications/positioning_backend/widget.h b/tests/applications/positioning_backend/widget.h
index fc04c423..b67e53b8 100644
--- a/tests/applications/positioning_backend/widget.h
+++ b/tests/applications/positioning_backend/widget.h
@@ -28,6 +28,8 @@
#ifndef WIDGET_H
#define WIDGET_H
+#include "logwidget.h"
+
#include <QWidget>
#include <QGeoPositionInfoSource>
@@ -40,7 +42,7 @@ class Widget : public QWidget
Q_OBJECT
public:
- explicit Widget(QWidget *parent = 0);
+ explicit Widget(LogWidget *log, QWidget *parent = nullptr);
~Widget();
public slots:
@@ -59,6 +61,7 @@ private slots:
void on_buttonUpdateSupported_clicked();
private:
+ LogWidget *log = nullptr;
Ui::Widget *ui;
QGeoPositionInfoSource *m_posSource;
};