QGeoAreaMonitorSource Class
The QGeoAreaMonitorSource class enables the detection of proximity changes for a specified set of coordinates. More...
Header: | #include <QGeoAreaMonitorSource> |
qmake: | QT += positioning |
Since: | Qt 5.2 |
Inherits: | QObject |
Public Types
enum | AreaMonitorFeature { PersistentAreaMonitorFeature, AnyAreaMonitorFeature } |
flags | AreaMonitorFeatures |
enum | Error { AccessError, InsufficientPositionInfo, NoError, UnknownSourceError } |
Public Functions
QGeoAreaMonitorSource(QObject *parent) | |
virtual | ~QGeoAreaMonitorSource() |
virtual QList<QGeoAreaMonitorInfo> | activeMonitors() const = 0 |
virtual QList<QGeoAreaMonitorInfo> | activeMonitors(const QGeoShape &lookupArea) const = 0 |
virtual QGeoAreaMonitorSource::Error | error() const = 0 |
virtual QGeoPositionInfoSource * | positionInfoSource() const |
virtual bool | requestUpdate(const QGeoAreaMonitorInfo &monitor, const char *signal) = 0 |
virtual void | setPositionInfoSource(QGeoPositionInfoSource *newSource) |
QString | sourceName() const |
virtual bool | startMonitoring(const QGeoAreaMonitorInfo &monitor) = 0 |
virtual bool | stopMonitoring(const QGeoAreaMonitorInfo &monitor) = 0 |
virtual QGeoAreaMonitorSource::AreaMonitorFeatures | supportedAreaMonitorFeatures() const = 0 |
- 31 public functions inherited from QObject
Signals
void | areaEntered(const QGeoAreaMonitorInfo &monitor, const QGeoPositionInfo &update) |
void | areaExited(const QGeoAreaMonitorInfo &monitor, const QGeoPositionInfo &update) |
void | error(QGeoAreaMonitorSource::Error error) |
void | monitorExpired(const QGeoAreaMonitorInfo &monitor) |
- 2 signals inherited from QObject
Static Public Members
QStringList | availableSources() |
QGeoAreaMonitorSource * | createDefaultSource(QObject *parent) |
QGeoAreaMonitorSource * | createSource(const QString &sourceName, QObject *parent) |
const QMetaObject | staticMetaObject |
- 9 static public members inherited from QObject
Additional Inherited Members
- 1 property inherited from QObject
- 1 public slot inherited from QObject
- 9 protected functions inherited from QObject
Detailed Description
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 QGeoAreaMonitorInfo object. For example:
public: MyClass() : QObject() { QGeoAreaMonitorSource *monitor = QGeoAreaMonitorSource::createDefaultSource(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.setArea(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) { Q_UNUSED(mon) qDebug() << "Now within 100 meters, current position is" << update.coordinate(); } void areaExited(const QGeoAreaMonitorInfo &mon, const QGeoPositionInfo &update) { Q_UNUSED(mon) qDebug() << "No longer within 100 meters, current position is" << update.coordinate(); }
QGeoAreaMonitorSource
follows a singleton pattern. Each instance of the class with the same sourceName() shares the same area monitoring backend. If a new QGeoAreaMonitorInfo object is added via startMonitoring() or 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 QGeoPositionInfoSource instance used by this class. The following code snippet emphasizes the behavior:
QGeoAreaMonitorSource *s1 = QGeoAreaMonitorSource::createSource("blah", this); QGeoAreaMonitorSource *s2 = QGeoAreaMonitorSource::createSource("blah", this); QVERIFY(s1->positionInfoSource() == s2->positionInfoSource);
Member Type Documentation
enum QGeoAreaMonitorSource::AreaMonitorFeature
flags QGeoAreaMonitorSource::AreaMonitorFeatures
Defines the types of area monitoring capabilities.
Constant | Value | Description |
---|---|---|
QGeoAreaMonitorSource::PersistentAreaMonitorFeature | 0x00000001 | QGeoAreaMonitorInfo instances can be made persistent. A persistent monitor continues to be active even when the application managing the monitor is not running. |
QGeoAreaMonitorSource::AnyAreaMonitorFeature | 0xffffffff | Matches all possible area monitoring features. |
The AreaMonitorFeatures type is a typedef for QFlags<AreaMonitorFeature>. It stores an OR combination of AreaMonitorFeature values.
enum QGeoAreaMonitorSource::Error
Defines the types of positioning methods.
The Error enumeration represents the errors which can occur.
Constant | Value | Description |
---|---|---|
QGeoAreaMonitorSource::AccessError | 0 | The connection setup to the remote area monitoring backend failed because the application lacked the required privileges. |
QGeoAreaMonitorSource::InsufficientPositionInfo | 1 | 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. |
QGeoAreaMonitorSource::NoError | 3 | No error has occurred. |
QGeoAreaMonitorSource::UnknownSourceError | 2 | An unidentified error occurred. |
Member Function Documentation
QGeoAreaMonitorSource::QGeoAreaMonitorSource(QObject *parent)
Creates a monitor with the given parent.
[virtual]
QGeoAreaMonitorSource::~QGeoAreaMonitorSource()
Destroys the monitor.
[pure virtual]
QList<QGeoAreaMonitorInfo> QGeoAreaMonitorSource::activeMonitors() const
[pure virtual]
QList<QGeoAreaMonitorInfo> QGeoAreaMonitorSource::activeMonitors(const QGeoShape &lookupArea) const
[signal]
void QGeoAreaMonitorSource::areaEntered(const QGeoAreaMonitorInfo &monitor, const QGeoPositionInfo &update)
[signal]
void QGeoAreaMonitorSource::areaExited(const QGeoAreaMonitorInfo &monitor, const QGeoPositionInfo &update)
[static]
QStringList QGeoAreaMonitorSource::availableSources()
Returns a list of available monitor plugins, including the default system backend if one is available.
[static]
QGeoAreaMonitorSource *QGeoAreaMonitorSource::createDefaultSource(QObject *parent)
Creates and returns a monitor with the given parent that monitors areas using resources on the underlying system.
Returns 0 if the system has no support for position monitoring.
[static]
QGeoAreaMonitorSource *QGeoAreaMonitorSource::createSource(const QString &sourceName, QObject *parent)
Creates and returns a monitor with the given parent, by loading the plugin named sourceName.
Returns 0 if the plugin cannot be found.
[pure virtual]
QGeoAreaMonitorSource::Error QGeoAreaMonitorSource::error() const
[signal]
void QGeoAreaMonitorSource::error(QGeoAreaMonitorSource::Error error)
Note: Signal error is overloaded in this class. To connect to this signal by using the function pointer syntax, Qt provides a convenient helper for obtaining the function pointer as shown in this example:
connect(geoAreaMonitorSource, QOverload<QGeoAreaMonitorSource::Error>::of(&QGeoAreaMonitorSource::error), [=](QGeoAreaMonitorSource::Error error){ /* ... */ });
[signal]
void QGeoAreaMonitorSource::monitorExpired(const QGeoAreaMonitorInfo &monitor)
[virtual]
QGeoPositionInfoSource *QGeoAreaMonitorSource::positionInfoSource() const
Returns the current QGeoPositionInfoSource used by this QGeoAreaMonitorSource object. The function will return 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 QGeoPositionInfoSource instance should account for the fact that it may reside in a different thread.
See also QGeoPositionInfoSource and setPositionInfoSource().
[pure virtual]
bool QGeoAreaMonitorSource::requestUpdate(const QGeoAreaMonitorInfo &monitor, const char *signal)
[virtual]
void QGeoAreaMonitorSource::setPositionInfoSource(QGeoPositionInfoSource *newSource)
Sets the new QGeoPositionInfoSource to be used by this QGeoAreaMonitorSource object. The area monitoring backend becomes the new QObject parent for newSource. The previous QGeoPositionInfoSource object will be deleted. All QGeoAreaMonitorSource instances based on the same 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 newSource may be moved to a new thread.
See also positionInfoSource().
QString QGeoAreaMonitorSource::sourceName() const
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.