diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2013-08-16 10:02:13 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-02 14:30:40 +0200 |
commit | d35d28017d731dba9e2a4f2622d2cec97e724e55 (patch) | |
tree | fd1fbbaeb20c641ca868a424f3ee051c7c6c3a28 /src/imports/positioning | |
parent | ea5f625ab90406d7407bc961b90b3993230dd03a (diff) | |
download | qtlocation-d35d28017d731dba9e2a4f2622d2cec97e724e55.tar.gz |
Split QtLocation into QtPositioning and QtLocation
QtPositioning is not dependent on any gui component and mostly
covers everything around the retrieval of position information.
QtLocation covers place, map and navigation APIs.
Several documentation issues were fixed during the process.
Change-Id: I98e2a53065549a2fc43f93a75b4f65b5bc884c92
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/imports/positioning')
23 files changed, 3803 insertions, 0 deletions
diff --git a/src/imports/positioning/error_messages.cpp b/src/imports/positioning/error_messages.cpp new file mode 100644 index 00000000..45b85e0a --- /dev/null +++ b/src/imports/positioning/error_messages.cpp @@ -0,0 +1,48 @@ +/*************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "error_messages.h" + +QT_BEGIN_NAMESPACE + +const char CONTEXT_NAME[] = "QtPositioningQML"; +const char MISSED_NMEA_FILE[] = QT_TRANSLATE_NOOP("QtPositioningQML", "Nmea file not found."); + +QT_END_NAMESPACE diff --git a/src/imports/positioning/error_messages.h b/src/imports/positioning/error_messages.h new file mode 100644 index 00000000..3c888dff --- /dev/null +++ b/src/imports/positioning/error_messages.h @@ -0,0 +1,54 @@ + +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef ERROR_MESSAGES_H +#define ERROR_MESSAGES_H + +#include <QString> + +QT_BEGIN_NAMESPACE + +extern const char CONTEXT_NAME[]; +extern const char MISSED_NMEA_FILE[]; + +QT_END_NAMESPACE + +#endif // ERROR_MESSAGES_H diff --git a/src/imports/positioning/locationsingleton.cpp b/src/imports/positioning/locationsingleton.cpp new file mode 100644 index 00000000..c44db946 --- /dev/null +++ b/src/imports/positioning/locationsingleton.cpp @@ -0,0 +1,163 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "locationsingleton.h" + +/*! + \qmltype QtPositioning + \instantiates LocationSingleton + \inqmlmodule QtPositioning 5.0 + + \brief The QtPositioning global object provides useful functions for working with location-based + types in QML. + + \qml + import QtPositioning 5.0 + + Item { + property variant coordinate: QtPositioning.coordinate(-27.5, 153.1) + } + \endqml +*/ + +LocationSingleton::LocationSingleton(QObject *parent) +: QObject(parent) +{ +} + +/*! + \qmlmethod coordinate ::QtPositioning::coordinate() + + Constructs an invalid coordinate. + +*/ +QGeoCoordinate LocationSingleton::coordinate() const +{ + return QGeoCoordinate(); +} + +/*! + \qmlmethod coordinate QtPositioning::coordinate(real latitude, real longitue, real altitude) const + + Constructs a coordinate with the specified \a latitude, \a longitude and optional \a altitude. + Both \a latitude and \a longitude must be valid, otherwise an invalid coordinate is returned. + + \sa {coordinate} +*/ +QGeoCoordinate LocationSingleton::coordinate(double latitude, double longitude, double altitude) const +{ + return QGeoCoordinate(latitude, longitude, altitude); +} + +/*! + \qmlmethod geoshape QtPositioning::shape() const + + Constructs an invalid geoshape. + + \sa {geoshape} +*/ +QGeoShape LocationSingleton::shape() const +{ + return QGeoShape(); +} + +/*! + \qmlmethod georectangle QtPositioning::rectangle() const + + Constructs an invalid georectangle. + + \sa {georectangle} +*/ +QGeoRectangle LocationSingleton::rectangle() const +{ + return QGeoRectangle(); +} + +/*! + \qmlmethod georectangle QtPositioning::rectangle(coordinate center, real width, real height) const + + Constructs a georectangle centered at \a center with a width of \a width degrees and a hight of + \a height degrees. + + \sa {georectangle} +*/ +QGeoRectangle LocationSingleton::rectangle(const QGeoCoordinate ¢er, + double width, double height) const +{ + return QGeoRectangle(center, width, height); +} + +/*! + \qmlmethod georectangle QtPositioning::rectangle(coordinate topLeft, coordinate bottomRight) const + + Constructs a georectangle with its top left corner positioned at \a topLeft and its bottom + right corner positioned at \a {bottomLeft}. + + \sa {georectangle} +*/ +QGeoRectangle LocationSingleton::rectangle(const QGeoCoordinate &topLeft, + const QGeoCoordinate &bottomRight) const +{ + return QGeoRectangle(topLeft, bottomRight); +} + +/*! + \qmlmethod geocircle QtPositioning::circle() const + + Constructs an invalid geocircle. + + \sa {geocircle} +*/ +QGeoCircle LocationSingleton::circle() const +{ + return QGeoCircle(); +} + +/*! + \qmlmethod geocircle QtPositioning::circle(coordinate center, real radius) const + + Constructs a geocircle centered at \a center with a radius of \a radius meters. +*/ +QGeoCircle LocationSingleton::circle(const QGeoCoordinate ¢er, qreal radius) const +{ + return QGeoCircle(center, radius); +} + diff --git a/src/imports/positioning/locationsingleton.h b/src/imports/positioning/locationsingleton.h new file mode 100644 index 00000000..b5e6476e --- /dev/null +++ b/src/imports/positioning/locationsingleton.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LOCATIONSINGLETON_H +#define LOCATIONSINGLETON_H + +#include <QtCore/QObject> +#include <QtCore/qnumeric.h> +#include <QtPositioning/QGeoCoordinate> +#include <QtPositioning/QGeoShape> +#include <QtPositioning/QGeoRectangle> +#include <QtPositioning/QGeoCircle> + +class LocationSingleton : public QObject +{ + Q_OBJECT + +public: + explicit LocationSingleton(QObject *parent = 0); + + Q_INVOKABLE QGeoCoordinate coordinate() const; + Q_INVOKABLE QGeoCoordinate coordinate(double latitude, double longitude, + double altitude = qQNaN()) const; + + Q_INVOKABLE QGeoShape shape() const; + + Q_INVOKABLE QGeoRectangle rectangle() const; + Q_INVOKABLE QGeoRectangle rectangle(const QGeoCoordinate ¢er, + double width, double height) const; + Q_INVOKABLE QGeoRectangle rectangle(const QGeoCoordinate &topLeft, + const QGeoCoordinate &bottomRight) const; + + Q_INVOKABLE QGeoCircle circle() const; + Q_INVOKABLE QGeoCircle circle(const QGeoCoordinate ¢er, qreal radius = -1.0) const; +}; + +#endif // LOCATIONSINGLETON_H diff --git a/src/imports/positioning/locationvaluetypeprovider.cpp b/src/imports/positioning/locationvaluetypeprovider.cpp new file mode 100644 index 00000000..9ee93dbe --- /dev/null +++ b/src/imports/positioning/locationvaluetypeprovider.cpp @@ -0,0 +1,231 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "locationvaluetypeprovider.h" +#include "qdeclarativecoordinate_p.h" +#include "qdeclarativegeoshape.h" +#include "qdeclarativegeorectangle.h" +#include "qdeclarativegeocircle.h" +#include <QtPositioning/QGeoRectangle> +#include <QtPositioning/QGeoCircle> + +QT_BEGIN_NAMESPACE + +LocationValueTypeProvider::LocationValueTypeProvider() +: QQmlValueTypeProvider() +{ +} + +bool LocationValueTypeProvider::create(int type, QQmlValueType *&v) +{ + if (type == qMetaTypeId<QGeoCoordinate>()) + return typedCreate<CoordinateValueType>(v); + else if (type == qMetaTypeId<QGeoShape>()) + return typedCreate<GeoShapeValueType>(v); + else if (type == qMetaTypeId<QGeoRectangle>()) + return typedCreate<GeoRectangleValueType>(v); + else if (type == qMetaTypeId<QGeoCircle>()) + return typedCreate<GeoCircleValueType>(v); + + return false; +} + +bool LocationValueTypeProvider::init(int type, void *data, size_t dataSize) +{ + if (type == qMetaTypeId<QGeoCoordinate>()) + return typedInit<QGeoCoordinate>(data, dataSize); + else if (type == qMetaTypeId<QGeoShape>()) + return typedInit<QGeoShape>(data, dataSize); + else if (type == qMetaTypeId<QGeoRectangle>()) + return typedInit<QGeoRectangle>(data, dataSize); + else if (type == qMetaTypeId<QGeoCircle>()) + return typedInit<QGeoCircle>(data, dataSize); + + return false; +} + +bool LocationValueTypeProvider::destroy(int type, void *data, size_t dataSize) +{ + if (type == qMetaTypeId<QGeoCoordinate>()) + return typedDestroy<QGeoCoordinate>(data, dataSize); + else if (type == qMetaTypeId<QGeoShape>()) + return typedDestroy<QGeoShape>(data, dataSize); + else if (type == qMetaTypeId<QGeoRectangle>()) + return typedDestroy<QGeoRectangle>(data, dataSize); + else if (type == qMetaTypeId<QGeoCircle>()) + return typedDestroy<QGeoCircle>(data, dataSize); + + return false; +} + +bool LocationValueTypeProvider::copy(int type, const void *src, void *dst, size_t dstSize) +{ + if (type == qMetaTypeId<QGeoCoordinate>()) + return typedCopyConstruct<QGeoCoordinate>(src, dst, dstSize); + else if (type == qMetaTypeId<QGeoShape>()) + return typedCopyConstruct<QGeoShape>(src, dst, dstSize); + else if (type == qMetaTypeId<QGeoRectangle>()) + return typedCopyConstruct<QGeoRectangle>(src, dst, dstSize); + else if (type == qMetaTypeId<QGeoCircle>()) + return typedCopyConstruct<QGeoCircle>(src, dst, dstSize); + + return false; +} + +bool LocationValueTypeProvider::create(int type, int argc, const void *argv[], QVariant *v) +{ + if (type == qMetaTypeId<QGeoCoordinate>()) { + if (argc == 2) { + const float *a = reinterpret_cast<const float *>(argv[0]); + const float *b = reinterpret_cast<const float *>(argv[1]); + *v = QVariant::fromValue(QGeoCoordinate(*a, *b)); + return true; + } else if (argc == 3) { + const float *a = reinterpret_cast<const float *>(argv[0]); + const float *b = reinterpret_cast<const float *>(argv[1]); + const float *c = reinterpret_cast<const float *>(argv[2]); + *v = QVariant::fromValue(QGeoCoordinate(*a, *b, *c)); + return true; + } + } + + return false; +} + +bool LocationValueTypeProvider::createFromString(int type, const QString &s, void *data, size_t dataSize) +{ + Q_UNUSED(data) + Q_UNUSED(dataSize) + + if (type == qMetaTypeId<QGeoCoordinate>() || type == qMetaTypeId<QGeoShape>() || + type == qMetaTypeId<QGeoRectangle>() || type == qMetaTypeId<QGeoCircle>()) { + qWarning("Cannot create value type %d from string '%s'", type, qPrintable(s)); + } + + return false; +} + +bool LocationValueTypeProvider::createStringFrom(int type, const void *data, QString *s) +{ + Q_UNUSED(data) + Q_UNUSED(s) + + if (type == qMetaTypeId<QGeoCoordinate>() || type == qMetaTypeId<QGeoShape>() || + type == qMetaTypeId<QGeoRectangle>() || type == qMetaTypeId<QGeoCircle>()) { + qWarning("Cannot create string from value type %d", type); + } + + return false; +} + +bool LocationValueTypeProvider::variantFromJsObject(int type, QQmlV4Handle h, QV8Engine *e, QVariant *v) +{ + Q_UNUSED(h) + Q_UNUSED(e) + Q_UNUSED(v) + + if (type == qMetaTypeId<QGeoCoordinate>() || type == qMetaTypeId<QGeoShape>() || + type == qMetaTypeId<QGeoRectangle>() || type == qMetaTypeId<QGeoCircle>()) { + qWarning("Cannot create variant from js object for type %d", type); + } + + return false; +} + +bool LocationValueTypeProvider::equal(int type, const void *lhs, const void *rhs, size_t rhsSize) +{ + Q_UNUSED(rhsSize) + + if (type == qMetaTypeId<QGeoCoordinate>()) + return typedEqual<QGeoCoordinate>(lhs, rhs); + else if (type == qMetaTypeId<QGeoShape>()) + return typedEqual<QGeoShape>(lhs, rhs); + else if (type == qMetaTypeId<QGeoRectangle>()) + return typedEqual<QGeoRectangle>(lhs, rhs); + else if (type == qMetaTypeId<QGeoCircle>()) + return typedEqual<QGeoCircle>(lhs, rhs); + + return false; +} + +bool LocationValueTypeProvider::store(int type, const void *src, void *dst, size_t dstSize) +{ + if (type == qMetaTypeId<QGeoCoordinate>()) + return typedStore<QGeoCoordinate>(src, dst, dstSize); + else if (type == qMetaTypeId<QGeoShape>()) + return typedStore<QGeoShape>(src, dst, dstSize); + else if (type == qMetaTypeId<QGeoRectangle>()) + return typedStore<QGeoRectangle>(src, dst, dstSize); + else if (type == qMetaTypeId<QGeoCircle>()) + return typedStore<QGeoCircle>(src, dst, dstSize); + + return false; +} + +bool LocationValueTypeProvider::read(int srcType, const void *src, size_t srcSize, int dstType, void *dst) +{ + if (srcType == qMetaTypeId<QGeoCoordinate>()) + return typedRead<QGeoCoordinate>(srcType, src, srcSize, dstType, dst); + else if (srcType == qMetaTypeId<QGeoShape>()) + return typedRead<QGeoShape>(srcType, src, srcSize, dstType, dst); + else if (srcType == qMetaTypeId<QGeoRectangle>()) + return typedRead<QGeoRectangle>(srcType, src, srcSize, dstType, dst); + else if (srcType == qMetaTypeId<QGeoCircle>()) + return typedRead<QGeoCircle>(srcType, src, srcSize, dstType, dst); + + return false; +} + +bool LocationValueTypeProvider::write(int type, const void *src, void *dst, size_t dstSize) +{ + if (type == qMetaTypeId<QGeoCoordinate>()) + return typedWrite<QGeoCoordinate>(src, dst, dstSize); + else if (type == qMetaTypeId<QGeoShape>()) + return typedWrite<QGeoShape>(src, dst, dstSize); + else if (type == qMetaTypeId<QGeoRectangle>()) + return typedWrite<QGeoRectangle>(src, dst, dstSize); + else if (type == qMetaTypeId<QGeoCircle>()) + return typedWrite<QGeoCircle>(src, dst, dstSize); + + return false; +} + +QT_END_NAMESPACE diff --git a/src/imports/positioning/locationvaluetypeprovider.h b/src/imports/positioning/locationvaluetypeprovider.h new file mode 100644 index 00000000..b60d2c99 --- /dev/null +++ b/src/imports/positioning/locationvaluetypeprovider.h @@ -0,0 +1,164 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LOCATIONVALUETYPEPROVIDER_H +#define LOCATIONVALUETYPEPROVIDER_H + +#include <QtQml/private/qqmlglobal_p.h> + +QT_BEGIN_NAMESPACE + +class LocationValueTypeProvider : public QQmlValueTypeProvider +{ +public: + LocationValueTypeProvider(); + +private: + template<typename T> + bool typedCreate(QQmlValueType *&v) + { + v = new T; + return true; + } + + bool create(int type, QQmlValueType *&v) Q_DECL_OVERRIDE; + + template<typename T> + bool typedInit(void *data, size_t dataSize) + { + Q_ASSERT(dataSize >= sizeof(T)); + Q_UNUSED(dataSize); + T *t = reinterpret_cast<T *>(data); + new (t) T(); + return true; + } + + bool init(int type, void *data, size_t dataSize) Q_DECL_OVERRIDE; + + template<typename T> + bool typedDestroy(void *data, size_t dataSize) + { + Q_ASSERT(dataSize >= sizeof(T)); + Q_UNUSED(dataSize); + T *t = reinterpret_cast<T *>(data); + t->~T(); + return true; + } + + bool destroy(int type, void *data, size_t dataSize) Q_DECL_OVERRIDE; + + template<typename T> + bool typedCopyConstruct(const void *src, void *dst, size_t dstSize) + { + Q_ASSERT(dstSize >= sizeof(T)); + Q_UNUSED(dstSize); + const T *srcT = reinterpret_cast<const T *>(src); + T *dstT = reinterpret_cast<T *>(dst); + new (dstT) T(*srcT); + return true; + } + + bool copy(int type, const void *src, void *dst, size_t dstSize) Q_DECL_OVERRIDE; + + bool create(int type, int argc, const void *argv[], QVariant *v) Q_DECL_OVERRIDE; + bool createFromString(int type, const QString &s, void *data, size_t dataSize) Q_DECL_OVERRIDE; + bool createStringFrom(int type, const void *data, QString *s) Q_DECL_OVERRIDE; + + bool variantFromJsObject(int type, QQmlV4Handle h, QV8Engine *e, QVariant *v) Q_DECL_OVERRIDE; + + template<typename T> + bool typedEqual(const void *lhs, const void *rhs) + { + return *reinterpret_cast<const T *>(lhs) == *reinterpret_cast<const T *>(rhs); + } + + bool equal(int type, const void *lhs, const void *rhs, size_t rhsSize) Q_DECL_OVERRIDE; + + template<typename T> + bool typedStore(const void *src, void *dst, size_t dstSize) + { + Q_ASSERT(dstSize >= sizeof(T)); + Q_UNUSED(dstSize); + const T *srcT = reinterpret_cast<const T *>(src); + T *dstT = reinterpret_cast<T *>(dst); + new (dstT) T(*srcT); + return true; + } + + bool store(int type, const void *src, void *dst, size_t dstSize) Q_DECL_OVERRIDE; + + template<typename T> + bool typedRead(int srcType, const void *src, size_t srcSize, int dstType, void *dst) + { + T *dstT = reinterpret_cast<T *>(dst); + if (srcType == dstType) { + Q_ASSERT(srcSize >= sizeof(T)); + Q_UNUSED(srcSize); + const T *srcT = reinterpret_cast<const T *>(src); + *dstT = *srcT; + } else { + *dstT = T(); + } + return true; + } + + bool read(int srcType, const void *src, size_t srcSize, int dstType, void *dst) Q_DECL_OVERRIDE; + + template<typename T> + bool typedWrite(const void *src, void *dst, size_t dstSize) + { + Q_ASSERT(dstSize >= sizeof(T)); + Q_UNUSED(dstSize); + const T *srcT = reinterpret_cast<const T *>(src); + T *dstT = reinterpret_cast<T *>(dst); + if (*dstT != *srcT) { + *dstT = *srcT; + return true; + } + return false; + } + + bool write(int type, const void *src, void *dst, size_t dstSize) Q_DECL_OVERRIDE; +}; + +QT_END_NAMESPACE + +#endif // LOCATIONVALUETYPEPROVIDER_H diff --git a/src/imports/positioning/plugin.json b/src/imports/positioning/plugin.json new file mode 100644 index 00000000..2c63c085 --- /dev/null +++ b/src/imports/positioning/plugin.json @@ -0,0 +1,2 @@ +{ +} diff --git a/src/imports/positioning/plugins.qmltypes b/src/imports/positioning/plugins.qmltypes new file mode 100644 index 00000000..3f5b1ff7 --- /dev/null +++ b/src/imports/positioning/plugins.qmltypes @@ -0,0 +1,167 @@ +import QtQuick.tooling 1.1 + +// This file describes the plugin-supplied types contained in the library. +// It is used for QML tooling purposes only. +// +// This file was auto-generated with the command 'qmlplugindump -notrelocatable QtPositioning 5.0'. + +Module { + Component { + name: "GeoShapeValueType" + prototype: "QQmlValueType" + exports: ["QtPositioning/GeoShape 5.0"] + exportMetaObjectRevisions: [0] + Enum { + name: "ShapeType" + values: { + "UnknownType": 0, + "RectangleType": 1, + "CircleType": 2 + } + } + Property { name: "type"; type: "ShapeType"; isReadonly: true } + Property { name: "isValid"; type: "bool"; isReadonly: true } + Property { name: "isEmpty"; type: "bool"; isReadonly: true } + Method { + name: "contains" + type: "bool" + Parameter { name: "coordinate"; type: "QGeoCoordinate" } + } + } + Component { + name: "LocationSingleton" + prototype: "QObject" + exports: ["QtPositioning/QtPositioning 5.0"] + exportMetaObjectRevisions: [0] + Method { name: "coordinate"; type: "QGeoCoordinate" } + Method { + name: "coordinate" + type: "QGeoCoordinate" + Parameter { name: "latitude"; type: "double" } + Parameter { name: "longitude"; type: "double" } + Parameter { name: "altitude"; type: "double" } + } + Method { + name: "coordinate" + type: "QGeoCoordinate" + Parameter { name: "latitude"; type: "double" } + Parameter { name: "longitude"; type: "double" } + } + Method { name: "shape"; type: "QGeoShape" } + Method { name: "rectangle"; type: "QGeoRectangle" } + Method { + name: "rectangle" + type: "QGeoRectangle" + Parameter { name: "center"; type: "QGeoCoordinate" } + Parameter { name: "width"; type: "double" } + Parameter { name: "height"; type: "double" } + } + Method { + name: "rectangle" + type: "QGeoRectangle" + Parameter { name: "topLeft"; type: "QGeoCoordinate" } + Parameter { name: "bottomRight"; type: "QGeoCoordinate" } + } + Method { name: "circle"; type: "QGeoCircle" } + Method { + name: "circle" + type: "QGeoCircle" + Parameter { name: "center"; type: "QGeoCoordinate" } + Parameter { name: "radius"; type: "double" } + } + Method { + name: "circle" + type: "QGeoCircle" + Parameter { name: "center"; type: "QGeoCoordinate" } + } + } + Component { + name: "QDeclarativeGeoAddress" + prototype: "QObject" + exports: ["QtPositioning/Address 5.0"] + exportMetaObjectRevisions: [0] + Property { name: "address"; type: "QGeoAddress" } + Property { name: "text"; type: "string" } + Property { name: "country"; type: "string" } + Property { name: "countryCode"; type: "string" } + Property { name: "state"; type: "string" } + Property { name: "county"; type: "string" } + Property { name: "city"; type: "string" } + Property { name: "district"; type: "string" } + Property { name: "street"; type: "string" } + Property { name: "postalCode"; type: "string" } + Property { name: "isTextGenerated"; type: "bool"; isReadonly: true } + } + Component { + name: "QDeclarativeGeoLocation" + prototype: "QObject" + exports: ["QtPositioning/Location 5.0"] + exportMetaObjectRevisions: [0] + Property { name: "location"; type: "QGeoLocation" } + Property { name: "address"; type: "QDeclarativeGeoAddress"; isPointer: true } + Property { name: "coordinate"; type: "QGeoCoordinate" } + Property { name: "boundingBox"; type: "QGeoRectangle" } + } + Component { + name: "QDeclarativePosition" + prototype: "QObject" + exports: ["QtPositioning/Position 5.0"] + exportMetaObjectRevisions: [0] + Property { name: "latitudeValid"; type: "bool"; isReadonly: true } + Property { name: "longitudeValid"; type: "bool"; isReadonly: true } + Property { name: "altitudeValid"; type: "bool"; isReadonly: true } + Property { name: "coordinate"; type: "QGeoCoordinate"; isReadonly: true } + Property { name: "timestamp"; type: "QDateTime"; isReadonly: true } + Property { name: "speed"; type: "double"; isReadonly: true } + Property { name: "speedValid"; type: "bool"; isReadonly: true } + Property { name: "horizontalAccuracy"; type: "double" } + Property { name: "verticalAccuracy"; type: "double" } + Property { name: "horizontalAccuracyValid"; type: "bool"; isReadonly: true } + Property { name: "verticalAccuracyValid"; type: "bool"; isReadonly: true } + } + Component { + name: "QDeclarativePositionSource" + prototype: "QObject" + exports: ["QtPositioning/PositionSource 5.0"] + exportMetaObjectRevisions: [0] + Enum { + name: "PositioningMethod" + values: { + "NoPositioningMethod": 0, + "SatellitePositioningMethod": 255, + "NonSatellitePositioningMethod": -256, + "AllPositioningMethods": -1 + } + } + Enum { + name: "PositioningMethods" + values: { + "NoPositioningMethod": 0, + "SatellitePositioningMethod": 255, + "NonSatellitePositioningMethod": -256, + "AllPositioningMethods": -1 + } + } + Enum { + name: "SourceError" + values: { + "AccessError": 0, + "ClosedError": 1, + "UnknownSourceError": -1 + } + } + Property { name: "position"; type: "QDeclarativePosition"; isReadonly: true; isPointer: true } + Property { name: "active"; type: "bool" } + Property { name: "valid"; type: "bool"; isReadonly: true } + Property { name: "nmeaSource"; type: "QUrl" } + Property { name: "updateInterval"; type: "int" } + Property { name: "supportedPositioningMethods"; type: "PositioningMethods"; isReadonly: true } + Property { name: "preferredPositioningMethods"; type: "PositioningMethods" } + Property { name: "sourceError"; type: "SourceError"; isReadonly: true } + Property { name: "name"; type: "string" } + Signal { name: "validityChanged" } + Method { name: "update" } + Method { name: "start" } + Method { name: "stop" } + } +} diff --git a/src/imports/positioning/positioning.cpp b/src/imports/positioning/positioning.cpp new file mode 100644 index 00000000..031b06b2 --- /dev/null +++ b/src/imports/positioning/positioning.cpp @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "locationvaluetypeprovider.h" + +#include <QtPositioning/private/qdeclarativegeoaddress_p.h> +#include <QtPositioning/private/qdeclarativegeolocation_p.h> + +#include "qdeclarativepositionsource_p.h" +#include "qdeclarativeposition_p.h" + +#include "qdeclarativegeoshape.h" +#include "qdeclarativegeorectangle.h" +#include "qdeclarativegeocircle.h" +#include "qdeclarativecoordinate_p.h" + +#include "locationsingleton.h" + +#include <QtQml/qqmlextensionplugin.h> +#include <QtQml/qqml.h> +#include <QtQml/private/qqmlvaluetype_p.h> +#include <QtQml/private/qqmlglobal_p.h> +#include <QtQml/private/qqmlmetatype_p.h> + +#include <QtPositioning/QGeoRectangle> +#include <QtPositioning/QGeoCircle> +#include <QtPositioning/QGeoLocation> + +#include <QtCore/QDebug> + +QT_BEGIN_NAMESPACE + +static QObject *singleton_type_factory(QQmlEngine *engine, QJSEngine *jsEngine) +{ + Q_UNUSED(engine) + Q_UNUSED(jsEngine) + + return new LocationSingleton; +} + +static LocationValueTypeProvider *getValueTypeProvider() +{ + static LocationValueTypeProvider provider; + return &provider; +} + +class QLocationDeclarativeModule: public QQmlExtensionPlugin +{ + Q_OBJECT + + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0" + FILE "plugin.json") + +public: + virtual void registerTypes(const char *uri) + { + if (QLatin1String(uri) == QLatin1String("QtPositioning")) { + + // @uri QtPositioning 5.0 + + qmlRegisterSingletonType<LocationSingleton>(uri, 5, 0, "QtPositioning", singleton_type_factory); + + QQml_addValueTypeProvider(getValueTypeProvider()); + qmlRegisterValueTypeEnums<GeoShapeValueType>(uri, 5, 0, "GeoShape"); + + qmlRegisterType<QDeclarativePosition>(uri, 5, 0, "Position"); + qmlRegisterType<QDeclarativePositionSource>(uri, 5, 0, "PositionSource"); + qmlRegisterType<QDeclarativeGeoAddress>(uri, 5, 0, "Address"); + + qmlRegisterType<QDeclarativeGeoLocation>(uri, 5, 0, "Location"); + + qRegisterMetaType<QGeoCoordinate>("QGeoCoordinate"); + qRegisterMetaType<QGeoAddress>("QGeoAddress"); + qRegisterMetaType<QGeoRectangle>("QGeoRectangle"); + qRegisterMetaType<QGeoCircle>("QGeoCircle"); + qRegisterMetaType<QGeoLocation>("QGeoLocation"); + } else { + qDebug() << "Unsupported URI given to load positioning QML plugin: " << QLatin1String(uri); + } + } +}; + +#include "positioning.moc" + +QT_END_NAMESPACE diff --git a/src/imports/positioning/positioning.pro b/src/imports/positioning/positioning.pro new file mode 100644 index 00000000..2d396463 --- /dev/null +++ b/src/imports/positioning/positioning.pro @@ -0,0 +1,32 @@ +QT += quick-private positioning-private qml-private core-private + +INCLUDEPATH *= $$PWD +DEFINES += TOUCH_EVENT_WORKAROUND + +HEADERS += qdeclarativeposition_p.h \ + qdeclarativepositionsource_p.h \ + qdeclarativecoordinate_p.h \ + qdeclarativegeoshape.h \ + qdeclarativegeorectangle.h \ + qdeclarativegeocircle.h \ + locationvaluetypeprovider.h \ + locationsingleton.h \ + error_messages.h \ + locationvaluetypehelper_p.h + +SOURCES += qdeclarativeposition.cpp \ + positioning.cpp \ + qdeclarativepositionsource.cpp \ + qdeclarativecoordinate.cpp \ + qdeclarativegeoshape.cpp \ + qdeclarativegeorectangle.cpp \ + qdeclarativegeocircle.cpp \ + locationvaluetypeprovider.cpp \ + locationsingleton.cpp \ + error_messages.cpp + +load(qml_plugin) + +OTHER_FILES += \ + plugin.json \ + qmldir diff --git a/src/imports/positioning/qdeclarativecoordinate.cpp b/src/imports/positioning/qdeclarativecoordinate.cpp new file mode 100644 index 00000000..20dd5cef --- /dev/null +++ b/src/imports/positioning/qdeclarativecoordinate.cpp @@ -0,0 +1,320 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativecoordinate_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmlbasictype coordinate + \inqmlmodule QtPositioning 5.0 + \ingroup qml-QtPositioning5-basictypes + \since Qt Positioning 5.0 + + \brief The coordinate type represents and stores a geographic position. + + The \c coordinate type represents a geographic position in the form of \l {latitude}, + \l longitude and \l altitude attributes. The \l latitude attribute specifies the number of + decimal degrees above and below the equator. A positive latitude indicates the Northern + Hemisphere and a negative latitude indicates the Southern Hemisphere. The \l longitude + attribute specifies the number of decimal degrees east and west. A positive longitude + indicates the Eastern Hemisphere and a negative longitude indicates the Western Hemisphere. + The \l altitude attribute specifies the number of meters above sea level. Together, these + attributes specify a 3-dimensional position anywhere on or near the Earth's surface. + + The \l isValid attribute can be used to test if a coordinate is valid. A coordinate is + considered valid if it has a valid latitude and longitude. A valid altitude is not required. + The latitude must be between -90 and 90 inclusive and the longitude must be between -180 and + 180 inclusive. + + The coordinate type is used by many other types in the Qt Location module, for specifying + the position of an object on a Map, the current position of a device and many other tasks. + They also feature a number of important utility methods that make otherwise complex + calculations simple to use, such as \l atDistanceAndAzimuth(). + + \section2 Accuracy + + The latitude, longitude and altitude attributes stored in the coordinate type are represented + as doubles, giving them approximately 16 decimal digits of precision -- enough to specify + micrometers. The calculations performed in coordinate's methods such as \l azimuthTo() and + \l distanceTo() also use doubles for all intermediate values, but the inherent inaccuracies in + their spherical Earth model dominate the amount of error in their output. + + \section2 Example Usage + + Use properties of type \l variant to store a \c {coordinate}. To create a \c coordinate use + one of the methods described below. In all cases, specifying the \l altitude attribute is + optional. + + To create a \c coordinate value, use the \l{QtPositioning::coordinate}{QtPositioning.coordinate()} + function: + + \qml + import QtPositioning 5.0 + + Location { coordinate: QtPositioning.coordinate(-27.5, 153.1) } + \endqml + + or as separate \l latitude, \l longitude and \l altitude components: + + \qml + Location { + coordinate { + latitude: -27.5 + longitude: 153.1 + } + } + \endqml + + When integrating with C++, note that any QGeoCoordinate value passed into QML from C++ is + automatically converted into a \c coordinate value, and vice-versa. + + \section2 Properties + + \section3 latitude + + \code + real latitude + \endcode + + This property holds latitude value of the geographical position + (decimal degrees). A positive latitude indicates the Northern Hemisphere, + and a negative latitude indicates the Southern Hemisphere. + If the property has not been set, its default value is NaN. + + \section3 longitude + + \code + real longitude + \endcode + + This property holds the longitude value of the geographical position + (decimal degrees). A positive longitude indicates the Eastern Hemisphere, + and a negative longitude indicates the Western Hemisphere + If the property has not been set, its default value is NaN. + + \section3 altitude + + \code + real altitude + \endcode + + This property holds the value of altitude (meters above sea level). + If the property has not been set, its default value is NaN. + + \section3 isValid + + \code + bool isValid + \endcode + + This property holds the current validity of the coordinate. Coordinates + are considered valid if they have been set with a valid latitude and + longitude (altitude is not required). + + The latitude must be between -90 to 90 inclusive to be considered valid, + and the longitude must be between -180 to 180 inclusive to be considered + valid. + + This is a read-only property. + + \section2 Methods + + \section3 distanceTo() + + \code + real distanceTo(coordinate other) + \endcode + + Returns the distance (in meters) from this coordinate to the coordinate specified by \a other. + Altitude is not used in the calculation. + + This calculation returns the great-circle distance between the two coordinates, with an + assumption that the Earth is spherical for the purpose of this calculation. + + \section3 azimuthTo() + + \code + real azimuth(coordinate other) + \endcode + + Returns the azimuth (or bearing) in degrees from this coordinate to the coordinate specified by + \a other. Altitude is not used in the calculation. + + There is an assumption that the Earth is spherical for the purpose of this calculation. + + \section3 atDistanceAndAzimuth() + + \code + coordinate atDistanceAndAzimuth(real distance, real azimuth) + \endcode + + Returns the coordinate that is reached by traveling \a distance metres from this coordinate at + \a azimuth degrees along a great-circle. + + There is an assumption that the Earth is spherical for the purpose of this calculation. +*/ + + +CoordinateValueType::CoordinateValueType(QObject *parent) +: QQmlValueTypeBase<QGeoCoordinate>(qMetaTypeId<QGeoCoordinate>(), parent) +{ +} + +CoordinateValueType::~CoordinateValueType() +{ +} + +/* + This property holds the value of altitude (meters above sea level). + If the property has not been set, its default value is NaN. + +*/ +void CoordinateValueType::setAltitude(double altitude) +{ + v.setAltitude(altitude); +} + +double CoordinateValueType::altitude() const +{ + return v.altitude(); +} + +/* + This property holds the longitude value of the geographical position + (decimal degrees). A positive longitude indicates the Eastern Hemisphere, + and a negative longitude indicates the Western Hemisphere + If the property has not been set, its default value is NaN. +*/ +void CoordinateValueType::setLongitude(double longitude) +{ + v.setLongitude(longitude); +} + +double CoordinateValueType::longitude() const +{ + return v.longitude(); +} + +/* + This property holds latitude value of the geographical position + (decimal degrees). A positive latitude indicates the Northern Hemisphere, + and a negative latitude indicates the Southern Hemisphere. + If the property has not been set, its default value is NaN. +*/ +void CoordinateValueType::setLatitude(double latitude) +{ + v.setLatitude(latitude); +} + +double CoordinateValueType::latitude() const +{ + return v.latitude(); +} + +/* + This property holds the current validity of the coordinate. Coordinates + are considered valid if they have been set with a valid latitude and + longitude (altitude is not required). + + The latitude must be between -90 to 90 inclusive to be considered valid, + and the longitude must be between -180 to 180 inclusive to be considered + valid. +*/ +bool CoordinateValueType::isValid() const +{ + return v.isValid(); +} + +QString CoordinateValueType::toString() const +{ + return QStringLiteral("QGeoCoordinate(%1,%2,%3)") + .arg(v.latitude()).arg(v.longitude()).arg(v.altitude()); +} + +bool CoordinateValueType::isEqual(const QVariant &other) const +{ + if (other.userType() != qMetaTypeId<QGeoCoordinate>()) + return false; + + return v == other.value<QGeoCoordinate>(); +} + +/* + Returns the distance (in meters) from this coordinate to the + coordinate specified by other. Altitude is not used in the calculation. + + This calculation returns the great-circle distance between the two + coordinates, with an assumption that the Earth is spherical for the + purpose of this calculation. +*/ +qreal CoordinateValueType::distanceTo(const QGeoCoordinate &coordinate) const +{ + return v.distanceTo(coordinate); +} + +/* + Returns the azimuth (or bearing) in degrees from this coordinate to the + coordinate specified by other. Altitude is not used in the calculation. + + There is an assumption that the Earth is spherical for the purpose of + this calculation. +*/ +qreal CoordinateValueType::azimuthTo(const QGeoCoordinate &coordinate) const +{ + return v.azimuthTo(coordinate); +} + +/* + Returns the coordinate that is reached by traveling distance metres + from the current coordinate at azimuth degrees along a great-circle. + + There is an assumption that the Earth is spherical for the purpose + of this calculation. +*/ +QGeoCoordinate CoordinateValueType::atDistanceAndAzimuth(qreal distance, qreal azimuth) const +{ + return v.atDistanceAndAzimuth(distance, azimuth); +} + +#include "moc_qdeclarativecoordinate_p.cpp" + +QT_END_NAMESPACE diff --git a/src/imports/positioning/qdeclarativecoordinate_p.h b/src/imports/positioning/qdeclarativecoordinate_p.h new file mode 100644 index 00000000..8f7a47e5 --- /dev/null +++ b/src/imports/positioning/qdeclarativecoordinate_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVECOORDINATE_H +#define QDECLARATIVECOORDINATE_H + +#include <QtQml/private/qqmlvaluetype_p.h> +#include <QtPositioning/QGeoCoordinate> + +QT_BEGIN_NAMESPACE + +class CoordinateValueType : public QQmlValueTypeBase<QGeoCoordinate> +{ + Q_OBJECT + + Q_PROPERTY(double latitude READ latitude WRITE setLatitude) + Q_PROPERTY(double longitude READ longitude WRITE setLongitude) + Q_PROPERTY(double altitude READ altitude WRITE setAltitude) + Q_PROPERTY(bool isValid READ isValid) + +public: + explicit CoordinateValueType(QObject *parent = 0); + ~CoordinateValueType(); + + Q_INVOKABLE qreal distanceTo(const QGeoCoordinate &coordinate) const; + Q_INVOKABLE qreal azimuthTo(const QGeoCoordinate &coordinate) const; + + Q_INVOKABLE QGeoCoordinate atDistanceAndAzimuth(qreal distance, qreal azimuth) const; + + double latitude() const; + void setLatitude(double latitude); + + double longitude() const; + void setLongitude(double longitude); + + double altitude() const; + void setAltitude(double altitude); + + bool isValid() const; + + QString toString() const Q_DECL_OVERRIDE; + bool isEqual(const QVariant &other) const Q_DECL_OVERRIDE; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/imports/positioning/qdeclarativegeocircle.cpp b/src/imports/positioning/qdeclarativegeocircle.cpp new file mode 100644 index 00000000..4424d2d7 --- /dev/null +++ b/src/imports/positioning/qdeclarativegeocircle.cpp @@ -0,0 +1,206 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#include "qdeclarativegeocircle.h" + +#include <QtCore/qnumeric.h> +#include <QtPositioning/QGeoCircle> + +#include <QtCore/QDebug> + +QT_BEGIN_NAMESPACE + +/*! + \qmlbasictype geocircle + \inqmlmodule QtPositioning 5.0 + \ingroup qml-QtPositioning5-basictypes + \since Qt Positioning 5.0 + + \brief The geocircle type represents a circular geographic area. + + The \c geocircle type is a \l {geoshape} that represents a circular + geographic area. It is defined in terms of a \l {coordinate} which + specifies the \l center of the circle and a qreal which specifies the \l radius of the circle + in meters. + + The circle is considered invalid if the \l center coordinate is invalid or if the \l radius is less + than zero. + + \section2 Example Usage + + Use properties of type \l variant to store a \c {geocircle}. To create a \c geocircle value, + use the \l {QtPositioning::circle}{QtPositioning.circle()} function: + + \qml + import QtPositioning 5.0 + + Item { + property variant region: QtPositioning.circle(QtPositioning.coordinate(-27.5, 153.1), 1000) + } + \endqml + + When integrating with C++, note that any QGeoCircle value passed into QML from C++ is + automatically converted into a \c geocircle value, and vise-versa. + + \section2 Properties + + \section3 center + + \code + coordinate radius + \endcode + + This property holds the coordinate of the center of the geocircle. + + \section3 radius + + \code + real radius + \endcode + + This property holds the radius of the geocircle in meters. + + The default value for the radius is -1 indicating an invalid geocircle area. +*/ + +GeoCircleValueType::GeoCircleValueType(QObject *parent) +: GeoShapeValueType(qMetaTypeId<QGeoCircle>(), parent) +{ +} + +GeoCircleValueType::~GeoCircleValueType() +{ +} + +/* + This property holds the coordinate of the center of the geocircle. +*/ +QGeoCoordinate GeoCircleValueType::center() +{ + return QGeoCircle(v).center(); +} + +void GeoCircleValueType::setCenter(const QGeoCoordinate &coordinate) +{ + QGeoCircle c = v; + + if (c.center() == coordinate) + return; + + c.setCenter(coordinate); + v = c; +} + +/* + This property holds the radius of the geocircle in meters. + + The default value for the radius is -1 indicating an invalid geocircle area. +*/ +qreal GeoCircleValueType::radius() const +{ + return QGeoCircle(v).radius(); +} + +void GeoCircleValueType::setRadius(qreal radius) +{ + QGeoCircle c = v; + + if (c.radius() == radius) + return; + + c.setRadius(radius); + v = c; +} + +QString GeoCircleValueType::toString() const +{ + if (v.type() != QGeoShape::CircleType) { + qWarning("Not a circle"); + return QStringLiteral("QGeoCircle(not a circle)"); + } + + QGeoCircle c = v; + return QStringLiteral("QGeoCircle({%1, %2}, %3)") + .arg(c.center().latitude()) + .arg(c.center().longitude()) + .arg(c.radius()); +} + +void GeoCircleValueType::setValue(const QVariant &value) +{ + if (value.userType() == qMetaTypeId<QGeoCircle>()) + v = value.value<QGeoCircle>(); + else if (value.userType() == qMetaTypeId<QGeoShape>()) + v = value.value<QGeoShape>(); + else + v = QGeoCircle(); + + onLoad(); +} + +QVariant GeoCircleValueType::value() +{ + return QVariant::fromValue(QGeoCircle(v)); +} + +void GeoCircleValueType::write(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags) +{ + QGeoCircle c = v; + writeProperty(obj, idx, flags, &c); +} + +void GeoCircleValueType::writeVariantValue(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags, QVariant *from) +{ + if (from->userType() == qMetaTypeId<QGeoCircle>()) { + writeProperty(obj, idx, flags, from); + } else if (from->userType() == qMetaTypeId<QGeoShape>()) { + QGeoCircle c = from->value<QGeoShape>(); + QVariant v = QVariant::fromValue(c); + writeProperty(obj, idx, flags, &v); + } else { + QVariant v = QVariant::fromValue(QGeoCircle()); + writeProperty(obj, idx, flags, &v); + } +} + +#include "moc_qdeclarativegeocircle.cpp" + +QT_END_NAMESPACE diff --git a/src/imports/positioning/qdeclarativegeocircle.h b/src/imports/positioning/qdeclarativegeocircle.h new file mode 100644 index 00000000..82948f8f --- /dev/null +++ b/src/imports/positioning/qdeclarativegeocircle.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVEGEOCIRCLE_H +#define QDECLARATIVEGEOCIRCLE_H + +#include "qdeclarativegeoshape.h" + +QT_BEGIN_NAMESPACE + +class GeoCircleValueType : public GeoShapeValueType +{ + Q_OBJECT + + Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter) + Q_PROPERTY(qreal radius READ radius WRITE setRadius) + +public: + explicit GeoCircleValueType(QObject *parent = 0); + ~GeoCircleValueType(); + + QGeoCoordinate center(); + void setCenter(const QGeoCoordinate &coordinate); + + qreal radius() const; + void setRadius(qreal radius); + + QString toString() const Q_DECL_OVERRIDE; + void setValue(const QVariant &value) Q_DECL_OVERRIDE; + QVariant value() Q_DECL_OVERRIDE; + void write(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags) Q_DECL_OVERRIDE; + void writeVariantValue(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags, QVariant *from) Q_DECL_OVERRIDE; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/imports/positioning/qdeclarativegeorectangle.cpp b/src/imports/positioning/qdeclarativegeorectangle.cpp new file mode 100644 index 00000000..f1162b77 --- /dev/null +++ b/src/imports/positioning/qdeclarativegeorectangle.cpp @@ -0,0 +1,357 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#include "qdeclarativegeorectangle.h" + +#include <QtCore/qnumeric.h> +#include <QtPositioning/QGeoRectangle> + +#include <QtCore/QDebug> + +QT_BEGIN_NAMESPACE + +/*! + \qmlbasictype georectangle + \inqmlmodule QtPositioning 5.0 + \ingroup qml-QtPositioning5-basictypes + \since Qt Positioning 5.0 + + \brief The georectangle type represents a rectangular geographic area. + + The \c georectangle type is a \l {geoshape} that represents a + rectangular geographic area. It is defined by a pair of + \l {coordinate}{coordinates} which represent the top-left and bottom-right corners + of the \c {georectangle}. The coordinates are accessible from the \l topLeft and + \l bottomRight attributes. + + A \c georectangle is considered invalid if the top-left or bottom-right coordinates are invalid + or if the top-left coordinate is South of the bottom-right coordinate. + + The coordinates of the four corners of the \c georectangle can be accessed with the + \l {topLeft}, \l {topRight}, \l {bottomLeft} and \l {bottomRight} attributes. The \l center + attribute can be used to get the coordinate of the center of the \c georectangle. The \l width + and \l height attributes can be used to get the width and height of the \c georectangle in + degrees. Setting one of these attributes will cause the other attributes to be adjusted + accordingly. + + \section2 Limitations + + A \c georectangle can never cross the poles. + + If the height or center of a \c georectangle is adjusted such that it would cross one of the + poles the height is modified such that the \c georectangle touches but does not cross the pole + and that the center coordinate is still in the center of the \c georectangle. + + \section2 Example Usage + + Use properties of type \l variant to store a \c {georectangle}. To create a \c georectangle + value, use the \l {QtPositioning::rectangle}{QtPositioning.rectangle()} function: + + \qml + import QtPositioning 5.0 + + Item { + property variant region: QtPositioning.rectangle(QtPositioning.coordinate(-27.5, 153.1), QtPositioning.coordinate(-27.6, 153.2)) + } + \endqml + + When integrating with C++, note that any QGeoRectangle value passed into QML from C++ is + automatically converted into a \c georectangle value, and vice-versa. + + \section2 Properties + + \section3 bottomLeft + + \code + coordinate bottomLeft + \endcode + + This property holds the bottom left coordinate of this georectangle. + + \section3 bottomRight + + \code + coordinate bottomRight + \endcode + + This property holds the bottom right coordinate of this georectangle. + + \section3 center + + \code + coordinate center + \endcode + + This property holds the center coordinate of this georectangle. For more details + see \l {QGeoRectangle::setCenter()}. + + \section3 height + + \code + double height + \endcode + + This property holds the height of this georectangle (in degrees). For more details + see \l {QGeoRectangle::setHeight()}. + + \section3 topLeft + + \code + coordinate topLeft + \endcode + + This property holds the top left coordinate of this georectangle. + + \section3 topRight + + \code + coordinate topRight + \endcode + + This property holds the top right coordinate of this georectangle. + + \section3 width + + \code + double width + \endcode + + This property holds the width of this georectangle (in degrees). For more details + see \l {QGeoRectangle::setWidth()}. +*/ + +GeoRectangleValueType::GeoRectangleValueType(QObject *parent) +: GeoShapeValueType(qMetaTypeId<QGeoRectangle>(), parent) +{ +} + +GeoRectangleValueType::~GeoRectangleValueType() +{ +} + +QGeoCoordinate GeoRectangleValueType::bottomLeft() +{ + return QGeoRectangle(v).bottomLeft(); +} + +/* + This property holds the bottom left coordinate of this georectangle. +*/ +void GeoRectangleValueType::setBottomLeft(const QGeoCoordinate &coordinate) +{ + QGeoRectangle r = v; + + if (r.bottomLeft() == coordinate) + return; + + r.setBottomLeft(coordinate); + v = r; +} + +QGeoCoordinate GeoRectangleValueType::bottomRight() +{ + return QGeoRectangle(v).bottomRight(); +} + +/* + This property holds the bottom right coordinate of this georectangle. +*/ +void GeoRectangleValueType::setBottomRight(const QGeoCoordinate &coordinate) +{ + QGeoRectangle r = v; + + if (r.bottomRight() == coordinate) + return; + + r.setBottomRight(coordinate); + v = r; +} + +QGeoCoordinate GeoRectangleValueType::topLeft() +{ + return QGeoRectangle(v).topLeft(); +} + +/* + This property holds the top left coordinate of this georectangle. +*/ +void GeoRectangleValueType::setTopLeft(const QGeoCoordinate &coordinate) +{ + QGeoRectangle r = v; + + if (r.topLeft() == coordinate) + return; + + r.setTopLeft(coordinate); + v = r; +} + +QGeoCoordinate GeoRectangleValueType::topRight() +{ + return QGeoRectangle(v).topRight(); +} + +/* + This property holds the top right coordinate of this georectangle. +*/ +void GeoRectangleValueType::setTopRight(QGeoCoordinate &coordinate) +{ + QGeoRectangle r = v; + + if (r.topRight() == coordinate) + return; + + r.setTopRight(coordinate); + v = r; +} + +QGeoCoordinate GeoRectangleValueType::center() +{ + return QGeoRectangle(v).center(); +} + +/* + This property holds the center coordinate of this georectangle. +*/ +void GeoRectangleValueType::setCenter(const QGeoCoordinate &coordinate) +{ + QGeoRectangle r = v; + + if (r.center() == coordinate) + return; + + r.setCenter(coordinate); + v = r; +} + +double GeoRectangleValueType::height() +{ + return QGeoRectangle(v).height(); +} + +/* + This property holds the height of this georectangle (in degrees). +*/ +void GeoRectangleValueType::setHeight(double height) +{ + QGeoRectangle r = v; + + if (!r.isValid()) + r.setCenter(QGeoCoordinate(0.0, 0.0)); + + r.setHeight(height); + v = r; +} + +double GeoRectangleValueType::width() +{ + return QGeoRectangle(v).width(); +} + +/* + This property holds the width of this georectangle (in degrees). +*/ +void GeoRectangleValueType::setWidth(double width) +{ + QGeoRectangle r = v; + + if (!r.isValid()) + r.setCenter(QGeoCoordinate(0.0, 0.0)); + + r.setWidth(width); + v = r; +} + +QString GeoRectangleValueType::toString() const +{ + if (v.type() != QGeoShape::RectangleType) { + qWarning("Not a rectangle a %d\n", v.type()); + return QStringLiteral("QGeoRectangle(not a rectangle)"); + } + + QGeoRectangle r = v; + return QStringLiteral("QGeoRectangle({%1, %2}, {%3, %4})") + .arg(r.topLeft().latitude()) + .arg(r.topLeft().longitude()) + .arg(r.bottomRight().latitude()) + .arg(r.bottomRight().longitude()); +} + +void GeoRectangleValueType::setValue(const QVariant &value) +{ + if (value.userType() == qMetaTypeId<QGeoRectangle>()) + v = value.value<QGeoRectangle>(); + else if (value.userType() == qMetaTypeId<QGeoShape>()) + v = value.value<QGeoShape>(); + else + v = QGeoRectangle(); + + onLoad(); +} + +QVariant GeoRectangleValueType::value() +{ + return QVariant::fromValue(QGeoRectangle(v)); +} + +void GeoRectangleValueType::write(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags) +{ + QGeoRectangle r = v; + writeProperty(obj, idx, flags, &r); +} + +void GeoRectangleValueType::writeVariantValue(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags, QVariant *from) +{ + if (from->userType() == qMetaTypeId<QGeoRectangle>()) { + writeProperty(obj, idx, flags, from); + } else if (from->userType() == qMetaTypeId<QGeoShape>()) { + QGeoRectangle r = from->value<QGeoShape>(); + QVariant v = QVariant::fromValue(r); + writeProperty(obj, idx, flags, &v); + } else { + QVariant v = QVariant::fromValue(QGeoRectangle()); + writeProperty(obj, idx, flags, &v); + } +} + +#include "moc_qdeclarativegeorectangle.cpp" + +QT_END_NAMESPACE diff --git a/src/imports/positioning/qdeclarativegeorectangle.h b/src/imports/positioning/qdeclarativegeorectangle.h new file mode 100644 index 00000000..eaf63dce --- /dev/null +++ b/src/imports/positioning/qdeclarativegeorectangle.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVEGEORECTANGLE_H +#define QDECLARATIVEGEORECTANGLE_H + +#include "qdeclarativegeoshape.h" + +QT_BEGIN_NAMESPACE + +class GeoRectangleValueType : public GeoShapeValueType +{ + Q_OBJECT + + Q_PROPERTY(QGeoCoordinate bottomLeft READ bottomLeft WRITE setBottomLeft) + Q_PROPERTY(QGeoCoordinate bottomRight READ bottomRight WRITE setBottomRight) + Q_PROPERTY(QGeoCoordinate topLeft READ topLeft WRITE setTopLeft) + Q_PROPERTY(QGeoCoordinate topRight READ topRight WRITE setTopRight) + Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter) + Q_PROPERTY(double height READ height WRITE setHeight) + Q_PROPERTY(double width READ width WRITE setWidth) + +public: + explicit GeoRectangleValueType(QObject *parent = 0); + ~GeoRectangleValueType(); + + QGeoCoordinate bottomLeft(); + void setBottomLeft(const QGeoCoordinate &coordinate); + QGeoCoordinate bottomRight(); + void setBottomRight(const QGeoCoordinate &coordinate); + QGeoCoordinate topLeft(); + void setTopLeft(const QGeoCoordinate &coordinate); + QGeoCoordinate topRight(); + void setTopRight(QGeoCoordinate &coordinate); + QGeoCoordinate center(); + void setCenter(const QGeoCoordinate &coordinate); + double height(); + void setHeight(double height); + double width(); + void setWidth(double width); + + QString toString() const Q_DECL_OVERRIDE; + void setValue(const QVariant &value) Q_DECL_OVERRIDE; + QVariant value() Q_DECL_OVERRIDE; + void write(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags) Q_DECL_OVERRIDE; + void writeVariantValue(QObject *obj, int idx, QQmlPropertyPrivate::WriteFlags flags, QVariant *from) Q_DECL_OVERRIDE; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/imports/positioning/qdeclarativegeoshape.cpp b/src/imports/positioning/qdeclarativegeoshape.cpp new file mode 100644 index 00000000..d79f5622 --- /dev/null +++ b/src/imports/positioning/qdeclarativegeoshape.cpp @@ -0,0 +1,220 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeoshape.h" + +#include <QtPositioning/QGeoRectangle> +#include <QtPositioning/QGeoCircle> + +QT_BEGIN_NAMESPACE + +/*! + \qmlbasictype geoshape + \inqmlmodule QtPositioning 5.0 + \ingroup qml-QtPositioning5-basictypes + \since Qt Positioning 5.0 + + \brief A geoshape type represents an abstract geographic area. + + The \c geoshape type represents an abstract geographic area. It includes attributes and + methods common to all geographic areas. To create objects that represent a valid geographic + area use \l {georectangle} or \l {geocircle}. + + The \l isValid attribute can be used to test if the geoshape represents a valid geographic + area. + + The \l isEmpty attribute can be used to test if the geoshape represents a region with a + geomatrical area of 0. + + The \l contains() method can be used to test if a \l {coordinate} is + within the geoshape. + + \section2 Example Usage + + Use properties of type \l variant to store a \c {geoshape}. To create a \c geoshape use one + of the methods described below. + + To create a \c geoshape value, specify it as a "shape()" string: + + \qml + import QtPositioning + + Item { + property variant region: "shape()" + } + \endqml + + or with the \l {QtPositioning::shape}{QtPositioning.shape()} function: + + \qml + import QtPositioning 5.0 + + Item { + property variant region: QtPositioning.shape() + } + \endqml + + When integrating with C++, note that any QGeoShape value passed into QML from C++ is + automatically converted into a \c geoshape value, and vice-versa. + + \section2 Properties + + \section3 isEmpty + + \code + bool isEmpty + \endcode + + Returns whether this geo shape is empty. An empty geo shape is a region which has + a geometrical area of 0. + + \section3 isValid + + \code + bool isValid + \endcode + + Returns whether this geo shape is valid. + + A geo shape is considered to be invalid if some of the data that is required to + unambiguously describe the geo shape has not been set or has been set to an + unsuitable value. + + + \section2 Methods + + \section3 contains() + + \code + bool contains(coordinate coord) + \endcode + + Returns true if the \l {QtPositioning::coordinate}{coordinate} specified by \a coord is within + this geoshape; Otherwise returns false. +*/ + +GeoShapeValueType::GeoShapeValueType(QObject *parent) +: QQmlValueTypeBase<QGeoShape>(qMetaTypeId<QGeoShape>(), parent) +{ +} + +GeoShapeValueType::~GeoShapeValueType() +{ +} + +GeoShapeValueType::ShapeType GeoShapeValueType::type() const +{ + return static_cast<GeoShapeValueType::ShapeType>(v.type()); +} + +bool GeoShapeValueType::isValid() const +{ + return v.isValid(); +} + +bool GeoShapeValueType::isEmpty() const +{ + return v.isEmpty(); +} + +bool GeoShapeValueType::contains(const QGeoCoordinate &coordinate) const +{ + return v.contains(coordinate); +} + +QString GeoShapeValueType::toString() const +{ + switch (v.type()) { + case QGeoShape::UnknownType: + return QStringLiteral("QGeoShape()"); + case QGeoShape::RectangleType: { + QGeoRectangle r = v; + return QStringLiteral("QGeoRectangle({%1, %2}, {%3, %4})") + .arg(r.topLeft().latitude()) + .arg(r.topLeft().longitude()) + .arg(r.bottomRight().latitude()) + .arg(r.bottomRight().longitude()); + } + case QGeoShape::CircleType: { + QGeoCircle c = v; + return QStringLiteral("QGeoCircle({%1, %2}, %3)") + .arg(c.center().latitude()) + .arg(c.center().longitude()) + .arg(c.radius()); + } + } + + return QStringLiteral("QGeoShape(%1)").arg(v.type()); +} + +void GeoShapeValueType::setValue(const QVariant &value) +{ + if (value.userType() == qMetaTypeId<QGeoShape>()) + v = value.value<QGeoShape>(); + else if (value.userType() == qMetaTypeId<QGeoRectangle>()) + v = value.value<QGeoRectangle>(); + else if (value.userType() == qMetaTypeId<QGeoCircle>()) + v = value.value<QGeoCircle>(); + else + v = QGeoShape(); + + onLoad(); +} + +bool GeoShapeValueType::isEqual(const QVariant &other) const +{ + if (other.userType() == qMetaTypeId<QGeoShape>()) + return v == other.value<QGeoShape>(); + else if (other.userType() == qMetaTypeId<QGeoRectangle>()) + return v == other.value<QGeoRectangle>(); + else if (other.userType() == qMetaTypeId<QGeoCircle>()) + return v == other.value<QGeoCircle>(); + else + return false; +} + +GeoShapeValueType::GeoShapeValueType(int userType, QObject *parent) +: QQmlValueTypeBase<QGeoShape>(userType, parent) +{ + QMetaType::construct(userType, &v, 0); +} + +QT_END_NAMESPACE diff --git a/src/imports/positioning/qdeclarativegeoshape.h b/src/imports/positioning/qdeclarativegeoshape.h new file mode 100644 index 00000000..e75830b0 --- /dev/null +++ b/src/imports/positioning/qdeclarativegeoshape.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVEGEOSHAPE_H +#define QDECLARATIVEGEOSHAPE_H + +#include <QtQml/private/qqmlvaluetype_p.h> +#include <QtPositioning/QGeoShape> + +QT_BEGIN_NAMESPACE + +class GeoShapeValueType : public QQmlValueTypeBase<QGeoShape> +{ + Q_OBJECT + + Q_PROPERTY(ShapeType type READ type) + Q_PROPERTY(bool isValid READ isValid) + Q_PROPERTY(bool isEmpty READ isEmpty) + + Q_ENUMS(ShapeType) + +public: + explicit GeoShapeValueType(QObject *parent = 0); + ~GeoShapeValueType(); + + enum ShapeType { + UnknownType = QGeoShape::UnknownType, + RectangleType = QGeoShape::RectangleType, + CircleType = QGeoShape::CircleType + }; + + ShapeType type() const; + bool isValid() const; + bool isEmpty() const; + + Q_INVOKABLE bool contains(const QGeoCoordinate &coordinate) const; + + QString toString() const Q_DECL_OVERRIDE; + void setValue(const QVariant &value) Q_DECL_OVERRIDE; + bool isEqual(const QVariant &other) const Q_DECL_OVERRIDE; + +protected: + explicit GeoShapeValueType(int userType, QObject *parent = 0); +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/imports/positioning/qdeclarativeposition.cpp b/src/imports/positioning/qdeclarativeposition.cpp new file mode 100644 index 00000000..bce1b1fa --- /dev/null +++ b/src/imports/positioning/qdeclarativeposition.cpp @@ -0,0 +1,375 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativeposition_p.h" +#include <QtQml/qqml.h> +#include <qnmeapositioninfosource.h> +#include <QFile> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Position + \instantiates QDeclarativePosition + \inqmlmodule QtPositioning 5.0 + \since Qt Positioning 5.0 + + \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{declarative/flickr}{Flickr} example application. + + \sa PositionSource, coordinate + +*/ + +QDeclarativePosition::QDeclarativePosition(QObject *parent) + : QObject(parent), m_latitudeValid(false), m_longitudeValid(false), + m_altitudeValid(false), m_speed(-1), m_speedValid(false), m_horizontalAccuracyValid(false), + m_verticalAccuracyValid(false), m_horizontalAccuracy(-1), m_verticalAccuracy(-1) +{ +} + +QDeclarativePosition::~QDeclarativePosition() +{ +} + +/*! + \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 +*/ + +void QDeclarativePosition::setCoordinate(const QGeoCoordinate &coordinate) +{ + if (m_coordinate == coordinate) + return; + + m_coordinate = coordinate; + + if (coordinate.type() == QGeoCoordinate::Coordinate3D && !m_altitudeValid) { + m_altitudeValid = true; + emit altitudeValidChanged(); + } else if (m_altitudeValid) { + m_altitudeValid = false; + emit altitudeValidChanged(); + } + if (coordinate.isValid()) { + if (!m_longitudeValid) { + m_longitudeValid = true; + emit longitudeValidChanged(); + } + if (!m_latitudeValid) { + m_latitudeValid = true; + emit latitudeValidChanged(); + } + } else { + if (m_longitudeValid) { + m_longitudeValid = false; + emit longitudeValidChanged(); + } + if (m_latitudeValid) { + m_latitudeValid = false; + emit latitudeValidChanged(); + } + } + emit coordinateChanged(); +} + +QGeoCoordinate QDeclarativePosition::coordinate() +{ + return m_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 m_latitudeValid; +} + + +/*! + \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 m_longitudeValid; +} + + +/*! + \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 m_speedValid; +} + +/*! + \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 m_altitudeValid; +} + +/*! + \qmlproperty double Position::speed + + This property holds the value of speed (groundspeed, meters / second). + + It is a read-only property. + + \sa speedValid, coordinate +*/ + +void QDeclarativePosition::setSpeed(double speed) +{ + if (speed == m_speed) + return; + m_speed = speed; + if (!m_speedValid) { + m_speedValid = true; + emit speedValidChanged(); + } + emit speedChanged(); +} + +double QDeclarativePosition::speed() const +{ + return m_speed; +} + +/*! + \qmlproperty real Position::horizontalAccuracy + + This property holds the horizontal accuracy of the coordinate (in meters). + + \sa horizontalAccuracyValid, coordinate +*/ + +void QDeclarativePosition::setHorizontalAccuracy(qreal horizontalAccuracy) +{ + if (horizontalAccuracy == m_horizontalAccuracy) + return; + m_horizontalAccuracy = horizontalAccuracy; + if (!m_horizontalAccuracyValid) { + m_horizontalAccuracyValid = true; + emit horizontalAccuracyValidChanged(); + } + emit horizontalAccuracyChanged(); +} + +qreal QDeclarativePosition::horizontalAccuracy() const +{ + return m_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 m_horizontalAccuracyValid; +} + +/*! + \qmlproperty real Position::verticalAccuracy + + This property holds the vertical accuracy of the coordinate (in meters). + + \sa verticalAccuracyValid, coordinate +*/ + +void QDeclarativePosition::setVerticalAccuracy(qreal verticalAccuracy) +{ + if (verticalAccuracy == m_verticalAccuracy) + return; + m_verticalAccuracy = verticalAccuracy; + if (!m_verticalAccuracyValid) { + m_verticalAccuracyValid = true; + emit verticalAccuracyValidChanged(); + } + emit verticalAccuracyChanged(); +} + +qreal QDeclarativePosition::verticalAccuracy() const +{ + return m_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 m_verticalAccuracyValid; +} + +/*! + \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. +*/ + +void QDeclarativePosition::setTimestamp(const QDateTime ×tamp) +{ + if (timestamp == m_timestamp) + return; + m_timestamp = timestamp; + emit timestampChanged(); +} + +QDateTime QDeclarativePosition::timestamp() const +{ + return m_timestamp; +} + +void QDeclarativePosition::invalidate() +{ + // Invalidate all data + if (m_latitudeValid) { + m_latitudeValid = false; + emit latitudeValidChanged(); + } + if (m_longitudeValid) { + m_longitudeValid = false; + emit longitudeValidChanged(); + } + if (m_altitudeValid) { + m_altitudeValid = false; + emit altitudeValidChanged(); + } + if (m_speedValid) { + m_speedValid = false; + emit speedValidChanged(); + } + if (m_horizontalAccuracyValid) { + m_horizontalAccuracyValid = false; + emit horizontalAccuracyValidChanged(); + } + if (m_verticalAccuracyValid) { + m_verticalAccuracyValid = false; + emit verticalAccuracyValidChanged(); + } +} + +#include "moc_qdeclarativeposition_p.cpp" + +QT_END_NAMESPACE diff --git a/src/imports/positioning/qdeclarativeposition_p.h b/src/imports/positioning/qdeclarativeposition_p.h new file mode 100644 index 00000000..99c2d8fc --- /dev/null +++ b/src/imports/positioning/qdeclarativeposition_p.h @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVEPOSITION_H +#define QDECLARATIVEPOSITION_H + +#include <QtCore> +#include <QDateTime> +#include <qgeopositioninfosource.h> +#include <qgeopositioninfo.h> +#include "qdeclarativecoordinate_p.h" +#include <QtQml/qqml.h> + +// Define this to get qDebug messages +// #define QDECLARATIVE_POSITION_DEBUG + +#ifdef QDECLARATIVE_POSITION_DEBUG +#include <QDebug> +#endif + +QT_BEGIN_NAMESPACE + +class 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) + +public: + + explicit QDeclarativePosition(QObject *parent = 0); + ~QDeclarativePosition(); + + bool isLatitudeValid() const; + bool isLongitudeValid() const; + bool isAltitudeValid() const; + QDateTime timestamp() const; + void setTimestamp(const QDateTime ×tamp); + double speed() const; + void setSpeed(double speed); + 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); + + // C++ + void setCoordinate(const QGeoCoordinate &coordinate); + void invalidate(); + +Q_SIGNALS: + void latitudeValidChanged(); + void longitudeValidChanged(); + void altitudeValidChanged(); + void timestampChanged(); + void speedChanged(); + void speedValidChanged(); + void coordinateChanged(); + void horizontalAccuracyChanged(); + void horizontalAccuracyValidChanged(); + void verticalAccuracyChanged(); + void verticalAccuracyValidChanged(); + +private: + bool m_latitudeValid; + bool m_longitudeValid; + bool m_altitudeValid; + QDateTime m_timestamp; + double m_speed; + bool m_speedValid; + bool m_horizontalAccuracyValid; + bool m_verticalAccuracyValid; + qreal m_horizontalAccuracy; + qreal m_verticalAccuracy; + QGeoCoordinate m_coordinate; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QDeclarativePosition) + +#endif diff --git a/src/imports/positioning/qdeclarativepositionsource.cpp b/src/imports/positioning/qdeclarativepositionsource.cpp new file mode 100644 index 00000000..97ad1bbc --- /dev/null +++ b/src/imports/positioning/qdeclarativepositionsource.cpp @@ -0,0 +1,646 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativepositionsource_p.h" +#include "qdeclarativeposition_p.h" +#include "error_messages.h" + +#include <QtQml/qqmlinfo.h> +#include <QtQml/qqml.h> +#include <qnmeapositioninfosource.h> +#include <QFile> +#include <QTimer> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype PositionSource + \instantiates QDeclarativePositionSource + \inqmlmodule QtPositioning 5.0 + \since Qt Positioning 5.0 + + \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{declarative/flickr}{Flickr} example application shows how to use + a PositionSource in your application to retrieve local data for users + from a REST web service. + + \sa {QtPositioning5::Position}, {QGeoPositionInfoSource} + +*/ + +QDeclarativePositionSource::QDeclarativePositionSource() +: m_positionSource(0), m_preferredPositioningMethods(NoPositioningMethod), m_nmeaFile(0), + m_active(false), m_singleUpdate(false), m_updateInterval(0), m_sourceError(UnknownSourceError) +{ +} + +QDeclarativePositionSource::~QDeclarativePositionSource() +{ + delete m_nmeaFile; + 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))); + + m_positionSource->setUpdateInterval(m_updateInterval); + m_positionSource->setPreferredPositioningMethods( + static_cast<QGeoPositionInfoSource::PositioningMethods>(int(m_preferredPositioningMethods))); + } + + 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) +{ + // Strip the filename. This is clumsy but the file may be prefixed in several + // ways: "file:///", "qrc:///", "/", "" in platform dependant manner. + QString localFileName = nmeaSource.toString(); + if (!QFile::exists(localFileName)) { + if (localFileName.startsWith("qrc:///")) { + localFileName.remove(0, 7); + } else if (localFileName.startsWith("file:///")) { + localFileName.remove(0, 7); + } + if (!QFile::exists(localFileName) && localFileName.startsWith("/")) { + localFileName.remove(0,1); + } + } + if (m_nmeaFileName == localFileName) + return; + m_nmeaFileName = localFileName; + m_nmeaSource = nmeaSource; + + PositioningMethods previousPositioningMethods = supportedPositioningMethods(); + + // The current position source needs to be deleted + // because QNmeaPositionInfoSource can be bound only to a one file. + delete m_positionSource; + m_positionSource = 0; + // 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))->setDevice(m_nmeaFile); + connect(m_positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)), + this, SLOT(positionUpdateReceived(QGeoPositionInfo))); + if (m_active && !m_singleUpdate) { + // Keep on updating even though source changed + QTimer::singleShot(0, this, SLOT(start())); + } + } else { + qmlInfo(this) << QCoreApplication::translate(CONTEXT_NAME, MISSED_NMEA_FILE) << 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(); + + emit nmeaSourceChanged(); +} + +/*! + \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.NoPositioningMethod - No positioning methods supported (no source). + \li PositionSource.SatellitePositioningMethod - Satellite-based positioning methods such as GPS are supported. + \li PositionSource.NonSatellitePositioningMethod - 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) { + QGeoPositionInfoSource::PositioningMethods methods = m_positionSource->supportedPositioningMethods(); + if ( (methods & QGeoPositionInfoSource::AllPositioningMethods) == methods ) { + return QDeclarativePositionSource::AllPositioningMethods; + } else if (methods & QGeoPositionInfoSource::SatellitePositioningMethods) { + return QDeclarativePositionSource::SatellitePositioningMethod; + } else if (methods & QGeoPositionInfoSource::NonSatellitePositioningMethods) { + return QDeclarativePositionSource::NonSatellitePositioningMethod; + } + } + return QDeclarativePositionSource::NoPositioningMethod; +} + +/*! + \qmlproperty enumeration PositionSource::preferredPositioningMethods + + This property holds the preferred positioning methods of the + current source. + + \list + \li PositionSource.SatellitePositioningMethod - Satellite-based positioning methods such as GPS should be preferred. + \li PositionSource.NonSatellitePositioningMethod - 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) { + QGeoPositionInfoSource::PositioningMethods methods = + m_positionSource->preferredPositioningMethods(); + if ( (methods & QGeoPositionInfoSource::AllPositioningMethods) == methods) { + return QDeclarativePositionSource::AllPositioningMethods; + } else if (methods & QGeoPositionInfoSource::SatellitePositioningMethods) { + return QDeclarativePositionSource::SatellitePositioningMethod; + } else if (methods & QGeoPositionInfoSource::NonSatellitePositioningMethods) { + return QDeclarativePositionSource::NonSatellitePositioningMethod; + } + } + 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) + return; + + 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) +{ + if (update.isValid()) { + m_position.setTimestamp(update.timestamp()); + m_position.setCoordinate(update.coordinate()); + if (update.hasAttribute(QGeoPositionInfo::GroundSpeed)) { + m_position.setSpeed(update.attribute(QGeoPositionInfo::GroundSpeed)); + } + if (update.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) { + m_position.setHorizontalAccuracy(update.attribute(QGeoPositionInfo::HorizontalAccuracy)); + } + if (update.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) { + m_position.setVerticalAccuracy(update.attribute(QGeoPositionInfo::VerticalAccuracy)); + } + emit positionChanged(); + } else { + m_position.invalidate(); + } + if (m_singleUpdate && m_active) { + m_active = false; + m_singleUpdate = false; + emit activeChanged(); + } +} + + +/*! + \qmlproperty enumeration PositionSource::sourceError + + This property holds the error which last occured 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 remote positioning backend closed the connection, which happens for example in case + the user is switching location services to off. This object becomes invalid and should be deleted. + A new source can be declared later on to check whether the positioning backend is up again. + \li PositionSource.UnknownSourceError - An unidentified error occurred. + \endlist + +*/ + +QDeclarativePositionSource::SourceError QDeclarativePositionSource::sourceError() const +{ + return m_sourceError; +} + +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))); + + m_positionSource->setUpdateInterval(m_updateInterval); + m_positionSource->setPreferredPositioningMethods( + static_cast<QGeoPositionInfoSource::PositioningMethods>(int(m_preferredPositioningMethods))); + } + + 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(); + } + + 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 { + m_sourceError = QDeclarativePositionSource::UnknownSourceError; + } + emit sourceErrorChanged(); +} + +#include "moc_qdeclarativepositionsource_p.cpp" + +QT_END_NAMESPACE diff --git a/src/imports/positioning/qdeclarativepositionsource_p.h b/src/imports/positioning/qdeclarativepositionsource_p.h new file mode 100644 index 00000000..70506c00 --- /dev/null +++ b/src/imports/positioning/qdeclarativepositionsource_p.h @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef QDECLARATIVEPOSITIONSOURCE_H +#define QDECLARATIVEPOSITIONSOURCE_H + +#include "qdeclarativeposition_p.h" + +#include <QtCore/QObject> +#include <QtQml/QQmlParserStatus> +#include <QtPositioning/QGeoPositionInfoSource> + +QT_BEGIN_NAMESPACE + +class QFile; + +class 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 { + NoPositioningMethod = 0, + SatellitePositioningMethod = QGeoPositionInfoSource::SatellitePositioningMethods, + NonSatellitePositioningMethod = QGeoPositionInfoSource::NonSatellitePositioningMethods, + AllPositioningMethods = QGeoPositionInfoSource::AllPositioningMethods + }; + + Q_DECLARE_FLAGS(PositioningMethods, PositioningMethod) + Q_FLAGS(PositioningMethods) + + enum SourceError { + AccessError = QGeoPositionInfoSource::AccessError, + ClosedError = QGeoPositionInfoSource::ClosedError, + UnknownSourceError = QGeoPositionInfoSource::UnknownSourceError + }; + 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; + + // Virtuals from QQmlParserStatus + void classBegin() { } + void componentComplete(); + +public Q_SLOTS: + void update(); + void start(); + void stop(); + +Q_SIGNALS: + void positionChanged(); + void activeChanged(); + void nmeaSourceChanged(); + void updateIntervalChanged(); + void supportedPositioningMethodsChanged(); + void preferredPositioningMethodsChanged(); + void sourceErrorChanged(); + void nameChanged(); + void validityChanged(); + + +private Q_SLOTS: + void positionUpdateReceived(const QGeoPositionInfo &update); + void sourceErrorReceived(const QGeoPositionInfoSource::Error error); +private: + QGeoPositionInfoSource *m_positionSource; + QDeclarativePosition m_position; + PositioningMethods m_preferredPositioningMethods; + QFile *m_nmeaFile; + 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/imports/positioning/qmldir b/src/imports/positioning/qmldir new file mode 100644 index 00000000..4143e0d5 --- /dev/null +++ b/src/imports/positioning/qmldir @@ -0,0 +1,3 @@ +module QtPositioning +plugin declarative_positioning +typeinfo plugins.qmltypes |