summaryrefslogtreecommitdiff
path: root/src/positioning
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2013-08-26 09:35:01 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-17 11:38:14 +0200
commit0ed9f7496656fa0ea52d703c7fddff26c2192857 (patch)
treeec0d4d7dc638e8018a8896a0b62cc91840c9c23d /src/positioning
parent87ce030b7b7336e561779dc9516d5ae2242a5d5f (diff)
downloadqtlocation-0ed9f7496656fa0ea52d703c7fddff26c2192857.tar.gz
Improve area monitoring API.
1.) QGeoAreaMonitor renamed to QGeoAreaMonitorSource 2.) Add new QGeoAreaMonitorInfo data type encpsulating individual areas to be monitored 3.) Port positionpoll plug-in to new features 4.) Make positionpoll monitor thread safe 4.) Extend and fix the QGeoAreaMonitor unit test 5.) Fix documentation. Task-number: QTBUG-31711 Change-Id: Icfc982de4753d2f43cb4d15c234eb7b7c039a0c4 Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/positioning')
-rw-r--r--src/positioning/doc/snippets/cpp/cppqml.cpp40
-rw-r--r--src/positioning/doc/src/cpp-position.qdoc4
-rw-r--r--src/positioning/doc/src/qtpositioning-plugins.qdoc2
-rw-r--r--src/positioning/positioning.pro6
-rw-r--r--src/positioning/qgeoareamonitor.cpp256
-rw-r--r--src/positioning/qgeoareamonitorinfo.cpp379
-rw-r--r--src/positioning/qgeoareamonitorinfo.h (renamed from src/positioning/qgeoareamonitor.h)74
-rw-r--r--src/positioning/qgeoareamonitorsource.cpp390
-rw-r--r--src/positioning/qgeoareamonitorsource.h109
-rw-r--r--src/positioning/qgeopositioninfosourcefactory.cpp4
-rw-r--r--src/positioning/qgeopositioninfosourcefactory.h4
-rw-r--r--src/positioning/qgeosatelliteinfosource.cpp17
-rw-r--r--src/positioning/qgeosatelliteinfosource.h4
13 files changed, 996 insertions, 293 deletions
diff --git a/src/positioning/doc/snippets/cpp/cppqml.cpp b/src/positioning/doc/snippets/cpp/cppqml.cpp
index 5ab23513..95d34b7c 100644
--- a/src/positioning/doc/snippets/cpp/cppqml.cpp
+++ b/src/positioning/doc/snippets/cpp/cppqml.cpp
@@ -39,9 +39,12 @@
****************************************************************************/
#include <QtCore/QObject>
+#include <QtCore/QDebug>
#include <QtCore/QVariant>
#include <QtPositioning/QGeoAddress>
#include <QtPositioning/QGeoLocation>
+#include <QtPositioning/QGeoCircle>
+#include <QtPositioning/QGeoAreaMonitorSource>
void cppQmlInterface(QObject *qmlObject)
{
@@ -62,3 +65,40 @@ void cppQmlInterface(QObject *qmlObject)
//! [Location set]
}
+class MyClass : public QObject
+{
+ Q_OBJECT
+//! [BigBen]
+public:
+ MyClass() : QObject()
+ {
+ QGeoAreaMonitorSource *monitor = QGeoAreaMonitorSource::createDefaultMonitorSource(this);
+ if (monitor) {
+ connect(monitor, SIGNAL(areaEntered(QGeoAreaMonitorInfo,QGeoPositionInfo)),
+ this, SLOT(areaEntered(QGeoAreaMonitorInfo,QGeoPositionInfo));
+ connect(monitor, SIGNAL(areaExited(QGeoAreaMonitorInfo,QGeoPositionInfo)),
+ this, SLOT(areaExited(QGeoAreaMonitorInfo,QGeoPositionInfo)));
+
+ QGeoAreaMonitorInfo bigBen("Big Ben");
+ QGeoCoordinate position(51.50104, -0.124632);
+ bigBen.setMonitoredArea(QGeoCircle(position, 100));
+
+ monitor->startMonitoring(bigBen);
+
+ } else {
+ qDebug() << "Could not create default area monitor";
+ }
+ }
+
+public Q_SLOTS:
+ void areaEntered(const QGeoAreaMonitorInfo &mon, const QGeoPositionInfo &update)
+ {
+ qDebug() << "Now within 100 meters, current position is" << update.coordinate();
+ }
+
+ void areaExited(const QGeoAreaMonitorInfo &mon, const QGeoPositionInfo &update)
+ {
+ qDebug() << "No longer within 100 meters, current position is" << update.coordinate();
+ }
+//! [BigBen]
+};
diff --git a/src/positioning/doc/src/cpp-position.qdoc b/src/positioning/doc/src/cpp-position.qdoc
index 75c2e30e..16fceea5 100644
--- a/src/positioning/doc/src/cpp-position.qdoc
+++ b/src/positioning/doc/src/cpp-position.qdoc
@@ -84,10 +84,10 @@ the platform.
If a problem occurs with access to the information source then an
\l {QGeoPositionInfoSource::error()}{error()} signal is emitted.
-The QGeoAreaMonitor class enables client applications to be notified when
+The QGeoAreaMonitorSource class enables client applications to be notified when
the receiving device has moved in or out of a particular area, as specified
by a coordinate and radius. If the platform provides built-in support for
-area monitoring, QGeoAreaMonitor::createDefaultMonitor() returns an instance of
+area monitoring, QGeoAreaMonitorSource::createDefaultMonitor() returns an instance of
the default area monitor.
Satellite information can also be distributed through the
diff --git a/src/positioning/doc/src/qtpositioning-plugins.qdoc b/src/positioning/doc/src/qtpositioning-plugins.qdoc
index 1ed1be1a..5873aadd 100644
--- a/src/positioning/doc/src/qtpositioning-plugins.qdoc
+++ b/src/positioning/doc/src/qtpositioning-plugins.qdoc
@@ -61,7 +61,7 @@ The entries have the following meaning:
\li Set to \c true if the plugin implements a \l QGeoSatelliteInfoSource.
\row
\li Monitor
- \li Set to \c true if the plugin implements a \l QGeoAreaMonitor.
+ \li Set to \c true if the plugin implements a \l QGeoAreaMonitorSource.
\row
\li Priority
\li The plugin priority. If multiple plugins have the same provider name, the plugin
diff --git a/src/positioning/positioning.pro b/src/positioning/positioning.pro
index da1186bf..296356d0 100644
--- a/src/positioning/positioning.pro
+++ b/src/positioning/positioning.pro
@@ -8,7 +8,8 @@ OTHER_FILES += doc/src/*.qdoc # show .qdoc files in Qt Creator
PUBLIC_HEADERS += \
qgeoaddress.h \
- qgeoareamonitor.h \
+ qgeoareamonitorinfo.h \
+ qgeoareamonitorsource.h \
qgeoshape.h \
qgeorectangle.h \
qgeocircle.h \
@@ -37,7 +38,8 @@ PRIVATE_HEADERS += \
SOURCES += \
qgeoaddress.cpp \
- qgeoareamonitor.cpp \
+ qgeoareamonitorsource.cpp \
+ qgeoareamonitorinfo.cpp \
qgeoshape.cpp \
qgeorectangle.cpp \
qgeocircle.cpp \
diff --git a/src/positioning/qgeoareamonitor.cpp b/src/positioning/qgeoareamonitor.cpp
deleted file mode 100644
index 5ad69e9a..00000000
--- a/src/positioning/qgeoareamonitor.cpp
+++ /dev/null
@@ -1,256 +0,0 @@
-/****************************************************************************
-**
-** 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 <qgeoareamonitor.h>
-#include "qgeopositioninfosourcefactory.h"
-#include "qgeopositioninfosource_p.h"
-
-/*!
- \class QGeoAreaMonitor
- \inmodule QtPositioning
- \ingroup QtPositioning-positioning
- \since Qt Positioning 5.0
-
- \brief The QGeoAreaMonitor class enables the detection of proximity
- changes for a specified set of coordinates.
-
- A QGeoAreaMonitor emits signals when the current position is in
- range, or has moved out of range, of a specified circular area.
- The area is specified by a coordinate (the center point) and a
- radius (in meters).
-
- For example:
-
- \code
- public:
- MyClass::MyClass()
- {
- QGeoAreaMonitor *monitor = QGeoAreaMonitor::createDefaultMonitor();
- if (monitor) {
- connect(monitor, SIGNAL(areaEntered(QGeoPositionInfo)),
- this, SLOT(areaEntered(QGeoPositionInfo)));
- connect(monitor, SIGNAL(areaExited(QGeoPositionInfo)),
- this, SLOT(areaExited(QGeoPositionInfo)));
-
- QGeoCoordinate bigBenLocation(51.50104, -0.124632);
- monitor->setCenter(bigBenLocation);
- monitor->setRadius(100);
- } else {
- qDebug() << "Could not create default area monitor";
- }
- }
-
- public Q_SLOTS:
- void areaEntered(const QGeoPositionInfo &update)
- {
- qDebug() << "Now within 100 meters, current position is" << update.coordinate();
- }
-
- void areaExited(const QGeoPositionInfo &update)
- {
- qDebug() << "No longer within 100 meters, current position is" << update.coordinate();
- }
- \endcode
-*/
-
-QT_BEGIN_NAMESPACE
-
-class QGeoAreaMonitorPrivate
-{
-public:
- QGeoCoordinate coord;
- qreal radius;
-};
-
-
-/*!
- Creates a monitor with the given \a parent.
-*/
-QGeoAreaMonitor::QGeoAreaMonitor(QObject *parent)
- : QObject(parent),
- d(new QGeoAreaMonitorPrivate)
-{
- d->radius = qreal(0.0);
-}
-
-/*!
- Destroys the monitor.
-*/
-QGeoAreaMonitor::~QGeoAreaMonitor()
-{
- delete d;
-}
-
-/*!
- \property QGeoAreaMonitor::center
- \brief holds the center of the area to be monitored.
-
- When the center is set, if the radius has already been set and
- the current position is within the monitored area, areaEntered()
- is emitted immediately.
-
- By default, contains an invalid coordinate.
-
- Note: Subclass implementations must call the base implementation of
- setCenter() so that center() returns the correct value.
-*/
-void QGeoAreaMonitor::setCenter(const QGeoCoordinate &coordinate)
-{
- d->coord = coordinate;
-}
-
-QGeoCoordinate QGeoAreaMonitor::center() const
-{
- return d->coord;
-}
-
-/*!
- \property QGeoAreaMonitor::radius
- \brief holds the radius of the area to be monitored, in meters.
-
- If the specified radius is less than the minimum supported radius, the
- radius is set to the minimum radius.
-
- When this property is set, if the center coordinate has already been set and
- the current position is within the monitored area, areaEntered()
- is emitted immediately.
-
- By default, this property is 0.
-
- Note: Subclass implementations must call the base implementation of
- setRadius() so that radius() returns the correct value.
-*/
-void QGeoAreaMonitor::setRadius(qreal radius)
-{
- d->radius = radius;
-}
-
-qreal QGeoAreaMonitor::radius() const
-{
- return d->radius;
-}
-
-/*!
- Creates and returns a monitor with the given \a parent that
- monitors areas using resources on the underlying system.
-
- Returns 0 if the system has no support for position monitoring.
-*/
-QGeoAreaMonitor *QGeoAreaMonitor::createDefaultMonitor(QObject *parent)
-{
- QList<QJsonObject> plugins = QGeoPositionInfoSourcePrivate::pluginsSorted();
- foreach (const QJsonObject &obj, plugins) {
- if (obj.value(QStringLiteral("Monitor")).isBool()
- && obj.value(QStringLiteral("Monitor")).toBool())
- {
- QGeoPositionInfoSourcePrivate d;
- d.metaData = obj;
- d.loadPlugin();
- QGeoAreaMonitor *s = 0;
- if (d.factory)
- s = d.factory->areaMonitor(parent);
- return s;
- }
- }
-
- return 0;
-}
-
-/*!
- Creates and returns a monitor with the given \a parent,
- by loading the plugin named \a sourceName.
-
- Returns 0 if the plugin cannot be found.
-*/
-QGeoAreaMonitor *QGeoAreaMonitor::createMonitor(const QString &sourceName, QObject *parent)
-{
- QHash<QString, QJsonObject> plugins = QGeoPositionInfoSourcePrivate::plugins();
- if (plugins.contains(sourceName)) {
- QGeoPositionInfoSourcePrivate d;
- d.metaData = plugins.value(sourceName);
- d.loadPlugin();
- QGeoAreaMonitor *s = 0;
- if (d.factory)
- s = d.factory->areaMonitor(parent);
- return s;
- }
-
- return 0;
-}
-
-/*!
- Returns a list of available monitor plugins, including the default system
- backend if one is available.
-*/
-QStringList QGeoAreaMonitor::availableMonitors()
-{
- QStringList plugins;
- QHash<QString, QJsonObject> meta = QGeoPositionInfoSourcePrivate::plugins();
- foreach (const QString &name, meta.keys()) {
- if (meta.value(name).value(QStringLiteral("Monitor")).isBool()
- && meta.value(name).value(QStringLiteral("Monitor")).toBool()) {
- plugins << name;
- }
- }
-
- return plugins;
-}
-
-
-
-/*!
- \fn void QGeoAreaMonitor::areaEntered(const QGeoPositionInfo &update);
-
- Emitted when the current position has moved from a position outside the
- monitored area to a position within the monitored area.
-
- The \a update holds the new position.
-*/
-
-/*!
- \fn void QGeoAreaMonitor::areaExited(const QGeoPositionInfo &update);
-
- Emitted when the current position has moved from a position within the
- monitored area to a position outside the monitored area.
-
- The \a update holds the new position.
-*/
-
-QT_END_NAMESPACE
diff --git a/src/positioning/qgeoareamonitorinfo.cpp b/src/positioning/qgeoareamonitorinfo.cpp
new file mode 100644
index 00000000..b4e0d179
--- /dev/null
+++ b/src/positioning/qgeoareamonitorinfo.cpp
@@ -0,0 +1,379 @@
+/****************************************************************************
+**
+** 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 <QGeoAreaMonitorInfo>
+#include <QDateTime>
+#include <QSharedData>
+#include <QUuid>
+
+#ifndef QT_NO_DEBUG_STREAM
+#include <QDebug>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QGeoAreaMonitorInfo
+ \inmodule QtPositioning
+ \since Qt Positioning 5.2
+ \ingroup QtPositioning-positioning
+
+ \brief The QGeoAreaMonitorInfo class describes the parameters of an area or region
+ to be monitored for proximity.
+
+ The purpose of area monitoring is to inform a user when he/she comes close to an area of
+ interest. In general such an area is described by a \l QGeoCircle. The circle's center
+ represents the place of interest and the area around it identifies the geographical region
+ within which notifications are sent.
+
+ A QGeoAreaMonitorInfo object is valid if it has a non-empty name and a valid \l area().
+ Such objects must be registered with a \l QGeoAreaMonitorSource to start and stop the
+ monitoring process. Note that extensive monitoring can be very resource consuming
+ because the positioning engine must remain active and has to match the current position
+ with each QGeoAreaMonitorInfo instance.
+
+ To further reduce the burden on the system there are optional attributes which can
+ set. Each monitored area can have an expiry date which automatically removes the
+ to-be-monitored area from the monitoring source once the expiry date has been reached.
+ Another option is to adjust the persistence of a monitored area. A QGeoAreaMonitorInfo
+ that \l isPersistent() will remain active beyond
+ the current applications lifetime. If an area is entered while the monitoring
+ application is not running the application will be started. Note that this feature is
+ not available on all platforms. Its availability can be checked via
+ \l QGeoAreaMonitorSource::supportedAreaMonitorFeatures().
+
+ \sa QGeoAreaMonitorSource
+
+ */
+
+class QGeoAreaMonitorInfoPrivate : public QSharedData
+{
+public:
+ QGeoAreaMonitorInfoPrivate() : QSharedData(), persistent(false) {}
+ QGeoAreaMonitorInfoPrivate(const QGeoAreaMonitorInfoPrivate &other)
+ : QSharedData(other)
+ {
+ uid = other.uid;
+ name = other.name;
+ shape = other.shape;
+ persistent = other.persistent;
+ notificationParameters = other.notificationParameters;
+ expiry = other.expiry;
+ }
+ ~QGeoAreaMonitorInfoPrivate() {}
+
+ QUuid uid;
+ QString name;
+ QGeoShape shape;
+ bool persistent;
+ QVariantMap notificationParameters;
+ QDateTime expiry;
+};
+
+/*!
+ Constructs a QGeoAreaMonitorInfo object with the specified \a name.
+
+ \sa name()
+ */
+QGeoAreaMonitorInfo::QGeoAreaMonitorInfo(const QString &name)
+{
+ d = new QGeoAreaMonitorInfoPrivate;
+ d->name = name;
+ d->uid = QUuid::createUuid();
+}
+
+/*!
+ Constructs a QGeoAreaMonitorInfo object as a copy of \a other.
+ */
+QGeoAreaMonitorInfo::QGeoAreaMonitorInfo(const QGeoAreaMonitorInfo &other)
+ : d(other.d)
+{
+}
+
+/*!
+ Destructor
+ */
+QGeoAreaMonitorInfo::~QGeoAreaMonitorInfo()
+{
+}
+
+/*!
+ Assigns \a other to this QGeoAreaMonitorInfo object and returns a reference
+ to this QGeoAreaMonitorInfo object.
+ */
+QGeoAreaMonitorInfo &QGeoAreaMonitorInfo::operator=(const QGeoAreaMonitorInfo &other)
+{
+ d = other.d;
+ return *this;
+}
+
+/*!
+ Returns true if all of this object's values are the same as those of
+ \a other.
+*/
+bool QGeoAreaMonitorInfo::operator==(const QGeoAreaMonitorInfo &other) const
+{
+ return (d->name == other.d->name &&
+ d->uid == other.d->uid &&
+ d->shape == other.d->shape &&
+ d->persistent == other.d->persistent &&
+ d->expiry == other.d->expiry &&
+ d->notificationParameters == other.d->notificationParameters);
+}
+
+/*!
+ Returns true if any of this object's values are not the same as those of
+ \a other.
+*/
+bool QGeoAreaMonitorInfo::operator!=(const QGeoAreaMonitorInfo &other) const
+{
+ return !QGeoAreaMonitorInfo::operator ==(other);
+}
+
+/*!
+ Returns the name of the QGeoAreaMonitorInfo object. The name should be used to
+ for user-visibility purposes.
+ */
+QString QGeoAreaMonitorInfo::name() const
+{
+ return d->name;
+}
+
+/*!
+ Sets the user visibile \a name.
+ */
+void QGeoAreaMonitorInfo::setName(const QString &name)
+{
+ if (d->name != name)
+ d->name = name;
+}
+
+/*!
+ Returns the identifier of the QGeoAreaMonitorInfo object.
+ The identifier is automatically generated upon construction of a new
+ QGeoAreaMonitorInfo object.
+*/
+
+QString QGeoAreaMonitorInfo::identifier() const
+{
+ return d->uid.toString();
+}
+
+/*!
+ Returns true, if the monitor is valid. A valid QGeoAreaMonitorInfo has a non-empty name()
+ and the monitored area is not \l {QGeoShape::isEmpty()}{empty()}.
+ Otherwise this function returns false.
+ */
+bool QGeoAreaMonitorInfo::isValid() const
+{
+ return (!d->name.isEmpty() && !d->shape.isEmpty());
+}
+
+/*!
+ Returns the boundaries of the to-be-monitored area. This area must not be empty.
+
+ \sa setArea()
+ */
+QGeoShape QGeoAreaMonitorInfo::area() const
+{
+ return d->shape;
+}
+
+/*!
+ Sets the to-be-monitored area to \a newShape.
+
+ \sa area()
+ */
+void QGeoAreaMonitorInfo::setArea(const QGeoShape &newShape)
+{
+ d->shape = newShape;
+}
+
+/*!
+ Returns the expiry date.
+
+ After an active QGeoAreaMonitorInfo has expired the region is no longer monitored
+ and the QGeoAreaMonitorInfo object is removed from the list of
+ \l {QGeoAreaMonitorSource::activeMonitors()}{active monitors}.
+
+ If the expiry \l QDateTime is invalid the QGeoAreaMonitorInfo object is treated as not having
+ an expiry date. This implies an indefinite monitoring period if the object is persistent or
+ until the current application closes if the object is non-persistent.
+
+ \sa QGeoAreaMonitorSource::activeMonitors()
+ */
+QDateTime QGeoAreaMonitorInfo::expiration() const
+{
+ return d->expiry;
+}
+
+/*!
+ Sets the expiry date and time to \a expiry.
+ */
+void QGeoAreaMonitorInfo::setExpiration(const QDateTime &expiry)
+{
+ d->expiry = expiry;
+}
+
+/*!
+ Returns true if the QGeoAreaMonitorInfo is persistent.
+ The default value for this property is false.
+
+ A non-persistent QGeoAreaMonitorInfo will be removed by the system once
+ the application owning the monitor object stops. Persistent objects remain
+ active and can be retrieved once the application restarts.
+
+ If the system triggers an event associated to a persistent QGeoAreaMonitorInfo
+ the relevant application will be re-started and the appropriate signal emitted.
+
+ \sa setPersistent()
+ */
+bool QGeoAreaMonitorInfo::isPersistent() const
+{
+ return d->persistent;
+}
+
+/*!
+ Sets the QGeoAreaMonitorInfo objects persistence to \a isPersistent.
+
+ Note that setting this flag does not imply that QGeoAreaMonitorInfoSource supports persistent
+ monitoring. \l QGeoAreaMonitorSource::supportedAreaMonitorFeatures() can be used to
+ check for this feature's availability.
+
+ \sa isPersistent()
+ */
+void QGeoAreaMonitorInfo::setPersistent(bool isPersistent)
+{
+ d->persistent = isPersistent;
+}
+
+
+/*!
+ Returns the set of platform specific paraemters used by this QGeoAreaMonitorInfo.
+
+ \sa setNotificationParameters()
+ */
+QVariantMap QGeoAreaMonitorInfo::notificationParameters() const
+{
+ return d->notificationParameters;
+}
+
+/*!
+ Sets the set of platform specific \a parameters used by QGeoAreaMonitorInfo.
+
+ \sa notificationParameters()
+ */
+void QGeoAreaMonitorInfo::setNotificationParameters(const QVariantMap &parameters)
+{
+ d->notificationParameters = parameters;
+}
+
+#ifndef QT_NO_DATASTREAM
+
+/*!
+ \fn QDataStream &operator<<(QDataStream &stream, const QGeoAreaMonitorInfo &monitor)
+ \relates QGeoAreaMonitorInfo
+
+ Writes the given \a monitor to the specified \a stream.
+
+ \sa {Serializing Qt Data Types}
+*/
+QDataStream &operator<<(QDataStream &ds, const QGeoAreaMonitorInfo &monitor)
+{
+ ds << monitor.name() << monitor.d->uid << monitor.area()
+ << monitor.isPersistent() << monitor.notificationParameters() << monitor.expiration();
+ return ds;
+}
+
+/*!
+ \fn QDataStream &operator>>(QDataStream &stream, QGeoAreaMonitorInfo &monitor)
+ \relates QGeoAreaMonitorInfo
+
+ Reads a area monitoring data from the specified \a stream into the given
+ \a monitor.
+
+ \sa {Serializing Qt Data Types}
+*/
+
+QDataStream &operator>>(QDataStream &ds, QGeoAreaMonitorInfo &monitor)
+{
+ QString s;
+ ds >> s;
+ monitor = QGeoAreaMonitorInfo(s);
+
+ QUuid id;
+ ds >> id;
+ monitor.d->uid = id;
+
+ QGeoShape shape;
+ ds >> shape;
+ monitor.setArea(shape);
+
+ bool persistent;
+ ds >> persistent;
+ monitor.setPersistent(persistent);
+
+ QVariantMap map;
+ ds >> map;
+ monitor.setNotificationParameters(map);
+
+ QDateTime dt;
+ ds >> dt;
+ monitor.setExpiration(dt);
+
+ return ds;
+}
+
+#endif
+
+#ifndef QT_NO_DEBUG_STREAM
+QDebug operator<<(QDebug dbg, const QGeoAreaMonitorInfo &monitor)
+{
+ dbg.nospace() << "QGeoAreaMonitorInfo(\"" << qPrintable(monitor.name())
+ << "\", " << monitor.area()
+ << ", persistent: " << monitor.isPersistent()
+ << ", expiry: " << monitor.expiration() << ")";
+ return dbg.space();
+}
+
+#endif
+
+QT_END_NAMESPACE
diff --git a/src/positioning/qgeoareamonitor.h b/src/positioning/qgeoareamonitorinfo.h
index 1aed8b6b..938671df 100644
--- a/src/positioning/qgeoareamonitor.h
+++ b/src/positioning/qgeoareamonitorinfo.h
@@ -38,48 +38,68 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef QGEOAREAMONITOR_H
-#define QGEOAREAMONITOR_H
-#include <QtPositioning/QGeoCoordinate>
+#ifndef QGEOAREAMONITORINFO_H
+#define QGEOAREAMONITORINFO_H
-#include <QObject>
-#include <QStringList>
+#include <QtPositioning/QGeoCoordinate>
+#include <QtPositioning/QGeoShape>
+#include <QtCore/QSharedDataPointer>
+#include <QtCore/QVariantMap>
QT_BEGIN_NAMESPACE
-class QGeoPositionInfo;
-class QGeoAreaMonitorPrivate;
-class Q_POSITIONING_EXPORT QGeoAreaMonitor : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter)
- Q_PROPERTY(qreal radius READ radius WRITE setRadius)
+class QDataStream;
+class QGeoAreaMonitorInfo;
+#ifndef QT_NO_DATASTREAM
+Q_POSITIONING_EXPORT QDataStream &operator<<(QDataStream &, const QGeoAreaMonitorInfo &);
+Q_POSITIONING_EXPORT QDataStream &operator>>(QDataStream &, QGeoAreaMonitorInfo &);
+#endif
+
+class QGeoAreaMonitorInfoPrivate;
+class Q_POSITIONING_EXPORT QGeoAreaMonitorInfo
+{
public:
- explicit QGeoAreaMonitor(QObject *parent);
- virtual ~QGeoAreaMonitor() = 0;
+ explicit QGeoAreaMonitorInfo(const QString &name = QString());
+ QGeoAreaMonitorInfo(const QGeoAreaMonitorInfo &other);
+ ~QGeoAreaMonitorInfo();
+
+ QGeoAreaMonitorInfo &operator=(const QGeoAreaMonitorInfo &other);
- virtual void setCenter(const QGeoCoordinate &coordinate);
- QGeoCoordinate center() const;
+ bool operator==(const QGeoAreaMonitorInfo &other) const;
+ bool operator!=(const QGeoAreaMonitorInfo &other) const;
- virtual void setRadius(qreal radius);
- qreal radius() const;
+ QString name() const;
+ void setName(const QString &name);
- static QGeoAreaMonitor *createDefaultMonitor(QObject *parent);
- static QGeoAreaMonitor *createMonitor(const QString& sourceName, QObject *parent);
- static QStringList availableMonitors();
+ QString identifier() const;
+ bool isValid() const;
-Q_SIGNALS:
- void areaEntered(const QGeoPositionInfo &update);
- void areaExited(const QGeoPositionInfo &update);
+ QGeoShape area() const;
+ void setArea(const QGeoShape &newShape);
+ QDateTime expiration() const;
+ void setExpiration(const QDateTime &expiry);
+
+ bool isPersistent() const;
+ void setPersistent(bool isPersistent);
+
+ QVariantMap notificationParameters() const;
+ void setNotificationParameters(const QVariantMap &parameters);
private:
- Q_DISABLE_COPY(QGeoAreaMonitor)
- QGeoAreaMonitorPrivate *d;
+ QSharedDataPointer<QGeoAreaMonitorInfoPrivate> d;
+
+#ifndef QT_NO_DATASTREAM
+ friend Q_POSITIONING_EXPORT QDataStream &operator<<(QDataStream &, const QGeoAreaMonitorInfo &);
+ friend Q_POSITIONING_EXPORT QDataStream &operator>>(QDataStream &, QGeoAreaMonitorInfo &);
+#endif
};
+#ifndef QT_NO_DEBUG_STREAM
+Q_POSITIONING_EXPORT QDebug operator<<(QDebug, const QGeoAreaMonitorInfo &);
+#endif
QT_END_NAMESPACE
-#endif
+#endif // QGEOAREAMONITORINFO_H
diff --git a/src/positioning/qgeoareamonitorsource.cpp b/src/positioning/qgeoareamonitorsource.cpp
new file mode 100644
index 00000000..2f23d942
--- /dev/null
+++ b/src/positioning/qgeoareamonitorsource.cpp
@@ -0,0 +1,390 @@
+/****************************************************************************
+**
+** 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 <QGeoAreaMonitorSource>
+#include "qgeopositioninfosourcefactory.h"
+#include "qgeopositioninfosource_p.h"
+
+/*!
+ \class QGeoAreaMonitorSource
+ \inmodule QtPositioning
+ \ingroup QtPositioning-positioning
+ \since Qt Positioning 5.0
+
+ \brief The QGeoAreaMonitorSource class enables the detection of proximity
+ changes for a specified set of coordinates.
+
+ A QGeoAreaMonitorSource emits signals when the current position is in
+ range, or has moved out of range, of a specified area.
+ Each area is specified by a \l QGeoAreaMonitorInfo object.
+ For example:
+
+ \snippet cpp/cppqml.cpp BigBen
+
+ \c QGeoAreaMonitorSource follows a singleton pattern. Each instance of
+ the class with the same \l sourceName() shares the same area monitoring backend.
+ If a new \l QGeoAreaMonitorInfo object is added via \l startMonitoring()
+ or \l requestUpdate() it can be retrieved by another instance of this class
+ (provided that they are sourced from the same area monitor provider plug-in).
+ The same singleton pattern applies to the \l QGeoPositionInfoSource instance
+ used by this class. The following code snippet emphasizes the behavior:
+
+ \code
+ QGeoAreaMonitorSource *s1 = QGeoAreaMonitorSource::createSource("blah", this);
+ QGeoAreaMonitorSource *s2 = QGeoAreaMonitorSource::createSource("blah", this);
+ QVERIFY(s1->positionInfoSource() == s2->positionInfoSource);
+ \endcode
+*/
+
+QT_BEGIN_NAMESPACE
+
+
+
+class QGeoAreaMonitorSourcePrivate
+{
+public:
+ QGeoPositionInfoSource *source;
+ QString providerName;
+};
+
+/*!
+ \enum QGeoAreaMonitorSource::Error
+ Defines the types of positioning methods.
+
+ The Error enumeration represents the errors which can occur.
+
+ \value AccessError The connection setup to the remote area monitoring backend failed because the
+ application lacked the required privileges.
+ \value InsufficientPositionInfo The area monitoring source could not retrieve a location fix or
+ the accuracy of the fix is not high enough to provide an effective area monitoring.
+ \value UnknownSourceError An unidentified error occurred.
+*/
+
+/*!
+ \enum QGeoAreaMonitorSource::AreaMonitorFeature
+ Defines the types of area monitoring capabilities.
+
+ \value PersistentAreaMonitorFeature QGeoAreaMonitorInfo instances can be made persistent.
+ A persistent monitor continues to be active even when the application managing the monitor is
+ not running.
+ \value AnyAreaMonitorFeature Matches all possible area monitoring features.
+*/
+
+/*!
+ \fn virtual AreaMonitoringFeatures QGeoAreaMonitorSource::supportedAreaMonitorFeatures() const = 0;
+
+ Returns the area monitoring features available to this source.
+*/
+
+/*!
+ \fn virtual QGeoAreaMonitorSource::Error QGeoAreaMonitorSource::error() const
+
+ Returns the type of error that last occurred.
+*/
+
+/*!
+ Creates a monitor with the given \a parent.
+*/
+QGeoAreaMonitorSource::QGeoAreaMonitorSource(QObject *parent)
+ : QObject(parent),
+ d(new QGeoAreaMonitorSourcePrivate)
+{
+ d->source = 0;
+}
+
+/*!
+ Destroys the monitor.
+*/
+QGeoAreaMonitorSource::~QGeoAreaMonitorSource()
+{
+ delete d;
+}
+
+/*!
+ Creates and returns a monitor with the given \a parent that
+ monitors areas using resources on the underlying system.
+
+ Returns 0 if the system has no support for position monitoring.
+*/
+QGeoAreaMonitorSource *QGeoAreaMonitorSource::createDefaultSource(QObject *parent)
+{
+ QList<QJsonObject> plugins = QGeoPositionInfoSourcePrivate::pluginsSorted();
+ foreach (const QJsonObject &obj, plugins) {
+ if (obj.value(QStringLiteral("Monitor")).isBool()
+ && obj.value(QStringLiteral("Monitor")).toBool())
+ {
+ QGeoPositionInfoSourcePrivate d;
+ d.metaData = obj;
+ d.loadPlugin();
+ QGeoAreaMonitorSource *s = 0;
+ if (d.factory)
+ s = d.factory->areaMonitor(parent);
+ if (s)
+ s->d->providerName = d.metaData.value(QStringLiteral("Provider")).toString();
+ return s;
+ }
+ }
+
+ return 0;
+}
+
+/*!
+ Creates and returns a monitor with the given \a parent,
+ by loading the plugin named \a sourceName.
+
+ Returns 0 if the plugin cannot be found.
+*/
+QGeoAreaMonitorSource *QGeoAreaMonitorSource::createSource(const QString &sourceName, QObject *parent)
+{
+ QHash<QString, QJsonObject> plugins = QGeoPositionInfoSourcePrivate::plugins();
+ if (plugins.contains(sourceName)) {
+ QGeoPositionInfoSourcePrivate d;
+ d.metaData = plugins.value(sourceName);
+ d.loadPlugin();
+ QGeoAreaMonitorSource *s = 0;
+ if (d.factory)
+ s = d.factory->areaMonitor(parent);
+ if (s)
+ s->d->providerName = d.metaData.value(QStringLiteral("Provider")).toString();
+ return s;
+ }
+
+ return 0;
+}
+
+/*!
+ Returns a list of available monitor plugins, including the default system
+ backend if one is available.
+*/
+QStringList QGeoAreaMonitorSource::availableSources()
+{
+ QStringList plugins;
+ QHash<QString, QJsonObject> meta = QGeoPositionInfoSourcePrivate::plugins();
+ foreach (const QString &name, meta.keys()) {
+ if (meta.value(name).value(QStringLiteral("Monitor")).isBool()
+ && meta.value(name).value(QStringLiteral("Monitor")).toBool()) {
+ plugins << name;
+ }
+ }
+
+ return plugins;
+}
+
+/*!
+ Returns the unique name of the area monitor source implementation in use.
+
+ This is the same name that can be passed to createSource() in order to
+ create a new instance of a particular area monitor source implementation.
+*/
+QString QGeoAreaMonitorSource::sourceName() const
+{
+ return d->providerName;
+}
+
+/*!
+ Returns the current QGeoPositionInfoSource used by this QGeoAreaMonitorSource
+ object. The function will return \l QGeoPositionInfoSource::createDefaultSource()
+ if no other object has been set.
+
+ The function returns 0 if not even a default QGeoPositionInfoSource exists.
+
+ Any usage of the returned \l QGeoPositionInfoSource instance should account
+ for the fact that it may reside in a different thread.
+
+ \sa QGeoPositionInfoSource, setPositionInfoSource()
+*/
+QGeoPositionInfoSource* QGeoAreaMonitorSource::positionInfoSource() const
+{
+ return d->source;
+}
+
+/*!
+ Sets the new \l QGeoPositionInfoSource to be used by this QGeoAreaMonitorSource object.
+ The area monitoring backend becomes the new QObject parent for \a newSource.
+ The previous \l QGeoPositionInfoSource object will be deleted. All QGeoAreaMonitorSource
+ instances based on the same \l sourceName() share the same QGeoPositionInfoSource
+ instance.
+
+ This may be useful when it is desirable to manipulate the positioning system
+ used by the area monitoring engine.
+
+ Note that ownership must be taken care of by subclasses of QGeoAreaMonitorSource.
+ Due to the singleton pattern behind this class \a newSource may be moved to a
+ new thread.
+
+ \sa positionInfoSource()
+ */
+void QGeoAreaMonitorSource::setPositionInfoSource(QGeoPositionInfoSource *newSource)
+{
+ d->source = newSource;
+}
+
+
+/*!
+ \fn virtual bool QGeoAreaMonitorSource::startMonitoring(const QGeoAreaMonitorInfo &monitor)
+
+ Returns \c true if the monitoring of \a monitor could be successfully started; otherwise
+ returns false. A reason for not being able to start monitoring could be the unavailability
+ of an appropriate default position info source while no alternative QGeoPositionInfoSource
+ has been set via \l setPositionInfoSource().
+
+ If \a monitor is already active the existing monitor object will be replaced by the new \a monitor reference.
+ The identification of QGeoAreaMonitorInfo instances happens via \l QGeoAreaMonitorInfo::identifier().
+ Therefore this function can also be used to update active monitors.
+
+ If \a monitor has an expiry date that has been passed this function returns false. Calling
+ this function for an already via \l requestUpdate() registered single shot monitor
+ switches the monitor to a permanent monitoring mode.
+
+ Requesting persistent monitoring on a QGeoAreaMonitorSource instance fails if the area monitoring
+ backend doesn't support \l QGeoAreaMonitorSource::PersistentAreaMonitorFeature.
+
+ \sa stopMonitoring()
+*/
+
+/*!
+ \fn virtual bool QGeoAreaMonitorSource::requestUpdate(const QGeoAreaMonitorInfo &monitor, const char *signal)
+
+ Enables single shot area monitoring. Area monitoring for \a monitor will be performed
+ until this QGeoAreaMonitorSource instance emits \a signal for the first time. Once
+ the signal was emitted, \a monitor is automatically removed from the list of \l activeMonitors().
+ If \a monitor is invalid or has an expiry date that has been passed this function returns false.
+
+ \code
+ QGeoAreaMonitor singleShotMonitor;
+ QGeoAreaMonitorSource * source = QGeoAreaMonitorSource::createDefaultSource(this);
+ //...
+ bool ret = source->requestUpdate(singleShotMonitor,
+ SIGNAL(areaExited(QGeoAreaMonitor,QGeoPositionInfo)));
+ \endcode
+
+ The above \c singleShotMonitor object will cease to send updates once the \l areaExited() signal
+ was emitted for the first time. Until this point in time any other signal may be emitted
+ zero or more times depending on the area context.
+
+ It is not possible to simultanously request updates for more than one signal of the same monitor object.
+ The last call to this function determines the signal upon which the updates cease to continue.
+ At this stage only the \l areaEntered() and \l areaExited() signals can be used to
+ terminate the monitoring process.
+
+ Requesting persistent monitoring on a QGeoAreaMonitorSource instance fails if the area monitoring
+ backend doesn't support \l QGeoAreaMonitorSource::PersistentAreaMonitorFeature.
+
+ If \a monitor was already registered via \l startMonitoring() it is converted to a single
+ shot behavior.
+
+ \sa startMonitoring(), stopMonitoring()
+ */
+
+/*!
+ \fn virtual bool QGeoAreaMonitorSource::stopMonitoring(const QGeoAreaMonitorInfo &monitor)
+
+ Returns true if \a monitor was successfully removed from the list of \l activeMonitors();
+ otherwise returns false. This behavior is independent on whether \a monitor was registered
+ via \l startMonitoring() or \l requestUpdate().
+*/
+
+/*!
+ \fn virtual QList<QGeoAreaMonitorInfo> QGeoAreaMonitorSource::activeMonitors() const
+
+ Returns the list of all active monitors known to the QGeoAreaMonitorSource object.
+
+ An active monitor was started via startMonitoring() the source object will emit
+ the required signals such as areaEntered() or areaExited(). Multiple \l QGeoAreaMonitorSource
+ instances within the same application share the same active monitor objects.
+
+ Unless an active QGeoAreaMonitorInfo \l {QGeoAreaMonitorInfo::isPersistent()}{isPersistent()} an active QGeoAreaMonitorInfo
+ will be stopped once the current application terminates.
+*/
+
+/*!
+ \fn virtual QList<QGeoAreaMonitorInfo> QGeoAreaMonitorSource::activeMonitors(const QGeoShape &lookupArea) const
+
+ Returns the list of all active monitors known to the QGeoAreaMonitorSource object whose
+ center lies within \a lookupArea. If \a lookupArea is empty the returned list will be empty.
+
+ An active monitor was started via startMonitoring() and the source object will emit
+ the required signals such as areaEntered() or areaExited(). Multiple QGeoAreaMonitorSource
+ instances within the same application share the same monitor objects.
+
+ Unless an active QGeoAreaMonitorInfo \l {QGeoAreaMonitorInfo::isPersistent()}{isPersistent()} an active QGeoAreaMonitorInfo
+ will be stopped once the current application terminates.
+
+ \sa QGeoShape
+*/
+
+
+/*!
+ \fn void QGeoAreaMonitorSource::monitorExpired(const QGeoAreaMonitorInfo &monitor)
+
+ Emitted when \a monitor has expired. An expired area monitor is automatically
+ removed from the list of \l activeMonitors().
+
+ \sa activeMonitors()
+*/
+
+/*!
+ \fn void QGeoAreaMonitorSource::areaEntered(const QGeoAreaMonitorInfo &monitor, const QGeoPositionInfo &update)
+
+ Emitted when the current position has moved from a position outside of the active \a monitor
+ to a position within the monitored area.
+
+ The \a update holds the new position.
+*/
+
+/*!
+ \fn void QGeoAreaMonitorSource::areaExited(const QGeoAreaMonitorInfo &monitor, const QGeoPositionInfo &update)
+
+ Emitted when the current position has moved from a position within the active \a monitor
+ to a position outside the monitored area.
+
+ The \a update holds the new position.
+*/
+
+/*!
+ \fn void QGeoAreaMonitorSource::error(QGeoAreaMonitorSource::Error areaMonitoringError)
+
+ This signal is emitted after an error occurred. The \a areaMonitoringError
+ parameter describes the type of error that occurred.
+
+*/
+
+QT_END_NAMESPACE
diff --git a/src/positioning/qgeoareamonitorsource.h b/src/positioning/qgeoareamonitorsource.h
new file mode 100644
index 00000000..03c98874
--- /dev/null
+++ b/src/positioning/qgeoareamonitorsource.h
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** 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 QGEOAREAMONITORSOURCE_H
+#define QGEOAREAMONITORSOURCE_H
+
+#include <QtPositioning/QGeoCoordinate>
+#include <QtPositioning/QGeoAreaMonitorInfo>
+#include <QtPositioning/QGeoPositionInfoSource>
+
+#include <QObject>
+#include <QStringList>
+
+QT_BEGIN_NAMESPACE
+
+class QGeoPositionInfo;
+class QGeoAreaMonitorSourcePrivate;
+class Q_POSITIONING_EXPORT QGeoAreaMonitorSource : public QObject
+{
+ Q_OBJECT
+
+public:
+ enum Error {
+ AccessError = 0,
+ InsufficientPositionInfo,
+ UnknownSourceError
+ };
+ Q_ENUMS(Error)
+
+ enum AreaMonitorFeature {
+ PersistentAreaMonitorFeature = 0x00000001,
+ AnyAreaMonitorFeature = 0xffffffff
+ };
+ Q_DECLARE_FLAGS(AreaMonitorFeatures, AreaMonitorFeature)
+
+ explicit QGeoAreaMonitorSource(QObject *parent);
+ virtual ~QGeoAreaMonitorSource();
+
+ static QGeoAreaMonitorSource *createDefaultSource(QObject *parent);
+ static QGeoAreaMonitorSource *createSource(const QString& sourceName, QObject *parent);
+ static QStringList availableSources();
+
+ virtual void setPositionInfoSource(QGeoPositionInfoSource *source);
+ virtual QGeoPositionInfoSource* positionInfoSource() const;
+
+ QString sourceName() const;
+
+ virtual Error error() const = 0;
+ virtual AreaMonitorFeatures supportedAreaMonitorFeatures() const = 0;
+
+ virtual bool startMonitoring(const QGeoAreaMonitorInfo &monitor) = 0;
+ virtual bool stopMonitoring(const QGeoAreaMonitorInfo &monitor) = 0;
+ virtual bool requestUpdate(const QGeoAreaMonitorInfo &monitor, const char *signal) = 0;
+
+ virtual QList<QGeoAreaMonitorInfo> activeMonitors() const = 0;
+ virtual QList<QGeoAreaMonitorInfo> activeMonitors(const QGeoShape &lookupArea) const = 0;
+
+Q_SIGNALS:
+ void areaEntered(const QGeoAreaMonitorInfo &monitor, const QGeoPositionInfo &update);
+ void areaExited(const QGeoAreaMonitorInfo &monitor, const QGeoPositionInfo &update);
+ void monitorExpired(const QGeoAreaMonitorInfo &monitor);
+ void error(QGeoAreaMonitorSource::Error error);
+
+private:
+ Q_DISABLE_COPY(QGeoAreaMonitorSource)
+ QGeoAreaMonitorSourcePrivate *d;
+};
+
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/positioning/qgeopositioninfosourcefactory.cpp b/src/positioning/qgeopositioninfosourcefactory.cpp
index a113a4aa..bebbe20e 100644
--- a/src/positioning/qgeopositioninfosourcefactory.cpp
+++ b/src/positioning/qgeopositioninfosourcefactory.cpp
@@ -73,9 +73,9 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QGeoAreaMonitor *QGeoPositionInfoSourceFactory::areaMonitor(QObject *parent);
+ \fn QGeoAreaMonitorSource *QGeoPositionInfoSourceFactory::areaMonitor(QObject *parent);
- Returns a new QGeoAreaMonitor associated with this plugin with parent \a parent.
+ Returns a new QGeoAreaMonitorSource associated with this plugin with parent \a parent.
Can also return 0, in which case the plugin loader will use the factory with the
next highest priority.
*/
diff --git a/src/positioning/qgeopositioninfosourcefactory.h b/src/positioning/qgeopositioninfosourcefactory.h
index 32e0bc00..5704c2dc 100644
--- a/src/positioning/qgeopositioninfosourcefactory.h
+++ b/src/positioning/qgeopositioninfosourcefactory.h
@@ -44,7 +44,7 @@
#include <QtPositioning/QGeoPositionInfoSource>
#include <QtPositioning/QGeoSatelliteInfoSource>
-#include <QtPositioning/QGeoAreaMonitor>
+#include <QtPositioning/QGeoAreaMonitorSource>
#include <QList>
QT_BEGIN_NAMESPACE
@@ -56,7 +56,7 @@ public:
virtual QGeoPositionInfoSource *positionInfoSource(QObject *parent) = 0;
virtual QGeoSatelliteInfoSource *satelliteInfoSource(QObject *parent) = 0;
- virtual QGeoAreaMonitor *areaMonitor(QObject *parent) = 0;
+ virtual QGeoAreaMonitorSource *areaMonitor(QObject *parent) = 0;
};
#define QT_POSITION_SOURCE_INTERFACE
diff --git a/src/positioning/qgeosatelliteinfosource.cpp b/src/positioning/qgeosatelliteinfosource.cpp
index faf8dad8..ee1b316a 100644
--- a/src/positioning/qgeosatelliteinfosource.cpp
+++ b/src/positioning/qgeosatelliteinfosource.cpp
@@ -93,6 +93,7 @@ class QGeoSatelliteInfoSourcePrivate
{
public:
int interval;
+ QString providerName;
};
/*!
@@ -114,6 +115,18 @@ QGeoSatelliteInfoSource::~QGeoSatelliteInfoSource()
}
/*!
+ Returns the unique name of the satellite source implementation in use.
+
+ This is the same name that can be passed to createSource() in order to
+ create a new instance of a particular satellite source implementation.
+*/
+QString QGeoSatelliteInfoSource::sourceName() const
+{
+ return d->providerName;
+}
+
+
+/*!
\property QGeoSatelliteInfoSource::updateInterval
\brief This property holds the requested interval in milliseconds between each update.
@@ -168,6 +181,8 @@ QGeoSatelliteInfoSource *QGeoSatelliteInfoSource::createDefaultSource(QObject *p
QGeoSatelliteInfoSource *s = 0;
if (d.factory)
s = d.factory->satelliteInfoSource(parent);
+ if (s)
+ s->d->providerName = d.metaData.value(QStringLiteral("Provider")).toString();
return s;
}
}
@@ -191,6 +206,8 @@ QGeoSatelliteInfoSource *QGeoSatelliteInfoSource::createSource(const QString &so
QGeoSatelliteInfoSource *src = 0;
if (d.factory)
src = d.factory->satelliteInfoSource(parent);
+ if (src)
+ src->d->providerName = d.metaData.value(QStringLiteral("Provider")).toString();
return src;
}
diff --git a/src/positioning/qgeosatelliteinfosource.h b/src/positioning/qgeosatelliteinfosource.h
index 35aa2b33..2b25aec7 100644
--- a/src/positioning/qgeosatelliteinfosource.h
+++ b/src/positioning/qgeosatelliteinfosource.h
@@ -57,7 +57,7 @@ class Q_POSITIONING_EXPORT QGeoSatelliteInfoSource : public QObject
public:
enum Error {
- AccessError,
+ AccessError = 0,
ClosedError, /* 1 */
UnknownSourceError = -1
};
@@ -70,6 +70,8 @@ public:
static QGeoSatelliteInfoSource *createSource(const QString &sourceName, QObject *parent);
static QStringList availableSources();
+ QString sourceName() const;
+
virtual void setUpdateInterval(int msec);
int updateInterval() const;
virtual int minimumUpdateInterval() const = 0;