summaryrefslogtreecommitdiff
path: root/src/positioningquick
diff options
context:
space:
mode:
Diffstat (limited to 'src/positioningquick')
-rw-r--r--src/positioningquick/positioningquick.pro10
-rw-r--r--src/positioningquick/qdeclarativeposition.cpp474
-rw-r--r--src/positioningquick/qdeclarativeposition_p.h149
-rw-r--r--src/positioningquick/qdeclarativepositionsource.cpp768
-rw-r--r--src/positioningquick/qdeclarativepositionsource_p.h174
-rw-r--r--src/positioningquick/qpositioningquickglobal.h69
-rw-r--r--src/positioningquick/qpositioningquickglobal_p.h61
7 files changed, 1705 insertions, 0 deletions
diff --git a/src/positioningquick/positioningquick.pro b/src/positioningquick/positioningquick.pro
new file mode 100644
index 00000000..75bd68a3
--- /dev/null
+++ b/src/positioningquick/positioningquick.pro
@@ -0,0 +1,10 @@
+TARGET = QtPositioningQuick
+QT = quick-private positioning-private qml-private core-private
+CONFIG += simd optimize_full
+
+INCLUDEPATH += $$PWD
+
+SOURCES += $$files(*.cpp)
+HEADERS += $$files(*.h)
+
+load(qt_module)
diff --git a/src/positioningquick/qdeclarativeposition.cpp b/src/positioningquick/qdeclarativeposition.cpp
new file mode 100644
index 00000000..7e72f358
--- /dev/null
+++ b/src/positioningquick/qdeclarativeposition.cpp
@@ -0,0 +1,474 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Jolla Ltd.
+** Contact: Aaron McCarthy <aaron.mccarthy@jollamobile.com>
+** Copyright (C) 2016 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:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QtNumeric>
+#include "qdeclarativeposition_p.h"
+#include <QtQml/qqml.h>
+#include <qnmeapositioninfosource.h>
+#include <QFile>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype Position
+ \instantiates QDeclarativePosition
+ \inqmlmodule QtPositioning
+ \since 5.2
+
+ \brief The Position type holds positional data at a particular point in time,
+ such as coordinate (longitude, latitude, altitude) and speed.
+
+ The Position type holds values related to geographic location such as
+ a \l coordinate (longitude, latitude, and altitude), the \l timestamp when
+ the Position was obtained, the \l speed at that time, and the accuracy of
+ the data.
+
+ Primarily, it is used in the \l{PositionSource::position}{position} property
+ of a \l{PositionSource}, as the basic unit of data available from the system
+ location data source.
+
+ Not all properties of a Position object are necessarily valid or available
+ (for example latitude and longitude may be valid, but speed update has not been
+ received or set manually). As a result, corresponding "valid" properties
+ are available (for example \l{coordinate} and \l{longitudeValid}, \l{latitudeValid}
+ etc) to discern whether the data is available and valid in this position
+ update.
+
+ Position objects are read-only and can only be produced by a PositionSource.
+
+ \section2 Example Usage
+
+ See the example given for the \l{PositionSource} type, or the
+ \l{geoflickr}{GeoFlickr} example application.
+
+ \sa PositionSource, coordinate
+*/
+
+namespace
+{
+
+bool equalOrNaN(qreal a, qreal b)
+{
+ return a == b || (qIsNaN(a) && qIsNaN(b));
+}
+
+bool exclusiveNaN(qreal a, qreal b)
+{
+ return qIsNaN(a) != qIsNaN(b);
+}
+
+}
+
+QDeclarativePosition::QDeclarativePosition(QObject *parent)
+: QObject(parent)
+{
+}
+
+QDeclarativePosition::~QDeclarativePosition()
+{
+}
+
+void QDeclarativePosition::setPosition(const QGeoPositionInfo &info)
+{
+ // timestamp
+ const QDateTime pTimestamp = m_info.timestamp();
+ const QDateTime timestamp = info.timestamp();
+ bool emitTimestampChanged = pTimestamp != timestamp;
+
+ // coordinate
+ const QGeoCoordinate pCoordinate = m_info.coordinate();
+ const QGeoCoordinate coordinate = info.coordinate();
+ bool emitCoordinateChanged = pCoordinate != coordinate;
+ bool emitLatitudeValidChanged = exclusiveNaN(pCoordinate.latitude(), coordinate.latitude());
+ bool emitLongitudeValidChanged = exclusiveNaN(pCoordinate.longitude(), coordinate.longitude());
+ bool emitAltitudeValidChanged = exclusiveNaN(pCoordinate.altitude(), coordinate.altitude());
+
+ // direction
+ const qreal pDirection = m_info.attribute(QGeoPositionInfo::Direction);
+ const qreal direction = info.attribute(QGeoPositionInfo::Direction);
+ bool emitDirectionChanged = !equalOrNaN(pDirection, direction);
+ bool emitDirectionValidChanged = exclusiveNaN(pDirection, direction);
+
+ // ground speed
+ const qreal pSpeed = m_info.attribute(QGeoPositionInfo::GroundSpeed);
+ const qreal speed = info.attribute(QGeoPositionInfo::GroundSpeed);
+ bool emitSpeedChanged = !equalOrNaN(pSpeed, speed);
+ bool emitSpeedValidChanged = exclusiveNaN(pSpeed, speed);
+
+ // vertical speed
+ const qreal pVerticalSpeed = m_info.attribute(QGeoPositionInfo::VerticalSpeed);
+ const qreal verticalSpeed = info.attribute(QGeoPositionInfo::VerticalSpeed);
+ bool emitVerticalSpeedChanged = !equalOrNaN(pVerticalSpeed, verticalSpeed);
+ bool emitVerticalSpeedValidChanged = exclusiveNaN(pVerticalSpeed, verticalSpeed);
+
+ // magnetic variation
+ const qreal pMagneticVariation = m_info.attribute(QGeoPositionInfo::MagneticVariation);
+ const qreal magneticVariation = info.attribute(QGeoPositionInfo::MagneticVariation);
+ bool emitMagneticVariationChanged = !equalOrNaN(pMagneticVariation, magneticVariation);
+ bool emitMagneticVariationValidChanged = exclusiveNaN(pMagneticVariation, magneticVariation);
+
+ // horizontal accuracy
+ const qreal pHorizontalAccuracy = m_info.attribute(QGeoPositionInfo::HorizontalAccuracy);
+ const qreal horizontalAccuracy = info.attribute(QGeoPositionInfo::HorizontalAccuracy);
+ bool emitHorizontalAccuracyChanged = !equalOrNaN(pHorizontalAccuracy, horizontalAccuracy);
+ bool emitHorizontalAccuracyValidChanged = exclusiveNaN(pHorizontalAccuracy, horizontalAccuracy);
+
+ // vertical accuracy
+ const qreal pVerticalAccuracy = m_info.attribute(QGeoPositionInfo::VerticalAccuracy);
+ const qreal verticalAccuracy = info.attribute(QGeoPositionInfo::VerticalAccuracy);
+ bool emitVerticalAccuracyChanged = !equalOrNaN(pVerticalAccuracy, verticalAccuracy);
+ bool emitVerticalAccuracyValidChanged = exclusiveNaN(pVerticalAccuracy, verticalAccuracy);
+
+ m_info = info;
+
+ if (emitTimestampChanged)
+ emit timestampChanged();
+ if (emitCoordinateChanged)
+ emit coordinateChanged();
+ if (emitLatitudeValidChanged)
+ emit latitudeValidChanged();
+ if (emitLongitudeValidChanged)
+ emit longitudeValidChanged();
+ if (emitAltitudeValidChanged)
+ emit altitudeValidChanged();
+ if (emitDirectionChanged)
+ emit directionChanged();
+ if (emitDirectionValidChanged)
+ emit directionValidChanged();
+ if (emitSpeedChanged)
+ emit speedChanged();
+ if (emitSpeedValidChanged)
+ emit speedValidChanged();
+ if (emitVerticalSpeedChanged)
+ emit verticalSpeedChanged();
+ if (emitVerticalSpeedValidChanged)
+ emit verticalSpeedValidChanged();
+ if (emitHorizontalAccuracyChanged)
+ emit horizontalAccuracyChanged();
+ if (emitHorizontalAccuracyValidChanged)
+ emit horizontalAccuracyValidChanged();
+ if (emitVerticalAccuracyChanged)
+ emit verticalAccuracyChanged();
+ if (emitVerticalAccuracyValidChanged)
+ emit verticalAccuracyValidChanged();
+ if (emitMagneticVariationChanged)
+ emit magneticVariationChanged();
+ if (emitMagneticVariationValidChanged)
+ emit magneticVariationValidChanged();
+}
+
+const QGeoPositionInfo &QDeclarativePosition::position() const
+{
+ return m_info;
+}
+
+/*!
+ \qmlproperty coordinate Position::coordinate
+
+ This property holds the latitude, longitude, and altitude value of the Position.
+
+ It is a read-only property.
+
+ \sa longitudeValid, latitudeValid, altitudeValid
+*/
+QGeoCoordinate QDeclarativePosition::coordinate()
+{
+ return m_info.coordinate();
+}
+
+/*!
+ \qmlproperty bool Position::latitudeValid
+
+ This property is true if coordinate's latitude has been set
+ (to indicate whether that data has been received or not, as every update
+ does not necessarily contain all data).
+
+ \sa coordinate
+*/
+bool QDeclarativePosition::isLatitudeValid() const
+{
+ return !qIsNaN(m_info.coordinate().latitude());
+}
+
+
+/*!
+ \qmlproperty bool Position::longitudeValid
+
+ This property is true if coordinate's longitude has been set
+ (to indicate whether that data has been received or not, as every update
+ does not necessarily contain all data).
+
+ \sa coordinate
+*/
+bool QDeclarativePosition::isLongitudeValid() const
+{
+ return !qIsNaN(m_info.coordinate().longitude());
+}
+
+
+/*!
+ \qmlproperty bool Position::speedValid
+
+ This property is true if \l speed has been set
+ (to indicate whether that data has been received or not, as every update
+ does not necessarily contain all data).
+
+ \sa speed
+*/
+bool QDeclarativePosition::isSpeedValid() const
+{
+ return !qIsNaN(m_info.attribute(QGeoPositionInfo::GroundSpeed));
+}
+
+/*!
+ \qmlproperty bool Position::altitudeValid
+
+ This property is true if coordinate's altitude has been set
+ (to indicate whether that data has been received or not, as every update
+ does not necessarily contain all data).
+
+ \sa coordinate
+*/
+bool QDeclarativePosition::isAltitudeValid() const
+{
+ return !qIsNaN(m_info.coordinate().altitude());
+}
+
+/*!
+ \qmlproperty double Position::speed
+
+ This property holds the value of speed (groundspeed, meters / second).
+
+ It is a read-only property.
+
+ \sa speedValid, coordinate
+*/
+double QDeclarativePosition::speed() const
+{
+ return m_info.attribute(QGeoPositionInfo::GroundSpeed);
+}
+
+/*!
+ \qmlproperty real Position::horizontalAccuracy
+
+ This property holds the horizontal accuracy of the coordinate (in meters).
+
+ \sa horizontalAccuracyValid, coordinate
+*/
+void QDeclarativePosition::setHorizontalAccuracy(qreal horizontalAccuracy)
+{
+ const qreal pHorizontalAccuracy = m_info.attribute(QGeoPositionInfo::HorizontalAccuracy);
+
+ if (equalOrNaN(pHorizontalAccuracy, horizontalAccuracy))
+ return;
+
+ bool validChanged = exclusiveNaN(pHorizontalAccuracy, horizontalAccuracy);
+
+ m_info.setAttribute(QGeoPositionInfo::HorizontalAccuracy, horizontalAccuracy);
+ emit horizontalAccuracyChanged();
+ if (validChanged)
+ emit horizontalAccuracyValidChanged();
+}
+
+qreal QDeclarativePosition::horizontalAccuracy() const
+{
+ return m_info.attribute(QGeoPositionInfo::HorizontalAccuracy);
+}
+
+/*!
+ \qmlproperty bool Position::horizontalAccuracyValid
+
+ This property is true if \l horizontalAccuracy has been set
+ (to indicate whether that data has been received or not, as every update
+ does not necessarily contain all data).
+
+ \sa horizontalAccuracy
+*/
+bool QDeclarativePosition::isHorizontalAccuracyValid() const
+{
+ return !qIsNaN(m_info.attribute(QGeoPositionInfo::HorizontalAccuracy));
+}
+
+/*!
+ \qmlproperty real Position::verticalAccuracy
+
+ This property holds the vertical accuracy of the coordinate (in meters).
+
+ \sa verticalAccuracyValid, coordinate
+*/
+void QDeclarativePosition::setVerticalAccuracy(qreal verticalAccuracy)
+{
+ const qreal pVerticalAccuracy = m_info.attribute(QGeoPositionInfo::VerticalAccuracy);
+
+ if (equalOrNaN(pVerticalAccuracy, verticalAccuracy))
+ return;
+
+ bool validChanged = exclusiveNaN(pVerticalAccuracy, verticalAccuracy);
+
+ m_info.setAttribute(QGeoPositionInfo::VerticalAccuracy, verticalAccuracy);
+ emit verticalAccuracyChanged();
+ if (validChanged)
+ emit verticalAccuracyValidChanged();
+}
+
+qreal QDeclarativePosition::verticalAccuracy() const
+{
+ return m_info.attribute(QGeoPositionInfo::VerticalAccuracy);
+}
+
+/*!
+ \qmlproperty bool Position::verticalAccuracyValid
+
+ This property is true if \l verticalAccuracy has been set
+ (to indicate whether that data has been received or not, as every update
+ does not necessarily contain all data).
+
+ \sa verticalAccuracy
+*/
+bool QDeclarativePosition::isVerticalAccuracyValid() const
+{
+ return !qIsNaN(m_info.attribute(QGeoPositionInfo::VerticalAccuracy));
+}
+
+/*!
+ \qmlproperty date Position::timestamp
+
+ This property holds the timestamp when this position
+ was received. If the property has not been set, it is invalid.
+
+ It is a read-only property.
+*/
+QDateTime QDeclarativePosition::timestamp() const
+{
+ return m_info.timestamp();
+}
+
+/*!
+ \qmlproperty bool Position::directionValid
+ \since Qt Positioning 5.3
+
+ This property is true if \l direction has been set (to indicate whether that data has been
+ received or not, as every update does not necessarily contain all data).
+
+ \sa direction
+*/
+bool QDeclarativePosition::isDirectionValid() const
+{
+ return !qIsNaN(m_info.attribute(QGeoPositionInfo::Direction));
+}
+
+/*!
+ \qmlproperty double Position::direction
+ \since Qt Positioning 5.3
+
+ This property holds the value of the direction of travel in degrees from true north.
+
+ It is a read-only property.
+
+ \sa directionValid
+*/
+double QDeclarativePosition::direction() const
+{
+ return m_info.attribute(QGeoPositionInfo::Direction);
+}
+
+/*!
+ \qmlproperty bool Position::verticalSpeedValid
+ \since Qt Positioning 5.3
+
+ This property is true if \l verticalSpeed has been set (to indicate whether that data has been
+ received or not, as every update does not necessarily contain all data).
+
+ \sa verticalSpeed
+*/
+bool QDeclarativePosition::isVerticalSpeedValid() const
+{
+ return !qIsNaN(m_info.attribute(QGeoPositionInfo::VerticalSpeed));
+}
+
+/*!
+ \qmlproperty double Position::verticalSpeed
+ \since Qt Positioning 5.3
+
+ This property holds the value of the vertical speed in meters per second.
+
+ It is a read-only property.
+
+ \sa verticalSpeedValid
+*/
+double QDeclarativePosition::verticalSpeed() const
+{
+ return m_info.attribute(QGeoPositionInfo::VerticalSpeed);
+}
+
+/*!
+ \qmlproperty bool Position::magneticVariationValid
+ \since Qt Positioning 5.4
+
+ This property is true if \l magneticVariation has been set (to indicate whether that data has been
+ received or not, as every update does not necessarily contain all data).
+
+ \sa magneticVariation
+*/
+bool QDeclarativePosition::isMagneticVariationValid() const
+{
+ return !qIsNaN(m_info.attribute(QGeoPositionInfo::MagneticVariation));
+}
+
+/*!
+ \qmlproperty double Position::magneticVariation
+ \since Qt Positioning 5.4
+
+ This property holds the angle between the horizontal component of the
+ magnetic field and true north, in degrees. Also known as magnetic
+ declination. A positive value indicates a clockwise direction from
+ true north and a negative value indicates a counter-clockwise direction.
+
+ It is a read-only property.
+
+ \sa magneticVariationValid
+*/
+double QDeclarativePosition::magneticVariation() const
+{
+ return m_info.attribute(QGeoPositionInfo::MagneticVariation);
+}
+
+QT_END_NAMESPACE
diff --git a/src/positioningquick/qdeclarativeposition_p.h b/src/positioningquick/qdeclarativeposition_p.h
new file mode 100644
index 00000000..141c37b7
--- /dev/null
+++ b/src/positioningquick/qdeclarativeposition_p.h
@@ -0,0 +1,149 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Jolla Ltd.
+** Contact: Aaron McCarthy <aaron.mccarthy@jollamobile.com>
+** Copyright (C) 2016 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:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+***************************************************************************/
+
+#ifndef QDECLARATIVEPOSITION_H
+#define QDECLARATIVEPOSITION_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/QObject>
+#include <QtCore/QDateTime>
+#include <QtQml/qqml.h>
+#include <QtPositioningQuick/private/qpositioningquickglobal_p.h>
+#include <QtPositioning/QGeoPositionInfo>
+
+QT_BEGIN_NAMESPACE
+
+class Q_POSITIONINGQUICK_PRIVATE_EXPORT QDeclarativePosition : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(bool latitudeValid READ isLatitudeValid NOTIFY latitudeValidChanged)
+ Q_PROPERTY(bool longitudeValid READ isLongitudeValid NOTIFY longitudeValidChanged)
+ Q_PROPERTY(bool altitudeValid READ isAltitudeValid NOTIFY altitudeValidChanged)
+ Q_PROPERTY(QGeoCoordinate coordinate READ coordinate NOTIFY coordinateChanged)
+ Q_PROPERTY(QDateTime timestamp READ timestamp NOTIFY timestampChanged)
+ Q_PROPERTY(double speed READ speed NOTIFY speedChanged)
+ Q_PROPERTY(bool speedValid READ isSpeedValid NOTIFY speedValidChanged)
+ Q_PROPERTY(qreal horizontalAccuracy READ horizontalAccuracy WRITE setHorizontalAccuracy NOTIFY horizontalAccuracyChanged)
+ Q_PROPERTY(qreal verticalAccuracy READ verticalAccuracy WRITE setVerticalAccuracy NOTIFY verticalAccuracyChanged)
+ Q_PROPERTY(bool horizontalAccuracyValid READ isHorizontalAccuracyValid NOTIFY horizontalAccuracyValidChanged)
+ Q_PROPERTY(bool verticalAccuracyValid READ isVerticalAccuracyValid NOTIFY verticalAccuracyValidChanged)
+
+ Q_PROPERTY(bool directionValid READ isDirectionValid NOTIFY directionValidChanged REVISION 1)
+ Q_PROPERTY(double direction READ direction NOTIFY directionChanged REVISION 1)
+ Q_PROPERTY(bool verticalSpeedValid READ isVerticalSpeedValid NOTIFY verticalSpeedValidChanged REVISION 1)
+ Q_PROPERTY(double verticalSpeed READ verticalSpeed NOTIFY verticalSpeedChanged REVISION 1)
+
+ Q_PROPERTY(double magneticVariation READ magneticVariation NOTIFY magneticVariationChanged REVISION 2)
+ Q_PROPERTY(bool magneticVariationValid READ isMagneticVariationValid NOTIFY magneticVariationChanged REVISION 2)
+
+public:
+ explicit QDeclarativePosition(QObject *parent = 0);
+ ~QDeclarativePosition();
+
+ bool isLatitudeValid() const;
+ bool isLongitudeValid() const;
+ bool isAltitudeValid() const;
+ QDateTime timestamp() const;
+ double speed() const;
+ bool isSpeedValid() const;
+ QGeoCoordinate coordinate();
+ bool isHorizontalAccuracyValid() const;
+ qreal horizontalAccuracy() const;
+ void setHorizontalAccuracy(qreal horizontalAccuracy);
+ bool isVerticalAccuracyValid() const;
+ qreal verticalAccuracy() const;
+ void setVerticalAccuracy(qreal verticalAccuracy);
+
+ bool isDirectionValid() const;
+ double direction() const;
+ void setDirection(double direction);
+
+ bool isVerticalSpeedValid() const;
+ double verticalSpeed() const;
+ void setVerticalSpeed(double speed);
+
+ bool isMagneticVariationValid() const;
+ double magneticVariation() const;
+
+ void setPosition(const QGeoPositionInfo &info);
+ const QGeoPositionInfo &position() const;
+
+Q_SIGNALS:
+ void latitudeValidChanged();
+ void longitudeValidChanged();
+ void altitudeValidChanged();
+ void timestampChanged();
+ void speedChanged();
+ void speedValidChanged();
+ void coordinateChanged();
+ void horizontalAccuracyChanged();
+ void horizontalAccuracyValidChanged();
+ void verticalAccuracyChanged();
+ void verticalAccuracyValidChanged();
+
+ Q_REVISION(1) void directionValidChanged();
+ Q_REVISION(1) void directionChanged();
+ Q_REVISION(1) void verticalSpeedValidChanged();
+ Q_REVISION(1) void verticalSpeedChanged();
+
+ Q_REVISION(2) void magneticVariationChanged();
+ Q_REVISION(2) void magneticVariationValidChanged();
+
+private:
+ QGeoPositionInfo m_info;
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QDeclarativePosition)
+
+#endif
diff --git a/src/positioningquick/qdeclarativepositionsource.cpp b/src/positioningquick/qdeclarativepositionsource.cpp
new file mode 100644
index 00000000..d290de25
--- /dev/null
+++ b/src/positioningquick/qdeclarativepositionsource.cpp
@@ -0,0 +1,768 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 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:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdeclarativepositionsource_p.h"
+#include "qdeclarativeposition_p.h"
+
+#include <QtCore/QCoreApplication>
+#include <QtQml/qqmlinfo.h>
+#include <QtQml/qqml.h>
+#include <qnmeapositioninfosource.h>
+#include <QFile>
+#include <QtNetwork/QTcpSocket>
+#include <QTimer>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype PositionSource
+ \instantiates QDeclarativePositionSource
+ \inqmlmodule QtPositioning
+ \since 5.2
+
+ \brief The PositionSource type provides the device's current position.
+
+ The PositionSource type provides information about the user device's
+ current position. The position is available as a \l{Position} type, which
+ contains all the standard parameters typically available from GPS and other
+ similar systems, including longitude, latitude, speed and accuracy details.
+
+ As different position sources are available on different platforms and
+ devices, these are categorized by their basic type (Satellite, NonSatellite,
+ and AllPositioningMethods). The available methods for the current platform
+ can be enumerated in the \l{supportedPositioningMethods} property.
+
+ To indicate which methods are suitable for your application, set the
+ \l{preferredPositioningMethods} property. If the preferred methods are not
+ available, the default source of location data for the platform will be
+ chosen instead. If no default source is available (because none are installed
+ for the runtime platform, or because it is disabled), the \l{valid} property
+ will be set to false.
+
+ The \l updateInterval property can then be used to indicate how often your
+ application wishes to receive position updates. The \l{start}(),
+ \l{stop}() and \l{update}() methods can be used to control the operation
+ of the PositionSource, as well as the \l{active} property, which when set
+ is equivalent to calling \l{start}() or \l{stop}().
+
+ When the PositionSource is active, position updates can be retrieved
+ either by simply using the \l{position} property in a binding (as the
+ value of another item's property), or by providing an implementation of
+ the \c {onPositionChanged} signal-handler.
+
+ \section2 Example Usage
+
+ The following example shows a simple PositionSource used to receive
+ updates every second and print the longitude and latitude out to
+ the console.
+
+ \code
+ PositionSource {
+ id: src
+ updateInterval: 1000
+ active: true
+
+ onPositionChanged: {
+ var coord = src.position.coordinate;
+ console.log("Coordinate:", coord.longitude, coord.latitude);
+ }
+ }
+ \endcode
+
+ The \l{geoflickr}{GeoFlickr} example application shows how to use
+ a PositionSource in your application to retrieve local data for users
+ from a REST web service.
+
+ \sa {QtPositioning::Position}, {QGeoPositionInfoSource}
+
+*/
+
+/*!
+ \qmlsignal PositionSource::updateTimeout()
+
+ If \l update() was called, this signal is emitted if the current position could not be
+ retrieved within a certain amount of time.
+
+ If \l start() was called, this signal is emitted if the position engine determines that
+ it is not able to provide further regular updates.
+
+ \since Qt Positioning 5.5
+
+ \sa QGeoPositionInfoSource::updateTimeout()
+*/
+
+
+QDeclarativePositionSource::QDeclarativePositionSource()
+: m_positionSource(0), m_preferredPositioningMethods(NoPositioningMethods), m_nmeaFile(0),
+ m_nmeaSocket(0), m_active(false), m_singleUpdate(false), m_updateInterval(0),
+ m_sourceError(NoError)
+{
+}
+
+QDeclarativePositionSource::~QDeclarativePositionSource()
+{
+ delete m_nmeaFile;
+ delete m_nmeaSocket;
+ delete m_positionSource;
+}
+
+
+/*!
+ \qmlproperty string PositionSource::name
+
+ This property holds the unique internal name for the plugin currently
+ providing position information.
+
+ Setting the property causes the PositionSource to use a particular positioning provider. If
+ the PositionSource is active at the time that the name property is changed, it will become
+ inactive. If the specified positioning provider cannot be loaded the position source will
+ become invalid.
+
+ Changing the name property may cause the \l {updateInterval}, \l {supportedPositioningMethods}
+ and \l {preferredPositioningMethods} properties to change as well.
+*/
+
+
+QString QDeclarativePositionSource::name() const
+{
+ if (m_positionSource)
+ return m_positionSource->sourceName();
+ else
+ return QString();
+}
+
+void QDeclarativePositionSource::setName(const QString &newName)
+{
+ if (m_positionSource && m_positionSource->sourceName() == newName)
+ return;
+
+ const QString previousName = name();
+ int previousUpdateInterval = updateInterval();
+ PositioningMethods previousPositioningMethods = supportedPositioningMethods();
+ PositioningMethods previousPreferredPositioningMethods = preferredPositioningMethods();
+
+ delete m_positionSource;
+ if (newName.isEmpty())
+ m_positionSource = QGeoPositionInfoSource::createDefaultSource(this);
+ else
+ m_positionSource = QGeoPositionInfoSource::createSource(newName, this);
+
+ if (m_positionSource) {
+ connect(m_positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)),
+ this, SLOT(positionUpdateReceived(QGeoPositionInfo)));
+ connect(m_positionSource, SIGNAL(error(QGeoPositionInfoSource::Error)),
+ this, SLOT(sourceErrorReceived(QGeoPositionInfoSource::Error)));
+ connect(m_positionSource, SIGNAL(updateTimeout()),
+ this, SLOT(updateTimeoutReceived()));
+
+ m_positionSource->setUpdateInterval(m_updateInterval);
+ m_positionSource->setPreferredPositioningMethods(
+ static_cast<QGeoPositionInfoSource::PositioningMethods>(int(m_preferredPositioningMethods)));
+
+ setPosition(m_positionSource->lastKnownPosition());
+ }
+
+ if (previousUpdateInterval != updateInterval())
+ emit updateIntervalChanged();
+
+ if (previousPreferredPositioningMethods != preferredPositioningMethods())
+ emit preferredPositioningMethodsChanged();
+
+ if (previousPositioningMethods != supportedPositioningMethods())
+ emit supportedPositioningMethodsChanged();
+
+ emit validityChanged();
+
+ if (m_active) {
+ m_active = false;
+ emit activeChanged();
+ }
+
+ if (previousName != name())
+ emit nameChanged();
+}
+
+/*!
+ \qmlproperty bool PositionSource::valid
+
+ This property is true if the PositionSource object has acquired a valid
+ backend plugin to provide data. If false, other methods on the PositionSource
+ will have no effect.
+
+ Applications should check this property to determine whether positioning is
+ available and enabled on the runtime platform, and react accordingly.
+*/
+bool QDeclarativePositionSource::isValid() const
+{
+ return (m_positionSource != 0);
+}
+
+/*!
+ \internal
+*/
+void QDeclarativePositionSource::setNmeaSource(const QUrl &nmeaSource)
+{
+ if (nmeaSource.scheme() == QLatin1String("socket")) {
+ if (m_nmeaSocket
+ && nmeaSource.host() == m_nmeaSocket->peerName()
+ && nmeaSource.port() == m_nmeaSocket->peerPort()) {
+ return;
+ }
+
+ delete m_nmeaSocket;
+ m_nmeaSocket = new QTcpSocket();
+
+ connect(m_nmeaSocket, static_cast<void (QTcpSocket::*)(QAbstractSocket::SocketError)> (&QAbstractSocket::error),
+ this, &QDeclarativePositionSource::socketError);
+ connect(m_nmeaSocket, &QTcpSocket::connected,
+ this, &QDeclarativePositionSource::socketConnected);
+
+ m_nmeaSocket->connectToHost(nmeaSource.host(), nmeaSource.port(), QTcpSocket::ReadOnly);
+ } else {
+ // Strip the filename. This is clumsy but the file may be prefixed in several
+ // ways: "file:///", "qrc:///", "/", "" in platform dependent manner.
+ QString localFileName = nmeaSource.toString();
+ if (!QFile::exists(localFileName)) {
+ if (localFileName.startsWith(QStringLiteral("qrc:///"))) {
+ localFileName.remove(0, 7);
+ } else if (localFileName.startsWith(QStringLiteral("file:///"))) {
+ localFileName.remove(0, 7);
+ } else if (localFileName.startsWith(QStringLiteral("qrc:/"))) {
+ localFileName.remove(0, 5);
+ }
+ if (!QFile::exists(localFileName) && localFileName.startsWith('/')) {
+ localFileName.remove(0,1);
+ }
+ }
+ if (m_nmeaFileName == localFileName)
+ return;
+ m_nmeaFileName = localFileName;
+
+ PositioningMethods previousPositioningMethods = supportedPositioningMethods();
+
+ // The current position source needs to be deleted
+ // because QNmeaPositionInfoSource can be bound only to a one file.
+ delete m_nmeaSocket;
+ m_nmeaSocket = 0;
+ delete m_positionSource;
+ m_positionSource = 0;
+ setPosition(QGeoPositionInfo());
+ // Create the NMEA source based on the given data. QML has automatically set QUrl
+ // type to point to correct path. If the file is not found, check if the file actually
+ // was an embedded resource file.
+ delete m_nmeaFile;
+ m_nmeaFile = new QFile(localFileName);
+ if (!m_nmeaFile->exists()) {
+ localFileName.prepend(':');
+ m_nmeaFile->setFileName(localFileName);
+ }
+ if (m_nmeaFile->exists()) {
+#ifdef QDECLARATIVE_POSITION_DEBUG
+ qDebug() << "QDeclarativePositionSource NMEA File was found: " << localFileName;
+#endif
+ m_positionSource = new QNmeaPositionInfoSource(QNmeaPositionInfoSource::SimulationMode);
+ (qobject_cast<QNmeaPositionInfoSource *>(m_positionSource))->setUserEquivalentRangeError(2.5); // it is internally multiplied by 2 in qlocationutils_readGga
+ (qobject_cast<QNmeaPositionInfoSource *>(m_positionSource))->setDevice(m_nmeaFile);
+ connect(m_positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)),
+ this, SLOT(positionUpdateReceived(QGeoPositionInfo)));
+ connect(m_positionSource, SIGNAL(error(QGeoPositionInfoSource::Error)),
+ this, SLOT(sourceErrorReceived(QGeoPositionInfoSource::Error)));
+ connect(m_positionSource, SIGNAL(updateTimeout()),
+ this, SLOT(updateTimeoutReceived()));
+
+ setPosition(m_positionSource->lastKnownPosition());
+ if (m_active && !m_singleUpdate) {
+ // Keep on updating even though source changed
+ QTimer::singleShot(0, this, SLOT(start()));
+ }
+ } else {
+ qmlWarning(this) << QStringLiteral("Nmea file not found") << localFileName;
+#ifdef QDECLARATIVE_POSITION_DEBUG
+ qDebug() << "QDeclarativePositionSource NMEA File was not found: " << localFileName;
+#endif
+ if (m_active) {
+ m_active = false;
+ m_singleUpdate = false;
+ emit activeChanged();
+ }
+ }
+
+ if (previousPositioningMethods != supportedPositioningMethods())
+ emit supportedPositioningMethodsChanged();
+ }
+
+ m_nmeaSource = nmeaSource;
+ emit nmeaSourceChanged();
+}
+
+/*!
+ \internal
+*/
+void QDeclarativePositionSource::socketConnected()
+{
+#ifdef QDECLARATIVE_POSITION_DEBUG
+ qDebug() << "Socket connected: " << m_nmeaSocket->peerName();
+#endif
+ PositioningMethods previousPositioningMethods = supportedPositioningMethods();
+
+ // The current position source needs to be deleted
+ // because QNmeaPositionInfoSource can be bound only to a one file.
+ delete m_nmeaFile;
+ m_nmeaFile = 0;
+ delete m_positionSource;
+
+ m_positionSource = new QNmeaPositionInfoSource(QNmeaPositionInfoSource::RealTimeMode);
+ (qobject_cast<QNmeaPositionInfoSource *>(m_positionSource))->setDevice(m_nmeaSocket);
+
+ connect(m_positionSource, &QNmeaPositionInfoSource::positionUpdated,
+ this, &QDeclarativePositionSource::positionUpdateReceived);
+ connect(m_positionSource, SIGNAL(error(QGeoPositionInfoSource::Error)),
+ this, SLOT(sourceErrorReceived(QGeoPositionInfoSource::Error)));
+ connect(m_positionSource, SIGNAL(updateTimeout()),
+ this, SLOT(updateTimeoutReceived()));
+
+ setPosition(m_positionSource->lastKnownPosition());
+
+ if (m_active && !m_singleUpdate) {
+ // Keep on updating even though source changed
+ QTimer::singleShot(0, this, SLOT(start()));
+ }
+
+ if (previousPositioningMethods != supportedPositioningMethods())
+ emit supportedPositioningMethodsChanged();
+}
+
+/*!
+ \internal
+*/
+void QDeclarativePositionSource::socketError(QAbstractSocket::SocketError error)
+{
+ delete m_nmeaSocket;
+ m_nmeaSocket = 0;
+
+ switch (error) {
+ case QAbstractSocket::UnknownSocketError:
+ m_sourceError = QDeclarativePositionSource::UnknownSourceError;
+ break;
+ case QAbstractSocket::SocketAccessError:
+ m_sourceError = QDeclarativePositionSource::AccessError;
+ break;
+ case QAbstractSocket::RemoteHostClosedError:
+ m_sourceError = QDeclarativePositionSource::ClosedError;
+ break;
+ default:
+ qWarning() << "Connection failed! QAbstractSocket::SocketError" << error;
+ m_sourceError = QDeclarativePositionSource::SocketError;
+ break;
+ }
+
+ emit sourceErrorChanged();
+}
+
+
+void QDeclarativePositionSource::updateTimeoutReceived()
+{
+ if (!m_active)
+ return;
+
+ if (m_singleUpdate) {
+ m_singleUpdate = false;
+
+ // only singleUpdate based timeouts change activity
+ // continuous updates may resume again (see QGeoPositionInfoSource::startUpdates())
+ m_active = false;
+ emit activeChanged();
+ }
+
+ emit updateTimeout();
+}
+
+void QDeclarativePositionSource::setPosition(const QGeoPositionInfo &pi)
+{
+ m_position.setPosition(pi);
+ emit positionChanged();
+}
+
+/*!
+ \internal
+*/
+void QDeclarativePositionSource::setUpdateInterval(int updateInterval)
+{
+ if (m_positionSource) {
+ int previousUpdateInterval = m_positionSource->updateInterval();
+
+ m_updateInterval = updateInterval;
+
+ if (previousUpdateInterval != updateInterval) {
+ m_positionSource->setUpdateInterval(updateInterval);
+ if (previousUpdateInterval != m_positionSource->updateInterval())
+ emit updateIntervalChanged();
+ }
+ } else {
+ if (m_updateInterval != updateInterval) {
+ m_updateInterval = updateInterval;
+ emit updateIntervalChanged();
+ }
+ }
+}
+
+/*!
+ \qmlproperty url PositionSource::nmeaSource
+
+ This property holds the source for NMEA (National Marine Electronics Association)
+ position-specification data (file). One purpose of this property is to be of
+ development convenience.
+
+ Setting this property will override any other position source. Currently only
+ files local to the .qml -file are supported. The NMEA source is created in simulation mode,
+ meaning that the data and time information in the NMEA source data is used to provide
+ positional updates at the rate at which the data was originally recorded.
+
+ If nmeaSource has been set for a PositionSource object, there is no way to revert
+ back to non-file sources.
+*/
+
+QUrl QDeclarativePositionSource::nmeaSource() const
+{
+ return m_nmeaSource;
+}
+
+/*!
+ \qmlproperty int PositionSource::updateInterval
+
+ This property holds the desired interval between updates (milliseconds).
+
+ \sa {QGeoPositionInfoSource::updateInterval()}
+*/
+
+int QDeclarativePositionSource::updateInterval() const
+{
+ if (!m_positionSource)
+ return m_updateInterval;
+
+ return m_positionSource->updateInterval();
+}
+
+/*!
+ \qmlproperty enumeration PositionSource::supportedPositioningMethods
+
+ This property holds the supported positioning methods of the
+ current source.
+
+ \list
+ \li PositionSource.NoPositioningMethods - No positioning methods supported (no source).
+ \li PositionSource.SatellitePositioningMethods - Satellite-based positioning methods such as GPS are supported.
+ \li PositionSource.NonSatellitePositioningMethods - Non-satellite-based methods are supported.
+ \li PositionSource.AllPositioningMethods - Both satellite-based and non-satellite positioning methods are supported.
+ \endlist
+
+*/
+
+QDeclarativePositionSource::PositioningMethods QDeclarativePositionSource::supportedPositioningMethods() const
+{
+ if (m_positionSource) {
+ return static_cast<QDeclarativePositionSource::PositioningMethods>(
+ int(m_positionSource->supportedPositioningMethods()));
+ }
+ return QDeclarativePositionSource::NoPositioningMethods;
+}
+
+/*!
+ \qmlproperty enumeration PositionSource::preferredPositioningMethods
+
+ This property holds the preferred positioning methods of the
+ current source.
+
+ \list
+ \li PositionSource.NoPositioningMethods - No positioning method is preferred.
+ \li PositionSource.SatellitePositioningMethods - Satellite-based positioning methods such as GPS should be preferred.
+ \li PositionSource.NonSatellitePositioningMethods - Non-satellite-based methods should be preferred.
+ \li PositionSource.AllPositioningMethods - Any positioning methods are acceptable.
+ \endlist
+
+*/
+
+void QDeclarativePositionSource::setPreferredPositioningMethods(PositioningMethods methods)
+{
+ if (m_positionSource) {
+ PositioningMethods previousPreferredPositioningMethods = preferredPositioningMethods();
+
+ m_preferredPositioningMethods = methods;
+
+ if (previousPreferredPositioningMethods != methods) {
+ m_positionSource->setPreferredPositioningMethods(
+ static_cast<QGeoPositionInfoSource::PositioningMethods>(int(methods)));
+ if (previousPreferredPositioningMethods != m_positionSource->preferredPositioningMethods())
+ emit preferredPositioningMethodsChanged();
+ }
+ } else {
+ if (m_preferredPositioningMethods != methods) {
+ m_preferredPositioningMethods = methods;
+ emit preferredPositioningMethodsChanged();
+ }
+ }
+}
+
+QDeclarativePositionSource::PositioningMethods QDeclarativePositionSource::preferredPositioningMethods() const
+{
+ if (m_positionSource) {
+ return static_cast<QDeclarativePositionSource::PositioningMethods>(
+ int(m_positionSource->preferredPositioningMethods()));
+ }
+ return m_preferredPositioningMethods;
+}
+
+/*!
+ \qmlmethod PositionSource::start()
+
+ Requests updates from the location source.
+ Uses \l updateInterval if set, default interval otherwise.
+ If there is no source available, this method has no effect.
+
+ \sa stop, update, active
+*/
+
+void QDeclarativePositionSource::start()
+{
+ if (m_positionSource)
+ m_positionSource->startUpdates();
+
+ if (!m_active) {
+ m_active = true;
+ emit activeChanged();
+ }
+}
+
+/*!
+ \qmlmethod PositionSource::update()
+
+ A convenience method to request single update from the location source.
+ If there is no source available, this method has no effect.
+
+ If the position source is not active, it will be activated for as
+ long as it takes to receive an update, or until the request times
+ out. The request timeout period is source-specific.
+
+ \sa start, stop, active
+*/
+
+void QDeclarativePositionSource::update()
+{
+ if (m_positionSource) {
+ if (!m_active) {
+ m_active = true;
+ m_singleUpdate = true;
+ emit activeChanged();
+ }
+ // Use default timeout value. Set active before calling the
+ // update request because on some platforms there may
+ // be results immediately.
+ m_positionSource->requestUpdate();
+ }
+}
+
+/*!
+ \qmlmethod PositionSource::stop()
+
+ Stops updates from the location source.
+ If there is no source available or it is not active,
+ this method has no effect.
+
+ \sa start, update, active
+*/
+
+void QDeclarativePositionSource::stop()
+{
+ if (m_positionSource) {
+ m_positionSource->stopUpdates();
+ if (m_active) {
+ m_active = false;
+ emit activeChanged();
+ }
+ }
+}
+
+/*!
+ \qmlproperty bool PositionSource::active
+
+ This property indicates whether the position source is active.
+ Setting this property to false equals calling \l stop, and
+ setting this property true equals calling \l start.
+
+ \sa start, stop, update
+*/
+void QDeclarativePositionSource::setActive(bool active)
+{
+ if (active == m_active)
+ return;
+
+ if (active)
+ QTimer::singleShot(0, this, SLOT(start())); // delay ensures all properties have been set
+ else
+ stop();
+}
+
+bool QDeclarativePositionSource::isActive() const
+{
+ return m_active;
+}
+
+/*!
+ \qmlproperty Position PositionSource::position
+
+ This property holds the last known positional data.
+ It is a read-only property.
+
+ The Position type has different positional member variables,
+ whose validity can be checked with appropriate validity functions
+ (for example sometimes an update does not have speed or altitude data).
+
+ However, whenever a \c {positionChanged} signal has been received, at least
+ position::coordinate::latitude, position::coordinate::longitude, and position::timestamp can
+ be assumed to be valid.
+
+ \sa start, stop, update
+*/
+
+QDeclarativePosition *QDeclarativePositionSource::position()
+{
+ return &m_position;
+}
+
+void QDeclarativePositionSource::positionUpdateReceived(const QGeoPositionInfo &update)
+{
+ setPosition(update);
+
+ if (m_singleUpdate && m_active) {
+ m_active = false;
+ m_singleUpdate = false;
+ emit activeChanged();
+ }
+}
+
+
+/*!
+ \qmlproperty enumeration PositionSource::sourceError
+
+ This property holds the error which last occurred with the PositionSource.
+
+ \list
+ \li PositionSource.AccessError - The connection setup to the remote positioning backend failed because the
+ application lacked the required privileges.
+ \li PositionSource.ClosedError - The positioning backend closed the connection, which happens for example in case
+ the user is switching location services to off. As soon as the location service is re-enabled
+ regular updates will resume.
+ \li PositionSource.NoError - No error has occurred.
+ \li PositionSource.UnknownSourceError - An unidentified error occurred.
+ \li PositionSource.SocketError - An error occurred while connecting to an nmea source using a socket.
+ \endlist
+
+*/
+
+QDeclarativePositionSource::SourceError QDeclarativePositionSource::sourceError() const
+{
+ return m_sourceError;
+}
+
+QGeoPositionInfoSource *QDeclarativePositionSource::positionSource() const
+{
+ return m_positionSource;
+}
+
+void QDeclarativePositionSource::componentComplete()
+{
+ if (!m_positionSource) {
+ int previousUpdateInterval = updateInterval();
+ PositioningMethods previousPositioningMethods = supportedPositioningMethods();
+ PositioningMethods previousPreferredPositioningMethods = preferredPositioningMethods();
+
+ m_positionSource = QGeoPositionInfoSource::createDefaultSource(this);
+ if (m_positionSource) {
+ connect(m_positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)),
+ this, SLOT(positionUpdateReceived(QGeoPositionInfo)));
+ connect(m_positionSource, SIGNAL(error(QGeoPositionInfoSource::Error)),
+ this, SLOT(sourceErrorReceived(QGeoPositionInfoSource::Error)));
+ connect(m_positionSource, SIGNAL(updateTimeout()),
+ this, SLOT(updateTimeoutReceived()));
+
+ m_positionSource->setUpdateInterval(m_updateInterval);
+ m_positionSource->setPreferredPositioningMethods(
+ static_cast<QGeoPositionInfoSource::PositioningMethods>(int(m_preferredPositioningMethods)));
+
+ setPosition(m_positionSource->lastKnownPosition());
+
+ if (m_active)
+ QTimer::singleShot(0, this, SLOT(start())); // delay ensures all properties have been set
+ } else if (m_active) {
+ m_active = false;
+ emit activeChanged();
+ }
+
+ if (previousUpdateInterval != updateInterval())
+ emit updateIntervalChanged();
+
+ if (previousPreferredPositioningMethods != preferredPositioningMethods())
+ emit preferredPositioningMethodsChanged();
+
+ if (previousPositioningMethods != supportedPositioningMethods())
+ emit supportedPositioningMethodsChanged();
+
+ emit validityChanged();
+ emit nameChanged();
+ }
+}
+
+/*!
+ \internal
+*/
+void QDeclarativePositionSource::sourceErrorReceived(const QGeoPositionInfoSource::Error error)
+{
+ if (error == QGeoPositionInfoSource::AccessError)
+ m_sourceError = QDeclarativePositionSource::AccessError;
+ else if (error == QGeoPositionInfoSource::ClosedError)
+ m_sourceError = QDeclarativePositionSource::ClosedError;
+ else if (error == QGeoPositionInfoSource::NoError)
+ return; //nothing to do
+ else
+ m_sourceError = QDeclarativePositionSource::UnknownSourceError;
+
+ emit sourceErrorChanged();
+}
+
+QT_END_NAMESPACE
diff --git a/src/positioningquick/qdeclarativepositionsource_p.h b/src/positioningquick/qdeclarativepositionsource_p.h
new file mode 100644
index 00000000..bb9b618a
--- /dev/null
+++ b/src/positioningquick/qdeclarativepositionsource_p.h
@@ -0,0 +1,174 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 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:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+***************************************************************************/
+
+#ifndef QDECLARATIVEPOSITIONSOURCE_H
+#define QDECLARATIVEPOSITIONSOURCE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qdeclarativeposition_p.h"
+
+#include <QtCore/QObject>
+#include <QtNetwork/QAbstractSocket>
+#include <QtQml/QQmlParserStatus>
+#include <QtPositioningQuick/private/qpositioningquickglobal_p.h>
+#include <QtPositioning/QGeoPositionInfoSource>
+
+QT_BEGIN_NAMESPACE
+
+class QFile;
+class QTcpSocket;
+
+class Q_POSITIONINGQUICK_PRIVATE_EXPORT QDeclarativePositionSource : public QObject, public QQmlParserStatus
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QDeclarativePosition *position READ position NOTIFY positionChanged)
+ Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
+ Q_PROPERTY(bool valid READ isValid NOTIFY validityChanged)
+ Q_PROPERTY(QUrl nmeaSource READ nmeaSource WRITE setNmeaSource NOTIFY nmeaSourceChanged)
+ Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval NOTIFY updateIntervalChanged)
+ Q_PROPERTY(PositioningMethods supportedPositioningMethods READ supportedPositioningMethods NOTIFY supportedPositioningMethodsChanged)
+ Q_PROPERTY(PositioningMethods preferredPositioningMethods READ preferredPositioningMethods WRITE setPreferredPositioningMethods NOTIFY preferredPositioningMethodsChanged)
+ Q_PROPERTY(SourceError sourceError READ sourceError NOTIFY sourceErrorChanged)
+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
+ Q_ENUMS(PositioningMethod)
+
+ Q_INTERFACES(QQmlParserStatus)
+
+public:
+ enum PositioningMethod {
+ NoPositioningMethods = QGeoPositionInfoSource::NoPositioningMethods,
+ SatellitePositioningMethods = QGeoPositionInfoSource::SatellitePositioningMethods,
+ NonSatellitePositioningMethods = QGeoPositionInfoSource::NonSatellitePositioningMethods,
+ AllPositioningMethods = QGeoPositionInfoSource::AllPositioningMethods
+ };
+
+ Q_DECLARE_FLAGS(PositioningMethods, PositioningMethod)
+ Q_FLAGS(PositioningMethods)
+
+ enum SourceError {
+ AccessError = QGeoPositionInfoSource::AccessError,
+ ClosedError = QGeoPositionInfoSource::ClosedError,
+ UnknownSourceError = QGeoPositionInfoSource::UnknownSourceError,
+ NoError = QGeoPositionInfoSource::NoError,
+
+ //Leave a gap for future error enum values in QGeoPositionInfoSource::Error
+ SocketError = 100
+ };
+ Q_ENUMS(SourceError)
+
+ QDeclarativePositionSource();
+ ~QDeclarativePositionSource();
+ void setNmeaSource(const QUrl &nmeaSource);
+ void setUpdateInterval(int updateInterval);
+ void setActive(bool active);
+ void setPreferredPositioningMethods(PositioningMethods methods);
+
+ QString name() const;
+ void setName(const QString &name);
+
+ QUrl nmeaSource() const;
+ int updateInterval() const;
+ bool isActive() const;
+ bool isValid() const;
+ QDeclarativePosition *position();
+ PositioningMethods supportedPositioningMethods() const;
+ PositioningMethods preferredPositioningMethods() const;
+ SourceError sourceError() const;
+ QGeoPositionInfoSource *positionSource() const;
+
+ // Virtuals from QQmlParserStatus
+ void classBegin() { }
+ void componentComplete();
+
+public Q_SLOTS:
+ void update(); // TODO Qt 6 change to void update(int)
+ void start();
+ void stop();
+
+Q_SIGNALS:
+ void positionChanged();
+ void activeChanged();
+ void nmeaSourceChanged();
+ void updateIntervalChanged();
+ void supportedPositioningMethodsChanged();
+ void preferredPositioningMethodsChanged();
+ void sourceErrorChanged();
+ void nameChanged();
+ void validityChanged();
+ void updateTimeout();
+
+private Q_SLOTS:
+ void positionUpdateReceived(const QGeoPositionInfo &update);
+ void sourceErrorReceived(const QGeoPositionInfoSource::Error error);
+ void socketConnected();
+ void socketError(QAbstractSocket::SocketError error);
+ void updateTimeoutReceived();
+
+private:
+ void setPosition(const QGeoPositionInfo &pi);
+
+ QGeoPositionInfoSource *m_positionSource;
+ QDeclarativePosition m_position;
+ PositioningMethods m_preferredPositioningMethods;
+ QFile *m_nmeaFile;
+ QTcpSocket *m_nmeaSocket;
+ QString m_nmeaFileName;
+ QUrl m_nmeaSource;
+ bool m_active;
+ bool m_singleUpdate;
+ int m_updateInterval;
+ SourceError m_sourceError;
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QDeclarativePositionSource)
+
+#endif
diff --git a/src/positioningquick/qpositioningquickglobal.h b/src/positioningquick/qpositioningquickglobal.h
new file mode 100644
index 00000000..214e4628
--- /dev/null
+++ b/src/positioningquick/qpositioningquickglobal.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QPOSITIONINGQUICKGLOBAL_H
+#define QPOSITIONINGQUICKGLOBAL_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qglobal.h>
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_STATIC
+# if defined(QT_BUILD_POSITIONINGQUICK_LIB)
+# define Q_POSITIONINGQUICK_EXPORT Q_DECL_EXPORT
+# else
+# define Q_POSITIONINGQUICK_EXPORT Q_DECL_IMPORT
+# endif
+#else
+# define Q_POSITIONINGQUICK_EXPORT
+#endif
+
+QT_END_NAMESPACE
+
+#endif // QPOSITIONINGQUICKGLOBAL_H
diff --git a/src/positioningquick/qpositioningquickglobal_p.h b/src/positioningquick/qpositioningquickglobal_p.h
new file mode 100644
index 00000000..46e40f25
--- /dev/null
+++ b/src/positioningquick/qpositioningquickglobal_p.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QPOSITIONINGQUICKGLOBAL_P_H
+#define QPOSITIONINGQUICKGLOBAL_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qpositioningquickglobal.h"
+
+QT_BEGIN_NAMESPACE
+
+#define Q_POSITIONINGQUICK_PRIVATE_EXPORT Q_POSITIONINGQUICK_EXPORT
+
+QT_END_NAMESPACE
+
+#endif // QPOSITIONINGQUICKGLOBAL_P_H