PySide6.QtPositioning.QGeoAreaMonitorSource¶
- class QGeoAreaMonitorSource¶
The
QGeoAreaMonitorSourceclass enables the detection of proximity changes for a specified set of coordinates. More…Synopsis¶
Methods¶
def
__init__()def
sourceName()
Virtual methods¶
def
activeMonitors()def
error()def
requestUpdate()def
stopMonitoring()
Signals¶
def
areaEntered()def
areaExited()def
errorOccurred()def
monitorExpired()
Static functions¶
def
createSource()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
A
QGeoAreaMonitorSourceemits signals when the current position is in range, or has moved out of range, of a specified area. Each area is specified by aQGeoAreaMonitorInfoobject. For example:# public MyClass() : QObject() monitor = QGeoAreaMonitorSource.createDefaultSource(self) if monitor: connect(monitor, SIGNAL(areaEntered(QGeoAreaMonitorInfo,QGeoPositionInfo)), self, SLOT(areaEntered(QGeoAreaMonitorInfo,QGeoPositionInfo))) connect(monitor, SIGNAL(areaExited(QGeoAreaMonitorInfo,QGeoPositionInfo)), self, SLOT(areaExited(QGeoAreaMonitorInfo,QGeoPositionInfo))) bigBen = QGeoAreaMonitorInfo("Big Ben") position = QGeoCoordinate(51.50104, -0.124632) bigBen.setArea(QGeoCircle(position, 100)) monitor.startMonitoring(bigBen) else: print("Could not create default area monitor") public Q_SLOTS: def areaEntered(mon, update): Q_UNUSED(mon) print("Now within 100 meters, current position is", update.coordinate()) def areaExited(mon, update): Q_UNUSED(mon) print("No longer within 100 meters, current position is", update.coordinate())
QGeoAreaMonitorSourcefollows a singleton pattern. Each instance of the class with the samesourceName()shares the same area monitoring backend. If a newQGeoAreaMonitorInfoobject is added viastartMonitoring()orrequestUpdate()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 theQGeoPositionInfoSourceinstance 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);
- class Error¶
Defines the types of positioning methods.
The Error enumeration represents the errors which can occur.
Constant
Description
QGeoAreaMonitorSource.Error.AccessError
The connection setup to the remote area monitoring backend failed because the application lacked the required privileges.
QGeoAreaMonitorSource.Error.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.
QGeoAreaMonitorSource.Error.NoError
No error has occurred.
QGeoAreaMonitorSource.Error.UnknownSourceError
An unidentified error occurred.
- class AreaMonitorFeature¶
(inherits
enum.Flag) Defines the types of area monitoring capabilities.Constant
Description
QGeoAreaMonitorSource.AreaMonitorFeature.PersistentAreaMonitorFeature
QGeoAreaMonitorInfoinstances can be made persistent. A persistent monitor continues to be active even when the application managing the monitor is not running.QGeoAreaMonitorSource.AreaMonitorFeature.AnyAreaMonitorFeature
Matches all possible area monitoring features.
Creates a monitor source with the given
parent.- abstract activeMonitors()¶
- Return type:
.list of QGeoAreaMonitorInfo
Returns the list of all active monitors known to the
QGeoAreaMonitorSourceobject.An active monitor was started via
startMonitoring(). For every active monitor the source object will emit the required signals, such asareaEntered()orareaExited(). MultipleQGeoAreaMonitorSourceinstances within the same application share the same active monitor objects.Unless an active
QGeoAreaMonitorInfoisPersistent()an activeQGeoAreaMonitorInfowill be stopped once the current application terminates.- abstract activeMonitors(lookupArea)
- Parameters:
lookupArea –
QGeoShape- Return type:
.list of QGeoAreaMonitorInfo
Returns the list of all active monitors known to the
QGeoAreaMonitorSourceobject whose center lies withinlookupArea. IflookupAreais empty the returned list will be empty.An active monitor was started via
startMonitoring(). For every active monitor the source object will emit the required signals, such asareaEntered()orareaExited(). MultipleQGeoAreaMonitorSourceinstances within the same application share the same active monitor objects.Unless an active
QGeoAreaMonitorInfoisPersistent()an activeQGeoAreaMonitorInfowill be stopped once the current application terminates.See also
- areaEntered(monitor, update)¶
- Parameters:
monitor –
QGeoAreaMonitorInfoupdate –
QGeoPositionInfo
Emitted when the current position has moved from a position outside of the active
monitorto a position within the monitored area.The
updateholds the new position.- areaExited(monitor, update)¶
- Parameters:
monitor –
QGeoAreaMonitorInfoupdate –
QGeoPositionInfo
Emitted when the current position has moved from a position within the active
monitorto a position outside the monitored area.The
updateholds the new position.- static availableSources()¶
- Return type:
list of strings
Returns a list of available monitor plugins, including the default system backend if one is available.
- backendProperty(name)¶
- Parameters:
name – str
- Return type:
object
Returns the value of the backend-specific property named
name, if present. Otherwise the returned value will be invalid.See also
Creates and returns a monitor source with the given
parentthat monitors areas using resources on the underlying system.Returns
nullptrif the system has no support for position monitoring.Creates and returns a monitor source with the given
parent, by loading the plugin namedsourceName.Returns
nullptrif the plugin cannot be found.Returns the type of error that last occurred.
Note
Since Qt6 the last error is always reset when calling
startMonitoring()orrequestUpdate().This signal is emitted after an error occurred. The
areaMonitoringErrorparameter describes the type of error that occurred.- monitorExpired(monitor)¶
- Parameters:
monitor –
QGeoAreaMonitorInfo
Emitted when
monitorhas expired. An expired area monitor is automatically removed from the list ofactiveMonitors().See also
- positionInfoSource()¶
- Return type:
Returns the current
QGeoPositionInfoSourceused by thisQGeoAreaMonitorSourceobject. The function will returncreateDefaultSource()if no other object has been set.The function returns
nullptrif not even a defaultQGeoPositionInfoSourceexists.Any usage of the returned
QGeoPositionInfoSourceinstance should account for the fact that it may reside in a different thread.- abstract requestUpdate(monitor, signal)¶
- Parameters:
monitor –
QGeoAreaMonitorInfosignal – str
- Return type:
bool
Enables single shot area monitoring. Area monitoring for
monitorwill be performed until thisQGeoAreaMonitorSourceinstance emitssignalfor the first time. Once the signal was emitted,monitoris automatically removed from the list ofactiveMonitors(). Ifmonitoris invalid or has an expiry date that has been passed, this function returnsfalse.QGeoAreaMonitor singleShotMonitor; QGeoAreaMonitorSource * source = QGeoAreaMonitorSource::createDefaultSource(this); //... bool ret = source->requestUpdate(singleShotMonitor, SIGNAL(areaExited(QGeoAreaMonitor,QGeoPositionInfo)));
The above
singleShotMonitorobject will cease to send updates once theareaExited()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
areaEntered()andareaExited()signals can be used to terminate the monitoring process.Requesting persistent monitoring on a
QGeoAreaMonitorSourceinstance fails if the area monitoring backend doesn’t supportPersistentAreaMonitorFeature.If
monitorwas already registered viastartMonitoring()it is converted to a single shot behavior.Note
Since Qt6 this method always resets the last error to
NoErrorbefore starting monitoring.See also
- setBackendProperty(name, value)¶
- Parameters:
name – str
value – object
- Return type:
bool
Sets the backend-specific property named
nametovalue. Returnstrueon success, otherwise returnsfalse. Backend-specific properties can be used to configure the area monitoring subsystem behavior at runtime.See also
- setPositionInfoSource(source)¶
- Parameters:
source –
QGeoPositionInfoSource
Sets the new
QGeoPositionInfoSourceto be used by thisQGeoAreaMonitorSourceobject. The area monitoring backend becomes the new QObject parent fornewSource. The previousQGeoPositionInfoSourceobject will be deleted. AllQGeoAreaMonitorSourceinstances based on the samesourceName()share the sameQGeoPositionInfoSourceinstance.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 classnewSourcemay be moved to a new thread.See also
- sourceName()¶
- Return type:
str
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.- abstract startMonitoring(monitor)¶
- Parameters:
monitor –
QGeoAreaMonitorInfo- Return type:
bool
Returns
trueif the monitoring ofmonitorcould be successfully started; otherwise returnsfalse. A reason for not being able to start monitoring could be the unavailability of an appropriate default position info source while no alternativeQGeoPositionInfoSourcehas been set viasetPositionInfoSource().If
monitoris already active, the existing monitor object will be replaced by the newmonitorreference. The identification ofQGeoAreaMonitorInfoinstances happens viaidentifier(). Therefore this function can also be used to update active monitors.If
monitorhas an expiry date that has been passed this function returns false. Calling this function for an already viarequestUpdate()registered single shot monitor switches the monitor to a permanent monitoring mode.Requesting persistent monitoring on a
QGeoAreaMonitorSourceinstance fails if the area monitoring backend doesn’t supportPersistentAreaMonitorFeature.Note
Since Qt6 this method always resets the last error to
NoErrorbefore starting monitoring.See also
- abstract stopMonitoring(monitor)¶
- Parameters:
monitor –
QGeoAreaMonitorInfo- Return type:
bool
Returns true if
monitorwas successfully removed from the list ofactiveMonitors(); otherwise returns false. This behavior is independent on whethermonitorwas registered viastartMonitoring()orrequestUpdate().- abstract supportedAreaMonitorFeatures()¶
- Return type:
Combination of
AreaMonitorFeature
Returns the area monitoring features available to this source.