5#include <QtPositioning/qgeocoordinate.h>
6#include <QtPositioning/qgeorectangle.h>
7#include <QtPositioning/qgeocircle.h>
9#include <QtCore/qhash.h>
10#include <QtCore/qmetaobject.h>
11#include <QtCore/qtimer.h>
12#include <QtCore/qdebug.h>
13#include <QtCore/qmutex.h>
14#include <QtCore/qset.h>
18#define UPDATE_INTERVAL_5S 5000
47 nextExpiryTimer =
new QTimer(
this);
55 const std::lock_guard<QRecursiveMutex> locker(mutex);
61 setupNextExpiryTimeout();
66 const std::lock_guard<QRecursiveMutex> locker(mutex);
72 setupNextExpiryTimeout();
77 const std::lock_guard<QRecursiveMutex> locker(mutex);
82 setupNextExpiryTimeout();
89 const std::lock_guard<QRecursiveMutex> locker(mutex);
100 registeredClients.
append(client);
105 const std::lock_guard<QRecursiveMutex> locker(mutex);
108 if (registeredClients.
isEmpty())
114 const std::lock_guard<QRecursiveMutex> locker(mutex);
127 if (
source->updateInterval() == 0)
140 const std::lock_guard<QRecursiveMutex> locker(mutex);
146 const std::lock_guard<QRecursiveMutex> locker(mutex);
148 return activeMonitorAreas;
153 const std::lock_guard<QRecursiveMutex> locker(mutex);
155 bool signalsConnected =
false;
157 if (client->hasConnections()) {
158 signalsConnected =
true;
163 if (signalsConnected && !activeMonitorAreas.
isEmpty()) {
176 void setupNextExpiryTimeout()
178 nextExpiryTimer->
stop();
180 activeExpiry.second =
QString();
183 if (
info.expiration().isValid()) {
184 if (!activeExpiry.first.isValid()) {
185 activeExpiry.first =
info.expiration();
186 activeExpiry.second =
info.identifier();
189 if (
info.expiration() < activeExpiry.first) {
190 activeExpiry.first =
info.expiration();
191 activeExpiry.second =
info.identifier();
196 if (activeExpiry.first.isValid())
202 bool processInsideArea(
const QString &monitorIdent)
204 if (!insideArea.
contains(monitorIdent)) {
207 singleShotTrigger.
remove(monitorIdent);
208 activeMonitorAreas.
remove(monitorIdent);
209 setupNextExpiryTimeout();
211 insideArea.
insert(monitorIdent);
220 bool processOutsideArea(
const QString &monitorIdent)
222 if (insideArea.
contains(monitorIdent)) {
225 singleShotTrigger.
remove(monitorIdent);
226 activeMonitorAreas.
remove(monitorIdent);
227 setupNextExpiryTimeout();
229 insideArea.
remove(monitorIdent);
251 setupNextExpiryTimeout();
261 if (processInsideArea(identifier))
264 if (processOutsideArea(identifier))
287 d = pollingPrivate();
288 d->registerClient(
this);
290 if (!positionInfoSource())
336int QGeoAreaMonitorPolling::idForSignal(
const char *
signal)
344bool QGeoAreaMonitorPolling::hasConnections()
const
347 return signalConnections > 0;
366 const int signalId = idForSignal(
signal);
388 return info.isValid();
420 const bool alreadyConnected = hasConnections();
422 if (!alreadyConnected)
431 if (hasConnections())
433 if (!hasConnections())
473#include "qgeoareamonitor_polling.moc"
474#include "moc_qgeoareamonitor_polling.cpp"
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
\inmodule QtCore\reentrant
static QDateTime currentDateTime()
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isValid() const
Returns true if this datetime represents a definite moment, otherwise false.
QGeoShape area() const
Returns the boundaries of the to-be-monitored area.
bool isValid() const
Returns true, if the monitor is valid.
QString identifier() const
Returns the identifier of the QGeoAreaMonitorInfo object.
QDateTime expiration() const
Returns the expiry date.
bool isPersistent() const
Returns true if the QGeoAreaMonitorInfo is persistent.
QGeoAreaMonitorInfo stopMonitoring(const QGeoAreaMonitorInfo &monitor)
void timeout(const QGeoAreaMonitorInfo &info)
void areaEventDetected(const QGeoAreaMonitorInfo &minfo, const QGeoPositionInfo &pinfo, bool isEnteredEvent)
void registerClient(QGeoAreaMonitorPolling *client)
void requestUpdate(const QGeoAreaMonitorInfo &monitor, int signalId)
void positionError(const QGeoPositionInfoSource::Error error)
QGeoPositionInfoSource * positionSource() const
MonitorTable activeMonitors() const
void setPositionSource(QGeoPositionInfoSource *newSource)
void deregisterClient(QGeoAreaMonitorPolling *client)
QGeoAreaMonitorPollingPrivate()
void startMonitoring(const QGeoAreaMonitorInfo &monitor)
Error error() const override
Returns the type of error that last occurred.
QGeoPositionInfoSource * positionInfoSource() const override
Returns the current QGeoPositionInfoSource used by this QGeoAreaMonitorSource object.
void connectNotify(const QMetaMethod &signal) override
QGeoAreaMonitorSource::AreaMonitorFeatures supportedAreaMonitorFeatures() const override
Returns the area monitoring features available to this source.
QList< QGeoAreaMonitorInfo > activeMonitors() const override
Returns the list of all active monitors known to the QGeoAreaMonitorSource object.
bool stopMonitoring(const QGeoAreaMonitorInfo &monitor) override
Returns true if monitor was successfully removed from the list of \l activeMonitors(); otherwise retu...
~QGeoAreaMonitorPolling()
void setPositionInfoSource(QGeoPositionInfoSource *source) override
Sets the new \l QGeoPositionInfoSource to be used by this QGeoAreaMonitorSource object.
bool requestUpdate(const QGeoAreaMonitorInfo &monitor, const char *signal) override
Enables single shot area monitoring.
bool startMonitoring(const QGeoAreaMonitorInfo &monitor) override
Returns true if the monitoring of monitor could be successfully started; otherwise returns false.
void disconnectNotify(const QMetaMethod &signal) override
void areaEntered(const QGeoAreaMonitorInfo &monitor, const QGeoPositionInfo &update)
Emitted when the current position has moved from a position outside of the active monitor to a positi...
void errorOccurred(QGeoAreaMonitorSource::Error error)
This signal is emitted after an error occurred.
Error
Defines the types of positioning methods.
@ InsufficientPositionInfo
void monitorExpired(const QGeoAreaMonitorInfo &monitor)
Emitted when monitor has expired.
void areaExited(const QGeoAreaMonitorInfo &monitor, const QGeoPositionInfo &update)
Emitted when the current position has moved from a position within the active monitor to a position o...
static QGeoPositionInfoSource * createDefaultSource(QObject *parent)
Creates and returns a position source with the given parent that reads from the system's default sour...
Error
The Error enumeration represents the errors which can occur.
Q_INVOKABLE bool contains(const QGeoCoordinate &coordinate) const
Returns whether the coordinate coordinate is contained within this geo shape.
bool isEmpty
This property defines whether this geo shape is empty.
bool remove(const Key &key)
Removes the item that has the key from the hash.
QList< T > values() const
Returns a list containing all the values in the hash, in an arbitrary order.
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it.
T value(const Key &key) const noexcept
bool isEmpty() const noexcept
Returns true if the hash contains no items; otherwise returns false.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
bool isEmpty() const noexcept
qsizetype removeAll(const AT &t)
void append(parameter_type t)
bool isSignalConnected(const QMetaMethod &signal) const
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
void setParent(QObject *parent)
Makes the object a child of parent.
QThread * thread() const
Returns the thread in which the object lives.
bool remove(const T &value)
bool contains(const T &value) const
iterator insert(const T &value)
\macro QT_RESTRICTED_CAST_FROM_ASCII
void setSingleShot(bool singleShot)
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
void stop()
Stops the timer.
std::pair< T1, T2 > QPair
DBusConnection const char DBusError * error
QHash< QString, QGeoAreaMonitorInfo > MonitorTable
static QMetaMethod areaEnteredSignal()
#define UPDATE_INTERVAL_5S
static QMetaMethod monitorExpiredSignal()
static QMetaMethod areaExitedSignal()
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
static qint64 msecsTo(const QDateTime &from, const QDateTime &to)
GLsizei GLsizei GLchar * source
QFileInfo info(fileName)
[8]
obj metaObject() -> className()
myObject disconnect()
[26]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent